From 84bfa4ae2a77a8a7d09bf12a75dcd7ea3e7d5d3d Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 23 Jun 2022 07:26:21 +1000 Subject: [PATCH] Cache CMAKE_CURRENT_LIST_DIR for correct paths in macros --- link_flag.cmake | 4 +++- search_libs.cmake | 5 +++-- test_restrict.cmake | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/link_flag.cmake b/link_flag.cmake index cbd8cdd..474f732 100644 --- a/link_flag.cmake +++ b/link_flag.cmake @@ -1,4 +1,6 @@ ############################################################################### +set(_LINK_FLAG_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}) + macro(check_link_flag _variable _flag) string (MAKE_C_IDENTIFIER ${_flag} _name) @@ -12,7 +14,7 @@ macro(check_link_flag _variable _flag) __check_link_flag_${_name} "${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp" SOURCES - "${CMAKE_CURRENT_LIST_DIR}/test_link_flag.cpp") + "${_LINK_FLAG_LIST_DIR}/test_link_flag.cpp") if (__check_link_flag_${_name}) message (STATUS "checking linker flag ${_flag} - found") diff --git a/search_libs.cmake b/search_libs.cmake index 156987e..1a99a35 100644 --- a/search_libs.cmake +++ b/search_libs.cmake @@ -12,6 +12,7 @@ ## ## Does not work for C++ symbols. +set(_SEARCH_LIBS_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}) macro(search_libs _variable _symbol) if (NOT DEFINED __search_libs_${_symbol}) message (STATUS "searching for ${_symbol}") @@ -21,7 +22,7 @@ macro(search_libs _variable _symbol) __search_libs_${_symbol} "${CMAKE_BINARY_DIR}/CMakeTmp" SOURCES - "${CMAKE_CURRENT_LIST_DIR}/search_libs.cpp" + "${_SEARCH_LIBS_LIST_DIR}/search_libs.cpp" COMPILE_DEFINITIONS "-DSYMBOL=${_symbol}") @@ -36,7 +37,7 @@ macro(search_libs _variable _symbol) __search_libs_${_symbol} "${CMAKE_BINARY_DIR}/CMakeTmp" SOURCES - "${CMAKE_CURRENT_LIST_DIR}/search_libs.cpp" + "${_SEARCH_LIBS_LIST_DIR}/search_libs.cpp" LINK_LIBRARIES "${lib}" COMPILE_DEFINITIONS diff --git a/test_restrict.cmake b/test_restrict.cmake index bba526e..43c66a1 100644 --- a/test_restrict.cmake +++ b/test_restrict.cmake @@ -1,3 +1,5 @@ +set(_TEST_RESTRICT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}) + macro(test_restrict VARIABLE) if (NOT DEFINED TEST_${VARIABLE}) message (STATUS "checking for restrict keyword") @@ -6,7 +8,7 @@ macro(test_restrict VARIABLE) TRY_COMPILE( TEST_${VARIABLE} "${CMAKE_BINARY_DIR}/CMakeTmp" - SOURCES "${CMAKE_CURRENT_LIST_DIR}/test_restrict.cpp" + SOURCES "${_TEST_RESTRICT_LIST_DIR}/test_restrict.cpp" COMPILE_DEFINITIONS "-DKEYWORD=${KEYWORD}") set(__test_restrict_last ${KEYWORD}) ENDIF (NOT TEST_${VARIABLE})