diff options
Diffstat (limited to 'cmake/QtInternalTargets.cmake')
-rw-r--r-- | cmake/QtInternalTargets.cmake | 134 |
1 files changed, 111 insertions, 23 deletions
diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index 9fcdb37b45..d7eadc1a73 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -1,5 +1,5 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +# SPDX-License-Identifier: BSD-3-Clause function(qt_internal_set_warnings_are_errors_flags target target_scope) @@ -48,6 +48,11 @@ function(qt_internal_set_warnings_are_errors_flags target target_scope) if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "11.0.0") # We do mixed enum arithmetic all over the place: list(APPEND flags -Wno-error=deprecated-enum-enum-conversion -Wno-error=deprecated-enum-float-conversion) + + # GCC has some false positive, and it specifically comes through in MINGW + if (MINGW) + list(APPEND flags -Wno-error=stringop-overread) + endif() endif() if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "11.0.0" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "11.2.0") @@ -97,7 +102,7 @@ function(qt_internal_add_global_definition definition) set(optional_args) set(single_value_args VALUE) set(multi_value_args SCOPE) - cmake_parse_arguments(args + cmake_parse_arguments(arg "${optional_args}" "${single_value_args}" "${multi_value_args}" @@ -151,7 +156,12 @@ qt_internal_add_target_aliases(PlatformToolInternal) target_link_libraries(PlatformToolInternal INTERFACE PlatformAppInternal) qt_internal_add_global_definition(QT_NO_JAVA_STYLE_ITERATORS) +qt_internal_add_global_definition(QT_NO_QASCONST) +qt_internal_add_global_definition(QT_NO_QEXCHANGE) qt_internal_add_global_definition(QT_NO_NARROWING_CONVERSIONS_IN_CONNECT) +qt_internal_add_global_definition(QT_EXPLICIT_QFILE_CONSTRUCTION_FROM_PATH) +qt_internal_add_global_definition(QT_USE_QSTRINGBUILDER SCOPE PLUGIN TOOL MODULE) +qt_internal_add_global_definition(QT_NO_FOREACH) if(WARNINGS_ARE_ERRORS) qt_internal_set_warnings_are_errors_flags(PlatformModuleInternal INTERFACE) @@ -162,6 +172,8 @@ if(WIN32) # Needed for M_PI define. Same as mkspecs/features/qt_module.prf. # It's set for every module being built, but it's not propagated to user apps. target_compile_definitions(PlatformModuleInternal INTERFACE _USE_MATH_DEFINES) + # Not disabling min/max macros may result in unintended substitutions of std::min/max + target_compile_definitions(PlatformCommonInternal INTERFACE NOMINMAX) endif() if(FEATURE_largefile AND UNIX) target_compile_definitions(PlatformCommonInternal @@ -199,6 +211,14 @@ function(qt_internal_apply_bitcode_flags target) target_compile_options("${target}" INTERFACE ${bitcode_flags}) endfunction() +# Function guards linker options that are applicable for internal Qt targets only from propagating +# them to user projects. +function(qt_internal_platform_link_options target scope) + set(options ${ARGN}) + set(is_internal_target_genex "$<BOOL:$<TARGET_PROPERTY:_qt_is_internal_target>>") + target_link_options(${target} ${scope} "$<${is_internal_target_genex}:${options}>") +endfunction() + # Apple deprecated the entire OpenGL API in favor of Metal, which # we are aware of, so silence the deprecation warnings in code. # This does not apply to user-code, which will need to silence @@ -209,6 +229,31 @@ elseif(UIKIT) target_compile_definitions(PlatformCommonInternal INTERFACE GLES_SILENCE_DEPRECATION) endif() +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "14.0.0") + # Xcode 14's Clang will emit objc_msgSend stubs by default, which ld + # from earlier Xcode versions will fail to understand when linking + # against static libraries with these stubs. Disable the stubs explicitly, + # for as long as we do support Xcode < 14. + set(is_static_lib "$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>") + set(is_objc "$<COMPILE_LANGUAGE:OBJC,OBJCXX>") + set(is_static_and_objc "$<AND:${is_static_lib},${is_objc}>") + target_compile_options(PlatformCommonInternal INTERFACE + "$<${is_static_and_objc}:-fno-objc-msgsend-selector-stubs>" + ) + endif() + + # A bug in Xcode 15 adds duplicate flags to the linker. In addition, the + # `-warn_duplicate_libraries` is now enabled by default which may result + # in several 'duplicate libraries warning'. + # - https://gitlab.kitware.com/cmake/cmake/-/issues/25297 and + # - https://indiestack.com/2023/10/xcode-15-duplicate-library-linker-warnings/ + set(is_xcode15 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,15>") + set(not_disabled "$<NOT:$<BOOL:$<TARGET_PROPERTY:QT_NO_DISABLE_WARN_DUPLICATE_LIBRARIES>>>") + target_link_options(PlatformCommonInternal INTERFACE + "$<$<AND:${not_disabled},${is_xcode15}>:LINKER:-no_warn_duplicate_libraries>") +endif() + if(MSVC) target_compile_definitions(PlatformCommonInternal INTERFACE "_CRT_SECURE_NO_WARNINGS" @@ -221,7 +266,7 @@ if(WASM AND QT_FEATURE_sse2) endif() # Taken from mkspecs/common/msvc-version.conf and mkspecs/common/msvc-desktop.conf -if (MSVC) +if (MSVC AND NOT CLANG) if (MSVC_VERSION GREATER_EQUAL 1799) target_compile_options(PlatformCommonInternal INTERFACE -FS @@ -232,21 +277,20 @@ if (MSVC) if (MSVC_VERSION GREATER_EQUAL 1899) target_compile_options(PlatformCommonInternal INTERFACE -Zc:strictStrings + -Zc:throwingNew ) - if (NOT CLANG) - target_compile_options(PlatformCommonInternal INTERFACE - -Zc:throwingNew - ) - endif() endif() - if (MSVC_VERSION GREATER_EQUAL 1909 AND NOT CLANG) + if (MSVC_VERSION GREATER_EQUAL 1909) # MSVC 2017 target_compile_options(PlatformCommonInternal INTERFACE -Zc:referenceBinding + -Zc:ternary ) endif() - if (MSVC_VERSION GREATER_EQUAL 1919 AND NOT CLANG) + if (MSVC_VERSION GREATER_EQUAL 1919) # MSVC 2019 target_compile_options(PlatformCommonInternal INTERFACE -Zc:externConstexpr + #-Zc:lambda # Buggy. TODO: Enable again when stable enough. + #-Zc:preprocessor # breaks build due to bug in default Windows SDK 10.0.19041 ) endif() @@ -259,7 +303,7 @@ if (MSVC) $<$<NOT:$<CONFIG:Debug>>:-guard:cf -Gw> ) - target_link_options(PlatformCommonInternal INTERFACE + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE -DYNAMICBASE -NXCOMPAT -LARGEADDRESSAWARE $<$<NOT:$<CONFIG:Debug>>:-OPT:REF -OPT:ICF -GUARD:CF> ) @@ -273,18 +317,52 @@ if (GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "9.2") target_compile_options(PlatformCommonInternal INTERFACE $<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-override>) endif() +# Hardening options if(QT_FEATURE_intelcet) if(MSVC) - target_link_options(PlatformCommonInternal INTERFACE - -CETCOMPAT - ) + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE -CETCOMPAT) else() - target_compile_options(PlatformCommonInternal INTERFACE - -fcf-protection=full - ) + target_compile_options(PlatformCommonInternal INTERFACE -fcf-protection=full) endif() endif() +if(QT_FEATURE_glibc_fortify_source) + set(is_optimized_build "$<OR:$<NOT:$<CONFIG:Debug>>,$<BOOL:${QT_FEATURE_optimize_debug}>>") + # Some compilers may define _FORTIFY_SOURCE by default when optimizing, remove it + # before defining our own + target_compile_options(PlatformCommonInternal BEFORE INTERFACE "$<${is_optimized_build}:-U_FORTIFY_SOURCE>") + if(TEST_glibc_234) + target_compile_options(PlatformCommonInternal INTERFACE "$<${is_optimized_build}:-D_FORTIFY_SOURCE=3>") + else() + target_compile_options(PlatformCommonInternal INTERFACE "$<${is_optimized_build}:-D_FORTIFY_SOURCE=2>") + endif() +endif() + +if(QT_FEATURE_trivial_auto_var_init_pattern) + target_compile_options(PlatformCommonInternal INTERFACE -ftrivial-auto-var-init=pattern) +endif() + +if(QT_FEATURE_stack_protector) + target_compile_options(PlatformCommonInternal INTERFACE -fstack-protector-strong) +endif() + +if(QT_FEATURE_stack_clash_protection) + target_compile_options(PlatformCommonInternal INTERFACE -fstack-clash-protection) +endif() + +if(QT_FEATURE_libstdcpp_assertions) + target_compile_definitions(PlatformCommonInternal INTERFACE _GLIBCXX_ASSERTIONS) +endif() + +if(QT_FEATURE_libcpp_hardening) + target_compile_definitions(PlatformCommonInternal INTERFACE -D_LIBCPP_HARDENING_MODE=$<IF:$<CONFIG:Debug>,_LIBCPP_HARDENING_MODE_EXTENSIVE,_LIBCPP_HARDENING_MODE_FAST>) +endif() + +if(QT_FEATURE_relro_now_linker) + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE "-Wl,-z,relro,-z,now") +endif() + + if(QT_FEATURE_force_asserts) target_compile_definitions(PlatformCommonInternal INTERFACE QT_FORCE_ASSERTS) endif() @@ -304,30 +382,40 @@ endif() if(DEFINED QT_EXTRA_FRAMEWORKPATHS AND APPLE) list(TRANSFORM QT_EXTRA_FRAMEWORKPATHS PREPEND "-F" OUTPUT_VARIABLE __qt_fw_flags) target_compile_options(PlatformCommonInternal INTERFACE ${__qt_fw_flags}) - target_link_options(PlatformCommonInternal INTERFACE ${__qt_fw_flags}) + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE ${__qt_fw_flags}) unset(__qt_fw_flags) endif() qt_internal_get_active_linker_flags(__qt_internal_active_linker_flags) if(__qt_internal_active_linker_flags) - target_link_options(PlatformCommonInternal INTERFACE "${__qt_internal_active_linker_flags}") + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE + "${__qt_internal_active_linker_flags}") endif() unset(__qt_internal_active_linker_flags) if(QT_FEATURE_enable_gdb_index) - target_link_options(PlatformCommonInternal INTERFACE "-Wl,--gdb-index") + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE "-Wl,--gdb-index") endif() if(QT_FEATURE_enable_new_dtags) - target_link_options(PlatformCommonInternal INTERFACE "-Wl,--enable-new-dtags") + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE "-Wl,--enable-new-dtags") endif() +function(qt_internal_apply_coverage_flags) + if(QT_FEATURE_coverage_gcov) + target_compile_options(PlatformCommonInternal INTERFACE + "$<$<CONFIG:Debug>:--coverage>") + target_link_options(PlatformCommonInternal INTERFACE "$<$<CONFIG:Debug>:--coverage>") + endif() +endfunction() +qt_internal_apply_coverage_flags() + function(qt_get_implicit_sse2_genex_condition out_var) set(is_shared_lib "$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>") set(is_static_lib "$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>") set(is_static_qt_build "$<NOT:$<BOOL:${QT_BUILD_SHARED_LIBS}>>") - set(is_staitc_lib_during_static_qt_build "$<AND:${is_static_qt_build},${is_static_lib}>") - set(enable_sse2_condition "$<OR:${is_shared_lib},${is_staitc_lib_during_static_qt_build}>") + set(is_static_lib_during_static_qt_build "$<AND:${is_static_qt_build},${is_static_lib}>") + set(enable_sse2_condition "$<OR:${is_shared_lib},${is_static_lib_during_static_qt_build}>") set(${out_var} "${enable_sse2_condition}" PARENT_SCOPE) endfunction() |