Make the SOURCES target property writable.

This commit is contained in:
Stephen Kelly 2013-07-08 20:18:42 +02:00
parent 6e636f2eba
commit 81ad69e056
11 changed files with 83 additions and 3 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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);
}

View File

@ -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\)
+

View File

@ -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
)

View File

@ -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\)

View File

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

View File

@ -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)

View File

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

View File

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

View File

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