Commit 81ad69e0 authored by Stephen Kelly's avatar Stephen Kelly

Make the SOURCES target property writable.

parent 6e636f2e
......@@ -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.
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.
......@@ -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);
}
......
......@@ -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\)
+
......
......@@ -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
)
......@@ -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\)
......
#ifdef _WIN32
__declspec(dllexport)
#endif
int empty()
{
return 0;
}
......@@ -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)
......@@ -3,5 +3,5 @@
int main(int argc, char** argv)
{
return iface();
return iface() + prop();
}
int prop()
{
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment