Skip to content

Commit 476d65f

Browse files
committed
enable testing if this is the main project
1 parent e82b5b8 commit 476d65f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

CMakeLists.txt

+14-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,20 @@ add_subdirectory(src/lib)
3535
# ENABLE TESTING
3636
#################################################################
3737

38-
option(BUILD_TESTING "Build the testing tree." OFF)
39-
if(BUILD_TESTING)
40-
include(CTest)
38+
if(${PROJECT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
39+
set(main_project TRUE)
40+
else()
41+
set(main_project FALSE)
42+
endif()
43+
44+
include(CMakeDependentOption)
45+
cmake_dependent_option(BUILD_TESTING_${PROJECT_NAME}
46+
"Build the testing tree for project ${PROJECT_NAME}." OFF
47+
"BUILD_TESTING;NOT main_project" OFF
48+
)
49+
50+
if(main_project OR BUILD_TESTING_${PROJECT_NAME})
51+
enable_testing()
4152
add_subdirectory(src/tests)
4253
endif()
4354

0 commit comments

Comments
 (0)