summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-02-04 14:59:29 (GMT)
committerBrad King <brad.king@kitware.com>2015-02-04 14:59:29 (GMT)
commit8d8aacd65af229da0cadf81911ffa3ef77db7b57 (patch)
tree7a85fbe387dae1fb9667176fe6ce350df28e09f0
parent1074cb11ebdc29bff2fc7eb633252348e0758106 (diff)
downloadCastXML-8d8aacd65af229da0cadf81911ffa3ef77db7b57.zip
CastXML-8d8aacd65af229da0cadf81911ffa3ef77db7b57.tar.gz
CastXML-8d8aacd65af229da0cadf81911ffa3ef77db7b57.tar.bz2
Detect: Use Clang builtin include dir even with --castxml-cc-<id>
We need implementation-provided headers to come from Clang to match what is really built in to the parser. When not using --castxml-cc-<id>, the Clang driver adds its builtin include directory in methods like Linux::AddClangSystemIncludeArgs MSVCToolChain::AddClangSystemIncludeArgs CrossWindowsToolChain::AddClangSystemIncludeArgs (see lib/Driver/*ToolChain*.cpp). When using --castxml-cc-<id>, we must add the Clang builtin include dir in the appropriate place. GNU-like compilers should have a builtin include directory too, providing files like <emmintrin.h>. The Clang driver does not add this directory from GCC toolchains and instead adds its own builtin include directory. In this case, replace the detected compiler builtin include directory with ours. MSVC-like compilers have no separate builtin include directory. The Clang driver simply places its own builtin include direcory before the system include directory read from the INCLUDE environment variable. In this case, do the same.
-rw-r--r--src/Detect.cxx12
-rw-r--r--test/CMakeLists.txt2
-rw-r--r--test/cc-gnu-builtin/emmintrin.h0
-rw-r--r--test/cc-gnu.c1
-rw-r--r--test/expect/cmd.cc-gnu-c-cmd.stderr.txt2
-rw-r--r--test/expect/cmd.cc-gnu-cxx-cmd.stderr.txt2
-rw-r--r--test/expect/cmd.cc-msvc-c-cmd.stderr.txt2
-rw-r--r--test/expect/cmd.cc-msvc-cxx-cmd.stderr.txt2
8 files changed, 19 insertions, 4 deletions
diff --git a/src/Detect.cxx b/src/Detect.cxx
index 7e7cfc4..4db82f9 100644
--- a/src/Detect.cxx
+++ b/src/Detect.cxx
@@ -24,6 +24,12 @@
#include <string.h>
//----------------------------------------------------------------------------
+static std::string getClangBuiltinIncludeDir()
+{
+ return getClangResourceDir() + "/include";
+}
+
+//----------------------------------------------------------------------------
static bool failedCC(const char* id,
std::vector<const char*> const& args,
std::string const& out,
@@ -118,6 +124,10 @@ static bool detectCC_GNU(const char* const* argBeg,
(inc.substr(inc.size()-fwImplicitSuffix.size()) ==
fwImplicitSuffix));
}
+ // Replace the compiler builtin include directory with ours.
+ if(!fw && cxsys::SystemTools::FileExists((inc+"/emmintrin.h"))) {
+ inc = getClangBuiltinIncludeDir();
+ }
opts.Includes.push_back(Options::Include(inc, fw));
}
}
@@ -149,6 +159,8 @@ static bool detectCC_MSVC(const char* const* argBeg,
if(const char* predefs = strstr(out.c_str(), "\n#define")) {
opts.Predefines = predefs+1;
}
+ // Prepend the Clang compiler builtin include directory.
+ opts.Includes.push_back(getClangBuiltinIncludeDir());
if(const char* includes_str = cxsys::SystemTools::GetEnv("INCLUDE")) {
std::vector<std::string> includes;
cxsys::SystemTools::Split(includes_str, includes, ';');
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index db8bc74..1725bbb 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -123,6 +123,8 @@ castxml_test_cmd(rsp-o-missing @${input}/o-missing.rsp)
# Test --castxml-cc-gnu detection.
add_executable(cc-gnu cc-gnu.c)
+set_property(SOURCE cc-gnu.c APPEND PROPERTY COMPILE_DEFINITIONS
+ "TEST_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"")
castxml_test_cmd(cc-gnu-c-E --castxml-cc-gnu $<TARGET_FILE:cc-gnu> ${empty_c} -E -dM)
castxml_test_cmd(cc-gnu-c-cmd --castxml-cc-gnu $<TARGET_FILE:cc-gnu> ${empty_c} "-###")
castxml_test_cmd(cc-gnu-cxx-E --castxml-cc-gnu $<TARGET_FILE:cc-gnu> ${empty_cxx} -E -dM)
diff --git a/test/cc-gnu-builtin/emmintrin.h b/test/cc-gnu-builtin/emmintrin.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/cc-gnu-builtin/emmintrin.h
diff --git a/test/cc-gnu.c b/test/cc-gnu.c
index b1cb2ea..2bf616d 100644
--- a/test/cc-gnu.c
+++ b/test/cc-gnu.c
@@ -8,6 +8,7 @@ int main(void)
fprintf(stderr,
"#include <...> search starts here:\n"
" /some/include\n"
+ " " TEST_DIR "/cc-gnu-builtin\n"
" /some/Frameworks\n"
" /some/CustomFW (framework directory)\n"
);
diff --git a/test/expect/cmd.cc-gnu-c-cmd.stderr.txt b/test/expect/cmd.cc-gnu-c-cmd.stderr.txt
index 1ac617b..175c3bd 100644
--- a/test/expect/cmd.cc-gnu-c-cmd.stderr.txt
+++ b/test/expect/cmd.cc-gnu-c-cmd.stderr.txt
@@ -1 +1 @@
-"clang" .* "-[^i][^"]*" "[^-"][^"]*" "-isystem" "/some/include" "-iframework" "/some/Frameworks" "-iframework" "/some/CustomFW" "-[^i]
+"clang" .* "-[^i][^"]*" "[^-"][^"]*" "-isystem" "/some/include" "-isystem" "[^"]*/include" "-iframework" "/some/Frameworks" "-iframework" "/some/CustomFW" "-[^i]
diff --git a/test/expect/cmd.cc-gnu-cxx-cmd.stderr.txt b/test/expect/cmd.cc-gnu-cxx-cmd.stderr.txt
index 1ac617b..175c3bd 100644
--- a/test/expect/cmd.cc-gnu-cxx-cmd.stderr.txt
+++ b/test/expect/cmd.cc-gnu-cxx-cmd.stderr.txt
@@ -1 +1 @@
-"clang" .* "-[^i][^"]*" "[^-"][^"]*" "-isystem" "/some/include" "-iframework" "/some/Frameworks" "-iframework" "/some/CustomFW" "-[^i]
+"clang" .* "-[^i][^"]*" "[^-"][^"]*" "-isystem" "/some/include" "-isystem" "[^"]*/include" "-iframework" "/some/Frameworks" "-iframework" "/some/CustomFW" "-[^i]
diff --git a/test/expect/cmd.cc-msvc-c-cmd.stderr.txt b/test/expect/cmd.cc-msvc-c-cmd.stderr.txt
index fb9ae02..7c2e031 100644
--- a/test/expect/cmd.cc-msvc-c-cmd.stderr.txt
+++ b/test/expect/cmd.cc-msvc-c-cmd.stderr.txt
@@ -1 +1 @@
-"clang" .* "-[^i][^"]*" "[^-"][^"]*" "-isystem" "/some/include" "-isystem" "/some/other/include" "-[^i]
+"clang" .* "-[^i][^"]*" "[^-"][^"]*" "-isystem" "[^"]*/include" "-isystem" "/some/include" "-isystem" "/some/other/include" "-[^i]
diff --git a/test/expect/cmd.cc-msvc-cxx-cmd.stderr.txt b/test/expect/cmd.cc-msvc-cxx-cmd.stderr.txt
index fb9ae02..7c2e031 100644
--- a/test/expect/cmd.cc-msvc-cxx-cmd.stderr.txt
+++ b/test/expect/cmd.cc-msvc-cxx-cmd.stderr.txt
@@ -1 +1 @@
-"clang" .* "-[^i][^"]*" "[^-"][^"]*" "-isystem" "/some/include" "-isystem" "/some/other/include" "-[^i]
+"clang" .* "-[^i][^"]*" "[^-"][^"]*" "-isystem" "[^"]*/include" "-isystem" "/some/include" "-isystem" "/some/other/include" "-[^i]