ENH: rework cmake, added ruleMaker classes and changed the syntax of the CMakeLists.txt files.

This commit is contained in:
Bill Hoffman 2001-01-05 11:41:20 -05:00
parent d888b5e39d
commit c54a05bfc7
78 changed files with 2945 additions and 915 deletions

View File

@ -1,7 +1,7 @@
#include "cmUnixMakefile.h"
#include "cmMakefile.h"
#include "cmStandardIncludes.h"
#include "cmMakeDepend.h"
#include <iostream>
#include "cmUnixMakefileGenerator.h"
// This is the main program used to gentrate makefile fragments
// from CMakeLists.txt input files.
@ -12,10 +12,9 @@ main(int ac, char** av)
std::cerr << "Usage: " << av[0] << " Makefile.in -Ipath ..." << std::endl;
return -1;
}
// Create a unix makefile
cmUnixMakefile mf;
// Create a depends object
cmMakeDepend md;
// Create a makefile
cmMakefile mf;
mf.AddDefinition("UNIX", "1");
// Parse the command line
if(ac > 2)
{
@ -42,16 +41,12 @@ main(int ac, char** av)
}
}
}
mf.SetMakefileGenerator(new cmUnixMakefileGenerator);
// Read and parse the input makefile
if(!mf.ReadMakefile(av[1]))
{
std::cerr << "Usage: " << av[0] << " Makefile.in -Ipath ..." << std::endl;
return -1;
}
// Set the makefile object on the depend object
md.SetMakefile(&mf);
// compute the depend information
md.DoDepends();
// Ouput the result
mf.OutputMakefile("CMakeTargets.make");
mf.GenerateMakefile();
}

View File

@ -1,6 +1,7 @@
#include "cmDSWMakefile.h"
#include "cmDSPMakefile.h"
#include <iostream>
#include "cmStandardIncludes.h"
#include "cmMakefile.h"
#include "cmMSProjectGenerator.h"
// this is the command line version of CMakeSetup.
// It is called from Visual Studio when a CMakeLists.txt
@ -21,7 +22,6 @@ void SetArgs(cmMakefile& builder, int ac, char** av)
if(arg.find("-D",0) != std::string::npos)
{
std::string path = arg.substr(2);
std::cerr << "set makefile dir " << path.c_str() << std::endl;
builder.SetCurrentDirectory(path.c_str());
}
if(arg.find("-O",0) != std::string::npos)
@ -44,24 +44,25 @@ main(int ac, char** av)
if(ac < 3)
{
std::cerr << "Usage: " << av[0] <<
" Makefile.in -[DSP|DSW] -Hinsighthome -Dcurrentdir -Ooutput directory" << std::endl;
" CMakeLists.txt -[DSP|DSW] -Hinsighthome -Dcurrentdir"
" -Ooutput directory" << std::endl;
return -1;
}
std::string arg = av[2];
cmMakefile builder;
SetArgs(builder, ac, av);
cmMSProjectGenerator* pg = new cmMSProjectGenerator;
if(arg.find("-DSP", 0) != std::string::npos)
{
cmDSPMakefile builder;
SetArgs(builder, ac, av);
builder.ReadMakefile(av[1]);
builder.OutputDSPFile();
pg->SetBuildDSP();
}
else
{
cmDSWMakefile builder;
SetArgs(builder, ac, av);
builder.ReadMakefile(av[1]);
builder.OutputDSWFile();
pg->SetBuildDSW();
}
builder.SetMakefileGenerator(pg);
builder.ReadMakefile(av[1]);
builder.GenerateMakefile();
return 0;
}

View File

@ -91,15 +91,23 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\cmAbstractFilesRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmAddTargetRule.cxx
# End Source File
# Begin Source File
SOURCE=.\CMakeSetupCMD.cxx
# End Source File
# Begin Source File
SOURCE=.\cmClassFile.cxx
SOURCE=.\cmAuxSourceDirectoryRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmCollectFlags.cxx
SOURCE=.\cmClassFile.cxx
# End Source File
# Begin Source File
@ -115,6 +123,38 @@ SOURCE=.\cmDSWMakefile.cxx
# End Source File
# Begin Source File
SOURCE=.\cmExecutablesRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmFindIncludeRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmFindLibraryRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmFindProgramRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmIncludeDirectoryRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmLibraryRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmLinkDirectoriesRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmLinkLibrariesRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmMakeDepend.cxx
# End Source File
# Begin Source File
@ -123,16 +163,196 @@ SOURCE=.\cmMakefile.cxx
# End Source File
# Begin Source File
SOURCE=.\cmMakefileGenerator.cxx
# End Source File
# Begin Source File
SOURCE=.\cmMSProjectGenerator.cxx
# End Source File
# Begin Source File
SOURCE=.\cmProjectRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmRegularExpression.cxx
# End Source File
# Begin Source File
SOURCE=.\cmSourceFilesRequireRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmSourceFilesRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmSubdirRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmSystemTools.cxx
# End Source File
# Begin Source File
SOURCE=.\cmTestsRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmUnixDefinesRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmUnixLibrariesRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmWin32DefinesRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmWin32LibrariesRule.cxx
# End Source File
# Begin Source File
SOURCE=.\cmWindowsConfigure.cxx
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\cmAbstractFilesRule.h
# End Source File
# Begin Source File
SOURCE=.\cmAddTargetRule.h
# End Source File
# Begin Source File
SOURCE=.\cmAuxSourceDirectoryRule.h
# End Source File
# Begin Source File
SOURCE=.\cmClassFile.h
# End Source File
# Begin Source File
SOURCE=.\cmDirectory.h
# End Source File
# Begin Source File
SOURCE=.\cmDSPMakefile.h
# End Source File
# Begin Source File
SOURCE=.\cmDSWMakefile.h
# End Source File
# Begin Source File
SOURCE=.\cmExecutablesRule.h
# End Source File
# Begin Source File
SOURCE=.\cmFindIncludeRule.h
# End Source File
# Begin Source File
SOURCE=.\cmFindLibraryRule.h
# End Source File
# Begin Source File
SOURCE=.\cmFindProgramRule.h
# End Source File
# Begin Source File
SOURCE=.\cmIncludeDirectoryRule.h
# End Source File
# Begin Source File
SOURCE=.\cmLibraryRule.h
# End Source File
# Begin Source File
SOURCE=.\cmLinkDirectoriesRule.h
# End Source File
# Begin Source File
SOURCE=.\cmLinkLibrariesRule.h
# End Source File
# Begin Source File
SOURCE=.\cmMakeDepend.h
# End Source File
# Begin Source File
SOURCE=.\cmMakefile.h
# End Source File
# Begin Source File
SOURCE=.\cmMakefile2.h
# End Source File
# Begin Source File
SOURCE=.\cmMakefileGenerator.h
# End Source File
# Begin Source File
SOURCE=.\cmMSProjectGenerator.h
# End Source File
# Begin Source File
SOURCE=.\cmProjectRule.h
# End Source File
# Begin Source File
SOURCE=.\cmRegularExpression.h
# End Source File
# Begin Source File
SOURCE=.\cmRuleMaker.h
# End Source File
# Begin Source File
SOURCE=.\cmSourceFilesRule.h
# End Source File
# Begin Source File
SOURCE=.\cmStandardIncludes.h
# End Source File
# Begin Source File
SOURCE=.\cmSubdirRule.h
# End Source File
# Begin Source File
SOURCE=.\cmSystemTools.h
# End Source File
# Begin Source File
SOURCE=.\cmTestsRule.h
# End Source File
# Begin Source File
SOURCE=.\cmUnixDefinesRule.h
# End Source File
# Begin Source File
SOURCE=.\cmUnixLibrariesRule.h
# End Source File
# Begin Source File
SOURCE=.\cmWin32DefinesRule.h
# End Source File
# Begin Source File
SOURCE=.\cmWin32LibrariesRule.h
# End Source File
# Begin Source File
SOURCE=.\cmWindowsConfigure.h
# End Source File
# End Group
# Begin Group "Resource Files"

View File

@ -92,6 +92,14 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=..\cmAbstractFilesRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmAddTargetRule.cxx
# End Source File
# Begin Source File
SOURCE=.\CMakeSetup.cpp
# End Source File
# Begin Source File
@ -100,15 +108,19 @@ SOURCE=.\CMakeSetup.rc
# End Source File
# Begin Source File
SOURCE=..\CMakeSetupCMD.cxx
# End Source File
# Begin Source File
SOURCE=.\CMakeSetupDialog.cpp
# End Source File
# Begin Source File
SOURCE=..\cmClassFile.cxx
SOURCE=..\cmAuxSourceDirectoryRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmCollectFlags.cxx
SOURCE=..\cmClassFile.cxx
# End Source File
# Begin Source File
@ -124,6 +136,38 @@ SOURCE=..\cmDSWMakefile.cxx
# End Source File
# Begin Source File
SOURCE=..\cmExecutablesRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmFindIncludeRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmFindLibraryRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmFindProgramRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmIncludeDirectoryRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmLibraryRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmLinkDirectoriesRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmLinkLibrariesRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmMakeDepend.cxx
# End Source File
# Begin Source File
@ -132,14 +176,58 @@ SOURCE=..\cmMakefile.cxx
# End Source File
# Begin Source File
SOURCE=..\cmMakefileGenerator.cxx
# End Source File
# Begin Source File
SOURCE=..\cmMSProjectGenerator.cxx
# End Source File
# Begin Source File
SOURCE=..\cmProjectRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmRegularExpression.cxx
# End Source File
# Begin Source File
SOURCE=..\cmSourceFilesRequireRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmSourceFilesRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmSubdirRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmSystemTools.cxx
# End Source File
# Begin Source File
SOURCE=..\cmTestsRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmUnixDefinesRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmUnixLibrariesRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmWin32DefinesRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmWin32LibrariesRule.cxx
# End Source File
# Begin Source File
SOURCE=..\cmWindowsConfigure.cxx
# End Source File
# Begin Source File
@ -153,6 +241,14 @@ SOURCE=.\StdAfx.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\cmAbstractFilesRule.h
# End Source File
# Begin Source File
SOURCE=..\cmAddTargetRule.h
# End Source File
# Begin Source File
SOURCE=..\CMakeSetup.h
# End Source File
# Begin Source File
@ -165,10 +261,18 @@ SOURCE=.\CMakeSetupDialog.h
# End Source File
# Begin Source File
SOURCE=..\cmAuxSourceDirectoryRule.h
# End Source File
# Begin Source File
SOURCE=..\cmClassFile.h
# End Source File
# Begin Source File
SOURCE=..\cmDirectory.h
# End Source File
# Begin Source File
SOURCE=..\cmDSPBuilder.h
# End Source File
# Begin Source File
@ -185,6 +289,38 @@ SOURCE=..\cmDSWMakefile.h
# End Source File
# Begin Source File
SOURCE=..\cmExecutablesRule.h
# End Source File
# Begin Source File
SOURCE=..\cmFindIncludeRule.h
# End Source File
# Begin Source File
SOURCE=..\cmFindLibraryRule.h
# End Source File
# Begin Source File
SOURCE=..\cmFindProgramRule.h
# End Source File
# Begin Source File
SOURCE=..\cmIncludeDirectoryRule.h
# End Source File
# Begin Source File
SOURCE=..\cmLibraryRule.h
# End Source File
# Begin Source File
SOURCE=..\cmLinkDirectoriesRule.h
# End Source File
# Begin Source File
SOURCE=..\cmLinkLibrariesRule.h
# End Source File
# Begin Source File
SOURCE=..\cmMakeDepend.h
# End Source File
# Begin Source File
@ -193,10 +329,74 @@ SOURCE=..\cmMakefile.h
# End Source File
# Begin Source File
SOURCE=..\cmMakefile2.h
# End Source File
# Begin Source File
SOURCE=..\cmMakefileGenerator.h
# End Source File
# Begin Source File
SOURCE=..\cmMSProjectGenerator.h
# End Source File
# Begin Source File
SOURCE=..\cmProjectRule.h
# End Source File
# Begin Source File
SOURCE=..\cmRegularExpression.h
# End Source File
# Begin Source File
SOURCE=..\cmRuleMaker.h
# End Source File
# Begin Source File
SOURCE=..\cmSourceFilesRequireRule.h
# End Source File
# Begin Source File
SOURCE=..\cmSourceFilesRule.h
# End Source File
# Begin Source File
SOURCE=..\cmStandardIncludes.h
# End Source File
# Begin Source File
SOURCE=..\cmSubdirRule.h
# End Source File
# Begin Source File
SOURCE=..\cmSystemTools.h
# End Source File
# Begin Source File
SOURCE=..\cmTestsRule.h
# End Source File
# Begin Source File
SOURCE=..\cmUnixDefinesRule.h
# End Source File
# Begin Source File
SOURCE=..\cmUnixLibrariesRule.h
# End Source File
# Begin Source File
SOURCE=..\cmWin32DefinesRule.h
# End Source File
# Begin Source File
SOURCE=..\cmWin32LibrariesRule.h
# End Source File
# Begin Source File
SOURCE=..\cmWindowsConfigure.h
# End Source File
# Begin Source File
SOURCE=.\Resource.h
# End Source File
# Begin Source File

View File

@ -6,7 +6,7 @@
#include "CMakeSetupDialog.h"
#include "../cmDSWMakefile.h"
#include "../cmWindowsConfigure.h"
#include "../cmMSProjectGenerator.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
@ -269,19 +269,21 @@ void CMakeSetupDialog::OnOK()
}
cmDSWMakefile builder;
// Set the ITK home directory
builder.SetHomeDirectory(m_WhereSource);
cmMakefile mf;
mf.SetMakefileGenerator(new cmMSProjectGenerator);
mf.SetHomeDirectory(m_WhereSource);
// Set the output directory
mf.SetOutputDirectory(m_WhereBuild);
// set the directory which contains the CMakeLists.txt
mf.SetCurrentDirectory(m_WhereSource);
// Create the master DSW file and all children dsp files for ITK
// Set the CMakeLists.txt file
CString makefileIn = m_WhereSource;
makefileIn += "/CMakeLists.txt";
builder.ReadMakefile(makefileIn);
// Set the output directory
builder.SetOutputDirectory(m_WhereBuild);
// set the directory which contains the CMakeLists.txt
builder.SetCurrentDirectory(m_WhereSource);
// Create the master DSW file and all children dsp files for ITK
builder.OutputDSWFile();
mf.ReadMakefile(makefileIn);
// Move this to the cache editor
mf.GenerateMakefile();
CDialog::OnOK();
this->SaveToRegistry();
}

View File

