summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-04-16 19:43:09 (GMT)
committerBrad King <brad.king@kitware.com>2015-04-16 19:43:38 (GMT)
commit3c777ef360beb3a37fec567806f56d0f9aab9bd6 (patch)
treef20cff5aea3ce4755b305e47a33d55f9621c9582 /src
parent43fa139ddd22813b4cc96e244ecd3d9d51ab5cc5 (diff)
downloadCastXML-3c777ef360beb3a37fec567806f56d0f9aab9bd6.zip
CastXML-3c777ef360beb3a37fec567806f56d0f9aab9bd6.tar.gz
CastXML-3c777ef360beb3a37fec567806f56d0f9aab9bd6.tar.bz2
Detect: Improve target triple selection
Use llvm::Triple to compute the triple string for us. Start with the builtin default triple and modify its components based on what we find in the detected preprocessor definitions. Then recompose the final target triple.
Diffstat (limited to 'src')
-rw-r--r--src/Detect.cxx28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/Detect.cxx b/src/Detect.cxx
index d9d2607..d3f6d23 100644
--- a/src/Detect.cxx
+++ b/src/Detect.cxx
@@ -18,6 +18,9 @@
#include "Options.h"
#include "Utils.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Host.h"
+
#include <cxsys/SystemTools.hxx>
#include <iostream>
@@ -89,30 +92,25 @@ static void fixPredefines(Options& opts)
static void setTriple(Options& opts)
{
std::string const& pd = opts.Predefines;
- std::string arch;
- std::string os;
+ llvm::Triple triple(llvm::sys::getDefaultTargetTriple());
if(pd.find("#define __x86_64__ 1") != pd.npos ||
pd.find("#define _M_X64 ") != pd.npos) {
- arch = "x86_64";
+ triple.setArchName("x86_64");
} else if(pd.find("#define __amd64__ 1") != pd.npos ||
pd.find("#define _M_AMD64 ") != pd.npos) {
- arch = "amd64";
+ triple.setArchName("amd64");
} else if(pd.find("#define __i386__ 1") != pd.npos ||
pd.find("#define _M_IX86 ") != pd.npos) {
- arch = "i386";
+ triple.setArchName("i386");
}
- if(pd.find("#define __MINGW32__ 1") != pd.npos) {
- if(arch.find("64") != arch.npos) {
- os = "w64-mingw32";
- } else {
- os = "pc-mingw32";
- }
- } else if(pd.find("#define _WIN32 1") != pd.npos) {
- os = "pc-win32";
+ if(pd.find("#define _WIN32 1") != pd.npos) {
+ triple.setVendorName("pc");
+ triple.setOSName("windows");
}
- if(!arch.empty() && !os.empty()) {
- opts.Triple = arch + "-" + os;
+ if(pd.find("#define __MINGW32__ 1") != pd.npos) {
+ triple.setEnvironmentName("gnu");
}
+ opts.Triple = triple.getTriple();
}
//----------------------------------------------------------------------------