ENH: Added SOURCES property to targets. This is based on patch from issues #6137.

This commit is contained in:
Brad King 2007-12-17 10:12:22 -05:00
parent 99d57b3c8c
commit 8506938407
2 changed files with 45 additions and 1 deletions

View File

@ -296,6 +296,13 @@ void cmTarget::DefineProperties(cmake *cm)
"An internal property used by some generators to record the name of "
"project or dsp file associated with this target.");
cm->DefineProperty
("SOURCES", cmProperty::TARGET,
"Source names specified for a target.",
"Read-only list of sources specified for a target. "
"The names returned are suitable for passing to the "
"set_source_files_properties command.");
#if 0
cm->DefineProperty
("OBJECT_FILES", cmProperty::TARGET,
@ -1524,6 +1531,33 @@ const char *cmTarget::GetProperty(const char* prop,
return this->IsImported()?"TRUE":"FALSE";
}
if(!strcmp(prop,"SOURCES"))
{
cmOStringStream ss;
const char* sep = "";
for(std::vector<cmSourceFile*>::const_iterator
i = this->SourceFiles.begin();
i != this->SourceFiles.end(); ++i)
{
// Separate from the previous list entries.
ss << sep;
sep = ";";
// Construct what is known about this source file location.
cmSourceFileLocation const& location = (*i)->GetLocation();
std::string sname = location.GetDirectory();
if(!sname.empty())
{
sname += "/";
}
sname += location.GetName();
// Append this list entry.
ss << sname;
}
this->SetProperty("SOURCES", ss.str().c_str());
}
// the type property returns what type the target is
if (!strcmp(prop,"TYPE"))
{

View File

@ -35,7 +35,7 @@ get_property(SOURCE_FILERESULT SOURCE_FILE SubDir/properties3.cxx SOURCETEST)
if (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
DIRECTORYRESULT AND SOURCE_FILERESULT)
add_executable (Properties SubDir/properties3.cxx)
add_executable (Properties SubDir/properties3.cxx properties)
else (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
DIRECTORYRESULT AND SOURCE_FILERESULT)
message("Error: test results are RESULT1=${RESULT1} RESULT2=${RESULT2} "
@ -51,3 +51,13 @@ get_property(TARGETRESULT TARGET Properties TARGETTEST)
if (NOT TARGETRESULT)
message("Error: target result is TARGETRESULT=${TARGETRESULT}")
endif (NOT TARGETRESULT)
# test the target SOURCES property
get_property(Properties_SOURCES TARGET Properties SOURCES)
set_source_files_properties(${Properties_SOURCES} PROPERTIES TEST4 1)
get_source_file_property(RESULT4 properties.h TEST4)
if(NOT RESULT4)
message("Error: target result is"
" RESULT4=${RESULT4}"
" Properties_SOURCES=[${Properties_SOURCES}]")
endif(NOT RESULT4)