diff --git a/README b/README index 86a016433..bc70780a8 100644 --- a/README +++ b/README @@ -67,6 +67,14 @@ make TODO: -configure stuff for windows should be a copy configure file -read in depend regular expression from a file + + +Add include and directories to the build on windows. +For unix just add them to the CMakeLocal.make.in + +Add a --with idea, sets a #define in the config.h file + +Change ME to LIBRARY, and add PROJECT= + + diff --git a/Source/CMakeBuildTargets.cxx b/Source/CMakeBuildTargets.cxx index 0da141078..eea02d952 100644 --- a/Source/CMakeBuildTargets.cxx +++ b/Source/CMakeBuildTargets.cxx @@ -2,6 +2,9 @@ #include "cmMakeDepend.h" #include + +// This is the main program used to gentrate makefile fragments +// from CMakeLists.txt input files. main(int ac, char** av) { if(ac < 2) @@ -9,38 +12,46 @@ main(int ac, char** av) std::cerr << "Usage: " << av[0] << " Makefile.in -Ipath ..." << std::endl; return -1; } - cmUnixMakefile* mf = new cmUnixMakefile; + // Create a unix makefile + cmUnixMakefile mf; + // Create a depends object cmMakeDepend md; + // Parse the command line if(ac > 2) { for(int i =2; i < ac; i++) { std::string arg = av[i]; + // Set the current source directory with a -S dir options if(arg.find("-S",0) != std::string::npos) { std::string path = arg.substr(2); - mf->SetCurrentDirectory(path.c_str()); + mf.SetCurrentDirectory(path.c_str()); } + // Set the output or binary directory with a -B dir option if(arg.find("-B",0) != std::string::npos) { std::string path = arg.substr(2); - mf->SetOutputHomeDirectory(path.c_str()); + mf.SetOutputHomeDirectory(path.c_str()); } + // Set the source home directory with a -H dir option if(arg.find("-H",0) != std::string::npos) { std::string path = arg.substr(2); - mf->SetHomeDirectory(path.c_str()); + mf.SetHomeDirectory(path.c_str()); } } } - if(!mf->ReadMakefile(av[1])) + // Read and parse the input makefile + if(!mf.ReadMakefile(av[1])) { std::cerr << "Usage: " << av[0] << " Makefile.in -Ipath ..." << std::endl; return -1; } - - md.SetMakefile(mf); + // Set the makefile object on the depend object + md.SetMakefile(&mf); + // compute the depend information md.DoDepends(); - mf->OutputMakefile("CMakeTargets.make"); - delete mf; + // Ouput the result + mf.OutputMakefile("CMakeTargets.make"); } diff --git a/Source/CMakeSetupCMD.cxx b/Source/CMakeSetupCMD.cxx index 4ffd20c0f..8e6432479 100644 --- a/Source/CMakeSetupCMD.cxx +++ b/Source/CMakeSetupCMD.cxx @@ -2,6 +2,12 @@ #include "cmDSPMakefile.h" #include +// this is the command line version of CMakeSetup. +// It is called from Visual Studio when a CMakeLists.txt +// file is changed. + + +// Set the command line arguments void SetArgs(cmMakefile& builder, int ac, char** av) { for(int i =3; i < ac; i++) @@ -32,10 +38,9 @@ void SetArgs(cmMakefile& builder, int ac, char** av) } } + main(int ac, char** av) { - std::cerr << "pcbuilderCMD\n "; - if(ac < 3) { std::cerr << "Usage: " << av[0] << diff --git a/Source/cmCollectFlags.cxx b/Source/cmCollectFlags.cxx index c936718f0..6e7e33cd8 100644 --- a/Source/cmCollectFlags.cxx +++ b/Source/cmCollectFlags.cxx @@ -1,4 +1,5 @@ #include "cmCollectFlags.h" +#include "cmMakefile.h" #include "cmSystemTools.h" #include #include @@ -107,3 +108,32 @@ void cmCollectFlags::ParseDirectory(const char* dir) this->ParseDirectory(dotdotDir.c_str()); } } + + +// expance CMAKE_BINARY_DIR and CMAKE_SOURCE_ROOT in the +// include and library directories. + +void cmCollectFlags::ExpandVaribles(cmMakefile* makefile) +{ + // Now replace varibles + std::vector& includes = m_IncludeDirectories; + 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}", + makefile->GetOutputHomeDirectory() ); + cmSystemTools::ReplaceString(*j, "${CMAKE_SOURCE_ROOT}", + makefile->GetHomeDirectory() ); + } + begin = m_LinkDirectories.begin(); + end = m_LinkDirectories.end(); + for(j = begin; j != end; ++j) + { + cmSystemTools::ReplaceString(*j, "${CMAKE_BINARY_DIR}", + makefile->GetOutputHomeDirectory() ); + cmSystemTools::ReplaceString(*j, "${CMAKE_SOURCE_ROOT}", + makefile->GetHomeDirectory() ); + } +} diff --git a/Source/cmCollectFlags.h b/Source/cmCollectFlags.h index 8f037da96..28448b117 100644 --- a/Source/cmCollectFlags.h +++ b/Source/cmCollectFlags.h @@ -15,12 +15,16 @@ =========================================================================*/ /** * cmCollectFlags - collect flags from CMakeLists.txt files. + * This class collects include and link flags from a CMakeLists.txt + * file and any CMakeLists.txt files above it in the directory tree. + * It stops searching wen the home directory is found. */ #ifndef cmCollectFlags_h #define cmCollectFlags_h #include #include +class cmMakefile; class cmCollectFlags { @@ -45,6 +49,13 @@ public: */ void Print(); + /** + * Expance varibles for home and binary root in the collected flags. + * CMAKE_BINARY_DIR and CMAKE_SOURCE_ROOT are replaced with + * makefile->GetOutputHomeDirectory() and + * makefile->GetHomeDirectory() + */ + void ExpandVaribles(cmMakefile* makefile); std::vector& GetIncludeDirectories() { diff --git a/Source/cmDSPMakefile.cxx b/Source/cmDSPMakefile.cxx index 3fa6c0622..9147bcbcf 100644 --- a/Source/cmDSPMakefile.cxx +++ b/Source/cmDSPMakefile.cxx @@ -16,17 +16,13 @@ static void Die(const char* message) void cmDSPMakefile::OutputDSPFile() { + // Setup /I and /LIBPATH options std::vector& includes = m_BuildFlags.GetIncludeDirectories(); std::vector::iterator i; for(i = includes.begin(); i != includes.end(); ++i) { - std::string include = *i; - cmSystemTools::ReplaceString(include, "${CMAKE_BINARY_DIR}", - this->GetOutputHomeDirectory() ); - cmSystemTools::ReplaceString(include, "${CMAKE_SOURCE_ROOT}", - this->GetHomeDirectory() ); m_IncludeOptions += "/I \""; - m_IncludeOptions += include; + m_IncludeOptions += *i; m_IncludeOptions += "\" "; } std::vector& libs = m_BuildFlags.GetLinkLibraries(); @@ -48,8 +44,6 @@ void cmDSPMakefile::OutputDSPFile() { m_DebugLibraryOptions += " /LIBPATH:\""; m_DebugLibraryOptions += *i; - cmSystemTools::ReplaceString(m_DebugLibraryOptions, "${CMAKE_BINARY_DIR}", - this->GetOutputHomeDirectory() ); if(i->find("Debug") == std::string::npos) { if(i->find("Release") == std::string::npos) diff --git a/Source/cmDSPWriter.cxx b/Source/cmDSPWriter.cxx index 3fa6c0622..9147bcbcf 100644 --- a/Source/cmDSPWriter.cxx +++ b/Source/cmDSPWriter.cxx @@ -16,17 +16,13 @@ static void Die(const char* message) void cmDSPMakefile::OutputDSPFile() { + // Setup /I and /LIBPATH options std::vector& includes = m_BuildFlags.GetIncludeDirectories(); std::vector::iterator i; for(i = includes.begin(); i != includes.end(); ++i) { - std::string include = *i; - cmSystemTools::ReplaceString(include, "${CMAKE_BINARY_DIR}", - this->GetOutputHomeDirectory() ); - cmSystemTools::ReplaceString(include, "${CMAKE_SOURCE_ROOT}", - this->GetHomeDirectory() ); m_IncludeOptions += "/I \""; - m_IncludeOptions += include; + m_IncludeOptions += *i; m_IncludeOptions += "\" "; } std::vector& libs = m_BuildFlags.GetLinkLibraries(); @@ -48,8 +44,6 @@ void cmDSPMakefile::OutputDSPFile() { m_DebugLibraryOptions += " /LIBPATH:\""; m_DebugLibraryOptions += *i; - cmSystemTools::ReplaceString(m_DebugLibraryOptions, "${CMAKE_BINARY_DIR}", - this->GetOutputHomeDirectory() ); if(i->find("Debug") == std::string::npos) { if(i->find("Release") == std::string::npos) diff --git a/Source/cmDSWMakefile.cxx b/Source/cmDSWMakefile.cxx index 271bd3ead..5ce7b2c18 100644 --- a/Source/cmDSWMakefile.cxx +++ b/Source/cmDSWMakefile.cxx @@ -12,7 +12,7 @@ #undef GetCurrentDirectory #undef SetCurrentDirectory -// virtual override, ouput the makefile +// output the DSW file void cmDSWMakefile::OutputDSWFile() { if(m_OutputDirectory == "") diff --git a/Source/cmDSWWriter.cxx b/Source/cmDSWWriter.cxx index 271bd3ead..5ce7b2c18 100644 --- a/Source/cmDSWWriter.cxx +++ b/Source/cmDSWWriter.cxx @@ -12,7 +12,7 @@ #undef GetCurrentDirectory #undef SetCurrentDirectory -// virtual override, ouput the makefile +// output the DSW file void cmDSWMakefile::OutputDSWFile() { if(m_OutputDirectory == "") diff --git a/Source/cmMakeDepend.cxx b/Source/cmMakeDepend.cxx index d6841606a..8499d87b1 100644 --- a/Source/cmMakeDepend.cxx +++ b/Source/cmMakeDepend.cxx @@ -48,10 +48,6 @@ void cmMakeDepend::SetMakefile(cmMakefile* makefile) std::vector::iterator j; for(j = includes.begin(); j != includes.end(); ++j) { - cmSystemTools::ReplaceString(*j, "${CMAKE_BINARY_DIR}", - m_Makefile->GetOutputHomeDirectory() ); - cmSystemTools::ReplaceString(*j, "${CMAKE_SOURCE_ROOT}", - m_Makefile->GetHomeDirectory() ); this->AddSearchPath(j->c_str()); } // Now create cmDependInformation objects for files in the directory diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 3fa59a98e..1b6538c8e 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -24,13 +24,13 @@ void cmMakefile::Print() } // Parse the given CMakeLists.txt file into a list of classes. - bool cmMakefile::ReadMakefile(const char* filename) { m_BuildFlags.SetSourceHomeDirectory(this->GetHomeDirectory()); m_BuildFlags.SetStartDirectory(this->GetCurrentDirectory()); m_BuildFlags.ParseDirectories(); - + m_BuildFlags.ExpandVaribles(this); + std::ifstream fin(filename); if(!fin) { @@ -188,11 +188,12 @@ void cmMakefile::ReadTemplateInstanceDirectory(std::string& line) std::string::size_type start = line.find("="); if(start != std::string::npos) { - std::string dirname = line.substr(start+1, line.size()); - dirname = cmSystemTools::CleanUpName(dirname.c_str()); + std::string templateDirectory = line.substr(start+1, line.size()); + templateDirectory = cmSystemTools::CleanUpName(templateDirectory.c_str()); + m_TemplateDirectories.push_back(templateDirectory); std::string tdir = this->GetCurrentDirectory(); tdir += "/"; - tdir += dirname; + tdir += templateDirectory; // Load all the files in the directory cmDirectory dir; if(dir.Load(tdir.c_str())) @@ -207,7 +208,7 @@ void cmMakefile::ReadTemplateInstanceDirectory(std::string& line) // Remove the extension std::string::size_type dotpos = file.rfind("."); file = file.substr(0, dotpos); - std::string fullname = dirname; + std::string fullname = templateDirectory; fullname += "/"; fullname += file; // add the file as a class file so @@ -221,8 +222,8 @@ void cmMakefile::ReadTemplateInstanceDirectory(std::string& line) } else { - std::cerr << "Error can not open template instance directory " - << dirname.c_str() << std::endl; + std::cerr << "Warning can not open template instance directory " + << templateDirectory.c_str() << std::endl; } } } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 94cb988ab..3396dd5fb 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -101,6 +101,7 @@ private: protected: bool m_Executables; std::string m_Prefix; + std::vector m_TemplateDirectories; // Template directory name if found in file std::string m_OutputDirectory; // Current output directory for makefile std::string m_OutputHomeDirectory; // Top level output directory std::string m_cmHomeDirectory; // Home directory for source diff --git a/Source/cmUnixMakefile.cxx b/Source/cmUnixMakefile.cxx index a5d9b67c4..8a212959e 100644 --- a/Source/cmUnixMakefile.cxx +++ b/Source/cmUnixMakefile.cxx @@ -4,7 +4,8 @@ #include // Output the depend information for all the classes -// in the makefile. +// in the makefile. These would have been generated +// by the class cmMakeDepend in the main of CMakeBuildTargets. void cmUnixMakefile::OutputDepends(std::ostream& fout) { for(int i = 0; i < m_Classes.size(); i++) @@ -64,6 +65,18 @@ inline std::string FixDirectoryName(const char* dir) void cmUnixMakefile::OutputMakefile(const char* file) { + if( m_TemplateDirectories.size() ) + { + // For the case when this is running as a remote build + // on unix, make the directory + + for(std::vector::iterator i = m_TemplateDirectories.begin(); + i != m_TemplateDirectories.end(); ++i) + { + cmSystemTools::MakeDirectory(i->c_str()); + } + } + std::ofstream fout(file); if(!fout) { @@ -144,8 +157,6 @@ void cmUnixMakefile::OutputMakefile(const char* file) linkLibs += " "; } linkLibs += " ${LOCAL_LINK_FLAGS} "; - cmSystemTools::ReplaceString(linkLibs, "${CMAKE_BINARY_DIR}", - this->GetOutputHomeDirectory() ); // Now create rules for all of the executables to be built for(int i = 0; i < m_Classes.size(); i++) { diff --git a/Source/itkVC60Configure.cxx b/Source/itkVC60Configure.cxx deleted file mode 100644 index 498e30fe5..000000000 --- a/Source/itkVC60Configure.cxx +++ /dev/null @@ -1,57 +0,0 @@ -#include "itkVC60Configure.h" -#include "cmSystemTools.h" -#include "stdlib.h" -#include - -void itkVC60Configure::Configure() -{ - this->GenerateITKConfigHeader(); - this->GenerateVNLConfigHeader(); -} - -void itkVC60Configure::GenerateITKConfigHeader() -{ - // for now just copy the itkConfigure.h.in file into place - std::string source = m_WhereSource; - source += "/itkConfigure.h.in"; - std::string destdir = m_WhereBuild; - std::string dest = destdir; - dest += "/itkConfigure.h"; - this->CopyFileTo(source.c_str(), - destdir.c_str(), - dest.c_str()); -} - -void itkVC60Configure::CopyFileTo(const char* source, - const char* destdir, - const char* dest) -{ - if(!cmSystemTools::MakeDirectory(destdir) ) - { - std::string error = "Error: can not create directory: "; - error += destdir; - MessageBox(0, error.c_str(), "config ERROR", MB_OK); - } - if(!CopyFile(source, dest, FALSE)) - { - std::string error = "Error: can not create : "; - error += dest; - MessageBox(0, error.c_str(), "config ERROR", MB_OK); - } -} - - -void itkVC60Configure::GenerateVNLConfigHeader() -{ - // Copy the vcl config stuff for vc50 into place - std::string source = m_WhereSource; - source += "/Code/Insight3DParty/vxl/vcl/vcl_config-vc60.h "; - std::string destdir = m_WhereBuild; - destdir += "/Code/Insight3DParty/vxl/vcl"; - std::string dest = destdir; - dest += "/vcl_config.h"; - this->CopyFileTo(source.c_str(), - destdir.c_str(), - dest.c_str()); - -} diff --git a/Source/itkVC60Configure.h b/Source/itkVC60Configure.h deleted file mode 100644 index a30c71eb2..000000000 --- a/Source/itkVC60Configure.h +++ /dev/null @@ -1,46 +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. - -=========================================================================*/ -/** - * itkVC60Configure : a class that configures itk for build - * on windows with VC60 - */ -#ifndef itkVC60Configure_h -#define itkVC60Configure_h - -#include "cmWindowsConfigure.h" - -class itkVC60Configure : public cmWindowsConfigure -{ -public: - /** - * implement configure from parent - */ - virtual void Configure(); - /** - * create the main itk configure file - */ - virtual void GenerateITKConfigHeader(); - /** - * Create the vnl configure file - */ - virtual void GenerateVNLConfigHeader(); -protected: - void CopyFileTo(const char* source, - const char* destdir, - const char* dest); -}; - -#endif