более современная генерация cmake
This commit is contained in:
1
main.py
1
main.py
@@ -42,7 +42,6 @@ def create_all(libname, libpath, examples):
|
|||||||
write_file(f"{libpath}/CMakeLists.txt", render_template("CMakeLists.txt", context))
|
write_file(f"{libpath}/CMakeLists.txt", render_template("CMakeLists.txt", context))
|
||||||
write_file(f"{libpath}/include/{context['include_header']}", render_template("include/lib/lib.h", context))
|
write_file(f"{libpath}/include/{context['include_header']}", render_template("include/lib/lib.h", context))
|
||||||
write_file(f"{libpath}/src/{context['namespace']}.cpp", render_template("src/lib.cpp", context))
|
write_file(f"{libpath}/src/{context['namespace']}.cpp", render_template("src/lib.cpp", context))
|
||||||
write_file(f"{libpath}/tests/CMakeLists.txt", render_template("tests/CMakeLists.txt", context))
|
|
||||||
write_file(f"{libpath}/tests/main.cpp", render_template("tests/main.cpp", context))
|
write_file(f"{libpath}/tests/main.cpp", render_template("tests/main.cpp", context))
|
||||||
write_file(f"{libpath}/tests/test-{context['namespace']}.cpp", render_template("tests/test-lib.cpp", context))
|
write_file(f"{libpath}/tests/test-{context['namespace']}.cpp", render_template("tests/test-lib.cpp", context))
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,13 @@ endif()
|
|||||||
message("{{ project_name }} CXX Flags: " ${CMAKE_CXX_FLAGS})
|
message("{{ project_name }} CXX Flags: " ${CMAKE_CXX_FLAGS})
|
||||||
message("{{ project_name }} CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})
|
message("{{ project_name }} CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} STATIC
|
set(SRC_CORE
|
||||||
include/{{ include_header }}
|
include/{{ include_header }}
|
||||||
src/{{ namespace }}.cpp
|
src/{{ namespace }}.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} STATIC ${SRC_CORE})
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC include/)
|
target_include_directories(${PROJECT_NAME} PUBLIC include/)
|
||||||
|
|
||||||
{% if len(examples_names) > 0 %}if ({{ project_name | replace(" ", "_") | upper }}_BUILD_EXAMPLES)
|
{% if len(examples_names) > 0 %}if ({{ project_name | replace(" ", "_") | upper }}_BUILD_EXAMPLES)
|
||||||
@@ -38,5 +40,13 @@ target_include_directories(${PROJECT_NAME} PUBLIC include/)
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
if ({{ project_name | replace(" ", "_") | upper }}_BUILD_TESTS)
|
if ({{ project_name | replace(" ", "_") | upper }}_BUILD_TESTS)
|
||||||
message("Build tests enabled")
|
message("Build tests enabled")
|
||||||
add_subdirectory(tests)
|
|
||||||
|
find_package(GTest REQUIRED)
|
||||||
|
add_executable(${PROJECT_NAME}-tests
|
||||||
|
tests/main.cpp
|
||||||
|
tests/test-{{ namespace }}.cpp
|
||||||
|
${SRC_CORE}
|
||||||
|
)
|
||||||
|
target_link_libraries(${PROJECT_NAME}-tests GTest::gtest)
|
||||||
|
target_include_directories(${PROJECT_NAME}-tests PRIVATE src include)
|
||||||
endif()
|
endif()
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
project({{ project_name_cmake }}-tests)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
|
||||||
|
|
||||||
find_package(GTest REQUIRED)
|
|
||||||
|
|
||||||
set(default_build_type "Release")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0") # -fprofile-arcs -ftest-coverage
|
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -s")
|
|
||||||
|
|
||||||
message(${CMAKE_CXX_FLAGS})
|
|
||||||
|
|
||||||
include_directories(../include)
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
|
||||||
main.cpp
|
|
||||||
test-{{ namespace }}.cpp
|
|
||||||
../include/{{ include_header }}
|
|
||||||
../src/{{ namespace }}.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} GTest::gtest)
|
|
||||||
Reference in New Issue
Block a user