/*========================================================================= Program: CMake - Cross-Platform Makefile Generator Module: $RCSfile: cmExtraCodeBlocksGenerator.cxx,v $ Language: C++ Date: $Date: 2008-09-03 13:43:17 $ Version: $Revision: 1.18.2.1 $ Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved. Copyright (c) 2004 Alexander Neundorf neundorf@kde.org, 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 "cmExtraCodeBlocksGenerator.h" #include "cmGlobalUnixMakefileGenerator3.h" #include "cmLocalUnixMakefileGenerator3.h" #include "cmMakefile.h" #include "cmake.h" #include "cmSourceFile.h" #include "cmGeneratedFileStream.h" #include "cmTarget.h" #include "cmSystemTools.h" #include /* Some useful URLs: Homepage: http://www.codeblocks.org File format docs: http://wiki.codeblocks.org/index.php?title=File_formats_description http://wiki.codeblocks.org/index.php?title=Workspace_file http://wiki.codeblocks.org/index.php?title=Project_file Discussion: http://forums.codeblocks.org/index.php/topic,6789.0.html */ //---------------------------------------------------------------------------- void cmExtraCodeBlocksGenerator ::GetDocumentation(cmDocumentationEntry& entry, const char*) const { entry.Name = this->GetName(); entry.Brief = "Generates CodeBlocks project files."; entry.Full = "Project files for CodeBlocks will be created in the top directory " "and in every subdirectory which features a CMakeLists.txt file " "containing a PROJECT() call. " "Additionally a hierarchy of makefiles is generated into the " "build tree. The appropriate make program can build the project through " "the default make target. A \"make install\" target is also provided."; } cmExtraCodeBlocksGenerator::cmExtraCodeBlocksGenerator() :cmExternalMakefileProjectGenerator() { #if defined(_WIN32) this->SupportedGlobalGenerators.push_back("MinGW Makefiles"); // disable until somebody actually tests it: // this->SupportedGlobalGenerators.push_back("NMake Makefiles"); // this->SupportedGlobalGenerators.push_back("MSYS Makefiles"); #endif this->SupportedGlobalGenerators.push_back("Unix Makefiles"); } void cmExtraCodeBlocksGenerator::SetGlobalGenerator( cmGlobalGenerator* generator) { cmExternalMakefileProjectGenerator::SetGlobalGenerator(generator); cmGlobalUnixMakefileGenerator3* mf = (cmGlobalUnixMakefileGenerator3*) generator; mf->SetToolSupportsColor(false); mf->SetForceVerboseMakefiles(true); } void cmExtraCodeBlocksGenerator::Generate() { // for each sub project in the project create a codeblocks project for (std::map >::const_iterator it = this->GlobalGenerator->GetProjectMap().begin(); it!= this->GlobalGenerator->GetProjectMap().end(); ++it) { // create a project file this->CreateProjectFile(it->second); } } /* create the project file */ void cmExtraCodeBlocksGenerator::CreateProjectFile( const std::vector& lgs) { const cmMakefile* mf=lgs[0]->GetMakefile(); std::string outputDir=mf->GetStartOutputDirectory(); std::string projectName=mf->GetProjectName(); std::string filename=outputDir+"/"; filename+=projectName+".cbp"; std::string sessionFilename=outputDir+"/"; sessionFilename+=projectName+".layout"; this->CreateNewProjectFile(lgs, filename); } void cmExtraCodeBlocksGenerator ::CreateNewProjectFile(const std::vector& lgs, const std::string& filename) { const cmMakefile* mf=lgs[0]->GetMakefile(); cmGeneratedFileStream fout(filename.c_str()); if(!fout) { return; } // figure out the compiler std::string compiler = this->GetCBCompilerId(mf); std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); fout<<"\n" "\n" " \n" " \n" " \n" "\n"; } // 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<<" \n"; if (target!=0) { int cbTargetType = this->GetCBTargetType(target); fout<<" \n"; } // Translate the cmake compiler id into the CodeBlocks compiler id 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"; if (this->GlobalGenerator->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") { compiler = "gcc"; } return compiler; } // Translate the cmake target type into the CodeBlocks target type id 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; } // Create the command line for building the given target using the selected // make 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; }