summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2007-12-17 15:12:22 (GMT)
committerBrad King <brad.king@kitware.com>2007-12-17 15:12:22 (GMT)
commit8506938407722306adeccf12b407a8e8d92a90a6 (patch)
tree8f84564decc3f55af6c2a14244fc471f75e093e1
parent99d57b3c8cc84f40dee02036cc6c3e12510aa08c (diff)
downloadCMake-8506938407722306adeccf12b407a8e8d92a90a6.zip
CMake-8506938407722306adeccf12b407a8e8d92a90a6.tar.gz
CMake-8506938407722306adeccf12b407a8e8d92a90a6.tar.bz2
ENH: Added SOURCES property to targets. This is based on patch from issues #6137.
-rw-r--r--Source/cmTarget.cxx34
-rw-r--r--Tests/Properties/CMakeLists.txt12
2 files changed, 45 insertions, 1 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index e74dd85..2f4bb67 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -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"))
{
diff --git a/Tests/Properties/CMakeLists.txt b/Tests/Properties/CMakeLists.txt
index cb2ca7b..7b7bd2d 100644
--- a/Tests/Properties/CMakeLists.txt
+++ b/Tests/Properties/CMakeLists.txt
@@ -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)