{# This is the template file, do not Edit it! -#}
cmake_minimum_required(VERSION 3.24)

project({{ project_name }} LANGUAGES C CXX)

# Set cmake path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
{% if workspace.build_options %}
# Some option
{%- for option in workspace.build_options %}
option({{option.name | upper}} "{{option.description}}" {{option.status}})
{%- endfor %}
{%- endif %}

# Some necessary settings
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(INSTALL_CONFIG_NAME ${PROJECT_NAME}-config)

# Master project configuration
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

  set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  set(CMAKE_CXX_VISIBLITY_INLINES_HIDDEN ON)
  set(BUILD_SHARED_LIBS OFF)

  if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    if({{ project_name | upper }}_BUILD_TESTS)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
    endif()
  endif()

  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
  add_compile_options(/utf-8 /wd4819)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
endif()

if(WIN32)
  add_compile_definitions(NOMINMAX)
endif()

# Include cmake module
include(NamespaceTool)

if({{ project_name | upper }}_BUILD_TESTS)
  include(GetGTest)
  enable_testing()
endif()

set(YAML_CPP_INSTALL ON)
include(GetAimRT)
{%- for depend in workspace.depends_std_modules %}
include(Get{{ depend.std_depend_name }})
{%- endfor %}

# find_package(rclcpp REQUIRED)

# Add subdirectory
add_subdirectory(src)

# Install
install(
  DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake
  DESTINATION ./
  FILES_MATCHING
  PATTERN "*.cmake")
install(EXPORT ${INSTALL_CONFIG_NAME} DESTINATION lib/cmake/${PROJECT_NAME})
{# blank line #}