diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 6f474e70a..bebf2cab2 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -33,6 +33,7 @@ #include "cmIncludeDirectoryCommand.cxx" #include "cmIncludeRegularExpressionCommand.cxx" #include "cmInstallFilesCommand.cxx" +#include "cmInstallProgramsCommand.cxx" #include "cmInstallTargetsCommand.cxx" #include "cmLinkDirectoriesCommand.cxx" #include "cmLinkLibrariesCommand.cxx" @@ -87,6 +88,7 @@ void GetPredefinedCommands(std::list& commands) commands.push_back(new cmIncludeDirectoryCommand); commands.push_back(new cmIncludeRegularExpressionCommand); commands.push_back(new cmInstallFilesCommand); + commands.push_back(new cmInstallProgramsCommand); commands.push_back(new cmInstallTargetsCommand); commands.push_back(new cmLinkDirectoriesCommand); commands.push_back(new cmLinkLibrariesCommand); diff --git a/Source/cmDSPWriter.cxx b/Source/cmDSPWriter.cxx index eff7bf15b..67f1890e9 100644 --- a/Source/cmDSPWriter.cxx +++ b/Source/cmDSPWriter.cxx @@ -114,13 +114,16 @@ void cmDSPWriter::OutputDSPFile() case cmTarget::UTILITY: this->SetBuildType(UTILITY, l->first.c_str()); break; - case cmTarget::INSTALL: + case cmTarget::INSTALL_FILES: + break; + case cmTarget::INSTALL_PROGRAMS: break; default: cmSystemTools::Error("Bad target type", l->first.c_str()); break; } - if (l->second.GetType() != cmTarget::INSTALL) + if ((l->second.GetType() != cmTarget::INSTALL_FILES) + && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)) { this->CreateSingleDSP(l->first.c_str(),l->second); } diff --git a/Source/cmDSWWriter.cxx b/Source/cmDSWWriter.cxx index 3662f28d9..92cc9d455 100644 --- a/Source/cmDSWWriter.cxx +++ b/Source/cmDSWWriter.cxx @@ -171,7 +171,8 @@ void cmDSWWriter::WriteDSWFile(std::ostream& fout) } } // Write the project into the DSW file - if (l->second.GetType() != cmTarget::INSTALL) + if ((l->second.GetType() != cmTarget::INSTALL_FILES) + && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)) { this->WriteProject(fout, si->c_str(), dir.c_str(), pg->GetDSPWriter(),l->second); diff --git a/Source/cmInstallFilesCommand.cxx b/Source/cmInstallFilesCommand.cxx index 4de311026..d7f68e56a 100644 --- a/Source/cmInstallFilesCommand.cxx +++ b/Source/cmInstallFilesCommand.cxx @@ -52,9 +52,9 @@ bool cmInstallFilesCommand::InitialPass(std::vector& args) cmTargets &tgts = m_Makefile->GetTargets(); std::vector::iterator s = args.begin(); - if (tgts.find("INSTALL") != tgts.end()) + if (tgts.find("INSTALL_FILES") != tgts.end()) { - tgts["INSTALL"].SetInstallPath(args[0].c_str()); + tgts["INSTALL_FILES"].SetInstallPath(args[0].c_str()); } ++s; for (;s != args.end(); ++s) @@ -71,7 +71,7 @@ void cmInstallFilesCommand::FinalPass() std::string testf; std::string ext = m_FinalArgs[0]; - if (tgts.find("INSTALL") == tgts.end()) + if (tgts.find("INSTALL_FILES") == tgts.end()) { return; } @@ -98,7 +98,7 @@ void cmInstallFilesCommand::FinalPass() { testf = c->GetSourceName() + ext; // add to the result - tgts["INSTALL"].GetSourceLists().push_back(testf); + tgts["INSTALL_FILES"].GetSourceLists().push_back(testf); } } // if one wasn't found then assume it is a single class @@ -106,7 +106,7 @@ void cmInstallFilesCommand::FinalPass() { testf = temps + ext; // add to the result - tgts["INSTALL"].GetSourceLists().push_back(testf); + tgts["INSTALL_FILES"].GetSourceLists().push_back(testf); } } } @@ -120,7 +120,7 @@ void cmInstallFilesCommand::FinalPass() // for each argument, get the files for (;s != files.end(); ++s) { - tgts["INSTALL"].GetSourceLists().push_back(*s); + tgts["INSTALL_FILES"].GetSourceLists().push_back(*s); } } } diff --git a/Source/cmInstallProgramsCommand.cxx b/Source/cmInstallProgramsCommand.cxx new file mode 100644 index 000000000..e8fac318f --- /dev/null +++ b/Source/cmInstallProgramsCommand.cxx @@ -0,0 +1,106 @@ +/*========================================================================= + + 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 "cmInstallProgramsCommand.h" +#include "cmCacheManager.h" + +// cmExecutableCommand +bool cmInstallProgramsCommand::InitialPass(std::vector& args) +{ + if(args.size() < 2) + { + this->SetError("called with incorrect number of arguments"); + return false; + } + + cmTargets &tgts = m_Makefile->GetTargets(); + std::vector::iterator s = args.begin(); + if (tgts.find("INSTALL_PROGRAMS") != tgts.end()) + { + tgts["INSTALL_PROGRAMS"].SetInstallPath(args[0].c_str()); + } + ++s; + for (;s != args.end(); ++s) + { + m_FinalArgs.push_back(*s); + } + + return true; +} + +void cmInstallProgramsCommand::FinalPass() +{ + cmTargets &tgts = m_Makefile->GetTargets(); + + if (tgts.find("INSTALL_PROGRAMS") == tgts.end()) + { + return; + } + + // two different options + if (m_FinalArgs.size() > 1) + { + // for each argument, get the programs + for (std::vector::iterator s = m_FinalArgs.begin(); + s != m_FinalArgs.end(); ++s) + { + // replace any variables + std::string temps = *s; + m_Makefile->ExpandVariablesInString(temps); + // add to the result + tgts["INSTALL_PROGRAMS"].GetSourceLists().push_back(temps); + } + } + else // reg exp list + { + std::vector programs; + cmSystemTools::Glob(m_Makefile->GetCurrentDirectory(), + m_FinalArgs[0].c_str(), programs); + + std::vector::iterator s = programs.begin(); + // for each argument, get the programs + for (;s != programs.end(); ++s) + { + tgts["INSTALL_PROGRAMS"].GetSourceLists().push_back(*s); + } + } +} + + diff --git a/Source/cmInstallProgramsCommand.h b/Source/cmInstallProgramsCommand.h new file mode 100644 index 000000000..4c5c37078 --- /dev/null +++ b/Source/cmInstallProgramsCommand.h @@ -0,0 +1,109 @@ +/*========================================================================= + + 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 cmInstallProgramsCommand_h +#define cmInstallProgramsCommand_h + +#include "cmStandardIncludes.h" +#include "cmCommand.h" + +/** \class cmInstallProgramsCommand + * \brief Specifies where to install some programs + * + * cmInstallProgramsCommand specifies the relative path where a list of + * programs should be installed. + */ +class cmInstallProgramsCommand : public cmCommand +{ +public: + /** + * This is a virtual constructor for the command. + */ + virtual cmCommand* Clone() + { + return new cmInstallProgramsCommand; + } + + /** + * This is called when the command is first encountered in + * the CMakeLists.txt file. + */ + virtual bool InitialPass(std::vector& args); + + /** + * The name of the command as specified in CMakeList.txt. + */ + virtual const char* GetName() { return "INSTALL_PROGRAMS";} + + /** + * Succinct documentation. + */ + virtual const char* GetTerseDocumentation() + { + return "Create install rules for programs"; + } + + /** + * This is called at the end after all the information + * specified by the command is accumulated. Most commands do + * not implement this method. At this point, reading and + * writing to the cache can be done. + */ + virtual void FinalPass(); + + /** + * More documentation. + */ + virtual const char* GetFullDocumentation() + { + return + "INSTALL_PROGRAMS(path file file ...)\n" + "INSTALL_PROGRAMS(path regexp)\n" + "Create rules to install the listed programs into the path. Path is relative to the variable CMAKE_INSTALL_PREFIX. There are two forms for this command. In the first the programs can be specified explicitly. In the second form any program in the current directory that match the regular expression will be installed."; + } + + cmTypeMacro(cmInstallProgramsCommand, cmCommand); + + private: + std::vector m_FinalArgs; +}; + + +#endif diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 19cc38612..a509de883 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -122,11 +122,13 @@ void cmMakefile::AddDefaultCommands() #if defined(__APPLE__) this->AddDefinition("APPLE", "1"); #endif - // always creat an empty install target + // always creat an empty install targets for files and programs. cmTarget target; - target.SetType(cmTarget::INSTALL); target.SetInAll(false); - m_Targets.insert(cmTargets::value_type("INSTALL",target)); + target.SetType(cmTarget::INSTALL_FILES); + m_Targets.insert(cmTargets::value_type("INSTALL_FILES", target)); + target.SetType(cmTarget::INSTALL_PROGRAMS); + m_Targets.insert(cmTargets::value_type("INSTALL_PROGRAMS", target)); } cmMakefile::~cmMakefile() diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index ea983f9dc..8fc06ea5a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -44,7 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. void cmTarget::GenerateSourceFilesFromSourceLists(const cmMakefile &mf) { // this is only done for non install targets - if (this->m_TargetType == cmTarget::INSTALL) + if ((this->m_TargetType == cmTarget::INSTALL_FILES) + || (this->m_TargetType == cmTarget::INSTALL_PROGRAMS)) { return; } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 4b8e612f1..e7946a630 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -55,7 +55,7 @@ class cmTarget { public: enum TargetType { EXECUTABLE, WIN32_EXECUTABLE, STATIC_LIBRARY, - SHARED_LIBRARY, UTILITY, INSTALL }; + SHARED_LIBRARY, UTILITY, INSTALL_FILES, INSTALL_PROGRAMS }; /** * Return the type of target. diff --git a/Source/cmUnixMakefileGenerator.cxx b/Source/cmUnixMakefileGenerator.cxx index 966db4a4f..225cd338d 100644 --- a/Source/cmUnixMakefileGenerator.cxx +++ b/Source/cmUnixMakefileGenerator.cxx @@ -1042,7 +1042,7 @@ void cmUnixMakefileGenerator::OutputInstallRules(std::ostream& fout) << cmSystemTools::GetExecutableExtension() << " " << prefix << l->second.GetInstallPath() << "\n"; break; - case cmTarget::INSTALL: + case cmTarget::INSTALL_FILES: { const std::vector &sf = l->second.GetSourceLists(); std::vector::const_iterator i; @@ -1058,7 +1058,7 @@ void cmUnixMakefileGenerator::OutputInstallRules(std::ostream& fout) } else { - fout << "\t $(INSTALL) "; + fout << "\t $(INSTALL_DATA) "; } fout << *i << " " << prefix << l->second.GetInstallPath() << "; \\\n"; @@ -1071,7 +1071,47 @@ void cmUnixMakefileGenerator::OutputInstallRules(std::ostream& fout) } else { - fout << "\t $(INSTALL) "; + fout << "\t $(INSTALL_DATA) "; + } + fout << "${srcdir}/" << *i + << " " << prefix << l->second.GetInstallPath() << "; \\\n"; + fout << "\telse \\\n"; + fout << "\t echo \" ERROR!!! Unable to find: " << *i + << " \"; \\\n"; + fout << "\t fi\n"; + } + } + break; + case cmTarget::INSTALL_PROGRAMS: + { + const std::vector &sf = l->second.GetSourceLists(); + std::vector::const_iterator i; + for (i = sf.begin(); i != sf.end(); ++i) + { + fout << "\t@ echo \"Installing " << *i << " \"\n"; + fout << "\t@if [ -f " << *i << " ] ; then \\\n"; + // avoid using install-sh to install install-sh + // does not work on windows.... + if(*i == "install-sh") + { + fout << "\t cp "; + } + else + { + fout << "\t $(INSTALL_PROGRAM) "; + } + fout << *i + << " " << prefix << l->second.GetInstallPath() << "; \\\n"; + fout << "\t elif [ -f ${srcdir}/" << *i << " ] ; then \\\n"; + // avoid using install-sh to install install-sh + // does not work on windows.... + if(*i == "install-sh") + { + fout << "\t cp "; + } + else + { + fout << "\t $(INSTALL_PROGRAM) "; } fout << "${srcdir}/" << *i << " " << prefix << l->second.GetInstallPath() << "; \\\n"; diff --git a/Templates/CMakeLists.txt b/Templates/CMakeLists.txt index f69f370c1..6c4c135fc 100644 --- a/Templates/CMakeLists.txt +++ b/Templates/CMakeLists.txt @@ -1,2 +1,3 @@ # just install the modules -INSTALL_FILES(/share/CMake/Templates "" configure install-sh CMakeSystemConfig.cmake.in) +INSTALL_FILES(/share/CMake/Templates "" CMakeSystemConfig.cmake.in) +INSTALL_PROGRAMS(/share/CMake/Templates configure install-sh)