From 93b876dee746f29f2107cb2121ce955dc4ba6a29 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 18 Jun 2019 11:28:17 +1000 Subject: [PATCH] nc: set a variable to point to this directory --- link_flag.cmake | 2 +- nc.cmake | 14 ++++++++++++++ search_libs.cmake | 4 ++-- test_restrict.cmake | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/link_flag.cmake b/link_flag.cmake index 954b299..da890dc 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 - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/test_link_flag.cpp") + "${NC_CMAKE_BASE}/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 6b90ff8..784deda 100644 --- a/nc.cmake +++ b/nc.cmake @@ -13,6 +13,20 @@ 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}) + message (STATUS testing nc_cmake_base at "${d}") + if (EXISTS "${d}/nc.cmake") + set (NC_CMAKE_BASE "${d}") + message (STATUS testing nc_cmake_base at "${d} - found") + break() + else () + message (STATUS testing nc_cmake_base at "${d} - not found") + endif () +endforeach() + include (nc_cxx) include (nc_sanitizer) include (nc_platform) diff --git a/search_libs.cmake b/search_libs.cmake index bf063fe..a662aff 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 - "${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp" + "${NC_CMAKE_BASE}/search_libs.cpp" COMPILE_DEFINITIONS "-DSYMBOL=${_symbol}") @@ -36,7 +36,7 @@ macro(search_libs _variable _symbol) __search_libs_${_symbol} "${CMAKE_BINARY_DIR}/CMakeTmp" SOURCES - "${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp" + "${NC_CMAKE_BASE}/search_libs.cpp" LINK_LIBRARIES "${lib}" COMPILE_DEFINITIONS diff --git a/test_restrict.cmake b/test_restrict.cmake index 243fd92..3ada0eb 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 "${CMAKE_SOURCE_DIR}/cmake/test_restrict.cpp" + SOURCES "${NC_CMAKE_BASE}/test_restrict.cpp" COMPILE_DEFINITIONS "-DKEYWORD=${KEYWORD}") set(__test_restrict_last ${KEYWORD}) ENDIF (NOT TEST_${VARIABLE})