determine compiler version at build time, not in configure

this makes it consistent with the determination of the default
include/library paths. this makes sense, as it's possible to switch the
sdk/toolchain after building qt (within reason).

a side effect of this change is that for compilers which emulate other
compilers, both the real and the emulated version are now made
available.

Change-Id: Icfcc672c0d2e3d1b5e622993c366063d70ad327c
Started-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Oswald Buddenhagen 2016-12-15 16:20:27 +01:00
parent d0db09681f
commit 1b5271f27f
14 changed files with 108 additions and 83 deletions

View File

@ -1 +0,0 @@
_MSC_FULL_VER

View File

@ -253,11 +253,6 @@
"type": "compile",
"test": "common/c++98default"
},
"compiler": {
"label": "Compiler",
"type": "checkCompiler",
"log": "compilerDescription"
},
"precompile_header": {
"label": "precompiled header support",
"type": "compile",
@ -684,11 +679,6 @@
"condition": "features.c++14 && tests.c++1z",
"output": [ "publicFeature", "publicQtConfig" ]
},
"compiler": {
"label": "Compiler version",
"condition": "tests.compiler",
"output": [ "compilerVersion" ]
},
"precompile_header": {
"label": "Using precompiled headers",
"condition": "config.msvc || tests.precompile_header",

View File

@ -397,50 +397,6 @@ defineTest(qtConfTest_buildParts) {
return(true)
}
defineTest(qtConfTest_checkCompiler) {
contains(QMAKE_CXX, ".*clang.*") {
qtRunLoggedCommand("$$QMAKE_CXX -v 2>&1", versionstr)|return(false)
versionstr = "$$versionstr"
contains(versionstr, "^Apple (clang|LLVM) version .*") {
$${1}.compilerDescription = "Apple Clang"
$${1}.compilerId = "apple_clang"
$${1}.compilerVersion = $$replace(versionstr, "^Apple (clang|LLVM) version ([0-9.]+).*$", "\\2")
} else: contains(versionstr, ".*clang version.*") {
$${1}.compilerDescription = "Clang"
$${1}.compilerId = "clang"
$${1}.compilerVersion = $$replace(versionstr, "^.*clang version ([0-9.]+).*", "\\1")
} else {
return(false)
}
} else: contains(QMAKE_CXX, ".*g\\+\\+.*") {
qtRunLoggedCommand("$$QMAKE_CXX -dumpversion", version)|return(false)
$${1}.compilerDescription = "GCC"
$${1}.compilerId = "gcc"
$${1}.compilerVersion = $$version
} else: contains(QMAKE_CXX, ".*icpc") {
qtRunLoggedCommand("$$QMAKE_CXX -dumpversion", version)|return(false)
$${1}.compilerDescription = "ICC"
$${1}.compilerId = "icc"
$${1}.compilerVersion = $$version
} else: msvc {
command = $$QMAKE_CXX /EP /nologo $$source $$system_quote($$QMAKE_CONFIG_TESTS_DIR/win/msvc_version.cpp)
qtRunLoggedCommand("$$command", version)|return(false)
version = "$$version"
$${1}.compilerDescription = "MSVC"
$${1}.compilerId = "cl"
$${1}.compilerVersion = $$replace(version, "^.*([0-9]{2})([0-9]{2})([0-9]{5}).*$", "\\1.\\2.\\3")
} else {
return(false)
}
$${1}.compilerDescription += $$eval($${1}.compilerVersion)
export($${1}.compilerDescription)
export($${1}.compilerId)
export($${1}.compilerVersion)
$${1}.cache += compilerDescription compilerId compilerVersion
export($${1}.cache)
return(true)
}
# custom outputs
# this reloads the qmakespec as completely as reasonably possible.
@ -947,25 +903,6 @@ defineTest(qtConfOutput_debugAndRelease) {
}
}
defineTest(qtConfOutput_compilerVersion) {
!$${2}: return()
name = $$upper($$eval($${currentConfig}.tests.compiler.compilerId))
version = $$eval($${currentConfig}.tests.compiler.compilerVersion)
major = $$section(version, '.', 0, 0)
minor = $$section(version, '.', 1, 1)
patch = $$section(version, '.', 2, 2)
isEmpty(minor): minor = 0
isEmpty(patch): patch = 0
$${currentConfig}.output.publicPro += \
"QT_$${name}_MAJOR_VERSION = $$major" \
"QT_$${name}_MINOR_VERSION = $$minor" \
"QT_$${name}_PATCH_VERSION = $$patch"
export($${currentConfig}.output.publicPro)
}
defineTest(qtConfOutput_compilerFlags) {
# this output also exports the variables locally, so that subsequent compiler tests can use them

View File

@ -16,7 +16,7 @@ QMAKE_PLATFORM = win32
QMAKE_COMPILER = msvc
CONFIG += incremental flat precompile_header autogen_precompile_source debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe
DEFINES += UNICODE WIN32
QMAKE_COMPILER_DEFINES += _MSC_VER=$$MSC_VER _WIN32
QMAKE_COMPILER_DEFINES += _WIN32
contains(QMAKE_TARGET.arch, x86_64) {
DEFINES += WIN64
QMAKE_COMPILER_DEFINES += _WIN64

View File

@ -0,0 +1,28 @@
// Keep this file small. The pre-processed contents are eval'd by qmake.
#ifdef _MSC_VER
QMAKE_MSC_VER = _MSC_VER
QMAKE_MSC_FULL_VER = _MSC_FULL_VER
#endif
#ifdef __INTEL_COMPILER
QMAKE_ICC_VER = __INTEL_COMPILER
QMAKE_ICC_UPDATE_VER = __INTEL_COMPILER_UPDATE
#endif
#ifdef __APPLE_CC__
QMAKE_APPLE_CC = __APPLE_CC__
#endif
#ifdef __clang__
#ifdef __APPLE_CC__
QT_APPLE_CLANG_MAJOR_VERSION = __clang_major__
QT_APPLE_CLANG_MINOR_VERSION = __clang_minor__
QT_APPLE_CLANG_PATCH_VERSION = __clang_patchlevel__
#else
QT_CLANG_MAJOR_VERSION = __clang_major__
QT_CLANG_MINOR_VERSION = __clang_minor__
QT_CLANG_PATCH_VERSION = __clang_patchlevel__
#endif
#endif
#ifdef __GNUC__
QT_GCC_MAJOR_VERSION = __GNUC__
QT_GCC_MINOR_VERSION = __GNUC_MINOR__
QT_GCC_PATCH_VERSION = __GNUC_PATCHLEVEL__
#endif

View File

@ -58,3 +58,79 @@ isEmpty(QMAKE_DEFAULT_INCDIRS):!host_build {
!isEmpty(QMAKE_DEFAULT_INCDIRS): cache(QMAKE_DEFAULT_INCDIRS, set stash)
!isEmpty(QMAKE_DEFAULT_LIBDIRS): cache(QMAKE_DEFAULT_LIBDIRS, set stash)
}
#
# Determine and cache the compiler version
#
defineReplace(qtVariablesFromMSVC) {
return($$system("$$1 -nologo -E $$2 $$system_quote($$PWD/data/macros.cpp) <NUL 2>NUL", lines))
}
defineReplace(qtVariablesFromGCC) {
null_device = /dev/null
equals(QMAKE_HOST.os, Windows): null_device = NUL
return($$system("$$1 -E $$system_quote($$PWD/data/macros.cpp) <$$null_device 2>$$null_device", lines))
}
host_build: \
target_prefix = QMAKE_HOST_CXX
else: \
target_prefix = QMAKE_CXX
isEmpty($${target_prefix}.COMPILER_MACROS) {
msvc {
vars = $$qtVariablesFromMSVC($$QMAKE_CXX $$QMAKE_CXXFLAGS)
} else: gcc {
vars = $$qtVariablesFromGCC($$QMAKE_CXX)
}
for (v, vars) {
isEmpty(v)|contains(v, $${LITERAL_HASH}.*): next()
# Set both <varname> for the outer scope ...
eval($$v)
v ~= s/ .*//
isEmpty($$v): error("Compiler produced empty value for $${v}.")
# ... and save QMAKE_(HOST_)?CXX.<varname> in the cache.
cache($${target_prefix}.$$v, set stash, $$v)
$${target_prefix}.COMPILER_MACROS += $$v
}
cache($${target_prefix}.COMPILER_MACROS, set stash)
} else {
# load from the cache
for (i, $${target_prefix}.COMPILER_MACROS): \
$$i = $$eval($${target_prefix}.$$i)
}
unset(target_prefix)
# Populate QMAKE_COMPILER_DEFINES and some compatibility variables.
# The $$format_number() calls strip leading zeros to avoid misinterpretation as octal.
!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")
QT_MSVC_MINOR_VERSION = $$format_number($$replace(QMAKE_MSC_FULL_VER, "(..)(..)(.*)", "\\2"))
QT_MSVC_PATCH_VERSION = $$replace(QMAKE_MSC_FULL_VER, "(..)(..)(.*)", "\\3"))
}
!isEmpty(QMAKE_ICC_VER) {
QMAKE_COMPILER_DEFINES += __INTEL_COMPILER=$$QMAKE_ICC_VER __INTEL_COMPILER_UPDATE=$$QMAKE_ICC_UPDATE_VER
QT_ICC_MAJOR_VERSION = $$replace(QMAKE_ICC_VER, "(..)(..)", "\\1")
QT_ICC_MINOR_VERSION = $$format_number($$replace(QMAKE_ICC_VER, "(..)(..)", "\\2"))
QT_ICC_PATCH_VERSION = $$QMAKE_ICC_UPDATE_VER
}
!isEmpty(QMAKE_APPLE_CC): \
QMAKE_COMPILER_DEFINES += __APPLE_CC__=$$QMAKE_APPLE_CC
!isEmpty(QT_APPLE_CLANG_MAJOR_VERSION): \
QMAKE_COMPILER_DEFINES += __clang__ \
__clang_major__=$$QT_APPLE_CLANG_MAJOR_VERSION \
__clang_minor__=$$QT_APPLE_CLANG_MINOR_VERSION \
__clang_patchlevel__=$$QT_APPLE_CLANG_PATCH_VERSION
!isEmpty(QT_CLANG_MAJOR_VERSION): \
QMAKE_COMPILER_DEFINES += __clang__ \
__clang_major__=$$QT_CLANG_MAJOR_VERSION \
__clang_minor__=$$QT_CLANG_MINOR_VERSION \
__clang_patchlevel__=$$QT_CLANG_PATCH_VERSION
!isEmpty(QT_GCC_MAJOR_VERSION): \
QMAKE_COMPILER_DEFINES += \
__GNUC__=$$QT_GCC_MAJOR_VERSION \
__GNUC_MINOR__=$$QT_GCC_MINOR_VERSION \
__GNUC_PATCHLEVEL__=$$QT_GCC_PATCH_VERSION

