Commit fce56c57 authored by Ken Martin's avatar Ken Martin
Browse files

some cleanup and fixes

parent 252b0d89
......@@ -21,7 +21,7 @@ clean: ${SUBDIR_CLEAN}
rm -f ${SRC_OBJ} ${EXECUTABLES}
CMakeTargets.make: ${CMAKE} ${srcdir}/CMakeLists.txt
${CMAKE} ${srcdir}/CMakeLists.txt -S${currentdir} -H${topdir} -B${CMAKE_CONFIG_DIR}
${CMAKE} ${srcdir}/CMakeLists.txt -S${currentdir} -O${currentbindir} -H${topdir} -B${CMAKE_CONFIG_DIR}
#------------------------------------------------------------------------------
# rules for the normal library
......
......@@ -34,6 +34,9 @@ topdir = @fullSrcDir@
# This is the directory that contains the source for the CMakeLists.txt file
currentdir = `cd ${srcdir}; pwd`
# This is the directory that contains the output for the CMakeLists.txt file
currentbindir = `pwd`
# This is the directory configure was run in
# where the binaries will be placed
CMAKE_CONFIG_DIR = @CMAKE_CONFIG_DIR@
......
......@@ -36,18 +36,17 @@ int main(int ac, char** av)
for(int i =2; i < ac; i++)
{
std::string arg = av[i];
// Set the current source directory with a -S dir options
// Set the start source directory with a -S dir options
if(arg.find("-S",0) == 0)
{
std::string path = arg.substr(2);
mf.SetCurrentDirectory(path.c_str());
mf.SetStartDirectory(path.c_str());
}
// Set the output or binary directory with a -B dir option
if(arg.find("-B",0) == 0)
// Set the start output directory with a -O dir options
if(arg.find("-O",0) == 0)
{
std::string path = arg.substr(2);
mf.SetOutputHomeDirectory(path.c_str());
mf.SetOutputDirectory(path.c_str());
mf.SetStartOutputDirectory(path.c_str());
}
// Set the source home directory with a -H dir option
if(arg.find("-H",0) == 0)
......@@ -55,12 +54,19 @@ int main(int ac, char** av)
std::string path = arg.substr(2);
mf.SetHomeDirectory(path.c_str());
}
// Set the output or binary directory with a -B dir option
if(arg.find("-B",0) == 0)
{
std::string path = arg.substr(2);
mf.SetHomeOutputDirectory(path.c_str());
}
}
}
mf.SetMakefileGenerator(new cmUnixMakefileGenerator);
// Read and parse the input makefile
if(!mf.ReadMakefile(av[1]))
mf.MakeStartDirectoriesCurrent();
if(!mf.ReadListFile(av[1]))
{
std::cerr << "Usage: " << av[0] << " Makefile.in -Ipath ..." << std::endl;
return -1;
......
......@@ -34,20 +34,20 @@ void SetArgs(cmMakefile& builder, int ac, char** av)
std::string path = arg.substr(2);
builder.SetHomeDirectory(path.c_str());
}
if(arg.find("-D",0) != std::string::npos)
if(arg.find("-S",0) != std::string::npos)
{
std::string path = arg.substr(2);
builder.SetCurrentDirectory(path.c_str());
builder.SetStartDirectory(path.c_str());
}
if(arg.find("-O",0) != std::string::npos)
{
std::string path = arg.substr(2);
builder.SetOutputDirectory(path.c_str());
builder.SetStartOutputDirectory(path.c_str());
}
if(arg.find("-B",0) != std::string::npos)
{
std::string path = arg.substr(2);
builder.SetOutputHomeDirectory(path.c_str());
builder.SetHomeOutputDirectory(path.c_str());
std::cout << "set output home to " << path.c_str() << std::endl;
}
}
......@@ -76,7 +76,8 @@ int main(int ac, char** av)
pg->BuildDSWOn();
}
builder.SetMakefileGenerator(pg);
builder.ReadMakefile(av[1]);
builder.MakeStartDirectoriesCurrent();
builder.ReadListFile(av[1]);
builder.GenerateMakefile();
return 0;
}
......
......@@ -257,15 +257,16 @@ void CMakeSetupDialog::OnOK()
mf.SetHomeDirectory(m_WhereSource);
// Set the output directory
mf.SetOutputDirectory(m_WhereBuild);
mf.SetOutputHomeDirectory(m_WhereBuild);
mf.SetStartOutputDirectory(m_WhereBuild);
mf.SetHomeOutputDirectory(m_WhereBuild);
// set the directory which contains the CMakeLists.txt
mf.SetCurrentDirectory(m_WhereSource);
mf.SetStartDirectory(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";
mf.ReadMakefile(makefileIn);
mf.MakeStartDirectoriesCurrent();
mf.ReadListFile(makefileIn);
// Move this to the cache editor
mf.GenerateMakefile();
CDialog::OnOK();
......
......@@ -90,5 +90,9 @@ void cmClassFile::Print()
std::cout << "Header file ";
else
std::cout << "CXX file ";
if(m_IsExecutable)
std::cout << "Executable ";
else
std::cout << "Non Executable ";
std::cout << m_ClassName << std::endl;
}
......@@ -35,6 +35,7 @@ public:
{
m_AbstractClass = false;
m_HeaderFileOnly = false;
m_IsExecutable = false;
}
/**
......@@ -59,6 +60,11 @@ public:
*/
bool m_HeaderFileOnly;
/**
* Indicate whether this class is an executable file
*/
bool m_IsExecutable;
/**
* The full path to the file.
*/
......
......@@ -55,7 +55,8 @@ public:
"CONFIGURE_HEADER(InputFile OutputFile)\n"
"The Input and Ouput files have to have full paths.\n"
"They can also use variables like CMAKE_BINARY_DIR,CMAKE_SOURCE_DIR.\n"
"This command is only run if autoconf was not used.\n";
"This command is only run if configure was not used. In other\n";
"words it is only run for non UNIX style builds.\n";
}
/**
......
......@@ -79,28 +79,25 @@ void cmDSPMakefile::OutputDSPFile()
cmSystemTools::ReplaceString(m_ReleaseLibraryOptions, "Debug", "Release");
// If the output directory is not the m_cmHomeDirectory
// then create it.
if(strcmp(m_Makefile->GetOutputDirectory(),
if(strcmp(m_Makefile->GetStartOutputDirectory(),
m_Makefile->GetHomeDirectory()) != 0)
{
if(!cmSystemTools::MakeDirectory(m_Makefile->GetOutputDirectory()))
if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
{
std::string message = "Error creating directory ";
message += m_Makefile->GetOutputDirectory();
message += m_Makefile->GetStartOutputDirectory();
Die(message.c_str());
}
}
if(!m_Makefile->HasExecutables())
// if there is a library, build it
if(strlen(m_Makefile->GetLibraryName()) != 0)
{
if(strlen(m_Makefile->GetLibraryName()) == 0)
{
// if no library silently give up
return;
}
this->SetBuildType(STATIC_LIBRARY);
this->CreateSingleDSP();
}
else
// if there are executables build them
if (m_Makefile->HasExecutables())
{
this->CreateExecutableDSPFiles();
}
......@@ -111,32 +108,34 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
for(int i = 0; i < Classes.size(); ++i)
{
cmClassFile& classfile = Classes[i];
std::string fname = m_Makefile->GetOutputDirectory();
fname += "/";
fname += classfile.m_ClassName;
fname += ".dsp";
std::ofstream fout(fname.c_str());
if(!fout)
{
std::string message = "Error Writing ";
message += fname;
Die(message.c_str());
}
else
if (classfile.m_IsExecutable)
{
m_Makefile->SetLibraryName(classfile.m_ClassName.c_str());
this->SetBuildType(EXECUTABLE);
std::string pname = m_Makefile->GetLibraryName();
m_CreatedProjectNames.push_back(pname);
this->WriteDSPHeader(fout);
this->WriteDSPBeginGroup(fout, "Source Files", "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat");
this->WriteDSPBuildRule(fout, classfile.m_FullPath.c_str());
this->WriteDSPEndGroup(fout);
this->WriteDSPBuildRule(fout);
this->WriteDSPFooter(fout);
std::string fname = m_Makefile->GetStartOutputDirectory();
fname += "/";
fname += classfile.m_ClassName;
fname += ".dsp";
std::ofstream fout(fname.c_str());
if(!fout)
{
std::string message = "Error Writing ";
message += fname;
Die(message.c_str());
}
else
{
m_Makefile->SetLibraryName(classfile.m_ClassName.c_str());
this->SetBuildType(EXECUTABLE);
std::string pname = m_Makefile->GetLibraryName();
m_CreatedProjectNames.push_back(pname);
this->WriteDSPHeader(fout);
this->WriteDSPBeginGroup(fout, "Source Files", "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat");
this->WriteDSPBuildRule(fout, classfile.m_FullPath.c_str());
this->WriteDSPEndGroup(fout);
this->WriteDSPBuildRule(fout);
this->WriteDSPFooter(fout);
}
}
}
}
......@@ -144,7 +143,7 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
void cmDSPMakefile::CreateSingleDSP()
{
std::string fname;
fname = m_Makefile->GetOutputDirectory();
fname = m_Makefile->GetStartOutputDirectory();
fname += "/";
fname += m_Makefile->GetLibraryName();
fname += ".dsp";
......@@ -165,7 +164,7 @@ void cmDSPMakefile::WriteDSPBuildRule(std::ostream& fout)
{
std::string dspname = *(m_CreatedProjectNames.end()-1);
dspname += ".dsp";
std::string makefileIn = m_Makefile->GetCurrentDirectory();
std::string makefileIn = m_Makefile->GetStartDirectory();
makefileIn += "/";
makefileIn += "CMakeLists.txt";
std::string dsprule = m_Makefile->GetHomeDirectory();
......@@ -173,12 +172,12 @@ void cmDSPMakefile::WriteDSPBuildRule(std::ostream& fout)
dsprule += makefileIn;
dsprule += " -DSP -H";
dsprule += m_Makefile->GetHomeDirectory();
dsprule += " -D";
dsprule += m_Makefile->GetCurrentDirectory();
dsprule += " -S";
dsprule += m_Makefile->GetStartDirectory();
dsprule += " -O";
dsprule += m_Makefile->GetOutputDirectory();
dsprule += m_Makefile->GetStartOutputDirectory();
dsprule += " -B";
dsprule += m_Makefile->GetOutputHomeDirectory();
dsprule += m_Makefile->GetHomeOutputDirectory();
this->WriteCustomRule(fout, makefileIn.c_str(),
dspname.c_str(),
dsprule.c_str());
......@@ -307,7 +306,8 @@ void cmDSPMakefile::WriteDSPBuildRules(std::ostream& fout)
std::vector<cmClassFile>& Classes = m_Makefile->GetClasses();
for(int i = 0; i < Classes.size(); ++i)
{
if(!Classes[i].m_AbstractClass && !Classes[i].m_HeaderFileOnly)
if(!Classes[i].m_IsExecutable && !Classes[i].m_AbstractClass &&
!Classes[i].m_HeaderFileOnly)
{
this->WriteDSPBuildRule(fout, Classes[i].m_FullPath.c_str());
}
......
......@@ -79,28 +79,25 @@ void cmDSPMakefile::OutputDSPFile()
cmSystemTools::ReplaceString(m_ReleaseLibraryOptions, "Debug", "Release");
// If the output directory is not the m_cmHomeDirectory
// then create it.
if(strcmp(m_Makefile->GetOutputDirectory(),
if(strcmp(m_Makefile->GetStartOutputDirectory(),
m_Makefile->GetHomeDirectory()) != 0)
{
if(!cmSystemTools::MakeDirectory(m_Makefile->GetOutputDirectory()))
if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
{
std::string message = "Error creating directory ";
message += m_Makefile->GetOutputDirectory();
message += m_Makefile->GetStartOutputDirectory();
Die(message.c_str());
}
}
if(!m_Makefile->HasExecutables())
// if there is a library, build it
if(strlen(m_Makefile->GetLibraryName()) != 0)
{
if(strlen(m_Makefile->GetLibraryName()) == 0)
{
// if no library silently give up
return;
}
this->SetBuildType(STATIC_LIBRARY);
this->CreateSingleDSP();
}
else
// if there are executables build them
if (m_Makefile->HasExecutables())
{
this->CreateExecutableDSPFiles();
}
......@@ -111,32 +108,34 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
for(int i = 0; i < Classes.size(); ++i)
{
cmClassFile& classfile = Classes[i];
std::string fname = m_Makefile->GetOutputDirectory();
fname += "/";
fname += classfile.m_ClassName;
fname += ".dsp";
std::ofstream fout(fname.c_str());
if(!fout)
{
std::string message = "Error Writing ";
message += fname;
Die(message.c_str());
}
else
if (classfile.m_IsExecutable)
{
m_Makefile->SetLibraryName(classfile.m_ClassName.c_str());
this->SetBuildType(EXECUTABLE);
std::string pname = m_Makefile->GetLibraryName();
m_CreatedProjectNames.push_back(pname);
this->WriteDSPHeader(fout);
this->WriteDSPBeginGroup(fout, "Source Files", "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat");
this->WriteDSPBuildRule(fout, classfile.m_FullPath.c_str());
this->WriteDSPEndGroup(fout);
this->WriteDSPBuildRule(fout);
this->WriteDSPFooter(fout);
std::string fname = m_Makefile->GetStartOutputDirectory();
fname += "/";
fname += classfile.m_ClassName;
fname += ".dsp";
std::ofstream fout(fname.c_str());
if(!fout)
{
std::string message = "Error Writing ";
message += fname;
Die(message.c_str());
}
else
{
m_Makefile->SetLibraryName(classfile.m_ClassName.c_str());
this->SetBuildType(EXECUTABLE);
std::string pname = m_Makefile->GetLibraryName();
m_CreatedProjectNames.push_back(pname);
this->WriteDSPHeader(fout);
this->WriteDSPBeginGroup(fout, "Source Files", "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat");
this->WriteDSPBuildRule(fout, classfile.m_FullPath.c_str());
this->WriteDSPEndGroup(fout);
this->WriteDSPBuildRule(fout);
this->WriteDSPFooter(fout);
}
}
}
}
......@@ -144,7 +143,7 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
void cmDSPMakefile::CreateSingleDSP()
{
std::string fname;
fname = m_Makefile->GetOutputDirectory();
fname = m_Makefile->GetStartOutputDirectory();
fname += "/";
fname += m_Makefile->GetLibraryName();
fname += ".dsp";
......@@ -165,7 +164,7 @@ void cmDSPMakefile::WriteDSPBuildRule(std::ostream& fout)
{
std::string dspname = *(m_CreatedProjectNames.end()-1);
dspname += ".dsp";
std::string makefileIn = m_Makefile->GetCurrentDirectory();
std::string makefileIn = m_Makefile->GetStartDirectory();
makefileIn += "/";
makefileIn += "CMakeLists.txt";
std::string dsprule = m_Makefile->GetHomeDirectory();
......@@ -173,12 +172,12 @@ void cmDSPMakefile::WriteDSPBuildRule(std::ostream& fout)
dsprule += makefileIn;
dsprule += " -DSP -H";
dsprule += m_Makefile->GetHomeDirectory();
dsprule += " -D";
dsprule += m_Makefile->GetCurrentDirectory();
dsprule += " -S";
dsprule += m_Makefile->GetStartDirectory();
dsprule += " -O";
dsprule += m_Makefile->GetOutputDirectory();
dsprule += m_Makefile->GetStartOutputDirectory();
dsprule += " -B";
dsprule += m_Makefile->GetOutputHomeDirectory();
dsprule += m_Makefile->GetHomeOutputDirectory();
this->WriteCustomRule(fout, makefileIn.c_str(),
dspname.c_str(),
dsprule.c_str());
......@@ -307,7 +306,8 @@ void cmDSPMakefile::WriteDSPBuildRules(std::ostream& fout)
std::vector<cmClassFile>& Classes = m_Makefile->GetClasses();
for(int i = 0; i < Classes.size(); ++i)
{
if(!Classes[i].m_AbstractClass && !Classes[i].m_HeaderFileOnly)
if(!Classes[i].m_IsExecutable && !Classes[i].m_AbstractClass &&
!Classes[i].m_HeaderFileOnly)
{
this->WriteDSPBuildRule(fout, Classes[i].m_FullPath.c_str());
}
......
......@@ -32,24 +32,24 @@ cmDSWMakefile::cmDSWMakefile(cmMakefile* m)
// output the DSW file
void cmDSWMakefile::OutputDSWFile()
{
if(m_Makefile->GetOutputDirectory() == "")
if(m_Makefile->GetStartOutputDirectory() == "")
{
// default to build in place
m_Makefile->SetOutputDirectory(m_Makefile->GetHomeDirectory());
m_Makefile->SetStartOutputDirectory(m_Makefile->GetHomeDirectory());
}
// If the output directory is not the m_cmHomeDirectory
// then create it.
if(strcmp(m_Makefile->GetOutputDirectory(),
if(strcmp(m_Makefile->GetStartOutputDirectory(),
m_Makefile->GetHomeDirectory()) != 0)
{
if(!cmSystemTools::MakeDirectory(m_Makefile->GetOutputDirectory()))
if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
{
MessageBox(0, "Error creating directory ", 0, MB_OK);
MessageBox(0, m_Makefile->GetOutputDirectory(), 0, MB_OK);
MessageBox(0, m_Makefile->GetStartOutputDirectory(), 0, MB_OK);
}
}
std::string fname;
fname = m_Makefile->GetOutputDirectory();
fname = m_Makefile->GetStartOutputDirectory();
fname += "/";
fname += m_Makefile->GetProjectName();
fname += ".dsw";
......@@ -91,22 +91,23 @@ cmDSWMakefile
// add it to the vector
makefiles.push_back(pg);
// Set up the file with the current context
mf->SetOutputHomeDirectory(m_Makefile->GetOutputDirectory());
mf->SetHomeOutputDirectory(m_Makefile->GetStartOutputDirectory());
mf->SetHomeDirectory(m_Makefile->GetHomeDirectory());
// Set the output directory which may be different than the source
std::string outdir = m_Makefile->GetStartOutputDirectory();
outdir += "/";
outdir += subdir;
mf->SetStartOutputDirectory(outdir.c_str());
// set the current directory in the Source as a full
// path
std::string currentDir = m_Makefile->GetCurrentDirectory();
std::string currentDir = m_Makefile->GetStartDirectory();
currentDir += "/";
currentDir += subdir;
mf->SetCurrentDirectory(currentDir.c_str());
mf->SetStartDirectory(currentDir.c_str());
// Parse the CMakeLists.txt file
currentDir += "/CMakeLists.txt";
mf->ReadMakefile(currentDir.c_str());
// Set the output directory which may be different than the source
std::string outdir = m_Makefile->GetOutputDirectory();
outdir += "/";
outdir += subdir;
mf->SetOutputDirectory(outdir.c_str());
mf->MakeStartDirectoriesCurrent();
mf->ReadListFile(currentDir.c_str());
// Create the DSP file
mf->GenerateMakefile();
// Look at any sub directories parsed (SUBDIRS) and
......
......@@ -32,24 +32,24 @@ cmDSWMakefile::cmDSWMakefile(cmMakefile* m)
// output the DSW file
void cmDSWMakefile::OutputDSWFile()
{
if(m_Makefile->GetOutputDirectory() == "")
if(m_Makefile->GetStartOutputDirectory() == "")
{
// default to build in place
m_Makefile->SetOutputDirectory(m_Makefile->GetHomeDirectory());
m_Makefile->SetStartOutputDirectory(m_Makefile->GetHomeDirectory());
}
// If the output directory is not the m_cmHomeDirectory
// then create it.
if(strcmp(m_Makefile->GetOutputDirectory(),
if(strcmp(m_Makefile->GetStartOutputDirectory(),
m_Makefile->GetHomeDirectory()) != 0)
{
if(!cmSystemTools::MakeDirectory(m_Makefile->GetOutputDirectory()))
if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
{
MessageBox(0, "Error creating directory ", 0, MB_OK);
MessageBox(0, m_Makefile->GetOutputDirectory(), 0, MB_OK);
MessageBox(0, m_Makefile->GetStartOutputDirectory(), 0, MB_OK);
}
}
std::string fname;
fname = m_Makefile->GetOutputDirectory();
fname = m_Makefile->GetStartOutputDirectory();
fname += "/";
fname += m_Makefile->GetProjectName();
fname += ".dsw";
......@@ -91,22 +91,23 @@ cmDSWMakefile
// add it to the vector
makefiles.push_back(pg);
// Set up the file with the current context
mf->SetOutputHomeDirectory(m_Makefile->GetOutputDirectory());
mf->SetHomeOutputDirectory(m_Makefile->GetStartOutputDirectory());
mf->SetHomeDirectory(m_Makefile->GetHomeDirectory());
// Set the output directory which may be different than the source
std::string outdir = m_Makefile->GetStartOutputDirectory();
outdir += "/";
outdir += subdir;
mf->SetStartOutputDirectory(outdir.c_str());
// set the current directory in the Source as a full
// path
std::string currentDir = m_Makefile->GetCurrentDirectory();
std::string currentDir = m_Makefile->GetStartDirectory();
currentDir += "/";
currentDir += subdir;
mf->SetCurrentDirectory(currentDir.c_str());
mf->SetStartDirectory(currentDir.c_str());
// Parse the CMakeLists.txt file
currentDir += "/CMakeLists.txt";
mf->ReadMakefile(currentDir.c_str());
// Set the output directory which may be different than the source
std::string outdir = m_Makefile->GetOutputDirectory();
outdir += "/";
outdir += subdir;
mf->SetOutputDirectory(outdir.c_str());
mf->MakeStartDirectoriesCurrent();
mf->ReadListFile(currentDir.c_str());
// Create the DSP file
mf->GenerateMakefile();
// Look at any sub directories parsed (SUBDIRS) and
......
......@@ -26,7 +26,6 @@
cmMakefile::cmMakefile()
{
m_DefineFlags = " ";
m_Executables = false;
m_MakefileGenerator = 0;
this->AddDefaultCommands();
}
......@@ -84,14 +83,18 @@ void cmMakefile::Print()
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_CurrentOutputDirectory; " <<
m_CurrentOutputDirectory.c_str() << std::endl;
std::cout << " m_StartOutputDirectory; " <<
m_StartOutputDirectory.c_str() << std::endl;
std::cout << " m_HomeOutputDirectory; " <<
m_HomeOutputDirectory.c_str() << std::endl;
std::cout << " m_cmCurrentDirectory; " <<
m_cmCurrentDirectory.c_str() << std::endl;
std::cout << " m_cmStartDirectory; " <<
m_cmStartDirectory.c_str() << std::endl;
std::cout << " m_cmHomeDirectory; " <<
m_cmHomeDirectory.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);
......@@ -104,22 +107,39 @@ void cmMakefile::Print()
}
// Parse the given CMakeLists.txt file into a list of classes.
bool cmMakefile::ReadMakefile(const char* filename, bool inheriting)
// Reads in current CMakeLists file and all parent CMakeLists files
// executing all inherited commands in the parents
bool cmMakefile::ReadListFile(const char* filename)