Commit 077c3148 authored by Bill Hoffman's avatar Bill Hoffman
Browse files

ENH: move from tools and create working CMake program

parent 1f42f521
......@@ -15,7 +15,7 @@
#
#------------------------------------------------------------------------------
#
all: ${OBJ_SUB_DIRS} ${EXECUTABLES} ${SUBDIR_BUILD} ${ITK_LIB_FILE} ${LOCAL_BUILD_TARGETS}
all: ${OBJ_SUB_DIRS} ${EXECUTABLES} ${SUBDIR_BUILD} ${BUILD_LIB_FILE} ${LOCAL_BUILD_TARGETS}
#------------------------------------------------------------------------------
......@@ -46,6 +46,6 @@ lib$(ME)$(SHLIB_SUFFIX): ${KIT_OBJ}
lib$(ME)$(SHLIB_SUFFIX) \
${KIT_OBJ} ${SHLIB_LD_LIBS}
install: ${ITK_LIB_FILE}
@echo "Installing ${ITK_LIB_FILE}"
${INSTALL} -m 755 $(ITK_LIB_FILE) $(LIB_INSTALL_DIR)/$(ITK_LIB_FILE)
install: ${BUILD_LIB_FILE}
@echo "Installing ${BUILD_LIB_FILE}"
${INSTALL} -m 755 $(BUILD_LIB_FILE) $(LIB_INSTALL_DIR)/$(BUILD_LIB_FILE)
......@@ -105,5 +105,5 @@ CC_FLAGS = ${CPPFLAGS} ${LOCAL_CFLAGS} ${CFLAGS}
# set up the path to the rulesgen program
CMAKE = @CMAKE_OBJ_DIR@/CMake/Source/CMakeBuildTargets
KIT_OBJ = ${SRC_OBJ}
BUILD_LIB_FILE = lib${ME}${ITK_LIB_EXT}
......@@ -13,6 +13,18 @@ Unix
configure -> run on unix to configure for build
CMakeBuildTargets -> Unix program to read CMakeLists.txt and generate CMakeTargets.make
CMakeLists.txt:
WIN32_CLASSES =
UNIX_CLASSES =
ABSTRACT_CLASSES =
SUBDIRS =
EXECUTABLES =
ME =
BEGIN MAKE VERBATIM
... # copy stuff into CMakeTargets.make directly
END MAKE VERBATIM
TEMPLATE_INSTANCE_DIR =
TODO:
Fix cmUnixMakefile.cxx and cmDSPMakefile.cxx
to read libraries and -I stuff from a config file
......@@ -91,10 +91,18 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\CMakeSetupCMD.cxx
# End Source File
# Begin Source File
SOURCE=.\cmClassFile.cxx
# End Source File
# Begin Source File
SOURCE=.\cmDirectory.cxx
# End Source File
# Begin Source File
SOURCE=.\cmDSPBuilder.cxx
# End Source File
# Begin Source File
......@@ -129,10 +137,6 @@ SOURCE=.\cmRegularExpression.cxx
SOURCE=.\cmSystemTools.cxx
# End Source File
# Begin Source File
SOURCE=.\CMakeSetupCMD.cxx
# End Source File
# End Group
# Begin Group "Header Files"
......
......@@ -92,10 +92,26 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\CMakeSetup.cpp
# End Source File
# Begin Source File
SOURCE=.\CMakeSetup.rc
# End Source File
# Begin Source File
SOURCE=.\CMakeSetupDialog.cpp
# End Source File
# Begin Source File
SOURCE=..\cmClassFile.cxx
# End Source File
# Begin Source File
SOURCE=..\cmDirectory.cxx
# End Source File
# Begin Source File
SOURCE=..\cmDSPBuilder.cxx
# End Source File
# Begin Source File
......@@ -132,33 +148,33 @@ SOURCE=..\cmSystemTools.cxx
# End Source File
# Begin Source File
SOURCE=..\itkVC60Configure.cxx
SOURCE=..\cmWindowsConfigure.cxx
# End Source File
# Begin Source File
SOURCE=..\cmWindowsConfigure.cxx
SOURCE=..\itkVC60Configure.cxx
# End Source File
# Begin Source File
SOURCE=.\CMakeSetup.cpp
SOURCE=.\StdAfx.cpp
# ADD CPP /Yc"stdafx.h"
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\CMakeSetup.rc
SOURCE=..\CMakeSetup.h
# End Source File
# Begin Source File
SOURCE=.\CMakeSetupDialog.cpp
SOURCE=.\CMakeSetup.h
# End Source File
# Begin Source File
SOURCE=.\StdAfx.cpp
# ADD CPP /Yc"stdafx.h"
SOURCE=.\CMakeSetupDialog.h
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\cmClassFile.h
......@@ -189,22 +205,10 @@ SOURCE=..\cmMakefile.h
# End Source File
# Begin Source File
SOURCE=..\CMakeSetup.h
# End Source File
# Begin Source File
SOURCE=..\cmRegularExpression.h
# End Source File
# Begin Source File
SOURCE=.\CMakeSetup.h
# End Source File
# Begin Source File
SOURCE=.\CMakeSetupDialog.h
# End Source File
# Begin Source File
SOURCE=.\Resource.h
# End Source File
# Begin Source File
......@@ -221,11 +225,11 @@ SOURCE=.\res\CMakeSetup.ico
# End Source File
# Begin Source File
SOURCE=.\res\CMakeSetupDialog.rc2
SOURCE=.\res\CMakeSetupDialog.ico
# End Source File
# Begin Source File
SOURCE=.\res\CMakeSetupDialog.ico
SOURCE=.\res\CMakeSetupDialog.rc2
# End Source File
# End Group
# Begin Source File
......
......@@ -235,13 +235,13 @@ void CMakeSetupDialog::OnOK()
cmDSWBuilder builder;
// Set the ITK home directory
builder.SetHomeDirectory(m_WhereSource);
// Set the Makefile.in file
// Set the CMakeLists.txt file
CString makefileIn = m_WhereSource;
makefileIn += "/Makefile.in";
makefileIn += "/CMakeLists.txt";
builder.SetInputMakefilePath(makefileIn);
// Set the output directory
builder.SetOutputDirectory(m_WhereBuild);
// set the directory which contains the Makefile.in
// set the directory which contains the CMakeLists.txt
builder.SetMakefileDirectory(m_WhereSource);
// Create the master DSW file and all children dsp files for ITK
builder.CreateDSWFile();
......
......@@ -12,12 +12,15 @@ CMAKE =
OBJS = \
cmClassFile.o \
cmDirectory.o \
cmMakefile.o \
cmUnixMakefile.o \
cmMakeDepend.o \
cmRegularExpression.o \
CMakeBuildTargets.o
CMakeBuildTargets.o
cmDirectory.o : cmDirectory.h cmDirectory.cxx
cmClassFile.o : cmClassFile.h cmClassFile.cxx
cmMakefile.o : cmMakefile.h cmMakefile.cxx cmClassFile.h
cmUnixMakefile.o : cmUnixMakefile.h cmUnixMakefile.cxx cmMakefile.h cmClassFile.h
......
......@@ -38,11 +38,12 @@ void cmClassFile::SetName(const char* name, const char* dir)
std::string hname = pathname;
hname += ".cxx";
if(cmFileExists(hname.c_str()))
{
{
m_HeaderFileOnly = false;
m_FullPath = hname;
return;
}
}
hname = pathname;
hname += ".c";
if(cmFileExists(hname.c_str()))
......
......@@ -4,6 +4,13 @@
#include <fstream>
#include <windows.h>
static void Die(const char* message)
{
MessageBox(0, message, 0, MB_OK);
exit(-1);
}
void cmDSPMakefile::OutputDSPFile()
{
m_IncludeOptions = "/STACK:10000000 ";
......@@ -36,8 +43,9 @@ void cmDSPMakefile::OutputDSPFile()
{
if(!cmSystemTools::MakeDirectory(m_OutputDirectory.c_str()))
{
MessageBox(0, "Error creating directory ", 0, MB_OK);
MessageBox(0, m_OutputDirectory.c_str(), 0, MB_OK);
std::string message = "Error creating directory ";
message += m_OutputDirectory;
Die(message.c_str());
}
}
......@@ -45,22 +53,19 @@ void cmDSPMakefile::OutputDSPFile()
{
if(this->m_LibraryName == "")
{
std::cerr << "No library name in Makefile.in dsp not created" << std::endl;
// if no library silently give up
return;
}
std::cerr << "building library " << this->m_LibraryName.c_str() << std::endl;
this->SetBuildType(STATIC_LIBRARY);
this->CreateSingleDSP();
}
else
{
std::cerr << "Build Executables " << std::endl;
this->CreateExecutableDSPFiles();
}
}
void cmDSPMakefile::CreateExecutableDSPFiles()
{
std::cerr << "Create executables for ";
for(int i = 0; i < m_Classes.size(); ++i)
{
cmClassFile& classfile = m_Classes[i];
......@@ -71,9 +76,9 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
std::ofstream fout(fname.c_str());
if(!fout)
{
MessageBox(0, "Error writing ", 0, MB_OK);
MessageBox(0, fname.c_str(), 0, MB_OK);
std::cerr << "Error can not open " << fname.c_str() << " for write" << std::endl;
std::string message = "Error Writing ";
message += fname;
Die(message.c_str());
}
else
{
......@@ -97,8 +102,6 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
void cmDSPMakefile::CreateSingleDSP()
{
std::string fname;
std::cerr << "writting dsp file " << m_cmCurrentDirectory.c_str()
<< std::endl;
fname = m_OutputDirectory;
fname += "/";
fname += this->m_LibraryName;
......@@ -106,15 +109,13 @@ void cmDSPMakefile::CreateSingleDSP()
m_CreatedProjectNames.clear();
std::string pname = m_LibraryName;
m_CreatedProjectNames.push_back(pname);
std::cerr << "writting dsp file " << fname.c_str() << std::endl;
std::ofstream fout(fname.c_str());
if(!fout)
{
MessageBox(0, "Error writing ", 0, MB_OK);
MessageBox(0, fname.c_str(), 0, MB_OK);
std::cerr << "Error can not open " << fname.c_str() << " for write" << std::endl;
return;
}
std::string message = "Error Writing ";
message += fname;
Die(message.c_str());
}
this->WriteDSPFile(fout);
}
......@@ -125,7 +126,7 @@ void cmDSPMakefile::WriteDSPBuildRule(std::ostream& fout)
#undef GetCurrentDirectory
std::string makefileIn = this->GetCurrentDirectory();
makefileIn += "/";
makefileIn += "Makefile.in";
makefileIn += "CMakeLists.txt";
std::string dsprule = GetHomeDirectory();
dsprule += "/CMake/pcbuilderCMD ";
dsprule += makefileIn;
......@@ -191,21 +192,21 @@ void cmDSPMakefile::SetBuildType(BuildType b)
{
case STATIC_LIBRARY:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate += "/CMake/staticLibHeader.dsptemplate";
m_DSPHeaderTemplate += "/CMake/Source/staticLibHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate += "/CMake/staticLibFooter.dsptemplate";
m_DSPFooterTemplate += "/CMake/Source/staticLibFooter.dsptemplate";
break;
case DLL:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate += "/CMake/DLLHeader.dsptemplate";
m_DSPHeaderTemplate += "/CMake/Source/DLLHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate += "/CMake/DLLFooter.dsptemplate";
m_DSPFooterTemplate += "/CMake/Source/DLLFooter.dsptemplate";
break;
case EXECUTABLE:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate += "/CMake/EXEHeader.dsptemplate";
m_DSPHeaderTemplate += "/CMake/Source/EXEHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate += "/CMake/EXEFooter.dsptemplate";
m_DSPFooterTemplate += "/CMake/Source/EXEFooter.dsptemplate";
break;
}
}
......@@ -216,9 +217,9 @@ void cmDSPMakefile::WriteDSPHeader(std::ostream& fout)
std::ifstream fin(m_DSPHeaderTemplate.c_str());
if(!fin)
{
std::cerr << "failed to open " << m_DSPHeaderTemplate.c_str()
<< " for read" << std::endl;
return;
std::string message = "Error Reading ";
message += m_DSPHeaderTemplate;
Die(message.c_str());
}
char buffer[2048];
while(fin)
......@@ -245,9 +246,9 @@ void cmDSPMakefile::WriteDSPFooter(std::ostream& fout)
std::ifstream fin(m_DSPFooterTemplate.c_str());
if(!fin)
{
std::cerr << "can not open " << m_DSPFooterTemplate.c_str() <<
" for read" << std::endl;
return;
std::string message = "Error Reading ";
message += m_DSPFooterTemplate;
Die(message.c_str());
}
char buffer[2048];
while(fin)
......
......@@ -4,6 +4,13 @@
#include <fstream>
#include <windows.h>
static void Die(const char* message)
{
MessageBox(0, message, 0, MB_OK);
exit(-1);
}
void cmDSPMakefile::OutputDSPFile()
{
m_IncludeOptions = "/STACK:10000000 ";
......@@ -36,8 +43,9 @@ void cmDSPMakefile::OutputDSPFile()
{
if(!cmSystemTools::MakeDirectory(m_OutputDirectory.c_str()))
{
MessageBox(0, "Error creating directory ", 0, MB_OK);
MessageBox(0, m_OutputDirectory.c_str(), 0, MB_OK);
std::string message = "Error creating directory ";
message += m_OutputDirectory;
Die(message.c_str());
}
}
......@@ -45,22 +53,19 @@ void cmDSPMakefile::OutputDSPFile()
{
if(this->m_LibraryName == "")
{
std::cerr << "No library name in Makefile.in dsp not created" << std::endl;
// if no library silently give up
return;
}
std::cerr << "building library " << this->m_LibraryName.c_str() << std::endl;
this->SetBuildType(STATIC_LIBRARY);
this->CreateSingleDSP();
}
else
{
std::cerr << "Build Executables " << std::endl;
this->CreateExecutableDSPFiles();
}
}
void cmDSPMakefile::CreateExecutableDSPFiles()
{
std::cerr << "Create executables for ";
for(int i = 0; i < m_Classes.size(); ++i)
{
cmClassFile& classfile = m_Classes[i];
......@@ -71,9 +76,9 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
std::ofstream fout(fname.c_str());
if(!fout)
{
MessageBox(0, "Error writing ", 0, MB_OK);
MessageBox(0, fname.c_str(), 0, MB_OK);
std::cerr << "Error can not open " << fname.c_str() << " for write" << std::endl;
std::string message = "Error Writing ";
message += fname;
Die(message.c_str());
}
else
{
......@@ -97,8 +102,6 @@ void cmDSPMakefile::CreateExecutableDSPFiles()
void cmDSPMakefile::CreateSingleDSP()
{
std::string fname;
std::cerr << "writting dsp file " << m_cmCurrentDirectory.c_str()
<< std::endl;
fname = m_OutputDirectory;
fname += "/";
fname += this->m_LibraryName;
......@@ -106,15 +109,13 @@ void cmDSPMakefile::CreateSingleDSP()
m_CreatedProjectNames.clear();
std::string pname = m_LibraryName;
m_CreatedProjectNames.push_back(pname);
std::cerr << "writting dsp file " << fname.c_str() << std::endl;
std::ofstream fout(fname.c_str());
if(!fout)
{
MessageBox(0, "Error writing ", 0, MB_OK);
MessageBox(0, fname.c_str(), 0, MB_OK);
std::cerr << "Error can not open " << fname.c_str() << " for write" << std::endl;
return;
}
std::string message = "Error Writing ";
message += fname;
Die(message.c_str());
}
this->WriteDSPFile(fout);
}
......@@ -125,7 +126,7 @@ void cmDSPMakefile::WriteDSPBuildRule(std::ostream& fout)
#undef GetCurrentDirectory
std::string makefileIn = this->GetCurrentDirectory();
makefileIn += "/";
makefileIn += "Makefile.in";
makefileIn += "CMakeLists.txt";
std::string dsprule = GetHomeDirectory();
dsprule += "/CMake/pcbuilderCMD ";
dsprule += makefileIn;
......@@ -191,21 +192,21 @@ void cmDSPMakefile::SetBuildType(BuildType b)
{
case STATIC_LIBRARY:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate += "/CMake/staticLibHeader.dsptemplate";
m_DSPHeaderTemplate += "/CMake/Source/staticLibHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate += "/CMake/staticLibFooter.dsptemplate";
m_DSPFooterTemplate += "/CMake/Source/staticLibFooter.dsptemplate";
break;
case DLL:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate += "/CMake/DLLHeader.dsptemplate";
m_DSPHeaderTemplate += "/CMake/Source/DLLHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate += "/CMake/DLLFooter.dsptemplate";
m_DSPFooterTemplate += "/CMake/Source/DLLFooter.dsptemplate";
break;
case EXECUTABLE:
m_DSPHeaderTemplate = m_cmHomeDirectory;
m_DSPHeaderTemplate += "/CMake/EXEHeader.dsptemplate";
m_DSPHeaderTemplate += "/CMake/Source/EXEHeader.dsptemplate";
m_DSPFooterTemplate = m_cmHomeDirectory;
m_DSPFooterTemplate += "/CMake/EXEFooter.dsptemplate";
m_DSPFooterTemplate += "/CMake/Source/EXEFooter.dsptemplate";
break;
}
}
......@@ -216,9 +217,9 @@ void cmDSPMakefile::WriteDSPHeader(std::ostream& fout)
std::ifstream fin(m_DSPHeaderTemplate.c_str());
if(!fin)
{
std::cerr << "failed to open " << m_DSPHeaderTemplate.c_str()
<< " for read" << std::endl;
return;
std::string message = "Error Reading ";
message += m_DSPHeaderTemplate;
Die(message.c_str());
}
char buffer[2048];
while(fin)
......@@ -245,9 +246,9 @@ void cmDSPMakefile::WriteDSPFooter(std::ostream& fout)
std::ifstream fin(m_DSPFooterTemplate.c_str());
if(!fin)
{
std::cerr << "can not open " << m_DSPFooterTemplate.c_str() <<
" for read" << std::endl;
return;
std::string message = "Error Reading ";
message += m_DSPFooterTemplate;
Die(message.c_str());
}
char buffer[2048];
while(fin)
......
......@@ -62,7 +62,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
std::cerr << "Create dsp for " << (*si).c_str() << std::endl;
if(dspname == "")
{
std::cerr << "Project name not found in " << dir << "/Makefile.in" << std::endl;
std::cerr << "Project name not found in " << dir << "/CMakeLists.txt" << std::endl;
std::cerr << "Skipping Project " << std::endl;
}
else
......@@ -91,7 +91,7 @@ std::vector<std::string> cmDSWMakefile::CreateDSPFile(const char* subdir)
outdir += subdir;
dsp.SetOutputDirectory(outdir.c_str());
currentDir += "/";
currentDir += "Makefile.in";
currentDir += "CMakeLists.txt";
dsp.SetInputMakefilePath(currentDir.c_str());
dsp.CreateDSPFile();
return dsp.GetCreatedProjectNames();
......
......@@ -62,7 +62,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
std::cerr << "Create dsp for " << (*si).c_str() << std::endl;
if(dspname == "")
{
std::cerr << "Project name not found in " << dir << "/Makefile.in" << std::endl;
std::cerr << "Project name not found in " << dir << "/CMakeLists.txt" << std::endl;
std::cerr << "Skipping Project " << std::endl;
}
else
......@@ -91,7 +91,7 @@ std::vector<std::string> cmDSWMakefile::CreateDSPFile(const char* subdir)
outdir += subdir;
dsp.SetOutputDirectory(outdir.c_str());
currentDir += "/";
currentDir += "Makefile.in";
currentDir += "CMakeLists.txt";
dsp.SetInputMakefilePath(currentDir.c_str());
dsp.CreateDSPFile();
return dsp.GetCreatedProjectNames();
......
......@@ -3,13 +3,14 @@
#endif
#include "cmMakefile.h"
#include "cmClassFile.h"
#include "cmDirectory.h"
#include <fstream>
#include <iostream>
// remove extra spaces and the "\" character from the name
// of the class as it is in the Makefile.in
// of the class as it is in the CMakeLists.txt
inline std::string CleanUpName(const char* name)
{
std::string className = name;
......@@ -50,7 +51,7 @@ void cmMakefile::Print()
m_Classes[i].Print();
}
// Parse the given Makefile.in file into a list of classes.
// Parse the given CMakeLists.txt file into a list of classes.
bool cmMakefile::ReadMakefile(const char* filename)
{
......@@ -97,6 +98,10 @@ bool cmMakefile::ReadMakefile(const char* filename)
this->ReadClasses(fin, true);
}
}
else if(line.find("TEMPLATE_INSTANCE_DIRECTORY") != std::string::npos)
{
this->ReadTemplateInstanceDirectory(line);
}
else if(line.find("SUBDIRS") != std::string::npos)
{
if(line.find("\\") != std::string::npos)
......@@ -112,6 +117,23 @@ bool cmMakefile::ReadMakefile(const char* filename)
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)
{
fin.getline(inbuffer, 2047);
m_MakeVerbatim.push_back(inbuffer);
if((m_MakeVerbatim.end()-1)->find("END MAKE VERBATIM")
!= std::string::npos )
{