From eb2a9435044ac91442fafc606c5af2f473bff3c5 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 28 Apr 2025 17:06:00 +0100 Subject: [PATCH] cmake: Check user-defined `APPEND_*` variables early This change improves usability in cases where the user provides `APPEND_*` variables that are incompatible with the compiler for some reason. --- cmake/module/EnableLanguage.cmake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmake/module/EnableLanguage.cmake b/cmake/module/EnableLanguage.cmake index 6ba52d6492f..631668deafb 100644 --- a/cmake/module/EnableLanguage.cmake +++ b/cmake/module/EnableLanguage.cmake @@ -27,6 +27,22 @@ macro(bitcoincore_enable_language language) string(APPEND CMAKE_${language}_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS}") string(APPEND CMAKE_${language}_CREATE_SHARED_LIBRARY " ${APPEND_LDFLAGS}") string(APPEND CMAKE_${language}_LINK_EXECUTABLE " ${APPEND_LDFLAGS}") + + # CMake's `enable_language()` command internally checks + # whether the compiler is able to compile a simple test program. + # However, it does not take into consideration the contents + # of the user-defined `APPEND_*FLAGS` variables, because they + # modify CMake's compiler configuration variables, which in turn + # become available only after `enable_language()` is invoked. + # Therefore, we test the compiler again at this point. + include(CheckSourceCompiles) + check_source_compiles("${language}" "int main() { return 0; }" ${language}_COMPILER_WORKS) + if(NOT ${language}_COMPILER_WORKS) + unset(${language}_COMPILER_WORKS CACHE) + message(FATAL_ERROR "The ${language} compiler is not able to compile a simple test program.\n" + "Check that the \"APPEND_*FLAGS\" variables are set correctly.\n\n" + ) + endif() endif() unset(_description) endif()