From 5790aca4adfc21e9e042e93fa0dd290aab91be5c Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Sun, 9 Aug 2015 22:24:34 +0200 Subject: [PATCH 1/2] target_include_directories: Support relative SYSTEM include dirs (#15464) --- Source/cmTargetIncludeDirectoriesCommand.cxx | 20 +++++++++++++++++-- .../SystemIncludeDirectories/CMakeLists.txt | 10 ++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx index 7824c898d..7dfe9ca38 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.cxx +++ b/Source/cmTargetIncludeDirectoriesCommand.cxx @@ -75,7 +75,23 @@ bool cmTargetIncludeDirectoriesCommand tgt->InsertInclude(this->Join(content), lfbt, prepend); if (system) { - tgt->AddSystemIncludeDirectories(content); + std::string prefix = + this->Makefile->GetCurrentSourceDirectory() + std::string("/"); + std::set sdirs; + for (std::vector::const_iterator it = content.begin(); + it != content.end(); ++it) + { + if (cmSystemTools::FileIsFullPath(it->c_str()) + || cmGeneratorExpression::Find(*it) == 0) + { + sdirs.insert(*it); + } + else + { + sdirs.insert(prefix + *it); + } + } + tgt->AddSystemIncludeDirectories(sdirs); } return true; } @@ -91,7 +107,7 @@ void cmTargetIncludeDirectoriesCommand if (system) { - std::string joined = cmJoin(content, ";"); + std::string joined = this->Join(content); tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", joined.c_str()); } diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt index 0215e9322..dcee85eb4 100644 --- a/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt +++ b/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt @@ -35,6 +35,16 @@ add_library(imported_consumer2 imported_consumer.cpp) target_link_libraries(imported_consumer2 imported_consumer) target_compile_options(imported_consumer2 PRIVATE -Werror=unused-variable) +# add a target which has a relative system include +add_library(somelib imported_consumer.cpp) +target_include_directories(somelib SYSTEM PUBLIC "systemlib_header_only") +target_compile_options(somelib PRIVATE -Werror=unused-variable) + +# add a target which consumes a relative system include +add_library(otherlib upstream.cpp) +target_link_libraries(otherlib PUBLIC somelib) +target_compile_options(somelib PRIVATE -Werror=unused-variable) + macro(do_try_compile error_option) set(TC_ARGS IFACE_TRY_COMPILE_${error_option} From 8c076a8bdba8c5bc77fc01b3fafafa100fb59657 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Mon, 10 Aug 2015 21:41:38 +0200 Subject: [PATCH 2/2] cmTarget: Remove unused AddSystemIncludeDirectories overload --- Source/cmTarget.cxx | 7 ------- Source/cmTarget.h | 1 - 2 files changed, 8 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index d3170e4ae..316d85cef 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1350,13 +1350,6 @@ cmTarget::AddSystemIncludeDirectories(const std::set &incs) this->SystemIncludeDirectories.insert(incs.begin(), incs.end()); } -//---------------------------------------------------------------------------- -void -cmTarget::AddSystemIncludeDirectories(const std::vector &incs) -{ - this->SystemIncludeDirectories.insert(incs.begin(), incs.end()); -} - #if defined(_WIN32) && !defined(__CYGWIN__) //---------------------------------------------------------------------------- void diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 490aaa350..2007b4096 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -427,7 +427,6 @@ public: cmTarget::LinkLibraryType llt) const; void AddSystemIncludeDirectories(const std::set &incs); - void AddSystemIncludeDirectories(const std::vector &incs); std::set const & GetSystemIncludeDirectories() const { return this->SystemIncludeDirectories; }