ENH: clean up code, and varible names

This commit is contained in:
Bill Hoffman 2000-09-21 13:45:08 -04:00
parent 749b7ff7a3
commit 1e3ba0f1d7
15 changed files with 108 additions and 149 deletions

12
README
View File

@ -67,6 +67,14 @@ make
TODO: 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=

View File

@ -2,6 +2,9 @@
#include "cmMakeDepend.h" #include "cmMakeDepend.h"
#include <iostream> #include <iostream>
// This is the main program used to gentrate makefile fragments
// from CMakeLists.txt input files.
main(int ac, char** av) main(int ac, char** av)
{ {
if(ac < 2) if(ac < 2)
@ -9,38 +12,46 @@ main(int ac, char** av)
std::cerr << "Usage: " << av[0] << " Makefile.in -Ipath ..." << std::endl; std::cerr << "Usage: " << av[0] << " Makefile.in -Ipath ..." << std::endl;
return -1; return -1;
} }
cmUnixMakefile* mf = new cmUnixMakefile; // Create a unix makefile
cmUnixMakefile mf;
// Create a depends object
cmMakeDepend md; cmMakeDepend md;
// Parse the command line
if(ac > 2) if(ac > 2)
{ {
for(int i =2; i < ac; i++) for(int i =2; i < ac; i++)
{ {
std::string arg = av[i]; std::string arg = av[i];
// Set the current source directory with a -S dir options
if(arg.find("-S",0) != std::string::npos) if(arg.find("-S",0) != std::string::npos)
{ {
std::string path = arg.substr(2); 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) if(arg.find("-B",0) != std::string::npos)
{ {
std::string path = arg.substr(2); 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) if(arg.find("-H",0) != std::string::npos)
{ {
std::string path = arg.substr(2); 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; std::cerr << "Usage: " << av[0] << " Makefile.in -Ipath ..." << std::endl;
return -1; return -1;
} }
// Set the makefile object on the depend object
md.SetMakefile(mf); md.SetMakefile(&mf);
// compute the depend information
md.DoDepends(); md.DoDepends();
mf->OutputMakefile("CMakeTargets.make"); // Ouput the result
delete mf; mf.OutputMakefile("CMakeTargets.make");
} }

View File

@ -2,6 +2,12 @@
#include "cmDSPMakefile.h" #include "cmDSPMakefile.h"
#include <iostream> #include <iostream>
// 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) void SetArgs(cmMakefile& builder, int ac, char** av)
{ {
for(int i =3; i < ac; i++) for(int i =3; i < ac; i++)
@ -32,10 +38,9 @@ void SetArgs(cmMakefile& builder, int ac, char** av)
} }
} }
main(int ac, char** av) main(int ac, char** av)
{ {
std::cerr << "pcbuilderCMD\n ";
if(ac < 3) if(ac < 3)
{ {
std::cerr << "Usage: " << av[0] << std::cerr << "Usage: " << av[0] <<

View File

@ -1,4 +1,5 @@
#include "cmCollectFlags.h" #include "cmCollectFlags.h"
#include "cmMakefile.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include <fstream> #include <fstream>
#include <iterator> #include <iterator>
@ -107,3 +108,32 @@ void cmCollectFlags::ParseDirectory(const char* dir)
this->ParseDirectory(dotdotDir.c_str()); 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<std::string>& includes = m_IncludeDirectories;
std::vector<std::string>::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() );
}
}

View File

@ -15,12 +15,16 @@
=========================================================================*/ =========================================================================*/
/** /**
* cmCollectFlags - collect flags from CMakeLists.txt files. * 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 #ifndef cmCollectFlags_h
#define cmCollectFlags_h #define cmCollectFlags_h
#include <vector> #include <vector>
#include <string> #include <string>
class cmMakefile;
class cmCollectFlags class cmCollectFlags
{ {
@ -45,6 +49,13 @@ public:
*/ */
void Print(); 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<std::string>& GetIncludeDirectories() std::vector<std::string>& GetIncludeDirectories()
{ {

View File

@ -16,17 +16,13 @@ static void Die(const char* message)
void cmDSPMakefile::OutputDSPFile() void cmDSPMakefile::OutputDSPFile()
{ {
// Setup /I and /LIBPATH options
std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories(); std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories();
std::vector<std::string>::iterator i; std::vector<std::string>::iterator i;
for(i = includes.begin(); i != includes.end(); ++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 += "/I \"";
m_IncludeOptions += include; m_IncludeOptions += *i;
m_IncludeOptions += "\" "; m_IncludeOptions += "\" ";
} }
std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries(); std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries();
@ -48,8 +44,6 @@ void cmDSPMakefile::OutputDSPFile()
{ {
m_DebugLibraryOptions += " /LIBPATH:\""; m_DebugLibraryOptions += " /LIBPATH:\"";
m_DebugLibraryOptions += *i; m_DebugLibraryOptions += *i;
cmSystemTools::ReplaceString(m_DebugLibraryOptions, "${CMAKE_BINARY_DIR}",
this->GetOutputHomeDirectory() );
if(i->find("Debug") == std::string::npos) if(i->find("Debug") == std::string::npos)
{ {
if(i->find("Release") == std::string::npos) if(i->find("Release") == std::string::npos)

View File

@ -16,17 +16,13 @@ static void Die(const char* message)
void cmDSPMakefile::OutputDSPFile() void cmDSPMakefile::OutputDSPFile()
{ {
// Setup /I and /LIBPATH options
std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories(); std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories();
std::vector<std::string>::iterator i; std::vector<std::string>::iterator i;
for(i = includes.begin(); i != includes.end(); ++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 += "/I \"";
m_IncludeOptions += include; m_IncludeOptions += *i;
m_IncludeOptions += "\" "; m_IncludeOptions += "\" ";
} }
std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries(); std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries();
@ -48,8 +44,6 @@ void cmDSPMakefile::OutputDSPFile()
{ {
m_DebugLibraryOptions += " /LIBPATH:\""; m_DebugLibraryOptions += " /LIBPATH:\"";
m_DebugLibraryOptions += *i; m_DebugLibraryOptions += *i;
cmSystemTools::ReplaceString(m_DebugLibraryOptions, "${CMAKE_BINARY_DIR}",
this->GetOutputHomeDirectory() );
if(i->find("Debug") == std::string::npos) if(i->find("Debug") == std::string::npos)
{ {
if(i->find("Release") == std::string::npos) if(i->find("Release") == std::string::npos)

View File

@ -12,7 +12,7 @@
#undef GetCurrentDirectory #undef GetCurrentDirectory
#undef SetCurrentDirectory #undef SetCurrentDirectory
// virtual override, ouput the makefile // output the DSW file
void cmDSWMakefile::OutputDSWFile() void cmDSWMakefile::OutputDSWFile()
{ {
if(m_OutputDirectory == "") if(m_OutputDirectory == "")

View File

@ -12,7 +12,7 @@
#undef GetCurrentDirectory #undef GetCurrentDirectory
#undef SetCurrentDirectory #undef SetCurrentDirectory
// virtual override, ouput the makefile // output the DSW file
void cmDSWMakefile::OutputDSWFile() void cmDSWMakefile::OutputDSWFile()
{ {
if(m_OutputDirectory == "") if(m_OutputDirectory == "")

View File

@ -48,10 +48,6 @@ void cmMakeDepend::SetMakefile(cmMakefile* makefile)
std::vector<std::string>::iterator j; std::vector<std::string>::iterator j;
for(j = includes.begin(); j != includes.end(); ++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()); this->AddSearchPath(j->c_str());
} }
// Now create cmDependInformation objects for files in the directory // Now create cmDependInformation objects for files in the directory

View File

@ -24,12 +24,12 @@ void cmMakefile::Print()
} }
// Parse the given CMakeLists.txt file into a list of classes. // Parse the given CMakeLists.txt file into a list of classes.
bool cmMakefile::ReadMakefile(const char* filename) bool cmMakefile::ReadMakefile(const char* filename)
{ {
m_BuildFlags.SetSourceHomeDirectory(this->GetHomeDirectory()); m_BuildFlags.SetSourceHomeDirectory(this->GetHomeDirectory());
m_BuildFlags.SetStartDirectory(this->GetCurrentDirectory()); m_BuildFlags.SetStartDirectory(this->GetCurrentDirectory());
m_BuildFlags.ParseDirectories(); m_BuildFlags.ParseDirectories();
m_BuildFlags.ExpandVaribles(this);
std::ifstream fin(filename); std::ifstream fin(filename);
if(!fin) if(!fin)
@ -188,11 +188,12 @@ void cmMakefile::ReadTemplateInstanceDirectory(std::string& line)
std::string::size_type start = line.find("="); std::string::size_type start = line.find("=");
if(start != std::string::npos) if(start != std::string::npos)
{ {
std::string dirname = line.substr(start+1, line.size()); std::string templateDirectory = line.substr(start+1, line.size());
dirname = cmSystemTools::CleanUpName(dirname.c_str()); templateDirectory = cmSystemTools::CleanUpName(templateDirectory.c_str());
m_TemplateDirectories.push_back(templateDirectory);
std::string tdir = this->GetCurrentDirectory(); std::string tdir = this->GetCurrentDirectory();
tdir += "/"; tdir += "/";
tdir += dirname; tdir += templateDirectory;
// Load all the files in the directory // Load all the files in the directory
cmDirectory dir; cmDirectory dir;
if(dir.Load(tdir.c_str())) if(dir.Load(tdir.c_str()))
@ -207,7 +208,7 @@ void cmMakefile::ReadTemplateInstanceDirectory(std::string& line)
// Remove the extension // Remove the extension
std::string::size_type dotpos = file.rfind("."); std::string::size_type dotpos = file.rfind(".");
file = file.substr(0, dotpos); file = file.substr(0, dotpos);
std::string fullname = dirname; std::string fullname = templateDirectory;
fullname += "/"; fullname += "/";
fullname += file; fullname += file;
// add the file as a class file so // add the file as a class file so
@ -221,8 +222,8 @@ void cmMakefile::ReadTemplateInstanceDirectory(std::string& line)
} }
else else
{ {
std::cerr << "Error can not open template instance directory " std::cerr << "Warning can not open template instance directory "
<< dirname.c_str() << std::endl; << templateDirectory.c_str() << std::endl;
} }
} }
} }

View File

@ -101,6 +101,7 @@ private:
protected: protected:
bool m_Executables; bool m_Executables;
std::string m_Prefix; std::string m_Prefix;
std::vector<std::string> m_TemplateDirectories; // Template directory name if found in file
std::string m_OutputDirectory; // Current output directory for makefile std::string m_OutputDirectory; // Current output directory for makefile
std::string m_OutputHomeDirectory; // Top level output directory std::string m_OutputHomeDirectory; // Top level output directory
std::string m_cmHomeDirectory; // Home directory for source std::string m_cmHomeDirectory; // Home directory for source

View File

@ -4,7 +4,8 @@
#include <iostream> #include <iostream>
// Output the depend information for all the classes // 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) void cmUnixMakefile::OutputDepends(std::ostream& fout)
{ {
for(int i = 0; i < m_Classes.size(); i++) 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) 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<std::string>::iterator i = m_TemplateDirectories.begin();
i != m_TemplateDirectories.end(); ++i)
{
cmSystemTools::MakeDirectory(i->c_str());
}
}
std::ofstream fout(file); std::ofstream fout(file);
if(!fout) if(!fout)
{ {
@ -144,8 +157,6 @@ void cmUnixMakefile::OutputMakefile(const char* file)
linkLibs += " "; linkLibs += " ";
} }
linkLibs += " ${LOCAL_LINK_FLAGS} "; linkLibs += " ${LOCAL_LINK_FLAGS} ";
cmSystemTools::ReplaceString(linkLibs, "${CMAKE_BINARY_DIR}",
this->GetOutputHomeDirectory() );
// Now create rules for all of the executables to be built // Now create rules for all of the executables to be built
for(int i = 0; i < m_Classes.size(); i++) for(int i = 0; i < m_Classes.size(); i++)
{ {

View File

@ -1,57 +0,0 @@
#include "itkVC60Configure.h"
#include "cmSystemTools.h"
#include "stdlib.h"
#include <windows.h>
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());
}

View File

@ -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