ENH: don't hardcode gcc
-put the include dirs in the project file to enable autocompletion -prepare for nmake Alex
This commit is contained in:
parent
fc9f19b202
commit
a392c7b5b1
|
@ -24,6 +24,7 @@
|
||||||
#include "cmSourceFile.h"
|
#include "cmSourceFile.h"
|
||||||
#include "cmGeneratedFileStream.h"
|
#include "cmGeneratedFileStream.h"
|
||||||
#include "cmTarget.h"
|
#include "cmTarget.h"
|
||||||
|
#include "cmSystemTools.h"
|
||||||
|
|
||||||
#include <cmsys/SystemTools.hxx>
|
#include <cmsys/SystemTools.hxx>
|
||||||
|
|
||||||
|
@ -131,16 +132,17 @@ void cmExtraCodeBlocksGenerator
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// figure out the compiler
|
||||||
|
std::string compiler = this->GetCBCompilerId(mf);
|
||||||
std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
|
std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
|
||||||
|
|
||||||
fout<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"
|
fout<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"
|
||||||
"<CodeBlocks_project_file>\n"
|
"<CodeBlocks_project_file>\n"
|
||||||
" <FileVersion major=\"1\" minor=\"6\" />\n"
|
" <FileVersion major=\"1\" minor=\"6\" />\n"
|
||||||
" <Project>\n";
|
" <Project>\n"
|
||||||
|
" <Option title=\"" << mf->GetProjectName()<<"\" />\n"
|
||||||
fout<<" <Option title=\"" << mf->GetProjectName()<<"\" />\n"
|
|
||||||
" <Option makefile_is_custom=\"1\" />\n"
|
" <Option makefile_is_custom=\"1\" />\n"
|
||||||
" <Option compiler=\"gcc\" />\n"
|
" <Option compiler=\"" << compiler << "\" />\n"
|
||||||
" <Build>\n";
|
" <Build>\n";
|
||||||
|
|
||||||
bool installTargetCreated = false;
|
bool installTargetCreated = false;
|
||||||
|
@ -178,27 +180,39 @@ void cmExtraCodeBlocksGenerator
|
||||||
case cmTarget::STATIC_LIBRARY:
|
case cmTarget::STATIC_LIBRARY:
|
||||||
case cmTarget::SHARED_LIBRARY:
|
case cmTarget::SHARED_LIBRARY:
|
||||||
case cmTarget::MODULE_LIBRARY:
|
case cmTarget::MODULE_LIBRARY:
|
||||||
// case cmTarget::UTILITY:
|
{
|
||||||
|
int cbTargetType = this->GetCBTargetType(&ti->second);
|
||||||
|
std::string makefileName = makefile->GetStartOutputDirectory();
|
||||||
|
makefileName += "/Makefile";
|
||||||
|
makefileName = cmSystemTools::ConvertToOutputPath(
|
||||||
|
makefileName.c_str());
|
||||||
|
|
||||||
fout<<" <Target title=\"" << ti->first << "\">\n"
|
fout<<" <Target title=\"" << ti->first << "\">\n"
|
||||||
" <Option output=\""<<ti->second.GetLocation(0)
|
" <Option output=\"" << ti->second.GetLocation(0) << "\" prefix_auto=\"0\" extension_auto=\"0\" />\n"
|
||||||
<<"\" prefix_auto=\"0\" extension_auto=\"0\" />\n"
|
" <Option working_dir=\"" << makefile->GetStartOutputDirectory() <<"\" />\n"
|
||||||
" <Option working_dir=\""<<makefile->GetStartOutputDirectory()
|
" <Option type=\"" << cbTargetType << "\" />\n"
|
||||||
<<"\" />\n"
|
" <Option compiler=\"" << compiler << "\" />\n"
|
||||||
" <Option type=\"0\" />\n"
|
" <Compiler>\n";
|
||||||
" <Option compiler=\"gcc\" />\n"
|
|
||||||
" <MakeCommands>\n";
|
|
||||||
|
|
||||||
fout<<" <Build command=\""<<make<<" -f "
|
// the include directories for this target
|
||||||
<<makefile->GetStartOutputDirectory()<<"/Makefile "<<ti->first<<"\" />\n";
|
const std::vector<std::string>& incDirs =
|
||||||
fout<<" <CompileFile command=\""<<make<<" -f "
|
ti->second.GetMakefile()->GetIncludeDirectories();
|
||||||
<<makefile->GetStartOutputDirectory()<<"/Makefile "<<ti->first<<"\" />\n";
|
for(std::vector<std::string>::const_iterator dirIt=incDirs.begin();
|
||||||
fout<<" <Clean command=\""<<make<<" -f "
|
dirIt != incDirs.end();
|
||||||
<<makefile->GetStartOutputDirectory()<<"/Makefile clean\" />\n";
|
++dirIt)
|
||||||
fout<<" <DistClean command=\""<<make<<" -f "
|
{
|
||||||
<<makefile->GetStartOutputDirectory()<<"/Makefile clean\" />\n";
|
fout <<" <Add directory=\"" << dirIt->c_str() << "\" />\n";
|
||||||
|
}
|
||||||
|
|
||||||
fout<<" </MakeCommands>\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(), ti->first.c_str()) << "\" />\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";
|
" </Target>\n";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -232,7 +246,7 @@ void cmExtraCodeBlocksGenerator
|
||||||
sourceFiles[(*si)->GetFullPath()] = ti->first;
|
sourceFiles[(*si)->GetFullPath()] = ti->first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default: // intended fallthrough
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,12 +257,108 @@ void cmExtraCodeBlocksGenerator
|
||||||
sit!=sourceFiles.end();
|
sit!=sourceFiles.end();
|
||||||
++sit)
|
++sit)
|
||||||
{
|
{
|
||||||
fout<<" <Unit filename=\""<<sit->first <<"\">\n";
|
fout<<" <Unit filename=\""<<sit->first <<"\">\n"
|
||||||
fout<<" </Unit>\n";
|
" </Unit>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
fout<<" </Project>\n"
|
fout<<" </Project>\n"
|
||||||
"</CodeBlocks_project_file>\n";
|
"</CodeBlocks_project_file>\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf)
|
||||||
|
{
|
||||||
|
// figure out which language to use
|
||||||
|
// for now care only for C and C++
|
||||||
|
std::string compilerIdVar = "CMAKE_CXX_COMPILER_ID";
|
||||||
|
cmGlobalGenerator* gg=const_cast<cmGlobalGenerator*>(this->GlobalGenerator);
|
||||||
|
if (gg->GetLanguageEnabled("CXX") == false)
|
||||||
|
{
|
||||||
|
compilerIdVar = "CMAKE_C_COMPILER_ID";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string hostSystemName = mf->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME");
|
||||||
|
std::string systemName = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
|
||||||
|
std::string compilerId = mf->GetRequiredDefinition(compilerIdVar.c_str());
|
||||||
|
std::string compiler = "gcc";
|
||||||
|
if (compilerId == "MSVC")
|
||||||
|
{
|
||||||
|
compiler = "msvc";
|
||||||
|
}
|
||||||
|
else if (compilerId == "Borland")
|
||||||
|
{
|
||||||
|
compiler = "bcc";
|
||||||
|
}
|
||||||
|
else if (compilerId == "SDCC")
|
||||||
|
{
|
||||||
|
compiler = "sdcc";
|
||||||
|
}
|
||||||
|
else if (compilerId == "Intel")
|
||||||
|
{
|
||||||
|
compiler = "icc";
|
||||||
|
}
|
||||||
|
else if (compilerId == "Watcom")
|
||||||
|
{
|
||||||
|
compiler = "ow";
|
||||||
|
}
|
||||||
|
else if (compilerId == "GNU")
|
||||||
|
{
|
||||||
|
if (hostSystemName == "Windows")
|
||||||
|
{
|
||||||
|
compiler = "mingw";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
compiler = "gcc";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return compiler;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int cmExtraCodeBlocksGenerator::GetCBTargetType(cmTarget* target)
|
||||||
|
{
|
||||||
|
if ( target->GetType()==cmTarget::EXECUTABLE)
|
||||||
|
{
|
||||||
|
if ((target->GetPropertyAsBool("WIN32_EXECUTABLE"))
|
||||||
|
|| (target->GetPropertyAsBool("MACOSX_BUNDLE")))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( target->GetType()==cmTarget::STATIC_LIBRARY)
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
else if ((target->GetType()==cmTarget::SHARED_LIBRARY)
|
||||||
|
|| (target->GetType()==cmTarget::MODULE_LIBRARY))
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string cmExtraCodeBlocksGenerator::BuildMakeCommand(
|
||||||
|
const std::string& make, const char* makefile, const char* target)
|
||||||
|
{
|
||||||
|
std::string command = make;
|
||||||
|
if (strcmp(this->GlobalGenerator->GetName(), "NMake Makefiles")==0)
|
||||||
|
{
|
||||||
|
command += " /NOLOGO /f \\\"";
|
||||||
|
command += makefile;
|
||||||
|
command += "\\\" ";
|
||||||
|
command += target;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
command += " -f ";
|
||||||
|
command += makefile;
|
||||||
|
command += " ";
|
||||||
|
command += target;
|
||||||
|
}
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
class cmLocalGenerator;
|
class cmLocalGenerator;
|
||||||
class cmMakefile;
|
class cmMakefile;
|
||||||
|
class cmTarget;
|
||||||
|
|
||||||
/** \class cmExtraCodeBlocksGenerator
|
/** \class cmExtraCodeBlocksGenerator
|
||||||
* \brief Write CodeBlocks project files for Makefile based projects
|
* \brief Write CodeBlocks project files for Makefile based projects
|
||||||
|
@ -50,6 +51,10 @@ private:
|
||||||
|
|
||||||
void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
|
void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
|
||||||
const std::string& filename);
|
const std::string& filename);
|
||||||
|
std::string GetCBCompilerId(const cmMakefile* mf);
|
||||||
|
int GetCBTargetType(cmTarget* target);
|
||||||
|
std::string BuildMakeCommand(const std::string& make, const char* makefile,
|
||||||
|
const char* target);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue