cpp-lib-generator/templates/CMakeLists.txt.jinja

42 lines
1.6 KiB
Django/Jinja

cmake_minimum_required(VERSION 3.20)
project({{ project_name_cmake }})
option({{ project_name | replace(" ", "_") | upper }}_BUILD_TESTS "Build {{ project_name }} tests" OFF)
{% if len(examples_names) > 0 %}option({{ project_name | replace(" ", "_") | upper }}_BUILD_EXAMPLES "Build {{ project_name }} examples" OFF)
{% endif %}
set(CMAKE_CXX_STANDARD 20)
set(default_build_type "Release")
set(CMAKE_CXX_FLAGS "-Wall ${CMAKE_CXX_FLAGS}")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
message(STATUS "Build type is release. Optimization for speed, without debug info.")
add_compile_options(-Ofast -s)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(STATUS "Minimal optimization, debug info included")
add_compile_options(-g)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
add_definitions(-DUSE_DEBUG)
else()
message(FATAL_ERROR "You must set build type \"Debug\" or \"Release\". Another build types not supported!")
endif()
message("{{ project_name }} CXX Flags: " ${CMAKE_CXX_FLAGS})
message("{{ project_name }} CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})
add_library(${PROJECT_NAME} STATIC
include/{{ include_header }}
src/{{ namespace }}.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC include/)
{% if len(examples_names) > 0 %}if ({{ project_name | replace(" ", "_") | upper }}_BUILD_EXAMPLES)
message("Build examples enabled")
{% for ex in examples_names %} add_subdirectory(examples/{{ ex | replace(" ", "-") | lower }})
{% endfor %}endif()
{% endif %}
if ({{ project_name | replace(" ", "_") | upper }}_BUILD_TESTS)
message("Build tests enabled")
add_subdirectory(tests)
endif()