From 81029e04ba3de6507ad871b3e90d03bb5553b93e Mon Sep 17 00:00:00 2001 From: Vladislav Ostapov Date: Thu, 23 Apr 2026 15:22:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=B3?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20cmake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 1 - templates/CMakeLists.txt.jinja | 18 ++++++++++++++---- templates/tests/CMakeLists.txt.jinja | 24 ------------------------ 3 files changed, 14 insertions(+), 29 deletions(-) delete mode 100644 templates/tests/CMakeLists.txt.jinja diff --git a/main.py b/main.py index 0daab4c..9ad8019 100644 --- a/main.py +++ b/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}/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}/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/test-{context['namespace']}.cpp", render_template("tests/test-lib.cpp", context)) diff --git a/templates/CMakeLists.txt.jinja b/templates/CMakeLists.txt.jinja index 63e4a34..7e35299 100644 --- a/templates/CMakeLists.txt.jinja +++ b/templates/CMakeLists.txt.jinja @@ -24,11 +24,13 @@ 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 +set(SRC_CORE + include/{{ include_header }} + src/{{ namespace }}.cpp ) +add_library(${PROJECT_NAME} STATIC ${SRC_CORE}) + target_include_directories(${PROJECT_NAME} PUBLIC include/) {% if len(examples_names) > 0 %}if ({{ project_name | replace(" ", "_") | upper }}_BUILD_EXAMPLES) @@ -38,5 +40,13 @@ target_include_directories(${PROJECT_NAME} PUBLIC include/) {% endif %} if ({{ project_name | replace(" ", "_") | upper }}_BUILD_TESTS) 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() \ No newline at end of file diff --git a/templates/tests/CMakeLists.txt.jinja b/templates/tests/CMakeLists.txt.jinja deleted file mode 100644 index 8f5d4a9..0000000 --- a/templates/tests/CMakeLists.txt.jinja +++ /dev/null @@ -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)