summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2019-10-17 10:14:09 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2019-10-17 19:23:25 +0000
commit7e7f41e40c39361059ce4693c5e3a5e1ccd6f7e5 (patch)
tree53add24af9d761f86045646d0d74ac438cc03a98
parent2fa23e46c0b79a065d92a95033bfc3ae10b707cf (diff)
Pick the latest available C/C++ standard when compiling Qtwip/cmake
This maps the behavior of mkspecs/features/qt_common.prf and enables the use of C++17 for example in Android, where the toolchain supports it anyway. Change-Id: I41f4bdb160a3929e2fb78f36efb1ad5f2ad391a5 Reviewed-by: Qt CMake Build Bot Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--CMakeLists.txt2
-rw-r--r--cmake/QtBuild.cmake19
-rw-r--r--cmake/QtSetup.cmake7
3 files changed, 23 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 190a39a859..98fe694adc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,6 +35,8 @@ include(QtBaseCMakeTesting)
## Targets for global features, etc.:
include(QtBaseGlobalTargets)
+qt_set_language_standards()
+
## Should this Qt be static or dynamically linked?
option(BUILD_SHARED_LIBS "Build Qt statically or dynamically" ON)
set(QT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index 537979ad8a..48d755450f 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -3298,3 +3298,22 @@ function(qt_generate_qconfig_cpp)
configure_file(global/qconfig.cpp.in global/qconfig.cpp @ONLY)
endfunction()
+
+function(qt_set_language_standards)
+ ## Use the latest standard the compiler supports (same as qt_common.prf)
+ if (QT_FEATURE_cxx2a)
+ set(CMAKE_CXX_STANDARD 20 PARENT_SCOPE)
+ elseif (QT_FEATURE_cxx17)
+ set(CMAKE_CXX_STANDARD 17 PARENT_SCOPE)
+ elseif (QT_FEATURE_cxx14)
+ set(CMAKE_CXX_STANDARD 14 PARENT_SCOPE)
+ elseif (QT_FEATURE_cxx11)
+ set(CMAKE_CXX_STANDARD 11 PARENT_SCOPE)
+ endif()
+
+ if (c_std_11 IN_LIST CMAKE_C_COMPILE_FEATURES)
+ set(CMAKE_C_STANDARD 11 PARENT_SCOPE)
+ elseif (c_std_99 IN_LIST CMAKE_C_COMPILE_FEATURES)
+ set(CMAKE_C_STANDARD 99 PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/cmake/QtSetup.cmake b/cmake/QtSetup.cmake
index 16fd9b7520..6f42e337da 100644
--- a/cmake/QtSetup.cmake
+++ b/cmake/QtSetup.cmake
@@ -24,11 +24,6 @@ elseif(APPLE)
set(CMAKE_DEBUG_POSTFIX "_debug")
endif()
-## Force C++ standard, do not fall back, do not use compiler extensions
-set(CMAKE_CXX_STANDARD 14)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
-set(CMAKE_CXX_EXTENSIONS OFF)
-
## Position independent code:
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -110,6 +105,8 @@ include(QtCompilerFlags)
## Set up non-prefix build:
qt_set_up_nonprefix_build()
+qt_set_language_standards()
+
## Find host tools (if non native):
set(QT_HOST_PATH "" CACHE PATH "Installed Qt host directory path, used for cross compiling.")