From 81ad69e056d6c6dd2360e3345f6d99f268ee9e54 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 8 Jul 2013 20:18:42 +0200 Subject: Make the SOURCES target property writable. --- Help/prop_tgt/SOURCES.rst | 3 +- Help/release/dev/target-SOURCES-write.rst | 6 ++++ Source/cmTarget.cxx | 38 ++++++++++++++++++++++ .../RunCMake/TargetSources/OriginDebug-stderr.txt | 8 +++++ Tests/RunCMake/TargetSources/OriginDebug.cmake | 4 +++ .../TargetSources/OriginDebugIDE-stderr.txt | 9 +++++ Tests/RunCMake/TargetSources/empty_3.cpp | 7 ++++ Tests/SourcesProperty/CMakeLists.txt | 2 ++ Tests/SourcesProperty/iface.h | 2 ++ Tests/SourcesProperty/main.cpp | 2 +- Tests/SourcesProperty/prop.cpp | 5 +++ 11 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 Help/release/dev/target-SOURCES-write.rst create mode 100644 Tests/RunCMake/TargetSources/empty_3.cpp create mode 100644 Tests/SourcesProperty/prop.cpp diff --git a/Help/prop_tgt/SOURCES.rst b/Help/prop_tgt/SOURCES.rst index 833b65a..493643e 100644 --- a/Help/prop_tgt/SOURCES.rst +++ b/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. diff --git a/Help/release/dev/target-SOURCES-write.rst b/Help/release/dev/target-SOURCES-write.rst new file mode 100644 index 0000000..a754a73 --- /dev/null +++ b/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. diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 10ecbfa..475bcdb 100644 --- a/Source/cmTarget.cxx +++ b/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 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 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); } diff --git a/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt b/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt index dad9fee..6b7453f 100644 --- a/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt +++ b/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt @@ -6,6 +6,14 @@ CMake Debug Log at OriginDebug.cmake:13 \(add_library\): 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\) ++ CMake Debug Log at OriginDebug.cmake:14 \(target_link_libraries\): Used sources for target OriginDebug: diff --git a/Tests/RunCMake/TargetSources/OriginDebug.cmake b/Tests/RunCMake/TargetSources/OriginDebug.cmake index 911a7d4..3fa5858 100644 --- a/Tests/RunCMake/TargetSources/OriginDebug.cmake +++ b/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 +) diff --git a/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt b/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt index 9797870..683c2e9 100644 --- a/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt +++ b/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt @@ -7,6 +7,15 @@ 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\) ++ CMake Debug Log: Used sources for target OriginDebug: diff --git a/Tests/RunCMake/TargetSources/empty_3.cpp b/Tests/RunCMake/TargetSources/empty_3.cpp new file mode 100644 index 0000000..bfbbdde --- /dev/null +++ b/Tests/RunCMake/TargetSources/empty_3.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +int empty() +{ + return 0; +} diff --git a/Tests/SourcesProperty/CMakeLists.txt b/Tests/SourcesProperty/CMakeLists.txt index 0b3097e..6c99e00 100644 --- a/Tests/SourcesProperty/CMakeLists.txt +++ b/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) diff --git a/Tests/SourcesProperty/iface.h b/Tests/SourcesProperty/iface.h index 2cac248..6da80a4 100644 --- a/Tests/SourcesProperty/iface.h +++ b/Tests/SourcesProperty/iface.h @@ -1,2 +1,4 @@ int iface(); + +int prop(); diff --git a/Tests/SourcesProperty/main.cpp b/Tests/SourcesProperty/main.cpp index ae4f305..33a97f4 100644 --- a/Tests/SourcesProperty/main.cpp +++ b/Tests/SourcesProperty/main.cpp @@ -3,5 +3,5 @@ int main(int argc, char** argv) { - return iface(); + return iface() + prop(); } diff --git a/Tests/SourcesProperty/prop.cpp b/Tests/SourcesProperty/prop.cpp new file mode 100644 index 0000000..e343431 --- /dev/null +++ b/Tests/SourcesProperty/prop.cpp @@ -0,0 +1,5 @@ + +int prop() +{ + return 0; +} -- cgit v0.12