Skip to content

Commit 140f0d8

Browse files
committed
Merge bitcoin/bitcoin#32027: cmake: Add NO_CACHE_IF_FAILED option for checking linker flags
52ac177 cmake: Add `NO_CACHE_IF_FAILED` option for checking linker flags (Hennadii Stepanov) Pull request description: 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. Addresses [this](bitcoin/bitcoin#31942 (comment)) comment from bitcoin/bitcoin#31942. ACKs for top commit: fanquake: ACK 52ac177 Tree-SHA512: 4004110585413792faa01551cf5a5b3b0de7f213c7a1dd333647107741f84abf626fd0ed067fc17e4c5a523de549432738d3752facf25d1e3dab240be8d13d03
2 parents 5dd6ebc + 52ac177 commit 140f0d8

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
@@ -374,6 +374,7 @@ if(SANITIZERS)
374374
int main() { return 0; }
375375
"
376376
RESULT_VAR linker_supports_sanitizers
377+
NO_CACHE_IF_FAILED
377378
)
378379
if(NOT linker_supports_sanitizers)
379380
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)