Commit 599114fc authored by Ken Martin's avatar Ken Martin
Browse files

under development

parent 9f5cf382
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Insight Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmGlobalCodeWarriorGenerator.h"
#include "cmLocalCodeWarriorGenerator.h"
#include "cmMakefile.h"
#include "cmake.h"
#include "cmTarget.h"
#include "windows.h"
void cmGlobalCodeWarriorGenerator::EnableLanguage(const char*,
cmMakefile *mf)
{
// now load the settings
if(!mf->GetDefinition("CMAKE_ROOT"))
{
cmSystemTools::Error(
"CMAKE_ROOT has not been defined, bad GUI or driver program");
return;
}
if(!this->GetLanguageEnabled("CXX"))
{
std::string fpath =
mf->GetDefinition("CMAKE_ROOT");
fpath += "/Templates/CMakeDotNetSystemConfig.cmake";
mf->ReadListFile(NULL,fpath.c_str());
this->SetLanguageEnabled("CXX");
}
}
int cmGlobalCodeWarriorGenerator::TryCompile(const char *,
const char *bindir,
const char *projectName,
const char *targetName,
std::string *output)
{
return 1;
}
///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *cmGlobalCodeWarriorGenerator::CreateLocalGenerator()
{
cmLocalGenerator *lg = new cmLocalCodeWarriorGenerator;
lg->SetGlobalGenerator(this);
return lg;
}
void cmGlobalCodeWarriorGenerator::Generate()
{
// first do the superclass method
this->cmGlobalGenerator::Generate();
// Now write out the Project File
this->OutputProject();
}
void cmGlobalCodeWarriorGenerator::OutputProject()
{
// if this is an out of source build, create the output directory
if(strcmp(m_CMakeInstance->GetStartOutputDirectory(),
m_CMakeInstance->GetHomeDirectory()) != 0)
{
if(!cmSystemTools::MakeDirectory(m_CMakeInstance->GetStartOutputDirectory()))
{
cmSystemTools::Error("Error creating output directory for Project file",
m_CMakeInstance->GetStartOutputDirectory());
}
}
// create the project file name
std::string fname;
fname = m_CMakeInstance->GetStartOutputDirectory();
fname += "/";
if(strlen(m_LocalGenerators[0]->GetMakefile()->GetProjectName()) == 0)
{
m_LocalGenerators[0]->GetMakefile()->SetProjectName("Project");
}
fname += m_LocalGenerators[0]->GetMakefile()->GetProjectName();
fname += ".xml";
std::ofstream fout(fname.c_str());
if(!fout)
{
cmSystemTools::Error("Error can not open project file for write: "
,fname.c_str());
return;
}
this->WriteProject(fout);
}
void cmGlobalCodeWarriorGenerator::WriteProject(std::ostream& fout)
{
// Write out the header for a SLN file
this->WriteProjectHeader(fout);
// start the project
fout << "<PROJECT>\n";
// write the target list
this->WriteTargetList(fout);
// write the target order
this->WriteTargetOrder(fout);
// write the group list
this->WriteGroupList(fout);
// close the project
fout << "</PROJECT>\n";
}
void cmGlobalCodeWarriorGenerator::WriteProjectHeader(std::ostream& fout)
{
fout << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n";
fout << "<?codewarrior exportversion=\"1.0.1\" ideversion=\"5.0\" ?>\n";
fout << "<!DOCTYPE PROJECT [\n";
fout << "<!ELEMENT PROJECT (TARGETLIST, TARGETORDER, GROUPLIST, DESIGNLIST?)>\n";
fout << "<!ELEMENT TARGETLIST (TARGET+)>\n";
fout << "<!ELEMENT TARGET (NAME, SETTINGLIST, FILELIST?, LINKORDER?, SEGMENTLIST?, OVERLAYGROUPLIST?, SUBTARGETLIST?, SUBPROJECTLIST?, FRAMEWORKLIST)>\n";
fout << "<!ELEMENT NAME (#PCDATA)>\n";
fout << "<!ELEMENT USERSOURCETREETYPE (#PCDATA)>\n";
fout << "<!ELEMENT PATH (#PCDATA)>\n";
fout << "<!ELEMENT FILELIST (FILE*)>\n";
fout << "<!ELEMENT FILE (PATHTYPE, PATHROOT?, ACCESSPATH?, PATH, PATHFORMAT?, ROOTFILEREF?, FILEKIND?, FILEFLAGS?)>\n";
fout << "<!ELEMENT PATHTYPE (#PCDATA)>\n";
fout << "<!ELEMENT PATHROOT (#PCDATA)>\n";
fout << "<!ELEMENT ACCESSPATH (#PCDATA)>\n";
fout << "<!ELEMENT PATHFORMAT (#PCDATA)>\n";
fout << "<!ELEMENT ROOTFILEREF (PATHTYPE, PATHROOT?, ACCESSPATH?, PATH, PATHFORMAT?)>\n";
fout << "<!ELEMENT FILEKIND (#PCDATA)>\n";
fout << "<!ELEMENT FILEFLAGS (#PCDATA)>\n";
fout << "<!ELEMENT FILEREF (TARGETNAME?, PATHTYPE, PATHROOT?, ACCESSPATH?, PATH, PATHFORMAT?)>\n";
fout << "<!ELEMENT TARGETNAME (#PCDATA)>\n";
fout << "<!ELEMENT SETTINGLIST ((SETTING|PANELDATA)+)>\n";
fout << "<!ELEMENT SETTING (NAME?, (VALUE|(SETTING+)))>\n";
fout << "<!ELEMENT PANELDATA (NAME, VALUE)>\n";
fout << "<!ELEMENT VALUE (#PCDATA)>\n";
fout << "<!ELEMENT LINKORDER (FILEREF*)>\n";
fout << "<!ELEMENT SEGMENTLIST (SEGMENT+)>\n";
fout << "<!ELEMENT SEGMENT (NAME, ATTRIBUTES?, FILEREF*)>\n";
fout << "<!ELEMENT ATTRIBUTES (#PCDATA)>\n";
fout << "<!ELEMENT OVERLAYGROUPLIST (OVERLAYGROUP+)>\n";
fout << "<!ELEMENT OVERLAYGROUP (NAME, BASEADDRESS, OVERLAY*)>\n";
fout << "<!ELEMENT BASEADDRESS (#PCDATA)>\n";
fout << "<!ELEMENT OVERLAY (NAME, FILEREF*)>\n";
fout << "<!ELEMENT SUBTARGETLIST (SUBTARGET+)>\n";
fout << "<!ELEMENT SUBTARGET (TARGETNAME, ATTRIBUTES?, FILEREF?)>\n";
fout << "<!ELEMENT SUBPROJECTLIST (SUBPROJECT+)>\n";
fout << "<!ELEMENT SUBPROJECT (FILEREF, SUBPROJECTTARGETLIST)>\n";
fout << "<!ELEMENT SUBPROJECTTARGETLIST (SUBPROJECTTARGET*)>\n";
fout << "<!ELEMENT SUBPROJECTTARGET (TARGETNAME, ATTRIBUTES?, FILEREF?)>\n";
fout << "<!ELEMENT FRAMEWORKLIST (FRAMEWORK+)>\n";
fout << "<!ELEMENT FRAMEWORK (FILEREF, LIBRARYFILE?, VERSION?)>\n";
fout << "<!ELEMENT LIBRARYFILE (FILEREF)>\n";
fout << "<!ELEMENT VERSION (#PCDATA)>\n";
fout << "<!ELEMENT TARGETORDER (ORDEREDTARGET|ORDEREDDESIGN)*>\n";
fout << "<!ELEMENT ORDEREDTARGET (NAME)>\n";
fout << "<!ELEMENT ORDEREDDESIGN (NAME, ORDEREDTARGET+)>\n";
fout << "<!ELEMENT GROUPLIST (GROUP|FILEREF)*>\n";
fout << "<!ELEMENT GROUP (NAME, (GROUP|FILEREF)*)>\n";
fout << "<!ELEMENT DESIGNLIST (DESIGN+)>\n";
fout << "<!ELEMENT DESIGN (NAME, DESIGNDATA)>\n";
fout << "<!ELEMENT DESIGNDATA (#PCDATA)>\n";
fout << "]>\n\n";
}
void cmGlobalCodeWarriorGenerator::WriteTargetList(std::ostream& fout)
{
fout << "<TARGETLIST>\n";
unsigned int i;
// for each local generator
for (i = 0; i < m_LocalGenerators.size(); ++i)
{
static_cast<cmLocalCodeWarriorGenerator *>(m_LocalGenerators[i])->WriteTargets(fout);
}
fout << "</TARGETLIST>\n";
}
cmTarget *cmGlobalCodeWarriorGenerator::GetTargetFromName(const char *tgtName)
{
// for each local generator, and each target
unsigned int i;
for(i = 0; i < m_LocalGenerators.size(); ++i)
{
cmMakefile* mf = m_LocalGenerators[i]->GetMakefile();
cmTargets &tgts = mf->GetTargets();
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
{
if (l->first == tgtName)
{
return &(l->second);
}
}
}
return 0;
}
void cmGlobalCodeWarriorGenerator::ComputeTargetOrder(
std::vector<std::string> &tgtOrder, const char *tgtName,
cmTarget const *target)
{
// if the target is already listed then we are done
if (std::find(tgtOrder.begin(),tgtOrder.end(),tgtName) != tgtOrder.end())
{
return;
}
// otherwise find all this target depends on and add them first
cmTarget::LinkLibraries::const_iterator j, jend;
j = target->GetLinkLibraries().begin();
jend = target->GetLinkLibraries().end();
for(;j!= jend; ++j)
{
if(j->first != tgtName)
{
// is the library part of this Project ?
std::string libPath = j->first + "_CMAKE_PATH";
const char* cacheValue
= m_CMakeInstance->GetCacheDefinition(libPath.c_str());
if(cacheValue)
{
// so add it to the tgtOrder vector if it isn't already there
// to do this we need the actual target
cmTarget *tgt = this->GetTargetFromName(j->first.c_str());
this->ComputeTargetOrder(tgtOrder,j->first.c_str(), tgt);
}
}
}
// finally add the target
tgtOrder.push_back(tgtName);
}
void cmGlobalCodeWarriorGenerator::WriteTargetOrder(std::ostream& fout)
{
fout << "<TARGETORDER>\n";
std::vector<std::string> tgtOrder;
unsigned int i;
// for each local generator, and each target
for(i = 0; i < m_LocalGenerators.size(); ++i)
{
cmMakefile* mf = m_LocalGenerators[i]->GetMakefile();
cmTargets &tgts = mf->GetTargets();
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
{
this->ComputeTargetOrder(tgtOrder, l->first.c_str(), &(l->second));
}
}
// now write out the target order
for(i = 0; i < tgtOrder.size(); ++i)
{
fout << "<ORDEREDTARGET><NAME>" << tgtOrder[i]
<< "</NAME></ORDEREDTARGET>\n";
}
fout << "</TARGETORDER>\n";
}
void cmGlobalCodeWarriorGenerator::WriteGroupList(std::ostream& fout)
{
fout << "<GROUPLIST>\n";
fout << "</GROUPLIST>\n";
}
void cmGlobalCodeWarriorGenerator::LocalGenerate()
{
this->cmGlobalGenerator::LocalGenerate();
}
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Insight Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmGlobalCodeWarriorGenerator_h
#define cmGlobalCodeWarriorGenerator_h
#include "cmGlobalGenerator.h"
class cmTarget;
/** \class cmGlobalCodeWarriorGenerator
* \brief Write a Unix makefiles.
*
* cmGlobalCodeWarriorGenerator manages UNIX build process for a tree
*/
class cmGlobalCodeWarriorGenerator : public cmGlobalGenerator
{
public:
///! Get the name for the generator.
virtual const char* GetName() {
return cmGlobalCodeWarriorGenerator::GetActualName();}
static const char* GetActualName() {return "Code Warrior";}
///! Create a local generator appropriate to this Global Generator
virtual cmLocalGenerator *CreateLocalGenerator();
/**
* Try to determine system infomation such as shared library
* extension, pthreads, byte order etc.
*/
virtual void EnableLanguage(const char*, cmMakefile *mf);
/**
* Try running cmake and building a file. This is used for dynalically
* loaded commands, not as part of the usual build process.
*/
virtual int TryCompile(const char *srcdir, const char *bindir,
const char *projectName, const char *targetName,
std::string *output);
/**
* Generate the all required files for building this project/tree. This
* basically creates a series of LocalGenerators for each directory and
* requests that they Generate.
*/
virtual void Generate();
/**
* Generate the required files for building this directory. This
* basically creates a single LocalGenerators and
* requests that it Generate.
*/
virtual void LocalGenerate();
/**
* Generate the DSW workspace file.
*/
virtual void OutputProject();
private:
cmTarget *GetTargetFromName(const char *tgtName);
void WriteProject(std::ostream & fout);
void WriteProjectHeader(std::ostream & fout);
void WriteTargetList(std::ostream & fout);
void WriteTargetOrder(std::ostream & fout);
void WriteGroupList(std::ostream & fout);
void ComputeTargetOrder(std::vector<std::string> &tgtOrder,
const char *tgtName, cmTarget const *tgt);
};
#endif
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Insight Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmGlobalCodeWarriorGenerator.h"
#include "cmLocalCodeWarriorGenerator.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
#include "cmSourceFile.h"
#include "cmCacheManager.h"
cmLocalCodeWarriorGenerator::cmLocalCodeWarriorGenerator()
{
}
cmLocalCodeWarriorGenerator::~cmLocalCodeWarriorGenerator()
{
}
void cmLocalCodeWarriorGenerator::Generate(bool /* fromTheTop */)
{
}
void cmLocalCodeWarriorGenerator::WriteTargets(std::ostream& fout)
{
cmTargets &tgts = m_Makefile->GetTargets();
for(cmTargets::iterator l = tgts.begin();
l != tgts.end(); l++)
{
this->WriteTarget(fout,l->first.c_str(),&(l->second));
}
}
void cmLocalCodeWarriorGenerator::WriteTarget(std::ostream& fout,
const char *tgtName,
cmTarget const *l)
{
fout << "<TARGET>\n";
fout << "<NAME>" << tgtName << "</NAME>\n";
this->WriteSettingList(fout,tgtName,l);
this->WriteFileList(fout,tgtName,l);
// this->WriteLinkOrder(fout,l);
// this->WriteSubTargetList(fout,l);
fout << "</TARGET>\n";
}
void cmLocalCodeWarriorGenerator::WriteSettingList(std::ostream& fout,
const char *tgtName,
cmTarget const *l)
{
fout << "<SETTINGLIST>\n";
// list the include paths
fout << "<SETTING><NAME>UserSearchPaths</NAME>\n";
std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
std::vector<std::string>::iterator i = includes.begin();
for(;i != includes.end(); ++i)
{
fout << "<SETTING>\n";
fout << "<SETTING><NAME>SearchPath</NAME>\n";
fout << "<SETTING><NAME>Path</NAME><VALUE>" << i->c_str() << "</VALUE></SETTING>\n";
fout << "<SETTING><NAME>PathFormat</NAME><VALUE>Generic</VALUE></SETTING>\n";
fout << "<SETTING><NAME>PathRoot</NAME><VALUE>Absolute</VALUE></SETTING>\n";
fout << "</SETTING>\n";
fout << "<SETTING><NAME>Recursive</NAME><VALUE>false</VALUE></SETTING>\n";
fout << "<SETTING><NAME>FrameworkPath</NAME><VALUE>false</VALUE></SETTING>\n";
fout << "<SETTING><NAME>HostFlags</NAME><VALUE>All</VALUE></SETTING>\n";
fout << "</SETTING>\n";
}
fout << "</SETTING>\n";
fout << "<SETTING><NAME>Targetname</NAME><VALUE>" << tgtName
<< "</VALUE></SETTING>\n";
fout << "</SETTINGLIST>\n";
}
void cmLocalCodeWarriorGenerator::WriteFileList(std::ostream& fout,
const char *tgtName,
cmTarget const *l)
{
fout << "<FILELIST>\n";
// for each file
std::vector<cmSourceFile*> const& classes = l->GetSourceFiles();
for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
i != classes.end(); i++)
{
// Add the file to the list of sources.
std::string source = (*i)->GetFullPath();
fout << "<FILE>\n";
fout << "<PATHTYPE>PathAbsolute</PATHTYPE>\n";
fout << "<PATHROOT>Absolute</PATHROOT>\n";
//fout << "<ACCESSPATH>common</ACCESSPATH>\n";
fout << "<PATH>" << source << "</PATH>\n";
fout << "<PATHFORMAT>Generic</PATHFORMAT>\n";
fout << "<FILEKIND>Text</FILEKIND>\n";
fout << "<FILEFLAGS>Debug</FILEFLAGS>\n";
fout << "</FILE>\n";
}
fout << "</FILELIST>\n";
}
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Insight Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmLocalCodeWarriorGenerator_h
#define cmLocalCodeWarriorGenerator_h
#include "cmLocalGenerator.h"
class cmMakeDepend;
class cmTarget;
class cmSourceFile;
// please remove me.... Yuck
#include "cmSourceGroup.h"
/** \class cmLocalCodeWarriorGenerator
* \brief Write a LocalUnix makefiles.
*
* cmLocalCodeWarriorGenerator produces a LocalUnix makefile from its
* member m_Makefile.
*/
class cmLocalCodeWarriorGenerator : public cmLocalGenerator
{
public:
///! Set cache only and recurse to false by default.
cmLocalCodeWarriorGenerator();
virtual ~cmLocalCodeWarriorGenerator();
/**
* Generate the makefile for this directory. fromTheTop indicates if this
* is being invoked as part of a global Generate or specific to this
* directory. The difference is that when done from the Top we might skip
* some steps to save time, such as dependency generation for the
* makefiles. This is done by a direct invocation from make.
*/
virtual void Generate(bool fromTheTop);
enum BuildType {STATIC_LIBRARY, DLL, EXECUTABLE, WIN32_EXECUTABLE, UTILITY};
/**
* Specify the type of the build: static, dll, or executable.
*/
void SetBuildType(BuildType,const char *name);
void WriteTargets(std::ostream& fout);
private:
void WriteTarget(std::ostream& fout, const char *name, cmTarget const *l);
void WriteSettingList(std::ostream& fout, const char *name,
cmTarget const *l);
void WriteFileList(std::ostream& fout, const char *name, cmTarget const *l);
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment