diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2015-08-21 17:08:19 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2016-07-20 02:54:03 +0000 |
commit | 36d524e6a3b64a8c35805c1b868d6d67ccae765c (patch) | |
tree | 56a864ba56b3426f17cb202d4d8bbc9e9912aa55 /qmake/main.cpp | |
parent | 23bf3da5a0767f0c54824b4db1ecf23edeb71e91 (diff) | |
download | qtbase-36d524e6a3b64a8c35805c1b868d6d67ccae765c.tar.gz |
moc: get the system #defines from the compiler itself
In order for moc to properly parse #ifdefs and family, we've had
QMAKE_COMPILER_DEFINES as a list of pre-defined macros from the
compiler. That list is woefully incomplete.
Instead, let's simply ask the compiler for the list. With GCC and
family, we use the -dM flag while preprocessing. With ICC on Windows,
the flag gains an extra "Q" but is otherwise the same. For MSVC, it
requires using some undocumented switches and parsing environment
variables (I've tested MSVC 2012, 2013 and 2015).
The new moc option is called --include to be similar to GCC's -include
option. It does more than just parse a list of pre-defined macros and
can be used to insert any sort of code that moc needs to parse prior to
the main file.
Change-Id: I7de033f80b0e4431b7f1ffff13fca02dbb60a0a6
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'qmake/main.cpp')
-rw-r--r-- | qmake/main.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/qmake/main.cpp b/qmake/main.cpp index 8410e83cbf..6d7e023b41 100644 --- a/qmake/main.cpp +++ b/qmake/main.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the qmake application of the Qt Toolkit. @@ -42,6 +43,10 @@ #include <sys/types.h> #include <sys/stat.h> +#ifdef Q_OS_WIN +# include <qt_windows.h> +#endif + QT_BEGIN_NAMESPACE #ifdef Q_OS_WIN @@ -241,6 +246,30 @@ static int doInstall(int argc, char **argv) return 3; } +static int dumpMacros(const wchar_t *cmdline) +{ + // from http://stackoverflow.com/questions/3665537/how-to-find-out-cl-exes-built-in-macros + int argc; + wchar_t **argv = CommandLineToArgvW(cmdline, &argc); + if (!argv) + return 2; + for (int i = 0; i < argc; ++i) { + if (argv[i][0] != L'-' || argv[i][1] != 'D') + continue; + + wchar_t *value = wcschr(argv[i], L'='); + if (value) { + *value = 0; + ++value; + } else { + // point to the NUL at the end, so we don't print anything + value = argv[i] + wcslen(argv[i]); + } + wprintf(L"#define %Ls %Ls\n", argv[i] + 2, value); + } + return 0; +} + #endif // Q_OS_WIN /* This is to work around lame implementation on Darwin. It has been noted that the getpwd(3) function @@ -275,6 +304,15 @@ int runQMake(int argc, char **argv) // Workaround for inferior/missing command line tools on Windows: make our own! if (argc >= 2 && !strcmp(argv[1], "-install")) return doInstall(argc - 2, argv + 2); + + { + // Support running as Visual C++'s compiler + const wchar_t *cmdline = _wgetenv(L"MSC_CMD_FLAGS"); + if (!cmdline || !*cmdline) + cmdline = _wgetenv(L"MSC_IDE_FLAGS"); + if (cmdline && *cmdline) + return dumpMacros(cmdline); + } #endif QMakeVfs vfs; |