@ -10,26 +10,68 @@ VPATH = @srcdir@
@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMake/CMakeSimpleRules.make@MAKEQUOTE@
OBJS = \
cmClassFile.o \
cmDirectory.o \
cmMakefile.o \
cmUnixMakefile.o \
CMakeBuildTargets.o \
cmMakeDepend.o \
cmMakefile.o \
cmAbstractFilesRule.o \
cmMakefileGenerator.o \
cmAddTargetRule.o \
cmProjectRule.o \
cmAuxSourceDirectoryRule.o \
cmRegularExpression.o \
cmClassFile.o \
cmSourceFilesRule.o \
cmSourceFilesRequireRule.o \
cmSubdirRule.o \
cmSystemTools.o \
CMakeBuildTargets.o \
cmCollectFlags.o
cmDirectory.o \
cmUnixDefinesRule.o \
cmExecutablesRule.o \
cmTestsRule.o \
cmUnixLibrariesRule.o \
cmFindIncludeRule.o \
cmFindLibraryRule.o \
cmUnixMakefileGenerator.o \
cmFindProgramRule.o \
cmIncludeDirectoryRule.o \
cmWin32DefinesRule.o \
cmLibraryRule.o \
cmWin32LibrariesRule.o \
cmLinkDirectoriesRule.o \
cmLinkLibrariesRule.o
cmCollectFlags.o : cmCollectFlags.h cmCollectFlags.cxx cmSystemTools.h
cmSystemTools.o : cmSystemTools.h cmSystemTools.cxx cmSystemTools.h
cmDirectory.o : cmDirectory.h cmDirectory.cxx cmSystemTools.h
cmClassFile.o : cmClassFile.h cmClassFile.cxx cmSystemTools.h
cmMakefile.o : cmMakefile.h cmMakefile.cxx cmClassFile.h cmSystemTools.h
cmUnixMakefile.o : cmUnixMakefile.h cmUnixMakefile.cxx cmMakefile.h cmClassFile.h
cmMakeDepend.o : cmMakeDepend.h cmMakeDepend.cxx cmMakefile.h cmClassFile.h cmRegularExpression.h
cmRegularExpression.o : cmRegularExpression.h cmRegularExpression.cxx
CMakeBuildTargets.o : CMakeBuildTargets.cxx cmMakefile.h cmMakeDepend.h
cmCollectFlags.o : $(srcdir)/*.h
CMakeBuildTargets.o : $(srcdir)/*.h
cmMakeDepend.o : $(srcdir)/*.h
cmMakefile.o : $(srcdir)/*.h
cmAbstractFilesRule.o : $(srcdir)/*.h
cmMakefileGenerator.o : $(srcdir)/*.h
cmAddTargetRule.o : $(srcdir)/*.h
cmProjectRule.o : $(srcdir)/*.h
cmAuxSourceDirectoryRule.o : $(srcdir)/*.h
cmRegularExpression.o : $(srcdir)/*.h
cmClassFile.o : $(srcdir)/*.h
cmSourceFilesRule.o : $(srcdir)/*.h
cmSourceFilesRequireRule.o : $(srcdir)/*.h
cmSubdirRule.o : $(srcdir)/*.h
cmSystemTools.o : $(srcdir)/*.h
cmDirectory.o : $(srcdir)/*.h
cmUnixDefinesRule.o : $(srcdir)/*.h
cmExecutablesRule.o : $(srcdir)/*.h
cmTestsRule.o : $(srcdir)/*.h
cmUnixLibrariesRule.o : $(srcdir)/*.h
cmFindIncludeRule.o : $(srcdir)/*.h
cmFindLibraryRule.o : $(srcdir)/*.h
cmUnixMakefileGenerator.o : $(srcdir)/*.h
cmFindProgramRule.o : $(srcdir)/*.h
cmIncludeDirectoryRule.o : $(srcdir)/*.h
cmWin32DefinesRule.o : $(srcdir)/*.h
cmLibraryRule.o : $(srcdir)/*.h
cmWin32LibrariesRule.o : $(srcdir)/*.h
cmLinkDirectoriesRule.o : $(srcdir)/*.h
cmLinkLibrariesRule.o : $(srcdir)/*.h
CMakeBuildTargets: ${OBJS}
${CXX} ${OBJS} ${CXX_FLAGS} -o CMakeBuildTargets

View File

@ -0,0 +1,26 @@
#include "cmAbstractFilesRule.h"
// cmAbstractFilesRule
bool cmAbstractFilesRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator j = args.begin();
j != args.end(); ++j)
{
std::vector<cmClassFile>& Classes = m_Makefile->GetClasses();
for(int i = 0; i < Classes.size(); i++)
{
if(Classes[i].m_ClassName == (*j))
{
Classes[i].m_AbstractClass = true;
break;
}
}
}
return true;
}

View File

@ -0,0 +1,37 @@
#ifndef cmAbstractFilesRule_h
#define cmAbstractFilesRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmAbstractFilesRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmAbstractFilesRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
// This is the name used in the input file.
virtual const char* GetName() { return "ABSTRACT_FILES";}
virtual const char* TerseDocumentaion()
{
return "A list of abstract classes, useful for wrappers.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"ABSTRACT_FILES(file1 file2 ..)";
}
};
#endif

View File

@ -0,0 +1,19 @@
#include "cmAddTargetRule.h"
// cmAddTargetRule
bool cmAddTargetRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
return false;
// for(std::vector<std::string>::iterator i = args.begin();
// i != args.end(); ++i)
// {
// m_Makefile->Add((*i).c_str());
// }
}

37
Source/cmAddTargetRule.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef cmAddTargetRule_h
#define cmAddTargetRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmAddTargetRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmAddTargetRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
// This is the name used in the input file.
virtual const char* GetName() { return "ADD_TARGET";}
virtual const char* TerseDocumentaion()
{
return "Add an extra target to the build system.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"ADD_TARGET(Name \"command to run\");";
}
};
#endif

View File

@ -0,0 +1,46 @@
#include "cmAuxSourceDirectoryRule.h"
#include "cmDirectory.h"
// cmAuxSourceDirectoryRule
bool cmAuxSourceDirectoryRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 || args.size() > 1)
{
this->SetError("PROJECT called with incorrect number of arguments");
return false;
}
std::string templateDirectory = args[0];
m_Makefile->AddExtraDirectory(templateDirectory.c_str());
std::string tdir = m_Makefile->GetCurrentDirectory();
tdir += "/";
tdir += templateDirectory;
// Load all the files in the directory
cmDirectory dir;
if(dir.Load(tdir.c_str()))
{
int numfiles = dir.GetNumberOfFiles();
for(int i =0; i < numfiles; ++i)
{
std::string file = dir.GetFile(i);
// ignore files less than f.cxx in length
if(file.size() > 4)
{
// Remove the extension
std::string::size_type dotpos = file.rfind(".");
file = file.substr(0, dotpos);
std::string fullname = templateDirectory;
fullname += "/";
fullname += file;
// add the file as a class file so
// depends can be done
cmClassFile cmfile;
cmfile.SetName(fullname.c_str(), m_Makefile->GetCurrentDirectory());
cmfile.m_AbstractClass = false;
m_Makefile->AddClass(cmfile);
}
}
}
return true;
}

View File

@ -0,0 +1,38 @@
#ifndef cmAuxSourceDirectoryRule_h
#define cmAuxSourceDirectoryRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmAuxSourceDirectoryRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmAuxSourceDirectoryRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
// This is the name used in the input file.
virtual const char* GetName() { return "AUX_SOURCE_DIRECTORY";}
virtual const char* TerseDocumentaion()
{
return "Add all the source files found in the specified directory to\n"
" the build.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"AUX_SOURCE_DIRECTORY(dir)";
}
};
#endif

View File

@ -1,9 +1,6 @@
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include "cmClassFile.h"
#include "cmStandardIncludes.h"
#include "cmSystemTools.h"
#include <iostream>
@ -62,8 +59,8 @@ void cmClassFile::SetName(const char* name, const char* dir)
hname += ".h";
if(!cmSystemTools::FileExists(hname.c_str()))
{
std::cerr << "ERROR, can not find file " << hname;
std::cerr << "Tried .txx .cxx .c " << std::endl;
cmSystemTools::Error("can not find file ", hname.c_str());
cmSystemTools::Error("Tried .txx .cxx .c for ", hname.c_str());
}
}

View File

@ -19,12 +19,17 @@
*/
#ifndef cmClassFile_h
#define cmClassFile_h
#include <string>
#include <vector>
#include "cmStandardIncludes.h"
struct cmClassFile
{
cmClassFile()
{
m_AbstractClass = false;
m_HeaderFileOnly = false;
}
/**
* Set the name of the file, given the directory
* the file should be in. Extensions are tried on

View File

@ -1,139 +0,0 @@
#include "cmCollectFlags.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
#include <fstream>
#include <iterator>
#include <iostream>
cmCollectFlags::cmCollectFlags()
{
}
cmCollectFlags::~cmCollectFlags()
{
}
void cmCollectFlags::Print()
{
std::ostream_iterator<std::string> out(std::cout, "\n");
std::cout << "m_IncludeDirectories " << std::endl;
std::copy(m_IncludeDirectories.begin(), m_IncludeDirectories.end(), out);
std::cout << "m_linkdirectories " << std::endl;
std::copy(m_LinkDirectories.begin(), m_LinkDirectories.end(), out);
std::cout << "m_LinkLibraries " << std::endl;
std::copy(m_LinkLibraries.begin(), m_LinkLibraries.end(), out);
std::cout << "m_LinkLibrariesWin32 " << std::endl;
std::copy(m_LinkLibrariesWin32.begin(), m_LinkLibrariesWin32.end(), out);
std::cout << "m_LinkLibrariesUnix " << std::endl;
std::copy(m_LinkLibrariesUnix.begin(), m_LinkLibrariesUnix.end(), out);
}
void cmCollectFlags::SetSourceHomeDirectory(const char* dir)
{
m_SourceHomeDirectory = dir;
cmSystemTools::ConvertToUnixSlashes(m_SourceHomeDirectory);
}
void cmCollectFlags::SetStartDirectory(const char* dir)
{
m_StartDirectory = dir;
cmSystemTools::ConvertToUnixSlashes(m_StartDirectory);
}
void cmCollectFlags::ParseDirectories()
{
this->ParseDirectory(m_StartDirectory.c_str());
}
void cmCollectFlags::ParseFile(const char* filename)
{
std::ifstream fin(filename);
if(!fin)
{
std::cerr << "error can not open file " << filename << std::endl;
return;
}
char inbuffer[2048];
while ( fin.getline(inbuffer, 2047 ) )
{
std::string line = inbuffer;
if(line.find("INCLUDE_DIRECTORIES") != std::string::npos)
{
cmSystemTools::ReadList(m_IncludeDirectories, fin);
}
if(line.find("LINK_DIRECTORIES") != std::string::npos)
{
cmSystemTools::ReadList(m_LinkDirectories, fin);
}
if(line.find("LINK_LIBRARIES") != std::string::npos)
{
cmSystemTools::ReadList(m_LinkLibraries, fin);
}
if(line.find("WIN32_LIBRARIES") != std::string::npos)
{
cmSystemTools::ReadList(m_LinkLibrariesWin32, fin);
}
if(line.find("UNIX_LIBRARIES") != std::string::npos)
{
cmSystemTools::ReadList(m_LinkLibrariesUnix, fin);
}
}
}
// Go until directory == m_cmHomeDirectory
// 1. fix slashes
// 2. peal off /dir until home found, go no higher
void cmCollectFlags::ParseDirectory(const char* dir)
{
std::string listsFile = dir;
listsFile += "/CMakeLists.txt";
if(cmSystemTools::FileExists(listsFile.c_str()))
{
this->ParseFile(listsFile.c_str());
}
if(m_SourceHomeDirectory == dir)
{
return;
}
std::string dotdotDir = dir;
std::string::size_type pos = dotdotDir.rfind('/');
if(pos != std::string::npos)
{
dotdotDir = dotdotDir.substr(0, pos);
this->ParseDirectory(dotdotDir.c_str());
}
}
// expance CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR 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_DIR}",
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_DIR}",
makefile->GetHomeDirectory() );
}
}

View File

@ -1,107 +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.
=========================================================================*/
/**
* 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
{
public:
cmCollectFlags();
~cmCollectFlags ();
/**
* Set the home directory for the source code.
*/
void SetSourceHomeDirectory(const char* dir);
/**
* Set the start directory to look for flags
*/
void SetStartDirectory(const char* dir);
/**
* Parse the directory and all of it's parents for config
* information
*/
void ParseDirectories();
/**
* Print to standard out
*/
void Print();
/**
* Expance varibles for home and binary root in the collected flags.
* CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR are replaced with
* makefile->GetOutputHomeDirectory() and
* makefile->GetHomeDirectory()
*/
void ExpandVaribles(cmMakefile* makefile);
std::vector<std::string>& GetIncludeDirectories()
{
return m_IncludeDirectories;
}
std::vector<std::string>& GetLinkDirectories()
{
return m_LinkDirectories;
}
std::vector<std::string>& GetLinkLibraries()
{
return m_LinkLibraries;
}
std::vector<std::string>& GetLinkLibrariesWin32()
{
return m_LinkLibrariesWin32;
}
std::vector<std::string>& GetLinkLibrariesUnix()
{
return m_LinkLibrariesUnix;
}
private:
/**
* Look for CMakeLists.txt files to parse in dir,
* then in dir's parents, until the SourceHome directory
* is found.
*/
void ParseDirectory(const char* dir);
/**
* Parse a file for includes links and libs
*/
void ParseFile(const char* dir);
std::string m_SourceHomeDirectory; // source code top level dir
std::string m_StartDirectory; // source code sub directory
std::vector<std::string> m_IncludeDirectories;
std::vector<std::string> m_LinkDirectories;
std::vector<std::string> m_LinkLibraries;
std::vector<std::string> m_LinkLibrariesWin32;
std::vector<std::string> m_LinkLibrariesUnix;
};
#endif

View File

