forked from qt-creator/qt-creator
ProjectExplorer: Update known predefined macros for MSVC
...and add a comment explaining what we do and why we do it this way. The added macros were collected as stated in the comment for MSVC versions (x86, amd64) 2003 - 2017. Note that for Visual Studio 2017 there is no "Predefined macros" page yet. Change-Id: I7601be08d7a0bbb63077abe9657d203661f76cb9 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -262,28 +262,51 @@ static QByteArray msvcCompilationFile()
|
|||||||
{
|
{
|
||||||
static const char* macros[] = {
|
static const char* macros[] = {
|
||||||
"_ATL_VER",
|
"_ATL_VER",
|
||||||
|
"__ATOM__",
|
||||||
|
"__AVX__",
|
||||||
|
"__AVX2__",
|
||||||
"_CHAR_UNSIGNED",
|
"_CHAR_UNSIGNED",
|
||||||
"__CLR_VER",
|
"__CLR_VER",
|
||||||
|
"_CMMN_INTRIN_FUNC",
|
||||||
|
"_CONTROL_FLOW_GUARD",
|
||||||
"__COUNTER__",
|
"__COUNTER__",
|
||||||
"__cplusplus",
|
"__cplusplus",
|
||||||
"__cplusplus_cli",
|
"__cplusplus_cli",
|
||||||
|
"__cplusplus_winrt",
|
||||||
"_CPPLIB_VER",
|
"_CPPLIB_VER",
|
||||||
"_CPPRTTI",
|
"_CPPRTTI",
|
||||||
"_CPPUNWIND",
|
"_CPPUNWIND",
|
||||||
"__DATE__",
|
"__DATE__",
|
||||||
"_DEBUG",
|
"_DEBUG",
|
||||||
"_DLL",
|
"_DLL",
|
||||||
|
"__FILE__",
|
||||||
|
"__func__",
|
||||||
"__FUNCDNAME__",
|
"__FUNCDNAME__",
|
||||||
"__FUNCSIG__",
|
"__FUNCSIG__",
|
||||||
"__FUNCTION__",
|
"__FUNCTION__",
|
||||||
"_INTEGRAL_MAX_BITS",
|
"_INTEGRAL_MAX_BITS",
|
||||||
|
"__INTELLISENSE__",
|
||||||
|
"_ISO_VOLATILE",
|
||||||
|
"_KERNEL_MODE",
|
||||||
|
"__LINE__",
|
||||||
"_M_AAMD64",
|
"_M_AAMD64",
|
||||||
"_M_ALPHA",
|
"_M_ALPHA",
|
||||||
|
"_M_AMD64",
|
||||||
"_MANAGED",
|
"_MANAGED",
|
||||||
|
"_M_ARM",
|
||||||
|
"_M_ARM64",
|
||||||
|
"_M_ARM_ARMV7VE",
|
||||||
|
"_M_ARM_FP",
|
||||||
|
"_M_ARM_NT",
|
||||||
|
"_M_ARMT",
|
||||||
"_M_CEE",
|
"_M_CEE",
|
||||||
"_M_CEE_PURE",
|
"_M_CEE_PURE",
|
||||||
"_M_CEE_SAFE",
|
"_M_CEE_SAFE",
|
||||||
"_MFC_VER",
|
"_MFC_VER",
|
||||||
|
"_M_FP_EXCEPT",
|
||||||
|
"_M_FP_FAST",
|
||||||
|
"_M_FP_PRECISE",
|
||||||
|
"_M_FP_STRICT",
|
||||||
"_M_IA64",
|
"_M_IA64",
|
||||||
"_M_IX86",
|
"_M_IX86",
|
||||||
"_M_IX86_FP",
|
"_M_IX86_FP",
|
||||||
@@ -294,11 +317,17 @@ static QByteArray msvcCompilationFile()
|
|||||||
"_MSC_EXTENSIONS",
|
"_MSC_EXTENSIONS",
|
||||||
"_MSC_FULL_VER",
|
"_MSC_FULL_VER",
|
||||||
"_MSC_VER",
|
"_MSC_VER",
|
||||||
|
"_MSVC_LANG",
|
||||||
"__MSVC_RUNTIME_CHECKS",
|
"__MSVC_RUNTIME_CHECKS",
|
||||||
"_MT",
|
"_MT",
|
||||||
|
"_M_THUMB",
|
||||||
"_M_X64",
|
"_M_X64",
|
||||||
"_NATIVE_WCHAR_T_DEFINED",
|
"_NATIVE_WCHAR_T_DEFINED",
|
||||||
"_OPENMP",
|
"_OPENMP",
|
||||||
|
"_PREFAST_",
|
||||||
|
"__STDC__",
|
||||||
|
"__STDC_HOSTED__",
|
||||||
|
"__STDCPP_THREADS__",
|
||||||
"__TIME__",
|
"__TIME__",
|
||||||
"__TIMESTAMP__",
|
"__TIMESTAMP__",
|
||||||
"_VC_NODEFAULTLIB",
|
"_VC_NODEFAULTLIB",
|
||||||
@@ -306,6 +335,7 @@ static QByteArray msvcCompilationFile()
|
|||||||
"_WIN32",
|
"_WIN32",
|
||||||
"_WIN32_WCE",
|
"_WIN32_WCE",
|
||||||
"_WIN64",
|
"_WIN64",
|
||||||
|
"_WINRT_DLL",
|
||||||
"_Wp64",
|
"_Wp64",
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
@@ -320,7 +350,62 @@ static QByteArray msvcCompilationFile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run MSVC 'cl' compiler to obtain #defines.
|
// Run MSVC 'cl' compiler to obtain #defines.
|
||||||
// Function must be thread-safe!
|
// This function must be thread-safe!
|
||||||
|
//
|
||||||
|
// Some notes regarding the used approach:
|
||||||
|
//
|
||||||
|
// It seems that there is no reliable way to get all the
|
||||||
|
// predefined macros for a cl invocation. The following two
|
||||||
|
// approaches are unfortunately limited since both lead to an
|
||||||
|
// incomplete list of actually predefined macros and come with
|
||||||
|
// other problems, too.
|
||||||
|
//
|
||||||
|
// 1) Maintain a list of predefined macros from the official
|
||||||
|
// documentation (for MSVC2015, e.g. [1]). Feed cl with a
|
||||||
|
// temporary file that queries the values of those macros.
|
||||||
|
//
|
||||||
|
// Problems:
|
||||||
|
// * Maintaining that list.
|
||||||
|
// * The documentation is incomplete, we do not get all
|
||||||
|
// predefined macros. E.g. the cl from MSVC2015, set up
|
||||||
|
// with "vcvars.bat x86_arm", predefines among others
|
||||||
|
// _M_ARMT, but that's not reflected in the
|
||||||
|
// documentation.
|
||||||
|
//
|
||||||
|
// 2) Run cl with the undocumented options /B1 and /Bx, as
|
||||||
|
// described in [2].
|
||||||
|
//
|
||||||
|
// Note: With qmake from Qt >= 5.8 it's possible to print
|
||||||
|
// the macros formatted as preprocessor code in an easy to
|
||||||
|
// read/compare/diff way:
|
||||||
|
//
|
||||||
|
// > cl /nologo /c /TC /B1 qmake NUL
|
||||||
|
// > cl /nologo /c /TP /Bx qmake NUL
|
||||||
|
//
|
||||||
|
// Problems:
|
||||||
|
// * Using undocumented options.
|
||||||
|
// * Resulting macros are incomplete.
|
||||||
|
// For example, the nowadays default option /Zc:wchar_t
|
||||||
|
// predefines _WCHAR_T_DEFINED, but this is not reflected
|
||||||
|
// with this approach.
|
||||||
|
//
|
||||||
|
// To work around this we would need extra cl invocations
|
||||||
|
// to get the actual values of the missing macros
|
||||||
|
// (approach 1).
|
||||||
|
//
|
||||||
|
// Currently we combine both approaches in this way:
|
||||||
|
// * As base, maintain the list from the documentation and
|
||||||
|
// update it once a new MSVC version is released.
|
||||||
|
// * Enrich it with macros that we discover with approach 2
|
||||||
|
// once a new MSVC version is released.
|
||||||
|
// * Enrich it further with macros that are not covered with
|
||||||
|
// the above points.
|
||||||
|
//
|
||||||
|
// TODO: Update the predefined macros for MSVC 2017 once the
|
||||||
|
// page exists.
|
||||||
|
//
|
||||||
|
// [1] https://msdn.microsoft.com/en-us/library/b0084kay.aspx
|
||||||
|
// [2] http://stackoverflow.com/questions/3665537/how-to-find-out-cl-exes-built-in-macros
|
||||||
QByteArray MsvcToolChain::msvcPredefinedMacros(const QStringList cxxflags,
|
QByteArray MsvcToolChain::msvcPredefinedMacros(const QStringList cxxflags,
|
||||||
const Utils::Environment &env) const
|
const Utils::Environment &env) const
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user