diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index 5002a53352..66242548ed 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -881,6 +881,34 @@ function(qt_config_compiler_supports_flag_test name) set(TEST_${name} "${TEST_${name}}" CACHE INTERNAL "${label}") endfunction() +function(qt_config_linker_supports_flag_test name) + if(DEFINED "TEST_${name}") + return() + endif() + + cmake_parse_arguments(arg "" "LABEL;FLAG" "" ${ARGN}) + set(flags "-Wl,${arg_FLAG}") + + # Select the right linker. + if(GCC OR CLANG) + # TODO: This works for now but is... suboptimal. Once + # QTBUG-86186 is resolved, we should check the *features* + # QT_FEATURE_use_gold_linker etc. instead of trying to + # replicate the feature conditions. + if(QT_FEATURE_use_gold_linker_alias OR INPUT_linker STREQUAL "gold") + list(PREPEND flags "-fuse-ld=gold") + elseif(INPUT_linker STREQUAL "bfd") + list(PREPEND flags "-fuse-ld=bfd") + elseif(INPUT_linker STREQUAL "lld") + list(PREPEND flags "-fuse-ld=lld") + endif() + endif() + + set(CMAKE_REQUIRED_LINK_OPTIONS ${flags}) + check_cxx_source_compiles("int main() { return 0; }" TEST_${name}) + set(TEST_${name} "${TEST_${name}}" CACHE INTERNAL "${label}") +endfunction() + function(qt_make_features_available target) if(NOT "${target}" MATCHES "^${QT_CMAKE_EXPORT_NAMESPACE}::[a-zA-Z0-9_-]*$") message(FATAL_ERROR "${target} does not match ${QT_CMAKE_EXPORT_NAMESPACE}::[a-zA-Z0-9_-]*. INVALID NAME.") diff --git a/cmake/QtProcessConfigureArgs.cmake b/cmake/QtProcessConfigureArgs.cmake index 7e3f789a7c..5e8e2677e7 100644 --- a/cmake/QtProcessConfigureArgs.cmake +++ b/cmake/QtProcessConfigureArgs.cmake @@ -97,6 +97,7 @@ defstub(qt_config_compile_test) defstub(qt_config_compile_test_machine_tuple) defstub(qt_config_compile_test_x86simd) defstub(qt_config_compiler_supports_flag_test) +defstub(qt_config_linker_supports_flag_test) defstub(qt_configure_add_report_entry) defstub(qt_configure_add_summary_build_mode) defstub(qt_configure_add_summary_build_parts) diff --git a/configure.cmake b/configure.cmake index f6863d01fe..e4b632f0db 100644 --- a/configure.cmake +++ b/configure.cmake @@ -130,6 +130,16 @@ qt_config_compiler_supports_flag_test(optimize_debug FLAG "-Og" ) +qt_config_linker_supports_flag_test(enable_new_dtags + LABEL "new dtags support" + FLAG "--enable-new-dtags" +) + +qt_config_linker_supports_flag_test(gdb_index + LABEL "gdb index support" + FLAG "--gdb-index" +) + # reduce_relocations qt_config_compile_test(reduce_relocations LABEL "-Bsymbolic-functions support" diff --git a/util/cmake/configurejson2cmake.py b/util/cmake/configurejson2cmake.py index ffe2dd11b7..8b74cf53cb 100755 --- a/util/cmake/configurejson2cmake.py +++ b/util/cmake/configurejson2cmake.py @@ -777,6 +777,14 @@ def write_compiler_supports_flag_test( cm_fh.write(lineify("FLAG", data.get("flag", ""))) cm_fh.write(")\n\n") +def write_linker_supports_flag_test( + ctx, name, details, data, cm_fh, manual_library_list=None, is_library_test=False +): + cm_fh.write(f"qt_config_linker_supports_flag_test({featureName(name)}\n") + cm_fh.write(lineify("LABEL", data.get("label", ""))) + cm_fh.write(lineify("FLAG", data.get("flag", ""))) + cm_fh.write(")\n\n") + def parseTest(ctx, test, data, cm_fh): skip_tests = { "c11", @@ -814,6 +822,16 @@ def parseTest(ctx, test, data, cm_fh): write_compiler_supports_flag_test(ctx, test, details, data, cm_fh) + if data["type"] == "linkerSupportsFlag": + knownTests.add(test) + + if "test" in data: + details = data["test"] + else: + details = test + + write_linker_supports_flag_test(ctx, test, details, data, cm_fh) + elif data["type"] == "libclang": knownTests.add(test)