File tree Expand file tree Collapse file tree 3 files changed +12
-21
lines changed Expand file tree Collapse file tree 3 files changed +12
-21
lines changed Original file line number Diff line number Diff line change @@ -8,22 +8,19 @@ include(cmake/utils.cmake)
88add_library (mylib) # initialized below
99add_library (mylib::mylib ALIAS mylib)
1010
11+ string (COMPARE EQUAL "${CMAKE_SOURCE_DIR} " "${CMAKE_CURRENT_SOURCE_DIR} " is_top_level)
12+
1113#----------------------------------------------------------------------------------------------------------------------
1214# general settings and options
1315#----------------------------------------------------------------------------------------------------------------------
1416
1517include (GNUInstallDirs)
1618
17- if (NOT DEFINED PROJECT_IS_TOP_LEVEL AND "${CMAKE_SOURCE_DIR} " STREQUAL "${CMAKE_CURRENT_SOURCE_DIR} " )
18- # support older CMake versions (prior 3.21) which do not define this variable
19- set (PROJECT_IS_TOP_LEVEL YES )
20- endif ()
21-
2219# MYLIB_SHARED_LIBS option (undefined by default) can be used to force shared/static build
2320option (MYLIB_BUILD_TESTS "Build mylib tests" OFF )
2421option (MYLIB_BUILD_EXAMPLES "Build mylib examples" OFF )
2522option (MYLIB_BUILD_DOCS "Build mylib documentation" OFF )
26- option (MYLIB_INSTALL "Generate target for installing mylib" ${PROJECT_IS_TOP_LEVEL } )
23+ option (MYLIB_INSTALL "Generate target for installing mylib" ${is_top_level } )
2724set_if_undefined(MYLIB_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR} /cmake/mylib-${PROJECT_VERSION} " CACHE
2825 STRING "Install path for mylib package-related CMake files" )
2926
@@ -148,7 +145,7 @@ endif()
148145#----------------------------------------------------------------------------------------------------------------------
149146
150147if (MYLIB_BUILD_TESTS)
151- if (PROJECT_IS_TOP_LEVEL )
148+ if (is_top_level )
152149 enable_testing ()
153150 endif ()
154151
Original file line number Diff line number Diff line change @@ -2,12 +2,9 @@ cmake_minimum_required(VERSION 3.14)
22project (mylib-add LANGUAGES CXX)
33include ("../../cmake/utils.cmake" )
44
5- if (NOT DEFINED PROJECT_IS_TOP_LEVEL AND "${CMAKE_SOURCE_DIR} " STREQUAL "${CMAKE_CURRENT_SOURCE_DIR} " )
6- # support older CMake versions (prior 3.21) which do not define this variable
7- set (PROJECT_IS_TOP_LEVEL YES )
8- endif ()
5+ string (COMPARE EQUAL "${CMAKE_SOURCE_DIR} " "${CMAKE_CURRENT_SOURCE_DIR} " is_top_level)
96
10- if (PROJECT_IS_TOP_LEVEL )
7+ if (is_top_level )
118 find_package (mylib REQUIRED)
129endif ()
1310
@@ -18,6 +15,6 @@ add_executable(mylib-add)
1815target_sources (mylib-add PRIVATE ${sources} )
1916target_link_libraries (mylib-add PRIVATE mylib::mylib)
2017
21- if (NOT PROJECT_IS_TOP_LEVEL )
18+ if (NOT is_top_level )
2219 win_copy_deps_to_target_dir(mylib-add mylib::mylib)
2320endif ()
Original file line number Diff line number Diff line change @@ -2,16 +2,13 @@ cmake_minimum_required(VERSION 3.14)
22project (mylib-tests)
33include ("../cmake/utils.cmake" )
44
5+ string (COMPARE EQUAL "${CMAKE_SOURCE_DIR} " "${CMAKE_CURRENT_SOURCE_DIR} " is_top_level)
6+
57#----------------------------------------------------------------------------------------------------------------------
68# general settings and options
79#----------------------------------------------------------------------------------------------------------------------
810
9- if (NOT DEFINED PROJECT_IS_TOP_LEVEL AND "${CMAKE_SOURCE_DIR} " STREQUAL "${CMAKE_CURRENT_SOURCE_DIR} " )
10- # support older CMake versions (prior 3.21) which do not define this variable
11- set (PROJECT_IS_TOP_LEVEL YES )
12- endif ()
13-
14- if (PROJECT_IS_TOP_LEVEL)
11+ if (is_top_level)
1512 enable_testing ()
1613endif ()
1714
@@ -35,7 +32,7 @@ FetchContent_MakeAvailable(googletest)
3532# tests dependencies
3633#----------------------------------------------------------------------------------------------------------------------
3734
38- if (PROJECT_IS_TOP_LEVEL )
35+ if (is_top_level )
3936 find_package (mylib REQUIRED)
4037endif ()
4138
@@ -59,7 +56,7 @@ target_link_libraries(mylib-tests
5956 mylib::mylib
6057 gtest_main)
6158
62- if (NOT PROJECT_IS_TOP_LEVEL )
59+ if (NOT is_top_level )
6360 win_copy_deps_to_target_dir(mylib-tests mylib::mylib)
6461endif ()
6562
You can’t perform that action at this time.
0 commit comments