configure: Auto-detect and enable C++11 support if available

Enabling support for C++11 adds CONFIG+=c++11 to the Qt build. Projects
using Qt can check for C++11 support using contains(QT_CONFIG, c++11) in
their .pr[iof] files.

The QMAKE_CXXFLAGS_CXX11 and QMAKE_LFLAGS_CXX11 qmake varibles contain
any arguments the compiler needs to enable C++11. CONFIG+=c++11 adds
these arguments to the build.

Support for clang, g++, and the Intel C++ Compiler for Linux are
included in this commit.

Change-Id: Id77f86d7ad4d5c740b890446a40b105879a0d327
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
This commit is contained in:
Bradley T. Hughes 2012-05-29 07:10:09 +02:00 committed by Qt by Nokia
parent a6d6719c26
commit bf84d1a1fe
10 changed files with 100 additions and 2 deletions

View File

@ -0,0 +1,48 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the FOO module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
// Compiler claims to support C++11, trust it
#else
# error "__cplusplus must be >= 201103L"
#endif
int main(int, char **) { return 0; }

View File

@ -0,0 +1,3 @@
SOURCES = c++11.cpp
CONFIG += c++11
CONFIG -= qt app_bundle

32
configure vendored
View File

@ -802,6 +802,7 @@ CFG_ICU=auto
CFG_FORCE_ASSERTS=no
CFG_PCRE=auto
QPA_PLATFORM_GUARD=yes
CFG_CXX11=auto
# initalize variables used for installation
QT_INSTALL_PREFIX=
@ -918,7 +919,7 @@ while [ "$#" -gt 0 ]; do
VAL=no
;;
#Qt style yes options
-profile|-shared|-static|-sm|-xinerama|-xshape|-xsync|-xinput|-xinput2|-egl|-reduce-exports|-pch|-separate-debug-info|-freetype|-xcursor|-xfixes|-xrandr|-xrender|-mitshm|-fontconfig|-xkb|-xcb|-eglfs|-directfb|-nis|-dbus|-dbus-linked|-glib|-gstreamer|-gtkstyle|-cups|-iconv|-largefile|-h|-help|-v|-verbose|-debug|-release|-fast|-accessibility|-confirm-license|-gnumake|-framework|-debug-and-release|-harfbuzz|-prefix-install|-silent|-optimized-qmake|-reduce-relocations|-sse|-openssl|-openssl-linked|-phonon-backend|-audio-backend|-qml-debug|-javascript-jit|-rpath|-pkg-config|-force-pkg-config|-icu|-force-asserts|-testcocoon)
-profile|-shared|-static|-sm|-xinerama|-xshape|-xsync|-xinput|-xinput2|-egl|-reduce-exports|-pch|-separate-debug-info|-freetype|-xcursor|-xfixes|-xrandr|-xrender|-mitshm|-fontconfig|-xkb|-xcb|-eglfs|-directfb|-nis|-dbus|-dbus-linked|-glib|-gstreamer|-gtkstyle|-cups|-iconv|-largefile|-h|-help|-v|-verbose|-debug|-release|-fast|-accessibility|-confirm-license|-gnumake|-framework|-debug-and-release|-harfbuzz|-prefix-install|-silent|-optimized-qmake|-reduce-relocations|-sse|-openssl|-openssl-linked|-phonon-backend|-audio-backend|-qml-debug|-javascript-jit|-rpath|-pkg-config|-force-pkg-config|-icu|-force-asserts|-testcocoon|-c++11)
VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
VAL=yes
;;
@ -1986,6 +1987,13 @@ while [ "$#" -gt 0 ]; do
UNKNOWN_OPT=yes
fi
;;
c++11)
if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
CFG_CXX11="$VAL"
else
UNKNOWN_OPT=yes
fi
;;
*)
UNKNOWN_OPT=yes
;;
@ -2871,7 +2879,7 @@ if [ "$OPT_HELP" = "yes" ]; then
Usage: $relconf [-h] [-prefix <dir>] [-prefix-install] [-bindir <dir>] [-libdir <dir>]
[-docdir <dir>] [-headerdir <dir>] [-plugindir <dir> ] [-importdir <dir>] [-datadir <dir>]
[-translationdir <dir>] [-sysconfdir <dir>] [-examplesdir <dir>] [-testsdir <dir>]
[-release] [-debug] [-debug-and-release]
[-release] [-debug] [-debug-and-release] [-c++11] [-no-c++11]
[-developer-build] [-shared] [-static] [-no-fast] [-fast] [-no-largefile]
[-largefile] [-no-accessibility] [-accessibility] [-no-sql-<driver>] [-sql-<driver>]
[-plugin-sql-<driver>] [-system-sqlite]
@ -2961,6 +2969,8 @@ Configure options:
-opensource ........ Compile and link the Open-Source Edition of Qt.
-commercial ........ Compile and link the Commercial Edition of Qt.
-no-c++11 .......... Do not compile Qt with C++11 support enabled.
+ -c++11 ............. Compile Qt with C++11 support enabled.
* -shared ............ Create and use shared Qt libraries.
-static ............ Create and use static Qt libraries.
@ -3728,6 +3738,21 @@ fi
# functionality tests
#-------------------------------------------------------------------------------
# Detect C++11 support
if [ "$CFG_CXX11" != "no" ]; then
if "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/unix/c++11 "C++11" $L_FLAGS $I_FLAGS $l_FLAGS; then
CFG_CXX11="yes"
elif [ "$CFG_CXX11" != "auto" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
echo "C++11 support cannot be enabled due to functionality tests!"
echo " Turn on verbose messaging (-v) to $0 to see the final report."
echo " If you believe this message is in error you may use the continue"
echo " switch (-continue) to $0 to continue."
exit 101
else
CFG_CXX11="no"
fi
fi
# detect availability of float math.h functions
if "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/unix/floatmath "floatmath" $L_FLAGS $I_FLAGS $D_FLAGS $l_FLAGS; then
CFG_USE_FLOATMATH=yes
@ -5006,6 +5031,8 @@ fi
# ask for all that hasn't been auto-detected or specified in the arguments
#-------------------------------------------------------------------------------
[ "$CFG_CXX11" = "yes" ] && QT_CONFIG="$QT_CONFIG c++11"
# ### Vestige
if [ "$CFG_PHONON_BACKEND" = "yes" ]; then
QT_CONFIG="$QT_CONFIG phonon-backend"
@ -5938,6 +5965,7 @@ if [ "$CFG_DEBUG_RELEASE" = "yes" ]; then
else
echo "Debug .................. $CFG_DEBUG"
fi
echo "C++11 support .......... $CFG_CXX11"
if [ -n "$PKG_CONFIG" ]; then
echo "pkg-config ............. yes"
else

6
dist/changes-5.0.0 vendored
View File

@ -287,6 +287,12 @@ General Improvements
more closely match the directory structure of the code under test.
Integration tests have been moved to tests/auto/integrationtests.
- Qt is compiled with C++11 support enabled by default, provided the compiler
supports C++11. Qmake based projects can enable C++11 support explicitly
using 'CONFIG+=c++11' in their .pro files. To enable it conditionally, use
'contains(QT_CONFIG,c++11):CONFIG+=c++11'. This will enable C++11 support
only if Qt was built with C++11 support.
Third party components
----------------------

View File

@ -15,3 +15,6 @@ QMAKE_CFLAGS_PRECOMPILE = -x c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_
QMAKE_CFLAGS_USE_PRECOMPILE = -Xclang -include-pch -Xclang ${QMAKE_PCH_OUTPUT}
QMAKE_CXXFLAGS_PRECOMPILE = -x c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
QMAKE_CXXFLAGS_CXX11 = -std=c++11
QMAKE_LFLAGS_CXX11 =

View File

@ -28,3 +28,6 @@ QMAKE_CFLAGS_PRECOMPILE = -x c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH
QMAKE_CFLAGS_USE_PRECOMPILE = -include ${QMAKE_PCH_OUTPUT_BASE}
QMAKE_CXXFLAGS_PRECOMPILE = -x c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
QMAKE_CXXFLAGS_CXX11 = -std=c++0x
QMAKE_LFLAGS_CXX11 =

View File

@ -0,0 +1,3 @@
QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_CXX11
QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_CXXFLAGS_CXX11
QMAKE_LFLAGS += $$QMAKE_LFLAGS_CXX11

View File

@ -50,6 +50,7 @@ contains(QT_CONFIG, largefile):CONFIG += largefile
contains(QT_CONFIG, build_all):CONFIG += build_all
contains(QT_CONFIG, separate_debug_info):CONFIG += separate_debug_info
contains(QT_CONFIG, separate_debug_info_nocopy):CONFIG += separate_debug_info_nocopy
contains(QT_CONFIG, c++11):CONFIG += c++11
#mac frameworks
mac:!static:contains(QT_CONFIG, qt_framework) {

View File

@ -11,6 +11,7 @@ TARGET = $$qtLibraryTarget($$TARGET)
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
contains(QT_CONFIG, separate_debug_info):CONFIG += separate_debug_info
contains(QT_CONFIG, separate_debug_info_nocopy):CONFIG += separate_debug_info_nocopy
contains(QT_CONFIG, c++11):CONFIG += c++11
load(qt_targets)

View File

@ -35,6 +35,7 @@ QMAKE_CXXFLAGS_SHLIB = $$QMAKE_CFLAGS_SHLIB
QMAKE_CXXFLAGS_STATIC_LIB = $$QMAKE_CFLAGS_STATIC_LIB
QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC
QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD
QMAKE_CXXFLAGS_CXX11 = -std=c++0x
QMAKE_INCDIR =
QMAKE_LIBDIR =
@ -56,6 +57,7 @@ QMAKE_LFLAGS_SONAME = -Wl,-soname,
QMAKE_LFLAGS_THREAD =
QMAKE_LFLAGS_NOUNDEF = -Wl,-z,defs
QMAKE_LFLAGS_RPATH = -Wl,-rpath,
QMAKE_LFLAGS_CXX11 =
QMAKE_LIBS =
QMAKE_LIBS_DYNLOAD = -ldl