diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index de9606c0100..9cffa58229e 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -1601,17 +1601,9 @@ function(qt_run_config_compile_test name) set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") set(CMAKE_REQUIRED_LIBRARIES "${arg_LIBRARIES}") - # OUTPUT_VARIABLE is an internal undocumented variable of check_cxx_source_compiles - # since 3.23. Allow an opt out in case this breaks in the future. - set(try_compile_output "") - set(output_var "") - if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.23" - AND NOT QT_INTERNAL_NO_TRY_COMPILE_OUTPUT_VARIABLE) - set(output_var OUTPUT_VARIABLE try_compile_output) - endif() - + _qt_internal_get_check_cxx_source_compiles_out_var(try_compile_output extra_args) check_cxx_source_compiles( - "${arg_UNPARSED_ARGUMENTS} ${arg_CODE}" HAVE_${name} ${output_var} + "${arg_UNPARSED_ARGUMENTS} ${arg_CODE}" HAVE_${name} ${extra_args} ) set(CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}") diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index 4e99a9a6ead..1747e7c7197 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -166,13 +166,15 @@ function(qt_internal_add_link_flags_no_undefined target) set(previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,-undefined,error") - check_cxx_source_compiles("int main() {}" HAVE_DASH_UNDEFINED_SYMBOLS) + _qt_internal_get_check_cxx_source_compiles_out_var(test_output_undefined_error extra_args) + check_cxx_source_compiles("int main() {}" HAVE_DASH_UNDEFINED_SYMBOLS ${extra_args}) if(HAVE_DASH_UNDEFINED_SYMBOLS) set(no_undefined_flag "-Wl,-undefined,error") endif() set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--no-undefined") - check_cxx_source_compiles("int main() {}" HAVE_DASH_DASH_NO_UNDEFINED) + _qt_internal_get_check_cxx_source_compiles_out_var(test_output_no_undefined extra_args) + check_cxx_source_compiles("int main() {}" HAVE_DASH_DASH_NO_UNDEFINED ${extra_args}) if(HAVE_DASH_DASH_NO_UNDEFINED) set(no_undefined_flag "-Wl,--no-undefined") endif() @@ -180,7 +182,10 @@ function(qt_internal_add_link_flags_no_undefined target) set(CMAKE_REQUIRED_LINK_OPTIONS ${previous_CMAKE_REQUIRED_LINK_OPTIONS}) if (NOT HAVE_DASH_UNDEFINED_SYMBOLS AND NOT HAVE_DASH_DASH_NO_UNDEFINED) - message(FATAL_ERROR "Platform linker doesn't support erroring upon encountering undefined symbols. Target:\"${target}\".") + message(FATAL_ERROR + "Platform linker doesn't support erroring upon encountering undefined symbols. " + "Target:\"${target}\". " + "Test errors: \n ${test_output_undefined_error} \n ${test_output_no_undefined}") endif() target_link_options("${target}" PRIVATE "${no_undefined_flag}") endif() diff --git a/cmake/QtPublicCMakeHelpers.cmake b/cmake/QtPublicCMakeHelpers.cmake index 7ba9f6f6ad1..43c744905f0 100644 --- a/cmake/QtPublicCMakeHelpers.cmake +++ b/cmake/QtPublicCMakeHelpers.cmake @@ -174,6 +174,21 @@ function(__qt_internal_prefix_paths_to_roots out_var prefix_paths) set("${out_var}" "${result}" PARENT_SCOPE) endfunction() +function(_qt_internal_get_check_cxx_source_compiles_out_var out_output_var out_func_args) + # This just resets the output var in the parent scope to an empty string. + set(${out_output_var} "" PARENT_SCOPE) + + # OUTPUT_VARIABLE is an internal undocumented variable of check_cxx_source_compiles + # since 3.23. Allow an opt out in case this breaks in the future. + set(extra_func_args "") + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.23" + AND NOT QT_INTERNAL_NO_TRY_COMPILE_OUTPUT_VARIABLE) + set(extra_func_args OUTPUT_VARIABLE ${out_output_var}) + endif() + + set(${out_func_args} "${extra_func_args}" PARENT_SCOPE) +endfunction() + # This function gets all targets below this directory # # Multi-value Arguments: