CMake: Support configure tests of type 'linkerSupportsFlag'

Task-number: QTBUG-86155
Change-Id: I3764d99cd4ad1c432b499ec9ba7c4c48391fa421
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2020-08-21 12:59:24 +02:00
parent 48cf015906
commit 7e7c9ba455
4 changed files with 57 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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