From 8d8aacd65af229da0cadf81911ffa3ef77db7b57 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 4 Feb 2015 09:59:29 -0500 Subject: Detect: Use Clang builtin include dir even with --castxml-cc- We need implementation-provided headers to come from Clang to match what is really built in to the parser. When not using --castxml-cc-, 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-, 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 . 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. --- src/Detect.cxx | 12 ++++++++++++ test/CMakeLists.txt | 2 ++ test/cc-gnu-builtin/emmintrin.h | 0 test/cc-gnu.c | 1 + test/expect/cmd.cc-gnu-c-cmd.stderr.txt | 2 +- test/expect/cmd.cc-gnu-cxx-cmd.stderr.txt | 2 +- test/expect/cmd.cc-msvc-c-cmd.stderr.txt | 2 +- test/expect/cmd.cc-msvc-cxx-cmd.stderr.txt | 2 +- 8 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 test/cc-gnu-builtin/emmintrin.h 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 //---------------------------------------------------------------------------- +static std::string getClangBuiltinIncludeDir() +{ + return getClangResourceDir() + "/include"; +} + +//---------------------------------------------------------------------------- static bool failedCC(const char* id, std::vector 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 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 $ ${empty_c} -E -dM) castxml_test_cmd(cc-gnu-c-cmd --castxml-cc-gnu $ ${empty_c} "-###") castxml_test_cmd(cc-gnu-cxx-E --castxml-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 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] -- cgit v0.12