From db267f533b9ac63db78559e9d3cb39a6db090770 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Mon, 12 Feb 2001 19:49:52 -0500 Subject: [PATCH] ENH: get rid of special msc configure file --- Source/CMakeBuildTargets.cxx | 2 + Source/MFCDialog/CMakeSetupDialog.cpp | 14 --- Source/Makefile.in | 2 + Source/cmCommands.cxx | 33 ++++++ Source/cmCommands.h | 30 ++++++ Source/cmConfigureFileNoAutoconf.cxx | 67 ++++++++++++ ...rCommand.h => cmConfigureFileNoAutoconf.h} | 16 +-- Source/cmConfigureHeaderCommand.cxx | 34 ------ Source/cmMakefile.cxx | 101 +++++++++--------- Source/cmMakefile.h | 7 ++ Source/cmStandardIncludes.h | 1 + Source/cmSystemTools.cxx | 5 +- 12 files changed, 204 insertions(+), 108 deletions(-) create mode 100644 Source/cmCommands.h create mode 100644 Source/cmConfigureFileNoAutoconf.cxx rename Source/{cmConfigureHeaderCommand.h => cmConfigureFileNoAutoconf.h} (74%) delete mode 100644 Source/cmConfigureHeaderCommand.cxx diff --git a/Source/CMakeBuildTargets.cxx b/Source/CMakeBuildTargets.cxx index e9c2dbb84..e4c9e92b2 100644 --- a/Source/CMakeBuildTargets.cxx +++ b/Source/CMakeBuildTargets.cxx @@ -47,6 +47,7 @@ int main(int ac, char** av) { std::string path = arg.substr(2); mf.SetOutputHomeDirectory(path.c_str()); + mf.SetOutputDirectory(path.c_str()); } // Set the source home directory with a -H dir option if(arg.find("-H",0) == 0) @@ -57,6 +58,7 @@ int main(int ac, char** av) } } mf.SetMakefileGenerator(new cmUnixMakefileGenerator); + // Read and parse the input makefile if(!mf.ReadMakefile(av[1])) { diff --git a/Source/MFCDialog/CMakeSetupDialog.cpp b/Source/MFCDialog/CMakeSetupDialog.cpp index 2a739c72d..32e3c95f5 100644 --- a/Source/MFCDialog/CMakeSetupDialog.cpp +++ b/Source/MFCDialog/CMakeSetupDialog.cpp @@ -252,20 +252,6 @@ void CMakeSetupDialog::OnOK() m_WhereBuild = m_WhereSource; } - // configure the system for VC60 - cmWindowsConfigure config; - config.SetWhereSource(m_WhereSource); - config.SetWhereBuild(m_WhereBuild); - std::string configSrc; - configSrc = m_WhereSource; - configSrc += "/CMakeSetupConfig.MSC"; - if(!config.Configure(configSrc.c_str())) - { - std::string error = "Warning: MSC configure input not found: "; - error += configSrc; - ::MessageBox(0, error.c_str(), "config ERROR", MB_OK); - } - cmMakefile mf; mf.SetMakefileGenerator(new cmMSProjectGenerator); mf.SetHomeDirectory(m_WhereSource); diff --git a/Source/Makefile.in b/Source/Makefile.in index d28afdaee..edc9ed3d8 100644 --- a/Source/Makefile.in +++ b/Source/Makefile.in @@ -6,6 +6,8 @@ VPATH = @srcdir@ # This will cause an infinite loop as it will add the # command for changing into this directory +# let cmake know that this was done with autoconf +KIT_FLAGS = -DCMAKE_HAS_AUTOCONF @MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMake/CMakeVariables.make@MAKEQUOTE@ @MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMake/CMakeSimpleRules.make@MAKEQUOTE@ diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index e6cf4b7a2..76ccce0ca 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -1,3 +1,8 @@ +// This file is used to compile all the commands +// that CMake knows about at compile time. +// This is sort of a boot strapping approach since you would +// like to have CMake to build CMake. +#include "cmCommands.h" #include "cmAbstractFilesCommand.cxx" #include "cmAddTargetCommand.cxx" #include "cmAuxSourceDirectoryCommand.cxx" @@ -18,3 +23,31 @@ #include "cmUnixLibrariesCommand.cxx" #include "cmWin32DefinesCommand.cxx" #include "cmWin32LibrariesCommand.cxx" +#include "cmConfigureFileNoAutoconf.cxx" + +void GetPredefinedCommands(std::list& commands) +{ + commands.push_back(new cmAbstractFilesCommand); + commands.push_back(new cmAddTargetCommand); + commands.push_back(new cmAuxSourceDirectoryCommand); + commands.push_back(new cmExecutablesCommand); + commands.push_back(new cmFindIncludeCommand); + commands.push_back(new cmFindLibraryCommand); + commands.push_back(new cmFindProgramCommand); + commands.push_back(new cmIncludeDirectoryCommand); + commands.push_back(new cmLibraryCommand); + commands.push_back(new cmLinkDirectoriesCommand); + commands.push_back(new cmLinkLibrariesCommand); + commands.push_back(new cmProjectCommand); + commands.push_back(new cmSourceFilesCommand); + commands.push_back(new cmSourceFilesRequireCommand); + commands.push_back(new cmSubdirCommand); + commands.push_back(new cmTestsCommand); + commands.push_back(new cmUnixDefinesCommand); + commands.push_back(new cmUnixLibrariesCommand); + commands.push_back(new cmWin32DefinesCommand); + commands.push_back(new cmWin32LibrariesCommand); + commands.push_back(new cmConfigureFileNoAutoconf); +} + + diff --git a/Source/cmCommands.h b/Source/cmCommands.h new file mode 100644 index 000000000..f006063de --- /dev/null +++ b/Source/cmCommands.h @@ -0,0 +1,30 @@ + /*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) 2000 National Library of Medicine + All rights reserved. + + See COPYRIGHT.txt for copyright details. + +=========================================================================*/ +#ifndef cmCommands_h +#define cmCommands_h +#include "cmStandardIncludes.h" + +class cmCommand; +/** + * Global function to return all compiled in commands. + * To add a new command edit cmCommands.cxx and add your command. + * It is up to the caller to delete the commands created by this + * call. + */ +void GetPredefinedCommands(std::list& commands); + + +#endif diff --git a/Source/cmConfigureFileNoAutoconf.cxx b/Source/cmConfigureFileNoAutoconf.cxx new file mode 100644 index 000000000..86a5897f2 --- /dev/null +++ b/Source/cmConfigureFileNoAutoconf.cxx @@ -0,0 +1,67 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) 2000 National Library of Medicine + All rights reserved. + + See COPYRIGHT.txt for copyright details. + +=========================================================================*/ +#include "cmConfigureFileNoAutoconf.h" + +// cmConfigureFileNoAutoconf +bool cmConfigureFileNoAutoconf::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 cmConfigureFileNoAutoconf::FinalPass() +{ +#ifdef CMAKE_HAS_AUTOCONF + return; +#else + m_Makefile->ExpandVariblesInString(m_InputFile); + m_Makefile->ExpandVariblesInString(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; + } + std::ofstream fout(m_OuputFile.c_str()); + if(!fout) + { + cmSystemTools::Error("Could not open file for write in copy operatation", + m_OuputFile.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; + while(fin) + { + fin.getline(buffer, bufSize); + inLine = buffer; + m_Makefile->ExpandVariblesInString(inLine); + fout << inLine << "\n"; + } +#endif +} + + diff --git a/Source/cmConfigureHeaderCommand.h b/Source/cmConfigureFileNoAutoconf.h similarity index 74% rename from Source/cmConfigureHeaderCommand.h rename to Source/cmConfigureFileNoAutoconf.h index 0680db523..e14b2cbe5 100644 --- a/Source/cmConfigureHeaderCommand.h +++ b/Source/cmConfigureFileNoAutoconf.h @@ -13,18 +13,18 @@ See COPYRIGHT.txt for copyright details. =========================================================================*/ -#ifndef cmConfigureHeaderCommand_h -#define cmConfigureHeaderCommand_h +#ifndef cmConfigureFileNoAutoconf_h +#define cmConfigureFileNoAutoconf_h #include "cmStandardIncludes.h" #include "cmCommand.h" -class cmConfigureHeaderCommand : public cmCommand +class cmConfigureFileNoAutoconf : public cmCommand { public: virtual cmCommand* Clone() { - return new cmConfigureHeaderCommand; + return new cmConfigureFileNoAutoconf; } /** @@ -36,7 +36,7 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "CONFIGURE_HEADER";} + virtual const char* GetName() { return "CONFIGURE_FILE_NOAUTOCONF";} /** * Succinct documentation. @@ -54,7 +54,8 @@ public: return "CONFIGURE_HEADER(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"; + "They can also use variables like CMAKE_BINARY_DIR,CMAKE_SOURCE_DIR.\n" + "This command is only run if autoconf was not used.\n"; } /** @@ -62,6 +63,9 @@ public: * all varibles can be expaned. */ virtual void FinalPass(); +private: + std::string m_InputFile; + std::string m_OuputFile; }; diff --git a/Source/cmConfigureHeaderCommand.cxx b/Source/cmConfigureHeaderCommand.cxx deleted file mode 100644 index 28f6cb8cb..000000000 --- a/Source/cmConfigureHeaderCommand.cxx +++ /dev/null @@ -1,34 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile$ - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) 2000 National Library of Medicine - All rights reserved. - - See COPYRIGHT.txt for copyright details. - -=========================================================================*/ -#include "cmConfigureHeaderCommand.h" - -// cmConfigureHeaderCommand -bool cmConfigureHeaderCommand::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 cmConfigureHeaderCommand::FinalPass() -{ - -} diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index eea43f472..5a7fa6d20 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -20,27 +20,7 @@ #include "cmDirectory.h" #include "cmSystemTools.h" #include "cmMakefileGenerator.h" - -#include "cmAbstractFilesCommand.h" -#include "cmAddTargetCommand.h" -#include "cmAuxSourceDirectoryCommand.h" -#include "cmExecutablesCommand.h" -#include "cmFindIncludeCommand.h" -#include "cmFindLibraryCommand.h" -#include "cmFindProgramCommand.h" -#include "cmIncludeDirectoryCommand.h" -#include "cmLibraryCommand.h" -#include "cmLinkDirectoriesCommand.h" -#include "cmLinkLibrariesCommand.h" -#include "cmProjectCommand.h" -#include "cmSourceFilesCommand.h" -#include "cmSourceFilesRequireCommand.h" -#include "cmSubdirCommand.h" -#include "cmUnixDefinesCommand.h" -#include "cmUnixLibrariesCommand.h" -#include "cmWin32DefinesCommand.h" -#include "cmWin32LibrariesCommand.h" -#include "cmTestsCommand.h" +#include "cmCommands.h" // default is not to be building executables cmMakefile::cmMakefile() @@ -53,26 +33,13 @@ cmMakefile::cmMakefile() void cmMakefile::AddDefaultCommands() { - this->AddCommand(new cmAbstractFilesCommand); - this->AddCommand(new cmAddTargetCommand); - this->AddCommand(new cmAuxSourceDirectoryCommand); - this->AddCommand(new cmExecutablesCommand); - this->AddCommand(new cmFindIncludeCommand); - this->AddCommand(new cmFindLibraryCommand); - this->AddCommand(new cmFindProgramCommand); - this->AddCommand(new cmIncludeDirectoryCommand); - this->AddCommand(new cmLibraryCommand); - this->AddCommand(new cmLinkDirectoriesCommand); - this->AddCommand(new cmLinkLibrariesCommand); - this->AddCommand(new cmProjectCommand); - this->AddCommand(new cmSourceFilesCommand); - this->AddCommand(new cmSourceFilesRequireCommand); - this->AddCommand(new cmSubdirCommand); - this->AddCommand(new cmUnixLibrariesCommand); - this->AddCommand(new cmUnixDefinesCommand); - this->AddCommand(new cmWin32LibrariesCommand); - this->AddCommand(new cmWin32DefinesCommand); - this->AddCommand(new cmTestsCommand); + std::list commands; + GetPredefinedCommands(commands); + for(std::list::iterator i = commands.begin(); + i != commands.end(); ++i) + { + this->AddCommand(*i); + } #ifdef _WIN32 this->AddDefinition("WIN32", "1"); #else @@ -147,7 +114,11 @@ bool cmMakefile::ReadMakefile(const char* filename, bool inheriting) cmSystemTools::ConvertToUnixSlashes(m_cmCurrentDirectory); m_SourceHomeDirectory = m_cmHomeDirectory; cmSystemTools::ConvertToUnixSlashes(m_SourceHomeDirectory); - this->ParseDirectory(m_cmCurrentDirectory.c_str()); + // if this is already the top level directory then + if(m_SourceHomeDirectory != m_cmCurrentDirectory) + { + this->ParseDirectory(m_cmCurrentDirectory.c_str()); + } } // Now read the input file std::ifstream fin(filename); @@ -180,7 +151,7 @@ bool cmMakefile::ReadMakefile(const char* filename, bool inheriting) cmCommand* usedCommand = rm->Clone(); usedCommand->SetMakefile(this); usedCommand->LoadCache(); - m_UsedCommands.push_back(usedCommand); + bool keepCommand = false; if(usedCommand->GetEnabled()) { // if not running in inherit mode or @@ -191,8 +162,20 @@ bool cmMakefile::ReadMakefile(const char* filename, bool inheriting) { cmSystemTools::Error(usedCommand->GetError()); } + else + { + // use the command + keepCommand = true; + m_UsedCommands.push_back(usedCommand); + } } } + // if the Cloned command was not used + // then delete it + if(!keepCommand) + { + delete usedCommand; + } } else { @@ -203,6 +186,7 @@ bool cmMakefile::ReadMakefile(const char* filename, bool inheriting) } return true; } + void cmMakefile::AddCommand(cmCommand* wg) @@ -326,6 +310,7 @@ void cmMakefile::ParseDirectory(const char* dir) return; } + std::string dotdotDir = dir; std::string::size_type pos = dotdotDir.rfind('/'); if(pos != std::string::npos) @@ -341,25 +326,23 @@ void cmMakefile::ParseDirectory(const char* dir) void cmMakefile::ExpandVaribles() { - // Now replace varibles + // make sure binary and source dir are defined + this->AddDefinition("CMAKE_BINARY_DIR", this->GetOutputDirectory()); + this->AddDefinition("CMAKE_SOURCE_DIR", this->GetHomeDirectory()); + + // Now expand varibles in the include and link strings std::vector::iterator j, begin, end; begin = m_IncludeDirectories.begin(); end = m_IncludeDirectories.end(); for(j = begin; j != end; ++j) { - cmSystemTools::ReplaceString(*j, "${CMAKE_BINARY_DIR}", - this->GetOutputHomeDirectory() ); - cmSystemTools::ReplaceString(*j, "${CMAKE_SOURCE_DIR}", - this->GetHomeDirectory() ); + this->ExpandVariblesInString(*j); } begin = m_LinkDirectories.begin(); end = m_LinkDirectories.end(); for(j = begin; j != end; ++j) { - cmSystemTools::ReplaceString(*j, "${CMAKE_BINARY_DIR}", - this->GetOutputHomeDirectory() ); - cmSystemTools::ReplaceString(*j, "${CMAKE_SOURCE_DIR}", - this->GetHomeDirectory() ); + this->ExpandVariblesInString(*j); } } @@ -403,3 +386,17 @@ int cmMakefile::DumpDocumentationToFile(const char *fileName) return 1; } + +void cmMakefile::ExpandVariblesInString(std::string& source) +{ + for(DefinitionMap::iterator i = m_Definitions.begin(); + i != m_Definitions.end(); ++i) + { + std::string variable = "${"; + variable += (*i).first; + variable += "}"; + cmSystemTools::ReplaceString(source, variable.c_str(), + (*i).second.c_str()); + } +} + diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index c1a698068..ff16c9dee 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -306,6 +306,13 @@ public: */ int DumpDocumentationToFile(const char *fileName); + /** + * Expand all defined varibles in the string. + * Defined varibles come from the m_Definitions map. + * They are expanded with ${var} where var is the + * entry in the m_Definitions map. + */ + void ExpandVariblesInString(std::string& source); protected: bool m_Executables; std::string m_Prefix; diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h index 3187f34c5..88bc30667 100644 --- a/Source/cmStandardIncludes.h +++ b/Source/cmStandardIncludes.h @@ -39,6 +39,7 @@ #include #include #include +#include #ifdef CMAKE_NO_STD_NAMESPACE #define std diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index b66a1789c..1f10cb2df 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -264,8 +264,8 @@ bool cmSystemTools::ParseFunction(std::ifstream& fin, void cmSystemTools::GetArguments(std::string& line, std::vector& arguments) { - cmRegularExpression argument("[\t ]*([-/\\\\{}\\$A-Za-z_0-9]+)[\t ]*"); - cmRegularExpression argumentWithSpaces("[\t ]*\"([- /\\\\{}\\$A-Za-z_0-9]+)\"[\t ]*"); + cmRegularExpression argument("[\t ]*([-/\\.\\\\{}\\$A-Za-z_0-9]+)[\t ]*"); + cmRegularExpression argumentWithSpaces("[\t ]*\"([-\\. /\\\\{}\\$A-Za-z_0-9]+)\"[\t ]*"); std::string arg(" "); while(arg.length() ) { @@ -308,3 +308,4 @@ void cmSystemTools::Error(const char* m1, const char* m2) std::cerr << message.c_str() << std::endl; #endif } +