Merge topic 'fix-target-property-commands'
7bf490e
Make subclasses responsible for joining content.f6b16d4
Don't allow targets args in the new target commands.b3a7e19
Make the Property name protected so that subclasses can use it.
This commit is contained in:
commit
da2b0245a3
|
@ -37,19 +37,32 @@ void cmTargetCompileDefinitionsCommand
|
||||||
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmTargetCompileDefinitionsCommand
|
//----------------------------------------------------------------------------
|
||||||
::HandleNonTargetArg(std::string &content,
|
std::string cmTargetCompileDefinitionsCommand
|
||||||
const std::string &sep,
|
::Join(const std::vector<std::string> &content)
|
||||||
const std::string &entry,
|
|
||||||
const std::string &)
|
|
||||||
{
|
{
|
||||||
content += sep + entry;
|
std::string defs;
|
||||||
return true;
|
std::string sep;
|
||||||
|
for(std::vector<std::string>::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
|
void cmTargetCompileDefinitionsCommand
|
||||||
::HandleDirectContent(cmTarget *tgt, const std::string &content,
|
::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
|
||||||
bool)
|
bool)
|
||||||
{
|
{
|
||||||
tgt->AppendProperty("COMPILE_DEFINITIONS", content.c_str());
|
tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,13 +81,10 @@ private:
|
||||||
virtual void HandleImportedTarget(const std::string &tgt);
|
virtual void HandleImportedTarget(const std::string &tgt);
|
||||||
virtual void HandleMissingTarget(const std::string &name);
|
virtual void HandleMissingTarget(const std::string &name);
|
||||||
|
|
||||||
virtual bool HandleNonTargetArg(std::string &content,
|
virtual void HandleDirectContent(cmTarget *tgt,
|
||||||
const std::string &sep,
|
const std::vector<std::string> &content,
|
||||||
const std::string &entry,
|
|
||||||
const std::string &tgt);
|
|
||||||
|
|
||||||
virtual void HandleDirectContent(cmTarget *tgt, const std::string &content,
|
|
||||||
bool prepend);
|
bool prepend);
|
||||||
|
virtual std::string Join(const std::vector<std::string> &content);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -41,32 +41,44 @@ void cmTargetIncludeDirectoriesCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
bool cmTargetIncludeDirectoriesCommand
|
static bool isGeneratorExpression(const std::string &lib)
|
||||||
::HandleNonTargetArg(std::string &content,
|
|
||||||
const std::string &sep,
|
|
||||||
const std::string &entry,
|
|
||||||
const std::string &tgt)
|
|
||||||
{
|
{
|
||||||
if (!cmSystemTools::FileIsFullPath(entry.c_str()))
|
const std::string::size_type openpos = lib.find("$<");
|
||||||
{
|
return (openpos != std::string::npos)
|
||||||
cmOStringStream e;
|
&& (lib.find(">", openpos) != std::string::npos);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
content += sep + entry;
|
//----------------------------------------------------------------------------
|
||||||
return true;
|
std::string cmTargetIncludeDirectoriesCommand
|
||||||
|
::Join(const std::vector<std::string> &content)
|
||||||
|
{
|
||||||
|
std::string dirs;
|
||||||
|
std::string sep;
|
||||||
|
std::string prefix = this->Makefile->GetStartDirectory() + std::string("/");
|
||||||
|
for(std::vector<std::string>::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
|
void cmTargetIncludeDirectoriesCommand
|
||||||
::HandleDirectContent(cmTarget *tgt, const std::string &content,
|
::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
|
||||||
bool prepend)
|
bool prepend)
|
||||||
{
|
{
|
||||||
cmListFileBacktrace lfbt;
|
cmListFileBacktrace lfbt;
|
||||||
this->Makefile->GetBacktrace(lfbt);
|
this->Makefile->GetBacktrace(lfbt);
|
||||||
cmMakefileIncludeDirectoriesEntry entry(content, lfbt);
|
cmMakefileIncludeDirectoriesEntry entry(this->Join(content), lfbt);
|
||||||
tgt->InsertInclude(entry, prepend);
|
tgt->InsertInclude(entry, prepend);
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,13 +85,10 @@ private:
|
||||||
virtual void HandleImportedTarget(const std::string &tgt);
|
virtual void HandleImportedTarget(const std::string &tgt);
|
||||||
virtual void HandleMissingTarget(const std::string &name);
|
virtual void HandleMissingTarget(const std::string &name);
|
||||||
|
|
||||||
virtual bool HandleNonTargetArg(std::string &content,
|
virtual void HandleDirectContent(cmTarget *tgt,
|
||||||
const std::string &sep,
|
const std::vector<std::string> &content,
|
||||||
const std::string &entry,
|
|
||||||
const std::string &tgt);
|
|
||||||
|
|
||||||
virtual void HandleDirectContent(cmTarget *tgt, const std::string &content,
|
|
||||||
bool prepend);
|
bool prepend);
|
||||||
|
virtual std::string Join(const std::vector<std::string> &content);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -65,14 +65,6 @@ bool cmTargetPropCommandBase
|
||||||
return true;
|
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
|
bool cmTargetPropCommandBase
|
||||||
::ProcessContentArgs(std::vector<std::string> const& args,
|
::ProcessContentArgs(std::vector<std::string> const& args,
|
||||||
|
@ -96,9 +88,8 @@ bool cmTargetPropCommandBase
|
||||||
|
|
||||||
++argIndex;
|
++argIndex;
|
||||||
|
|
||||||
std::string content;
|
std::vector<std::string> content;
|
||||||
|
|
||||||
std::string sep;
|
|
||||||
for(unsigned int i=argIndex; i < args.size(); ++i, ++argIndex)
|
for(unsigned int i=argIndex; i < args.size(); ++i, ++argIndex)
|
||||||
{
|
{
|
||||||
if(args[i] == "PUBLIC"
|
if(args[i] == "PUBLIC"
|
||||||
|
@ -108,20 +99,7 @@ bool cmTargetPropCommandBase
|
||||||
this->PopulateTargetProperies(scope, content, prepend);
|
this->PopulateTargetProperies(scope, content, prepend);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (this->Makefile->FindTargetToUse(args[i].c_str()))
|
content.push_back(args[i]);
|
||||||
{
|
|
||||||
content += sep + "$<TARGET_PROPERTY:" + args[i]
|
|
||||||
+ ",INTERFACE_" + this->Property + ">";
|
|
||||||
}
|
|
||||||
else if(isGeneratorExpression(args[i]))
|
|
||||||
{
|
|
||||||
content += sep + args[i];
|
|
||||||
}
|
|
||||||
else if (!this->HandleNonTargetArg(content, sep, args[i], args[0]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
sep = ";";
|
|
||||||
}
|
}
|
||||||
this->PopulateTargetProperies(scope, content, prepend);
|
this->PopulateTargetProperies(scope, content, prepend);
|
||||||
return true;
|
return true;
|
||||||
|
@ -130,7 +108,8 @@ bool cmTargetPropCommandBase
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmTargetPropCommandBase
|
void cmTargetPropCommandBase
|
||||||
::PopulateTargetProperies(const std::string &scope,
|
::PopulateTargetProperies(const std::string &scope,
|
||||||
const std::string &content, bool prepend)
|
const std::vector<std::string> &content,
|
||||||
|
bool prepend)
|
||||||
{
|
{
|
||||||
if (scope == "PRIVATE" || scope == "PUBLIC")
|
if (scope == "PRIVATE" || scope == "PUBLIC")
|
||||||
{
|
{
|
||||||
|
@ -142,7 +121,7 @@ void cmTargetPropCommandBase
|
||||||
{
|
{
|
||||||
const std::string propName = std::string("INTERFACE_") + this->Property;
|
const std::string propName = std::string("INTERFACE_") + this->Property;
|
||||||
const char *propValue = this->Target->GetProperty(propName.c_str());
|
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(";") + propValue
|
||||||
: std::string());
|
: std::string());
|
||||||
this->Target->SetProperty(propName.c_str(), totalContent.c_str());
|
this->Target->SetProperty(propName.c_str(), totalContent.c_str());
|
||||||
|
@ -150,7 +129,7 @@ void cmTargetPropCommandBase
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->Target->AppendProperty(("INTERFACE_" + this->Property).c_str(),
|
this->Target->AppendProperty(("INTERFACE_" + this->Property).c_str(),
|
||||||
content.c_str());
|
this->Join(content).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,27 +31,24 @@ public:
|
||||||
bool HandleArguments(std::vector<std::string> const& args,
|
bool HandleArguments(std::vector<std::string> const& args,
|
||||||
const char *prop, ArgumentFlags flags = NO_FLAGS);
|
const char *prop, ArgumentFlags flags = NO_FLAGS);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string Property;
|
||||||
|
cmTarget *Target;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void HandleImportedTarget(const std::string &tgt) = 0;
|
virtual void HandleImportedTarget(const std::string &tgt) = 0;
|
||||||
virtual void HandleMissingTarget(const std::string &name) = 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,
|
virtual void HandleDirectContent(cmTarget *tgt,
|
||||||
const std::string &content,
|
const std::vector<std::string> &content,
|
||||||
bool prepend) = 0;
|
bool prepend) = 0;
|
||||||
|
virtual std::string Join(const std::vector<std::string> &content) = 0;
|
||||||
|
|
||||||
bool ProcessContentArgs(std::vector<std::string> const& args,
|
bool ProcessContentArgs(std::vector<std::string> const& args,
|
||||||
unsigned int &argIndex, bool prepend);
|
unsigned int &argIndex, bool prepend);
|
||||||
void PopulateTargetProperies(const std::string &scope,
|
void PopulateTargetProperies(const std::string &scope,
|
||||||
const std::string &content, bool prepend);
|
const std::vector<std::string> &content,
|
||||||
|
bool prepend);
|
||||||
private:
|
|
||||||
cmTarget *Target;
|
|
||||||
std::string Property;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,7 +17,8 @@ add_executable(consumer
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(consumer
|
target_compile_definitions(consumer
|
||||||
PRIVATE target_compile_definitions importedlib
|
PRIVATE $<TARGET_PROPERTY:target_compile_definitions,INTERFACE_COMPILE_DEFINITIONS>
|
||||||
$<$<TARGET_DEFINED:notdefined>:SHOULD_NOT_BE_DEFINED>
|
$<$<TARGET_DEFINED:notdefined>:SHOULD_NOT_BE_DEFINED>
|
||||||
$<$<TARGET_DEFINED:target_compile_definitions>:SHOULD_BE_DEFINED>
|
$<$<TARGET_DEFINED:target_compile_definitions>:SHOULD_BE_DEFINED>
|
||||||
|
-DDASH_D_DEFINE
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,4 +19,8 @@
|
||||||
#error Expected SHOULD_BE_DEFINED
|
#error Expected SHOULD_BE_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DASH_D_DEFINE
|
||||||
|
#error Expected DASH_D_DEFINE
|
||||||
|
#endif
|
||||||
|
|
||||||
int main() { return 0; }
|
int main() { return 0; }
|
||||||
|
|
|
@ -43,5 +43,6 @@ add_executable(consumer
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(consumer
|
target_include_directories(consumer
|
||||||
PRIVATE target_include_directories
|
PRIVATE $<TARGET_PROPERTY:target_include_directories,INTERFACE_INCLUDE_DIRECTORIES>
|
||||||
|
relative_dir
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "publicinclude.h"
|
#include "publicinclude.h"
|
||||||
#include "interfaceinclude.h"
|
#include "interfaceinclude.h"
|
||||||
|
#include "relative_dir.h"
|
||||||
|
|
||||||
#ifdef PRIVATEINCLUDE_DEFINE
|
#ifdef PRIVATEINCLUDE_DEFINE
|
||||||
#error Unexpected PRIVATEINCLUDE_DEFINE
|
#error Unexpected PRIVATEINCLUDE_DEFINE
|
||||||
|
@ -19,4 +20,8 @@
|
||||||
#error Expected CURE_DEFINE
|
#error Expected CURE_DEFINE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef RELATIVE_DIR_DEFINE
|
||||||
|
#error Expected RELATIVE_DIR_DEFINE
|
||||||
|
#endif
|
||||||
|
|
||||||
int main() { return 0; }
|
int main() { return 0; }
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
#define RELATIVE_DIR_DEFINE
|
|
@ -159,15 +159,18 @@ endif()
|
||||||
|
|
||||||
add_executable(deps_iface deps_iface.c)
|
add_executable(deps_iface deps_iface.c)
|
||||||
target_link_libraries(deps_iface testLibDepends)
|
target_link_libraries(deps_iface testLibDepends)
|
||||||
target_include_directories(deps_iface PRIVATE testLibDepends)
|
target_include_directories(deps_iface PRIVATE $<TARGET_PROPERTY:testLibDepends,INTERFACE_INCLUDE_DIRECTORIES>)
|
||||||
target_compile_definitions(deps_iface PRIVATE testLibDepends)
|
target_compile_definitions(deps_iface PRIVATE $<TARGET_PROPERTY:testLibDepends,INTERFACE_COMPILE_DEFINITIONS>)
|
||||||
|
|
||||||
add_executable(deps_shared_iface deps_shared_iface.cpp)
|
add_executable(deps_shared_iface deps_shared_iface.cpp)
|
||||||
target_link_libraries(deps_shared_iface testSharedLibDepends)
|
target_link_libraries(deps_shared_iface testSharedLibDepends)
|
||||||
target_include_directories(deps_shared_iface PRIVATE testSharedLibDepends)
|
target_include_directories(deps_shared_iface
|
||||||
|
PRIVATE
|
||||||
|
$<TARGET_PROPERTY:testSharedLibDepends,INTERFACE_INCLUDE_DIRECTORIES>
|
||||||
|
)
|
||||||
target_compile_definitions(deps_shared_iface
|
target_compile_definitions(deps_shared_iface
|
||||||
PRIVATE
|
PRIVATE
|
||||||
testSharedLibDepends
|
$<TARGET_PROPERTY:testSharedLibDepends,INTERFACE_COMPILE_DEFINITIONS>
|
||||||
$<$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>:PIC_PROPERTY_IS_ON>
|
$<$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>:PIC_PROPERTY_IS_ON>
|
||||||
$<$<BOOL:$<TARGET_PROPERTY:CUSTOM_PROP>>:CUSTOM_PROPERTY_IS_ON>
|
$<$<BOOL:$<TARGET_PROPERTY:CUSTOM_PROP>>:CUSTOM_PROPERTY_IS_ON>
|
||||||
$<$<STREQUAL:$<TARGET_PROPERTY:CUSTOM_STRING>,testcontent>:CUSTOM_STRING_IS_MATCH>
|
$<$<STREQUAL:$<TARGET_PROPERTY:CUSTOM_STRING>,testcontent>:CUSTOM_STRING_IS_MATCH>
|
||||||
|
@ -197,9 +200,13 @@ endif()
|
||||||
|
|
||||||
add_executable(deps_shared_iface2 deps_shared_iface.cpp)
|
add_executable(deps_shared_iface2 deps_shared_iface.cpp)
|
||||||
target_link_libraries(deps_shared_iface2 bld_testSharedLibDepends bld_subdirlib)
|
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_PROPERTY:bld_testSharedLibDepends,INTERFACE_INCLUDE_DIRECTORIES>
|
||||||
|
$<TARGET_PROPERTY:bld_subdirlib,INTERFACE_INCLUDE_DIRECTORIES>
|
||||||
|
)
|
||||||
target_compile_definitions(deps_shared_iface2
|
target_compile_definitions(deps_shared_iface2
|
||||||
PRIVATE bld_testSharedLibDepends TEST_SUBDIR_LIB
|
PRIVATE $<TARGET_PROPERTY:bld_testSharedLibDepends,INTERFACE_COMPILE_DEFINITIONS> TEST_SUBDIR_LIB
|
||||||
$<$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>:PIC_PROPERTY_IS_ON>
|
$<$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>:PIC_PROPERTY_IS_ON>
|
||||||
$<$<BOOL:$<TARGET_PROPERTY:CUSTOM_PROP>>:CUSTOM_PROPERTY_IS_ON>
|
$<$<BOOL:$<TARGET_PROPERTY:CUSTOM_PROP>>:CUSTOM_PROPERTY_IS_ON>
|
||||||
$<$<STREQUAL:$<TARGET_PROPERTY:CUSTOM_STRING>,testcontent>:CUSTOM_STRING_IS_MATCH>
|
$<$<STREQUAL:$<TARGET_PROPERTY:CUSTOM_STRING>,testcontent>:CUSTOM_STRING_IS_MATCH>
|
||||||
|
|
Loading…
Reference in New Issue