Detect C standard and try using the most recent one (take 2)

Fixes the default C version used with gcc < 5

Change-Id: I948dece961caed8e6b181e1c6e6b9dc43c46583e
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2018-02-14 13:40:57 +01:00
parent 17ae9305af
commit 591edbb11c
11 changed files with 103 additions and 7 deletions

View File

@ -260,6 +260,36 @@
"type": "compile",
"test": "stl"
},
"c99": {
"label": "C99 support",
"type": "compile",
"test": {
"head": [
"#if __STDC_VERSION__ >= 199901L",
"// Compiler claims to support C99, trust it",
"#else",
"# error __STDC_VERSION__ must be >= 199901L",
"#endif"
],
"lang": "c",
"qmake": "CONFIG += c99"
}
},
"c11": {
"label": "C11 support",
"type": "compile",
"test": {
"head": [
"#if __STDC_VERSION__ >= 201112L",
"// Compiler claims to support C11, trust it",
"#else",
"# error __STDC_VERSION__ must be >= 201112L",
"#endif"
],
"lang": "c",
"qmake": "CONFIG += c11"
}
},
"c++14": {
"label": "C++14 support",
"type": "compile",
@ -787,6 +817,19 @@
"condition": "features.c++14 && tests.c++1z",
"output": [ "publicFeature", "publicQtConfig" ]
},
"c89": {
"label": "C89"
},
"c99": {
"label": "C99",
"condition": "tests.c99",
"output": [ "publicFeature" ]
},
"c11": {
"label": "C11",
"condition": "features.c99 && tests.c11",
"output": [ "publicFeature" ]
},
"precompile_header": {
"label": "Using precompiled headers",
"condition": "config.msvc || tests.precompile_header",
@ -1247,6 +1290,11 @@ Configure with '-qreal float' to create a build that is binary-compatible with 5
"condition": "!features.debug || features.debug_and_release"
},
"shared",
{
"message": "Using C standard",
"type": "firstAvailableFeature",
"args": "c11 c99 c89"
},
{
"message": "Using C++ standard",
"type": "firstAvailableFeature",

View File

@ -30,6 +30,8 @@ QMAKE_CFLAGS_THREAD = -D_REENTRANT
QMAKE_CFLAGS_HIDESYMS = -fvisibility=hidden
QMAKE_CFLAGS_NEON = -mfpu=neon
QMAKE_CFLAGS_GNUC99 = -std=gnu99
QMAKE_CFLAGS_GNUC11 = -std=gnu11
QMAKE_CXXFLAGS_CXX11 = -std=c++11
QMAKE_CXXFLAGS_CXX14 = -std=c++14
QMAKE_CXXFLAGS_CXX1Z = -std=c++1z

View File

@ -21,6 +21,8 @@ QMAKE_CFLAGS_PRECOMPILE = -x c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_
QMAKE_CFLAGS_USE_PRECOMPILE = -Xclang -include-pch -Xclang ${QMAKE_PCH_OUTPUT}
QMAKE_CFLAGS_LTCG = -flto
QMAKE_CFLAGS_DISABLE_LTCG = -fno-lto
QMAKE_CFLAGS_GNUC99 = -std=gnu99
QMAKE_CFLAGS_GNUC11 = -std=gnu11
QMAKE_CXXFLAGS_PRECOMPILE = -x c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE

View File

@ -27,6 +27,8 @@ 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_CFLAGS_GNUC99 = -std=gnu99
QMAKE_CFLAGS_GNUC11 = -std=gnu11
QMAKE_CXXFLAGS_CXX11 = -std=c++11
QMAKE_CXXFLAGS_CXX14 = -std=c++1y
QMAKE_CXXFLAGS_CXX1Z = -std=c++1z

View File

@ -81,6 +81,9 @@ QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO +=
QMAKE_LFLAGS_EXCEPTIONS_OFF +=
QMAKE_LFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG -fuse-linker-plugin
QMAKE_CFLAGS_C99 = -std=c99
QMAKE_CFLAGS_C11 = -std=c11
QMAKE_CFLAGS_SSE2 += -msse2
QMAKE_CFLAGS_SSE3 += -msse3
QMAKE_CFLAGS_SSSE3 += -mssse3

View File

@ -143,6 +143,19 @@ c++11|c++14|c++1z {
unset(cxxstd)
}
c99|c11 {
c11: cstd = C11
else: cstd = C99
!isEmpty(QMAKE_CFLAGS_GNU$$cstd) {
!strict_c|isEmpty(QMAKE_CFLAGS_$$cstd): cstd = GNU$$cstd
}
QMAKE_CFLAGS += $$eval(QMAKE_CFLAGS_$$cstd)
unset(cstd)
}
utf8_source {
QMAKE_CFLAGS += $$QMAKE_CFLAGS_UTF8_SOURCE
QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_UTF8_SOURCE

View File

@ -17,6 +17,8 @@ DEFINES *= QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
qtConfig(c++11): CONFIG += c++11 strict_c++
qtConfig(c++14): CONFIG += c++14
qtConfig(c++1z): CONFIG += c++1z
qtConfig(c99): CONFIG += c99
qtConfig(c11): CONFIG += c11
qtConfig(stack-protector-strong): CONFIG += stack_protector_strong
contains(TEMPLATE, .*lib) {
# module and plugins

View File

@ -870,6 +870,15 @@ defineTest(qtConfTestPrepare_compile) {
defineTest(qtConfPrepareCompileTestSource) {
test_dir = $$2
test_lang = $$eval($${1}.lang)
isEmpty(test_lang): test_lang = "c++"
equals(test_lang, "c++"): suffix = "cpp"
else: equals(test_lang, "c"): suffix = "c"
else: equals(test_lang, "objc"): suffix = "m"
else: equals(test_lang, "objc++"): suffix = "mm"
else: error("Unknown language '$$test_lang' in compile test $$1")
# Create source code
contents = "/* Generated by configure */"
# Custom code before includes
@ -893,10 +902,10 @@ defineTest(qtConfPrepareCompileTestSource) {
" /* END TEST */" \
" return 0;" \
"}"
write_file($$test_dir/main.cpp, contents)|error()
write_file($$test_dir/main.$$suffix, contents)|error()
# Create stub .pro file
contents = "SOURCES = main.cpp"
contents = "SOURCES = main.$$suffix"
# Custom project code
for (ent, $$qtConfScalarOrList($${1}.qmake)): \
contents += $$ent

View File

@ -956,12 +956,25 @@
default is used.
\row \li thread \li Thread support is enabled. This is enabled when CONFIG
includes \c qt, which is the default.
\row \li c99 \li C99 support is enabled. This option has no effect if
the compiler does not support C99, or can't select the C standard.
By default, the compiler default is used.
\row \li c11 \li C11 support is enabled. This option has no effect if
the compiler does not support C11, or can't select the C standard.
By default, the compiler default is used.
\row \li strict_c Disables support for C compiler extensions.
By default, they are enabled.
\row \li c++11 \li C++11 support is enabled. This option has no effect if
the compiler does not support C++11.
By default, support is disabled.
the compiler does not support C++11, or can't select the C++ standard.
By default, support is enabled.
\row \li c++14 \li C++14 support is enabled. This option has no effect if
the compiler does not support C++14.
the compiler does not support C++14, or can't select the C++ standard.
By default, the compiler default is used.
\row \li c++1z \li C++17 support is enabled. This option has no effect if
the compiler does not support C++17, or can't select the C++ standard.
By default, support is disabled.
\row \li strict_c++ Disables support for C++ compiler extensions.
By default, they are enabled.
\row \li depend_includepath \li Appending the value of INCLUDEPATH to
DEPENDPATH is enabled. Set by default.
\endtable

View File

@ -1,4 +1,6 @@
QMAKE_CFLAGS += -std=gnu99 -w
# Requires GNU C extensions
CONFIG -= strict_c
INCLUDEPATH += $$PWD/xkbcommon \
$$PWD/xkbcommon/xkbcommon \
$$PWD/xkbcommon/src \

View File

@ -898,7 +898,7 @@
/* C11 features supported in GCC 4.7: */
# define Q_COMPILER_STATIC_ASSERT
# endif
# if Q_CC_GNU >= 409
# if Q_CC_GNU >= 409 && defined(__has_include)
/* C11 features supported in GCC 4.9: */
# if __has_include(<threads.h>)
# define Q_COMPILER_THREAD_LOCAL