For the purpose of checks performed by the build system, we strive to handle user-defined APPEND_*FLAGS in the same way as flags provided by other standard means. In particular, they are considered when the try_compile() command is used.
However, these flags are not considered during enable_language() command invocation due to design limitations, which might cause issues, such as #32323.
This PR addresses the issue by introducing an additional compiler check that does consider the user-defined APPEND_*FLAGS.
Fixes #32323:
$ cmake -B build -DAPPEND_CXXFLAGS="-ftrivial-auto-var-init"
-- The CXX compiler identification is GNU 14.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CXX_COMPILER_WORKS
-- Performing Test CXX_COMPILER_WORKS - Failed
CMake Error at cmake/module/EnableLanguage.cmake:42 (message):
The CXX compiler is not able to compile a simple test program.
Check that the "APPEND_*FLAGS" variables are set correctly.
Call Stack (most recent call first):
CMakeLists.txt:71 (bitcoincore_enable_language)
-- Configuring incomplete, errors occurred!
hebasto@TS-P340:~/dev/bitcoin$ cmake -B build -DAPPEND_CXXFLAGS="-ftrivial-auto-var-init=zero"
-- Performing Test CXX_COMPILER_WORKS
-- Performing Test CXX_COMPILER_WORKS - Success
...