cmExtraCodeLiteGenerator.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2004-2009 Kitware, Inc.
  4. Copyright 2004 Alexander Neundorf ([email protected])
  5. Copyright 2013 Eran Ifrah ([email protected])
  6. Distributed under the OSI-approved BSD License (the "License");
  7. see accompanying file Copyright.txt for details.
  8. This software is distributed WITHOUT ANY WARRANTY; without even the
  9. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the License for more information.
  11. ============================================================================*/
  12. #include "cmExtraCodeLiteGenerator.h"
  13. #include "cmGeneratedFileStream.h"
  14. #include "cmGeneratorTarget.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmLocalGenerator.h"
  17. #include "cmMakefile.h"
  18. #include "cmSourceFile.h"
  19. #include "cmState.h"
  20. #include "cmSystemTools.h"
  21. #include "cmXMLWriter.h"
  22. #include "cmake.h"
  23. #include <cmsys/SystemInformation.hxx>
  24. #include <map>
  25. #include <set>
  26. #include <sstream>
  27. #include <string.h>
  28. #include <utility>
  29. cmExtraCodeLiteGenerator::cmExtraCodeLiteGenerator()
  30. : cmExternalMakefileProjectGenerator()
  31. , ConfigName("NoConfig")
  32. , CpuCount(2)
  33. {
  34. }
  35. cmExternalMakefileProjectGeneratorFactory*
  36. cmExtraCodeLiteGenerator::GetFactory()
  37. {
  38. static cmExternalMakefileProjectGeneratorSimpleFactory<
  39. cmExtraCodeLiteGenerator>
  40. factory("CodeLite", "Generates CodeLite project files.");
  41. if (factory.GetSupportedGlobalGenerators().empty()) {
  42. #if defined(_WIN32)
  43. factory.AddSupportedGlobalGenerator("MinGW Makefiles");
  44. factory.AddSupportedGlobalGenerator("NMake Makefiles");
  45. #endif
  46. factory.AddSupportedGlobalGenerator("Ninja");
  47. factory.AddSupportedGlobalGenerator("Unix Makefiles");
  48. }
  49. return &factory;
  50. }
  51. void cmExtraCodeLiteGenerator::Generate()
  52. {
  53. // Hold root tree information for creating the workspace
  54. std::string workspaceProjectName;
  55. std::string workspaceOutputDir;
  56. std::string workspaceFileName;
  57. std::string workspaceSourcePath;
  58. const std::map<std::string, std::vector<cmLocalGenerator*> >& projectMap =
  59. this->GlobalGenerator->GetProjectMap();
  60. // loop projects and locate the root project.
  61. // and extract the information for creating the worspace
  62. // root makefile
  63. const cmMakefile* rmf = CM_NULLPTR;
  64. for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
  65. it = projectMap.begin();
  66. it != projectMap.end(); ++it) {
  67. const cmMakefile* mf = it->second[0]->GetMakefile();
  68. this->ConfigName = GetConfigurationName(mf);
  69. if (strcmp(it->second[0]->GetCurrentBinaryDirectory(),
  70. it->second[0]->GetBinaryDirectory()) == 0) {
  71. workspaceOutputDir = it->second[0]->GetCurrentBinaryDirectory();
  72. workspaceProjectName = it->second[0]->GetProjectName();
  73. workspaceSourcePath = it->second[0]->GetSourceDirectory();
  74. workspaceFileName = workspaceOutputDir + "/";
  75. workspaceFileName += workspaceProjectName + ".workspace";
  76. this->WorkspacePath = it->second[0]->GetCurrentBinaryDirectory();
  77. rmf = it->second[0]->GetMakefile();
  78. ;
  79. break;
  80. }
  81. }
  82. cmGeneratedFileStream fout(workspaceFileName.c_str());
  83. cmXMLWriter xml(fout);
  84. xml.StartDocument("utf-8");
  85. xml.StartElement("CodeLite_Workspace");
  86. xml.Attribute("Name", workspaceProjectName);
  87. bool const targetsAreProjects =
  88. rmf && rmf->IsOn("CMAKE_CODELITE_USE_TARGETS");
  89. std::vector<std::string> ProjectNames;
  90. if (targetsAreProjects) {
  91. ProjectNames = CreateProjectsByTarget(&xml);
  92. } else {
  93. ProjectNames = CreateProjectsByProjectMaps(&xml);
  94. }
  95. xml.StartElement("BuildMatrix");
  96. xml.StartElement("WorkspaceConfiguration");
  97. xml.Attribute("Name", this->ConfigName);
  98. xml.Attribute("Selected", "yes");
  99. for (std::vector<std::string>::iterator it(ProjectNames.begin());
  100. it != ProjectNames.end(); it++) {
  101. xml.StartElement("Project");
  102. xml.Attribute("Name", *it);
  103. xml.Attribute("ConfigName", this->ConfigName);
  104. xml.EndElement();
  105. }
  106. xml.EndElement(); // WorkspaceConfiguration
  107. xml.EndElement(); // BuildMatrix
  108. xml.EndElement(); // CodeLite_Workspace
  109. }
  110. // Create projects where targets are the projects
  111. std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget(
  112. cmXMLWriter* xml)
  113. {
  114. std::vector<std::string> retval;
  115. // for each target in the workspace create a codelite project
  116. const std::vector<cmLocalGenerator*>& lgs =
  117. this->GlobalGenerator->GetLocalGenerators();
  118. for (std::vector<cmLocalGenerator*>::const_iterator lg(lgs.begin());
  119. lg != lgs.end(); lg++) {
  120. for (std::vector<cmGeneratorTarget*>::const_iterator lt =
  121. (*lg)->GetGeneratorTargets().begin();
  122. lt != (*lg)->GetGeneratorTargets().end(); lt++) {
  123. cmState::TargetType type = (*lt)->GetType();
  124. std::string outputDir = (*lg)->GetCurrentBinaryDirectory();
  125. std::string filename = outputDir + "/" + (*lt)->GetName() + ".project";
  126. retval.push_back((*lt)->GetName());
  127. // Make the project file relative to the workspace
  128. std::string relafilename = cmSystemTools::RelativePath(
  129. this->WorkspacePath.c_str(), filename.c_str());
  130. std::string visualname = (*lt)->GetName();
  131. switch (type) {
  132. case cmState::SHARED_LIBRARY:
  133. case cmState::STATIC_LIBRARY:
  134. case cmState::MODULE_LIBRARY:
  135. visualname = "lib" + visualname;
  136. case cmState::EXECUTABLE:
  137. xml->StartElement("Project");
  138. xml->Attribute("Name", visualname);
  139. xml->Attribute("Path", relafilename);
  140. xml->Attribute("Active", "No");
  141. xml->EndElement();
  142. CreateNewProjectFile(*lt, filename);
  143. break;
  144. default:
  145. break;
  146. }
  147. }
  148. }
  149. return retval;
  150. }
  151. // The "older way of doing it.
  152. std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByProjectMaps(
  153. cmXMLWriter* xml)
  154. {
  155. std::vector<std::string> retval;
  156. // for each sub project in the workspace create a codelite project
  157. for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
  158. it = this->GlobalGenerator->GetProjectMap().begin();
  159. it != this->GlobalGenerator->GetProjectMap().end(); it++) {
  160. std::string outputDir = it->second[0]->GetCurrentBinaryDirectory();
  161. std::string projectName = it->second[0]->GetProjectName();
  162. retval.push_back(projectName);
  163. std::string filename = outputDir + "/" + projectName + ".project";
  164. // Make the project file relative to the workspace
  165. filename = cmSystemTools::RelativePath(this->WorkspacePath.c_str(),
  166. filename.c_str());
  167. // create a project file
  168. this->CreateProjectFile(it->second);
  169. xml->StartElement("Project");
  170. xml->Attribute("Name", projectName);
  171. xml->Attribute("Path", filename);
  172. xml->Attribute("Active", "No");
  173. xml->EndElement();
  174. }
  175. return retval;
  176. }
  177. /* create the project file */
  178. void cmExtraCodeLiteGenerator::CreateProjectFile(
  179. const std::vector<cmLocalGenerator*>& lgs)
  180. {
  181. std::string outputDir = lgs[0]->GetCurrentBinaryDirectory();
  182. std::string projectName = lgs[0]->GetProjectName();
  183. std::string filename = outputDir + "/";
  184. filename += projectName + ".project";
  185. this->CreateNewProjectFile(lgs, filename);
  186. }
  187. std::string cmExtraCodeLiteGenerator::CollectSourceFiles(
  188. const cmMakefile* makefile, const cmGeneratorTarget* gt,
  189. std::map<std::string, cmSourceFile*>& cFiles,
  190. std::set<std::string>& otherFiles)
  191. {
  192. const std::vector<std::string>& srcExts =
  193. this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions();
  194. std::string projectType;
  195. switch (gt->GetType()) {
  196. case cmState::EXECUTABLE: {
  197. projectType = "Executable";
  198. } break;
  199. case cmState::STATIC_LIBRARY: {
  200. projectType = "Static Library";
  201. } break;
  202. case cmState::SHARED_LIBRARY: {
  203. projectType = "Dynamic Library";
  204. } break;
  205. case cmState::MODULE_LIBRARY: {
  206. projectType = "Dynamic Library";
  207. } break;
  208. default: // intended fallthrough
  209. break;
  210. }
  211. switch (gt->GetType()) {
  212. case cmState::EXECUTABLE:
  213. case cmState::STATIC_LIBRARY:
  214. case cmState::SHARED_LIBRARY:
  215. case cmState::MODULE_LIBRARY: {
  216. std::vector<cmSourceFile*> sources;
  217. gt->GetSourceFiles(sources,
  218. makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
  219. for (std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  220. si != sources.end(); si++) {
  221. // check whether it is a C/C++ implementation file
  222. bool isCFile = false;
  223. std::string lang = (*si)->GetLanguage();
  224. if (lang == "C" || lang == "CXX") {
  225. std::string srcext = (*si)->GetExtension();
  226. for (std::vector<std::string>::const_iterator ext = srcExts.begin();
  227. ext != srcExts.end(); ++ext) {
  228. if (srcext == *ext) {
  229. isCFile = true;
  230. break;
  231. }
  232. }
  233. }
  234. // then put it accordingly into one of the two containers
  235. if (isCFile) {
  236. cFiles[(*si)->GetFullPath()] = *si;
  237. } else {
  238. otherFiles.insert((*si)->GetFullPath());
  239. }
  240. }
  241. }
  242. default: // intended fallthrough
  243. break;
  244. }
  245. return projectType;
  246. }
  247. void cmExtraCodeLiteGenerator::CreateNewProjectFile(
  248. const std::vector<cmLocalGenerator*>& lgs, const std::string& filename)
  249. {
  250. const cmMakefile* mf = lgs[0]->GetMakefile();
  251. cmGeneratedFileStream fout(filename.c_str());
  252. if (!fout) {
  253. return;
  254. }
  255. cmXMLWriter xml(fout);
  256. ////////////////////////////////////
  257. xml.StartDocument("utf-8");
  258. xml.StartElement("CodeLite_Project");
  259. xml.Attribute("Name", lgs[0]->GetProjectName());
  260. xml.Attribute("InternalType", "");
  261. std::string projectType;
  262. // Collect all used source files in the project
  263. // Sort them into two containers, one for C/C++ implementation files
  264. // which may have an acompanying header, one for all other files
  265. std::map<std::string, cmSourceFile*> cFiles;
  266. std::set<std::string> otherFiles;
  267. for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin();
  268. lg != lgs.end(); lg++) {
  269. cmMakefile* makefile = (*lg)->GetMakefile();
  270. std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets();
  271. for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
  272. ti != targets.end(); ti++) {
  273. projectType = CollectSourceFiles(makefile, *ti, cFiles, otherFiles);
  274. }
  275. }
  276. // Get the project path ( we need it later to convert files to
  277. // their relative path)
  278. std::string projectPath = cmSystemTools::GetFilenamePath(filename);
  279. CreateProjectSourceEntries(cFiles, otherFiles, &xml, projectPath, mf,
  280. projectType);
  281. xml.EndElement(); // CodeLite_Project
  282. }
  283. void cmExtraCodeLiteGenerator::FindMatchingHeaderfiles(
  284. std::map<std::string, cmSourceFile*>& cFiles,
  285. std::set<std::string>& otherFiles)
  286. {
  287. const std::vector<std::string>& headerExts =
  288. this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
  289. // The following loop tries to add header files matching to implementation
  290. // files to the project. It does that by iterating over all source files,
  291. // replacing the file name extension with ".h" and checks whether such a
  292. // file exists. If it does, it is inserted into the map of files.
  293. // A very similar version of that code exists also in the kdevelop
  294. // project generator.
  295. for (std::map<std::string, cmSourceFile*>::const_iterator sit =
  296. cFiles.begin();
  297. sit != cFiles.end(); ++sit) {
  298. std::string headerBasename = cmSystemTools::GetFilenamePath(sit->first);
  299. headerBasename += "/";
  300. headerBasename += cmSystemTools::GetFilenameWithoutExtension(sit->first);
  301. // check if there's a matching header around
  302. for (std::vector<std::string>::const_iterator ext = headerExts.begin();
  303. ext != headerExts.end(); ++ext) {
  304. std::string hname = headerBasename;
  305. hname += ".";
  306. hname += *ext;
  307. // if it's already in the set, don't check if it exists on disk
  308. std::set<std::string>::const_iterator headerIt = otherFiles.find(hname);
  309. if (headerIt != otherFiles.end()) {
  310. break;
  311. }
  312. if (cmSystemTools::FileExists(hname.c_str())) {
  313. otherFiles.insert(hname);
  314. break;
  315. }
  316. }
  317. }
  318. }
  319. void cmExtraCodeLiteGenerator::CreateProjectSourceEntries(
  320. std::map<std::string, cmSourceFile*>& cFiles,
  321. std::set<std::string>& otherFiles, cmXMLWriter* _xml,
  322. const std::string& projectPath, const cmMakefile* mf,
  323. const std::string& projectType)
  324. {
  325. cmXMLWriter& xml(*_xml);
  326. FindMatchingHeaderfiles(cFiles, otherFiles);
  327. // Create 2 virtual folders: src and include
  328. // and place all the implementation files into the src
  329. // folder, the rest goes to the include folder
  330. xml.StartElement("VirtualDirectory");
  331. xml.Attribute("Name", "src");
  332. // insert all source files in the codelite project
  333. // first the C/C++ implementation files, then all others
  334. for (std::map<std::string, cmSourceFile*>::const_iterator sit =
  335. cFiles.begin();
  336. sit != cFiles.end(); ++sit) {
  337. xml.StartElement("File");
  338. std::string fpath(sit->first);
  339. std::string frelapath =
  340. cmSystemTools::RelativePath(projectPath.c_str(), sit->first.c_str());
  341. xml.Attribute("Name", frelapath);
  342. xml.EndElement();
  343. }
  344. xml.EndElement(); // VirtualDirectory
  345. xml.StartElement("VirtualDirectory");
  346. xml.Attribute("Name", "include");
  347. for (std::set<std::string>::const_iterator sit = otherFiles.begin();
  348. sit != otherFiles.end(); ++sit) {
  349. xml.StartElement("File");
  350. xml.Attribute(
  351. "Name", cmSystemTools::RelativePath(projectPath.c_str(), sit->c_str()));
  352. xml.EndElement();
  353. }
  354. xml.EndElement(); // VirtualDirectory
  355. // Get the number of CPUs. We use this information for the make -jN
  356. // command
  357. cmsys::SystemInformation info;
  358. info.RunCPUCheck();
  359. this->CpuCount =
  360. info.GetNumberOfLogicalCPU() * info.GetNumberOfPhysicalCPU();
  361. std::string codeliteCompilerName = this->GetCodeLiteCompilerName(mf);
  362. xml.StartElement("Settings");
  363. xml.Attribute("Type", projectType);
  364. xml.StartElement("Configuration");
  365. xml.Attribute("Name", this->ConfigName);
  366. xml.Attribute("CompilerType", this->GetCodeLiteCompilerName(mf));
  367. xml.Attribute("DebuggerType", "GNU gdb debugger");
  368. xml.Attribute("Type", projectType);
  369. xml.Attribute("BuildCmpWithGlobalSettings", "append");
  370. xml.Attribute("BuildLnkWithGlobalSettings", "append");
  371. xml.Attribute("BuildResWithGlobalSettings", "append");
  372. xml.StartElement("Compiler");
  373. xml.Attribute("Options", "-g");
  374. xml.Attribute("Required", "yes");
  375. xml.Attribute("PreCompiledHeader", "");
  376. xml.StartElement("IncludePath");
  377. xml.Attribute("Value", ".");
  378. xml.EndElement(); // IncludePath
  379. xml.EndElement(); // Compiler
  380. xml.StartElement("Linker");
  381. xml.Attribute("Options", "");
  382. xml.Attribute("Required", "yes");
  383. xml.EndElement(); // Linker
  384. xml.StartElement("ResourceCompiler");
  385. xml.Attribute("Options", "");
  386. xml.Attribute("Required", "no");
  387. xml.EndElement(); // ResourceCompiler
  388. xml.StartElement("General");
  389. std::string outputPath = mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  390. if (!outputPath.empty())
  391. xml.Attribute("OutputFile", outputPath + "/$(ProjectName)");
  392. else
  393. xml.Attribute("OutputFile", "$(IntermediateDirectory)/$(ProjectName)");
  394. xml.Attribute("IntermediateDirectory", "./");
  395. xml.Attribute("Command", "./$(ProjectName)");
  396. xml.Attribute("CommandArguments", "");
  397. if (!outputPath.empty())
  398. xml.Attribute("WorkingDirectory", outputPath);
  399. else
  400. xml.Attribute("WorkingDirectory", "$(IntermediateDirectory)");
  401. xml.Attribute("PauseExecWhenProcTerminates", "yes");
  402. xml.EndElement(); // General
  403. xml.StartElement("Debugger");
  404. xml.Attribute("IsRemote", "no");
  405. xml.Attribute("RemoteHostName", "");
  406. xml.Attribute("RemoteHostPort", "");
  407. xml.Attribute("DebuggerPath", "");
  408. xml.Element("PostConnectCommands");
  409. xml.Element("StartupCommands");
  410. xml.EndElement(); // Debugger
  411. xml.Element("PreBuild");
  412. xml.Element("PostBuild");
  413. xml.StartElement("CustomBuild");
  414. xml.Attribute("Enabled", "yes");
  415. xml.Element("RebuildCommand", GetRebuildCommand(mf));
  416. xml.Element("CleanCommand", GetCleanCommand(mf));
  417. xml.Element("BuildCommand", GetBuildCommand(mf));
  418. xml.Element("SingleFileCommand", GetSingleFileBuildCommand(mf));
  419. xml.Element("PreprocessFileCommand");
  420. xml.Element("WorkingDirectory", "$(WorkspacePath)");
  421. xml.EndElement(); // CustomBuild
  422. xml.StartElement("AdditionalRules");
  423. xml.Element("CustomPostBuild");
  424. xml.Element("CustomPreBuild");
  425. xml.EndElement(); // AdditionalRules
  426. xml.EndElement(); // Configuration
  427. xml.StartElement("GlobalSettings");
  428. xml.StartElement("Compiler");
  429. xml.Attribute("Options", "");
  430. xml.StartElement("IncludePath");
  431. xml.Attribute("Value", ".");
  432. xml.EndElement(); // IncludePath
  433. xml.EndElement(); // Compiler
  434. xml.StartElement("Linker");
  435. xml.Attribute("Options", "");
  436. xml.StartElement("LibraryPath");
  437. xml.Attribute("Value", ".");
  438. xml.EndElement(); // LibraryPath
  439. xml.EndElement(); // Linker
  440. xml.StartElement("ResourceCompiler");
  441. xml.Attribute("Options", "");
  442. xml.EndElement(); // ResourceCompiler
  443. xml.EndElement(); // GlobalSettings
  444. xml.EndElement(); // Settings
  445. }
  446. void cmExtraCodeLiteGenerator::CreateNewProjectFile(
  447. const cmGeneratorTarget* gt, const std::string& filename)
  448. {
  449. const cmMakefile* mf = gt->Makefile;
  450. cmGeneratedFileStream fout(filename.c_str());
  451. if (!fout) {
  452. return;
  453. }
  454. cmXMLWriter xml(fout);
  455. ////////////////////////////////////
  456. xml.StartDocument("utf-8");
  457. xml.StartElement("CodeLite_Project");
  458. std::string visualname = gt->GetName();
  459. switch (gt->GetType()) {
  460. case cmState::STATIC_LIBRARY:
  461. case cmState::SHARED_LIBRARY:
  462. case cmState::MODULE_LIBRARY:
  463. visualname = "lib" + visualname;
  464. default: // intended fallthrough
  465. break;
  466. }
  467. xml.Attribute("Name", visualname);
  468. xml.Attribute("InternalType", "");
  469. // Collect all used source files in the project
  470. // Sort them into two containers, one for C/C++ implementation files
  471. // which may have an acompanying header, one for all other files
  472. std::string projectType;
  473. std::vector<std::string> headerExts =
  474. this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
  475. std::map<std::string, cmSourceFile*> cFiles;
  476. std::set<std::string> otherFiles;
  477. projectType = CollectSourceFiles(mf, gt, cFiles, otherFiles);
  478. // Get the project path ( we need it later to convert files to
  479. // their relative path)
  480. std::string projectPath = cmSystemTools::GetFilenamePath(filename);
  481. CreateProjectSourceEntries(cFiles, otherFiles, &xml, projectPath, mf,
  482. projectType);
  483. xml.EndElement(); // CodeLite_Project
  484. }
  485. std::string cmExtraCodeLiteGenerator::GetCodeLiteCompilerName(
  486. const cmMakefile* mf) const
  487. {
  488. // figure out which language to use
  489. // for now care only for C and C++
  490. std::string compilerIdVar = "CMAKE_CXX_COMPILER_ID";
  491. if (!this->GlobalGenerator->GetLanguageEnabled("CXX")) {
  492. compilerIdVar = "CMAKE_C_COMPILER_ID";
  493. }
  494. std::string compilerId = mf->GetSafeDefinition(compilerIdVar);
  495. std::string compiler = "gnu g++"; // default to g++
  496. // Since we need the compiler for parsing purposes only
  497. // it does not matter if we use clang or clang++, same as
  498. // "gnu gcc" vs "gnu g++"
  499. if (compilerId == "MSVC") {
  500. compiler = "VC++";
  501. } else if (compilerId == "Clang") {
  502. compiler = "clang++";
  503. } else if (compilerId == "GNU") {
  504. compiler = "gnu g++";
  505. }
  506. return compiler;
  507. }
  508. std::string cmExtraCodeLiteGenerator::GetConfigurationName(
  509. const cmMakefile* mf) const
  510. {
  511. std::string confName = mf->GetSafeDefinition("CMAKE_BUILD_TYPE");
  512. // Trim the configuration name from whitespaces (left and right)
  513. confName.erase(0, confName.find_first_not_of(" \t\r\v\n"));
  514. confName.erase(confName.find_last_not_of(" \t\r\v\n") + 1);
  515. if (confName.empty()) {
  516. confName = "NoConfig";
  517. }
  518. return confName;
  519. }
  520. std::string cmExtraCodeLiteGenerator::GetBuildCommand(
  521. const cmMakefile* mf) const
  522. {
  523. std::string generator = mf->GetSafeDefinition("CMAKE_GENERATOR");
  524. std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  525. std::string buildCommand = make; // Default
  526. if (generator == "NMake Makefiles" || generator == "Ninja") {
  527. buildCommand = make;
  528. } else if (generator == "MinGW Makefiles" || generator == "Unix Makefiles") {
  529. std::ostringstream ss;
  530. ss << make << " -j " << this->CpuCount;
  531. buildCommand = ss.str();
  532. }
  533. return buildCommand;
  534. }
  535. std::string cmExtraCodeLiteGenerator::GetCleanCommand(
  536. const cmMakefile* mf) const
  537. {
  538. return GetBuildCommand(mf) + " clean";
  539. }
  540. std::string cmExtraCodeLiteGenerator::GetRebuildCommand(
  541. const cmMakefile* mf) const
  542. {
  543. return GetCleanCommand(mf) + " && " + GetBuildCommand(mf);
  544. }
  545. std::string cmExtraCodeLiteGenerator::GetSingleFileBuildCommand(
  546. const cmMakefile* mf) const
  547. {
  548. std::string buildCommand;
  549. std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  550. std::string generator = mf->GetSafeDefinition("CMAKE_GENERATOR");
  551. if (generator == "Unix Makefiles" || generator == "MinGW Makefiles") {
  552. std::ostringstream ss;
  553. ss << make << " -f$(ProjectPath)/Makefile $(CurrentFileName).cpp.o";
  554. buildCommand = ss.str();
  555. }
  556. return buildCommand;
  557. }