STYLE: move the code for generating the XML for one target in a separate

function AppendTarget()
-add "all" target
-some syncing with the Eclipse generator


Alex
This commit is contained in:
Alexander Neundorf 2007-11-25 07:45:18 -05:00
parent 38896657db
commit fc86a05455
2 changed files with 85 additions and 52 deletions

View File

@ -145,7 +145,6 @@ void cmExtraCodeBlocksGenerator
" <Option compiler=\"" << compiler << "\" />\n" " <Option compiler=\"" << compiler << "\" />\n"
" <Build>\n"; " <Build>\n";
bool preinstallTargetCreated = false;
bool installTargetCreated = false; bool installTargetCreated = false;
bool installStripTargetCreated = false; bool installStripTargetCreated = false;
bool testTargetCreated = false; bool testTargetCreated = false;
@ -154,8 +153,11 @@ void cmExtraCodeBlocksGenerator
bool packageTargetCreated = false; bool packageTargetCreated = false;
bool packageSourceTargetCreated = false; bool packageSourceTargetCreated = false;
bool rebuildCacheTargetCreated = false; bool rebuildCacheTargetCreated = false;
// add all executable and library targets and some of the GLOBAL targets this->AppendTarget(fout, "all", 0, make.c_str(), mf, compiler.c_str());
// add all executable and library targets and some of the GLOBAL
// and UTILITY targets
for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin(); for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin();
lg!=lgs.end(); lg++) lg!=lgs.end(); lg++)
{ {
@ -166,13 +168,10 @@ void cmExtraCodeBlocksGenerator
{ {
switch(ti->second.GetType()) switch(ti->second.GetType())
{ {
case cmTarget::UTILITY:
case cmTarget::GLOBAL_TARGET: case cmTarget::GLOBAL_TARGET:
// only add these global targets once // only add these targets once
if ((ti->first=="preinstall") && (preinstallTargetCreated==false)) if ((ti->first=="install") && (installTargetCreated==false))
{
preinstallTargetCreated=true;
}
else if ((ti->first=="install") && (installTargetCreated==false))
{ {
installTargetCreated=true; installTargetCreated=true;
} }
@ -212,57 +211,23 @@ void cmExtraCodeBlocksGenerator
{ {
break; break;
} }
this->AppendTarget(fout, ti->first.c_str(), 0,
make.c_str(), makefile, compiler.c_str());
break;
case cmTarget::EXECUTABLE: case cmTarget::EXECUTABLE:
case cmTarget::STATIC_LIBRARY: case cmTarget::STATIC_LIBRARY:
case cmTarget::SHARED_LIBRARY: case cmTarget::SHARED_LIBRARY:
case cmTarget::MODULE_LIBRARY: case cmTarget::MODULE_LIBRARY:
{ {
int cbTargetType = this->GetCBTargetType(&ti->second); this->AppendTarget(fout, ti->first.c_str(), &ti->second,
std::string makefileName = makefile->GetStartOutputDirectory(); make.c_str(), makefile, compiler.c_str());
makefileName += "/Makefile"; std::string fastTarget = ti->first;
makefileName = cmSystemTools::ConvertToOutputPath( fastTarget += "/fast";
makefileName.c_str()); this->AppendTarget(fout, fastTarget.c_str(), &ti->second,
make.c_str(), makefile, compiler.c_str());
fout<<" <Target title=\"" << ti->first << "\">\n"
" <Option output=\"" << ti->second.GetLocation(0)
<< "\" prefix_auto=\"0\" extension_auto=\"0\" />\n"
" <Option working_dir=\"" <<makefile->GetStartOutputDirectory()
<<"\" />\n"
" <Option object_output=\"./\" />\n"
" <Option type=\"" << cbTargetType << "\" />\n"
" <Option compiler=\"" << compiler << "\" />\n"
" <Compiler>\n";
// the include directories for this target
const std::vector<std::string>& incDirs =
ti->second.GetMakefile()->GetIncludeDirectories();
for(std::vector<std::string>::const_iterator dirIt=incDirs.begin();
dirIt != incDirs.end();
++dirIt)
{
fout <<" <Add directory=\"" << dirIt->c_str() << "\" />\n";
}
fout<<" </Compiler>\n"
" <MakeCommands>\n"
" <Build command=\""
<< this->BuildMakeCommand(make, makefileName.c_str(), ti->first.c_str())
<< "\" />\n"
" <CompileFile command=\""
<< this->BuildMakeCommand(make, makefileName.c_str(),"&quot;$file&quot;")
<< "\" />\n"
" <Clean command=\""
<< this->BuildMakeCommand(make, makefileName.c_str(), "clean")
<< "\" />\n"
" <DistClean command=\""
<< this->BuildMakeCommand(make, makefileName.c_str(), "clean")
<< "\" />\n"
" </MakeCommands>\n"
" </Target>\n";
} }
break; break;
// ignore these: // ignore these:
case cmTarget::UTILITY:
case cmTarget::INSTALL_FILES: case cmTarget::INSTALL_FILES:
case cmTarget::INSTALL_PROGRAMS: case cmTarget::INSTALL_PROGRAMS:
case cmTarget::INSTALL_DIRECTORY: case cmTarget::INSTALL_DIRECTORY:
@ -320,6 +285,67 @@ void cmExtraCodeBlocksGenerator
} }
// Generate the xml code for one target.
void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
const char* targetName,
cmTarget* target,
const char* make,
const cmMakefile* makefile,
const char* compiler)
{
std::string makefileName = makefile->GetStartOutputDirectory();
makefileName += "/Makefile";
makefileName = cmSystemTools::ConvertToOutputPath(makefileName.c_str());
fout<<" <Target title=\"" << targetName << "\">\n";
if (target!=0)
{
int cbTargetType = this->GetCBTargetType(target);
fout<<" <Option output=\"" << target->GetLocation(0)
<< "\" prefix_auto=\"0\" extension_auto=\"0\" />\n"
" <Option working_dir=\""
<< makefile->GetStartOutputDirectory() << "\" />\n"
" <Option object_output=\"./\" />\n"
" <Option type=\"" << cbTargetType << "\" />\n"
" <Option compiler=\"" << compiler << "\" />\n"
" <Compiler>\n";
// the include directories for this target
const std::vector<std::string>& incDirs =
target->GetMakefile()->GetIncludeDirectories();
for(std::vector<std::string>::const_iterator dirIt=incDirs.begin();
dirIt != incDirs.end();
++dirIt)
{
fout <<" <Add directory=\"" << dirIt->c_str() << "\" />\n";
}
fout<<" </Compiler>\n";
}
else // e.g. all and the GLOBAL and UTILITY targets
{
fout<<" <Option working_dir=\""
<< makefile->GetStartOutputDirectory() << "\" />\n"
<<" <Option type=\"" << 4 << "\" />\n";
}
fout<<" <MakeCommands>\n"
" <Build command=\""
<< this->BuildMakeCommand(make, makefileName.c_str(), targetName)
<< "\" />\n"
" <CompileFile command=\""
<< this->BuildMakeCommand(make, makefileName.c_str(),"&quot;$file&quot;")
<< "\" />\n"
" <Clean command=\""
<< this->BuildMakeCommand(make, makefileName.c_str(), "clean")
<< "\" />\n"
" <DistClean command=\""
<< this->BuildMakeCommand(make, makefileName.c_str(), "clean")
<< "\" />\n"
" </MakeCommands>\n"
" </Target>\n";
}
// Translate the cmake compiler id into the CodeBlocks compiler id // Translate the cmake compiler id into the CodeBlocks compiler id
std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf) std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf)
{ {

View File

@ -23,6 +23,7 @@
class cmLocalGenerator; class cmLocalGenerator;
class cmMakefile; class cmMakefile;
class cmTarget; class cmTarget;
class cmGeneratedFileStream;
/** \class cmExtraCodeBlocksGenerator /** \class cmExtraCodeBlocksGenerator
* \brief Write CodeBlocks project files for Makefile based projects * \brief Write CodeBlocks project files for Makefile based projects
@ -55,6 +56,12 @@ private:
int GetCBTargetType(cmTarget* target); int GetCBTargetType(cmTarget* target);
std::string BuildMakeCommand(const std::string& make, const char* makefile, std::string BuildMakeCommand(const std::string& make, const char* makefile,
const char* target); const char* target);
void AppendTarget(cmGeneratedFileStream& fout,
const char* targetName,
cmTarget* target,
const char* make,
const cmMakefile* makefile,
const char* compiler);
}; };