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:
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 <iostream>
// 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");
}

View File

@ -2,6 +2,12 @@
#include "cmDSPMakefile.h"
#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)
{
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] <<

View File

@ -1,4 +1,5 @@
#include "cmCollectFlags.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
#include <fstream>
#include <iterator>
@ -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<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.
* 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 <vector>
#include <string>
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<std::string>& GetIncludeDirectories()
{

View File

@ -16,17 +16,13 @@ static void Die(const char* message)
void cmDSPMakefile::OutputDSPFile()
{
// Setup /I and /LIBPATH options
std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories();
std::vector<std::string>::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<std::string>& 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)

View File

@ -16,17 +16,13 @@ static void Die(const char* message)
void cmDSPMakefile::OutputDSPFile()
{
// Setup /I and /LIBPATH options
std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories();
std::vector<std::string>::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<std::string>& 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)

View File

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

View File

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

View File

@ -48,10 +48,6 @@ void cmMakeDepend::SetMakefile(cmMakefile* makefile)
std::vector<std::string>::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

View File

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

View File

@ -101,6 +101,7 @@ private:
protected:
bool m_Executables;
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_OutputHomeDirectory; // Top level output directory
std::string m_cmHomeDirectory; // Home directory for source

View File

@ -4,7 +4,8 @@
#include <iostream>
// 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<std::string>::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++)
{

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