diff options
-rw-r--r-- | Help/command/target_sources.rst | 28 | ||||
-rw-r--r-- | Help/manual/cmake-commands.7.rst | 1 | ||||
-rw-r--r-- | Help/release/dev/target_sources-command.rst | 5 | ||||
-rw-r--r-- | Source/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Source/cmTargetSourcesCommand.cxx | 64 | ||||
-rw-r--r-- | Source/cmTargetSourcesCommand.h | 55 | ||||
-rw-r--r-- | Tests/RunCMake/TargetSources/OriginDebug-stderr.txt | 8 | ||||
-rw-r--r-- | Tests/RunCMake/TargetSources/OriginDebug.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt | 9 | ||||
-rw-r--r-- | Tests/RunCMake/TargetSources/empty_4.cpp | 7 |
10 files changed, 180 insertions, 0 deletions
diff --git a/Help/command/target_sources.rst b/Help/command/target_sources.rst new file mode 100644 index 0000000..ff756b4 --- /dev/null +++ b/Help/command/target_sources.rst @@ -0,0 +1,28 @@ +target_sources +-------------- + +Add sources to a target. + +:: + + target_sources(<target> + <INTERFACE|PUBLIC|PRIVATE> [items1...] + [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...]) + +Specify sources to use when compiling a given target. The +named ``<target>`` must have been created by a command such as +:command:`add_executable` or :command:`add_library` and must not be an +:prop_tgt:`IMPORTED Target`. + +The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to +specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC`` +items will populate the :prop_tgt:`SOURCES` property of +``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the +:prop_tgt:`INTERFACE_SOURCES` property of ``<target>``. The +following arguments specify sources. Repeated calls for the same +``<target>`` append items in the order called. + +Arguments to ``target_sources`` may use "generator expressions" +with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` +manual for available expressions. See the :manual:`cmake-buildsystem(7)` +manual for more on defining buildsystem properties. diff --git a/Help/manual/cmake-commands.7.rst b/Help/manual/cmake-commands.7.rst index fb0d2b5..4b1dbed 100644 --- a/Help/manual/cmake-commands.7.rst +++ b/Help/manual/cmake-commands.7.rst @@ -94,6 +94,7 @@ These commands may be used freely in CMake projects. /command/target_compile_options /command/target_include_directories /command/target_link_libraries + /command/target_sources /command/try_compile /command/try_run /command/unset diff --git a/Help/release/dev/target_sources-command.rst b/Help/release/dev/target_sources-command.rst new file mode 100644 index 0000000..abfb303 --- /dev/null +++ b/Help/release/dev/target_sources-command.rst @@ -0,0 +1,5 @@ +target_sources-command +---------------------- + +* The :command:`target_sources` command was added to add to the + :prop_tgt:`SOURCES` target property. diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 27d099d..4c678d8 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -348,6 +348,7 @@ foreach(command_file cmTargetCompileDefinitionsCommand cmTargetCompileOptionsCommand cmTargetIncludeDirectoriesCommand + cmTargetSourcesCommand cmUseMangledMesaCommand cmUtilitySourceCommand cmVariableRequiresCommand diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx new file mode 100644 index 0000000..e82b36d --- /dev/null +++ b/Source/cmTargetSourcesCommand.cxx @@ -0,0 +1,64 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2014 Stephen Kelly <steveire@gmail.com> + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmTargetSourcesCommand.h" + +#include "cmGeneratorExpression.h" + +//---------------------------------------------------------------------------- +bool cmTargetSourcesCommand +::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &) +{ + return this->HandleArguments(args, "SOURCES"); +} + +//---------------------------------------------------------------------------- +void cmTargetSourcesCommand +::HandleImportedTarget(const std::string &tgt) +{ + cmOStringStream e; + e << "Cannot specify sources for imported target \"" + << tgt << "\"."; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); +} + +//---------------------------------------------------------------------------- +void cmTargetSourcesCommand +::HandleMissingTarget(const std::string &name) +{ + cmOStringStream e; + e << "Cannot specify sources for target \"" << name << "\" " + "which is not built by this project."; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); +} + +//---------------------------------------------------------------------------- +std::string cmTargetSourcesCommand +::Join(const std::vector<std::string> &content) +{ + std::string srcs; + std::string sep; + for(std::vector<std::string>::const_iterator it = content.begin(); + it != content.end(); ++it) + { + srcs += sep + *it; + sep = ";"; + } + return srcs; +} + +//---------------------------------------------------------------------------- +void cmTargetSourcesCommand +::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content, + bool, bool) +{ + tgt->AppendProperty("SOURCES", this->Join(content).c_str()); +} diff --git a/Source/cmTargetSourcesCommand.h b/Source/cmTargetSourcesCommand.h new file mode 100644 index 0000000..dae78c4 --- /dev/null +++ b/Source/cmTargetSourcesCommand.h @@ -0,0 +1,55 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2014 Stephen Kelly <steveire@gmail.com> + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef cmTargetSourcesCommand_h +#define cmTargetSourcesCommand_h + +#include "cmTargetPropCommandBase.h" + +//---------------------------------------------------------------------------- +class cmTargetSourcesCommand : public cmTargetPropCommandBase +{ +public: + /** + * This is a virtual constructor for the command. + */ + virtual cmCommand* Clone() + { + return new cmTargetSourcesCommand; + } + + /** + * This is called when the command is first encountered in + * the CMakeLists.txt file. + */ + virtual bool InitialPass(std::vector<std::string> const& args, + cmExecutionStatus &status); + + /** + * The name of the command as specified in CMakeList.txt. + */ + virtual std::string GetName() const { return "target_sources";} + + cmTypeMacro(cmTargetSourcesCommand, cmTargetPropCommandBase); + +private: + virtual void HandleImportedTarget(const std::string &tgt); + virtual void HandleMissingTarget(const std::string &name); + + virtual void HandleDirectContent(cmTarget *tgt, + const std::vector<std::string> &content, + bool prepend, bool system); + + virtual std::string Join(const std::vector<std::string> &content); +}; + +#endif diff --git a/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt b/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt index 6b7453f..0200dcb 100644 --- a/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt +++ b/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt @@ -14,6 +14,14 @@ CMake Debug Log at OriginDebug.cmake:16 \(set_property\): Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) + +CMake Debug Log at OriginDebug.cmake:20 \(target_sources\): + Used sources for target OriginDebug: + + \* .*Tests/RunCMake/TargetSources/empty_4.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 3fa5858..5fe9ba7 100644 --- a/Tests/RunCMake/TargetSources/OriginDebug.cmake +++ b/Tests/RunCMake/TargetSources/OriginDebug.cmake @@ -16,3 +16,5 @@ target_link_libraries(OriginDebug iface) set_property(TARGET OriginDebug APPEND PROPERTY SOURCES empty_3.cpp ) + +target_sources(OriginDebug PRIVATE empty_4.cpp) diff --git a/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt b/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt index 683c2e9..fad7073 100644 --- a/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt +++ b/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt @@ -16,6 +16,15 @@ Call Stack \(most recent call first\): OriginDebugIDE.cmake:4 \(include\) CMakeLists.txt:3 \(include\) + +CMake Debug Log at OriginDebug.cmake:20 \(target_sources\): + Used sources for target OriginDebug: + + \* .*Tests/RunCMake/TargetSources/empty_4.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_4.cpp b/Tests/RunCMake/TargetSources/empty_4.cpp new file mode 100644 index 0000000..bfbbdde --- /dev/null +++ b/Tests/RunCMake/TargetSources/empty_4.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +int empty() +{ + return 0; +} |