/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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"
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 << "\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 << "\n";
}
void cmGlobalCodeWarriorGenerator::WriteProjectHeader(std::ostream& fout)
{
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "\n";
fout << "]>\n\n";
}
void cmGlobalCodeWarriorGenerator::WriteTargetList(std::ostream& fout)
{
fout << "\n";
unsigned int i;
// for each local generator
for (i = 0; i < m_LocalGenerators.size(); ++i)
{
static_cast(m_LocalGenerators[i])->WriteTargets(fout);
}
fout << "\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 &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 << "\n";
std::vector 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 << "" << tgtOrder[i]
<< "\n";
}
fout << "\n";
}
void cmGlobalCodeWarriorGenerator::WriteGroupList(std::ostream& fout)
{
fout << "\n";
unsigned int i;
// for each local generator
for (i = 0; i < m_LocalGenerators.size(); ++i)
{
static_cast(m_LocalGenerators[i])->WriteGroups(fout);
}
fout << "\n";
}
void cmGlobalCodeWarriorGenerator::LocalGenerate()
{
this->cmGlobalGenerator::LocalGenerate();
}