Skip to content

Commit 52ac177

Browse files
committed
cmake: Add NO_CACHE_IF_FAILED option for checking linker flags
Use it for checking `-fsanitize`. This change improves the user experience when the configuration step fails due to a missing library. Now, there is no need to manually clean the CMake cache after installing the required library.
1 parent 4571939 commit 52ac177

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ if(SANITIZERS)
376376
int main() { return 0; }
377377
"
378378
RESULT_VAR linker_supports_sanitizers
379+
NO_CACHE_IF_FAILED
379380
)
380381
if(NOT linker_supports_sanitizers)
381382
message(FATAL_ERROR "Linker did not accept requested flags, you are missing required libraries.")

cmake/module/TryAppendLinkerFlag.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ In configuration output, this function prints a string by the following pattern:
2020
function(try_append_linker_flag flag)
2121
cmake_parse_arguments(PARSE_ARGV 1
2222
TALF # prefix
23-
"" # options
23+
"NO_CACHE_IF_FAILED" # options
2424
"TARGET;VAR;SOURCE;RESULT_VAR" # one_value_keywords
2525
"IF_CHECK_PASSED" # multi_value_keywords
2626
)
@@ -68,6 +68,10 @@ function(try_append_linker_flag flag)
6868
if(DEFINED TALF_RESULT_VAR)
6969
set(${TALF_RESULT_VAR} "${${result}}" PARENT_SCOPE)
7070
endif()
71+
72+
if(NOT ${result} AND TALF_NO_CACHE_IF_FAILED)
73+
unset(${result} CACHE)
74+
endif()
7175
endfunction()
7276

7377
if(MSVC)

0 commit comments

Comments
 (0)