Fix syncqt compiler and linker flags handling

We want syncqt to be built optimized by default. The current approach
set the default build type for the external projects and optimized
flags for the non-configure-time syncqt build. The problem is that
syncqt still have compiler flags littered by either the Qt configuration
type or the system defaults that are applicable for RelWithDebugInfo
configuration(the default one we chose for syncqt).

This patch makes sure that we cleanup all compiler flags from any
optimizations and apply optimized flags for all configurations. Also
we discard '/RTC1' flag if it's set. Configure time executables now
respect the language related flags that are set in the project and
adjust the flags passed to try_compile.

For linker flags we should use those that are applicable for the
preferred build type. Since syncqt is built in RelWithDebugInfo
by default we should replace linker flags in all configs with
those are used for RelWithDebugInfo configuration.

Fixes: QTBUG-114925
Pick-to: 6.5 6.6
Change-Id: I782f81a36f5ef7ee4d342ce8ac6c217cb2552f3b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2023-06-28 15:36:02 +02:00
parent ed1fbc7a88
commit 49ce711796
2 changed files with 37 additions and 4 deletions

View File

@ -370,6 +370,7 @@ function(qt_internal_add_configure_time_executable target)
set(target_binary_dir "${CMAKE_CURRENT_BINARY_DIR}/configure_time_bins")
if(arg_CONFIG)
set(CMAKE_TRY_COMPILE_CONFIGURATION "${arg_CONFIG}")
string(TOUPPER "_${arg_CONFIG}" config_suffix)
endif()
get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
@ -463,6 +464,29 @@ function(qt_internal_add_configure_time_executable target)
set(cmake_flags_arg CMAKE_FLAGS "${arg_CMAKE_FLAGS}")
endif()
configure_file("${template}" "${target_binary_dir}/CMakeLists.txt" @ONLY)
qt_internal_get_enabled_languages_for_flag_manipulation(enabled_languages)
foreach(lang IN LISTS enabled_languages)
set(compiler_flags_var "CMAKE_${lang}_FLAGS")
list(APPEND cmake_flags_arg "-D${compiler_flags_var}:STRING=${${compiler_flags_var}}")
if(arg_CONFIG)
set(compiler_flags_var_config "${compiler_flags_var}${config_suffix}")
list(APPEND cmake_flags_arg
"-D${compiler_flags_var_config}:STRING=${${compiler_flags_var_config}}")
endif()
endforeach()
qt_internal_get_target_link_types_for_flag_manipulation(target_link_types)
foreach(linker_type IN LISTS target_link_types)
set(linker_flags_var "CMAKE_${linker_type}_LINKER_FLAGS")
list(APPEND cmake_flags_arg "-D${linker_flags_var}:STRING=${${linker_flags_var}}")
if(arg_CONFIG)
set(linker_flags_var_config "${linker_flags_var}${config_suffix}")
list(APPEND cmake_flags_arg
"-D${linker_flags_var_config}:STRING=${${linker_flags_var_config}}")
endif()
endforeach()
try_compile(result
"${target_binary_dir}"
"${target_binary_dir}"

View File

@ -1,6 +1,17 @@
# The tool should be optimized for maximum performance when working.
if(NOT QT_USE_DEFAULT_CMAKE_OPTIMIZATION_FLAGS)
if(NOT QT_INTERNAL_AVOID_OVERRIDING_SYNCQT_CONFIG)
qt_internal_get_configs_for_flag_manipulation(configs)
qt_internal_remove_known_optimization_flags(LANGUAGES CXX CONFIGS ${configs})
# The /RTC1 flag is present in the default DEBUG flags list and contradicts -O2 but is not
# removed by qt_internal_remove_known_optimization_flags
qt_internal_remove_compiler_flags("/RTC1" LANGUAGES CXX CONFIGS ${configs})
qt_internal_get_optimize_full_flags(optimize_full_flags)
qt_internal_add_compiler_flags(LANGUAGES CXX CONFIGS ${configs} FLAGS "${optimize_full_flags}")
# Replace all linker flags with those we use in the RelWithDebInfo configuration
list(REMOVE_ITEM configs RELWITHDEBINFO)
foreach(config IN LISTS configs)
set(CMAKE_EXE_LINKER_FLAGS_${config} "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
endforeach()
endif()
set(compile_definitions
@ -15,7 +26,6 @@ qt_get_tool_target_name(target_name syncqt)
if(NOT QT_SYNC_HEADERS_AT_CONFIGURE_TIME)
qt_internal_add_tool(${target_name}
DEFINES ${compile_definitions}
COMPILE_OPTIONS ${optimize_full_flags}
TOOLS_TARGET Core
CORE_LIBRARY None
INSTALL_DIR "${INSTALL_LIBEXECDIR}"
@ -39,7 +49,6 @@ else()
# To re-build syncqt use 'syncqt_build' target.
qt_internal_add_configure_time_tool(${target_name}
DEFINES ${compile_definitions}
COMPILE_OPTIONS ${optimize_full_flags}
TOOLS_TARGET Core
INSTALL_DIRECTORY "${INSTALL_LIBEXECDIR}"
CMAKE_FLAGS