View File

@ -5,7 +5,6 @@
#
include(../common/winrt_winphone/qmake.conf)
QMAKE_COMPILER_DEFINES += _MSC_VER=1800
QMAKE_PLATFORM = winphone $$QMAKE_PLATFORM
DEFINES += WINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP ARM __ARM__ __ARM__
CONFIG += no_generated_target_info

View File

@ -5,7 +5,6 @@
#
include(../common/winrt_winphone/qmake.conf)
QMAKE_COMPILER_DEFINES += _MSC_VER=1800
QMAKE_PLATFORM = winphone $$QMAKE_PLATFORM
DEFINES += WINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP X86 __X86__ __x86__
CONFIG += no_generated_target_info

View File

@ -5,7 +5,6 @@
#
include(../common/winrt_winphone/qmake.conf)
QMAKE_COMPILER_DEFINES += _MSC_VER=1800
DEFINES += WINAPI_FAMILY=WINAPI_FAMILY_PC_APP ARM __ARM__ __arm__
QMAKE_CFLAGS += -FS

View File

@ -6,7 +6,6 @@
MSC_VER = 1900
include(../common/winrt_winphone/qmake.conf)
QMAKE_COMPILER_DEFINES += _MSC_VER=1900
DEFINES += WINAPI_FAMILY=WINAPI_FAMILY_PC_APP WINAPI_PARTITION_PHONE_APP=1 ARM __ARM__ __arm__
QMAKE_CFLAGS += -FS

