Ver Fonte

Make the SOURCES target property writable.

Stephen Kelly há 12 anos atrás
pai
commit
81ad69e056

+ 1 - 2
Help/prop_tgt/SOURCES.rst

@@ -3,5 +3,4 @@ SOURCES
 
 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.
+List of sources specified for a target.

+ 6 - 0
Help/release/dev/target-SOURCES-write.rst

@@ -0,0 +1,6 @@
+target-SOURCES-write.rst
+------------------------
+
+* It is now possible to write and append to the :prop_tgt:`SOURCES` target
+  property.  The :variable:`CMAKE_DEBUG_TARGET_PROPERTIES` variable may be
+  used to trace the origin of sources.

+ 38 - 0
Source/cmTarget.cxx

@@ -1697,6 +1697,25 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
     this->Internal->LinkImplementationPropertyEntries.push_back(entry);
     return;
     }
+  if (prop == "SOURCES")
+    {
+    if(this->IsImported())
+      {
+      cmOStringStream e;
+      e << "SOURCES property can't be set on imported targets (\""
+            << this->Name << "\")\n";
+      this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+      return;
+      }
+    cmListFileBacktrace lfbt;
+    this->Makefile->GetBacktrace(lfbt);
+    cmGeneratorExpression ge(lfbt);
+    this->Internal->SourceEntries.clear();
+    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
+    this->Internal->SourceEntries.push_back(
+                          new cmTargetInternals::TargetPropertyEntry(cge));
+    return;
+    }
   this->Properties.SetProperty(prop, value, cmProperty::TARGET);
   this->MaybeInvalidatePropertyCache(prop);
 }
@@ -1764,6 +1783,25 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value,
     this->Internal->LinkImplementationPropertyEntries.push_back(entry);
     return;
     }
+  if (prop == "SOURCES")
+    {
+    if(this->IsImported())
+      {
+      cmOStringStream e;
+      e << "SOURCES property can't be set on imported targets (\""
+            << this->Name << "\")\n";
+      this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+      return;
+      }
+
+      cmListFileBacktrace lfbt;
+      this->Makefile->GetBacktrace(lfbt);
+      cmGeneratorExpression ge(lfbt);
+      cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
+      this->Internal->SourceEntries.push_back(
+                            new cmTargetInternals::TargetPropertyEntry(cge));
+    return;
+    }
   this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
   this->MaybeInvalidatePropertyCache(prop);
 }

+ 8 - 0
Tests/RunCMake/TargetSources/OriginDebug-stderr.txt

@@ -3,6 +3,14 @@ CMake Debug Log at OriginDebug.cmake:13 \(add_library\):
 
    \* .*Tests/RunCMake/TargetSources/empty_2.cpp
 
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
++
+CMake Debug Log at OriginDebug.cmake:16 \(set_property\):
+  Used sources for target OriginDebug:
+
+   \* .*Tests/RunCMake/TargetSources/empty_3.cpp
+
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
 +

+ 4 - 0
Tests/RunCMake/TargetSources/OriginDebug.cmake

@@ -12,3 +12,7 @@ set_property(TARGET iface PROPERTY INTERFACE_SOURCES
 
 add_library(OriginDebug empty_2.cpp)
 target_link_libraries(OriginDebug iface)
+
+set_property(TARGET OriginDebug APPEND PROPERTY SOURCES
+  empty_3.cpp
+)

+ 9 - 0
Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt

@@ -3,6 +3,15 @@ CMake Debug Log at OriginDebug.cmake:13 \(add_library\):
 
    \* .*Tests/RunCMake/TargetSources/empty_2.cpp
 
+Call Stack \(most recent call first\):
+  OriginDebugIDE.cmake:4 \(include\)
+  CMakeLists.txt:3 \(include\)
++
+CMake Debug Log at OriginDebug.cmake:16 \(set_property\):
+  Used sources for target OriginDebug:
+
+   \* .*Tests/RunCMake/TargetSources/empty_3.cpp
+
 Call Stack \(most recent call first\):
   OriginDebugIDE.cmake:4 \(include\)
   CMakeLists.txt:3 \(include\)

+ 7 - 0
Tests/RunCMake/TargetSources/empty_3.cpp

@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+  return 0;
+}

+ 2 - 0
Tests/SourcesProperty/CMakeLists.txt

@@ -8,3 +8,5 @@ set_property(TARGET iface PROPERTY INTERFACE_SOURCES iface.cpp)
 
 add_executable(SourcesProperty main.cpp)
 target_link_libraries(SourcesProperty iface)
+
+set_property(TARGET SourcesProperty APPEND PROPERTY SOURCES prop.cpp)

+ 2 - 0
Tests/SourcesProperty/iface.h

@@ -1,2 +1,4 @@
 
 int iface();
+
+int prop();

+ 1 - 1
Tests/SourcesProperty/main.cpp

@@ -3,5 +3,5 @@
 
 int main(int argc, char** argv)
 {
-  return iface();
+  return iface() + prop();
 }

+ 5 - 0
Tests/SourcesProperty/prop.cpp

@@ -0,0 +1,5 @@
+
+int prop()
+{
+  return 0;
+}