diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx index 683eff62a..76458338c 100644 --- a/Source/cmTargetCompileDefinitionsCommand.cxx +++ b/Source/cmTargetCompileDefinitionsCommand.cxx @@ -37,19 +37,32 @@ void cmTargetCompileDefinitionsCommand this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); } -bool cmTargetCompileDefinitionsCommand -::HandleNonTargetArg(std::string &content, - const std::string &sep, - const std::string &entry, - const std::string &) +//---------------------------------------------------------------------------- +std::string cmTargetCompileDefinitionsCommand +::Join(const std::vector &content) { - content += sep + entry; - return true; + std::string defs; + std::string sep; + for(std::vector::const_iterator it = content.begin(); + it != content.end(); ++it) + { + if (strncmp(it->c_str(), "-D", 2) == 0) + { + defs += sep + it->substr(2); + } + else + { + defs += sep + *it; + } + sep = ";"; + } + return defs; } +//---------------------------------------------------------------------------- void cmTargetCompileDefinitionsCommand -::HandleDirectContent(cmTarget *tgt, const std::string &content, +::HandleDirectContent(cmTarget *tgt, const std::vector &content, bool) { - tgt->AppendProperty("COMPILE_DEFINITIONS", content.c_str()); + tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str()); } diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h index d49b9e8ee..3b438207c 100644 --- a/Source/cmTargetCompileDefinitionsCommand.h +++ b/Source/cmTargetCompileDefinitionsCommand.h @@ -81,13 +81,10 @@ private: virtual void HandleImportedTarget(const std::string &tgt); virtual void HandleMissingTarget(const std::string &name); - virtual bool HandleNonTargetArg(std::string &content, - const std::string &sep, - const std::string &entry, - const std::string &tgt); - - virtual void HandleDirectContent(cmTarget *tgt, const std::string &content, + virtual void HandleDirectContent(cmTarget *tgt, + const std::vector &content, bool prepend); + virtual std::string Join(const std::vector &content); }; #endif diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx index aeba4686a..eaacfa9e7 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.cxx +++ b/Source/cmTargetIncludeDirectoriesCommand.cxx @@ -41,32 +41,44 @@ void cmTargetIncludeDirectoriesCommand } //---------------------------------------------------------------------------- -bool cmTargetIncludeDirectoriesCommand -::HandleNonTargetArg(std::string &content, - const std::string &sep, - const std::string &entry, - const std::string &tgt) +static bool isGeneratorExpression(const std::string &lib) { - if (!cmSystemTools::FileIsFullPath(entry.c_str())) - { - cmOStringStream e; - e << "Cannot specify relative include directory \"" << entry << "\" for " - "target \"" << tgt << "\". Only absolute paths are permitted"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); - return false; - } + const std::string::size_type openpos = lib.find("$<"); + return (openpos != std::string::npos) + && (lib.find(">", openpos) != std::string::npos); +} - content += sep + entry; - return true; +//---------------------------------------------------------------------------- +std::string cmTargetIncludeDirectoriesCommand +::Join(const std::vector &content) +{ + std::string dirs; + std::string sep; + std::string prefix = this->Makefile->GetStartDirectory() + std::string("/"); + for(std::vector::const_iterator it = content.begin(); + it != content.end(); ++it) + { + if (cmSystemTools::FileIsFullPath(it->c_str()) + || isGeneratorExpression(*it)) + { + dirs += sep + *it; + } + else + { + dirs += sep + prefix + *it; + } + sep = ";"; + } + return dirs; } //---------------------------------------------------------------------------- void cmTargetIncludeDirectoriesCommand -::HandleDirectContent(cmTarget *tgt, const std::string &content, +::HandleDirectContent(cmTarget *tgt, const std::vector &content, bool prepend) { cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(lfbt); - cmMakefileIncludeDirectoriesEntry entry(content, lfbt); + cmMakefileIncludeDirectoriesEntry entry(this->Join(content), lfbt); tgt->InsertInclude(entry, prepend); } diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h index 5a5f859fd..d02cb4a2f 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.h +++ b/Source/cmTargetIncludeDirectoriesCommand.h @@ -85,13 +85,10 @@ private: virtual void HandleImportedTarget(const std::string &tgt); virtual void HandleMissingTarget(const std::string &name); - virtual bool HandleNonTargetArg(std::string &content, - const std::string &sep, - const std::string &entry, - const std::string &tgt); - - virtual void HandleDirectContent(cmTarget *tgt, const std::string &content, + virtual void HandleDirectContent(cmTarget *tgt, + const std::vector &content, bool prepend); + virtual std::string Join(const std::vector &content); }; #endif diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx index e1eb1d2d4..18a1d2a9f 100644 --- a/Source/cmTargetPropCommandBase.cxx +++ b/Source/cmTargetPropCommandBase.cxx @@ -65,14 +65,6 @@ bool cmTargetPropCommandBase return true; } -//---------------------------------------------------------------------------- -static bool isGeneratorExpression(const std::string &lib) -{ - const std::string::size_type openpos = lib.find("$<"); - return (openpos != std::string::npos) - && (lib.find(">", openpos) != std::string::npos); -} - //---------------------------------------------------------------------------- bool cmTargetPropCommandBase ::ProcessContentArgs(std::vector const& args, @@ -96,9 +88,8 @@ bool cmTargetPropCommandBase ++argIndex; - std::string content; + std::vector content; - std::string sep; for(unsigned int i=argIndex; i < args.size(); ++i, ++argIndex) { if(args[i] == "PUBLIC" @@ -108,20 +99,7 @@ bool cmTargetPropCommandBase this->PopulateTargetProperies(scope, content, prepend); return true; } - if (this->Makefile->FindTargetToUse(args[i].c_str())) - { - content += sep + "$Property + ">"; - } - else if(isGeneratorExpression(args[i])) - { - content += sep + args[i]; - } - else if (!this->HandleNonTargetArg(content, sep, args[i], args[0])) - { - return false; - } - sep = ";"; + content.push_back(args[i]); } this->PopulateTargetProperies(scope, content, prepend); return true; @@ -130,7 +108,8 @@ bool cmTargetPropCommandBase //---------------------------------------------------------------------------- void cmTargetPropCommandBase ::PopulateTargetProperies(const std::string &scope, - const std::string &content, bool prepend) + const std::vector &content, + bool prepend) { if (scope == "PRIVATE" || scope == "PUBLIC") { @@ -142,7 +121,7 @@ void cmTargetPropCommandBase { const std::string propName = std::string("INTERFACE_") + this->Property; const char *propValue = this->Target->GetProperty(propName.c_str()); - const std::string totalContent = content + (propValue + const std::string totalContent = this->Join(content) + (propValue ? std::string(";") + propValue : std::string()); this->Target->SetProperty(propName.c_str(), totalContent.c_str()); @@ -150,7 +129,7 @@ void cmTargetPropCommandBase else { this->Target->AppendProperty(("INTERFACE_" + this->Property).c_str(), - content.c_str()); + this->Join(content).c_str()); } } } diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h index 15a78c9a6..a5b4ff823 100644 --- a/Source/cmTargetPropCommandBase.h +++ b/Source/cmTargetPropCommandBase.h @@ -31,27 +31,24 @@ public: bool HandleArguments(std::vector const& args, const char *prop, ArgumentFlags flags = NO_FLAGS); +protected: + std::string Property; + cmTarget *Target; + private: virtual void HandleImportedTarget(const std::string &tgt) = 0; virtual void HandleMissingTarget(const std::string &name) = 0; - virtual bool HandleNonTargetArg(std::string &content, - const std::string &sep, - const std::string &entry, - const std::string &tgt) = 0; - virtual void HandleDirectContent(cmTarget *tgt, - const std::string &content, + const std::vector &content, bool prepend) = 0; + virtual std::string Join(const std::vector &content) = 0; bool ProcessContentArgs(std::vector const& args, unsigned int &argIndex, bool prepend); void PopulateTargetProperies(const std::string &scope, - const std::string &content, bool prepend); - -private: - cmTarget *Target; - std::string Property; + const std::vector &content, + bool prepend); }; #endif diff --git a/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt index 3eca7fc78..8a4437ba5 100644 --- a/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt +++ b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt @@ -17,7 +17,8 @@ add_executable(consumer ) target_compile_definitions(consumer - PRIVATE target_compile_definitions importedlib + PRIVATE $ $<$:SHOULD_NOT_BE_DEFINED> $<$:SHOULD_BE_DEFINED> + -DDASH_D_DEFINE ) diff --git a/Tests/CMakeCommands/target_compile_definitions/consumer.cpp b/Tests/CMakeCommands/target_compile_definitions/consumer.cpp index f835b6cf5..1a46aa50c 100644 --- a/Tests/CMakeCommands/target_compile_definitions/consumer.cpp +++ b/Tests/CMakeCommands/target_compile_definitions/consumer.cpp @@ -19,4 +19,8 @@ #error Expected SHOULD_BE_DEFINED #endif +#ifndef DASH_D_DEFINE +#error Expected DASH_D_DEFINE +#endif + int main() { return 0; } diff --git a/Tests/CMakeCommands/target_include_directories/CMakeLists.txt b/Tests/CMakeCommands/target_include_directories/CMakeLists.txt index e190161d3..752928378 100644 --- a/Tests/CMakeCommands/target_include_directories/CMakeLists.txt +++ b/Tests/CMakeCommands/target_include_directories/CMakeLists.txt @@ -43,5 +43,6 @@ add_executable(consumer ) target_include_directories(consumer - PRIVATE target_include_directories + PRIVATE $ + relative_dir ) diff --git a/Tests/CMakeCommands/target_include_directories/consumer.cpp b/Tests/CMakeCommands/target_include_directories/consumer.cpp index 5d88488b5..82b800a40 100644 --- a/Tests/CMakeCommands/target_include_directories/consumer.cpp +++ b/Tests/CMakeCommands/target_include_directories/consumer.cpp @@ -2,6 +2,7 @@ #include "common.h" #include "publicinclude.h" #include "interfaceinclude.h" +#include "relative_dir.h" #ifdef PRIVATEINCLUDE_DEFINE #error Unexpected PRIVATEINCLUDE_DEFINE @@ -19,4 +20,8 @@ #error Expected CURE_DEFINE #endif +#ifndef RELATIVE_DIR_DEFINE +#error Expected RELATIVE_DIR_DEFINE +#endif + int main() { return 0; } diff --git a/Tests/CMakeCommands/target_include_directories/relative_dir/relative_dir.h b/Tests/CMakeCommands/target_include_directories/relative_dir/relative_dir.h new file mode 100644 index 000000000..7017b61a8 --- /dev/null +++ b/Tests/CMakeCommands/target_include_directories/relative_dir/relative_dir.h @@ -0,0 +1,2 @@ + +#define RELATIVE_DIR_DEFINE diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index 187c48ae0..e9bd2bac0 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -159,15 +159,18 @@ endif() add_executable(deps_iface deps_iface.c) target_link_libraries(deps_iface testLibDepends) -target_include_directories(deps_iface PRIVATE testLibDepends) -target_compile_definitions(deps_iface PRIVATE testLibDepends) +target_include_directories(deps_iface PRIVATE $) +target_compile_definitions(deps_iface PRIVATE $) add_executable(deps_shared_iface deps_shared_iface.cpp) target_link_libraries(deps_shared_iface testSharedLibDepends) -target_include_directories(deps_shared_iface PRIVATE testSharedLibDepends) +target_include_directories(deps_shared_iface + PRIVATE + $ +) target_compile_definitions(deps_shared_iface PRIVATE - testSharedLibDepends + $ $<$>:PIC_PROPERTY_IS_ON> $<$>:CUSTOM_PROPERTY_IS_ON> $<$,testcontent>:CUSTOM_STRING_IS_MATCH> @@ -197,9 +200,13 @@ endif() add_executable(deps_shared_iface2 deps_shared_iface.cpp) target_link_libraries(deps_shared_iface2 bld_testSharedLibDepends bld_subdirlib) -target_include_directories(deps_shared_iface2 PRIVATE bld_testSharedLibDepends bld_subdirlib) +target_include_directories(deps_shared_iface2 + PRIVATE + $ + $ +) target_compile_definitions(deps_shared_iface2 - PRIVATE bld_testSharedLibDepends TEST_SUBDIR_LIB + PRIVATE $ TEST_SUBDIR_LIB $<$>:PIC_PROPERTY_IS_ON> $<$>:CUSTOM_PROPERTY_IS_ON> $<$,testcontent>:CUSTOM_STRING_IS_MATCH>