ENH: change ME to LIBRARY and added PROJECT, also remove ITK stuff and replaced with CMake

This commit is contained in:
Bill Hoffman 2000-09-27 15:01:19 -04:00
parent 1e3ba0f1d7
commit 74c1345333
14 changed files with 176 additions and 49 deletions

View File

@ -1,3 +1,7 @@
#------------------------------------------------------------------------------
# move this from CMakeVariables.make.in so that depends can be done in CMakeTargets.make
CMAKE_LIB_EXT = @CMAKE_LIB_EXT@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Include generated rules # Include generated rules
@MAKEINCLUDE@ @MAKEQUOTE@CMakeTargets.make@MAKEQUOTE@ @MAKEINCLUDE@ @MAKEQUOTE@CMakeTargets.make@MAKEQUOTE@

View File

@ -1,4 +1,4 @@
# include simple rules for building .o files from source files # rules for building .o files from source files
@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMake/CMakeSimpleRules.make@MAKEQUOTE@ @MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMake/CMakeSimpleRules.make@MAKEQUOTE@
# #
@ -26,15 +26,15 @@ CMakeTargets.make: ${CMAKE} ${srcdir}/CMakeLists.txt
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# rules for the normal library # rules for the normal library
# #
lib${ME}.a: ${SRC_OBJ} ${KIT_OBJ} lib${LIBRARY}.a: ${SRC_OBJ} ${KIT_OBJ}
${AR} cr lib${ME}.a ${KIT_OBJ} ${AR} cr lib${LIBRARY}.a ${KIT_OBJ}
${RANLIB} lib$(ME).a ${RANLIB} lib$(LIBRARY).a
lib$(ME)$(SHLIB_SUFFIX): ${KIT_OBJ} lib$(LIBRARY)$(SHLIB_SUFFIX): ${KIT_OBJ}
rm -f lib$(ME)$(SHLIB_SUFFIX) rm -f lib$(LIBRARY)$(SHLIB_SUFFIX)
$(CXX) ${CXX_FLAGS} ${ITK_SHLIB_BUILD_FLAGS} -o \ $(CXX) ${CXX_FLAGS} ${CMAKE_SHLIB_BUILD_FLAGS} -o \
lib$(ME)$(SHLIB_SUFFIX) \ lib$(LIBRARY)$(SHLIB_SUFFIX) \
${KIT_OBJ} ${SHLIB_LD_LIBS} ${KIT_OBJ} ${SHLIB_LD_LIBS}
install: ${BUILD_LIB_FILE} install: ${BUILD_LIB_FILE}

View File

@ -43,10 +43,10 @@ SHELL = /bin/sh
RANLIB = @RANLIB@ RANLIB = @RANLIB@
CC = @CC@ CC = @CC@
CFLAGS = @ITK_SHLIB_CFLAGS@ @ANSI_CFLAGS@ CFLAGS = @CMAKE_SHLIB_CFLAGS@ @ANSI_CFLAGS@
CXX = @CXX@ CXX = @CXX@
CXXFLAGS = @ITK_SHLIB_CFLAGS@ @EXTRA_GCC_FLAG@ @ITK_TEMPLATE_FLAGS@ CXXFLAGS = @CMAKE_SHLIB_CFLAGS@ @EXTRA_GCC_FLAG@ @CMAKE_TEMPLATE_FLAGS@
@ -84,10 +84,9 @@ USE_LOCAL_JAVA = @USE_LOCAL_JAVA@
TOOLKIT_DEPENDS = @TOOLKIT_DEPENDS@ TOOLKIT_DEPENDS = @TOOLKIT_DEPENDS@
ITK_TCL_SHLIB_TARGET = @ITK_TCL_SHLIB_TARGET@ CMAKE_TCL_SHLIB_TARGET = @CMAKE_TCL_SHLIB_TARGET@
ITK_SHLIB_BUILD_FLAGS = @ITK_SHLIB_BUILD_FLAGS@ CMAKE_SHLIB_BUILD_FLAGS = @CMAKE_SHLIB_BUILD_FLAGS@
ITK_SHLIB_LINK_FLAGS = @ITK_SHLIB_LINK_FLAGS@ CMAKE_SHLIB_LINK_FLAGS = @CMAKE_SHLIB_LINK_FLAGS@
ITK_LIB_EXT = @ITK_LIB_EXT@
DL_LIBS = @DL_LIBS@ DL_LIBS = @DL_LIBS@
SHLIB_LD_LIBS = @SHLIB_LD_LIBS@ SHLIB_LD_LIBS = @SHLIB_LD_LIBS@
SHLIB_SUFFIX = @SHLIB_SUFFIX@ SHLIB_SUFFIX = @SHLIB_SUFFIX@

