2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2007-07-13 08:58:43 +04:00
|
|
|
#include "cmExtraCodeBlocksGenerator.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmGeneratorTarget.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
2007-07-13 08:58:43 +04:00
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmSourceFile.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmState.h"
|
2007-08-29 18:12:09 +04:00
|
|
|
#include "cmSystemTools.h"
|
2015-07-16 22:52:35 +03:00
|
|
|
#include "cmXMLWriter.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmake.h"
|
2007-07-13 08:58:43 +04:00
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
|
|
|
#include <ostream>
|
|
|
|
#include <string.h>
|
|
|
|
#include <utility>
|
2007-07-13 08:58:43 +04:00
|
|
|
|
2007-08-28 23:13:01 +04:00
|
|
|
/* Some useful URLs:
|
2010-11-12 00:02:07 +03:00
|
|
|
Homepage:
|
2007-08-28 23:13:01 +04:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2016-07-20 19:28:39 +03:00
|
|
|
cmExtraCodeBlocksGenerator::cmExtraCodeBlocksGenerator()
|
|
|
|
: cmExternalMakefileProjectGenerator()
|
2007-07-13 08:58:43 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-20 19:28:39 +03:00
|
|
|
cmExternalMakefileProjectGeneratorFactory*
|
|
|
|
cmExtraCodeBlocksGenerator::GetFactory()
|
2007-07-13 08:58:43 +04:00
|
|
|
{
|
2016-07-20 19:28:39 +03:00
|
|
|
static cmExternalMakefileProjectGeneratorSimpleFactory<
|
|
|
|
cmExtraCodeBlocksGenerator>
|
|
|
|
factory("CodeBlocks", "Generates CodeBlocks project files.");
|
|
|
|
|
|
|
|
if (factory.GetSupportedGlobalGenerators().empty()) {
|
2007-07-18 18:19:33 +04:00
|
|
|
#if defined(_WIN32)
|
2016-07-20 19:28:39 +03:00
|
|
|
factory.AddSupportedGlobalGenerator("MinGW Makefiles");
|
|
|
|
factory.AddSupportedGlobalGenerator("NMake Makefiles");
|
2007-08-27 21:23:37 +04:00
|
|
|
// disable until somebody actually tests it:
|
2016-07-20 19:28:39 +03:00
|
|
|
// this->AddSupportedGlobalGenerator("MSYS Makefiles");
|
2012-04-07 23:40:17 +04:00
|
|
|
#endif
|
2016-07-20 19:28:39 +03:00
|
|
|
factory.AddSupportedGlobalGenerator("Ninja");
|
|
|
|
factory.AddSupportedGlobalGenerator("Unix Makefiles");
|
|
|
|
}
|
|
|
|
|
|
|
|
return &factory;
|
2007-07-13 08:58:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmExtraCodeBlocksGenerator::Generate()
|
|
|
|
{
|
2007-08-06 21:24:42 +04:00
|
|
|
// for each sub project in the project create a codeblocks project
|
2014-02-10 09:21:34 +04:00
|
|
|
for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
|
2016-05-16 17:34:04 +03:00
|
|
|
it = this->GlobalGenerator->GetProjectMap().begin();
|
|
|
|
it != this->GlobalGenerator->GetProjectMap().end(); ++it) {
|
2007-07-13 08:58:43 +04:00
|
|
|
// create a project file
|
|
|
|
this->CreateProjectFile(it->second);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-13 08:58:43 +04:00
|
|
|
}
|
|
|
|
|
2008-08-17 00:48:42 +04:00
|
|
|
/* create the project file */
|
2007-07-20 16:36:16 +04:00
|
|
|
void cmExtraCodeBlocksGenerator::CreateProjectFile(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::vector<cmLocalGenerator*>& lgs)
|
2007-07-13 08:58:43 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string outputDir = lgs[0]->GetCurrentBinaryDirectory();
|
|
|
|
std::string projectName = lgs[0]->GetProjectName();
|
2007-07-13 08:58:43 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string filename = outputDir + "/";
|
|
|
|
filename += projectName + ".cbp";
|
|
|
|
std::string sessionFilename = outputDir + "/";
|
|
|
|
sessionFilename += projectName + ".layout";
|
2007-07-13 08:58:43 +04:00
|
|
|
|
2008-08-17 00:48:42 +04:00
|
|
|
this->CreateNewProjectFile(lgs, filename);
|
2007-07-13 08:58:43 +04:00
|
|
|
}
|
|
|
|
|
2009-06-28 12:58:27 +04:00
|
|
|
/* 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
|
2010-11-12 00:02:07 +03:00
|
|
|
now also be a "CMake Files" virtual folder.
|
2009-06-28 12:58:27 +04:00
|
|
|
Patch by Daniel Teske <daniel.teske AT nokia.com> (which use C::B project
|
|
|
|
files in QtCreator).*/
|
|
|
|
struct Tree
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string path; // only one component of the path
|
2009-06-28 12:58:27 +04:00
|
|
|
std::vector<Tree> folders;
|
|
|
|
std::vector<std::string> files;
|
2010-11-12 00:02:07 +03:00
|
|
|
void InsertPath(const std::vector<std::string>& splitted,
|
|
|
|
std::vector<std::string>::size_type start,
|
2009-06-28 12:58:27 +04:00
|
|
|
const std::string& fileName);
|
2015-07-16 22:52:35 +03:00
|
|
|
void BuildVirtualFolder(cmXMLWriter& xml) const;
|
2010-11-12 00:02:07 +03:00
|
|
|
void BuildVirtualFolderImpl(std::string& virtualFolders,
|
2009-06-28 12:58:27 +04:00
|
|
|
const std::string& prefix) const;
|
2015-07-16 22:52:35 +03:00
|
|
|
void BuildUnit(cmXMLWriter& xml, const std::string& fsPath) const;
|
2016-05-16 17:34:04 +03:00
|
|
|
void BuildUnitImpl(cmXMLWriter& xml, const std::string& virtualFolderPath,
|
2009-06-28 12:58:27 +04:00
|
|
|
const std::string& fsPath) const;
|
|
|
|
};
|
|
|
|
|
2010-11-12 00:02:07 +03:00
|
|
|
void Tree::InsertPath(const std::vector<std::string>& splitted,
|
|
|
|
std::vector<std::string>::size_type start,
|
2009-06-28 12:58:27 +04:00
|
|
|
const std::string& fileName)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (start == splitted.size()) {
|
2009-06-28 12:58:27 +04:00
|
|
|
files.push_back(fileName);
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (std::vector<Tree>::iterator it = folders.begin(); it != folders.end();
|
|
|
|
++it) {
|
|
|
|
if ((*it).path == splitted[start]) {
|
|
|
|
if (start + 1 < splitted.size()) {
|
2009-06-28 12:58:27 +04:00
|
|
|
it->InsertPath(splitted, start + 1, fileName);
|
|
|
|
return;
|
|
|
|
}
|
2016-08-18 21:36:29 +03:00
|
|
|
// last part of splitted
|
|
|
|
it->files.push_back(fileName);
|
|
|
|
return;
|
2009-06-28 12:58:27 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-06-28 12:58:27 +04:00
|
|
|
// Not found in folders, thus insert
|
|
|
|
Tree newFolder;
|
2009-06-29 22:27:45 +04:00
|
|
|
newFolder.path = splitted[start];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (start + 1 < splitted.size()) {
|
2009-06-28 12:58:27 +04:00
|
|
|
newFolder.InsertPath(splitted, start + 1, fileName);
|
|
|
|
folders.push_back(newFolder);
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-08-18 21:36:29 +03:00
|
|
|
// last part of splitted
|
|
|
|
newFolder.files.push_back(fileName);
|
|
|
|
folders.push_back(newFolder);
|
|
|
|
return;
|
2009-06-28 12:58:27 +04:00
|
|
|
}
|
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
void Tree::BuildVirtualFolder(cmXMLWriter& xml) const
|
2009-06-28 12:58:27 +04:00
|
|
|
{
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.StartElement("Option");
|
|
|
|
std::string virtualFolders = "CMake Files\\;";
|
2009-06-28 12:58:27 +04:00
|
|
|
for (std::vector<Tree>::const_iterator it = folders.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
it != folders.end(); ++it) {
|
2009-06-28 12:58:27 +04:00
|
|
|
it->BuildVirtualFolderImpl(virtualFolders, "");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.Attribute("virtualFolders", virtualFolders);
|
|
|
|
xml.EndElement();
|
2009-06-28 12:58:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Tree::BuildVirtualFolderImpl(std::string& virtualFolders,
|
|
|
|
const std::string& prefix) const
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
virtualFolders += "CMake Files\\" + prefix + path + "\\;";
|
2009-06-28 12:58:27 +04:00
|
|
|
for (std::vector<Tree>::const_iterator it = folders.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
it != folders.end(); ++it) {
|
2009-06-28 12:58:27 +04:00
|
|
|
it->BuildVirtualFolderImpl(virtualFolders, prefix + path + "\\");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-06-28 12:58:27 +04:00
|
|
|
}
|
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
void Tree::BuildUnit(cmXMLWriter& xml, const std::string& fsPath) const
|
2009-06-28 12:58:27 +04:00
|
|
|
{
|
|
|
|
for (std::vector<std::string>::const_iterator it = files.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
it != files.end(); ++it) {
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.StartElement("Unit");
|
|
|
|
xml.Attribute("filename", fsPath + *it);
|
|
|
|
|
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("virtualFolder", "CMake Files\\");
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.EndElement();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-06-28 12:58:27 +04:00
|
|
|
for (std::vector<Tree>::const_iterator it = folders.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
it != folders.end(); ++it) {
|
2015-07-16 22:52:35 +03:00
|
|
|
it->BuildUnitImpl(xml, "", fsPath);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-06-28 12:58:27 +04:00
|
|
|
}
|
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
void Tree::BuildUnitImpl(cmXMLWriter& xml,
|
2009-06-28 12:58:27 +04:00
|
|
|
const std::string& virtualFolderPath,
|
|
|
|
const std::string& fsPath) const
|
|
|
|
{
|
|
|
|
for (std::vector<std::string>::const_iterator it = files.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
it != files.end(); ++it) {
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.StartElement("Unit");
|
|
|
|
xml.Attribute("filename", fsPath + path + "/" + *it);
|
|
|
|
|
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("virtualFolder",
|
2016-05-16 17:34:04 +03:00
|
|
|
"CMake Files\\" + virtualFolderPath + path + "\\");
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.EndElement();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-06-28 12:58:27 +04:00
|
|
|
for (std::vector<Tree>::const_iterator it = folders.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
it != folders.end(); ++it) {
|
|
|
|
it->BuildUnitImpl(xml, virtualFolderPath + path + "\\",
|
|
|
|
fsPath + path + "/");
|
|
|
|
}
|
2009-06-28 12:58:27 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
|
|
|
|
const std::vector<cmLocalGenerator*>& lgs, const std::string& filename)
|
2007-07-13 08:58:43 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const cmMakefile* mf = lgs[0]->GetMakefile();
|
2007-07-13 08:58:43 +04:00
|
|
|
cmGeneratedFileStream fout(filename.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fout) {
|
2007-07-13 08:58:43 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-13 08:58:43 +04:00
|
|
|
|
2009-06-28 12:58:27 +04:00
|
|
|
Tree tree;
|
|
|
|
|
|
|
|
// build tree of virtual folders
|
2014-02-10 09:21:34 +04:00
|
|
|
for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
|
2016-05-16 17:34:04 +03:00
|
|
|
it = this->GlobalGenerator->GetProjectMap().begin();
|
|
|
|
it != this->GlobalGenerator->GetProjectMap().end(); ++it) {
|
2009-10-12 21:37:09 +04:00
|
|
|
// Collect all files
|
|
|
|
std::vector<std::string> listFiles;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmLocalGenerator*>::const_iterator jt =
|
|
|
|
it->second.begin();
|
|
|
|
jt != it->second.end(); ++jt) {
|
|
|
|
const std::vector<std::string>& files =
|
|
|
|
(*jt)->GetMakefile()->GetListFiles();
|
2009-10-12 21:37:09 +04:00
|
|
|
listFiles.insert(listFiles.end(), files.begin(), files.end());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-06-28 12:58:27 +04:00
|
|
|
|
2009-10-12 21:37:09 +04:00
|
|
|
// Convert
|
|
|
|
for (std::vector<std::string>::const_iterator jt = listFiles.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
jt != listFiles.end(); ++jt) {
|
2011-07-30 01:24:21 +04:00
|
|
|
// don't put cmake's own files into the project (#12110):
|
2016-05-16 17:34:04 +03:00
|
|
|
if (jt->find(cmSystemTools::GetCMakeRoot()) == 0) {
|
2011-07-30 01:24:21 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-07-30 01:24:21 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& relative = cmSystemTools::RelativePath(
|
|
|
|
it->second[0]->GetSourceDirectory(), jt->c_str());
|
2009-10-12 21:44:42 +04:00
|
|
|
std::vector<std::string> splitted;
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::SplitPath(relative, splitted, false);
|
2009-10-12 21:44:42 +04:00
|
|
|
// Split filename from path
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string fileName = *(splitted.end() - 1);
|
2009-10-12 21:44:42 +04:00
|
|
|
splitted.erase(splitted.end() - 1, splitted.end());
|
|
|
|
|
|
|
|
// We don't want paths with CMakeFiles in them
|
|
|
|
// or do we?
|
|
|
|
// In speedcrunch those where purely internal
|
2016-05-27 00:05:30 +03:00
|
|
|
if (!splitted.empty() &&
|
2016-05-16 17:34:04 +03:00
|
|
|
relative.find("CMakeFiles") == std::string::npos) {
|
2009-10-12 21:44:42 +04:00
|
|
|
tree.InsertPath(splitted, 1, fileName);
|
|
|
|
}
|
2009-06-28 12:58:27 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-06-28 12:58:27 +04:00
|
|
|
|
2007-08-29 18:12:09 +04:00
|
|
|
// figure out the compiler
|
|
|
|
std::string compiler = this->GetCBCompilerId(mf);
|
2007-07-13 08:58:43 +04:00
|
|
|
std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string makeArgs =
|
|
|
|
mf->GetSafeDefinition("CMAKE_CODEBLOCKS_MAKE_ARGUMENTS");
|
2007-07-13 08:58:43 +04:00
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
cmXMLWriter xml(fout);
|
|
|
|
xml.StartDocument();
|
|
|
|
xml.StartElement("CodeBlocks_project_file");
|
|
|
|
|
|
|
|
xml.StartElement("FileVersion");
|
|
|
|
xml.Attribute("major", 1);
|
|
|
|
xml.Attribute("minor", 6);
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("Project");
|
|
|
|
|
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("title", lgs[0]->GetProjectName());
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("makefile_is_custom", 1);
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("compiler", compiler);
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
// Now build a virtual tree
|
|
|
|
tree.BuildVirtualFolder(xml);
|
|
|
|
|
|
|
|
xml.StartElement("Build");
|
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
this->AppendTarget(xml, "all", CM_NULLPTR, make.c_str(), lgs[0],
|
|
|
|
compiler.c_str(), makeArgs);
|
2007-11-25 15:45:18 +03:00
|
|
|
|
2010-11-12 00:02:07 +03:00
|
|
|
// add all executable and library targets and some of the GLOBAL
|
2007-11-25 15:45:18 +03:00
|
|
|
// and UTILITY targets
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin();
|
|
|
|
lg != lgs.end(); lg++) {
|
|
|
|
std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets();
|
2015-10-18 18:06:14 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
ti != targets.end(); ti++) {
|
2015-10-18 18:06:14 +03:00
|
|
|
std::string targetName = (*ti)->GetName();
|
2016-05-16 17:34:04 +03:00
|
|
|
switch ((*ti)->GetType()) {
|
|
|
|
case cmState::GLOBAL_TARGET: {
|
2010-11-12 00:02:07 +03:00
|
|
|
// Only add the global targets from CMAKE_BINARY_DIR,
|
2009-10-12 21:44:42 +04:00
|
|
|
// not from the subdirs
|
2015-09-25 01:13:20 +03:00
|
|
|
if (strcmp((*lg)->GetCurrentBinaryDirectory(),
|
2016-05-16 17:34:04 +03:00
|
|
|
(*lg)->GetBinaryDirectory()) == 0) {
|
2016-06-27 23:44:16 +03:00
|
|
|
this->AppendTarget(xml, targetName, CM_NULLPTR, make.c_str(), *lg,
|
2016-05-16 17:34:04 +03:00
|
|
|
compiler.c_str(), makeArgs);
|
2009-10-12 21:44:42 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} break;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::UTILITY:
|
2009-10-12 21:44:42 +04:00
|
|
|
// Add all utility targets, except the Nightly/Continuous/
|
|
|
|
// Experimental-"sub"targets as e.g. NightlyStart
|
2016-05-16 17:34:04 +03:00
|
|
|
if (((targetName.find("Nightly") == 0) &&
|
|
|
|
(targetName != "Nightly")) ||
|
|
|
|
((targetName.find("Continuous") == 0) &&
|
|
|
|
(targetName != "Continuous")) ||
|
|
|
|
((targetName.find("Experimental") == 0) &&
|
|
|
|
(targetName != "Experimental"))) {
|
2007-07-13 08:58:43 +04:00
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-10-12 21:44:42 +04:00
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
this->AppendTarget(xml, targetName, CM_NULLPTR, make.c_str(), *lg,
|
2016-05-16 17:34:04 +03:00
|
|
|
compiler.c_str(), makeArgs);
|
2009-10-12 21:44:42 +04:00
|
|
|
break;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::EXECUTABLE:
|
|
|
|
case cmState::STATIC_LIBRARY:
|
|
|
|
case cmState::SHARED_LIBRARY:
|
|
|
|
case cmState::MODULE_LIBRARY:
|
2016-05-16 17:34:04 +03:00
|
|
|
case cmState::OBJECT_LIBRARY: {
|
2015-10-18 18:06:14 +03:00
|
|
|
cmGeneratorTarget* gt = *ti;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->AppendTarget(xml, targetName, gt, make.c_str(), *lg,
|
|
|
|
compiler.c_str(), makeArgs);
|
2015-10-18 18:06:14 +03:00
|
|
|
std::string fastTarget = targetName;
|
2009-10-12 21:44:42 +04:00
|
|
|
fastTarget += "/fast";
|
2016-05-16 17:34:04 +03:00
|
|
|
this->AppendTarget(xml, fastTarget, gt, make.c_str(), *lg,
|
|
|
|
compiler.c_str(), makeArgs);
|
|
|
|
} break;
|
2009-10-12 21:44:42 +04:00
|
|
|
default:
|
|
|
|
break;
|
2007-07-13 08:58:43 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-13 08:58:43 +04:00
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.EndElement(); // Build
|
2007-08-29 18:12:09 +04:00
|
|
|
|
2015-03-06 11:48:33 +03:00
|
|
|
// Collect all used source files in the project.
|
|
|
|
// Keep a list of C/C++ source files which might have an acompanying header
|
|
|
|
// that should be looked for.
|
|
|
|
typedef std::map<std::string, CbpUnit> all_files_map_t;
|
|
|
|
all_files_map_t allFiles;
|
|
|
|
std::vector<std::string> cFiles;
|
|
|
|
|
2015-10-24 15:58:23 +03:00
|
|
|
std::vector<std::string> srcExts =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions();
|
2015-10-24 15:58:23 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin();
|
|
|
|
lg != lgs.end(); lg++) {
|
|
|
|
cmMakefile* makefile = (*lg)->GetMakefile();
|
|
|
|
std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets();
|
2015-10-18 18:06:14 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
ti != targets.end(); ti++) {
|
|
|
|
switch ((*ti)->GetType()) {
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::EXECUTABLE:
|
|
|
|
case cmState::STATIC_LIBRARY:
|
|
|
|
case cmState::SHARED_LIBRARY:
|
|
|
|
case cmState::MODULE_LIBRARY:
|
|
|
|
case cmState::OBJECT_LIBRARY:
|
|
|
|
case cmState::UTILITY: // can have sources since 2.6.3
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2013-07-14 20:22:57 +04:00
|
|
|
std::vector<cmSourceFile*> sources;
|
2015-10-18 18:06:14 +03:00
|
|
|
cmGeneratorTarget* gt = *ti;
|
2015-08-29 18:51:15 +03:00
|
|
|
gt->GetSourceFiles(sources,
|
2016-05-16 17:34:04 +03:00
|
|
|
makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
|
|
|
|
for (std::vector<cmSourceFile*>::const_iterator si = sources.begin();
|
|
|
|
si != sources.end(); si++) {
|
2016-06-16 09:39:07 +03:00
|
|
|
// don't add source files from UTILITY target which have the
|
|
|
|
// GENERATED property set:
|
|
|
|
if (gt->GetType() == cmState::UTILITY &&
|
|
|
|
(*si)->GetPropertyAsBool("GENERATED")) {
|
2011-02-14 00:53:43 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-14 00:53:43 +03:00
|
|
|
|
2009-03-11 00:34:18 +03:00
|
|
|
// check whether it is a C/C++ implementation file
|
|
|
|
bool isCFile = false;
|
2014-02-04 06:20:56 +04:00
|
|
|
std::string lang = (*si)->GetLanguage();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lang == "C" || lang == "CXX") {
|
2014-02-25 05:47:20 +04:00
|
|
|
std::string srcext = (*si)->GetExtension();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator ext =
|
|
|
|
srcExts.begin();
|
|
|
|
ext != srcExts.end(); ++ext) {
|
|
|
|
if (srcext == *ext) {
|
2009-03-11 00:34:18 +03:00
|
|
|
isCFile = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-03-11 00:34:18 +03:00
|
|
|
|
2015-03-06 11:48:33 +03:00
|
|
|
std::string fullPath = (*si)->GetFullPath();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (isCFile) {
|
2015-03-06 11:48:33 +03:00
|
|
|
cFiles.push_back(fullPath);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-03-06 11:48:33 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
CbpUnit& cbpUnit = allFiles[fullPath];
|
2015-10-21 22:38:24 +03:00
|
|
|
cbpUnit.Targets.push_back(*ti);
|
2007-07-13 08:58:43 +04:00
|
|
|
}
|
2007-08-29 18:12:09 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
default: // intended fallthrough
|
|
|
|
break;
|
2007-07-13 08:58:43 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-08-29 18:12:09 +04:00
|
|
|
|
2015-10-24 15:58:23 +03:00
|
|
|
std::vector<std::string> headerExts =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
|
2015-10-24 15:58:23 +03:00
|
|
|
|
2009-03-08 22:33:58 +03:00
|
|
|
// The following loop tries to add header files matching to implementation
|
2015-03-06 11:48:33 +03:00
|
|
|
// files to the project. It does that by iterating over all
|
|
|
|
// C/C++ source files,
|
2010-11-12 00:02:07 +03:00
|
|
|
// replacing the file name extension with ".h" and checks whether such a
|
2009-03-08 22:33:58 +03:00
|
|
|
// file exists. If it does, it is inserted into the map of files.
|
|
|
|
// A very similar version of that code exists also in the kdevelop
|
|
|
|
// project generator.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator sit = cFiles.begin();
|
|
|
|
sit != cFiles.end(); ++sit) {
|
2015-03-06 11:48:33 +03:00
|
|
|
std::string const& fileName = *sit;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string headerBasename = cmSystemTools::GetFilenamePath(fileName);
|
|
|
|
headerBasename += "/";
|
|
|
|
headerBasename += cmSystemTools::GetFilenameWithoutExtension(fileName);
|
2009-03-08 22:33:58 +03:00
|
|
|
|
|
|
|
// check if there's a matching header around
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator ext = headerExts.begin();
|
|
|
|
ext != headerExts.end(); ++ext) {
|
|
|
|
std::string hname = headerBasename;
|
2009-03-08 22:33:58 +03:00
|
|
|
hname += ".";
|
|
|
|
hname += *ext;
|
2009-03-11 00:34:18 +03:00
|
|
|
// if it's already in the set, don't check if it exists on disk
|
2016-05-16 17:34:04 +03:00
|
|
|
if (allFiles.find(hname) != allFiles.end()) {
|
2009-03-11 00:34:18 +03:00
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-03-11 00:34:18 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(hname.c_str())) {
|
2015-03-06 11:48:33 +03:00
|
|
|
allFiles[hname].Targets = allFiles[fileName].Targets;
|
2009-03-08 22:33:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-03-08 22:33:58 +03:00
|
|
|
|
2009-03-11 00:34:18 +03:00
|
|
|
// insert all source files in the CodeBlocks project
|
2016-05-16 17:34:04 +03:00
|
|
|
for (all_files_map_t::const_iterator sit = allFiles.begin();
|
|
|
|
sit != allFiles.end(); ++sit) {
|
2015-03-06 11:48:33 +03:00
|
|
|
std::string const& unitFilename = sit->first;
|
|
|
|
CbpUnit const& unit = sit->second;
|
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.StartElement("Unit");
|
|
|
|
xml.Attribute("filename", unitFilename);
|
2015-03-06 11:48:33 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<const cmGeneratorTarget*>::const_iterator ti =
|
|
|
|
unit.Targets.begin();
|
|
|
|
ti != unit.Targets.end(); ++ti) {
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("target", (*ti)->GetName());
|
|
|
|
xml.EndElement();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-03-06 11:48:33 +03:00
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.EndElement();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-08-29 18:12:09 +04:00
|
|
|
|
2009-06-28 12:58:27 +04:00
|
|
|
// Add CMakeLists.txt
|
2015-07-16 22:52:35 +03:00
|
|
|
tree.BuildUnit(xml, std::string(mf->GetHomeDirectory()) + "/");
|
2009-06-28 12:58:27 +04:00
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.EndElement(); // Project
|
|
|
|
xml.EndElement(); // CodeBlocks_project_file
|
|
|
|
xml.EndDocument();
|
2007-08-29 18:12:09 +04:00
|
|
|
}
|
|
|
|
|
2012-04-09 16:53:47 +04:00
|
|
|
// Write a dummy file for OBJECT libraries, so C::B can reference some file
|
|
|
|
std::string cmExtraCodeBlocksGenerator::CreateDummyTargetFile(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalGenerator* lg, cmGeneratorTarget* target) const
|
2012-04-09 16:53:47 +04:00
|
|
|
{
|
|
|
|
// this file doesn't seem to be used by C::B in custom makefile mode,
|
|
|
|
// but we generate a unique file for each OBJECT library so in case
|
|
|
|
// C::B uses it in some way, the targets don't interfere with each other.
|
2015-09-25 01:13:20 +03:00
|
|
|
std::string filename = lg->GetCurrentBinaryDirectory();
|
2012-04-09 16:53:47 +04:00
|
|
|
filename += "/";
|
2015-10-09 23:27:46 +03:00
|
|
|
filename += lg->GetTargetDirectory(target);
|
2012-04-09 16:53:47 +04:00
|
|
|
filename += "/";
|
|
|
|
filename += target->GetName();
|
|
|
|
filename += ".objlib";
|
|
|
|
cmGeneratedFileStream fout(filename.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (fout) {
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2012-04-09 16:53:47 +04:00
|
|
|
fout << "# This is a dummy file for the OBJECT library "
|
|
|
|
<< target->GetName()
|
|
|
|
<< " for the CMake CodeBlocks project generator.\n"
|
|
|
|
<< "# Don't edit, this file will be overwritten.\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-04-09 16:53:47 +04:00
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2007-11-25 15:45:18 +03:00
|
|
|
// Generate the xml code for one target.
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmExtraCodeBlocksGenerator::AppendTarget(
|
|
|
|
cmXMLWriter& xml, const std::string& targetName, cmGeneratorTarget* target,
|
|
|
|
const char* make, const cmLocalGenerator* lg, const char* compiler,
|
|
|
|
const std::string& makeFlags)
|
2007-11-25 15:45:18 +03:00
|
|
|
{
|
2015-06-06 14:00:51 +03:00
|
|
|
cmMakefile const* makefile = lg->GetMakefile();
|
2015-09-25 01:13:20 +03:00
|
|
|
std::string makefileName = lg->GetCurrentBinaryDirectory();
|
2007-11-25 15:45:18 +03:00
|
|
|
makefileName += "/Makefile";
|
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.StartElement("Target");
|
|
|
|
xml.Attribute("title", targetName);
|
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
if (target != CM_NULLPTR) {
|
2015-10-21 22:38:24 +03:00
|
|
|
int cbTargetType = this->GetCBTargetType(target);
|
2015-09-25 01:13:20 +03:00
|
|
|
std::string workingDir = lg->GetCurrentBinaryDirectory();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetType() == cmState::EXECUTABLE) {
|
2009-09-26 12:26:28 +04:00
|
|
|
// Determine the directory where the executable target is created, and
|
|
|
|
// set the working directory to this dir.
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* runtimeOutputDir =
|
|
|
|
makefile->GetDefinition("CMAKE_RUNTIME_OUTPUT_DIRECTORY");
|
2016-06-27 23:44:16 +03:00
|
|
|
if (runtimeOutputDir != CM_NULLPTR) {
|
2009-09-26 12:26:28 +04:00
|
|
|
workingDir = runtimeOutputDir;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
const char* executableOutputDir =
|
|
|
|
makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
|
2016-06-27 23:44:16 +03:00
|
|
|
if (executableOutputDir != CM_NULLPTR) {
|
2009-09-26 12:26:28 +04:00
|
|
|
workingDir = executableOutputDir;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-26 12:26:28 +04:00
|
|
|
|
2014-06-23 17:34:38 +04:00
|
|
|
std::string buildType = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
2012-04-09 16:53:47 +04:00
|
|
|
std::string location;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetType() == cmState::OBJECT_LIBRARY) {
|
|
|
|
location =
|
|
|
|
this->CreateDummyTargetFile(const_cast<cmLocalGenerator*>(lg), target);
|
|
|
|
} else {
|
2015-10-09 23:27:46 +03:00
|
|
|
location = target->GetLocation(buildType);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-03-31 18:01:37 +04:00
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("output", location);
|
|
|
|
xml.Attribute("prefix_auto", 0);
|
|
|
|
xml.Attribute("extension_auto", 0);
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("working_dir", workingDir);
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("object_output", "./");
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("type", cbTargetType);
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("compiler", compiler);
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("Compiler");
|
2011-07-30 01:51:31 +04:00
|
|
|
|
|
|
|
// the compilerdefines for this target
|
2013-06-06 20:13:35 +04:00
|
|
|
std::vector<std::string> cdefs;
|
2015-10-09 23:27:46 +03:00
|
|
|
target->GetCompileDefinitions(cdefs, buildType, "C");
|
2012-09-21 10:51:42 +04:00
|
|
|
|
2013-06-06 20:13:35 +04:00
|
|
|
// Expand the list.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator di = cdefs.begin();
|
|
|
|
di != cdefs.end(); ++di) {
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.StartElement("Add");
|
|
|
|
xml.Attribute("option", "-D" + *di);
|
|
|
|
xml.EndElement();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-07-30 01:51:31 +04:00
|
|
|
|
2012-09-21 10:50:50 +04:00
|
|
|
// the include directories for this target
|
2016-06-14 18:16:57 +03:00
|
|
|
std::vector<std::string> allIncludeDirs;
|
2012-09-21 10:50:50 +04:00
|
|
|
|
|
|
|
std::vector<std::string> includes;
|
2015-10-09 23:27:46 +03:00
|
|
|
lg->GetIncludeDirectories(includes, target, "C", buildType);
|
2014-11-25 18:33:00 +03:00
|
|
|
|
2016-06-14 18:16:57 +03:00
|
|
|
allIncludeDirs.insert(allIncludeDirs.end(), includes.begin(),
|
|
|
|
includes.end());
|
2012-09-21 10:50:50 +04:00
|
|
|
|
|
|
|
std::string systemIncludeDirs = makefile->GetSafeDefinition(
|
2016-08-17 23:45:06 +03:00
|
|
|
"CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!systemIncludeDirs.empty()) {
|
2012-09-21 10:50:50 +04:00
|
|
|
std::vector<std::string> dirs;
|
2014-03-11 03:04:11 +04:00
|
|
|
cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
|
2016-06-14 18:16:57 +03:00
|
|
|
allIncludeDirs.insert(allIncludeDirs.end(), dirs.begin(), dirs.end());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-08-02 03:46:39 +04:00
|
|
|
|
2012-09-21 10:50:50 +04:00
|
|
|
systemIncludeDirs = makefile->GetSafeDefinition(
|
2016-08-17 23:45:06 +03:00
|
|
|
"CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!systemIncludeDirs.empty()) {
|
2012-09-21 10:50:50 +04:00
|
|
|
std::vector<std::string> dirs;
|
2014-03-11 03:04:11 +04:00
|
|
|
cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
|
2016-06-14 18:16:57 +03:00
|
|
|
allIncludeDirs.insert(allIncludeDirs.end(), dirs.begin(), dirs.end());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-08-02 03:46:39 +04:00
|
|
|
|
2016-06-14 18:16:57 +03:00
|
|
|
std::vector<std::string>::const_iterator end =
|
|
|
|
cmRemoveDuplicates(allIncludeDirs);
|
|
|
|
|
|
|
|
for (std::vector<std::string>::const_iterator i = allIncludeDirs.begin();
|
|
|
|
i != end; ++i) {
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.StartElement("Add");
|
2016-06-14 18:16:57 +03:00
|
|
|
xml.Attribute("directory", *i);
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.EndElement();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-21 10:50:50 +04:00
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.EndElement(); // Compiler
|
2016-05-16 17:34:04 +03:00
|
|
|
} else // e.g. all and the GLOBAL and UTILITY targets
|
|
|
|
{
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("working_dir", lg->GetCurrentBinaryDirectory());
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("Option");
|
|
|
|
xml.Attribute("type", 4);
|
|
|
|
xml.EndElement();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-16 22:52:35 +03:00
|
|
|
|
|
|
|
xml.StartElement("MakeCommands");
|
|
|
|
|
|
|
|
xml.StartElement("Build");
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Attribute("command", this->BuildMakeCommand(make, makefileName.c_str(),
|
|
|
|
targetName, makeFlags));
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("CompileFile");
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Attribute("command", this->BuildMakeCommand(make, makefileName.c_str(),
|
|
|
|
"\"$file\"", makeFlags));
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.EndElement();
|
2010-11-12 00:02:07 +03:00
|
|
|
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.StartElement("Clean");
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Attribute("command", this->BuildMakeCommand(make, makefileName.c_str(),
|
|
|
|
"clean", makeFlags));
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("DistClean");
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Attribute("command", this->BuildMakeCommand(make, makefileName.c_str(),
|
|
|
|
"clean", makeFlags));
|
2015-07-16 22:52:35 +03:00
|
|
|
xml.EndElement();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.EndElement(); // MakeCommands
|
|
|
|
xml.EndElement(); // Target
|
2007-11-25 15:45:18 +03:00
|
|
|
}
|
|
|
|
|
2007-11-25 13:26:58 +03:00
|
|
|
// Translate the cmake compiler id into the CodeBlocks compiler id
|
2007-08-29 18:12:09 +04:00
|
|
|
std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf)
|
|
|
|
{
|
|
|
|
// figure out which language to use
|
2016-02-12 02:00:10 +03:00
|
|
|
// for now care only for C, C++, and Fortran
|
|
|
|
|
|
|
|
// projects with C/C++ and Fortran are handled as C/C++ projects
|
|
|
|
bool pureFortran = false;
|
|
|
|
std::string compilerIdVar;
|
2016-06-02 00:29:53 +03:00
|
|
|
if (this->GlobalGenerator->GetLanguageEnabled("CXX")) {
|
2016-02-12 02:00:10 +03:00
|
|
|
compilerIdVar = "CMAKE_CXX_COMPILER_ID";
|
2016-06-02 00:29:53 +03:00
|
|
|
} else if (this->GlobalGenerator->GetLanguageEnabled("C")) {
|
2007-08-29 18:12:09 +04:00
|
|
|
compilerIdVar = "CMAKE_C_COMPILER_ID";
|
2016-06-02 00:29:53 +03:00
|
|
|
} else if (this->GlobalGenerator->GetLanguageEnabled("Fortran")) {
|
2016-02-12 02:00:10 +03:00
|
|
|
compilerIdVar = "CMAKE_Fortran_COMPILER_ID";
|
|
|
|
pureFortran = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-08-29 18:12:09 +04:00
|
|
|
|
2014-03-11 03:04:11 +04:00
|
|
|
std::string compilerId = mf->GetSafeDefinition(compilerIdVar);
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string compiler = "gcc"; // default to gcc
|
|
|
|
if (compilerId == "MSVC") {
|
2016-06-02 00:29:53 +03:00
|
|
|
if (mf->IsDefinitionSet("MSVC10")) {
|
2016-02-12 02:00:10 +03:00
|
|
|
compiler = "msvc10";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2016-02-12 02:00:10 +03:00
|
|
|
compiler = "msvc8";
|
2007-08-29 18:12:09 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (compilerId == "Borland") {
|
2007-08-29 18:12:09 +04:00
|
|
|
compiler = "bcc";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (compilerId == "SDCC") {
|
2007-08-29 18:12:09 +04:00
|
|
|
compiler = "sdcc";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (compilerId == "Intel") {
|
|
|
|
if (pureFortran && mf->IsDefinitionSet("WIN32")) {
|
2016-02-12 02:00:10 +03:00
|
|
|
compiler = "ifcwin"; // Intel Fortran for Windows (known by cbFortran)
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2016-02-12 02:00:10 +03:00
|
|
|
compiler = "icc";
|
2007-08-29 18:12:09 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (compilerId == "Watcom" || compilerId == "OpenWatcom") {
|
2007-08-29 18:12:09 +04:00
|
|
|
compiler = "ow";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (compilerId == "Clang") {
|
2016-02-12 02:00:10 +03:00
|
|
|
compiler = "clang";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (compilerId == "PGI") {
|
|
|
|
if (pureFortran) {
|
2016-02-12 02:00:10 +03:00
|
|
|
compiler = "pgifortran";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2016-02-12 02:00:10 +03:00
|
|
|
compiler = "pgi"; // does not exist as default in CodeBlocks 16.01
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (compilerId == "GNU") {
|
|
|
|
if (pureFortran) {
|
2016-02-12 02:00:10 +03:00
|
|
|
compiler = "gfortran";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2016-02-12 02:00:10 +03:00
|
|
|
compiler = "gcc";
|
2007-08-29 18:12:09 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-08-29 18:12:09 +04:00
|
|
|
return compiler;
|
|
|
|
}
|
|
|
|
|
2007-11-25 13:26:58 +03:00
|
|
|
// Translate the cmake target type into the CodeBlocks target type id
|
2015-10-21 22:38:24 +03:00
|
|
|
int cmExtraCodeBlocksGenerator::GetCBTargetType(cmGeneratorTarget* target)
|
2007-08-29 18:12:09 +04:00
|
|
|
{
|
2016-08-18 21:36:29 +03:00
|
|
|
switch (target->GetType()) {
|
|
|
|
case cmState::EXECUTABLE:
|
|
|
|
if ((target->GetPropertyAsBool("WIN32_EXECUTABLE")) ||
|
|
|
|
(target->GetPropertyAsBool("MACOSX_BUNDLE"))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2007-08-29 18:12:09 +04:00
|
|
|
return 1;
|
2016-08-18 21:36:29 +03:00
|
|
|
case cmState::STATIC_LIBRARY:
|
|
|
|
case cmState::OBJECT_LIBRARY:
|
|
|
|
return 2;
|
|
|
|
case cmState::SHARED_LIBRARY:
|
|
|
|
case cmState::MODULE_LIBRARY:
|
|
|
|
return 3;
|
|
|
|
default:
|
|
|
|
return 4;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-13 08:58:43 +04:00
|
|
|
}
|
|
|
|
|
2007-11-25 13:26:58 +03:00
|
|
|
// Create the command line for building the given target using the selected
|
|
|
|
// make
|
2007-08-29 18:12:09 +04:00
|
|
|
std::string cmExtraCodeBlocksGenerator::BuildMakeCommand(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& make, const char* makefile, const std::string& target,
|
|
|
|
const std::string& makeFlags)
|
2007-08-29 18:12:09 +04:00
|
|
|
{
|
|
|
|
std::string command = make;
|
2016-05-27 00:05:30 +03:00
|
|
|
if (!makeFlags.empty()) {
|
2016-02-24 00:37:44 +03:00
|
|
|
command += " ";
|
|
|
|
command += makeFlags;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-02-24 00:37:44 +03:00
|
|
|
|
2014-02-25 02:36:27 +04:00
|
|
|
std::string generator = this->GlobalGenerator->GetName();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (generator == "NMake Makefiles") {
|
2014-01-14 02:15:26 +04:00
|
|
|
// For Windows ConvertToOutputPath already adds quotes when required.
|
|
|
|
// These need to be escaped, see
|
2016-08-12 22:06:35 +03:00
|
|
|
// https://gitlab.kitware.com/cmake/cmake/issues/13952
|
2010-01-24 23:11:58 +03:00
|
|
|
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
|
2014-01-14 02:15:26 +04:00
|
|
|
command += " /NOLOGO /f ";
|
2015-07-16 22:52:35 +03:00
|
|
|
command += makefileName;
|
2010-11-12 00:06:09 +03:00
|
|
|
command += " VERBOSE=1 ";
|
2007-08-29 18:12:09 +04:00
|
|
|
command += target;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (generator == "MinGW Makefiles") {
|
2010-11-12 00:02:07 +03:00
|
|
|
// no escaping of spaces in this case, see
|
2016-08-12 22:06:35 +03:00
|
|
|
// https://gitlab.kitware.com/cmake/cmake/issues/10014
|
2010-11-12 00:02:07 +03:00
|
|
|
std::string makefileName = makefile;
|
2015-07-16 22:52:35 +03:00
|
|
|
command += " -f \"";
|
2010-01-24 23:11:58 +03:00
|
|
|
command += makefileName;
|
2015-07-16 22:52:35 +03:00
|
|
|
command += "\" ";
|
2010-11-12 00:06:09 +03:00
|
|
|
command += " VERBOSE=1 ";
|
2009-01-10 02:04:20 +03:00
|
|
|
command += target;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (generator == "Ninja") {
|
2013-01-05 11:29:58 +04:00
|
|
|
command += " -v ";
|
|
|
|
command += target;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2010-01-24 23:11:58 +03:00
|
|
|
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
|
2015-07-16 22:52:35 +03:00
|
|
|
command += " -f \"";
|
2010-01-24 23:11:58 +03:00
|
|
|
command += makefileName;
|
2015-07-16 22:52:35 +03:00
|
|
|
command += "\" ";
|
2010-11-12 00:06:09 +03:00
|
|
|
command += " VERBOSE=1 ";
|
2007-08-29 18:12:09 +04:00
|
|
|
command += target;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-08-29 18:12:09 +04:00
|
|
|
return command;
|
|
|
|
}
|