/*============================================================================ CMake - Cross Platform Makefile Generator Copyright 2004-2009 Kitware, Inc. Copyright 2004 Alexander Neundorf (neundorf@kde.org) Distributed under the OSI-approved BSD License (the "License"); see accompanying file Copyright.txt for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License 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 "cmXMLSafe.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 std::string&) const { entry.Name = this->GetName(); entry.Brief = "Generates CodeBlocks project files."; } cmExtraCodeBlocksGenerator::cmExtraCodeBlocksGenerator() :cmExternalMakefileProjectGenerator() { #if defined(_WIN32) this->SupportedGlobalGenerators.push_back("MinGW Makefiles"); this->SupportedGlobalGenerators.push_back("NMake Makefiles"); // disable until somebody actually tests it: // this->SupportedGlobalGenerators.push_back("MSYS Makefiles"); #endif this->SupportedGlobalGenerators.push_back("Ninja"); this->SupportedGlobalGenerators.push_back("Unix Makefiles"); } 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->GetCurrentBinaryDirectory(); std::string projectName=mf->GetProjectName(); std::string filename=outputDir+"/"; filename+=projectName+".cbp"; std::string sessionFilename=outputDir+"/"; sessionFilename+=projectName+".layout"; this->CreateNewProjectFile(lgs, filename); } /* Tree is used to create a "Virtual Folder" in CodeBlocks, in which all CMake files this project depends on will be put. This means additionally to the "Sources" and "Headers" virtual folders of CodeBlocks, there will now also be a "CMake Files" virtual folder. Patch by Daniel Teske (which use C::B project files in QtCreator).*/ struct Tree { std::string path; //only one component of the path std::vector folders; std::vector files; void InsertPath(const std::vector& splitted, std::vector::size_type start, const std::string& fileName); void BuildVirtualFolder(std::string& virtualFolders) const; void BuildVirtualFolderImpl(std::string& virtualFolders, const std::string& prefix) const; void BuildUnit(std::string& unitString, const std::string& fsPath) const; void BuildUnitImpl(std::string& unitString, const std::string& virtualFolderPath, const std::string& fsPath) const; }; void Tree::InsertPath(const std::vector& splitted, std::vector::size_type start, const std::string& fileName) { if (start == splitted.size()) { files.push_back(fileName); return; } for (std::vector::iterator it = folders.begin(); it != folders.end(); ++it) { if ((*it).path == splitted[start]) { if (start + 1 < splitted.size()) { it->InsertPath(splitted, start + 1, fileName); return; } else { // last part of splitted it->files.push_back(fileName); return; } } } // Not found in folders, thus insert Tree newFolder; newFolder.path = splitted[start]; if (start + 1 < splitted.size()) { newFolder.InsertPath(splitted, start + 1, fileName); folders.push_back(newFolder); return; } else { // last part of splitted newFolder.files.push_back(fileName); folders.push_back(newFolder); return; } } void Tree::BuildVirtualFolder(std::string& virtualFolders) const { virtualFolders += "