8
README
View File

@ -68,13 +68,13 @@ make
TODO: TODO:
FEATURES:
Add include and directories to the build on windows. Add include and directories to the build on windows.
For unix just add them to the CMakeLocal.make.in For unix just add them to the CMakeLocal.make.in
Add a --with idea, sets a #define in the config.h file Add a --with idea, sets a #define in the config.h file
CLEANUP:
Change ME to LIBRARY, and add PROJECT= Change ME to LIBRARY, and add PROJECT=
Remove the rest of the ITK_* stuff
move the libs used from the top into the testing...

View File

@ -33,7 +33,7 @@ void cmDSWMakefile::OutputDSWFile()
std::string fname; std::string fname;
fname = m_OutputDirectory; fname = m_OutputDirectory;
fname += "/"; fname += "/";
fname += this->m_LibraryName; fname += this->m_ProjectName;
fname += ".dsw"; fname += ".dsw";
std::cerr << "writting dsw file " << fname.c_str() << std::endl; std::cerr << "writting dsw file " << fname.c_str() << std::endl;
std::ofstream fout(fname.c_str()); std::ofstream fout(fname.c_str());
@ -149,7 +149,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
si != dspnames.end(); ++si) si != dspnames.end(); ++si)
{ {
// Write the project into the DSW file // Write the project into the DSW file
this->WriteProject(fout, si->c_str(), dir.c_str()); this->WriteProject(fout, si->c_str(), dir.c_str(), *k);
} }
// delete the cmDSPMakefile object once done with it to avoid // delete the cmDSPMakefile object once done with it to avoid
// leaks // leaks
@ -162,7 +162,8 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
void cmDSWMakefile::WriteProject(std::ostream& fout, void cmDSWMakefile::WriteProject(std::ostream& fout,
const char* dspname, const char* dspname,
const char* dir) const char* dir,
cmMakefile* project)
{ {
fout << "###############################################################################\n\n"; fout << "###############################################################################\n\n";
fout << "Project: \"" << dspname << "\"=" fout << "Project: \"" << dspname << "\"="
@ -170,7 +171,19 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
fout << "Package=<5>\n{{{\n}}}\n\n"; fout << "Package=<5>\n{{{\n}}}\n\n";
fout << "Package=<4>\n"; fout << "Package=<4>\n";
fout << "{{{\n"; fout << "{{{\n";
if(project->HasExecutables())
{
// insert Begin Project Dependency Project_Dep_Name project stuff here // 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();
for(;i!= end; ++i)
{
fout << "Begin Project Dependency\n";
fout << "Project_Dep_Name " << *i << "\n";
fout << "End Project Dependency\n";
}
}
fout << "}}}\n\n"; fout << "}}}\n\n";
} }

View File

@ -37,7 +37,8 @@ private:
void WriteDSWFile(std::ostream& fout); void WriteDSWFile(std::ostream& fout);
void WriteDSWHeader(std::ostream& fout); void WriteDSWHeader(std::ostream& fout);
void WriteProject(std::ostream& fout, void WriteProject(std::ostream& fout,
const char* name, const char* path); const char* name, const char* path,
cmMakefile* project);
void WriteDSWFooter(std::ostream& fout); void WriteDSWFooter(std::ostream& fout);
}; };

View File

@ -33,7 +33,7 @@ void cmDSWMakefile::OutputDSWFile()
std::string fname; std::string fname;
fname = m_OutputDirectory; fname = m_OutputDirectory;
fname += "/"; fname += "/";
fname += this->m_LibraryName; fname += this->m_ProjectName;
fname += ".dsw"; fname += ".dsw";
std::cerr << "writting dsw file " << fname.c_str() << std::endl; std::cerr << "writting dsw file " << fname.c_str() << std::endl;
std::ofstream fout(fname.c_str()); std::ofstream fout(fname.c_str());
@ -149,7 +149,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
si != dspnames.end(); ++si) si != dspnames.end(); ++si)
{ {
// Write the project into the DSW file // Write the project into the DSW file
this->WriteProject(fout, si->c_str(), dir.c_str()); this->WriteProject(fout, si->c_str(), dir.c_str(), *k);
} }
// delete the cmDSPMakefile object once done with it to avoid // delete the cmDSPMakefile object once done with it to avoid
// leaks // leaks
@ -162,7 +162,8 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
void cmDSWMakefile::WriteProject(std::ostream& fout, void cmDSWMakefile::WriteProject(std::ostream& fout,
const char* dspname, const char* dspname,
const char* dir) const char* dir,
cmMakefile* project)
{ {
fout << "###############################################################################\n\n"; fout << "###############################################################################\n\n";
fout << "Project: \"" << dspname << "\"=" fout << "Project: \"" << dspname << "\"="
@ -170,7 +171,19 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
fout << "Package=<5>\n{{{\n}}}\n\n"; fout << "Package=<5>\n{{{\n}}}\n\n";
fout << "Package=<4>\n"; fout << "Package=<4>\n";
fout << "{{{\n"; fout << "{{{\n";
if(project->HasExecutables())
{
// insert Begin Project Dependency Project_Dep_Name project stuff here // 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();
for(;i!= end; ++i)
{
fout << "Begin Project Dependency\n";
fout << "Project_Dep_Name " << *i << "\n";
fout << "End Project Dependency\n";
}
}
fout << "}}}\n\n"; fout << "}}}\n\n";
} }