View File

@ -5,7 +5,6 @@
#
include(../common/winrt_winphone/qmake.conf)
QMAKE_COMPILER_DEFINES += _MSC_VER=1800
DEFINES += WINAPI_FAMILY=WINAPI_FAMILY_APP X64 __X64__ __x64__
QMAKE_CFLAGS += -FS

View File

@ -6,7 +6,7 @@
MSC_VER = 1900
include(../common/winrt_winphone/qmake.conf)
QMAKE_COMPILER_DEFINES += _MSC_VER=1900 _WIN32
QMAKE_COMPILER_DEFINES += _WIN32
DEFINES += WINAPI_FAMILY=WINAPI_FAMILY_PC_APP WINAPI_PARTITION_PHONE_APP=1 X64 __X64__ __x64__
QMAKE_CFLAGS += -FS

View File

@ -5,7 +5,7 @@
#
include(../common/winrt_winphone/qmake.conf)
QMAKE_COMPILER_DEFINES += _MSC_VER=1800 _WIN32
QMAKE_COMPILER_DEFINES += _WIN32
DEFINES += WINAPI_FAMILY=WINAPI_FAMILY_PC_APP X86 __X86__ __x86__
QMAKE_CFLAGS += -FS

View File

@ -6,7 +6,7 @@
MSC_VER = 1900
include(../common/winrt_winphone/qmake.conf)
QMAKE_COMPILER_DEFINES += _MSC_VER=1900 _WIN32
QMAKE_COMPILER_DEFINES += _WIN32
DEFINES += WINAPI_FAMILY=WINAPI_FAMILY_PC_APP WINAPI_PARTITION_PHONE_APP=1 X86 __X86__ __x86__
QMAKE_CFLAGS += -FS