From a63333820901028df972f741a618816055241b36 Mon Sep 17 00:00:00 2001 From: Lukas Senionis Date: Fri, 9 Aug 2024 16:39:53 +0300 Subject: [PATCH 1/3] fix: build tests and docs only if main project --- CMakeLists.txt | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52567ba..c59068b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,14 +20,9 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") # # Project optional configuration # -option(BUILD_DOCS "Build documentation" ON) -option(BUILD_TESTS "Build tests" ON) - -# -# Documentation -# -if(BUILD_DOCS) - add_subdirectory(third-party/doxyconfig docs) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + option(BUILD_DOCS "Build documentation" ON) + option(BUILD_TESTS "Build tests" ON) endif() # Generate 'compile_commands.json' for clang_complete @@ -107,7 +102,25 @@ target_compile_options(${PROJECT_NAME} PRIVATE ${TRAY_COMPILE_OPTIONS}) target_link_directories(${PROJECT_NAME} PRIVATE ${TRAY_EXTERNAL_DIRECTORIES}) target_link_libraries(${PROJECT_NAME} PRIVATE ${TRAY_EXTERNAL_LIBRARIES}) -# tests -if(BUILD_TESTS) - add_subdirectory(tests) +# +# Testing and documentation are only available if this is the main project +# +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + if(BUILD_DOCS) + add_subdirectory(third-party/doxyconfig docs) + endif() + + if(BUILD_TESTS) + # + # Additional setup for coverage + # https://gcovr.com/en/stable/guide/compiling.html#compiler-options + # + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage -O0") + set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage -O0") + endif() + + enable_testing() + add_subdirectory(tests) + endif() endif() From 42a455034ff595f1bfae19c0b5d96db7f1f591a7 Mon Sep 17 00:00:00 2001 From: Lukas Senionis Date: Fri, 9 Aug 2024 16:43:02 +0300 Subject: [PATCH 2/3] Update CMakeLists.txt --- tests/CMakeLists.txt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e8f8bd3..4474708 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,8 +5,6 @@ project(test_tray) include_directories("${CMAKE_SOURCE_DIR}") -enable_testing() - # Add GoogleTest directory to the project set(GTEST_SOURCE_DIR "${CMAKE_SOURCE_DIR}/third-party/googletest") set(INSTALL_GTEST OFF) @@ -14,11 +12,6 @@ set(INSTALL_GMOCK OFF) add_subdirectory("${GTEST_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/googletest") include_directories("${GTEST_SOURCE_DIR}/googletest/include" "${GTEST_SOURCE_DIR}") -# coverage -# https://gcovr.com/en/stable/guide/compiling.html#compiler-options -set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage -ggdb -O0") -set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage -ggdb -O0") - # if windows if (WIN32) # For Windows: Prevent overriding the parent project's compiler/linker settings From 477dc90412a09b18fc0f18b2afd4057899c04422 Mon Sep 17 00:00:00 2001 From: Lukas Senionis Date: Fri, 9 Aug 2024 17:07:48 +0300 Subject: [PATCH 3/3] Update CMakeLists.txt --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c59068b..7b3712b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,8 +116,8 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) # https://gcovr.com/en/stable/guide/compiling.html#compiler-options # if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage -O0") - set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage -O0") + set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage -ggdb -O0") + set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage -ggdb -O0") endif() enable_testing()