ENH: add target properties
This commit is contained in:
parent
80c6f0fdec
commit
3859417d1a
|
@ -46,6 +46,7 @@
|
|||
#include "cmFLTKWrapUICommand.cxx"
|
||||
#include "cmGetFilenameComponentCommand.cxx"
|
||||
#include "cmGetSourceFilePropertyCommand.cxx"
|
||||
#include "cmGetTargetPropertyCommand.cxx"
|
||||
#include "cmITKWrapTclCommand.cxx"
|
||||
#include "cmIfCommand.cxx"
|
||||
#include "cmIncludeCommand.cxx"
|
||||
|
@ -69,6 +70,7 @@
|
|||
#include "cmSeparateArgumentsCommand.cxx"
|
||||
#include "cmSetCommand.cxx"
|
||||
#include "cmSetSourceFilesPropertiesCommand.cxx"
|
||||
#include "cmSetTargetPropertiesCommand.cxx"
|
||||
#include "cmSiteNameCommand.cxx"
|
||||
#include "cmSourceFilesCommand.cxx"
|
||||
#include "cmSourceFilesRemoveCommand.cxx"
|
||||
|
@ -128,6 +130,7 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
|
|||
commands.push_back(new cmFLTKWrapUICommand);
|
||||
commands.push_back(new cmGetFilenameComponentCommand);
|
||||
commands.push_back(new cmGetSourceFilePropertyCommand);
|
||||
commands.push_back(new cmGetTargetPropertyCommand);
|
||||
commands.push_back(new cmITKWrapTclCommand);
|
||||
commands.push_back(new cmIfCommand);
|
||||
commands.push_back(new cmIncludeCommand);
|
||||
|
@ -154,6 +157,7 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
|
|||
commands.push_back(new cmSeparateArgumentsCommand);
|
||||
commands.push_back(new cmSetCommand);
|
||||
commands.push_back(new cmSetSourceFilesPropertiesCommand);
|
||||
commands.push_back(new cmSetTargetPropertiesCommand);
|
||||
commands.push_back(new cmSiteNameCommand);
|
||||
commands.push_back(new cmSourceFilesCommand);
|
||||
commands.push_back(new cmSourceFilesRemoveCommand);
|
||||
|
|
|
@ -333,31 +333,41 @@ void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
|
|||
{
|
||||
if (l->second.IsInAll())
|
||||
{
|
||||
const char* targetPrefix = l->second.GetProperty("PREFIX");
|
||||
const char* targetSuffix = l->second.GetProperty("SUFFIX");
|
||||
std::string path = m_LibraryOutputPath;
|
||||
if(l->second.GetType() == cmTarget::STATIC_LIBRARY)
|
||||
const char* prefixVar = 0;
|
||||
const char* suffixVar = 0;
|
||||
switch(l->second.GetType())
|
||||
{
|
||||
path +=
|
||||
this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX") +
|
||||
l->first
|
||||
+ this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
|
||||
fout << " \\\n"
|
||||
<< cmSystemTools::ConvertToOutputPath(path.c_str());
|
||||
case cmTarget::STATIC_LIBRARY:
|
||||
prefixVar = "CMAKE_STATIC_LIBRARY_PREFIX";
|
||||
suffixVar = "CMAKE_STATIC_LIBRARY_SUFFIX";
|
||||
break;
|
||||
case cmTarget::SHARED_LIBRARY:
|
||||
prefixVar = "CMAKE_SHARED_LIBRARY_PREFIX";
|
||||
suffixVar = "CMAKE_SHARED_LIBRARY_SUFFIX";
|
||||
break;
|
||||
case cmTarget::MODULE_LIBRARY:
|
||||
prefixVar = "CMAKE_SHARED_MODULE_PREFIX";
|
||||
suffixVar = "CMAKE_SHARED_MODULE_SUFFIX";
|
||||
break;
|
||||
}
|
||||
else if(l->second.GetType() == cmTarget::SHARED_LIBRARY)
|
||||
// if it is a library this will be set
|
||||
if(prefixVar)
|
||||
{
|
||||
path +=
|
||||
this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX") +
|
||||
l->first
|
||||
+ this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
|
||||
fout << " \\\n"
|
||||
<< cmSystemTools::ConvertToOutputPath(path.c_str());
|
||||
// if there is no prefix on the target use the cmake definition
|
||||
if(!targetPrefix)
|
||||
{
|
||||
targetPrefix = this->GetSafeDefinition(prefixVar);
|
||||
}
|
||||
else if(l->second.GetType() == cmTarget::MODULE_LIBRARY)
|
||||
// if there is no suffix on the target use the cmake definition
|
||||
if(!targetSuffix)
|
||||
{
|
||||
targetSuffix = this->GetSafeDefinition(suffixVar);
|
||||
}
|
||||
path +=
|
||||
this->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX") +
|
||||
l->first
|
||||
+ this->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
|
||||
targetPrefix + l->first + targetSuffix;
|
||||
fout << " \\\n"
|
||||
<< cmSystemTools::ConvertToOutputPath(path.c_str());
|
||||
}
|
||||
|
@ -822,6 +832,8 @@ void cmLocalUnixMakefileGenerator::OutputLibraryRule(std::ostream& fout,
|
|||
// collect up the link libraries
|
||||
cmOStringStream linklibs;
|
||||
this->OutputLinkLibraries(linklibs, name, t);
|
||||
const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
|
||||
std::string allLinkFlags;
|
||||
for(std::vector<std::string>::iterator i = commands.begin();
|
||||
i != commands.end(); ++i)
|
||||
{
|
||||
|
@ -876,9 +888,25 @@ void cmLocalUnixMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
|
|||
}
|
||||
}
|
||||
#endif
|
||||
const char* targetPrefix = t.GetProperty("PREFIX");
|
||||
if(!targetPrefix)
|
||||
{
|
||||
targetPrefix = this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
|
||||
}
|
||||
const char* targetSuffix = t.GetProperty("SUFFIX");
|
||||
if(!targetSuffix)
|
||||
{
|
||||
targetSuffix = this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
|
||||
}
|
||||
const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
|
||||
if(targetLinkFlags)
|
||||
{
|
||||
linkFlags += targetLinkFlags;
|
||||
linkFlags += " ";
|
||||
}
|
||||
this->OutputLibraryRule(fout, name, t,
|
||||
this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX"),
|
||||
this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX"),
|
||||
targetPrefix,
|
||||
targetSuffix,
|
||||
createRule,
|
||||
"shared library",
|
||||
linkFlags.c_str());
|
||||
|
@ -908,9 +936,25 @@ void cmLocalUnixMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
|
|||
linkFlags += this->GetSafeDefinition(build.c_str());
|
||||
linkFlags += " ";
|
||||
}
|
||||
const char* targetPrefix = t.GetProperty("PREFIX");
|
||||
if(!targetPrefix)
|
||||
{
|
||||
targetPrefix = this->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
|
||||
}
|
||||
const char* targetSuffix = t.GetProperty("SUFFIX");
|
||||
if(!targetSuffix)
|
||||
{
|
||||
targetSuffix = this->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
|
||||
}
|
||||
const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
|
||||
if(targetLinkFlags)
|
||||
{
|
||||
linkFlags += targetLinkFlags;
|
||||
linkFlags += " ";
|
||||
}
|
||||
this->OutputLibraryRule(fout, name, t,
|
||||
this->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX"),
|
||||
this->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX"),
|
||||
targetPrefix,
|
||||
targetSuffix,
|
||||
createRule,
|
||||
"shared module",
|
||||
linkFlags.c_str());
|
||||
|
@ -930,9 +974,19 @@ void cmLocalUnixMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
|
|||
{
|
||||
createRule = "CMAKE_C_CREATE_STATIC_LIBRARY";
|
||||
}
|
||||
const char* targetPrefix = t.GetProperty("PREFIX");
|
||||
if(!targetPrefix)
|
||||
{
|
||||
targetPrefix = this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
|
||||
}
|
||||
const char* targetSuffix = t.GetProperty("SUFFIX");
|
||||
if(!targetSuffix)
|
||||
{
|
||||
targetSuffix = this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
|
||||
}
|
||||
this->OutputLibraryRule(fout, name, t,
|
||||
this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX"),
|
||||
this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX"),
|
||||
targetPrefix,
|
||||
targetSuffix,
|
||||
createRule,
|
||||
"static library", 0);
|
||||
|
||||
|
@ -1008,8 +1062,12 @@ void cmLocalUnixMakefileGenerator::OutputExecutableRule(std::ostream& fout,
|
|||
linkFlags += this->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
|
||||
linkFlags += " ";
|
||||
}
|
||||
|
||||
|
||||
const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
|
||||
if(targetLinkFlags)
|
||||
{
|
||||
linkFlags += targetLinkFlags;
|
||||
linkFlags += " ";
|
||||
}
|
||||
for(std::vector<std::string>::iterator i = commands.begin();
|
||||
i != commands.end(); ++i)
|
||||
{
|
||||
|
|
|
@ -544,3 +544,39 @@ void cmTarget::GatherDependencies( const cmMakefile& mf,
|
|||
DeleteDependency( dep_map, lib, lib); // cannot depend on itself
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cmTarget::SetProperty(const char* prop, const char* value)
|
||||
{
|
||||
if (!prop)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!value)
|
||||
{
|
||||
value = "NOTFOUND";
|
||||
}
|
||||
m_Properties[prop] = value;
|
||||
}
|
||||
|
||||
const char *cmTarget::GetProperty(const char* prop) const
|
||||
{
|
||||
std::map<cmStdString,cmStdString>::const_iterator i =
|
||||
m_Properties.find(prop);
|
||||
if (i != m_Properties.end())
|
||||
{
|
||||
return i->second.c_str();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool cmTarget::GetPropertyAsBool(const char* prop) const
|
||||
{
|
||||
std::map<cmStdString,cmStdString>::const_iterator i =
|
||||
m_Properties.find(prop);
|
||||
if (i != m_Properties.end())
|
||||
{
|
||||
return cmSystemTools::IsOn(i->second.c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -125,6 +125,11 @@ public:
|
|||
|
||||
void AnalyzeLibDependencies( const cmMakefile& mf );
|
||||
|
||||
///! Set/Get a property of this target file
|
||||
void SetProperty(const char *prop, const char *value);
|
||||
const char *GetProperty(const char *prop) const;
|
||||
bool GetPropertyAsBool(const char *prop) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* A list of direct dependencies. Use in conjunction with DependencyMap.
|
||||
|
@ -179,6 +184,7 @@ private:
|
|||
void GatherDependencies( const cmMakefile& mf, const std::string& lib,
|
||||
DependencyMap& dep_map );
|
||||
|
||||
|
||||
private:
|
||||
std::vector<cmCustomCommand> m_CustomCommands;
|
||||
std::vector<std::string> m_SourceLists;
|
||||
|
@ -191,6 +197,7 @@ private:
|
|||
std::string m_InstallPath;
|
||||
std::set<cmStdString> m_Utilities;
|
||||
bool m_RecordDependencies;
|
||||
std::map<cmStdString,cmStdString> m_Properties;
|
||||
};
|
||||
|
||||
typedef std::map<cmStdString,cmTarget> cmTargets;
|
||||
|
|
|
@ -40,6 +40,14 @@ SOURCE_FILES(SharedLibrarySources sharedFile)
|
|||
ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
|
||||
ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
|
||||
SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
|
||||
SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
|
||||
GET_TARGET_PROPERTY(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
|
||||
IF(${FOO_BAR_VAR} MATCHES "BAR")
|
||||
ELSE(${FOO_BAR_VAR} MATCHES "BAR")
|
||||
MESSAGE(SEND_ERROR "SET_TARGET_PROPERTIES or GET_TARGET_PROPERTY failed, FOO_BAR_VAR should be BAR, but is ${FOO_BAR_VAR}")
|
||||
ENDIF(${FOO_BAR_VAR} MATCHES "BAR")
|
||||
|
||||
|
||||
#
|
||||
# Attach a post-build custom-command to the lib.
|
||||
|
|
|
@ -40,6 +40,14 @@ SOURCE_FILES(SharedLibrarySources sharedFile)
|
|||
ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
|
||||
ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
|
||||
SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
|
||||
SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
|
||||
GET_TARGET_PROPERTY(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
|
||||
IF(${FOO_BAR_VAR} MATCHES "BAR")
|
||||
ELSE(${FOO_BAR_VAR} MATCHES "BAR")
|
||||
MESSAGE(SEND_ERROR "SET_TARGET_PROPERTIES or GET_TARGET_PROPERTY failed, FOO_BAR_VAR should be BAR, but is ${FOO_BAR_VAR}")
|
||||
ENDIF(${FOO_BAR_VAR} MATCHES "BAR")
|
||||
|
||||
|
||||
#
|
||||
# Attach a post-build custom-command to the lib.
|
||||
|
|
|
@ -40,6 +40,14 @@ SOURCE_FILES(SharedLibrarySources sharedFile)
|
|||
ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
|
||||
ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
|
||||
SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
|
||||
SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
|
||||
GET_TARGET_PROPERTY(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
|
||||
IF(${FOO_BAR_VAR} MATCHES "BAR")
|
||||
ELSE(${FOO_BAR_VAR} MATCHES "BAR")
|
||||
MESSAGE(SEND_ERROR "SET_TARGET_PROPERTIES or GET_TARGET_PROPERTY failed, FOO_BAR_VAR should be BAR, but is ${FOO_BAR_VAR}")
|
||||
ENDIF(${FOO_BAR_VAR} MATCHES "BAR")
|
||||
|
||||
|
||||
#
|
||||
# Attach a post-build custom-command to the lib.
|
||||
|
|
Loading…
Reference in New Issue