diff --git a/CMakeLists.txt b/CMakeLists.txt index de11a4d3e0c..bbcedcec2d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -374,6 +374,7 @@ if(SANITIZERS) int main() { return 0; } " RESULT_VAR linker_supports_sanitizers + NO_CACHE_IF_FAILED ) if(NOT linker_supports_sanitizers) message(FATAL_ERROR "Linker did not accept requested flags, you are missing required libraries.") diff --git a/cmake/module/TryAppendLinkerFlag.cmake b/cmake/module/TryAppendLinkerFlag.cmake index be41a2e1cc2..fe7c2bce51e 100644 --- a/cmake/module/TryAppendLinkerFlag.cmake +++ b/cmake/module/TryAppendLinkerFlag.cmake @@ -20,7 +20,7 @@ In configuration output, this function prints a string by the following pattern: function(try_append_linker_flag flag) cmake_parse_arguments(PARSE_ARGV 1 TALF # prefix - "" # options + "NO_CACHE_IF_FAILED" # options "TARGET;VAR;SOURCE;RESULT_VAR" # one_value_keywords "IF_CHECK_PASSED" # multi_value_keywords ) @@ -68,6 +68,10 @@ function(try_append_linker_flag flag) if(DEFINED TALF_RESULT_VAR) set(${TALF_RESULT_VAR} "${${result}}" PARENT_SCOPE) endif() + + if(NOT ${result} AND TALF_NO_CACHE_IF_FAILED) + unset(${result} CACHE) + endif() endfunction() if(MSVC)