From 885e37da224353e242e7135b0fc8e6f2445a54c7 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Mon, 7 May 2001 18:11:16 -0400 Subject: ENH: call configure from cmake --- CMakeSystemConfig.cmake.in | 2 - Source/CMakeBuildTargets.cxx | 24 ++++--- Source/Makefile.in | 2 +- Source/cmCacheManager.cxx | 32 +++++++-- Source/cmCommands.cxx | 10 +-- Source/cmConfigureFile.cxx | 126 ----------------------------------- Source/cmConfigureFile.h | 100 ---------------------------- Source/cmConfigureFileCommand.cxx | 133 +++++++++++++++++++++++++++++++++++++ Source/cmConfigureFileCommand.h | 102 ++++++++++++++++++++++++++++ Source/cmExecProgram.cxx | 56 ---------------- Source/cmExecProgram.h | 97 --------------------------- Source/cmExecProgramCommand.cxx | 71 ++++++++++++++++++++ Source/cmExecProgramCommand.h | 97 +++++++++++++++++++++++++++ Source/cmMakeDirectoryCommand.cxx | 56 ++++++++++++++++ Source/cmMakeDirectoryCommand.h | 101 ++++++++++++++++++++++++++++ Source/cmMakefile.cxx | 62 +---------------- Source/cmMakefile.h | 7 -- Source/cmSystemTools.cxx | 22 +++++- Source/cmUnixMakefileGenerator.cxx | 105 +++++++++++++++++++++++++++-- Source/cmUnixMakefileGenerator.h | 23 ++++++- 20 files changed, 748 insertions(+), 480 deletions(-) delete mode 100644 Source/cmConfigureFile.cxx delete mode 100644 Source/cmConfigureFile.h create mode 100644 Source/cmConfigureFileCommand.cxx create mode 100644 Source/cmConfigureFileCommand.h delete mode 100644 Source/cmExecProgram.cxx delete mode 100644 Source/cmExecProgram.h create mode 100644 Source/cmExecProgramCommand.cxx create mode 100644 Source/cmExecProgramCommand.h create mode 100644 Source/cmMakeDirectoryCommand.cxx create mode 100644 Source/cmMakeDirectoryCommand.h diff --git a/CMakeSystemConfig.cmake.in b/CMakeSystemConfig.cmake.in index c7a04c7..c68d768 100644 --- a/CMakeSystemConfig.cmake.in +++ b/CMakeSystemConfig.cmake.in @@ -3,8 +3,6 @@ # in, which need not be the source directory # SET (WORDS_BIGENDIAN @CMAKE_WORDS_BIGENDIAN@) -SET (HAVE_LIMITS_H @HAVE_LIMITS_H@) -SET (HAVE_UNISTD_H @HAVE_UNISTD_H@) SET (CMAKE_USE_SPROC @CMAKE_USE_SPROC@) SET (CMAKE_USE_PTHREADS @CMAKE_USE_PTHREADS@) SET (CMAKE_HP_PTHREADS @CMAKE_HP_PTHREADS@) diff --git a/Source/CMakeBuildTargets.cxx b/Source/CMakeBuildTargets.cxx index 0fa4086..d813f35 100644 --- a/Source/CMakeBuildTargets.cxx +++ b/Source/CMakeBuildTargets.cxx @@ -104,14 +104,23 @@ int main(int ac, char** av) std::string path = arg.substr(2); mf.SetHomeOutputDirectory(path.c_str()); } + if(arg.find("-D",0) == 0) + { + std::string value = arg.substr(2); + mf.AddDefinition(value.c_str(), true); + } } } // Only generate makefiles if not trying to make the cache - if(!makeCache) + cmUnixMakefileGenerator* gen = new cmUnixMakefileGenerator; + mf.SetMakefileGenerator(gen); + if(makeCache) { - mf.SetMakefileGenerator(new cmUnixMakefileGenerator); + // generate only enough for the cache + gen->SetCacheOnlyOn(); + // generate for this makefile and all below it + gen->SetRecurseOn(); } - // Read and parse the input makefile mf.MakeStartDirectoriesCurrent(); @@ -137,14 +146,7 @@ int main(int ac, char** av) Usage(av[0]); return -1; } - if(makeCache) - { - mf.GenerateCacheOnly(); - } - else - { - mf.GenerateMakefile(); - } + mf.GenerateMakefile(); cmCacheManager::GetInstance()->SaveCache(&mf); if(makeCache) { diff --git a/Source/Makefile.in b/Source/Makefile.in index aff3e90..ba65e25 100644 --- a/Source/Makefile.in +++ b/Source/Makefile.in @@ -40,7 +40,7 @@ cmSourceFile.o : $(DEPENDS) cmDirectory.o : $(DEPENDS) cmCustomCommand.o : $(DEPENDS) cmUnixMakefileGenerator.o : $(DEPENDS) -cmCommands.o : $(DEPENDS) $(srcdir)/*.cxx +cmCommands.o : $(DEPENDS) $(srcdir)/*Command*.cxx cmTarget.o : $(DEPENDS) cmCacheManager.o : $(DEPENDS) cmSourceGroup.o : $(DEPENDS) diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index cdffb56..7582f37 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -185,13 +185,30 @@ bool cmCacheManager::SaveCache(const char* path) const for( std::map::const_iterator i = m_Cache.begin(); i != m_Cache.end(); ++i) { + const CacheEntry& ce = (*i).second; + CacheEntryType t = ce.m_Type; + if(t != INTERNAL) + { + // Format is key:type=value + cmCacheManager::OutputHelpString(fout, ce.m_HelpString); + fout << (*i).first.c_str() << ":" + << cmCacheManagerTypes[t] << "=" + << ce.m_Value << "\n"; + } + } + for( std::map::const_iterator i = m_Cache.begin(); + i != m_Cache.end(); ++i) + { const CacheEntry& ce = (*i).second; CacheEntryType t = ce.m_Type; - // Format is key:type=value - cmCacheManager::OutputHelpString(fout, ce.m_HelpString); - fout << (*i).first.c_str() << ":" - << cmCacheManagerTypes[t] << "=" - << ce.m_Value << "\n"; + if(t == INTERNAL) + { + // Format is key:type=value + cmCacheManager::OutputHelpString(fout, ce.m_HelpString); + fout << (*i).first.c_str() << ":" + << cmCacheManagerTypes[t] << "=" + << ce.m_Value << "\n"; + } } fout << "\n"; fout.close(); @@ -279,7 +296,10 @@ void cmCacheManager::PrintCache(std::ostream& out) const for(std::map::const_iterator i = m_Cache.begin(); i != m_Cache.end(); ++i) { - out << (*i).first.c_str() << " = " << (*i).second.m_Value.c_str() << std::endl; + if((*i).second.m_Type != INTERNAL) + { + out << (*i).first.c_str() << " = " << (*i).second.m_Value.c_str() << std::endl; + } } out << "\n\n"; out << "To change values in the CMakeCache, \nedit CMakeCache.txt in your output directory.\n"; diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 3da08aa..4ecb917 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -23,11 +23,11 @@ #include "cmCablePackageEntryCommand.cxx" #include "cmCableSourceFilesCommand.cxx" #include "cmCableWrapCommand.cxx" -#include "cmConfigureFile.cxx" +#include "cmConfigureFileCommand.cxx" #include "cmConfigureFileNoAutoconf.cxx" #include "cmElseCommand.cxx" #include "cmEndIfCommand.cxx" -#include "cmExecProgram.cxx" +#include "cmExecProgramCommand.cxx" #include "cmFindFileCommand.cxx" #include "cmFindIncludeCommand.cxx" #include "cmFindLibraryCommand.cxx" @@ -39,6 +39,7 @@ #include "cmIncludeRegularExpressionCommand.cxx" #include "cmLinkDirectoriesCommand.cxx" #include "cmLinkLibrariesCommand.cxx" +#include "cmMakeDirectoryCommand.cxx" #include "cmOptionCommand.cxx" #include "cmProjectCommand.cxx" #include "cmSetCommand.cxx" @@ -74,11 +75,11 @@ void GetPredefinedCommands(std::list& commands) commands.push_back(new cmCablePackageCommand); commands.push_back(new cmCableSourceFilesCommand); commands.push_back(new cmCableWrapCommand); - commands.push_back(new cmConfigureFile); + commands.push_back(new cmConfigureFileCommand); commands.push_back(new cmConfigureFileNoAutoconf); commands.push_back(new cmElseCommand); commands.push_back(new cmEndIfCommand); - commands.push_back(new cmExecProgram); + commands.push_back(new cmExecProgramCommand); commands.push_back(new cmFindFileCommand); commands.push_back(new cmFindIncludeCommand); commands.push_back(new cmFindLibraryCommand); @@ -90,6 +91,7 @@ void GetPredefinedCommands(std::list& commands) commands.push_back(new cmIncludeRegularExpressionCommand); commands.push_back(new cmLinkDirectoriesCommand); commands.push_back(new cmLinkLibrariesCommand); + commands.push_back(new cmMakeDirectoryCommand); commands.push_back(new cmOptionCommand); commands.push_back(new cmProjectCommand); commands.push_back(new cmSetCommand); diff --git a/Source/cmConfigureFile.cxx b/Source/cmConfigureFile.cxx deleted file mode 100644 index 8171faf..0000000 --- a/Source/cmConfigureFile.cxx +++ /dev/null @@ -1,126 +0,0 @@ -/*========================================================================= - - 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 "cmConfigureFile.h" - -// cmConfigureFile -bool cmConfigureFile::Invoke(std::vector& args) -{ - if(args.size() != 2 ) - { - this->SetError("called with incorrect number of arguments, expected 2"); - return false; - } - m_InputFile = args[0]; - m_OuputFile = args[1]; - return true; -} - -void cmConfigureFile::FinalPass() -{ - m_Makefile->ExpandVariablesInString(m_InputFile); - m_Makefile->ExpandVariablesInString(m_OuputFile); - std::ifstream fin(m_InputFile.c_str()); - if(!fin) - { - cmSystemTools::Error("Could not open file for read in copy operatation", - m_InputFile.c_str()); - return; - } - cmSystemTools::ConvertToUnixSlashes(m_OuputFile); - std::string::size_type pos = m_OuputFile.rfind('/'); - if(pos != std::string::npos) - { - std::string path = m_OuputFile.substr(0, pos); - cmSystemTools::MakeDirectory(path.c_str()); - } - std::string tempOutputFile = m_OuputFile; - tempOutputFile += ".tmp"; - std::ofstream fout(tempOutputFile.c_str()); - if(!fout) - { - cmSystemTools::Error("Could not open file for write in copy operatation", - tempOutputFile.c_str()); - return; - } - // now copy input to output and expand varibles in the - // input file at the same time - const int bufSize = 4096; - char buffer[bufSize]; - std::string inLine; - cmRegularExpression cmdefine("#cmakedefine[ \t]*([A-Za-z_0-9]*)"); - while(fin) - { - fin.getline(buffer, bufSize); - if(fin) - { - inLine = buffer; - m_Makefile->ExpandVariablesInString(inLine); - // This call will remove all tcl variable substitutions of the form ${Foo} - // m_Makefile->RemoveVariablesInString(inLine); - - // look for special cmakedefine symbol and handle it - // is the symbol defined - if (cmdefine.find(inLine)) - { - const char *def = m_Makefile->GetDefinition(cmdefine.match(1).c_str()); - if(!cmSystemTools::IsOff(def)) - { - cmSystemTools::ReplaceString(inLine, - "#cmakedefine", "#define"); - } - else - { - cmSystemTools::ReplaceString(inLine, - "#cmakedefine", "#undef"); - } - } - fout << inLine << "\n"; - } - } - // close the files before attempting to copy - fin.close(); - fout.close(); - cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(), - m_OuputFile.c_str()); - cmSystemTools::RemoveFile(tempOutputFile.c_str()); -} - - diff --git a/Source/cmConfigureFile.h b/Source/cmConfigureFile.h deleted file mode 100644 index 54d3e5d..0000000 --- a/Source/cmConfigureFile.h +++ /dev/null @@ -1,100 +0,0 @@ -/*========================================================================= - - 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 cmConfigureFile_h -#define cmConfigureFile_h - -#include "cmStandardIncludes.h" -#include "cmCommand.h" - -class cmConfigureFile : public cmCommand -{ -public: - virtual cmCommand* Clone() - { - return new cmConfigureFile; - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - virtual bool Invoke(std::vector& args); - - /** - * The name of the command as specified in CMakeList.txt. - */ - virtual const char* GetName() { return "CONFIGURE_FILE";} - - /** - * Succinct documentation. - */ - virtual const char* GetTerseDocumentation() - { - return "Create a file from an autoconf style file.in file."; - } - - /** - * Longer documentation. - */ - virtual const char* GetFullDocumentation() - { - return - "CONFIGURE_FILE(InputFile OutputFile)\n" - "The Input and Ouput files have to have full paths.\n" - "They can also use variables like CMAKE_BINARY_DIR,CMAKE_SOURCE_DIR.\n" - "This command replaces any variables in the input file with their\n" - "values as determined by CMake. If a variables in not defined, it\n" - "will be replaced with nothing."; - } - - /** - * Create the header files in this pass. This is so - * all varibles can be expaned. - */ - virtual void FinalPass(); -private: - std::string m_InputFile; - std::string m_OuputFile; -}; - - - -#endif diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx new file mode 100644 index 0000000..77171a2 --- /dev/null +++ b/Source/cmConfigureFileCommand.cxx @@ -0,0 +1,133 @@ +/*========================================================================= + + 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 "cmConfigureFileCommand.h" + +// cmConfigureFileCommand +bool cmConfigureFileCommand::Invoke(std::vector& args) +{ + if(args.size() < 2 ) + { + this->SetError("called with incorrect number of arguments, expected 2"); + return false; + } + m_InputFile = args[0]; + m_OuputFile = args[1]; + m_CopyOnly = false; + if(args[2] == "COPYONLY") + { + m_CopyOnly = true; + } + + return true; +} + +void cmConfigureFileCommand::FinalPass() +{ + m_Makefile->ExpandVariablesInString(m_InputFile); + m_Makefile->ExpandVariablesInString(m_OuputFile); + std::ifstream fin(m_InputFile.c_str()); + if(!fin) + { + cmSystemTools::Error("Could not open file for read in copy operatation", + m_InputFile.c_str()); + return; + } + cmSystemTools::ConvertToUnixSlashes(m_OuputFile); + std::string::size_type pos = m_OuputFile.rfind('/'); + if(pos != std::string::npos) + { + std::string path = m_OuputFile.substr(0, pos); + cmSystemTools::MakeDirectory(path.c_str()); + } + std::string tempOutputFile = m_OuputFile; + tempOutputFile += ".tmp"; + std::ofstream fout(tempOutputFile.c_str()); + if(!fout) + { + cmSystemTools::Error("Could not open file for write in copy operatation", + tempOutputFile.c_str()); + return; + } + // now copy input to output and expand varibles in the + // input file at the same time + const int bufSize = 4096; + char buffer[bufSize]; + std::string inLine; + cmRegularExpression cmdefine("#cmakedefine[ \t]*([A-Za-z_0-9]*)"); + while(fin) + { + fin.getline(buffer, bufSize); + if(fin) + { + inLine = buffer; + if(!m_CopyOnly) + { + m_Makefile->ExpandVariablesInString(inLine); + m_Makefile->RemoveVariablesInString(inLine); + // look for special cmakedefine symbol and handle it + // is the symbol defined + if (cmdefine.find(inLine)) + { + const char *def = m_Makefile->GetDefinition(cmdefine.match(1).c_str()); + if(!cmSystemTools::IsOff(def)) + { + cmSystemTools::ReplaceString(inLine, + "#cmakedefine", "#define"); + } + else + { + cmSystemTools::ReplaceString(inLine, + "#cmakedefine", "#undef"); + } + } + } + fout << inLine << "\n"; + } + } + // close the files before attempting to copy + fin.close(); + fout.close(); + cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(), + m_OuputFile.c_str()); + cmSystemTools::RemoveFile(tempOutputFile.c_str()); +} + + diff --git a/Source/cmConfigureFileCommand.h b/Source/cmConfigureFileCommand.h new file mode 100644 index 0000000..e827f92 --- /dev/null +++ b/Source/cmConfigureFileCommand.h @@ -0,0 +1,102 @@ +/*========================================================================= + + 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 cmConfigureFileCommand_h +#define cmConfigureFileCommand_h + +#include "cmStandardIncludes.h" +#include "cmCommand.h" + +class cmConfigureFileCommand : public cmCommand +{ +public: + virtual cmCommand* Clone() + { + return new cmConfigureFileCommand; + } + + /** + * This is called when the command is first encountered in + * the input file. + */ + virtual bool Invoke(std::vector& args); + + /** + * The name of the command as specified in CMakeList.txt. + */ + virtual const char* GetName() { return "CONFIGURE_FILE";} + + /** + * Succinct documentation. + */ + virtual const char* GetTerseDocumentation() + { + return "Create a file from an autoconf style file.in file."; + } + + /** + * Longer documentation. + */ + virtual const char* GetFullDocumentation() + { + return + "CONFIGURE_FILE(InputFile OutputFile [COPYONLY])\n" + "The Input and Ouput files have to have full paths.\n" + "They can also use variables like CMAKE_BINARY_DIR,CMAKE_SOURCE_DIR.\n" + "This command replaces any variables in the input file with their\n" + "values as determined by CMake. If a variables in not defined, it\n" + "will be replaced with nothing. If COPYONLY is passed in, then\n" + "then no varible expansion will take place.\n"; + } + + /** + * Create the header files in this pass. This is so + * all varibles can be expaned. + */ + virtual void FinalPass(); +private: + std::string m_InputFile; + std::string m_OuputFile; + bool m_CopyOnly; +}; + + + +#endif diff --git a/Source/cmExecProgram.cxx b/Source/cmExecProgram.cxx deleted file mode 100644 index a1850ff..0000000 --- a/Source/cmExecProgram.cxx +++ /dev/null @@ -1,56 +0,0 @@ -/*========================================================================= - - 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 "cmExecProgram.h" -#include "cmSystemTools.h" - -// cmExecProgram -bool cmExecProgram::Invoke(std::vector& args) -{ - if(args.size() < 1 ) - { - this->SetError("called with incorrect number of arguments"); - return false; - } - std::string output; - cmSystemTools::RunCommand(args[0].c_str(), output); - return true; -} - diff --git a/Source/cmExecProgram.h b/Source/cmExecProgram.h deleted file mode 100644 index 26044f4..0000000 --- a/Source/cmExecProgram.h +++ /dev/null @@ -1,97 +0,0 @@ -/*========================================================================= - - 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 cmExecProgram_h -#define cmExecProgram_h - -#include "cmStandardIncludes.h" -#include "cmCommand.h" - -/** \class cmExecProgram - * \brief Command that adds a target to the build system. - * - * cmExecProgram 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 cmExecProgram : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - virtual cmCommand* Clone() - { - return new cmExecProgram; - } - - /** - * 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 "EXEC_PROGRAM";} - - /** - * Succinct documentation. - */ - virtual const char* GetTerseDocumentation() - { - return "Run and executable program during the processing of the CMakeList.txt file."; - } - - /** - * More documentation. - */ - virtual const char* GetFullDocumentation() - { - return - "EXEC_PROGRAM(Executble )"; - } - - cmTypeMacro(cmExecProgram, cmCommand); -}; - -#endif diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx new file mode 100644 index 0000000..b9f94ca --- /dev/null +++ b/Source/cmExecProgramCommand.cxx @@ -0,0 +1,71 @@ +/*========================================================================= + + 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 "cmExecProgramCommand.h" +#include "cmSystemTools.h" + +// cmExecProgramCommand +bool cmExecProgramCommand::Invoke(std::vector& args) +{ + if(args.size() < 1 ) + { + this->SetError("called with incorrect number of arguments"); + return false; + } + std::string output; + m_Makefile->ExpandVariablesInString(args[0]); + m_Makefile->ExpandVariablesInString(args[1]); + if(args.size() == 2) + { + cmSystemTools::MakeDirectory(args[1].c_str()); + std::string command; + command = "cd "; + command += args[1].c_str(); + command += "; "; + command += args[0].c_str(); + cmSystemTools::RunCommand(command.c_str(), output); + } + else + { + cmSystemTools::RunCommand(args[0].c_str(), output); + } + return true; +} + diff --git a/Source/cmExecProgramCommand.h b/Source/cmExecProgramCommand.h new file mode 100644 index 0000000..5e2ea5e --- /dev/null +++ b/Source/cmExecProgramCommand.h @@ -0,0 +1,97 @@ +/*========================================================================= + + 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 cmExecProgramCommand_h +#define cmExecProgramCommand_h + +#include "cmStandardIncludes.h" +#include "cmCommand.h" + +/** \class cmExecProgramCommand + * \brief Command that adds a target to the build system. + * + * cmExecProgramCommand 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 cmExecProgramCommand : public cmCommand +{ +public: + /** + * This is a virtual constructor for the command. + */ + virtual cmCommand* Clone() + { + return new cmExecProgramCommand; + } + + /** + * 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 "EXEC_PROGRAM";} + + /** + * Succinct documentation. + */ + virtual const char* GetTerseDocumentation() + { + return "Run and executable program during the processing of the CMakeList.txt file."; + } + + /** + * More documentation. + */ + virtual const char* GetFullDocumentation() + { + return + "EXEC_PROGRAM(Executble )"; + } + + cmTypeMacro(cmExecProgramCommand, cmCommand); +}; + +#endif diff --git a/Source/cmMakeDirectoryCommand.cxx b/Source/cmMakeDirectoryCommand.cxx new file mode 100644 index 0000000..4ccefc5 --- /dev/null +++ b/Source/cmMakeDirectoryCommand.cxx @@ -0,0 +1,56 @@ +/*========================================================================= + + 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 "cmMakeDirectoryCommand.h" +#include "cmDirectory.h" + +// cmMakeDirectoryCommand +bool cmMakeDirectoryCommand::Invoke(std::vector& args) +{ + if(args.size() < 1 ) + { + this->SetError("called with incorrect number of arguments"); + return false; + } + m_Makefile->ExpandVariablesInString(args[0]); + cmSystemTools::MakeDirectory(args[0].c_str()); + return true; +} + diff --git a/Source/cmMakeDirectoryCommand.h b/Source/cmMakeDirectoryCommand.h new file mode 100644 index 0000000..3f9db4c --- /dev/null +++ b/Source/cmMakeDirectoryCommand.h @@ -0,0 +1,101 @@ +/*========================================================================= + + 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 cmMakeDirectoryCommand_h +#define cmMakeDirectoryCommand_h + +#include "cmStandardIncludes.h" +#include "cmCommand.h" + +/** \class cmMakeDirectoryCommand + * \brief Specify auxiliary source code directories. + * + * cmMakeDirectoryCommand specifies source code directories + * that must be built as part of this build process. This directories + * are not recursively processed like the SUBDIR command (cmSubdirCommand). + * A side effect of this command is to create a subdirectory in the build + * directory structure. + */ +class cmMakeDirectoryCommand : public cmCommand +{ +public: + /** + * This is a virtual constructor for the command. + */ + virtual cmCommand* Clone() + { + return new cmMakeDirectoryCommand; + } + + /** + * 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 "MAKE_DIRECTORY";} + + /** + * Succinct documentation. + */ + virtual const char* GetTerseDocumentation() + { + return "Create a directory in the build tree if it does not exist.\n" + "Parent directories will be created if the do not exist.."; + } + + /** + * More documentation. + */ + virtual const char* GetFullDocumentation() + { + return + "MAKE_DIRECTORY(directory)"; + } + + cmTypeMacro(cmMakeDirectoryCommand, cmCommand); +}; + + + +#endif diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d8dfe2f..c5d566e 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -75,7 +75,7 @@ void cmMakefile::AddDefaultCommands() { this->AddCommand(*i); } -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) this->AddDefinition("WIN32", "1"); #else this->AddDefinition("UNIX", "1"); @@ -729,66 +729,6 @@ cmMakefile::FindSubDirectoryCMakeListsFiles(std::vector& } } - -void cmMakefile::GenerateCacheOnly() -{ - std::vector makefiles; - this->FindSubDirectoryCMakeListsFiles(makefiles); - for(std::vector::iterator i = makefiles.begin(); - i != makefiles.end(); ++i) - { - cmMakefile* mf = *i; - std::string source = mf->GetHomeDirectory(); - source += "/CMake/CMakeMakefileTemplate.in"; - cmSystemTools::MakeDirectory(mf->GetStartOutputDirectory()); - std::string dest = mf->GetStartOutputDirectory(); - dest += "/Makefile"; - std::ofstream fout(dest.c_str()); - std::cout << "cmake: creating : " << dest.c_str() << "\n"; - if(!fout) - { - cmSystemTools::Error("Failed to open file for write " , dest.c_str()); - } - else - { - if(strcmp(mf->GetHomeDirectory(), - mf->GetHomeOutputDirectory()) == 0) - { - fout << "srcdir = .\n\n"; - } - else - { - fout << "srcdir = " << mf->GetStartDirectory() << "\n"; - fout << "VPATH = " << mf->GetStartDirectory() << "\n"; - } - } - fout << "include " - << mf->GetHomeOutputDirectory() << "/CMake/CMakeMaster.make\n"; - dest = mf->GetStartOutputDirectory(); - dest += "/CMakeTargets.make"; - // make sure there is a CMakeTargets.make file as some - // makes require it to exist - if(!cmSystemTools::FileExists(dest.c_str())) - { - std::cout << "cmake: creating : " << dest.c_str() << "\n"; - std::ofstream fout(dest.c_str()); - if(!fout) - { - cmSystemTools::Error("Failed to open file for write " , dest.c_str()); - } - fout << "#Initial CMakeTargets.make file created only to keep \n"; - fout << "#certain makes happy that don't like to include makefiles\n"; - fout << "#that do not exist\n"; - } - } - - // CLEAN up the makefiles created - for(unsigned int i =0; i < makefiles.size(); ++i) - { - delete makefiles[i]; - } -} - /** * Add the default definitions to the makefile. These values must not diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 4823d36..6692c68 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -466,13 +466,6 @@ public: */ void FindSubDirectoryCMakeListsFiles(std::vector& makefiles); - /** Generate the cache file only. This is done - * by calling FindSubDirectoryCMakeListsFiles which - * will cause all the rules to fire, and the cache to - * be filled. - */ - void GenerateCacheOnly(); - /** * find what source group this source is in */ diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 7e01101..afc92e8 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -563,6 +563,10 @@ bool cmSystemTools::IsOff(const char* val) bool cmSystemTools::RunCommand(const char* command, std::string& output) { + const int BUFFER_SIZE = 4096; + char buffer[BUFFER_SIZE]; + +#if defined(WIN32) && !defined(__CYGWIN__) std::string commandToFile = command; commandToFile += " > "; std::string tempFile; @@ -576,8 +580,6 @@ bool cmSystemTools::RunCommand(const char* command, tempFile.c_str()); return false; } - const int BUFFER_SIZE = 4096; - char buffer[BUFFER_SIZE]; while(fin) { fin.getline(buffer, BUFFER_SIZE); @@ -585,6 +587,22 @@ bool cmSystemTools::RunCommand(const char* command, } cmSystemTools::RemoveFile(tempFile.c_str()); return true; +#else + std::cout << "runing " << command << std::endl; + FILE* cpipe = popen(command, "r"); + if(!cpipe) + { + return false; + } + fgets(buffer, BUFFER_SIZE, cpipe); + while(!feof(cpipe)) + { + std::cout << buffer; + output += buffer; + fgets(buffer, BUFFER_SIZE, cpipe); + } + fclose(cpipe); +#endif } #ifdef _MSC_VER diff --git a/Source/cmUnixMakefileGenerator.cxx b/Source/cmUnixMakefileGenerator.cxx index be72113..14339f5 100644 --- a/Source/cmUnixMakefileGenerator.cxx +++ b/Source/cmUnixMakefileGenerator.cxx @@ -46,14 +46,34 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "cmMakeDepend.h" #include "cmCacheManager.h" +cmUnixMakefileGenerator::cmUnixMakefileGenerator() +{ + m_CacheOnly = false; + m_Recurse = false; +} + void cmUnixMakefileGenerator::GenerateMakefile() { - // Generate depends - cmMakeDepend md; - md.SetMakefile(m_Makefile); - md.DoDepends(); - // output the makefile fragment - this->OutputMakefile("CMakeTargets.make"); + if(m_CacheOnly) + { + // Generate the cache only stuff + this->GenerateCacheOnly(); + // if recurse then generate for all sub- makefiles + if(m_Recurse) + { + this->RecursiveGenerateCacheOnly(); + } + } + // normal makefile output + else + { + // Generate depends + cmMakeDepend md; + md.SetMakefile(m_Makefile); + md.DoDepends(); + // output the makefile fragment + this->OutputMakefile("CMakeTargets.make"); + } } @@ -539,3 +559,76 @@ void cmUnixMakefileGenerator::OutputCustomRules(std::ostream& fout) } } } + + +void cmUnixMakefileGenerator::GenerateCacheOnly() +{ + + std::string source = m_Makefile->GetHomeDirectory(); + source += "/CMake/CMakeMakefileTemplate.in"; + cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()); + std::string dest = m_Makefile->GetStartOutputDirectory(); + dest += "/Makefile"; + std::ofstream fout(dest.c_str()); + std::cout << "cmake: creating : " << dest.c_str() << "\n"; + if(!fout) + { + cmSystemTools::Error("Failed to open file for write " , dest.c_str()); + } + else + { + if(strcmp(m_Makefile->GetHomeDirectory(), + m_Makefile->GetHomeOutputDirectory()) == 0) + { + fout << "srcdir = .\n\n"; + } + else + { + fout << "srcdir = " << m_Makefile->GetStartDirectory() << "\n"; + fout << "VPATH = " << m_Makefile->GetStartDirectory() << "\n"; + } + } + fout << "include " + << m_Makefile->GetHomeOutputDirectory() << "/CMake/CMakeMaster.make\n"; + dest = m_Makefile->GetStartOutputDirectory(); + dest += "/CMakeTargets.make"; + // make sure there is a CMakeTargets.make file as some + // makes require it to exist + if(!cmSystemTools::FileExists(dest.c_str())) + { + std::cout << "cmake: creating : " << dest.c_str() << "\n"; + std::ofstream fout(dest.c_str()); + if(!fout) + { + cmSystemTools::Error("Failed to open file for write " , dest.c_str()); + } + fout << "#Initial CMakeTargets.make file created only to keep \n"; + fout << "#certain makes happy that don't like to include makefiles\n"; + fout << "#that do not exist\n"; + } +} + +void cmUnixMakefileGenerator::RecursiveGenerateCacheOnly() +{ + std::vector makefiles; + m_Makefile->FindSubDirectoryCMakeListsFiles(makefiles); + for(std::vector::iterator i = makefiles.begin(); + i != makefiles.end(); ++i) + { + cmMakefile* mf = *i; + if(m_Makefile->GetDefinition("RUN_CONFIGURE")) + { + mf->AddDefinition("RUN_CONFIGURE", true); + } + cmUnixMakefileGenerator* gen = new cmUnixMakefileGenerator; + gen->SetCacheOnlyOn(); + gen->SetRecurseOff(); + mf->SetMakefileGenerator(gen); + mf->GenerateMakefile(); + } + // CLEAN up the makefiles created + for(unsigned int i =0; i < makefiles.size(); ++i) + { + delete makefiles[i]; + } +} diff --git a/Source/cmUnixMakefileGenerator.h b/Source/cmUnixMakefileGenerator.h index 4e8b069..ca13919 100644 --- a/Source/cmUnixMakefileGenerator.h +++ b/Source/cmUnixMakefileGenerator.h @@ -53,6 +53,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class cmUnixMakefileGenerator : public cmMakefileGenerator { public: + ///! Set cache only and recurse to false by default. + cmUnixMakefileGenerator(); + + /** + * If cache only is on. + * and only stub makefiles are generated, and no depends, for speed. + * The default is OFF. + **/ + void SetCacheOnlyOn() {m_CacheOnly = true;} + void SetCacheOnlyOff() {m_CacheOnly = false;} + /** + * If recurse is on, then all the makefiles below this one are parsed as well. + */ + void SetRecurseOn() {m_Recurse = true;} + void SetRecurseOff() {m_Recurse = false;} + /** * Produce the makefile (in this case a Unix makefile). */ @@ -65,7 +81,9 @@ public: */ void OutputObjectDepends(std::ostream&); -protected: +private: + void RecursiveGenerateCacheOnly(); + void GenerateCacheOnly(); void OutputMakefile(const char* file); void OutputMakeFlags(std::ostream&); void OutputVerbatim(std::ostream&); @@ -76,6 +94,9 @@ protected: void OutputDependInformation(std::ostream&); void OutputDependencies(std::ostream&); void OutputCustomRules(std::ostream&); +private: + bool m_CacheOnly; + bool m_Recurse; }; #endif -- cgit v0.12