View File

@ -37,7 +37,8 @@ private:
void WriteDSWFile(std::ostream& fout); void WriteDSWFile(std::ostream& fout);
void WriteDSWHeader(std::ostream& fout); void WriteDSWHeader(std::ostream& fout);
void WriteProject(std::ostream& fout, void WriteProject(std::ostream& fout,
const char* name, const char* path); const char* name, const char* path,
cmMakefile* project);
void WriteDSWFooter(std::ostream& fout); void WriteDSWFooter(std::ostream& fout);
}; };

View File

@ -109,24 +109,17 @@ bool cmMakefile::ReadMakefile(const char* filename)
} }
} }
} }
else if(line.find("ME") != std::string::npos) else if(line.find("LIBRARY") != std::string::npos)
{ {
size_t mestart = line.find("ME"); std::string libname = cmSystemTools::ExtractVariable("LIBRARY",
size_t start = line.find("="); line.c_str());
if(start != std::string::npos && start > mestart ) this->SetLibraryName(libname.c_str());
{
start++;
while(line[start] == ' ' && start < line.size())
{
start++;
} }
size_t end = line.size()-1; else if(line.find("PROJECT") != std::string::npos)
while(line[end] == ' ' && end > start)
{ {
end--; std::string libname = cmSystemTools::ExtractVariable("PROJECT",
} line.c_str());
this->SetLibraryName(line.substr(start, end).c_str()); this->SetProjectName(libname.c_str());
}
} }
} }
return true; return true;

View File

@ -64,6 +64,15 @@ public:
{ {
return m_LibraryName.c_str(); 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();
}
// Set the name of the library that is built by this makefile // Set the name of the library that is built by this makefile
void SetOutputDirectory(const char* lib) void SetOutputDirectory(const char* lib)
@ -93,6 +102,11 @@ public:
return m_SubDirectories; return m_SubDirectories;
} }
bool HasExecutables()
{
return m_Executables;
}
private: private:
void ReadTemplateInstanceDirectory(std::string&); void ReadTemplateInstanceDirectory(std::string&);
void ReadClasses(std::ifstream& fin, bool t); void ReadClasses(std::ifstream& fin, bool t);
@ -107,6 +121,7 @@ protected:
std::string m_cmHomeDirectory; // Home directory for source std::string m_cmHomeDirectory; // Home directory for source
std::string m_cmCurrentDirectory; // current directory in source std::string m_cmCurrentDirectory; // current directory in source
std::string m_LibraryName; // library name std::string m_LibraryName; // library name
std::string m_ProjectName; // project name
std::vector<cmClassFile> m_Classes; // list of classes in makefile 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_SubDirectories; // list of sub directories
std::vector<std::string> m_MakeVerbatim; // lines copied from input file std::vector<std::string> m_MakeVerbatim; // lines copied from input file

View File

