2022-07-05 11:26:52 +00:00
|
|
|
# Copyright (C) 2022 The Qt Company Ltd.
|
2022-08-19 13:21:34 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
2022-07-05 11:26:52 +00:00
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
if (MSVC)
|
|
|
|
if (QT_64BIT)
|
|
|
|
# SSE2 is mandatory on 64-bit mode, so skip the option. It triggers:
|
|
|
|
# cl : Command line warning D9002 : ignoring unknown option '-arch:SSE2'
|
|
|
|
set(QT_CFLAGS_SSE2 "")
|
|
|
|
else()
|
|
|
|
set(QT_CFLAGS_SSE2 "-arch:SSE2")
|
|
|
|
endif()
|
|
|
|
set(QT_CFLAGS_SSE3 "${QT_CFLAGS_SSE2}")
|
|
|
|
set(QT_CFLAGS_SSSE3 "${QT_CFLAGS_SSE2}")
|
|
|
|
set(QT_CFLAGS_SSE4_1 "${QT_CFLAGS_SSE2}")
|
|
|
|
set(QT_CFLAGS_SSE4_2 "${QT_CFLAGS_SSE2}")
|
|
|
|
set(QT_CFLAGS_AESNI "${QT_CFLAGS_SSE2}")
|
|
|
|
set(QT_CFLAGS_SHANI "${QT_CFLAGS_SSE2}")
|
2019-03-21 12:31:16 +00:00
|
|
|
|
|
|
|
set(QT_CFLAGS_AVX "-arch:AVX")
|
|
|
|
set(QT_CFLAGS_AVX2 "-arch:AVX2")
|
|
|
|
set(QT_CFLAGS_F16C "-arch:AVX")
|
|
|
|
set(QT_CFLAGS_RDRND "")
|
2020-09-04 16:10:32 +00:00
|
|
|
set(QT_CFLAGS_RDSEED "")
|
2019-03-21 12:31:16 +00:00
|
|
|
set(QT_CFLAGS_AVX512F "-arch:AVX512")
|
|
|
|
set(QT_CFLAGS_AVX512ER "-arch:AVX512")
|
|
|
|
set(QT_CFLAGS_AVX512CD "-arch:AVX512")
|
|
|
|
set(QT_CFLAGS_AVX512PF "-arch:AVX512")
|
|
|
|
set(QT_CFLAGS_AVX512DQ "-arch:AVX512")
|
|
|
|
set(QT_CFLAGS_AVX512BW "-arch:AVX512")
|
|
|
|
set(QT_CFLAGS_AVX512VL "-arch:AVX512")
|
|
|
|
set(QT_CFLAGS_AVX512IFMA "-arch:AVX512")
|
|
|
|
set(QT_CFLAGS_AVX512VBMI "-arch:AVX512")
|
2022-02-24 01:54:40 +00:00
|
|
|
set(QT_CFLAGS_AVX512VBMI2 "-arch:AVX512")
|
|
|
|
set(QT_CFLAGS_VAES "")
|
2018-10-24 13:20:27 +00:00
|
|
|
endif()
|
|
|
|
|
2021-12-16 15:12:12 +00:00
|
|
|
if(GCC OR CLANG OR QCC)
|
2018-10-24 13:20:27 +00:00
|
|
|
set(QT_CFLAGS_SSE2 "-msse2")
|
|
|
|
set(QT_CFLAGS_SSE3 "-msse3")
|
|
|
|
set(QT_CFLAGS_SSSE3 "-mssse3")
|
|
|
|
set(QT_CFLAGS_SSE4_1 "-msse4.1")
|
|
|
|
set(QT_CFLAGS_SSE4_2 "-msse4.2")
|
|
|
|
set(QT_CFLAGS_F16C "-mf16c")
|
|
|
|
set(QT_CFLAGS_RDRND "-mrdrnd")
|
2020-09-04 16:10:32 +00:00
|
|
|
set(QT_CFLAGS_RDSEED "-mrdseed")
|
2018-10-24 13:20:27 +00:00
|
|
|
set(QT_CFLAGS_AVX "-mavx")
|
|
|
|
set(QT_CFLAGS_AVX2 "-mavx2")
|
2020-09-04 16:11:02 +00:00
|
|
|
set(QT_CFLAGS_ARCH_HASWELL "-march=haswell")
|
2018-10-24 13:20:27 +00:00
|
|
|
set(QT_CFLAGS_AVX512F "-mavx512f")
|
|
|
|
set(QT_CFLAGS_AVX512ER "-mavx512er")
|
|
|
|
set(QT_CFLAGS_AVX512CD "-mavx512cd")
|
|
|
|
set(QT_CFLAGS_AVX512PF "-mavx512pf")
|
|
|
|
set(QT_CFLAGS_AVX512DQ "-mavx512dq")
|
|
|
|
set(QT_CFLAGS_AVX512BW "-mavx512bw")
|
|
|
|
set(QT_CFLAGS_AVX512VL "-mavx512vl")
|
|
|
|
set(QT_CFLAGS_AVX512IFMA "-mavx512ifma")
|
|
|
|
set(QT_CFLAGS_AVX512VBMI "-mavx512vbmi")
|
2022-02-24 01:54:40 +00:00
|
|
|
set(QT_CFLAGS_AVX512VBMI2 "-mavx512vbmi2")
|
2018-10-24 13:20:27 +00:00
|
|
|
set(QT_CFLAGS_AESNI "-maes")
|
|
|
|
set(QT_CFLAGS_SHANI "-msha")
|
2022-02-24 01:54:40 +00:00
|
|
|
set(QT_CFLAGS_VAES "-mvaes")
|
2020-03-16 12:36:47 +00:00
|
|
|
if(NOT UIKIT AND NOT QT_64BIT)
|
2019-04-08 15:23:57 +00:00
|
|
|
set(QT_CFLAGS_NEON "-mfpu=neon")
|
|
|
|
endif()
|
2018-10-24 13:20:27 +00:00
|
|
|
set(QT_CFLAGS_MIPS_DSP "-mdsp")
|
|
|
|
set(QT_CFLAGS_MIPS_DSPR2 "-mdspr2")
|
|
|
|
endif()
|
|
|
|
|
CMake: Adjust compiler flag optimizations to qmake mkspec ones
There are inconsistencies in the default optimization flags added by
CMake across configurations like Release and RelWithDebInfo.
In particular Release uses -O3, whereas RelWithDebInfo uses -O2,
as well as usage of /INCREMENTAL in release configs with MSVC, etc.
To make sure that the Qt 6 binaries built with CMake are consistent
across configs, as well as consistent with the flags we used when
building Qt 5 with qmake, add a horrible search and replace mechanism
to replaces the CMake flags with what our mkspecs indicate to use.
Ideally this would be done by providing custom CMake toolchain files
for each platform we support, and we might revisit that later if the
need really arises.
To implement the replacing, we first need the flags that should be
added. Port the QMAKE_CFLAGS_OPTIMIZE variables to CMake, which is
done in QtCompilerOptimization.cmake.
Then a new function called
qt_internal_set_up_config_optimizations_like_in_qmake will look for
any kind of optimization flags set in the
CMAKE_<LANG>_FLAGS_<CONFIG> style variables, remove them, and add
the appropriate flags that qmake mkspecs provide.
On some platforms (like Windows MSVC) the function also alters the
linker CMAKE_${TYPE}_LINKER_FLAGS_<CONFIG> style variables.
The mechanism allows opting out of this replacing by
setting the QT_USE_DEFAULT_CMAKE_OPTIMIZATION_FLAGS value.
It also allows opting into removal of flags for custom configs by
providing QT_ADDITIONAL_OPTIMIZATION_FLAG_CONFIGS. It's only removal,
because we wouldn't know what kind of config it is, and thus what
flags to add.
The currently modified configs are: Release, RelWithDebInfo,
MinSizeRel, Debug aka the usual default CMake provided ones.
The mechanism is only applied to C-like languages.
ASM is not handled to be on the safe side due to not knowing what kind
of compiler flags the platform assembler might take.
It's also important to skip RC on MSVC platforms.
Task-number: QTBUG-85992
Change-Id: I3712d5cd5a34fceab54f56a6fa46b4e678952362
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-08-17 15:32:28 +00:00
|
|
|
# Fall through is important, so that more specific flags that might be missing are set by the
|
|
|
|
# previous base cases.
|
|
|
|
# This mirrors qmake's mkspecs QMAKE_CFLAGS_OPTIMIZE assignments (mostly).
|
|
|
|
#
|
|
|
|
# TODO: Missing mkspecs flags we don't handle below: win32-clang-g++, win32-clang-msvc, rtems-base
|
|
|
|
#
|
|
|
|
# gcc and clang base
|
2022-10-07 07:53:00 +00:00
|
|
|
if(GCC OR CLANG)
|
CMake: Adjust compiler flag optimizations to qmake mkspec ones
There are inconsistencies in the default optimization flags added by
CMake across configurations like Release and RelWithDebInfo.
In particular Release uses -O3, whereas RelWithDebInfo uses -O2,
as well as usage of /INCREMENTAL in release configs with MSVC, etc.
To make sure that the Qt 6 binaries built with CMake are consistent
across configs, as well as consistent with the flags we used when
building Qt 5 with qmake, add a horrible search and replace mechanism
to replaces the CMake flags with what our mkspecs indicate to use.
Ideally this would be done by providing custom CMake toolchain files
for each platform we support, and we might revisit that later if the
need really arises.
To implement the replacing, we first need the flags that should be
added. Port the QMAKE_CFLAGS_OPTIMIZE variables to CMake, which is
done in QtCompilerOptimization.cmake.
Then a new function called
qt_internal_set_up_config_optimizations_like_in_qmake will look for
any kind of optimization flags set in the
CMAKE_<LANG>_FLAGS_<CONFIG> style variables, remove them, and add
the appropriate flags that qmake mkspecs provide.
On some platforms (like Windows MSVC) the function also alters the
linker CMAKE_${TYPE}_LINKER_FLAGS_<CONFIG> style variables.
The mechanism allows opting out of this replacing by
setting the QT_USE_DEFAULT_CMAKE_OPTIMIZATION_FLAGS value.
It also allows opting into removal of flags for custom configs by
providing QT_ADDITIONAL_OPTIMIZATION_FLAG_CONFIGS. It's only removal,
because we wouldn't know what kind of config it is, and thus what
flags to add.
The currently modified configs are: Release, RelWithDebInfo,
MinSizeRel, Debug aka the usual default CMake provided ones.
The mechanism is only applied to C-like languages.
ASM is not handled to be on the safe side due to not knowing what kind
of compiler flags the platform assembler might take.
It's also important to skip RC on MSVC platforms.
Task-number: QTBUG-85992
Change-Id: I3712d5cd5a34fceab54f56a6fa46b4e678952362
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-08-17 15:32:28 +00:00
|
|
|
set(QT_CFLAGS_OPTIMIZE "-O2")
|
|
|
|
set(QT_CFLAGS_OPTIMIZE_FULL "-O3")
|
|
|
|
set(QT_CFLAGS_OPTIMIZE_DEBUG "-Og")
|
|
|
|
set(QT_CFLAGS_OPTIMIZE_SIZE "-Os")
|
|
|
|
|
|
|
|
if(CLANG)
|
|
|
|
set(QT_CFLAGS_OPTIMIZE_SIZE "-Oz")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Flags that CMake might set, aka flags the compiler would see as valid values.
|
2021-10-12 20:39:37 +00:00
|
|
|
if(GCC OR CLANG OR QCC)
|
CMake: Adjust compiler flag optimizations to qmake mkspec ones
There are inconsistencies in the default optimization flags added by
CMake across configurations like Release and RelWithDebInfo.
In particular Release uses -O3, whereas RelWithDebInfo uses -O2,
as well as usage of /INCREMENTAL in release configs with MSVC, etc.
To make sure that the Qt 6 binaries built with CMake are consistent
across configs, as well as consistent with the flags we used when
building Qt 5 with qmake, add a horrible search and replace mechanism
to replaces the CMake flags with what our mkspecs indicate to use.
Ideally this would be done by providing custom CMake toolchain files
for each platform we support, and we might revisit that later if the
need really arises.
To implement the replacing, we first need the flags that should be
added. Port the QMAKE_CFLAGS_OPTIMIZE variables to CMake, which is
done in QtCompilerOptimization.cmake.
Then a new function called
qt_internal_set_up_config_optimizations_like_in_qmake will look for
any kind of optimization flags set in the
CMAKE_<LANG>_FLAGS_<CONFIG> style variables, remove them, and add
the appropriate flags that qmake mkspecs provide.
On some platforms (like Windows MSVC) the function also alters the
linker CMAKE_${TYPE}_LINKER_FLAGS_<CONFIG> style variables.
The mechanism allows opting out of this replacing by
setting the QT_USE_DEFAULT_CMAKE_OPTIMIZATION_FLAGS value.
It also allows opting into removal of flags for custom configs by
providing QT_ADDITIONAL_OPTIMIZATION_FLAG_CONFIGS. It's only removal,
because we wouldn't know what kind of config it is, and thus what
flags to add.
The currently modified configs are: Release, RelWithDebInfo,
MinSizeRel, Debug aka the usual default CMake provided ones.
The mechanism is only applied to C-like languages.
ASM is not handled to be on the safe side due to not knowing what kind
of compiler flags the platform assembler might take.
It's also important to skip RC on MSVC platforms.
Task-number: QTBUG-85992
Change-Id: I3712d5cd5a34fceab54f56a6fa46b4e678952362
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-08-17 15:32:28 +00:00
|
|
|
set(QT_CFLAGS_OPTIMIZE_VALID_VALUES "-O0" "-O1" "-O2" "-O3" "-Os" "-Oz")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
# Windows MSVC
|
|
|
|
if(MSVC)
|
2023-05-23 07:59:24 +00:00
|
|
|
set(QT_CFLAGS_OPTIMIZE "-O2 -Ob3") # -Ob3 was introduced in Visual Studio 2019 version 16.0
|
CMake: Adjust compiler flag optimizations to qmake mkspec ones
There are inconsistencies in the default optimization flags added by
CMake across configurations like Release and RelWithDebInfo.
In particular Release uses -O3, whereas RelWithDebInfo uses -O2,
as well as usage of /INCREMENTAL in release configs with MSVC, etc.
To make sure that the Qt 6 binaries built with CMake are consistent
across configs, as well as consistent with the flags we used when
building Qt 5 with qmake, add a horrible search and replace mechanism
to replaces the CMake flags with what our mkspecs indicate to use.
Ideally this would be done by providing custom CMake toolchain files
for each platform we support, and we might revisit that later if the
need really arises.
To implement the replacing, we first need the flags that should be
added. Port the QMAKE_CFLAGS_OPTIMIZE variables to CMake, which is
done in QtCompilerOptimization.cmake.
Then a new function called
qt_internal_set_up_config_optimizations_like_in_qmake will look for
any kind of optimization flags set in the
CMAKE_<LANG>_FLAGS_<CONFIG> style variables, remove them, and add
the appropriate flags that qmake mkspecs provide.
On some platforms (like Windows MSVC) the function also alters the
linker CMAKE_${TYPE}_LINKER_FLAGS_<CONFIG> style variables.
The mechanism allows opting out of this replacing by
setting the QT_USE_DEFAULT_CMAKE_OPTIMIZATION_FLAGS value.
It also allows opting into removal of flags for custom configs by
providing QT_ADDITIONAL_OPTIMIZATION_FLAG_CONFIGS. It's only removal,
because we wouldn't know what kind of config it is, and thus what
flags to add.
The currently modified configs are: Release, RelWithDebInfo,
MinSizeRel, Debug aka the usual default CMake provided ones.
The mechanism is only applied to C-like languages.
ASM is not handled to be on the safe side due to not knowing what kind
of compiler flags the platform assembler might take.
It's also important to skip RC on MSVC platforms.
Task-number: QTBUG-85992
Change-Id: I3712d5cd5a34fceab54f56a6fa46b4e678952362
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-08-17 15:32:28 +00:00
|
|
|
set(QT_CFLAGS_OPTIMIZE_DEBUG "-Od")
|
|
|
|
set(QT_CFLAGS_OPTIMIZE_SIZE "-O1")
|
2023-05-23 07:59:24 +00:00
|
|
|
set(QT_CFLAGS_OPTIMIZE_VALID_VALUES "/O2" "/O1" "/Od" "/Ob0" "/Ob1" "/Ob2" "/Ob3" "/O0" "-O0")
|
2020-11-02 04:36:14 +00:00
|
|
|
|
|
|
|
if(CLANG)
|
|
|
|
set(QT_CFLAGS_OPTIMIZE_FULL "/clang:-O3")
|
|
|
|
set(QT_CFLAGS_OPTIMIZE_SIZE "/clang:-Oz")
|
|
|
|
endif()
|
CMake: Adjust compiler flag optimizations to qmake mkspec ones
There are inconsistencies in the default optimization flags added by
CMake across configurations like Release and RelWithDebInfo.
In particular Release uses -O3, whereas RelWithDebInfo uses -O2,
as well as usage of /INCREMENTAL in release configs with MSVC, etc.
To make sure that the Qt 6 binaries built with CMake are consistent
across configs, as well as consistent with the flags we used when
building Qt 5 with qmake, add a horrible search and replace mechanism
to replaces the CMake flags with what our mkspecs indicate to use.
Ideally this would be done by providing custom CMake toolchain files
for each platform we support, and we might revisit that later if the
need really arises.
To implement the replacing, we first need the flags that should be
added. Port the QMAKE_CFLAGS_OPTIMIZE variables to CMake, which is
done in QtCompilerOptimization.cmake.
Then a new function called
qt_internal_set_up_config_optimizations_like_in_qmake will look for
any kind of optimization flags set in the
CMAKE_<LANG>_FLAGS_<CONFIG> style variables, remove them, and add
the appropriate flags that qmake mkspecs provide.
On some platforms (like Windows MSVC) the function also alters the
linker CMAKE_${TYPE}_LINKER_FLAGS_<CONFIG> style variables.
The mechanism allows opting out of this replacing by
setting the QT_USE_DEFAULT_CMAKE_OPTIMIZATION_FLAGS value.
It also allows opting into removal of flags for custom configs by
providing QT_ADDITIONAL_OPTIMIZATION_FLAG_CONFIGS. It's only removal,
because we wouldn't know what kind of config it is, and thus what
flags to add.
The currently modified configs are: Release, RelWithDebInfo,
MinSizeRel, Debug aka the usual default CMake provided ones.
The mechanism is only applied to C-like languages.
ASM is not handled to be on the safe side due to not knowing what kind
of compiler flags the platform assembler might take.
It's also important to skip RC on MSVC platforms.
Task-number: QTBUG-85992
Change-Id: I3712d5cd5a34fceab54f56a6fa46b4e678952362
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-08-17 15:32:28 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Android Clang
|
|
|
|
if(CLANG AND ANDROID)
|
2021-08-19 20:13:53 +00:00
|
|
|
if(QT_FEATURE_ltcg)
|
|
|
|
# When using LTCG, the linker cannot cope with -Oz. See QTBUG-89472 for details.
|
|
|
|
set(QT_CFLAGS_OPTIMIZE "-O2")
|
|
|
|
set(QT_CFLAGS_OPTIMIZE_FULL "-O3")
|
|
|
|
else()
|
|
|
|
set(QT_CFLAGS_OPTIMIZE "-Oz")
|
|
|
|
set(QT_CFLAGS_OPTIMIZE_FULL "-Oz")
|
|
|
|
endif()
|
CMake: Adjust compiler flag optimizations to qmake mkspec ones
There are inconsistencies in the default optimization flags added by
CMake across configurations like Release and RelWithDebInfo.
In particular Release uses -O3, whereas RelWithDebInfo uses -O2,
as well as usage of /INCREMENTAL in release configs with MSVC, etc.
To make sure that the Qt 6 binaries built with CMake are consistent
across configs, as well as consistent with the flags we used when
building Qt 5 with qmake, add a horrible search and replace mechanism
to replaces the CMake flags with what our mkspecs indicate to use.
Ideally this would be done by providing custom CMake toolchain files
for each platform we support, and we might revisit that later if the
need really arises.
To implement the replacing, we first need the flags that should be
added. Port the QMAKE_CFLAGS_OPTIMIZE variables to CMake, which is
done in QtCompilerOptimization.cmake.
Then a new function called
qt_internal_set_up_config_optimizations_like_in_qmake will look for
any kind of optimization flags set in the
CMAKE_<LANG>_FLAGS_<CONFIG> style variables, remove them, and add
the appropriate flags that qmake mkspecs provide.
On some platforms (like Windows MSVC) the function also alters the
linker CMAKE_${TYPE}_LINKER_FLAGS_<CONFIG> style variables.
The mechanism allows opting out of this replacing by
setting the QT_USE_DEFAULT_CMAKE_OPTIMIZATION_FLAGS value.
It also allows opting into removal of flags for custom configs by
providing QT_ADDITIONAL_OPTIMIZATION_FLAG_CONFIGS. It's only removal,
because we wouldn't know what kind of config it is, and thus what
flags to add.
The currently modified configs are: Release, RelWithDebInfo,
MinSizeRel, Debug aka the usual default CMake provided ones.
The mechanism is only applied to C-like languages.
ASM is not handled to be on the safe side due to not knowing what kind
of compiler flags the platform assembler might take.
It's also important to skip RC on MSVC platforms.
Task-number: QTBUG-85992
Change-Id: I3712d5cd5a34fceab54f56a6fa46b4e678952362
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-08-17 15:32:28 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# qcc
|
|
|
|
if (QCC)
|
|
|
|
set(QT_CFLAGS_OPTIMIZE "-O2")
|
|
|
|
set(QT_CFLAGS_OPTIMIZE_FULL "-O3")
|
|
|
|
endif()
|
|
|
|
|
2022-10-07 07:53:00 +00:00
|
|
|
# Emscripten Clang
|
2020-09-03 08:29:41 +00:00
|
|
|
if(WASM)
|
2022-10-07 07:53:00 +00:00
|
|
|
set(QT_CFLAGS_OPTIMIZE_DEBUG "-O2 -g") # -Og is not supported
|
2023-05-23 07:45:20 +00:00
|
|
|
set(QT_CFLAGS_SSE2 "-O2 -msimd128 -msse -msse2")
|
2020-09-03 08:29:41 +00:00
|
|
|
endif()
|