diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-06-04 11:29:00 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-08-05 09:03:15 +0000 |
commit | f69dbb0b41b1ddc6c951d23ca744bbed99afabdc (patch) | |
tree | 15f62e88ea7ea7f4bbe4d700bfe990a3b48be352 | |
parent | f12ddfaecc9461644df2410dcf49cb038e9187cf (diff) |
CMake: Don't use std=gnu++11 when building Qt internal targets
The logic is a bit involved in qmake.
The Qt internal qt_common.prf adds CONFIG += strict_c++ which applies
to qt modules, qt plugins, qml plugins, qt helper libs, winmain and
qt_apps, qt_tools, but NOT tests (which is important because the tests
on Windows MinGW fail to build without the GNU extensions).
Then default_post.prf checks for the strict_c++ value and either uses
the strict or non-strict C++ standard flags. default_post.prf is
loaded for all qmake projects, not just the Qt internal ones.
Now CMake doesn't provide a transitive based option to disable C++
GNU extensions with a mechanism similar to target_compile_features.
It only provides the CXX_EXTENSIONS property and it's associated
CMAKE_CXX_EXTENSIONS variable. We can't set the variable at a
directory scope, because that is too coarse grained.
So we rely on setting the property via a function in every relevant
qt_add_<target> function.
Now the naming of the function is weird.
We name the function as qt_internal_<...>, because it's not meant to be
used by Qt users.
We prepend an underscore to the name because we need to place it in
Qt6CoreMacros, so that the function can be called by
qt_add_qml_module which IS a public function.
That's because in Qt5 load(qml_plugin) was private API, but in Qt 6 +
CMake we decided to make qt_add_qml_module() as public API.
Change-Id: Id014626b087d590e25cb46843f93d0c67fc36e44
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r-- | cmake/QtApp.cmake | 1 | ||||
-rw-r--r-- | cmake/QtBuild.cmake | 4 | ||||
-rw-r--r-- | src/corelib/Qt6CoreMacros.cmake | 16 |
3 files changed, 21 insertions, 0 deletions
diff --git a/cmake/QtApp.cmake b/cmake/QtApp.cmake index c54bb3e940..ca46690fb7 100644 --- a/cmake/QtApp.cmake +++ b/cmake/QtApp.cmake @@ -38,6 +38,7 @@ function(qt_internal_add_app target) TARGET_COPYRIGHT "${arg_TARGET_COPYRIGHT}" ) qt_internal_add_target_aliases("${target}") + _qt_internal_apply_strict_cpp("${target}") # To mimic the default behaviors of qt_app.prf, we by default enable GUI Windows applications, # but don't enable macOS bundles. diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index f957d87332..c404a6b483 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -2686,6 +2686,7 @@ function(qt_add_module target) endif() qt_internal_add_target_aliases("${target}") qt_skip_warnings_are_errors_when_repo_unclean("${target}") + _qt_internal_apply_strict_cpp("${target}") # Add _private target to link against the private headers: if(NOT ${arg_NO_PRIVATE_MODULE}) @@ -3764,6 +3765,7 @@ function(qt_internal_add_plugin target) endif() qt_internal_add_target_aliases("${target}") qt_skip_warnings_are_errors_when_repo_unclean("${target}") + _qt_internal_apply_strict_cpp("${target}") # Disable linking of plugins against other plugins during static regular and # super builds. The latter causes cyclic dependencies otherwise. @@ -4654,6 +4656,7 @@ function(qt_add_3rdparty_library target) qt_internal_add_qt_repo_known_module(${target}) qt_internal_add_target_aliases(${target}) + _qt_internal_apply_strict_cpp(${target}) if (ANDROID) qt_android_apply_arch_suffix("${target}") @@ -4970,6 +4973,7 @@ function(qt_add_tool target_name) TARGET_COPYRIGHT "${arg_TARGET_COPYRIGHT}" ) qt_internal_add_target_aliases("${target_name}") + _qt_internal_apply_strict_cpp("${target_name}") if (NOT target_name STREQUAL name) set_target_properties(${target_name} PROPERTIES diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 008452ea7c..34e5efb5e9 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1290,3 +1290,19 @@ endif() function(qt_disable_utf8_sources target) set_target_properties("${target}" PROPERTIES QT_NO_UTF8_SOURCE TRUE) endfunction() + +function(_qt_internal_apply_strict_cpp target) + # Disable C, Obj-C and C++ GNU extensions aka no "-std=gnu++11". + # Similar to mkspecs/features/default_post.prf's CONFIG += strict_cpp. + # Allow opt-out via variable. + if(NOT QT_ENABLE_CXX_EXTENSIONS) + get_target_property(target_type "${target}" TYPE) + if(NOT target_type STREQUAL "INTERFACE_LIBRARY") + set_target_properties("${target}" PROPERTIES + CXX_EXTENSIONS OFF + C_EXTENSIONS OFF + OBJC_EXTENSIONS OFF + OBJCXX_EXTENSIONS OFF) + endif() + endif() +endfunction() |