@ -1,6 +1,7 @@
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "errno.h" #include "errno.h"
#include <sys/stat.h> #include <sys/stat.h>
#include "cmRegularExpression.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#include <windows.h> #include <windows.h>
@ -125,7 +126,7 @@ void cmSystemTools::ReadList(std::vector<std::string>& stringList,
bool done = false; bool done = false;
while ( !done ) while ( !done )
{ {
fin.getline(inbuffer, 2047 ); fin.getline(inbuffer, sizeof(inbuffer) );
std::string inname = inbuffer; std::string inname = inbuffer;
if(inname.find('\\') == std::string::npos) if(inname.find('\\') == std::string::npos)
{ {
@ -154,3 +155,45 @@ void cmSystemTools::ConvertToUnixSlashes(std::string& path)
path = path.substr(0, path.size()-1); path = path.substr(0, path.size()-1);
} }
} }
int cmSystemTools::Grep(const char* dir, const char* file, const char* expression)
{
std::string path = dir;
path += "/";
path += file;
std::ifstream fin(path.c_str());
char buffer[2056];
int count = 0;
cmRegularExpression reg(expression);
while(fin)
{
fin.getline(buffer, sizeof(buffer));
count += reg.find(buffer);
}
return count;
}
std::string cmSystemTools::ExtractVariable(const char* variable,
const char* l)
{
std::string line = l;
size_t varstart = line.find(variable);
size_t start = line.find("=");
if(start != std::string::npos && start > varstart )
{
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();
}
return std::string("");
}

View File

@ -55,6 +55,17 @@ public:
* Return true if a file exists * Return true if a file exists
*/ */
static bool FileExists(const char* filename); static bool FileExists(const char* filename);
/**
* Return the number of times expression occurs in file in dir
*/
static int Grep(const char* dir, const char* file, const char* expression);
/**
* Extract the right hand side of an asignment varibale = value
*/
static std::string ExtractVariable(const char* varible,
const char* line);
/** /**
* Read a list from a file into the array of strings. * Read a list from a file into the array of strings.
* This function assumes that the first line of the * This function assumes that the first line of the

View File

@ -101,8 +101,8 @@ void cmUnixMakefile::OutputMakefile(const char* file)
// Ouput Library name if there are SRC_OBJS // Ouput Library name if there are SRC_OBJS
if(strlen(this->GetLibraryName()) > 0) if(strlen(this->GetLibraryName()) > 0)
{ {
fout << "ME = " << this->GetLibraryName() << "\n\n"; fout << "LIBRARY = " << this->GetLibraryName() << "\n\n";
fout << "BUILD_LIB_FILE = lib${ME}${ITK_LIB_EXT}\n\n"; fout << "BUILD_LIB_FILE = lib${LIBRARY}${CMAKE_LIB_EXT}\n\n";
} }
// Output SRC_OBJ list for all the classes to be compiled // Output SRC_OBJ list for all the classes to be compiled
fout << "SRC_OBJ = \\\n"; fout << "SRC_OBJ = \\\n";
@ -157,6 +157,11 @@ void cmUnixMakefile::OutputMakefile(const char* file)
linkLibs += " "; linkLibs += " ";
} }
linkLibs += " ${LOCAL_LINK_FLAGS} "; linkLibs += " ${LOCAL_LINK_FLAGS} ";
// create and output a varible in the makefile that
// each executable will depend on. This will have all the
// libraries that the executable uses
fout << "CMAKE_DEPEND_LIBS = ";
this->OutputDependLibraries(fout);
// Now create rules for all of the executables to be built // Now create rules for all of the executables to be built
for(int i = 0; i < m_Classes.size(); i++) for(int i = 0; i < m_Classes.size(); i++)
{ {
@ -164,7 +169,9 @@ void cmUnixMakefile::OutputMakefile(const char* file)
{ {
std::string DotO = m_Classes[i].m_ClassName; std::string DotO = m_Classes[i].m_ClassName;
DotO += ".o"; DotO += ".o";
fout << m_Classes[i].m_ClassName << ": " << DotO << "\n";
fout << m_Classes[i].m_ClassName << ": " << DotO << " ";
fout << "${CMAKE_DEPEND_LIBS}\n";
fout << "\t${CXX} ${CXX_FLAGS} " fout << "\t${CXX} ${CXX_FLAGS} "
<< DotO.c_str() << " " << DotO.c_str() << " "
<< linkLibs.c_str() << linkLibs.c_str()
@ -239,3 +246,29 @@ void cmUnixMakefile::OutputMakefile(const char* file)
} }
this->OutputDepends(fout); this->OutputDepends(fout);
} }
void cmUnixMakefile::OutputDependLibraries(std::ostream& fout)
{
std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries();
std::vector<std::string>& libdirs = m_BuildFlags.GetLinkDirectories();
std::vector<std::string>::iterator dir, lib, endlibs, enddirs;
for(lib = libs.begin(); lib != libs.end(); ++lib)
{
bool found = false;
for(dir = libdirs.begin(); dir != libdirs.end() && !found; ++dir)
{
std::string expression = "LIBRARY.*=.*";
expression += lib->c_str();
if(cmSystemTools::Grep(dir->c_str(), "CMakeTargets.make", expression.c_str()))
{
std::string libpath = *dir;
libpath += "/lib";
libpath += *lib;
libpath += "${CMAKE_LIB_EXT}";
fout << libpath << " ";
found = true;
}
}
}
fout << "\n";
}

View File

@ -30,6 +30,7 @@ public:
*/ */
void OutputMakefile(const char* file); void OutputMakefile(const char* file);
protected: protected:
void OutputDependLibraries(std::ostream&);
void OutputDepends(std::ostream&); void OutputDepends(std::ostream&);
}; };