From c5f70ff27fb7ea9d2421b4cc25e303f171612525 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 9 Oct 2008 11:01:23 -0400 Subject: [PATCH] ENH: Allow custom sources in custom targets This adds a SOURCES option to ADD_CUSTOM_TARGET, enabling users to specify extra sources for inclusion in the target. Such sources may not build, but will show up in the IDE project files for convenient editing. See issue #5848. --- Source/cmAddCustomTargetCommand.cxx | 19 ++++++++++++++++--- Source/cmAddCustomTargetCommand.h | 11 +++++++++-- Tests/CustomCommand/CMakeLists.txt | 1 + 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index 94854b1ab..b609bd290 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -55,6 +55,7 @@ bool cmAddCustomTargetCommand bool verbatim = false; std::string comment_buffer; const char* comment = 0; + std::vector sources; // Keep track of parser state. enum tdoing { @@ -62,6 +63,7 @@ bool cmAddCustomTargetCommand doing_depends, doing_working_directory, doing_comment, + doing_source, doing_verbatim }; tdoing doing = doing_command; @@ -111,6 +113,10 @@ bool cmAddCustomTargetCommand currentLine.clear(); } } + else if(copy == "SOURCES") + { + doing = doing_source; + } else { switch (doing) @@ -128,6 +134,9 @@ bool cmAddCustomTargetCommand comment_buffer = copy; comment = comment_buffer.c_str(); break; + case doing_source: + sources.push_back(copy); + break; default: this->SetError("Wrong syntax. Unknown type of argument."); return false; @@ -164,9 +173,13 @@ bool cmAddCustomTargetCommand // Add the utility target to the makefile. bool escapeOldStyle = !verbatim; - this->Makefile->AddUtilityCommand(args[0].c_str(), excludeFromAll, - working_directory.c_str(), depends, - commandLines, escapeOldStyle, comment); + cmTarget* target = + this->Makefile->AddUtilityCommand(args[0].c_str(), excludeFromAll, + working_directory.c_str(), depends, + commandLines, escapeOldStyle, comment); + + // Add additional user-specified source files to the target. + target->AddSources(sources); return true; } diff --git a/Source/cmAddCustomTargetCommand.h b/Source/cmAddCustomTargetCommand.h index c988e6372..9eef4447f 100644 --- a/Source/cmAddCustomTargetCommand.h +++ b/Source/cmAddCustomTargetCommand.h @@ -68,7 +68,8 @@ public: " [COMMAND command2 [args2...] ...]\n" " [DEPENDS depend depend depend ... ]\n" " [WORKING_DIRECTORY dir]\n" - " [COMMENT comment] [VERBATIM])\n" + " [COMMENT comment] [VERBATIM]\n" + " [SOURCES src1 [src2...]])\n" "Adds a target with the given name that executes the given commands. " "The target has no output file and is ALWAYS CONSIDERED OUT OF DATE " "even if the commands try to create a file with the name of the " @@ -94,7 +95,13 @@ public: "Use of VERBATIM is recommended as it enables correct behavior. " "When VERBATIM is not given the behavior is platform specific. " "In the future VERBATIM may be enabled by default. The only reason " - "it is an option is to preserve compatibility with older CMake code."; + "it is an option is to preserve compatibility with older CMake code." + "\n" + "The SOURCES option specifies additional source files to be included " + "in the custom target. " + "Specified source files will be added to IDE project files for " + "convenience in editing even if they have not build rules." + ; } cmTypeMacro(cmAddCustomTargetCommand, cmCommand); diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt index b8410e183..8ac1f12cf 100644 --- a/Tests/CustomCommand/CMakeLists.txt +++ b/Tests/CustomCommand/CMakeLists.txt @@ -100,6 +100,7 @@ ADD_CUSTOM_TARGET(TDocument ALL ${PROJECT_BINARY_DIR}/doc2.h DEPENDS ${PROJECT_BINARY_DIR}/doc1.h doc1.txt COMMENT "Running top-level TDocument commands" + SOURCES doc1.tex ) # Setup a pre- and post-build pair that will fail if not run in the