@ -1,8 +1,6 @@
#include "cmDSPMakefile.h"
#include "cmStandardIncludes.h"
#include "cmSystemTools.h"
#include "cmCollectFlags.h"
#include <iostream>
#include <fstream>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef GetCurrentDirectory
@ -12,12 +10,20 @@ static void Die(const char* message)
MessageBox(0, message, 0, MB_OK);
exit(-1);
}
cmDSPMakefile::~cmDSPMakefile()
{
}
cmDSPMakefile::cmDSPMakefile(cmMakefile*mf)
{
m_Makefile = mf;
}
void cmDSPMakefile::OutputDSPFile()
{
// Setup /I and /LIBPATH options
std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories();
std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
std::vector<std::string>::iterator i;
for(i = includes.begin(); i != includes.end(); ++i)
{
@ -25,21 +31,21 @@ void cmDSPMakefile::OutputDSPFile()
m_IncludeOptions += *i;
m_IncludeOptions += "\" ";
}
std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries();
std::vector<std::string>& libs = m_Makefile->GetLinkLibraries();
for(i = libs.begin(); i != libs.end(); ++i)
{
m_DebugLibraryOptions += " ";
m_DebugLibraryOptions += *i;
m_DebugLibraryOptions += ".lib ";
}
std::vector<std::string>& libswin32 = m_BuildFlags.GetLinkLibrariesWin32();
std::vector<std::string>& libswin32 = m_Makefile->GetLinkLibrariesWin32();
for(i = libswin32.begin(); i != libswin32.end(); ++i)
{
m_DebugLibraryOptions += " ";
m_DebugLibraryOptions += *i;
m_DebugLibraryOptions += ".lib ";
}
std::vector<std::string>& libdirs = m_BuildFlags.GetLinkDirectories();
std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
for(i = libdirs.begin(); i != libdirs.end(); ++i)
{
m_DebugLibraryOptions += " /LIBPATH:\"";
@ -53,23 +59,27 @@ void cmDSPMakefile::OutputDSPFile()
}
}
m_DebugLibraryOptions += "/STACK:10000000 ";
// add any extra define flags
m_DebugLibraryOptions += m_Makefile->GetDefineFlags();
m_ReleaseLibraryOptions = m_DebugLibraryOptions;
cmSystemTools::ReplaceString(m_ReleaseLibraryOptions, "Debug", "Release");
// If the output directory is not the m_cmHomeDirectory
// then create it.
if(m_OutputDirectory != m_cmHomeDirectory)
if(strcmp(m_Makefile->GetOutputDirectory(),
m_Makefile->GetHomeDirectory()) != 0)
{
if(!cmSystemTools::MakeDirectory(m_OutputDirectory.c_str()))
if(!cmSystemTools::MakeDirectory(m_Makefile->GetOutputDirectory()))
{
std::string message = "Error creating directory ";
message += m_OutputDirectory;
message += m_Makefile->GetOutputDirectory();
Die(message.c_str());
}
}
if(!m_Executables)
if(!m_Makefile->HasExecutables())
{
if(this->m_LibraryName == "")
if(strlen(m_Makefile->GetLibraryName()) == 0)
{
// if no library silently give up
return;
@ -84,10 +94,11 @@ void cmDSPMakefile::OutputDSPFile()
}
void cmDSPMakefile::CreateExecutableDSPFiles()
{
for(int i = 0; i < m_Classes.size(); ++i)
std::vector<cmClassFile>& Classes = m_Makefile->GetClasses();
for(int i = 0; i < Classes.size(); ++i)
{
cmClassFile& classfile = m_Classes[i];
std::string fname = m_OutputDirectory;
cmClassFile& classfile = Classes[i];
std::string fname = m_Makefile->GetOutputDirectory();
fname += "/";
fname += classfile.m_ClassName;
fname += ".dsp";
@ -100,9 +111,9 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
}
else
{
m_LibraryName = classfile.m_ClassName;
m_Makefile->SetLibraryName(classfile.m_ClassName.c_str());
this->SetBuildType(EXECUTABLE);
std::string pname = m_LibraryName;
std::string pname = m_Makefile->GetLibraryName();
m_CreatedProjectNames.push_back(pname);
this->WriteDSPHeader(fout);
@ -120,12 +131,12 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
void cmDSPMakefile::CreateSingleDSP()
{
std::string fname;
fname = m_OutputDirectory;
fname = m_Makefile->GetOutputDirectory();
fname += "/";
fname += this->m_LibraryName;
fname += m_Makefile->GetLibraryName();
fname += ".dsp";
m_CreatedProjectNames.clear();
std::string pname = m_LibraryName;
std::string pname = m_Makefile->GetLibraryName();
m_CreatedProjectNames.push_back(pname);
std::ofstream fout(fname.c_str());
if(!fout)
@ -141,20 +152,20 @@ void cmDSPMakefile::WriteDSPBuildRule(std::ostream& fout)
{
std::string dspname = *(m_CreatedProjectNames.end()-1);
dspname += ".dsp";
std::string makefileIn = this->GetCurrentDirectory();
std::string makefileIn = m_Makefile->GetCurrentDirectory();
makefileIn += "/";
makefileIn += "CMakeLists.txt";
std::string dsprule = GetHomeDirectory();
std::string dsprule = m_Makefile->GetHomeDirectory();
dsprule += "/CMake/Source/CMakeSetupCMD ";
dsprule += makefileIn;
dsprule += " -DSP -H";
dsprule += this->GetHomeDirectory();
dsprule += m_Makefile->GetHomeDirectory();
dsprule += " -D";
dsprule += this->GetCurrentDirectory();
dsprule += m_Makefile->GetCurrentDirectory();
dsprule += " -O";
dsprule += this->GetOutputDirectory();
dsprule += m_Makefile->GetOutputDirectory();
dsprule += " -B";
dsprule += this->GetOutputHomeDirectory();
dsprule += m_Makefile->GetOutputHomeDirectory();
this->WriteCustomRule(fout, makefileIn.c_str(),
dspname.c_str(),
dsprule.c_str());
@ -172,9 +183,9 @@ void cmDSPMakefile::WriteDSPFile(std::ostream& fout)
void cmDSPMakefile::WriteCustomRule(std::ostream& fout,
const char* source,
const char* result,
const char* command)
const char* source,
const char* result,
const char* command)
{
fout << "# Begin Source File\n\n";
fout << "SOURCE=" << source << "\n\n";
@ -208,21 +219,21 @@ void cmDSPMakefile::SetBuildType(BuildType b)
switch(b)
{
case STATIC_LIBRARY:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate = m_Makefile->GetHomeDirectory();
m_DSPHeaderTemplate += "/CMake/Source/staticLibHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate = m_Makefile->GetHomeDirectory();
m_DSPFooterTemplate += "/CMake/Source/staticLibFooter.dsptemplate";
break;
case DLL:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate = m_Makefile->GetHomeDirectory();
m_DSPHeaderTemplate += "/CMake/Source/DLLHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate = m_Makefile->GetHomeDirectory();
m_DSPFooterTemplate += "/CMake/Source/DLLFooter.dsptemplate";
break;
case EXECUTABLE:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate = m_Makefile->GetHomeDirectory();
m_DSPHeaderTemplate += "/CMake/Source/EXEHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate = m_Makefile->GetHomeDirectory();
m_DSPFooterTemplate += "/CMake/Source/EXEFooter.dsptemplate";
break;
}
@ -250,7 +261,7 @@ void cmDSPMakefile::WriteDSPHeader(std::ostream& fout)
cmSystemTools::ReplaceString(line, "BUILD_INCLUDES",
m_IncludeOptions.c_str());
cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",
m_LibraryName.c_str());
m_Makefile->GetLibraryName());
cmSystemTools::ReplaceString(line,
"EXTRA_DEFINES", "");
fout << line.c_str() << std::endl;
@ -278,11 +289,12 @@ void cmDSPMakefile::WriteDSPFooter(std::ostream& fout)
void cmDSPMakefile::WriteDSPBuildRules(std::ostream& fout)
{
for(int i = 0; i < m_Classes.size(); ++i)
std::vector<cmClassFile>& Classes = m_Makefile->GetClasses();
for(int i = 0; i < Classes.size(); ++i)
{
if(!m_Classes[i].m_AbstractClass && !m_Classes[i].m_HeaderFileOnly)
if(!Classes[i].m_AbstractClass && !Classes[i].m_HeaderFileOnly)
{
this->WriteDSPBuildRule(fout, m_Classes[i].m_FullPath.c_str());
this->WriteDSPBuildRule(fout, Classes[i].m_FullPath.c_str());
}
}
}

View File

@ -20,15 +20,14 @@
*/
#ifndef cmDSPMakefile_h
#define cmDSPMakefile_h
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include "cmStandardIncludes.h"
#include "cmMakefile.h"
#include <vector>
class cmDSPMakefile : public cmMakefile
class cmDSPMakefile
{
public:
cmDSPMakefile(cmMakefile*);
~cmDSPMakefile();
void OutputDSPFile();
enum BuildType { STATIC_LIBRARY, DLL, EXECUTABLE };
void SetBuildType(BuildType );
@ -38,6 +37,10 @@ public:
{
return m_CreatedProjectNames;
}
cmMakefile* GetMakefile()
{
return m_Makefile;
}
private:
std::string m_DSPHeaderTemplate;
@ -64,6 +67,7 @@ private:
std::string m_IncludeOptions;
std::string m_DebugLibraryOptions;
std::string m_ReleaseLibraryOptions;
cmMakefile* m_Makefile;
};
#endif

View File

@ -1,8 +1,6 @@
#include "cmDSPMakefile.h"
#include "cmStandardIncludes.h"
#include "cmSystemTools.h"
#include "cmCollectFlags.h"
#include <iostream>
#include <fstream>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef GetCurrentDirectory
@ -12,12 +10,20 @@ static void Die(const char* message)
MessageBox(0, message, 0, MB_OK);
exit(-1);
}
cmDSPMakefile::~cmDSPMakefile()
{
}
cmDSPMakefile::cmDSPMakefile(cmMakefile*mf)
{
m_Makefile = mf;
}
void cmDSPMakefile::OutputDSPFile()
{
// Setup /I and /LIBPATH options
std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories();
std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
std::vector<std::string>::iterator i;
for(i = includes.begin(); i != includes.end(); ++i)
{
@ -25,21 +31,21 @@ void cmDSPMakefile::OutputDSPFile()
m_IncludeOptions += *i;
m_IncludeOptions += "\" ";
}
std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries();
std::vector<std::string>& libs = m_Makefile->GetLinkLibraries();
for(i = libs.begin(); i != libs.end(); ++i)
{
m_DebugLibraryOptions += " ";
m_DebugLibraryOptions += *i;
m_DebugLibraryOptions += ".lib ";
}
std::vector<std::string>& libswin32 = m_BuildFlags.GetLinkLibrariesWin32();
std::vector<std::string>& libswin32 = m_Makefile->GetLinkLibrariesWin32();
for(i = libswin32.begin(); i != libswin32.end(); ++i)
{
m_DebugLibraryOptions += " ";
m_DebugLibraryOptions += *i;
m_DebugLibraryOptions += ".lib ";
}
std::vector<std::string>& libdirs = m_BuildFlags.GetLinkDirectories();
std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
for(i = libdirs.begin(); i != libdirs.end(); ++i)
{
m_DebugLibraryOptions += " /LIBPATH:\"";
@ -53,23 +59,27 @@ void cmDSPMakefile::OutputDSPFile()
}
}
m_DebugLibraryOptions += "/STACK:10000000 ";
// add any extra define flags
m_DebugLibraryOptions += m_Makefile->GetDefineFlags();
m_ReleaseLibraryOptions = m_DebugLibraryOptions;
cmSystemTools::ReplaceString(m_ReleaseLibraryOptions, "Debug", "Release");
// If the output directory is not the m_cmHomeDirectory
// then create it.
if(m_OutputDirectory != m_cmHomeDirectory)
if(strcmp(m_Makefile->GetOutputDirectory(),
m_Makefile->GetHomeDirectory()) != 0)
{
if(!cmSystemTools::MakeDirectory(m_OutputDirectory.c_str()))
if(!cmSystemTools::MakeDirectory(m_Makefile->GetOutputDirectory()))
{
std::string message = "Error creating directory ";
message += m_OutputDirectory;
message += m_Makefile->GetOutputDirectory();
Die(message.c_str());
}
}
if(!m_Executables)
if(!m_Makefile->HasExecutables())
{
if(this->m_LibraryName == "")
if(strlen(m_Makefile->GetLibraryName()) == 0)
{
// if no library silently give up
return;
@ -84,10 +94,11 @@ void cmDSPMakefile::OutputDSPFile()
}
void cmDSPMakefile::CreateExecutableDSPFiles()
{
for(int i = 0; i < m_Classes.size(); ++i)
std::vector<cmClassFile>& Classes = m_Makefile->GetClasses();
for(int i = 0; i < Classes.size(); ++i)
{
cmClassFile& classfile = m_Classes[i];
std::string fname = m_OutputDirectory;
cmClassFile& classfile = Classes[i];
std::string fname = m_Makefile->GetOutputDirectory();
fname += "/";
fname += classfile.m_ClassName;
fname += ".dsp";
@ -100,9 +111,9 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
}
else
{
m_LibraryName = classfile.m_ClassName;
m_Makefile->SetLibraryName(classfile.m_ClassName.c_str());
this->SetBuildType(EXECUTABLE);
std::string pname = m_LibraryName;
std::string pname = m_Makefile->GetLibraryName();
m_CreatedProjectNames.push_back(pname);
this->WriteDSPHeader(fout);
@ -120,12 +131,12 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
void cmDSPMakefile::CreateSingleDSP()
{
std::string fname;
fname = m_OutputDirectory;
fname = m_Makefile->GetOutputDirectory();
fname += "/";
fname += this->m_LibraryName;
fname += m_Makefile->GetLibraryName();
fname += ".dsp";
m_CreatedProjectNames.clear();
std::string pname = m_LibraryName;
std::string pname = m_Makefile->GetLibraryName();
m_CreatedProjectNames.push_back(pname);
std::ofstream fout(fname.c_str());
if(!fout)
@ -141,20 +152,20 @@ void cmDSPMakefile::WriteDSPBuildRule(std::ostream& fout)
{
std::string dspname = *(m_CreatedProjectNames.end()-1);
dspname += ".dsp";
std::string makefileIn = this->GetCurrentDirectory();
std::string makefileIn = m_Makefile->GetCurrentDirectory();
makefileIn += "/";
makefileIn += "CMakeLists.txt";
std::string dsprule = GetHomeDirectory();
std::string dsprule = m_Makefile->GetHomeDirectory();
dsprule += "/CMake/Source/CMakeSetupCMD ";
dsprule += makefileIn;
dsprule += " -DSP -H";
dsprule += this->GetHomeDirectory();
dsprule += m_Makefile->GetHomeDirectory();
dsprule += " -D";
dsprule += this->GetCurrentDirectory();
dsprule += m_Makefile->GetCurrentDirectory();
dsprule += " -O";
dsprule += this->GetOutputDirectory();
dsprule += m_Makefile->GetOutputDirectory();
dsprule += " -B";
dsprule += this->GetOutputHomeDirectory();
dsprule += m_Makefile->GetOutputHomeDirectory();
this->WriteCustomRule(fout, makefileIn.c_str(),
dspname.c_str(),
dsprule.c_str());
@ -172,9 +183,9 @@ void cmDSPMakefile::WriteDSPFile(std::ostream& fout)
void cmDSPMakefile::WriteCustomRule(std::ostream& fout,
const char* source,
const char* result,
const char* command)
const char* source,
const char* result,
const char* command)
{
fout << "# Begin Source File\n\n";
fout << "SOURCE=" << source << "\n\n";
@ -208,21 +219,21 @@ void cmDSPMakefile::SetBuildType(BuildType b)
switch(b)
{
case STATIC_LIBRARY:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate = m_Makefile->GetHomeDirectory();
m_DSPHeaderTemplate += "/CMake/Source/staticLibHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate = m_Makefile->GetHomeDirectory();
m_DSPFooterTemplate += "/CMake/Source/staticLibFooter.dsptemplate";
break;
case DLL:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate = m_Makefile->GetHomeDirectory();
m_DSPHeaderTemplate += "/CMake/Source/DLLHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate = m_Makefile->GetHomeDirectory();
m_DSPFooterTemplate += "/CMake/Source/DLLFooter.dsptemplate";
break;
case EXECUTABLE:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate = m_Makefile->GetHomeDirectory();
m_DSPHeaderTemplate += "/CMake/Source/EXEHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate = m_Makefile->GetHomeDirectory();
m_DSPFooterTemplate += "/CMake/Source/EXEFooter.dsptemplate";
break;
}
@ -250,7 +261,7 @@ void cmDSPMakefile::WriteDSPHeader(std::ostream& fout)
cmSystemTools::ReplaceString(line, "BUILD_INCLUDES",
m_IncludeOptions.c_str());
cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",
m_LibraryName.c_str());
m_Makefile->GetLibraryName());
cmSystemTools::ReplaceString(line,
"EXTRA_DEFINES", "");
fout << line.c_str() << std::endl;
@ -278,11 +289,12 @@ void cmDSPMakefile::WriteDSPFooter(std::ostream& fout)
void cmDSPMakefile::WriteDSPBuildRules(std::ostream& fout)
{
for(int i = 0; i < m_Classes.size(); ++i)
std::vector<cmClassFile>& Classes = m_Makefile->GetClasses();
for(int i = 0; i < Classes.size(); ++i)
{
if(!m_Classes[i].m_AbstractClass && !m_Classes[i].m_HeaderFileOnly)
if(!Classes[i].m_AbstractClass && !Classes[i].m_HeaderFileOnly)
{
this->WriteDSPBuildRule(fout, m_Classes[i].m_FullPath.c_str());
this->WriteDSPBuildRule(fout, Classes[i].m_FullPath.c_str());
}
}
}

View File

@ -20,15 +20,14 @@
*/
#ifndef cmDSPMakefile_h
#define cmDSPMakefile_h
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include "cmStandardIncludes.h"
#include "cmMakefile.h"
#include <vector>
class cmDSPMakefile : public cmMakefile
class cmDSPMakefile
{
public:
cmDSPMakefile(cmMakefile*);
~cmDSPMakefile();
void OutputDSPFile();
enum BuildType { STATIC_LIBRARY, DLL, EXECUTABLE };
void SetBuildType(BuildType );
@ -38,6 +37,10 @@ public:
{
return m_CreatedProjectNames;
}
cmMakefile* GetMakefile()
{
return m_Makefile;
}
private:
std::string m_DSPHeaderTemplate;
@ -64,6 +67,7 @@ private:
std::string m_IncludeOptions;
std::string m_DebugLibraryOptions;
std::string m_ReleaseLibraryOptions;
cmMakefile* m_Makefile;
};
#endif

View File

@ -1,46 +1,47 @@
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include "cmDSWMakefile.h"
#include "cmStandardIncludes.h"
#include "cmSystemTools.h"
#include "cmDSPMakefile.h"
#include <iostream>
#include <fstream>
#include "cmMSProjectGenerator.h"
#include <windows.h>
// microsoft nonsense
#undef GetCurrentDirectory
#undef SetCurrentDirectory
cmDSWMakefile::cmDSWMakefile(cmMakefile* m)
{
m_Makefile = m;
}
// output the DSW file
void cmDSWMakefile::OutputDSWFile()
{
if(m_OutputDirectory == "")
if(m_Makefile->GetOutputDirectory() == "")
{
// default to build in place
m_OutputDirectory = m_cmHomeDirectory;
m_Makefile->SetOutputDirectory(m_Makefile->GetHomeDirectory());
}
// If the output directory is not the m_cmHomeDirectory
// then create it.
if(m_OutputDirectory != m_cmHomeDirectory)
if(strcmp(m_Makefile->GetOutputDirectory(),
m_Makefile->GetHomeDirectory()) != 0)
{
if(!cmSystemTools::MakeDirectory(m_OutputDirectory.c_str()))
if(!cmSystemTools::MakeDirectory(m_Makefile->GetOutputDirectory()))
{
MessageBox(0, "Error creating directory ", 0, MB_OK);
MessageBox(0, m_OutputDirectory.c_str(), 0, MB_OK);
MessageBox(0, m_Makefile->GetOutputDirectory(), 0, MB_OK);
}
}
std::string fname;
fname = m_OutputDirectory;
fname = m_Makefile->GetOutputDirectory();
fname += "/";
fname += this->m_ProjectName;
fname += m_Makefile->GetProjectName();
fname += ".dsw";
std::cerr << "writting dsw file " << fname.c_str() << std::endl;
std::ofstream fout(fname.c_str());
if(!fout)
{
std::cerr << "Error can not open "
<< fname.c_str() << " for write" << std::endl;
cmSystemTools::Error("Error can not open for write: " , fname.c_str());
return;
}
this->WriteDSWFile(fout);
@ -53,10 +54,12 @@ void cmDSWMakefile::OutputDSWFile()
// The result is a vector of cmDSPMakefile objects, one for
// each directory with a CMakeLists.txt file
//
void cmDSWMakefile::FindAllCMakeListsFiles(const char* subdir,
std::vector<cmDSPMakefile*>& makefiles)
void
cmDSWMakefile
::FindAllCMakeListsFiles(const char* subdir,
std::vector<cmMSProjectGenerator*>& makefiles)
{
std::string currentDir = this->GetCurrentDirectory();
std::string currentDir = m_Makefile->GetCurrentDirectory();
currentDir += "/";
currentDir += subdir;
currentDir += "/";
@ -66,31 +69,34 @@ void cmDSWMakefile::FindAllCMakeListsFiles(const char* subdir,
if(cmSystemTools::FileExists(currentDir.c_str()))
{
// Create a new cmDSPMakefile to read the currentDir CMakeLists.txt file
cmDSPMakefile* dsp = new cmDSPMakefile;
cmMSProjectGenerator* pg = new cmMSProjectGenerator;
pg->SetBuildDSP();
cmMakefile* mf = new cmMakefile;
mf->SetMakefileGenerator(pg);
// add it to the vector
makefiles.push_back(dsp);
makefiles.push_back(pg);
// Set up the file with the current context
dsp->SetOutputHomeDirectory(this->GetOutputDirectory());
dsp->SetHomeDirectory(this->GetHomeDirectory());
mf->SetOutputHomeDirectory(m_Makefile->GetOutputDirectory());
mf->SetHomeDirectory(m_Makefile->GetHomeDirectory());
// set the current directory in the Source as a full
// path
std::string currentDir = this->GetCurrentDirectory();
std::string currentDir = m_Makefile->GetCurrentDirectory();
currentDir += "/";
currentDir += subdir;
dsp->SetCurrentDirectory(currentDir.c_str());
mf->SetCurrentDirectory(currentDir.c_str());
// Parse the CMakeLists.txt file
currentDir += "/CMakeLists.txt";
dsp->ReadMakefile(currentDir.c_str());
mf->ReadMakefile(currentDir.c_str());
// Set the output directory which may be different than the source
std::string outdir = m_OutputDirectory;
std::string outdir = m_Makefile->GetOutputDirectory();
outdir += "/";
outdir += subdir;
dsp->SetOutputDirectory(outdir.c_str());
mf->SetOutputDirectory(outdir.c_str());
// Create the DSP file
dsp->OutputDSPFile();
mf->GenerateMakefile();
// Look at any sub directories parsed (SUBDIRS) and
// recurse into them
const std::vector<std::string>& subdirs = dsp->GetSubDirectories();
const std::vector<std::string>& subdirs = mf->GetSubDirectories();
for(std::vector<std::string>::const_iterator i = subdirs.begin();
i != subdirs.end(); ++i)
{
@ -105,8 +111,8 @@ void cmDSWMakefile::FindAllCMakeListsFiles(const char* subdir,
}
else
{
std::cerr << "Can not find CMakeLists.txt in " << currentDir.c_str()
<< std::endl;
cmSystemTools::Error("Can not find CMakeLists.txt in ",
currentDir.c_str());
}
}
@ -117,43 +123,43 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
// Write out the header for a DSW file
this->WriteDSWHeader(fout);
// Create an array of dsp files for the project
std::vector<cmDSPMakefile*> dspfiles;
std::vector<cmMSProjectGenerator*> dspfiles;
// loop over all the subdirectories for the DSW file,
// and find all sub directory projects
for(std::vector<std::string>::iterator j = m_SubDirectories.begin();
j != m_SubDirectories.end(); ++j)
const std::vector<std::string>& dirs = m_Makefile->GetSubDirectories();
for(std::vector<std::string>::const_iterator j = dirs.begin();
j != dirs.end(); ++j)
{
this->FindAllCMakeListsFiles(j->c_str(), dspfiles);
}
// For each DSP file created insert them into the DSW file
for(std::vector<cmDSPMakefile*>::iterator k = dspfiles.begin();
for(std::vector<cmMSProjectGenerator*>::iterator k = dspfiles.begin();
k != dspfiles.end(); ++k)
{
// Get the directory for the dsp file, it comes
// from the source, so it has the source path which needs
// to be removed as this may be built in a different directory
// than the source
std::string dir = (*k)->GetCurrentDirectory();
std::string dir = (*k)->GetDSPMakefile()->
GetMakefile()->GetCurrentDirectory();
// Get the home directory with the trailing slash
std::string homedir = this->GetHomeDirectory();
std::string homedir = m_Makefile->GetHomeDirectory();
homedir += "/";
// make the directory relative by removing the home directory part
cmSystemTools::ReplaceString(dir, homedir.c_str(), "");
// Get the list of create dsp files from the cmDSPMakefile, more
// than one dsp could have been created per input CMakeLists.txt file
std::vector<std::string> dspnames = (*k)->GetCreatedProjectNames();
std::cerr << "Create dsp for "
<< dspnames.size()
<< " number of dsp files in " << dir << std::endl;
std::vector<std::string> dspnames = (*k)->GetDSPMakefile()->GetCreatedProjectNames();
for(std::vector<std::string>::iterator si = dspnames.begin();
si != dspnames.end(); ++si)
{
// Write the project into the DSW file
this->WriteProject(fout, si->c_str(), dir.c_str(), *k);
this->WriteProject(fout, si->c_str(), dir.c_str(),
(*k)->GetDSPMakefile());
}
// delete the cmDSPMakefile object once done with it to avoid
// leaks
delete *k;
delete (*k)->GetDSPMakefile()->GetMakefile();
}
// Write the footer for the DSW file
this->WriteDSWFooter(fout);
@ -163,7 +169,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
void cmDSWMakefile::WriteProject(std::ostream& fout,
const char* dspname,
const char* dir,
cmMakefile* project)
cmDSPMakefile* project)
{
fout << "###############################################################################\n\n";
fout << "Project: \"" << dspname << "\"="
@ -171,12 +177,12 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
fout << "Package=<5>\n{{{\n}}}\n\n";
fout << "Package=<4>\n";
fout << "{{{\n";
if(project->HasExecutables())
if(project->GetMakefile()->HasExecutables())
{
// insert Begin Project Dependency Project_Dep_Name project stuff here
std::vector<std::string>::iterator i, end;
i = project->GetBuildFlags().GetLinkLibraries().begin();
end = project->GetBuildFlags().GetLinkLibraries().end();
i = project->GetMakefile()->GetLinkLibraries().begin();
end = project->GetMakefile()->GetLinkLibraries().end();
for(;i!= end; ++i)
{
fout << "Begin Project Dependency\n";

View File

@ -18,28 +18,27 @@
*/
#ifndef cmDSWMakefile_h
#define cmDSWMakefile_h
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include "cmStandardIncludes.h"
#include "cmMakefile.h"
#include <vector>
class cmDSPMakefile;
class cmMSProjectGenerator;
class cmDSWMakefile : public cmMakefile
class cmDSWMakefile
{
public:
cmDSWMakefile(cmMakefile*);
virtual void OutputDSWFile();
private:
void FindAllCMakeListsFiles(const char* subdir,
std::vector<cmDSPMakefile*>&);
std::vector<cmMSProjectGenerator*>&);
void WriteDSWFile(std::ostream& fout);
void WriteDSWHeader(std::ostream& fout);
void WriteProject(std::ostream& fout,
const char* name, const char* path,
cmMakefile* project);
const char* name, const char* path,
cmDSPMakefile* project);
void WriteDSWFooter(std::ostream& fout);
cmMakefile* m_Makefile;
};
#endif

View File

@ -1,46 +1,47 @@
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include "cmDSWMakefile.h"
#include "cmStandardIncludes.h"
#include "cmSystemTools.h"
#include "cmDSPMakefile.h"
#include <iostream>
#include <fstream>
#include "cmMSProjectGenerator.h"
#include <windows.h>
// microsoft nonsense
#undef GetCurrentDirectory
#undef SetCurrentDirectory
cmDSWMakefile::cmDSWMakefile(cmMakefile* m)
{
m_Makefile = m;
}
// output the DSW file
void cmDSWMakefile::OutputDSWFile()
{
if(m_OutputDirectory == "")
if(m_Makefile->GetOutputDirectory() == "")
{
// default to build in place
m_OutputDirectory = m_cmHomeDirectory;
m_Makefile->SetOutputDirectory(m_Makefile->GetHomeDirectory());
}
// If the output directory is not the m_cmHomeDirectory
// then create it.
if(m_OutputDirectory != m_cmHomeDirectory)
if(strcmp(m_Makefile->GetOutputDirectory(),
m_Makefile->GetHomeDirectory()) != 0)
{
if(!cmSystemTools::MakeDirectory(m_OutputDirectory.c_str()))
if(!cmSystemTools::MakeDirectory(m_Makefile->GetOutputDirectory()))
{
MessageBox(0, "Error creating directory ", 0, MB_OK);
MessageBox(0, m_OutputDirectory.c_str(), 0, MB_OK);
MessageBox(0, m_Makefile->GetOutputDirectory(), 0, MB_OK);
}
}
std::string fname;
fname = m_OutputDirectory;
fname = m_Makefile->GetOutputDirectory();
fname += "/";
fname += this->m_ProjectName;
fname += m_Makefile->GetProjectName();
fname += ".dsw";
std::cerr << "writting dsw file " << fname.c_str() << std::endl;
std::ofstream fout(fname.c_str());
if(!fout)
{
std::cerr << "Error can not open "
<< fname.c_str() << " for write" << std::endl;
cmSystemTools::Error("Error can not open for write: " , fname.c_str());
return;
}
this->WriteDSWFile(fout);
@ -53,10 +54,12 @@ void cmDSWMakefile::OutputDSWFile()
// The result is a vector of cmDSPMakefile objects, one for
// each directory with a CMakeLists.txt file
//
void cmDSWMakefile::FindAllCMakeListsFiles(const char* subdir,
std::vector<cmDSPMakefile*>& makefiles)
void
cmDSWMakefile
::FindAllCMakeListsFiles(const char* subdir,
std::vector<cmMSProjectGenerator*>& makefiles)
{
std::string currentDir = this->GetCurrentDirectory();
std::string currentDir = m_Makefile->GetCurrentDirectory();
currentDir += "/";
currentDir += subdir;
currentDir += "/";
@ -66,31 +69,34 @@ void cmDSWMakefile::FindAllCMakeListsFiles(const char* subdir,
if(cmSystemTools::FileExists(currentDir.c_str()))
{
// Create a new cmDSPMakefile to read the currentDir CMakeLists.txt file
cmDSPMakefile* dsp = new cmDSPMakefile;
cmMSProjectGenerator* pg = new cmMSProjectGenerator;
pg->SetBuildDSP();
cmMakefile* mf = new cmMakefile;
mf->SetMakefileGenerator(pg);
// add it to the vector
makefiles.push_back(dsp);
makefiles.push_back(pg);
// Set up the file with the current context
dsp->SetOutputHomeDirectory(this->GetOutputDirectory());
dsp->SetHomeDirectory(this->GetHomeDirectory());
mf->SetOutputHomeDirectory(m_Makefile->GetOutputDirectory());
mf->SetHomeDirectory(m_Makefile->GetHomeDirectory());
// set the current directory in the Source as a full
// path
std::string currentDir = this->GetCurrentDirectory();
std::string currentDir = m_Makefile->GetCurrentDirectory();
currentDir += "/";
currentDir += subdir;
dsp->SetCurrentDirectory(currentDir.c_str());
mf->SetCurrentDirectory(currentDir.c_str());
// Parse the CMakeLists.txt file
currentDir += "/CMakeLists.txt";
dsp->ReadMakefile(currentDir.c_str());
mf->ReadMakefile(currentDir.c_str());
// Set the output directory which may be different than the source
std::string outdir = m_OutputDirectory;
std::string outdir = m_Makefile->GetOutputDirectory();
outdir += "/";
outdir += subdir;
dsp->SetOutputDirectory(outdir.c_str());
mf->SetOutputDirectory(outdir.c_str());
// Create the DSP file
dsp->OutputDSPFile();
mf->GenerateMakefile();
// Look at any sub directories parsed (SUBDIRS) and
// recurse into them
const std::vector<std::string>& subdirs = dsp->GetSubDirectories();
const std::vector<std::string>& subdirs = mf->GetSubDirectories();
for(std::vector<std::string>::const_iterator i = subdirs.begin();
i != subdirs.end(); ++i)
{
@ -105,8 +111,8 @@ void cmDSWMakefile::FindAllCMakeListsFiles(const char* subdir,
}
else
{
std::cerr << "Can not find CMakeLists.txt in " << currentDir.c_str()
<< std::endl;
cmSystemTools::Error("Can not find CMakeLists.txt in ",
currentDir.c_str());
}
}
@ -117,43 +123,43 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
// Write out the header for a DSW file
this->WriteDSWHeader(fout);
// Create an array of dsp files for the project
std::vector<cmDSPMakefile*> dspfiles;
std::vector<cmMSProjectGenerator*> dspfiles;
// loop over all the subdirectories for the DSW file,
// and find all sub directory projects
for(std::vector<std::string>::iterator j = m_SubDirectories.begin();
j != m_SubDirectories.end(); ++j)
const std::vector<std::string>& dirs = m_Makefile->GetSubDirectories();
for(std::vector<std::string>::const_iterator j = dirs.begin();
j != dirs.end(); ++j)
{
this->FindAllCMakeListsFiles(j->c_str(), dspfiles);
}
// For each DSP file created insert them into the DSW file
for(std::vector<cmDSPMakefile*>::iterator k = dspfiles.begin();
for(std::vector<cmMSProjectGenerator*>::iterator k = dspfiles.begin();
k != dspfiles.end(); ++k)
{
// Get the directory for the dsp file, it comes
// from the source, so it has the source path which needs
// to be removed as this may be built in a different directory
// than the source
std::string dir = (*k)->GetCurrentDirectory();
std::string dir = (*k)->GetDSPMakefile()->
GetMakefile()->GetCurrentDirectory();
// Get the home directory with the trailing slash
std::string homedir = this->GetHomeDirectory();
std::string homedir = m_Makefile->GetHomeDirectory();
homedir += "/";
// make the directory relative by removing the home directory part
cmSystemTools::ReplaceString(dir, homedir.c_str(), "");
// Get the list of create dsp files from the cmDSPMakefile, more
// than one dsp could have been created per input CMakeLists.txt file
std::vector<std::string> dspnames = (*k)->GetCreatedProjectNames();
std::cerr << "Create dsp for "
<< dspnames.size()
<< " number of dsp files in " << dir << std::endl;
std::vector<std::string> dspnames = (*k)->GetDSPMakefile()->GetCreatedProjectNames();
for(std::vector<std::string>::iterator si = dspnames.begin();
si != dspnames.end(); ++si)
{
// Write the project into the DSW file
this->WriteProject(fout, si->c_str(), dir.c_str(), *k);
this->WriteProject(fout, si->c_str(), dir.c_str(),
(*k)->GetDSPMakefile());
}
// delete the cmDSPMakefile object once done with it to avoid
// leaks
delete *k;
delete (*k)->GetDSPMakefile()->GetMakefile();
}
// Write the footer for the DSW file
this->WriteDSWFooter(fout);
@ -163,7 +169,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
void cmDSWMakefile::WriteProject(std::ostream& fout,
const char* dspname,
const char* dir,
cmMakefile* project)
cmDSPMakefile* project)
{
fout << "###############################################################################\n\n";
fout << "Project: \"" << dspname << "\"="
@ -171,12 +177,12 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
fout << "Package=<5>\n{{{\n}}}\n\n";
fout << "Package=<4>\n";
fout << "{{{\n";
if(project->HasExecutables())
if(project->GetMakefile()->HasExecutables())
{
// insert Begin Project Dependency Project_Dep_Name project stuff here
std::vector<std::string>::iterator i, end;
i = project->GetBuildFlags().GetLinkLibraries().begin();
end = project->GetBuildFlags().GetLinkLibraries().end();
i = project->GetMakefile()->GetLinkLibraries().begin();
end = project->GetMakefile()->GetLinkLibraries().end();
for(;i!= end; ++i)
{
fout << "Begin Project Dependency\n";

View File

@ -18,28 +18,27 @@
*/
#ifndef cmDSWMakefile_h
#define cmDSWMakefile_h
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include "cmStandardIncludes.h"
#include "cmMakefile.h"
#include <vector>
class cmDSPMakefile;
class cmMSProjectGenerator;
class cmDSWMakefile : public cmMakefile
class cmDSWMakefile
{
public:
cmDSWMakefile(cmMakefile*);
virtual void OutputDSWFile();
private:
void FindAllCMakeListsFiles(const char* subdir,
std::vector<cmDSPMakefile*>&);
std::vector<cmMSProjectGenerator*>&);
void WriteDSWFile(std::ostream& fout);
void WriteDSWHeader(std::ostream& fout);
void WriteProject(std::ostream& fout,
const char* name, const char* path,
cmMakefile* project);
const char* name, const char* path,
cmDSPMakefile* project);
void WriteDSWFooter(std::ostream& fout);
cmMakefile* m_Makefile;
};
#endif

View File

@ -91,9 +91,8 @@ cmDirectory
return 0;
}
dirent* d =0;
dir = opendir(name);
for ( d = readdir(dir); d; d = readdir(dir) )
for (dirent* d = readdir(dir); d; d = readdir(dir) )
{
m_Files.push_back(d->d_name);
}
@ -114,7 +113,7 @@ cmDirectory
{
if ( index >= m_Files.size() )
{
std::cerr << "Bad index for GetFile on cmDirectory\n";
cmSystemTools::Error("Bad index for GetFile on cmDirectory\n", 0);
return 0;
}
return m_Files[index].c_str();

View File

@ -16,11 +16,8 @@
#ifndef __cmDirectory_h
#define __cmDirectory_h
#include <iostream>
#include <string>
#include <vector>
#include "cmStandardIncludes.h"
#include "cmSystemTools.h"
/** \class cmDirectory
* \brief Portable directory/filename traversal.
*

View File

@ -0,0 +1,20 @@
#include "cmExecutablesRule.h"
// cmExecutableRule
bool cmExecutablesRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
cmClassFile file;
file.SetName((*i).c_str(), m_Makefile->GetCurrentDirectory());
m_Makefile->AddExecutable(file);
}
return true;
}

View File

@ -0,0 +1,37 @@
#ifndef cmExecutablesRule_h
#define cmExecutablesRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmExecutablesRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmExecutablesRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
// This is the name used in the input file.
virtual const char* GetName() { return "EXECUTABLES";}
virtual const char* TerseDocumentaion()
{
return "Add a list of executables files.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"EXECUTABLES(file1 file2 ...)";
}
};
#endif

View File

@ -0,0 +1,18 @@
#include "cmFindIncludeRule.h"
// cmFindIncludeRule
bool cmFindIncludeRule::Invoke(std::vector<std::string>& args)
{
return false;
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
m_Makefile->AddDefineFlag((*i).c_str());
}
}

View File

@ -0,0 +1,38 @@
#ifndef cmFindIncludeRule_h
#define cmFindIncludeRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmFindIncludeRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmFindIncludeRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
virtual bool IsInherited() { return true; }
// This is the name used in the input file.
virtual const char* GetName() { return "FIND_INCLUDE";}
virtual const char* TerseDocumentaion()
{
return "Find an include path.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"FIND_INCLUDE(DEFINE try1 try2 ...);";
}
};
#endif

View File

@ -0,0 +1,18 @@
#include "cmFindLibraryRule.h"
// cmFindLibraryRule
bool cmFindLibraryRule::Invoke(std::vector<std::string>& args)
{
return false;
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
m_Makefile->AddDefineFlag((*i).c_str());
}
}

View File

@ -0,0 +1,38 @@
#ifndef cmFindLibraryRule_h
#define cmFindLibraryRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmFindLibraryRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmFindLibraryRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
virtual bool IsInherited() { return true; }
// This is the name used in the input file.
virtual const char* GetName() { return "FIND_LIBRARY";}
virtual const char* TerseDocumentaion()
{
return "Set a name for the entire project. One argument.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"FIND_LIBRARY(DEFINE try1 try2);";
}
};
#endif

View File

@ -0,0 +1,65 @@
#include "cmFindProgramRule.h"
#include <stdlib.h>
#include <stdio.h>
static void GetPath(std::vector<std::string>& path)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
char* pathSep = ";";
#else
char* pathSep = ":";
#endif
std::string pathEnv = getenv("PATH");
std::string::size_type start =0;
bool done = false;
while(!done)
{
std::string::size_type endpos = pathEnv.find(pathSep, start);
if(endpos != std::string::npos)
{
path.push_back(pathEnv.substr(start, endpos-start));
start = endpos+1;
}
else
{
done = true;
}
}
}
// cmFindProgramRule
bool cmFindProgramRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 2 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
std::vector<std::string> path;
GetPath(path);
std::vector<std::string>::iterator i = args.begin();
const char* define = (*i).c_str();
i++;
for(; i != args.end(); ++i)
{
for(int k=0; k < path.size(); k++)
{
std::string tryPath = path[k];
tryPath += "/";
tryPath += *i;
#ifdef _WIN32
tryPath += ".exe";
#endif
if(cmSystemTools::FileExists(tryPath.c_str()))
{
m_Makefile->AddDefinition(define, tryPath.c_str());
return true;
}
}
}
return false;
}

View File

@ -0,0 +1,39 @@
#ifndef cmFindProgramRule_h
#define cmFindProgramRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmFindProgramRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmFindProgramRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
virtual bool IsInherited() { return true; }
// This is the name used in the input file.
virtual const char* GetName() { return "FIND_PROGRARM";}
virtual const char* TerseDocumentaion()
{
return "not implemented.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"not implemented.\n"
"FIND_PROGRARM(NAME try1 try2 ...);";
}
};
#endif

View File

@ -0,0 +1,18 @@
#include "cmIncludeDirectoryRule.h"
// cmIncludeDirectoryRule
bool cmIncludeDirectoryRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
m_Makefile->AddIncludeDirectory((*i).c_str());
}
return true;
}

View File

@ -0,0 +1,38 @@
#ifndef cmIncludeDirectoryRule_h
#define cmIncludeDirectoryRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmIncludeDirectoryRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmIncludeDirectoryRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
virtual bool IsInherited() { return true; }
// This is the name used in the input file.
virtual const char* GetName() { return "INCLUDE_DIRECTORIES";}
virtual const char* TerseDocumentaion()
{
return "Add include directories to the build.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"INCLUDE_DIRECTORIES(dir1 dir2 ...).\n";
}
};
#endif

14
Source/cmLibraryRule.cxx Normal file
View File

@ -0,0 +1,14 @@
#include "cmLibraryRule.h"
// cmLibraryRule
bool cmLibraryRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 || args.size() > 1)
{
this->SetError("PROJECT called with incorrect number of arguments");
return false;
}
m_Makefile->SetLibraryName(args[0].c_str());
return true;
}

37
Source/cmLibraryRule.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef cmLibraryRule_h
#define cmLibraryRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmLibraryRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmLibraryRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
// This is the name used in the input file.
virtual const char* GetName() { return "LIBRARY";}
virtual const char* TerseDocumentaion()
{
return "Set a name for the Library.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"LIBRARY(libraryname);";
}
};
#endif

View File

@ -0,0 +1,18 @@
#include "cmLinkDirectoriesRule.h"
// cmLinkDirectoriesRule
bool cmLinkDirectoriesRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
m_Makefile->AddLinkDirectory((*i).c_str());
}
return true;
}

View File

@ -0,0 +1,42 @@
#ifndef cmLinkDirectoriesRule_h
#define cmLinkDirectoriesRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmLinkDirectoriesRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmLinkDirectoriesRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
virtual bool IsInherited() { return true; }
// This is the name used in the input file.
virtual const char* GetName() { return "LINK_DIRECTORIES";}
virtual const char* TerseDocumentaion()
{
return "Specify link directories.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"Specify the paths to the libraries that will be linked in.\n"
"LINK_DIRECTORIES(directory1 directory2 ...);\n"
"The directories can use built in definitions like \n"
"CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR.";
}
};
#endif

View File

@ -0,0 +1,18 @@
#include "cmLinkLibrariesRule.h"
// cmLinkLibrariesRule
bool cmLinkLibrariesRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
m_Makefile->AddLinkLibrary((*i).c_str());
}
return true;
}

View File

@ -0,0 +1,45 @@
#ifndef cmLinkLibrariesRule_h
#define cmLinkLibrariesRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmLinkLibrariesRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmLinkLibrariesRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
virtual bool IsInherited() { return true; }
// This is the name used in the input file.
virtual const char* GetName() { return "LINK_LIBRARIES";}
virtual const char* TerseDocumentaion()
{
return
"Specify a list of libraries to be linked into executables or \n"
"shared objects.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"Specify a list of libraries to be linked into executables or \n"
"shared objects. This rule is passed down to all other rules."
"LINK_LIBRARIES(library1 library2).\n"
"The library name should be the same as the name used in the\n"
"LIBRARY(library) rule.";
}
};
#endif

View File

@ -0,0 +1,31 @@
#include "cmMSProjectGenerator.h"
#include "cmDSWMakefile.h"
#include "cmDSPMakefile.h"
cmMSProjectGenerator::cmMSProjectGenerator()
{
m_DSWMakefile = 0;
m_DSPMakefile = 0;
SetBuildDSW();
}
void cmMSProjectGenerator::GenerateMakefile()
{
if(m_BuildDSW)
{
m_DSWMakefile = new cmDSWMakefile(m_Makefile);
m_DSWMakefile->OutputDSWFile();
}
else
{
m_DSPMakefile = new cmDSPMakefile(m_Makefile);
m_DSPMakefile->OutputDSPFile();
}
}
cmMSProjectGenerator::~cmMSProjectGenerator()
{
delete m_DSPMakefile;
delete m_DSWMakefile;
}

View File

@ -0,0 +1,45 @@
/*=========================================================================
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.
=========================================================================*/
/**
* cmMSProjectGenerator - class to write a microsoft DSW file.
*/
#ifndef cmMSProjectGenerator_h
#define cmMSProjectGenerator_h
#include "cmStandardIncludes.h"
#include "cmMakefileGenerator.h"
class cmDSPMakefile;
class cmDSWMakefile;
class cmMSProjectGenerator : public cmMakefileGenerator
{
public:
cmMSProjectGenerator();
~cmMSProjectGenerator();
virtual void GenerateMakefile();
void SetBuildDSP() { m_BuildDSW = false;}
void SetBuildDSW() { m_BuildDSW = true;}
cmDSWMakefile* GetDSWMakefile() { return m_DSWMakefile;}
cmDSPMakefile* GetDSPMakefile() { return m_DSPMakefile;}
private:
cmDSWMakefile* m_DSWMakefile;
cmDSPMakefile* m_DSPMakefile;
bool m_BuildDSW;
};
#endif

View File

@ -1,13 +1,6 @@
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include "cmMakeDepend.h"
#include "cmStandardIncludes.h"
#include "cmSystemTools.h"
#include <fstream>
#include <iostream>
#include <algorithm>
#include <functional>
cmMakeDepend::cmMakeDepend()
{
@ -43,8 +36,7 @@ void cmMakeDepend::SetMakefile(cmMakefile* makefile)
m_Makefile = makefile;
// Now extract any include paths from the makefile flags
cmCollectFlags& flags = m_Makefile->GetBuildFlags();
std::vector<std::string>& includes = flags.GetIncludeDirectories();
std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
std::vector<std::string>::iterator j;
for(j = includes.begin(); j != includes.end(); ++j)
{
@ -76,7 +68,7 @@ void cmMakeDepend::DoDepends()
// The size of the m_DependInformation will change as
// Depend is called so do not use an iterater but rather
// depend on the size of the array.
int j = 0;
unsigned int j = 0;
while(j != m_DependInformation.size())
{
cmDependInformation* info = m_DependInformation[j];
@ -94,7 +86,6 @@ void cmMakeDepend::DoDepends()
cmDependInformation* info = *i;
// Remove duplicate depends
info->RemoveDuplicateIndices();
std::vector<cmClassFile>::iterator j = m_Makefile->m_Classes.begin();
// find the class
if(info->m_ClassFileIndex != -1)
{
@ -115,14 +106,14 @@ void cmMakeDepend::Depend(cmDependInformation* info)
const char* path = info->m_FullPath.c_str();
if(!path)
{
std::cerr << "no full path for object" << std::endl;
cmSystemTools::Error("no full path for object", 0);
return;
}
std::ifstream fin(path);
if(!fin)
{
std::cerr << "error can not open " << info->m_FullPath << std::endl;
cmSystemTools::Error("error can not open ", info->m_FullPath.c_str());
return;
}
char line[255];
@ -142,8 +133,8 @@ void cmMakeDepend::Depend(cmDependInformation* info)
// if a < is not found then move on
if(qstart == std::string::npos)
{
std::cerr << "unknown include directive " << currentline
<< std::endl;
cmSystemTools::Error("unknown include directive ",
currentline.c_str() );
continue;
}
else
@ -162,7 +153,11 @@ void cmMakeDepend::Depend(cmDependInformation* info)
{
if(m_Verbose)
{
std::cerr << "skipping " << includeFile << " for file " << path << std::endl;
std::string message = "Skipping ";
message += includeFile;
message += " for file ";
message += path;
cmSystemTools::Error(message.c_str(), 0);
}
continue;
}
@ -196,7 +191,7 @@ void cmMakeDepend::Depend(cmDependInformation* info)
// object if one is not found
int cmMakeDepend::FindInformation(const char* fname)
{
int i = 0;
unsigned int i = 0;
while(i < m_DependInformation.size())
{
@ -245,6 +240,7 @@ std::string cmMakeDepend::FullPath(const char* fname)
{
return std::string(fname);
}
for(std::vector<std::string>::iterator i = m_IncludeDirectories.begin();
i != m_IncludeDirectories.end(); ++i)
{
@ -256,7 +252,7 @@ std::string cmMakeDepend::FullPath(const char* fname)
return path;
}
}
std::cerr << "Depend: File not found " << fname << std::endl;
cmSystemTools::Error("Depend: File not found ", fname);
return std::string(fname);
}
@ -274,7 +270,8 @@ void cmMakeDepend::AddFileToSearchPath(const char* file)
if(pos != std::string::npos)
{
std::string path = filepath.substr(0, pos);
if(std::find(m_IncludeDirectories.begin(), m_IncludeDirectories.end(), path)
if(std::find(m_IncludeDirectories.begin(),
m_IncludeDirectories.end(), path)
== m_IncludeDirectories.end())
{
m_IncludeDirectories.push_back(path);

View File

@ -22,8 +22,7 @@
#include "cmMakefile.h"
#include "cmClassFile.h"
#include "cmRegularExpression.h"
#include <vector>
#include <string>
#include "cmStandardIncludes.h"
// This structure stores the depend information

View File

@ -1,225 +1,359 @@
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include "cmMakefile.h"
#include "cmRuleMaker.h"
#include "cmStandardIncludes.h"
#include "cmClassFile.h"
#include "cmDirectory.h"
#include "cmSystemTools.h"
#include <fstream>
#include <iostream>
#include "cmMakefileGenerator.h"
#include "cmAbstractFilesRule.h"
#include "cmAddTargetRule.h"
#include "cmAuxSourceDirectoryRule.h"
#include "cmExecutablesRule.h"
#include "cmFindIncludeRule.h"
#include "cmFindLibraryRule.h"
#include "cmFindProgramRule.h"
#include "cmIncludeDirectoryRule.h"
#include "cmLibraryRule.h"
#include "cmLinkDirectoriesRule.h"
#include "cmLinkLibrariesRule.h"
#include "cmProjectRule.h"
#include "cmSourceFilesRule.h"
#include "cmSourceFilesRequireRule.h"
#include "cmSubdirRule.h"
#include "cmUnixDefinesRule.h"
#include "cmUnixLibrariesRule.h"
#include "cmWin32DefinesRule.h"
#include "cmWin32LibrariesRule.h"
#include "cmTestsRule.h"
// default is not to be building executables
cmMakefile::cmMakefile()
{
m_DefineFlags = " ";
m_Executables = false;
m_MakefileGenerator = 0;
this->AddDefaultRules();
}
void cmMakefile::AddDefaultRules()
{
this->AddRuleMaker(new cmAbstractFilesRule);
this->AddRuleMaker(new cmAddTargetRule);
this->AddRuleMaker(new cmAuxSourceDirectoryRule);
this->AddRuleMaker(new cmExecutablesRule);
this->AddRuleMaker(new cmFindIncludeRule);
this->AddRuleMaker(new cmFindLibraryRule);
this->AddRuleMaker(new cmFindProgramRule);
this->AddRuleMaker(new cmIncludeDirectoryRule);
this->AddRuleMaker(new cmLibraryRule);
this->AddRuleMaker(new cmLinkDirectoriesRule);
this->AddRuleMaker(new cmLinkLibrariesRule);
this->AddRuleMaker(new cmProjectRule);
this->AddRuleMaker(new cmSourceFilesRule);
this->AddRuleMaker(new cmSourceFilesRequireRule);
this->AddRuleMaker(new cmSubdirRule);
this->AddRuleMaker(new cmUnixLibrariesRule);
this->AddRuleMaker(new cmUnixDefinesRule);
this->AddRuleMaker(new cmWin32LibrariesRule);
this->AddRuleMaker(new cmWin32DefinesRule);
this->AddRuleMaker(new cmTestsRule);
#ifdef _WIN32
this->AddDefinition("WIN32", "1");
#else
this->AddDefinition("UNIX", "1");
#endif
// Cygwin is more like unix so enable the unix rules
#if defined(__CYGWIN__)
this->AddDefinition("UNIX", "1");
#endif
}
cmMakefile::~cmMakefile()
{
for(int i=0; i < m_UsedRuleMakers.size(); i++)
{
delete m_UsedRuleMakers[i];
}
for(StringRuleMakerMap::iterator j = m_RuleMakers.begin();
j != m_RuleMakers.end(); ++j)
{
delete (*j).second;
}
delete m_MakefileGenerator;
}
void cmMakefile::PrintStringVector(const char* s, std::vector<std::string>& v)
{
std::cout << s << ": ( \n";
for(std::vector<std::string>::iterator i = v.begin();
i != v.end(); ++i)
{
std::cout << (*i).c_str() << " ";
}
std::cout << " )\n";
}
// call print on all the classes in the makefile
void cmMakefile::Print()
{
for(int i = 0; i < m_Classes.size(); i++)
std::cout << "classes:\n";
for(unsigned int i = 0; i < m_Classes.size(); i++)
m_Classes[i].Print();
std::cout << " m_OutputDirectory; " <<
m_OutputDirectory.c_str() << std::endl;
std::cout << " m_OutputHomeDirectory; " <<
m_OutputHomeDirectory.c_str() << std::endl;
std::cout << " m_cmHomeDirectory; " <<
m_cmHomeDirectory.c_str() << std::endl;
std::cout << " m_cmCurrentDirectory; " <<
m_cmCurrentDirectory.c_str() << std::endl;
std::cout << " m_LibraryName; " << m_LibraryName.c_str() << std::endl;
std::cout << " m_ProjectName; " << m_ProjectName.c_str() << std::endl;
this->PrintStringVector("m_SubDirectories ", m_SubDirectories);
this->PrintStringVector("m_MakeVerbatim ", m_MakeVerbatim);
this->PrintStringVector("m_IncludeDirectories;", m_IncludeDirectories);
this->PrintStringVector("m_LinkDirectories", m_LinkDirectories);
this->PrintStringVector("m_LinkLibraries", m_LinkLibraries);
this->PrintStringVector("m_LinkLibrariesWin32", m_LinkLibrariesWin32);
this->PrintStringVector("m_LinkLibrariesUnix", m_LinkLibrariesUnix);
}
// Parse the given CMakeLists.txt file into a list of classes.
bool cmMakefile::ReadMakefile(const char* filename)
bool cmMakefile::ReadMakefile(const char* filename, bool inheriting)
{
m_BuildFlags.SetSourceHomeDirectory(this->GetHomeDirectory());
m_BuildFlags.SetStartDirectory(this->GetCurrentDirectory());
m_BuildFlags.ParseDirectories();
m_BuildFlags.ExpandVaribles(this);
// If not being called from ParseDirectory which
// sets the inheriting flag, then parse up the
// tree and collect inherited parameters
if(!inheriting)
{
cmSystemTools::ConvertToUnixSlashes(m_cmCurrentDirectory);
m_SourceHomeDirectory = m_cmHomeDirectory;
cmSystemTools::ConvertToUnixSlashes(m_SourceHomeDirectory);
this->ParseDirectory(m_cmCurrentDirectory.c_str());
}
// Now read the input file
std::ifstream fin(filename);
if(!fin)
{
std::cerr << "error can not open file " << filename << std::endl;
cmSystemTools::Error("error can not open file ", filename);
return false;
}
char inbuffer[2048];
while ( fin.getline(inbuffer, 2047 ) )
std::string name;
std::vector<std::string> arguments;
while ( fin )
{
std::string line = inbuffer;
cmClassFile file;
std::string::size_type pos = line.find("SOURCE_FILES");
if((pos != std::string::npos) && (pos == 0 ) )
if(cmSystemTools::ParseFunction(fin, name, arguments) )
{
if(line.find("\\") != std::string::npos)
{
this->ReadClasses(fin, false);
}
}
#ifdef _WIN32
else if(line.find("WIN32_SOURCE_FILES") != std::string::npos)
{
if(line.find("\\") != std::string::npos)
{
this->ReadClasses(fin, false);
}
}
#else
else if(line.find("UNIX_SOURCE_FILES") != std::string::npos)
{
if(line.find("\\") != std::string::npos)
{
this->ReadClasses(fin, false);
}
}
#endif
else if(line.find("ABSTRACT_CLASSES") != std::string::npos)
{
if(line.find("\\") != std::string::npos)
{
this->ReadClasses(fin, true);
}
}
else if(line.find("AUX_SOURCE_DIRECTORY") != std::string::npos)
{
this->ReadTemplateInstanceDirectory(line);
}
else if(line.find("SUBDIRS") != std::string::npos)
{
if(line.find("\\") != std::string::npos)
{
cmSystemTools::ReadList(m_SubDirectories, fin);
}
}
else if(line.find("EXECUTABLES") != std::string::npos || line.find("TESTS") != std::string::npos )
{
if(line.find("\\") != std::string::npos)
{
this->ReadClasses(fin, false);
m_Executables = true;
}
}
else if(line.find("BEGIN MAKE VERBATIM") != std::string::npos)
{
char inbuffer[2048];
bool done = false;
m_MakeVerbatim.push_back("# Begin CMakeLists Verbatim\n");
while(!done)
// Special rule that needs to be removed when
// ADD_RULE is implemented
if(name == "VERBATIM")
{
fin.getline(inbuffer, 2047);
m_MakeVerbatim.push_back(inbuffer);
if((m_MakeVerbatim.end()-1)->find("END MAKE VERBATIM")
!= std::string::npos )
if(!inheriting)
{
done = true;
*(m_MakeVerbatim.end()-1) = "# End CMakeLists VERBATIM\n\n";
m_MakeVerbatim = arguments;
}
}
else
{
StringRuleMakerMap::iterator pos = m_RuleMakers.find(name);
if(pos != m_RuleMakers.end())
{
cmRuleMaker* rm = (*pos).second;
cmRuleMaker* usedMaker = rm->Clone();
usedMaker->SetMakefile(this);
usedMaker->LoadCache();
m_UsedRuleMakers.push_back(usedMaker);
if(usedMaker->GetEnabled())
{
// if not running in inherit mode or
// if the rule is inherited then Invoke it.
if(!inheriting || usedMaker->IsInherited())
{
if(!usedMaker->Invoke(arguments))
{
cmSystemTools::Error(usedMaker->GetError());
}
}
}
}
else
{
cmSystemTools::Error("unknown CMake function", name.c_str());
}
}
}
else if(line.find("LIBRARY") != std::string::npos)
{
std::string libname = cmSystemTools::ExtractVariable("LIBRARY",
line.c_str());
this->SetLibraryName(libname.c_str());
}
else if(line.find("PROJECT") != std::string::npos)
{
std::string libname = cmSystemTools::ExtractVariable("PROJECT",
line.c_str());
this->SetProjectName(libname.c_str());
}
}
return true;
}
// Read a list from the Makefile stream
void cmMakefile::ReadClasses(std::ifstream& fin,
bool abstract)
void cmMakefile::AddRuleMaker(cmRuleMaker* wg)
{
char inbuffer[2048];
bool done = false;
while (!done)
{
// read a line from the makefile
fin.getline(inbuffer, 2047);
// convert to a string class
std::string classname = inbuffer;
// if the line does not end in \ then we are at the
// end of the list
if(classname.find('\\') == std::string::npos)
{
done = true;
}
// remove extra spaces and \ from the class name
classname = cmSystemTools::CleanUpName(classname.c_str());
// if this is not an abstract list then add new class
// to the list of classes in this makefile
if(!abstract)
{
cmClassFile file;
file.SetName(classname.c_str(), this->GetCurrentDirectory());
file.m_AbstractClass = false;
m_Classes.push_back(file);
}
else
{
// if this is an abstract list, then look
// for an existing class and set it to abstract
for(int i = 0; i < m_Classes.size(); i++)
{
if(m_Classes[i].m_ClassName == classname)
{
m_Classes[i].m_AbstractClass = true;
break;
}
}
}
}
std::string name = wg->GetName();
m_RuleMakers.insert( StringRuleMakerMap::value_type(name, wg));
}
// Find all of the files in dir as specified from this line:
// AUX_SOURCE_DIRECTORY = dir
// Add all the files to the m_Classes array.
void cmMakefile::ReadTemplateInstanceDirectory(std::string& line)
// Set the make file
void cmMakefile::SetMakefileGenerator(cmMakefileGenerator* mf)
{
std::string::size_type start = line.find("=");
if(start != std::string::npos)
delete m_MakefileGenerator;
m_MakefileGenerator = mf;
}
// Generate the output file
void cmMakefile::GenerateMakefile()
{
// do all the variable expansions here
this->ExpandVaribles();
// set the makefile on the generator
m_MakefileGenerator->SetMakefile(this);
// give all the rules a chance to do something
// after the file has been parsed before generation
for(std::vector<cmRuleMaker*>::iterator i = m_UsedRuleMakers.begin();
i != m_UsedRuleMakers.end(); ++i)
{
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 += templateDirectory;
// Load all the files in the directory
cmDirectory dir;
if(dir.Load(tdir.c_str()))
{
int numfiles = dir.GetNumberOfFiles();
for(int i =0; i < numfiles; ++i)
{
std::string file = dir.GetFile(i);
// ignore files less than f.cxx in length
if(file.size() > 4)
{
// Remove the extension
std::string::size_type dotpos = file.rfind(".");
file = file.substr(0, dotpos);
std::string fullname = templateDirectory;
fullname += "/";
fullname += file;
// add the file as a class file so
// depends can be done
cmClassFile cmfile;
cmfile.SetName(fullname.c_str(), this->GetCurrentDirectory());
cmfile.m_AbstractClass = false;
m_Classes.push_back(cmfile);
}
}
}
else
{
std::cerr << "Warning can not open template instance directory "
<< templateDirectory.c_str() << std::endl;
}
(*i)->FinalPass();
}
// now do the generation
m_MakefileGenerator->GenerateMakefile();
}
void cmMakefile::AddClass(cmClassFile& cmfile)
{
m_Classes.push_back(cmfile);
}
void cmMakefile::AddCustomRule(const char* source,
const char* result,
const char* command,
std::vector<std::string>& depends)
{
cmMakefile::customRule rule;
rule.m_Source = source;
rule.m_Result = result;
rule.m_Command = command;
rule.m_Depends = depends;
m_CustomRules.push_back(rule);
}
void cmMakefile::AddDefineFlag(const char* flag)
{
m_DefineFlags += " ";
m_DefineFlags += flag;
}
void cmMakefile::AddExecutable(cmClassFile& cf)
{
m_Classes.push_back(cf);
m_Executables = true;
}
void cmMakefile::AddLinkLibrary(const char* lib)
{
m_LinkLibraries.push_back(lib);
}
void cmMakefile::AddLinkDirectory(const char* dir)
{
m_LinkDirectories.push_back(dir);
}
void cmMakefile::AddSubDirectory(const char* sub)
{
m_SubDirectories.push_back(sub);
}
void cmMakefile::AddIncludeDirectory(const char* inc)
{
m_IncludeDirectories.push_back(inc);
}
void cmMakefile::AddDefinition(const char* name, const char* value)
{
m_Definitions.insert(DefinitionMap::value_type(name, value));
}
void cmMakefile::SetProjectName(const char* p)
{
m_ProjectName = p;
}
void cmMakefile::SetLibraryName(const char* l)
{
m_LibraryName = l;
}
void cmMakefile::AddExtraDirectory(const char* dir)
{
m_AuxSourceDirectories.push_back(dir);
}
// Go until directory == m_cmHomeDirectory
// 1. fix slashes
// 2. peal off /dir until home found, go no higher
void cmMakefile::ParseDirectory(const char* dir)
{
std::string listsFile = dir;
listsFile += "/CMakeLists.txt";
if(cmSystemTools::FileExists(listsFile.c_str()))
{
this->ReadMakefile(listsFile.c_str(), true);
}
if(m_SourceHomeDirectory == dir)
{
return;
}
std::string dotdotDir = dir;
std::string::size_type pos = dotdotDir.rfind('/');
if(pos != std::string::npos)
{
dotdotDir = dotdotDir.substr(0, pos);
this->ParseDirectory(dotdotDir.c_str());
}
}
// expance CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR in the
// include and library directories.
void cmMakefile::ExpandVaribles()
{
// Now replace varibles
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}",
this->GetOutputHomeDirectory() );
cmSystemTools::ReplaceString(*j, "${CMAKE_SOURCE_DIR}",
this->GetHomeDirectory() );
}
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() );
}
}
const char* cmMakefile::GetDefinition(const char* name)
{
DefinitionMap::iterator pos = m_Definitions.find(name);
if(pos != m_Definitions.end())
{
return (*pos).second.c_str();
}
return 0;
}

View File

@ -19,28 +19,52 @@
*/
#ifndef cmMakefile_h
#define cmMakefile_h
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include "cmStandardIncludes.h"
#include "cmClassFile.h"
#include "cmCollectFlags.h"
#include <vector>
#include <fstream>
#include <iostream>
#include "cmSystemTools.h"
class cmRuleMaker;
class cmMakefileGenerator;
class cmMakefile
{
public:
cmMakefile();
// Parse a Makfile.in file
bool ReadMakefile(const char* makefile);
~cmMakefile();
// Parse a CMakeLists.txt file
bool ReadMakefile(const char* makefile, bool inheriting = false);
// Add a wrap generator
void AddRuleMaker(cmRuleMaker* );
// Set the make file
void SetMakefileGenerator(cmMakefileGenerator*);
// Generate the output file
void GenerateMakefile();
// Print useful stuff to stdout
void Print();
// cmRuleMaker interfaces
void AddCustomRule(const char* source,
const char* result,
const char* command,
std::vector<std::string>& depends);
void AddDefineFlag(const char* definition);
void AddExecutable(cmClassFile&);
void AddLinkLibrary(const char*);
void AddLinkDirectory(const char*);
void AddSubDirectory(const char*);
void AddIncludeDirectory(const char*);
void AddDefinition(const char* name, const char* value);
void SetProjectName(const char*);
void SetLibraryName(const char*);
void AddClass(cmClassFile& );
void AddExtraDirectory(const char* dir);
// Set the home directory for the project
void SetHomeDirectory(const char* dir)
{
m_cmHomeDirectory = dir;
cmSystemTools::ConvertToUnixSlashes(m_cmHomeDirectory);
}
const char* GetHomeDirectory()
{
@ -56,19 +80,11 @@ public:
return m_cmCurrentDirectory.c_str();
}
// Set the name of the library that is built by this makefile
void SetLibraryName(const char* lib)
{
m_LibraryName = lib;
}
const char* GetLibraryName()
{
return m_LibraryName.c_str();
}
// Set the name of the library that is built by this makefile
void SetProjectName(const char* lib)
{
m_ProjectName = lib;
}
const char* GetProjectName()
{
return m_ProjectName.c_str();
@ -93,10 +109,6 @@ public:
{
return m_OutputHomeDirectory.c_str();
}
cmCollectFlags& GetBuildFlags()
{
return m_BuildFlags;
}
const std::vector<std::string>& GetSubDirectories()
{
return m_SubDirectories;
@ -107,15 +119,60 @@ public:
return m_Executables;
}
std::vector<std::string>& GetIncludeDirectories()
{
return m_IncludeDirectories;
}
std::vector<std::string>& GetLinkDirectories()
{
return m_LinkDirectories;
}
std::vector<std::string>& GetLinkLibraries()
{
return m_LinkLibraries;
}
std::vector<std::string>& GetLinkLibrariesWin32()
{
return m_LinkLibrariesWin32;
}
std::vector<std::string>& GetLinkLibrariesUnix()
{
return m_LinkLibrariesUnix;
}
std::vector<cmClassFile>& GetClasses(){ return m_Classes;}
std::vector<std::string>& GetAuxSourceDirectories()
{ return m_AuxSourceDirectories; }
std::vector<std::string>& GetMakeVerbatim()
{ return m_MakeVerbatim;}
const char* GetDefinition(const char*);
const char* GetDefineFlags()
{ return m_DefineFlags.c_str();}
private:
void ReadTemplateInstanceDirectory(std::string&);
/**
* Look for CMakeLists.txt files to parse in dir,
* then in dir's parents, until the SourceHome directory
* is found.
*/
void ParseDirectory(const char* dir);
/**
* Parse a file for includes links and libs
*/
void ExpandVaribles();
void ReadClasses(std::ifstream& fin, bool t);
friend class cmMakeDepend; // make depend needs direct access
// to the m_Classes array
// to the m_Classes array
void PrintStringVector(const char* s, std::vector<std::string>& v);
void AddDefaultRules();
protected:
bool m_Executables;
std::string m_Prefix;
std::vector<std::string> m_TemplateDirectories; // Template directory name if found in file
std::vector<std::string> m_AuxSourceDirectories; //
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
@ -125,7 +182,27 @@ protected:
std::vector<cmClassFile> m_Classes; // list of classes in makefile
std::vector<std::string> m_SubDirectories; // list of sub directories
std::vector<std::string> m_MakeVerbatim; // lines copied from input file
cmCollectFlags m_BuildFlags;
std::vector<std::string> m_IncludeDirectories;
std::vector<std::string> m_LinkDirectories;
std::vector<std::string> m_LinkLibraries;
std::vector<std::string> m_LinkLibrariesWin32;
std::vector<std::string> m_LinkLibrariesUnix;
std::string m_DefineFlags;
std::string m_SourceHomeDirectory;
struct customRule
{
std::string m_Source;
std::string m_Result;
std::string m_Command;
std::vector<std::string> m_Depends;
};
std::vector<customRule> m_CustomRules;
typedef std::map<std::string, cmRuleMaker*> StringRuleMakerMap;
typedef std::map<std::string, std::string> DefinitionMap;
DefinitionMap m_Definitions;
StringRuleMakerMap m_RuleMakers;
std::vector<cmRuleMaker*> m_UsedRuleMakers;
cmMakefileGenerator* m_MakefileGenerator;
};

View File

@ -0,0 +1,7 @@
#include "cmMakeFileGenerator.h"
void cmMakefileGenerator::SetMakefile(cmMakefile* mf)
{
m_Makefile = mf;
}

View File

@ -0,0 +1,20 @@
#ifndef cmMakeFileGenerator_h
#define cmMakeFileGenerator_h
#include "cmStandardIncludes.h"
class cmMakefile;
struct cmClassFile;
class cmMakefileGenerator
{
public:
// use the m_Makefile and the m_CustomRules and m_ExtraSourceFiles
// to generate the makefile
virtual void GenerateMakefile() = 0;
void SetMakefile(cmMakefile*);
protected:
cmMakefile* m_Makefile;
};
#endif

14
Source/cmProjectRule.cxx Normal file
View File

@ -0,0 +1,14 @@
#include "cmProjectRule.h"
// cmProjectRule
bool cmProjectRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 || args.size() > 1)
{
this->SetError("PROJECT called with incorrect number of arguments");
return false;
}
m_Makefile->SetProjectName(args[0].c_str());
return true;
}

38
Source/cmProjectRule.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef cmProjectRule_h
#define cmProjectRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmProjectRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmProjectRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
// This is the name used in the input file.
virtual const char* GetName() { return "PROJECT";}
virtual const char* TerseDocumentaion()
{
return "Set a name for the entire project. One argument.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"Set the name for the entire project. This takes one argument.\n"
"PROJECT(projectname);";
}
};
#endif

View File

@ -115,8 +115,9 @@
//
#include "cmRegularExpression.h" // Include class specification
#include "cmStandardIncludes.h"
#include <stdio.h>
#include <string>
// cmRegularExpression -- Copies the given regular expression.

View File

@ -32,7 +32,7 @@
#ifndef cmRegularExpression_h
#define cmRegularExpression_h
#include <string>
#include "cmStandardIncludes.h"
const int NSUBEXP = 10;

52
Source/cmRuleMaker.h Normal file
View File

@ -0,0 +1,52 @@
#ifndef cmRuleMaker_h
#define cmRuleMaker_h
#include "cmStandardIncludes.h"
#include "cmMakefile.h"
class cmRuleMaker
{
public:
cmRuleMaker() { m_Makefile = 0; m_Enabled = true; }
void SetMakefile(cmMakefile*m) {m_Makefile = m; }
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args) = 0;
// This is called after the entire file has been parsed.
virtual void FinalPass() = 0;
// This is called to let the rule check the cache
virtual void LoadCache() { }
virtual cmRuleMaker* Clone() = 0;
// This determines if the rule gets passed down
// to sub directory makefiles
virtual bool IsInherited()
{
return false;
}
// This is the name used in the input file.
virtual const char* GetName() = 0;
// Return the terse documentaion for the rule
virtual const char* TerseDocumentaion() = 0;
// Return full documentation for the rule
virtual const char* FullDocumentaion() = 0;
// enable or disable this rule
bool GetEnabled() { return m_Enabled; }
void SetEnableOn() { m_Enabled = true; }
void SetEnableOff() { m_Enabled = false; }
const char* GetError() { return m_Error.c_str();}
protected:
void SetError(const char* e)
{
m_Error = this->GetName();
m_Error += " ";
m_Error += e;
}
cmMakefile* m_Makefile;
private:
bool m_Enabled;
std::string m_Error;
};
#endif

View File

@ -0,0 +1,39 @@
#include "cmSourceFilesRequireRule.h"
// cmSourceFilesRequireRule
bool cmSourceFilesRequireRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 3 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
std::vector<std::string>::iterator i = args.begin();
// Search to the key word SOURCES_BEGIN is found
// if one of the required defines is not there, then
// return as none of the source files will be added
// if the required definition is not there.
while(i != args.end() && (*i) != "SOURCES_BEGIN" )
{
if(!m_Makefile->GetDefinition((*i).c_str()))
{
return true;
}
i++;
}
if(i != args.end())
{
i++;
}
// Add the rest of the arguments as source files
for(; i != args.end(); ++i)
{
cmClassFile file;
file.m_AbstractClass = false;
file.SetName((*i).c_str(), m_Makefile->GetCurrentDirectory());
m_Makefile->AddClass(file);
}
return true;
}

View File

@ -0,0 +1,37 @@
#ifndef cmSourceFilesRequireRule_h
#define cmSourceFilesRequireRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmSourceFilesRequireRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmSourceFilesRequireRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
// This is the name used in the input file.
virtual const char* GetName() { return "SOURCE_FILES_REQUIRE";}
virtual const char* TerseDocumentaion()
{
return "Add a list of source files.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"SOURCE_FILES(file1 file2 ...)";
}
};
#endif

View File

@ -0,0 +1,21 @@
#include "cmSourceFilesRule.h"
// cmSourceFilesRule
bool cmSourceFilesRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
cmClassFile file;
file.m_AbstractClass = false;
file.SetName((*i).c_str(), m_Makefile->GetCurrentDirectory());
m_Makefile->AddClass(file);
}
return true;
}

View File

@ -0,0 +1,37 @@
#ifndef cmSourceFilesRule_h
#define cmSourceFilesRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmSourceFilesRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmSourceFilesRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
// This is the name used in the input file.
virtual const char* GetName() { return "SOURCE_FILES";}
virtual const char* TerseDocumentaion()
{
return "Add a list of source files.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"SOURCE_FILES(file1 file2 ...)";
}
};
#endif

View File

@ -0,0 +1,29 @@
#ifndef cmStandardIncludes_h
#define cmStandardIncludes_h
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#ifndef CMAKE_NO_ANSI_STREAM_HEADERS
#include <fstream>
#include <iostream>
#else
#include <fsream.h>
#include <iostream.h>
#endif
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
#include <functional>
#include <map>
#ifdef CMAKE_NO_STD_NAMESPACE
#define std
#endif
#endif

18
Source/cmSubdirRule.cxx Normal file
View File

@ -0,0 +1,18 @@
#include "cmSubdirRule.h"
// cmSubdirRule
bool cmSubdirRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
m_Makefile->AddSubDirectory((*i).c_str());
}
return true;
}

40
Source/cmSubdirRule.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef cmSubdirRule_h
#define cmSubdirRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmSubdirRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmSubdirRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
// This is the name used in the input file.
virtual const char* GetName() { return "SUBDIRS";}
virtual const char* TerseDocumentaion()
{
return "Add a list of subdirectories to the build.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"Add a list of subdirectories to the build.\n"
"SUBDIRS(dir1 dir2 ...)\n"
"This will cause any CMakeLists.txt files in the sub directories\n"
"to be parsed by cmake.";
}
};
#endif

View File

@ -3,7 +3,7 @@
#include <sys/stat.h>
#include "cmRegularExpression.h"
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__BORLANDC__)
#include <windows.h>
#include <direct.h>
inline int Mkdir(const char* dir)
@ -20,39 +20,6 @@ inline int Mkdir(const char* dir)
}
#endif
// remove extra spaces and the "\" character from the name
// of the class as it is in the CMakeLists.txt
std::string cmSystemTools::CleanUpName(const char* name)
{
std::string className = name;
size_t i =0;
while(className[i] == ' ' || className[i] == '\t')
{
i++;
}
if(i)
{
className = className.substr(i, className.size());
}
size_t pos = className.find('\\');
if(pos != std::string::npos)
{
className = className.substr(0, pos);
}
pos = className.find(' ');
if(pos != std::string::npos)
{
className = className.substr(0, pos);
}
pos = className.find('\t');
if(pos != std::string::npos)
{
className = className.substr(0, pos);
}
return className;
}
bool cmSystemTools::MakeDirectory(const char* path)
{
@ -121,29 +88,6 @@ bool cmSystemTools::FileExists(const char* filename)
}
}
// Read a list from a CMakeLists.txt file open stream.
// assume the stream has just read "VAR = \"
// read until there is not a "\" at the end of the line.
void cmSystemTools::ReadList(std::vector<std::string>& stringList,
std::ifstream& fin)
{
char inbuffer[2048];
bool done = false;
while ( !done )
{
fin.getline(inbuffer, sizeof(inbuffer) );
std::string inname = inbuffer;
if(inname.find('\\') == std::string::npos)
{
done = true;
}
if(inname.size())
{
stringList.push_back(cmSystemTools::CleanUpName(inname.c_str()));
}
}
}
// convert windows slashes to unix slashes \ with /
void cmSystemTools::ConvertToUnixSlashes(std::string& path)
@ -179,26 +123,167 @@ int cmSystemTools::Grep(const char* dir, const char* file, const char* expressio
return count;
}
std::string cmSystemTools::ExtractVariable(const char* variable,
const char* l)
void cmSystemTools::ConvertCygwinPath(std::string& pathname)
{
std::string line = l;
size_t varstart = line.find(variable);
size_t start = line.find("=");
if(start != std::string::npos && start > varstart )
if(pathname.find("/cygdrive/") != std::string::npos)
{
start++;
while(line[start] == ' ' && start < line.size())
{
start++;
}
size_t end = line.size()-1;
while(line[end] == ' ' && end > start)
{
end--;
}
return line.substr(start, end).c_str();
std::string cygStuff = pathname.substr(0, 11);
std::string replace;
replace += cygStuff.at(10);
replace += ":";
cmSystemTools::ReplaceString(pathname, cygStuff.c_str(), replace.c_str());
}
return std::string("");
}
bool cmSystemTools::ParseFunction(std::ifstream& fin,
std::string& name,
std::vector<std::string>& arguments)
{
name = "";
arguments = std::vector<std::string>();
const int BUFFER_SIZE = 4096;
char inbuffer[BUFFER_SIZE];
if(!fin)
{
return false;
}
if(fin.getline(inbuffer, BUFFER_SIZE ) )
{
cmRegularExpression blankLine("^$");
cmRegularExpression comment("^#.*");
cmRegularExpression oneLiner("[ \t]*([A-Za-z_0-9]*).*\\((.*)\\)");
cmRegularExpression multiLine("[ \t]*([A-Za-z_0-9]*).*\\((.*)");
cmRegularExpression lastLine("(.*)\\)");
// BEGIN VERBATIM JUNK SHOULD BE REMOVED
cmRegularExpression verbatim("BEGIN MAKE VERBATIM");
if(verbatim.find(inbuffer))
{
cmRegularExpression endVerbatim("END MAKE VERBATIM");
name = "VERBATIM";
bool done = false;
while(!done)
{
if(fin.getline(inbuffer, BUFFER_SIZE))
{
if(endVerbatim.find(inbuffer))
{
done = true;
}
else
{
arguments.push_back(inbuffer);
}
}
else
{
done = true;
}
}
return true;
}
// END VERBATIM JUNK SHOULD BE REMOVED
// check for black line or comment
if(blankLine.find(inbuffer) || comment.find(inbuffer))
{
return false;
}
// look for a oneline fun(arg arg2)
else if(oneLiner.find(inbuffer))
{
// the arguments are the second match
std::string args = oneLiner.match(2);
name = oneLiner.match(1);
// break up the arguments
cmSystemTools::GetArguments(args, arguments);
return true;
}
// look for a start of a multiline with no trailing ")" fun(arg arg2
else if(multiLine.find(inbuffer))
{
name = multiLine.match(1);
std::string args = multiLine.match(2);
cmSystemTools::GetArguments(args, arguments);
// Read lines until the closing paren is hit
bool done = false;
while(!done)
{
// read lines until the end paren is found
if(fin.getline(inbuffer, BUFFER_SIZE ) )
{
if(lastLine.find(inbuffer))
{
done = true;
std::string args = lastLine.match(1);
cmSystemTools::GetArguments(args, arguments);
}
else
{
std::string line = inbuffer;
cmSystemTools::GetArguments(line, arguments);
}
}
}
return true;
}
else
{
cmSystemTools::Error("Parse error in read function ", inbuffer);
return false;
}
}
return false;
}
void cmSystemTools::GetArguments(std::string& line,
std::vector<std::string>& arguments)
{
cmRegularExpression argument("[\t ]*([-/\\\\{}\\$A-Za-z_0-9]+)[\t ]*");
cmRegularExpression argumentWithSpaces("[\t ]*\"([- /\\\\{}\\$A-Za-z_0-9]+)\"[\t ]*");
std::string arg(" ");
while(arg.length() )
{
arg = "";
long endpos;
if (argumentWithSpaces.find(line.c_str()))
{
arg = argumentWithSpaces.match(1);
endpos = argumentWithSpaces.end(1);
}
else if(argument.find(line.c_str()))
{
arg = argument.match(1);
endpos = argument.end(1);
}
if(arg.length())
{
arguments.push_back(arg);
line = line.substr(endpos, line.length() - endpos);
}
}
}
void cmSystemTools::Error(const char* m1, const char* m2)
{
std::string message = "CMake Error: ";
if(m1)
{
message += m1;
}
if(m2)
{
message += m2;
}
#ifdef _WIN32
// MessageBox(0, message.c_str(), 0, MB_OK);
std::cerr << message.c_str() << std::endl;
#else
std::cerr << message.c_str() << std::endl;
#endif
}

View File

@ -18,13 +18,8 @@
*/
#ifndef cmSystemTools_h
#define cmSystemTools_h
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include <string>
#include <vector>
#include <fstream>
#include "cmStandardIncludes.h"
class cmSystemTools
{
@ -42,10 +37,6 @@ public:
static void ReplaceString(std::string& source,
const char* replace,
const char* with);
/**
* Remove extra spaces and the trailing \ from a string.
*/
static std::string CleanUpName(const char* name);
/**
* Replace windows slashes with unix style slashes
*/
@ -61,20 +52,30 @@ public:
static int Grep(const char* dir, const char* file, const char* expression);
/**
* Extract the right hand side of an asignment varibale = value
* remove /cygdrive/d and replace with d:/
*/
static std::string ExtractVariable(const char* varible,
const char* line);
static void ConvertCygwinPath(std::string& pathname);
/**
* Read a list from a file into the array of strings.
* This function assumes that the first line of the
* list has been read. For example: NAME = \ was already
* read in. The reading stops when there are no more
* continuation characters.
* Read a cmake function from an input file. This
* returns the name of the function and a list of its
* arguments.
*/
static void ReadList(std::vector<std::string>& stringList,
std::ifstream& fin);
static bool ParseFunction(std::ifstream&,
std::string& name,
std::vector<std::string>& arguments);
/**
* Extract space separated arguments from a string.
* Double quoted strings are accepted with spaces.
* This is called by ParseFunction.
*/
static void GetArguments(std::string& line,
std::vector<std::string>& arguments);
/**
* Display an error message.
*/
static void Error(const char* m, const char* m2=0 );
};

20
Source/cmTestsRule.cxx Normal file
View File

@ -0,0 +1,20 @@
#include "cmTestsRule.h"
// cmExecutableRule
bool cmTestsRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
cmClassFile file;
file.SetName((*i).c_str(), m_Makefile->GetCurrentDirectory());
m_Makefile->AddExecutable(file);
}
return true;
}

37
Source/cmTestsRule.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef cmTestsRule_h
#define cmTestsRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmTestsRule : public cmRuleMaker
{
public:
virtual cmRuleMaker* Clone()
{
return new cmTestsRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
// This is the name used in the input file.
virtual const char* GetName() { return "TESTS";}
virtual const char* TerseDocumentaion()
{
return "Add a list of executables files that are run as tests.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"TESTS(file1 file2 ...)";
}
};
#endif

View File

@ -0,0 +1,25 @@
#include "cmUnixDefinesRule.h"
cmUnixDefinesRule::cmUnixDefinesRule()
{
#if defined(_WIN32) && !defined(__CYGWIN__)
this->SetEnableOff();
#endif
}
// cmUNIXDefinesRule
bool cmUnixDefinesRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("Win32Defines called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
m_Makefile->AddDefineFlag((*i).c_str());
}
return true;
}

View File

@ -0,0 +1,40 @@
#ifndef cmUnixDefinesRule_h
#define cmUnixDefinesRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmUnixDefinesRule : public cmRuleMaker
{
public:
cmUnixDefinesRule();
virtual cmRuleMaker* Clone()
{
return new cmUnixDefinesRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
virtual bool IsInherited() { return true; }
// This is the name used in the input file.
virtual const char* GetName() { return "UNIX_DEFINES";}
virtual const char* TerseDocumentaion()
{
return "Add -D flags to the command line for unix only.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"Add -D flags to the command line for unix only.\n"
"UNIX_DEFINES(-DFOO -DBAR);";
}
};
#endif

View File

@ -0,0 +1,25 @@
#include "cmUnixLibrariesRule.h"
cmUnixLibrariesRule::cmUnixLibrariesRule()
{
#if defined(_WIN32) && !defined(__CYGWIN__)
this->SetEnableOff();
#endif
}
// cmUnixLibrariesRule
bool cmUnixLibrariesRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
m_Makefile->AddLinkLibrary((*i).c_str());
}
return true;
}

