Merge bitcoin/bitcoin#32027: cmake: Add NO_CACHE_IF_FAILED option for checking linker flags

52ac17757e 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](https://github.com/bitcoin/bitcoin/issues/31942#issuecomment-2703801270) comment from https://github.com/bitcoin/bitcoin/issues/31942.

ACKs for top commit:
  fanquake:
    ACK 52ac17757e

Tree-SHA512: 4004110585413792faa01551cf5a5b3b0de7f213c7a1dd333647107741f84abf626fd0ed067fc17e4c5a523de549432738d3752facf25d1e3dab240be8d13d03
This commit is contained in:
merge-script 2025-03-27 15:44:26 +08:00
commit 140f0d89bf
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1
2 changed files with 6 additions and 1 deletions

View file

@ -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.")

View file

@ -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)