cmExtraCodeLiteGenerator.cxx 21 KB

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