View File

@ -0,0 +1,39 @@
#ifndef cmUnixLibrariesRule_h
#define cmUnixLibrariesRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmUnixLibrariesRule : public cmRuleMaker
{
public:
cmUnixLibrariesRule();
virtual cmRuleMaker* Clone()
{
return new cmUnixLibrariesRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
virtual bool IsInherited() { return true; }
// This is the name used in the input file.
virtual const char* GetName() { return "UNIX_LIBRARIES";}
virtual const char* TerseDocumentaion()
{
return "Add libraries that are only used for unix programs.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"UNIX_LIBRARIES(library -lm ...);";
}
};
#endif

View File

@ -1,25 +1,37 @@
#include "cmUnixMakefile.h"
#include "cmUnixMakefileGenerator.h"
#include "cmMakefile.h"
#include "cmStandardIncludes.h"
#include "cmSystemTools.h"
#include <fstream>
#include <iostream>
#include "cmClassFile.h"
#include "cmMakeDepend.h"
void cmUnixMakefileGenerator::GenerateMakefile()
{
cmMakeDepend md;
md.SetMakefile(m_Makefile);
md.DoDepends();
this->OutputMakefile("CMakeTargets.make");
}
// Output the depend information for all the classes
// in the makefile. These would have been generated
// by the class cmMakeDepend in the main of CMakeBuildTargets.
void cmUnixMakefile::OutputDepends(std::ostream& fout)
// by the class cmMakeDepend GenerateMakefile
void cmUnixMakefileGenerator::OutputDepends(std::ostream& fout)
{
for(int i = 0; i < m_Classes.size(); i++)
std::vector<cmClassFile>& Classes = m_Makefile->GetClasses();
for(unsigned int i = 0; i < Classes.size(); i++)
{
if(!m_Classes[i].m_AbstractClass && !m_Classes[i].m_HeaderFileOnly)
if(!Classes[i].m_AbstractClass && !Classes[i].m_HeaderFileOnly)
{
if( m_Classes[i].m_Depends.size())
if( Classes[i].m_Depends.size())
{
fout << m_Classes[i].m_ClassName << ".o : \\\n";
fout << Classes[i].m_ClassName << ".o : \\\n";
for(std::vector<std::string>::iterator j =
m_Classes[i].m_Depends.begin();
j != m_Classes[i].m_Depends.end(); ++j)
Classes[i].m_Depends.begin();
j != Classes[i].m_Depends.end(); ++j)
{
if(j+1 == m_Classes[i].m_Depends.end())
if(j+1 == Classes[i].m_Depends.end())
{
fout << *j << " \n";
}
@ -63,15 +75,16 @@ inline std::string FixDirectoryName(const char* dir)
// 4. Rules to build in sub directories
// 5. The name of the library being built, if it is a library
void cmUnixMakefile::OutputMakefile(const char* file)
void cmUnixMakefileGenerator::OutputMakefile(const char* file)
{
if( m_TemplateDirectories.size() )
std::vector<std::string>& auxSourceDirs = m_Makefile->GetAuxSourceDirectories();
if( auxSourceDirs.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)
for(std::vector<std::string>::iterator i = auxSourceDirs.begin();
i != auxSourceDirs.end(); ++i)
{
cmSystemTools::MakeDirectory(i->c_str());
}
@ -80,12 +93,12 @@ void cmUnixMakefile::OutputMakefile(const char* file)
std::ofstream fout(file);
if(!fout)
{
std::cerr << "Error can not open " << file << " for write" << std::endl;
cmSystemTools::Error("Error can not open for write: ", file);
return;
}
// Output Include paths
fout << "INCLUDE_FLAGS = ";
std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories();
std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
std::vector<std::string>::iterator i;
for(i = includes.begin(); i != includes.end(); ++i)
{
@ -96,22 +109,23 @@ void cmUnixMakefile::OutputMakefile(const char* file)
fout << "\n";
// see if there are files to compile in this makefile
// These are used for both libraries and executables
if(m_Classes.size() )
std::vector<cmClassFile>& Classes = m_Makefile->GetClasses();
if(Classes.size() )
{
// Ouput Library name if there are SRC_OBJS
if(strlen(this->GetLibraryName()) > 0)
if(strlen(m_Makefile->GetLibraryName()) > 0)
{
fout << "LIBRARY = " << this->GetLibraryName() << "\n\n";
fout << "LIBRARY = " << m_Makefile->GetLibraryName() << "\n\n";
fout << "BUILD_LIB_FILE = lib${LIBRARY}${CMAKE_LIB_EXT}\n\n";
}
// Output SRC_OBJ list for all the classes to be compiled
fout << "SRC_OBJ = \\\n";
for(int i = 0; i < m_Classes.size(); i++)
for(unsigned int i = 0; i < Classes.size(); i++)
{
if(!m_Classes[i].m_AbstractClass && !m_Classes[i].m_HeaderFileOnly)
if(!Classes[i].m_AbstractClass && !Classes[i].m_HeaderFileOnly)
{
fout << m_Classes[i].m_ClassName << ".o ";
if(i == m_Classes.size() -1)
fout << Classes[i].m_ClassName << ".o ";
if(i == Classes.size() -1)
{
fout << "\n\n";
}
@ -123,34 +137,43 @@ void cmUnixMakefile::OutputMakefile(const char* file)
}
fout << "\n";
}
std::vector<std::string>& MakeVerbatim = m_Makefile->GetMakeVerbatim();
// Ouput user make text embeded in the input file
for(int i =0; i < m_MakeVerbatim.size(); i++)
for(unsigned int i =0; i < MakeVerbatim.size(); i++)
{
fout << m_MakeVerbatim[i] << "\n";
fout << MakeVerbatim[i] << "\n";
}
fout << "\n\n";
// Output rules for building executables
if( m_Executables )
if( m_Makefile->HasExecutables() )
{
// collect all the flags needed for linking libraries
std::string linkLibs;
std::vector<std::string>::iterator j;
std::vector<std::string>& libdirs = m_BuildFlags.GetLinkDirectories();
std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
for(j = libdirs.begin(); j != libdirs.end(); ++j)
{
linkLibs += "-L";
{
if((*j).find("-L") == std::string::npos
&& (*j).find("${") == std::string::npos)
{
linkLibs += "-L";
}
linkLibs += *j;
linkLibs += " ";
}
std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries();
std::vector<std::string>& libs = m_Makefile->GetLinkLibraries();
for(j = libs.begin(); j != libs.end(); ++j)
{
linkLibs += "-l";
if((*j).find("-l") == std::string::npos
&& (*j).find("${") == std::string::npos)
{
linkLibs += "-l";
}
linkLibs += *j;
linkLibs += " ";
}
std::vector<std::string>& libsUnix = m_BuildFlags.GetLinkLibrariesUnix();
std::vector<std::string>& libsUnix = m_Makefile->GetLinkLibrariesUnix();
for(j = libsUnix.begin(); j != libsUnix.end(); ++j)
{
linkLibs += *j;
@ -163,16 +186,15 @@ void cmUnixMakefile::OutputMakefile(const char* file)
fout << "CMAKE_DEPEND_LIBS = ";
this->OutputDependLibraries(fout);
// Now create rules for all of the executables to be built
for(int i = 0; i < m_Classes.size(); i++)
for(unsigned int i = 0; i < Classes.size(); i++)
{
if(!m_Classes[i].m_AbstractClass && !m_Classes[i].m_HeaderFileOnly)
if(!Classes[i].m_AbstractClass && !Classes[i].m_HeaderFileOnly)
{
std::string DotO = m_Classes[i].m_ClassName;
std::string DotO = Classes[i].m_ClassName;
DotO += ".o";
fout << m_Classes[i].m_ClassName << ": " << DotO << " ";
fout << Classes[i].m_ClassName << ": " << DotO << " ";
fout << "${CMAKE_DEPEND_LIBS}\n";
fout << "\t${CXX} ${CXX_FLAGS} "
fout << "\t${CXX} ${CXX_FLAGS} " << m_Makefile->GetDefineFlags()
<< DotO.c_str() << " "
<< linkLibs.c_str()
<< " -o $@ ""\n\n";
@ -180,12 +202,12 @@ void cmUnixMakefile::OutputMakefile(const char* file)
}
// ouput the list of executables
fout << "EXECUTABLES = \\\n";
for(int i = 0; i < m_Classes.size(); i++)
for(unsigned int i = 0; i < Classes.size(); i++)
{
if(!m_Classes[i].m_AbstractClass && !m_Classes[i].m_HeaderFileOnly)
if(!Classes[i].m_AbstractClass && !Classes[i].m_HeaderFileOnly)
{
fout << m_Classes[i].m_ClassName;
if(i < m_Classes.size()-1)
fout << Classes[i].m_ClassName;
if(i < Classes.size()-1)
{
fout << " \\";
}
@ -195,15 +217,18 @@ void cmUnixMakefile::OutputMakefile(const char* file)
fout << "\n";
}
// Output Sub directory build rules
if( m_SubDirectories.size() )
const std::vector<std::string>& SubDirectories
= m_Makefile->GetSubDirectories();
if( SubDirectories.size() )
{
fout << "SUBDIR_BUILD = \\\n";
int i;
for(i =0; i < m_SubDirectories.size(); i++)
unsigned int i;
for(i =0; i < SubDirectories.size(); i++)
{
std::string subdir = FixDirectoryName(m_SubDirectories[i].c_str());
std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
fout << "build_" << subdir.c_str();
if(i == m_SubDirectories.size()-1)
if(i == SubDirectories.size()-1)
{
fout << " \n\n";
}
@ -214,11 +239,11 @@ void cmUnixMakefile::OutputMakefile(const char* file)
}
fout << std::endl;
fout << "SUBDIR_CLEAN = \\\n";
for(i =0; i < m_SubDirectories.size(); i++)
for(i =0; i < SubDirectories.size(); i++)
{
std::string subdir = FixDirectoryName(m_SubDirectories[i].c_str());
std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
fout << "clean_" << subdir.c_str();
if(i == m_SubDirectories.size()-1)
if(i == SubDirectories.size()-1)
{
fout << " \n\n";
}
@ -230,27 +255,30 @@ void cmUnixMakefile::OutputMakefile(const char* file)
fout << std::endl;
fout << "alldirs : ${SUBDIR_BUILD}\n\n";
for(i =0; i < m_SubDirectories.size(); i++)
for(i =0; i < SubDirectories.size(); i++)
{
std::string subdir = FixDirectoryName(m_SubDirectories[i].c_str());
std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
fout << "build_" << subdir.c_str() << ":\n";
fout << "\tcd " << m_SubDirectories[i].c_str()
fout << "\tcd " << SubDirectories[i].c_str()
<< "; ${MAKE} -${MAKEFLAGS} CMakeTargets.make\n";
fout << "\tcd " << m_SubDirectories[i].c_str()
fout << "\tcd " << SubDirectories[i].c_str()
<< "; ${MAKE} -${MAKEFLAGS} all\n\n";
fout << "clean_" << subdir.c_str() << ": \n";
fout << "\tcd " << m_SubDirectories[i].c_str()
fout << "\tcd " << SubDirectories[i].c_str()
<< "; ${MAKE} -${MAKEFLAGS} clean\n\n";
}
}
this->OutputDepends(fout);
}
void cmUnixMakefile::OutputDependLibraries(std::ostream& fout)
// output the list of libraries that the executables
// in this makefile will depend on.
void cmUnixMakefileGenerator::OutputDependLibraries(std::ostream& fout)
{
std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries();
std::vector<std::string>& libdirs = m_BuildFlags.GetLinkDirectories();
std::vector<std::string>& libs = m_Makefile->GetLinkLibraries();
std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
std::vector<std::string>::iterator dir, lib, endlibs, enddirs;
for(lib = libs.begin(); lib != libs.end(); ++lib)
{

View File

@ -17,21 +17,22 @@
* itkUnixMakefile is used generate unix makefiles.
*/
#ifndef cmUnixMakefile_h
#define cmUnixMakefile_h
#ifndef cmUnixMakefileGenerator_h
#define cmUnixMakefileGenerator_h
#include "cmMakefile.h"
#include "cmMakefileGenerator.h"
class cmUnixMakefile : public cmMakefile
class cmUnixMakefileGenerator : public cmMakefileGenerator
{
public:
/**
* Write the makefile to the named file
*/
void OutputMakefile(const char* file);
protected:
void OutputDependLibraries(std::ostream&);
virtual void GenerateMakefile();
void OutputDepends(std::ostream&);
protected:
void OutputMakefile(const char* file);
void OutputDependLibraries(std::ostream&);
};
#endif

View File

@ -0,0 +1,28 @@
#include "cmWin32DefinesRule.h"
cmWin32DefinesRule::cmWin32DefinesRule()
{
#ifndef _WIN32
this->SetEnableOff();
#endif
}
// cmWin32DefinesRule
bool cmWin32DefinesRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
m_Makefile->AddDefineFlag((*i).c_str());
}
return true;
}

View File

@ -0,0 +1,39 @@
#ifndef cmWin32DefinesRule_h
#define cmWin32DefinesRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmWin32DefinesRule : public cmRuleMaker
{
public:
cmWin32DefinesRule();
virtual cmRuleMaker* Clone()
{
return new cmWin32DefinesRule;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
virtual bool IsInherited() { return true; }
// This is the name used in the input file.
virtual const char* GetName() { return "WIN32_DEFINES";}
virtual const char* TerseDocumentaion()
{
return "Add -D define flags to command line for win32 environments.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"Add -D define flags to command line for win32 environments.\n"
"WIN32_DEFINES(-DFOO -DBAR ...);";
}
};
#endif

View File

@ -0,0 +1,25 @@
#include "cmWin32LibrariesRule.h"
cmWin32LibrariesRule::cmWin32LibrariesRule()
{
#ifndef _WIN32
this->SetEnableOff();
#endif
}
// cmWin32LibrariesRule
bool cmWin32LibrariesRule::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("Called with incorrect number of arguments");
return false;
}
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
m_Makefile->AddLinkLibrary((*i).c_str());
}
return true;
}

View File

@ -0,0 +1,42 @@
#ifndef cmWin32LibrariesRule_h
#define cmWin32LibrariesRule_h
#include "cmStandardIncludes.h"
#include "cmRuleMaker.h"
class cmWin32LibrariesRule : public cmRuleMaker
{
public:
cmWin32LibrariesRule();
virtual cmRuleMaker* Clone()
{
return new cmWin32LibrariesRule ;
}
// This is called when the rule is firt encountered in
// the input file
virtual bool Invoke(std::vector<std::string>& args);
virtual void FinalPass() { }
virtual bool IsInherited() { return true; }
// This is the name used in the input file.
virtual const char* GetName() { return "WIN32_LIBRARIES";}
virtual const char* TerseDocumentaion()
{
return "Set a name for the library to be built. One argument.";
}
// Return full documentation for the rule
virtual const char* FullDocumentaion()
{
return
"Set the name for the library in this makefile. \n"
"This takes one argument.\n"
"LIBRARY(libraryname);\n"
"There can be only one library per CMakeLists.txt file.\n";
}
};
#endif

View File

@ -1,9 +1,8 @@
#include "cmWindowsConfigure.h"
#include "cmStandardIncludes.h"
#include "cmSystemTools.h"
#include <fstream>
#include <windows.h>
bool cmWindowsConfigure::Configure(const char* file)
{
std::ifstream fin(file);

View File

@ -21,7 +21,7 @@
*/
#ifndef cmWindowsConfigure_h
#define cmWindowsConfigure_h
#include <string>
#include "cmStandardIncludes.h"
class cmWindowsConfigure
{