From fdaef7a50cfc7342b99577cec124f1a93c003bdd Mon Sep 17 00:00:00 2001 From: Thijs Paelman Date: Thu, 6 Nov 2025 01:18:12 +0100 Subject: build: Only enable tests for the project itself Only enable testing when this project itself is build, not when it is included in another project, hence the extra CMAKE_PROJECT_NAME condition. https://cliutils.gitlab.io/modern-cmake/chapters/testing.html Signed-off-by: Thijs Paelman Signed-off-by: Sander Vrijders --- CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index cd2bffee..b5632ad9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,9 +180,12 @@ else () endif() include(CTest) # Sets BUILD_TESTING by default to on. -# BUILD_TESTS: control if tests are included by CMAKE. -# Can depend on more than only BUILD_TESTING in the future. -set(BUILD_TESTS ${BUILD_TESTING}) +# BUILD_TESTS: control if tests are included by CMAKE for this project. +if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) + set(BUILD_TESTS ON) +else () + set(BUILD_TESTS OFF) +endif() add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) find_package(ProtobufC QUIET) -- cgit v1.2.3