summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-12-03 19:38:44 (GMT)
committerBrad King <brad.king@kitware.com>2015-12-03 19:51:38 (GMT)
commitd2ef49b321a3a8f33662b46183a778478e834411 (patch)
treecba3d4b9536a67a9ab0de57ad9d89f568bf00f5a /src
parente79f75a52e3da64686dcf56a1befcd17b26bbb55 (diff)
downloadCastXML-d2ef49b321a3a8f33662b46183a778478e834411.zip
CastXML-d2ef49b321a3a8f33662b46183a778478e834411.tar.gz
CastXML-d2ef49b321a3a8f33662b46183a778478e834411.tar.bz2
Add predefined macros for versions of CastXML and internal Clang
Some translation units may need to know the real tool that is performing the preprocessing even when --castxml-cc-<id> switches predefined macros to those from another compiler. Provide dedicated version macros for both CastXML and the internal Clang against which it is built.
Diffstat (limited to 'src')
-rw-r--r--src/RunClang.cxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/RunClang.cxx b/src/RunClang.cxx
index fcd9ef9..bba6be6 100644
--- a/src/RunClang.cxx
+++ b/src/RunClang.cxx
@@ -24,6 +24,7 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
+#include "clang/Basic/Version.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/DriverDiagnostic.h"
@@ -151,6 +152,28 @@ protected:
std::string builtins;
+ // Add a builtin to identify CastXML itself.
+ char castxml_version[64];
+ sprintf(castxml_version, "#define __castxml__ %u\n", getVersionValue());
+ builtins += castxml_version;
+
+ // Add builtins to identify the internal Clang compiler.
+ builtins +=
+#define STR(x) STR_(x)
+#define STR_(x) #x
+ "#define __castxml_clang_major__ " STR(CLANG_VERSION_MAJOR) "\n"
+ "#define __castxml_clang_minor__ " STR(CLANG_VERSION_MINOR) "\n"
+ "#define __castxml_clang_patchlevel__ "
+#ifdef CLANG_VERSION_PATCHLEVEL
+ STR(CLANG_VERSION_PATCHLEVEL)
+#else
+ "0"
+#endif
+ "\n"
+#undef STR
+#undef STR_
+ ;
+
// If we detected predefines from another compiler, substitute them.
if (this->Opts.HaveCC) {
builtins += this->Opts.Predefines;