diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-03-04 09:33:35 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-03-31 21:08:32 +0000 |
commit | a03390a8b0318e30ae3b6dc9954093c137a20c32 (patch) | |
tree | df22fd510d9d6b8889e7cc531beb20f6b75b61aa | |
parent | 62013d77721820976102581b4cbd31404c109903 (diff) |
Detect the (stated) C++ standard edition at build time
The configure-time detection (cxx11default) isn't enough if the compiler
can be changed. This is especially necessary if Qt is compiled with a
compiler that defaults to >= C++11 (e.g., GCC 6) and then the user
selects a compiler another compiler (e.g., Clang) via -spec option. In
that case, we'd miss adding the -std=c++11 or -std=gnu++11 option to the
command-line, causing the compilation to fail.
As a nice side-effect, even moc without moc_predefs.h will now get the
__cplusplus setting.
Task-number: QTBUG-58321
Change-Id: I74966ed02f674a7295f8fffd14a8be35da9640e1
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
-rw-r--r-- | config.tests/common/c++98default/c++98default.cpp | 44 | ||||
-rw-r--r-- | config.tests/common/c++98default/c++98default.pro | 3 | ||||
-rw-r--r-- | configure.json | 10 | ||||
-rw-r--r-- | mkspecs/features/data/macros.cpp | 1 | ||||
-rw-r--r-- | mkspecs/features/default_post.prf | 5 | ||||
-rw-r--r-- | mkspecs/features/toolchain.prf | 1 |
6 files changed, 7 insertions, 57 deletions
diff --git a/config.tests/common/c++98default/c++98default.cpp b/config.tests/common/c++98default/c++98default.cpp deleted file mode 100644 index 3ff92eda33..0000000000 --- a/config.tests/common/c++98default/c++98default.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the configuration of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#if __cplusplus < 201103L -#error "compiler does not use c++11 or higher by default" -#endif - -int main(int, char **) {} diff --git a/config.tests/common/c++98default/c++98default.pro b/config.tests/common/c++98default/c++98default.pro deleted file mode 100644 index 97cf2d7b20..0000000000 --- a/config.tests/common/c++98default/c++98default.pro +++ /dev/null @@ -1,3 +0,0 @@ -TEMPLATE = app -CONFIG -= c++11 c++14 c++1z -SOURCES = c++98default.cpp diff --git a/configure.json b/configure.json index d987832fba..06a1e639fe 100644 --- a/configure.json +++ b/configure.json @@ -245,11 +245,6 @@ "type": "compile", "test": "common/c++1z" }, - "cxx11default": { - "label": "compiler defaulting to C++11 or higher", - "type": "compile", - "test": "common/c++98default" - }, "precompile_header": { "label": "precompiled header support", "type": "compile", @@ -451,11 +446,6 @@ "condition": "call.crossCompile", "output": [ "publicConfig", "privateConfig", "crossCompile" ] }, - "cxx11default": { - "label": "Compiler defaults to C++11 or higher", - "condition": "!tests.cxx11default", - "output": [ { "type": "publicConfig", "name": "c++11" } ] - }, "compiler-flags": { "output": [ "compilerFlags" ] }, diff --git a/mkspecs/features/data/macros.cpp b/mkspecs/features/data/macros.cpp index 88473fb980..e677dace12 100644 --- a/mkspecs/features/data/macros.cpp +++ b/mkspecs/features/data/macros.cpp @@ -1,4 +1,5 @@ // Keep this file small. The pre-processed contents are eval'd by qmake. +QT_COMPILER_STDCXX = __cplusplus #ifdef _MSC_VER QMAKE_MSC_VER = _MSC_VER QMAKE_MSC_FULL_VER = _MSC_FULL_VER diff --git a/mkspecs/features/default_post.prf b/mkspecs/features/default_post.prf index 60759b445e..359191c2d3 100644 --- a/mkspecs/features/default_post.prf +++ b/mkspecs/features/default_post.prf @@ -95,6 +95,11 @@ breakpad { !isEmpty(QMAKE_STRIP):QMAKE_POST_LINK = $$QMAKE_POST_LINK$$escape_expand(\\n\\t)$$quote($$QMAKE_STRIP $$DEBUGFILENAME) } +!c++11:!c++14:!c++1z { + # Qt requires C++11 since 5.7, check if we need to force a compiler option + QT_COMPILER_STDCXX_no_L = $$replace(QT_COMPILER_STDCXX, "L$", "") + !greaterThan(QT_COMPILER_STDCXX_no_L, 199711): CONFIG += c++11 +} c++11|c++14|c++1z { # Disable special compiler flags for host builds !host_build|!cross_compile { diff --git a/mkspecs/features/toolchain.prf b/mkspecs/features/toolchain.prf index 6d96eaf689..46a9c5707a 100644 --- a/mkspecs/features/toolchain.prf +++ b/mkspecs/features/toolchain.prf @@ -137,6 +137,7 @@ unset(target_prefix) # Populate QMAKE_COMPILER_DEFINES and some compatibility variables. # The $$format_number() calls strip leading zeros to avoid misinterpretation as octal. +QMAKE_COMPILER_DEFINES += __cplusplus=$$QT_COMPILER_STDCXX !isEmpty(QMAKE_MSC_VER) { QMAKE_COMPILER_DEFINES += _MSC_VER=$$QMAKE_MSC_VER _MSC_FULL_VER=$$QMAKE_MSC_FULL_VER QT_MSVC_MAJOR_VERSION = $$replace(QMAKE_MSC_FULL_VER, "(..)(..)(.*)", "\\1") |