From 089aa3e10628aff58992a62b12fa1f1ce6e643b8 Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Fri, 4 May 2001 15:50:26 -0400 Subject: [PATCH] option to make utilities in the all target --- Source/cmAddCustomTargetCommand.cxx | 15 ++++- Source/cmAddCustomTargetCommand.h | 3 +- Source/cmAddTargetCommand.cxx | 66 +++++++++++++++++++ Source/cmAddTargetCommand.h | 98 +++++++++++++++++++++++++++++ Source/cmDSWMakefile.cxx | 4 +- Source/cmDSWWriter.cxx | 4 +- Source/cmMakefile.cxx | 18 +++++- Source/cmMakefile.h | 8 ++- Source/cmTarget.h | 8 +++ Source/cmVTKWrapJavaCommand.cxx | 15 ++++- 10 files changed, 226 insertions(+), 13 deletions(-) create mode 100644 Source/cmAddTargetCommand.cxx create mode 100644 Source/cmAddTargetCommand.h diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index bbe15a2d8..ad3a0f440 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -43,16 +43,27 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // cmAddCustomTargetCommand bool cmAddCustomTargetCommand::Invoke(std::vector& args) { + bool all = false; + if(args.size() < 2 ) { this->SetError("called with incorrect number of arguments"); return false; } - std::vector dep; m_Makefile->ExpandVariablesInString(args[0]); m_Makefile->ExpandVariablesInString(args[1]); + + // all target option + if (args.size() >= 3) + { + if (args[2] == "ALL") + { + all = true; + } + } m_Makefile->AddUtilityCommand(args[0].c_str(), - args[1].c_str()); + args[1].c_str(), all); + return true; } diff --git a/Source/cmAddCustomTargetCommand.h b/Source/cmAddCustomTargetCommand.h index a82207d88..d4cf52029 100644 --- a/Source/cmAddCustomTargetCommand.h +++ b/Source/cmAddCustomTargetCommand.h @@ -90,7 +90,8 @@ public: virtual const char* GetFullDocumentation() { return - "ADD_CUSTOM_TARGET(Name \"command to run\")"; + "ADD_CUSTOM_TARGET(Name \"command to run\" ALL)\n" + "The ALL option is optional. If it is specified it indicates that this target should be added to the Build all target."; } cmTypeMacro(cmAddCustomTargetCommand, cmCommand); diff --git a/Source/cmAddTargetCommand.cxx b/Source/cmAddTargetCommand.cxx new file mode 100644 index 000000000..25f079775 --- /dev/null +++ b/Source/cmAddTargetCommand.cxx @@ -0,0 +1,66 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + +Copyright (c) 2001 Insight Consortium +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * The name of the Insight Consortium, nor the names of any consortium members, + nor of any contributors, may be used to endorse or promote products derived + from this software without specific prior written permission. + + * Modified source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=========================================================================*/ +#include "cmAddTargetCommand.h" + +// cmAddTargetCommand +bool cmAddTargetCommand::Invoke(std::vector& args) +{ + bool all = false; + if(args.size() < 2 ) + { + this->SetError("called with incorrect number of arguments"); + return false; + } + + // all target option + if (args.size() >= 3) + { + if (args[2] == "ALL") + { + all = true; + } + } + std::vector dep; + m_Makefile->AddUtilityCommand(args[0].c_str(), + args[1].c_str(), all); + return true; +} + diff --git a/Source/cmAddTargetCommand.h b/Source/cmAddTargetCommand.h new file mode 100644 index 000000000..e52e24fcc --- /dev/null +++ b/Source/cmAddTargetCommand.h @@ -0,0 +1,98 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + +Copyright (c) 2001 Insight Consortium +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * The name of the Insight Consortium, nor the names of any consortium members, + nor of any contributors, may be used to endorse or promote products derived + from this software without specific prior written permission. + + * Modified source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=========================================================================*/ +#ifndef cmAddTargetCommand_h +#define cmAddTargetCommand_h + +#include "cmStandardIncludes.h" +#include "cmCommand.h" + +/** \class cmAddTargetCommand + * \brief Command that adds a target to the build system. + * + * cmAddTargetCommand adds an extra target to the build system. + * This is useful when you would like to add special + * targets like "install,", "clean," and so on. + */ +class cmAddTargetCommand : public cmCommand +{ +public: + /** + * This is a virtual constructor for the command. + */ + virtual cmCommand* Clone() + { + return new cmAddTargetCommand; + } + + /** + * This is called when the command is first encountered in + * the CMakeLists.txt file. + */ + virtual bool Invoke(std::vector& args); + + /** + * The name of the command as specified in CMakeList.txt. + */ + virtual const char* GetName() + {return "ADD_TARGET";} + + /** + * Succinct documentation. + */ + virtual const char* GetTerseDocumentation() + { + return "Add an extra target to the build system."; + } + + /** + * More documentation. + */ + virtual const char* GetFullDocumentation() + { + return + "ADD_TARGET(Name \"command to run\" ALL)\n" + "Add a target to the make process. The third argument ALL is optional. If it is specified then the target will be added to the all target." ; + } + + cmTypeMacro(cmAddTargetCommand, cmCommand); +}; + +#endif diff --git a/Source/cmDSWMakefile.cxx b/Source/cmDSWMakefile.cxx index 723784ac4..f377780c1 100644 --- a/Source/cmDSWMakefile.cxx +++ b/Source/cmDSWMakefile.cxx @@ -95,7 +95,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout) allListFiles.push_back(m_Makefile); // add a special target that depends on ALL projects for easy build // of Debug only - m_Makefile->AddUtilityCommand("ALL_BUILD", "echo \"Build all projects\""); + m_Makefile->AddUtilityCommand("ALL_BUILD", "echo \"Build all projects\"", false); m_Makefile->FindSubDirectoryCMakeListsFiles(allListFiles); // For each cmMakefile, create a DSP for it, and @@ -144,7 +144,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout) for(cmTargets::const_iterator al = atgts.begin(); al != atgts.end(); ++al) { - if(al->second.GetType() != cmTarget::UTILITY) + if(al->second.IsInAll()) { l->second.GetLinkLibraries().push_back( cmTarget::LinkLibraries::value_type(al->first, cmTarget::GENERAL)); diff --git a/Source/cmDSWWriter.cxx b/Source/cmDSWWriter.cxx index 723784ac4..f377780c1 100644 --- a/Source/cmDSWWriter.cxx +++ b/Source/cmDSWWriter.cxx @@ -95,7 +95,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout) allListFiles.push_back(m_Makefile); // add a special target that depends on ALL projects for easy build // of Debug only - m_Makefile->AddUtilityCommand("ALL_BUILD", "echo \"Build all projects\""); + m_Makefile->AddUtilityCommand("ALL_BUILD", "echo \"Build all projects\"", false); m_Makefile->FindSubDirectoryCMakeListsFiles(allListFiles); // For each cmMakefile, create a DSP for it, and @@ -144,7 +144,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout) for(cmTargets::const_iterator al = atgts.begin(); al != atgts.end(); ++al) { - if(al->second.GetType() != cmTarget::UTILITY) + if(al->second.IsInAll()) { l->second.GetLinkLibraries().push_back( cmTarget::LinkLibraries::value_type(al->first, cmTarget::GENERAL)); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 0cfe26545..9680064c2 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -482,12 +482,24 @@ void cmMakefile::AddExecutable(const char *exeName, void cmMakefile::AddUtilityCommand(const char* utilityName, - const char* command) + const char* command, + bool all) +{ + std::vector empty; + this->AddUtilityCommand(utilityName,command,all, + empty,empty); +} + +void cmMakefile::AddUtilityCommand(const char* utilityName, + const char* command, + bool all, + const std::vector &dep, + const std::vector &out) { cmTarget target; target.SetType(cmTarget::UTILITY); - std::vector empty; - cmCustomCommand cc(utilityName, command, empty, empty); + target.SetInAll(all); + cmCustomCommand cc(utilityName, command, dep, out); target.GetCustomCommands().push_back(cc); m_Targets.insert(cmTargets::value_type(utilityName,target)); } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index ff60091e6..4823d36a9 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -140,7 +140,13 @@ public: * a command that is run every time a target is built. */ void AddUtilityCommand(const char* utilityName, - const char* command); + const char* command, + bool all); + void AddUtilityCommand(const char* utilityName, + const char* command, + bool all, + const std::vector &depends, + const std::vector &outputs); /** * Add a utility on which this project depends. A utility is an executable diff --git a/Source/cmTarget.h b/Source/cmTarget.h index dd0152196..8def2551b 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -65,6 +65,13 @@ public: void SetType(TargetType f) { m_TargetType = f; } + /** + * Indicate whether the target is part of the all target + */ + bool IsInAll() const { return m_InAll; } + bool GetInAll() const { return m_InAll; } + void SetInAll(bool f) { m_InAll = f; } + /** * Get the list of the custom commands for this target */ @@ -110,6 +117,7 @@ private: TargetType m_TargetType; std::vector m_SourceFiles; LinkLibraries m_LinkLibraries; + bool m_InAll; }; typedef std::map cmTargets; diff --git a/Source/cmVTKWrapJavaCommand.cxx b/Source/cmVTKWrapJavaCommand.cxx index d290b3ac4..b0d191ed1 100644 --- a/Source/cmVTKWrapJavaCommand.cxx +++ b/Source/cmVTKWrapJavaCommand.cxx @@ -104,6 +104,8 @@ void cmVTKWrapJavaCommand::FinalPass() int lastClass = m_WrapClasses.size(); std::vector depends; std::vector depends2; + std::vector alldepends; + std::vector empty; std::string wjava = "${VTK_WRAP_JAVA_EXE}"; std::string pjava = "${VTK_PARSE_JAVA_EXE}"; std::string hints = "${VTK_WRAP_HINTS}"; @@ -118,7 +120,8 @@ void cmVTKWrapJavaCommand::FinalPass() // wrap java std::string res = m_WrapClasses[classNum].GetSourceName() + ".cxx"; - std::string res2 = m_OriginalNames[classNum] + ".java"; + std::string res2 = resultDirectory + "/" + + m_OriginalNames[classNum] + ".java"; std::string cmd = wjava + " " + m_WrapHeaders[classNum] + " " + hints + (m_WrapClasses[classNum].IsAnAbstractClass() ? " 0 " : " 1 ") + " > " + m_WrapClasses[classNum].GetSourceName() + ".cxx"; @@ -127,11 +130,19 @@ void cmVTKWrapJavaCommand::FinalPass() res.c_str(), m_LibraryName.c_str()); cmd = pjava + " " + m_WrapHeaders[classNum] + " " - + hints + (m_WrapClasses[classNum].IsAnAbstractClass() ? " 0 " : " 1 ") + " > " + resultDirectory + "/" + m_OriginalNames[classNum] + ".java"; + + hints + (m_WrapClasses[classNum].IsAnAbstractClass() ? " 0 " : " 1 ") + " > " + res2; m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(), cmd.c_str(), depends2, res2.c_str(), m_LibraryName.c_str()); + alldepends.push_back(res2); } + + m_Makefile->AddUtilityCommand((m_LibraryName+"JavaClasses").c_str(), + "", + true, + alldepends, + empty); + }