summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtFlagHandlingHelpers.cmake84
-rw-r--r--cmake/QtModuleHelpers.cmake8
-rw-r--r--cmake/QtPublicAndroidHelpers.cmake2
-rw-r--r--cmake/QtTargetHelpers.cmake58
-rw-r--r--cmake/QtToolHelpers.cmake3
5 files changed, 147 insertions, 8 deletions
diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake
index b32acc4cfa3..8d616cebd2c 100644
--- a/cmake/QtFlagHandlingHelpers.cmake
+++ b/cmake/QtFlagHandlingHelpers.cmake
@@ -1495,3 +1495,87 @@ function(qt_internal_set_up_config_optimizations_like_in_qmake)
"${target_link_types}")
endif()
endfunction()
+
+# Adds optimized flags to targets created in the calling directory scope.
+# This is the only way to add release flags in a debug build, which would build successfully.
+# The approach of just appending -O3, and thus overriding any previous -O0 works on GCC / Clang
+# but not MSVC, because MSVC has other debug flags which are not compatible when -Ox optimizations
+# are turned on.
+function(qt_internal_add_optimized_flags_for_debug_config_in_current_scope)
+ qt_internal_remove_known_optimization_flags(CONFIGS DEBUG)
+
+ # Remove incompatible Windows debug flags with release flags.
+ if(MSVC)
+ set(default_debug_flags_to_remove "/RTC1")
+
+ qt_internal_get_enabled_languages_for_flag_manipulation(enabled_languages)
+ foreach(lang ${enabled_languages})
+ set(flag_var_name "CMAKE_${lang}_FLAGS_DEBUG")
+ qt_internal_remove_flags_impl(${flag_var_name} "${default_debug_flags_to_remove}" "")
+ endforeach()
+ endif()
+
+ qt_internal_get_optimize_full_flags(optimize_full_flags)
+ qt_internal_add_compiler_flags(FLAGS "${optimize_full_flags}" CONFIGS DEBUG)
+
+ # Set the flags in the parent scope. This will apply the flags to all targets within
+ # that directory scope.
+ qt_internal_set_optimized_flags_for_debug_config_in_parent_scope()
+endfunction()
+
+# Conditionally adds optimized flags to the calling directory scope, depending on whether
+# the QT_FEATURE_optimized_tools is ON, and whether a target or project specific override was not
+# set.
+# Overrides can be set via:
+# -DQT_FORCE_NO_OPTIMIZE_<target>=ON
+# -DQT_FORCE_NO_OPTIMIZE_<project_name>=ON
+# e.g -DQT_FORCE_NO_OPTIMIZE_moc=ON -DQT_FORCE_NO_OPTIMIZE_qtdeclarative=ON
+function(qt_internal_add_target_optimized_flags_for_debug_config_in_current_scope target)
+ set(opt_args "")
+ set(single_args
+ OUT_VAR_DID_ADD
+ )
+ set(multi_args "")
+
+ cmake_parse_arguments(PARSE_ARGV 1 arg "${opt_args}" "${single_args}" "${multi_args}")
+ _qt_internal_validate_all_args_are_parsed(arg)
+
+ string(TOLOWER "${PROJECT_NAME}" project_name_lower)
+
+ if(QT_FEATURE_optimized_tools
+ AND NOT QT_FORCE_NO_OPTIMIZE_${target}
+ AND NOT QT_FORCE_NO_OPTIMIZE_${project_name_lower}
+ )
+ qt_internal_add_optimized_flags_for_debug_config_in_current_scope()
+ qt_internal_set_optimized_flags_for_debug_config_in_parent_scope()
+ set(did_add TRUE)
+ else()
+ set(did_add FALSE)
+ endif()
+
+ if(arg_OUT_VAR_DID_ADD)
+ set(${arg_OUT_VAR_DID_ADD} "${did_add}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+# Helper to propagate the optimized flags for the debug config to the parent scope.
+macro(qt_internal_set_optimized_flags_for_debug_config_in_parent_scope)
+ qt_internal_get_enabled_languages_for_flag_manipulation(__qt_internal_debug_enabled_languages)
+ foreach(__qt_internal_debug_lang IN LISTS __qt_internal_debug_enabled_languages)
+ set(flag_var_name "CMAKE_${__qt_internal_debug_lang}_FLAGS_DEBUG")
+ set(${flag_var_name} "${${flag_var_name}}" PARENT_SCOPE)
+ endforeach()
+ unset(__qt_internal_debug_lang)
+ unset(__qt_internal_debug_enabled_languages)
+endmacro()
+
+# Same as qt_internal_add_target_optimized_flags_for_debug_config_in_current_scope, but also
+# propagates the optimized flags to the parent scope.
+macro(qt_internal_add_target_optimized_flags_for_debug_config_in_parent_scope target)
+ qt_internal_add_target_optimized_flags_for_debug_config_in_current_scope("${target}"
+ OUT_VAR_DID_ADD __qt_internal_did_add_optimized_flag_in_current_scope)
+ if(__qt_internal_did_add_optimized_flag_in_current_scope)
+ qt_internal_set_optimized_flags_for_debug_config_in_parent_scope()
+ endif()
+ unset(__qt_internal_did_add_optimized_flag_in_current_scope)
+endmacro()
diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake
index b8c9914aba5..358cdadc59c 100644
--- a/cmake/QtModuleHelpers.cmake
+++ b/cmake/QtModuleHelpers.cmake
@@ -326,13 +326,7 @@ function(qt_internal_add_module target)
endif()
endif()
- if((FEATURE_ltcg OR CMAKE_INTERPROCEDURAL_OPTIMIZATION) AND GCC AND is_static_lib)
- # CMake <= 3.19 appends -fno-fat-lto-objects for all library types if
- # CMAKE_INTERPROCEDURAL_OPTIMIZATION is enabled. Static libraries need
- # the opposite compiler option.
- # (https://gitlab.kitware.com/cmake/cmake/-/issues/21696)
- target_compile_options(${target} PRIVATE -ffat-lto-objects)
- endif()
+ qt_internal_workaround_static_lib_gcc_lto_issue("${target}")
qt_internal_add_target_aliases("${target}")
diff --git a/cmake/QtPublicAndroidHelpers.cmake b/cmake/QtPublicAndroidHelpers.cmake
index 30ffec43ad8..dbaf01f0359 100644
--- a/cmake/QtPublicAndroidHelpers.cmake
+++ b/cmake/QtPublicAndroidHelpers.cmake
@@ -67,7 +67,7 @@ function(_qt_internal_locate_android_jar)
# This variable specifies the API level used for building Java code, it can be the same as Qt
# for Android's maximum supported Android version or higher.
if(NOT QT_ANDROID_API_USED_FOR_JAVA)
- set(QT_ANDROID_API_USED_FOR_JAVA "android-35")
+ set(QT_ANDROID_API_USED_FOR_JAVA "android-36")
endif()
set(jar_location "${ANDROID_SDK_ROOT}/platforms/${QT_ANDROID_API_USED_FOR_JAVA}/android.jar")
diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake
index da210820bb2..10d60807212 100644
--- a/cmake/QtTargetHelpers.cmake
+++ b/cmake/QtTargetHelpers.cmake
@@ -2023,3 +2023,61 @@ function(qt_internal_apply_dynamic_list_linker_flags target dynlist_template)
target_link_options(${target} PRIVATE "LINKER:--dynamic-list=${dynlist_file_abspath}")
endfunction()
+
+function(qt_internal_workaround_static_lib_gcc_lto_issue target)
+ get_target_property(target_type "${target}" TYPE)
+ get_target_property(target_lto_enabled "${target}" INTERPROCEDURAL_OPTIMIZATION)
+ get_target_property(target_lto_enabled_debug "${target}" INTERPROCEDURAL_OPTIMIZATION_DEBUG)
+ set(target_lto_enabled_debug_unset FALSE)
+
+ if(target_lto_enabled_debug MATCHES "-NOTFOUND")
+ set(target_lto_enabled_debug_unset TRUE)
+ endif()
+
+ set(general_lto_enabled FALSE)
+
+ if(FEATURE_ltcg
+ OR QT_FEATURE_ltcg
+ OR CMAKE_INTERPROCEDURAL_OPTIMIZATION
+ OR target_lto_enabled)
+ set(general_lto_enabled TRUE)
+ endif()
+
+ if((general_lto_enabled OR target_lto_enabled_debug)
+ AND GCC
+ AND target_type STREQUAL "STATIC_LIBRARY")
+ # CMake <= 3.19 appends -fno-fat-lto-objects for all library types if
+ # CMAKE_INTERPROCEDURAL_OPTIMIZATION is enabled. Static libraries need
+ # the opposite compiler option.
+ # (https://gitlab.kitware.com/cmake/cmake/-/issues/21696)
+ set(flag_name -ffat-lto-objects)
+
+ if((general_lto_enabled AND target_lto_enabled_debug_unset)
+ OR (general_lto_enabled AND target_lto_enabled)
+ )
+ set(flag_wrapped "${flag_name}")
+ elseif(general_lto_enabled AND NOT target_lto_enabled_debug)
+ set(flag_wrapped "$<$<NOT:$<CONFIG:Debug>>:${flag_name}>")
+ elseif(target_lto_enabled_debug)
+ set(flag_wrapped "$<$<CONFIG:Debug>:${flag_name}>")
+ endif()
+
+ target_compile_options("${target}" PRIVATE "${flag_wrapped}")
+ endif()
+endfunction()
+
+# Enable LTO for the debug configuration of optimized tool or library targets.
+# Can be opted out via various options.
+function(qt_internal_enable_optimized_tools_lto target)
+ string(TOLOWER "${PROJECT_NAME}" project_name_lower)
+
+ if(QT_FEATURE_optimized_tools
+ AND NOT QT_FORCE_NO_OPTIMIZED_TOOLS_LTO
+ AND NOT QT_FORCE_NO_OPTIMIZE_${target}
+ AND NOT QT_FORCE_NO_OPTIMIZE_${project_name_lower}
+ AND NOT QT_FORCE_NO_LTO_${target}
+ AND NOT QT_FORCE_NO_LTO_${project_name_lower}
+ )
+ set_target_properties("${target}" PROPERTIES INTERPROCEDURAL_OPTIMIZATION_DEBUG ON)
+ endif()
+endfunction()
diff --git a/cmake/QtToolHelpers.cmake b/cmake/QtToolHelpers.cmake
index 5d531818ebd..16743dcd9eb 100644
--- a/cmake/QtToolHelpers.cmake
+++ b/cmake/QtToolHelpers.cmake
@@ -292,6 +292,9 @@ function(qt_internal_add_tool target_name)
)
qt_internal_install_pdb_files(${target_name} "${install_dir}")
+ qt_internal_add_target_optimized_flags_for_debug_config_in_parent_scope("${target_name}")
+ qt_internal_enable_optimized_tools_lto("${target_name}")
+
if(QT_GENERATE_SBOM)
_qt_internal_forward_function_args(
FORWARD_APPEND