From 8506938407722306adeccf12b407a8e8d92a90a6 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 17 Dec 2007 10:12:22 -0500 Subject: ENH: Added SOURCES property to targets. This is based on patch from issues #6137. --- Source/cmTarget.cxx | 34 ++++++++++++++++++++++++++++++++++ Tests/Properties/CMakeLists.txt | 12 +++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) 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::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) -- cgit v0.12