summaryrefslogtreecommitdiffstats
path: root/configure.cmake
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2019-10-17 10:49:44 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2019-10-17 16:57:25 +0000
commit2fa23e46c0b79a065d92a95033bfc3ae10b707cf (patch)
treeab13778363b9719fbf6bb055608ae88fcd614642 /configure.cmake
parent4df389eb4f1ae10284c03023e923ce2164d46753 (diff)
Fix C++ standard detection
We cannot use a generator expression in an if statement, it does not work. Instead, we could inspect the CMAKE_C/CXX_COMPILE_FEATURES list, but unfortunately that's not reliable. For example it detects that ICPC supports C++17 when in fact that depends on the installed libstdc++. Therefore this patch revives our own configure tests. Change-Id: Ic3bc5762fbe81837722523e3881ac16e84628519 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'configure.cmake')
-rw-r--r--configure.cmake55
1 files changed, 52 insertions, 3 deletions
diff --git a/configure.cmake b/configure.cmake
index 55c2d6b73c..f6fba22731 100644
--- a/configure.cmake
+++ b/configure.cmake
@@ -15,6 +15,54 @@ qt_find_package(Libudev PROVIDED_TARGETS PkgConfig::Libudev)
#### Tests
+# c++14
+qt_config_compile_test(cxx14
+ LABEL "C++14 support"
+"#if __cplusplus > 201103L
+// Compiler claims to support C++14, trust it
+#else
+# error __cplusplus must be > 201103L (the value of C++11)
+#endif
+
+
+int main(int argc, char **argv)
+{
+ (void)argc; (void)argv;
+ /* BEGIN TEST: */
+
+ /* END TEST: */
+ return 0;
+}
+"
+ CXX_STANDARD 14
+)
+
+# c++17
+qt_config_compile_test(cxx17
+ LABEL "C++17 support"
+"#if __cplusplus > 201402L
+// Compiler claims to support C++17, trust it
+#else
+# error __cplusplus must be > 201402L (the value for C++14)
+#endif
+#include <map> // https://bugs.llvm.org//show_bug.cgi?id=33117
+#include <variant>
+
+
+int main(int argc, char **argv)
+{
+ (void)argc; (void)argv;
+ /* BEGIN TEST: */
+std::variant<int> v(42);
+int i = std::get<int>(v);
+std::visit([](const auto &) { return 1; }, v);
+ /* END TEST: */
+ return 0;
+}
+"
+ CXX_STANDARD 17
+)
+
# c++2a
qt_config_compile_test(cxx2a
LABEL "C++2a support"
@@ -33,7 +81,8 @@ int main(int argc, char **argv)
/* END TEST: */
return 0;
}
-"# FIXME: qmake: CONFIG += c++11 c++14 c++17 c++2a
+"
+ CXX_STANDARD 20
)
# precompile_header
@@ -294,11 +343,11 @@ qt_feature("cxx11" PUBLIC
)
qt_feature("cxx14" PUBLIC
LABEL "C++14"
- CONDITION QT_FEATURE_cxx11 AND $<COMPILE_FEATURES:cxx_std_14>
+ CONDITION QT_FEATURE_cxx11 AND TEST_cxx14
)
qt_feature("cxx17" PUBLIC
LABEL "C++17"
- CONDITION QT_FEATURE_cxx14 AND $<COMPILE_FEATURES:cxx_std_17>
+ CONDITION QT_FEATURE_cxx14 AND TEST_cxx17
)
qt_feature("cxx1z" PUBLIC
LABEL "C++17"