From 54f0855312e6653aea50bbab06602bb57ba18513 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 15 Jun 2022 10:46:52 +1000 Subject: [PATCH] Use CMAKE_CURRENT_LIST_DIR for local includes to simplify usage This means that we no longer need to modify the module path for CMake before including the root script. --- link_flag.cmake | 2 +- nc.cmake | 24 +++++------------------- nc_cxx.cmake | 8 ++++---- nc_optimisation.cmake | 6 +++--- nc_platform.cmake | 4 ++-- nc_warnings.cmake | 2 +- search_libs.cmake | 4 ++-- test_restrict.cmake | 2 +- 8 files changed, 19 insertions(+), 33 deletions(-) diff --git a/link_flag.cmake b/link_flag.cmake index da890dc..cbd8cdd 100644 --- a/link_flag.cmake +++ b/link_flag.cmake @@ -12,7 +12,7 @@ macro(check_link_flag _variable _flag) __check_link_flag_${_name} "${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp" SOURCES - "${NC_CMAKE_BASE}/test_link_flag.cpp") + "${CMAKE_CURRENT_LIST_DIR}/test_link_flag.cpp") if (__check_link_flag_${_name}) message (STATUS "checking linker flag ${_flag} - found") diff --git a/nc.cmake b/nc.cmake index 9e5128a..4408613 100644 --- a/nc.cmake +++ b/nc.cmake @@ -13,22 +13,8 @@ set (THREADS_PREFER_PTHREAD_FLAG ON) find_package (Threads REQUIRED) link_libraries (Threads::Threads) -# Set the variable NC_CMAKE_BASE to the root path of this collection of cmake -# files so that we can reliably point to soure files contained therein -# (eg, the search_lib.cpp tests and friends). -foreach (d ${CMAKE_MODULE_PATH}) - if (EXISTS "${d}/nc.cmake") - set (NC_CMAKE_BASE "${d}") - break() - endif () -endforeach() - -if (NOT NC_CMAKE_BASE) - message (FATAL_ERROR "Unable to locate the NC CMake directory") -endif () - -include (nc_cxx) -include (nc_sanitizer) -include (nc_platform) -include (nc_optimisation) -include (nc_warnings) +include ("${CMAKE_CURRENT_LIST_DIR}/nc_cxx.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/nc_sanitizer.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/nc_platform.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/nc_optimisation.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/nc_warnings.cmake") diff --git a/nc_cxx.cmake b/nc_cxx.cmake index 4994058..c0b4644 100644 --- a/nc_cxx.cmake +++ b/nc_cxx.cmake @@ -15,9 +15,9 @@ set (CMAKE_C_FLAGS_DEBUG "") ############################################################################### -include (compile_flag) -include (link_flag) -include (test_restrict) +include ("${CMAKE_CURRENT_LIST_DIR}/compile_flag.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/link_flag.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/test_restrict.cmake") ############################################################################### @@ -52,7 +52,7 @@ endif () # try_compile( # __nc_cxx_stdcxxfs ${CMAKE_CURRENT_BINARY_DIR} # SOURCES -# ${NC_CMAKE_BASE}/nc_cxx_stdcxxfs.cpp +# ${CMAKE_CURRENT_LIST_DIR}/nc_cxx_stdcxxfs.cpp # LINK_LIBRARIES # ${lib} # ) diff --git a/nc_optimisation.cmake b/nc_optimisation.cmake index ade173d..4b2e07b 100644 --- a/nc_optimisation.cmake +++ b/nc_optimisation.cmake @@ -7,9 +7,9 @@ set (__nc_optimisation TRUE) ############################################################################### -include (compile_flag) -include (link_flag) -include (canonical_host) +include ("${CMAKE_CURRENT_LIST_DIR}/compile_flag.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/link_flag.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/canonical_host.cmake") ############################################################################### diff --git a/nc_platform.cmake b/nc_platform.cmake index ed320aa..9bb7176 100644 --- a/nc_platform.cmake +++ b/nc_platform.cmake @@ -7,8 +7,8 @@ set (__nc_platform TRUE) ############################################################################### -include (compile_flag) -include (link_flag) +include ("${CMAKE_CURRENT_LIST_DIR}/compile_flag.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/link_flag.cmake") ############################################################################### diff --git a/nc_warnings.cmake b/nc_warnings.cmake index ebb9908..53849ea 100644 --- a/nc_warnings.cmake +++ b/nc_warnings.cmake @@ -7,7 +7,7 @@ set (__nc_warnings TRUE) ############################################################################### -include (compile_flag) +include ("${CMAKE_CURRENT_LIST_DIR}/compile_flag.cmake") ############################################################################### diff --git a/search_libs.cmake b/search_libs.cmake index a662aff..156987e 100644 --- a/search_libs.cmake +++ b/search_libs.cmake @@ -21,7 +21,7 @@ macro(search_libs _variable _symbol) __search_libs_${_symbol} "${CMAKE_BINARY_DIR}/CMakeTmp" SOURCES - "${NC_CMAKE_BASE}/search_libs.cpp" + "${CMAKE_CURRENT_LIST_DIR}/search_libs.cpp" COMPILE_DEFINITIONS "-DSYMBOL=${_symbol}") @@ -36,7 +36,7 @@ macro(search_libs _variable _symbol) __search_libs_${_symbol} "${CMAKE_BINARY_DIR}/CMakeTmp" SOURCES - "${NC_CMAKE_BASE}/search_libs.cpp" + "${CMAKE_CURRENT_LIST_DIR}/search_libs.cpp" LINK_LIBRARIES "${lib}" COMPILE_DEFINITIONS diff --git a/test_restrict.cmake b/test_restrict.cmake index 3ada0eb..bba526e 100644 --- a/test_restrict.cmake +++ b/test_restrict.cmake @@ -6,7 +6,7 @@ macro(test_restrict VARIABLE) TRY_COMPILE( TEST_${VARIABLE} "${CMAKE_BINARY_DIR}/CMakeTmp" - SOURCES "${NC_CMAKE_BASE}/test_restrict.cpp" + SOURCES "${CMAKE_CURRENT_LIST_DIR}/test_restrict.cpp" COMPILE_DEFINITIONS "-DKEYWORD=${KEYWORD}") set(__test_restrict_last ${KEYWORD}) ENDIF (NOT TEST_${VARIABLE})