cmExtraCodeBlocksGenerator.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2004-2009 Kitware, Inc.
  4. Copyright 2004 Alexander Neundorf ([email protected])
  5. Distributed under the OSI-approved BSD License (the "License");
  6. see accompanying file Copyright.txt for details.
  7. This software is distributed WITHOUT ANY WARRANTY; without even the
  8. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. See the License for more information.
  10. ============================================================================*/
  11. #include "cmExtraCodeBlocksGenerator.h"
  12. #include "cmGlobalUnixMakefileGenerator3.h"
  13. #include "cmLocalUnixMakefileGenerator3.h"
  14. #include "cmMakefile.h"
  15. #include "cmake.h"
  16. #include "cmSourceFile.h"
  17. #include "cmGeneratedFileStream.h"
  18. #include "cmTarget.h"
  19. #include "cmSystemTools.h"
  20. #include <cmsys/SystemTools.hxx>
  21. /* Some useful URLs:
  22. Homepage:
  23. http://www.codeblocks.org
  24. File format docs:
  25. http://wiki.codeblocks.org/index.php?title=File_formats_description
  26. http://wiki.codeblocks.org/index.php?title=Workspace_file
  27. http://wiki.codeblocks.org/index.php?title=Project_file
  28. Discussion:
  29. http://forums.codeblocks.org/index.php/topic,6789.0.html
  30. */
  31. //----------------------------------------------------------------------------
  32. void cmExtraCodeBlocksGenerator
  33. ::GetDocumentation(cmDocumentationEntry& entry, const char*) const
  34. {
  35. entry.Name = this->GetName();
  36. entry.Brief = "Generates CodeBlocks project files.";
  37. entry.Full =
  38. "Project files for CodeBlocks will be created in the top directory "
  39. "and in every subdirectory which features a CMakeLists.txt file "
  40. "containing a PROJECT() call. "
  41. "Additionally a hierarchy of makefiles is generated into the "
  42. "build tree. The appropriate make program can build the project through "
  43. "the default make target. A \"make install\" target is also provided.";
  44. }
  45. cmExtraCodeBlocksGenerator::cmExtraCodeBlocksGenerator()
  46. :cmExternalMakefileProjectGenerator()
  47. {
  48. #if defined(_WIN32)
  49. this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
  50. this->SupportedGlobalGenerators.push_back("NMake Makefiles");
  51. // disable until somebody actually tests it:
  52. // this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
  53. #endif
  54. this->SupportedGlobalGenerators.push_back("Unix Makefiles");
  55. }
  56. void cmExtraCodeBlocksGenerator::SetGlobalGenerator(
  57. cmGlobalGenerator* generator)
  58. {
  59. cmExternalMakefileProjectGenerator::SetGlobalGenerator(generator);
  60. cmGlobalUnixMakefileGenerator3* mf = (cmGlobalUnixMakefileGenerator3*)
  61. generator;
  62. mf->SetToolSupportsColor(false);
  63. mf->SetForceVerboseMakefiles(true);
  64. }
  65. void cmExtraCodeBlocksGenerator::Generate()
  66. {
  67. // for each sub project in the project create a codeblocks project
  68. for (std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
  69. it = this->GlobalGenerator->GetProjectMap().begin();
  70. it!= this->GlobalGenerator->GetProjectMap().end();
  71. ++it)
  72. {
  73. // create a project file
  74. this->CreateProjectFile(it->second);
  75. }
  76. }
  77. /* create the project file */
  78. void cmExtraCodeBlocksGenerator::CreateProjectFile(
  79. const std::vector<cmLocalGenerator*>& lgs)
  80. {
  81. const cmMakefile* mf=lgs[0]->GetMakefile();
  82. std::string outputDir=mf->GetStartOutputDirectory();
  83. std::string projectName=mf->GetProjectName();
  84. std::string filename=outputDir+"/";
  85. filename+=projectName+".cbp";
  86. std::string sessionFilename=outputDir+"/";
  87. sessionFilename+=projectName+".layout";
  88. this->CreateNewProjectFile(lgs, filename);
  89. }
  90. /* Tree is used to create a "Virtual Folder" in CodeBlocks, in which all
  91. CMake files this project depends on will be put. This means additionally
  92. to the "Sources" and "Headers" virtual folders of CodeBlocks, there will
  93. now also be a "CMake Files" virtual folder.
  94. Patch by Daniel Teske <daniel.teske AT nokia.com> (which use C::B project
  95. files in QtCreator).*/
  96. struct Tree
  97. {
  98. std::string path; //only one component of the path
  99. std::vector<Tree> folders;
  100. std::vector<std::string> files;
  101. void InsertPath(const std::vector<std::string>& splitted,
  102. std::vector<std::string>::size_type start,
  103. const std::string& fileName);
  104. void BuildVirtualFolder(std::string& virtualFolders) const;
  105. void BuildVirtualFolderImpl(std::string& virtualFolders,
  106. const std::string& prefix) const;
  107. void BuildUnit(std::string& unitString, const std::string& fsPath) const;
  108. void BuildUnitImpl(std::string& unitString,
  109. const std::string& virtualFolderPath,
  110. const std::string& fsPath) const;
  111. };
  112. void Tree::InsertPath(const std::vector<std::string>& splitted,
  113. std::vector<std::string>::size_type start,
  114. const std::string& fileName)
  115. {
  116. if (start == splitted.size())
  117. {
  118. files.push_back(fileName);
  119. return;
  120. }
  121. for (std::vector<Tree>::iterator
  122. it = folders.begin();
  123. it != folders.end();
  124. ++it)
  125. {
  126. if ((*it).path == splitted[start])
  127. {
  128. if (start + 1 < splitted.size())
  129. {
  130. it->InsertPath(splitted, start + 1, fileName);
  131. return;
  132. }
  133. else
  134. {
  135. // last part of splitted
  136. it->files.push_back(fileName);
  137. return;
  138. }
  139. }
  140. }
  141. // Not found in folders, thus insert
  142. Tree newFolder;
  143. newFolder.path = splitted[start];
  144. if (start + 1 < splitted.size())
  145. {
  146. newFolder.InsertPath(splitted, start + 1, fileName);
  147. folders.push_back(newFolder);
  148. return;
  149. }
  150. else
  151. {
  152. // last part of splitted
  153. newFolder.files.push_back(fileName);
  154. folders.push_back(newFolder);
  155. return;
  156. }
  157. }
  158. void Tree::BuildVirtualFolder(std::string& virtualFolders) const
  159. {
  160. virtualFolders += "<Option virtualFolders=\"CMake Files\\;";
  161. for (std::vector<Tree>::const_iterator it = folders.begin();
  162. it != folders.end();
  163. ++it)
  164. {
  165. it->BuildVirtualFolderImpl(virtualFolders, "");
  166. }
  167. virtualFolders += "\" />";
  168. }
  169. void Tree::BuildVirtualFolderImpl(std::string& virtualFolders,
  170. const std::string& prefix) const
  171. {
  172. virtualFolders += "CMake Files\\" + prefix + path + "\\;";
  173. for (std::vector<Tree>::const_iterator it = folders.begin();
  174. it != folders.end();
  175. ++it)
  176. {
  177. it->BuildVirtualFolderImpl(virtualFolders, prefix + path + "\\");
  178. }
  179. }
  180. void Tree::BuildUnit(std::string& unitString, const std::string& fsPath) const
  181. {
  182. for (std::vector<std::string>::const_iterator it = files.begin();
  183. it != files.end();
  184. ++it)
  185. {
  186. unitString += " <Unit filename=\"" + fsPath + *it + "\">\n";
  187. unitString += " <Option virtualFolder=\"CMake Files\\\" />\n";
  188. unitString += " </Unit>\n";
  189. }
  190. for (std::vector<Tree>::const_iterator it = folders.begin();
  191. it != folders.end();
  192. ++it)
  193. {
  194. it->BuildUnitImpl(unitString, "", fsPath);
  195. }
  196. }
  197. void Tree::BuildUnitImpl(std::string& unitString,
  198. const std::string& virtualFolderPath,
  199. const std::string& fsPath) const
  200. {
  201. for (std::vector<std::string>::const_iterator it = files.begin();
  202. it != files.end();
  203. ++it)
  204. {
  205. unitString += " <Unit filename=\"" +fsPath+path+ "/" + *it + "\">\n";
  206. unitString += " <Option virtualFolder=\"CMake Files\\"
  207. + virtualFolderPath + path + "\\\" />\n";
  208. unitString += " </Unit>\n";
  209. }
  210. for (std::vector<Tree>::const_iterator it = folders.begin();
  211. it != folders.end();
  212. ++it)
  213. {
  214. it->BuildUnitImpl(unitString,
  215. virtualFolderPath + path + "\\", fsPath + path + "/");
  216. }
  217. }
  218. void cmExtraCodeBlocksGenerator
  219. ::CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
  220. const std::string& filename)
  221. {
  222. const cmMakefile* mf=lgs[0]->GetMakefile();
  223. cmGeneratedFileStream fout(filename.c_str());
  224. if(!fout)
  225. {
  226. return;
  227. }
  228. Tree tree;
  229. // build tree of virtual folders
  230. for (std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
  231. it = this->GlobalGenerator->GetProjectMap().begin();
  232. it != this->GlobalGenerator->GetProjectMap().end();
  233. ++it)
  234. {
  235. // Collect all files
  236. std::vector<std::string> listFiles;
  237. for (std::vector<cmLocalGenerator *>::const_iterator
  238. jt = it->second.begin();
  239. jt != it->second.end();
  240. ++jt)
  241. {
  242. const std::vector<std::string> & files =
  243. (*jt)->GetMakefile()->GetListFiles();
  244. listFiles.insert(listFiles.end(), files.begin(), files.end());
  245. }
  246. // Convert
  247. for (std::vector<std::string>::const_iterator jt = listFiles.begin();
  248. jt != listFiles.end();
  249. ++jt)
  250. {
  251. const std::string &relative = cmSystemTools::RelativePath(
  252. it->second[0]->GetMakefile()->GetHomeDirectory(),
  253. jt->c_str());
  254. std::vector<std::string> splitted;
  255. cmSystemTools::SplitPath(relative.c_str(), splitted, false);
  256. // Split filename from path
  257. std::string fileName = *(splitted.end()-1);
  258. splitted.erase(splitted.end() - 1, splitted.end());
  259. // We don't want paths with ".." in them
  260. // reasons are that we don't want files outside the project
  261. // TODO: the path should be normalized first though
  262. // We don't want paths with CMakeFiles in them
  263. // or do we?
  264. // In speedcrunch those where purely internal
  265. if (splitted.size() >= 1
  266. && relative.find("..") == std::string::npos
  267. && relative.find("CMakeFiles") == std::string::npos)
  268. {
  269. tree.InsertPath(splitted, 1, fileName);
  270. }
  271. }
  272. }
  273. // Now build a virtual tree string
  274. std::string virtualFolders;
  275. tree.BuildVirtualFolder(virtualFolders);
  276. // And one for <Unit>
  277. std::string unitFiles;
  278. tree.BuildUnit(unitFiles, std::string(mf->GetHomeDirectory()) + "/");
  279. // figure out the compiler
  280. std::string compiler = this->GetCBCompilerId(mf);
  281. std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  282. fout<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"
  283. "<CodeBlocks_project_file>\n"
  284. " <FileVersion major=\"1\" minor=\"6\" />\n"
  285. " <Project>\n"
  286. " <Option title=\"" << mf->GetProjectName()<<"\" />\n"
  287. " <Option makefile_is_custom=\"1\" />\n"
  288. " <Option compiler=\"" << compiler << "\" />\n"
  289. " "<<virtualFolders<<"\n"
  290. " <Build>\n";
  291. this->AppendTarget(fout, "all", 0, make.c_str(), mf, compiler.c_str());
  292. // add all executable and library targets and some of the GLOBAL
  293. // and UTILITY targets
  294. for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin();
  295. lg!=lgs.end(); lg++)
  296. {
  297. cmMakefile* makefile=(*lg)->GetMakefile();
  298. cmTargets& targets=makefile->GetTargets();
  299. for (cmTargets::iterator ti = targets.begin();
  300. ti != targets.end(); ti++)
  301. {
  302. switch(ti->second.GetType())
  303. {
  304. case cmTarget::GLOBAL_TARGET:
  305. {
  306. bool insertTarget = false;
  307. // Only add the global targets from CMAKE_BINARY_DIR,
  308. // not from the subdirs
  309. if (strcmp(makefile->GetStartOutputDirectory(),
  310. makefile->GetHomeOutputDirectory())==0)
  311. {
  312. insertTarget = true;
  313. // only add the "edit_cache" target if it's not ccmake, because
  314. // this will not work within the IDE
  315. if (ti->first == "edit_cache")
  316. {
  317. const char* editCommand = makefile->GetDefinition
  318. ("CMAKE_EDIT_COMMAND");
  319. if (editCommand == 0)
  320. {
  321. insertTarget = false;
  322. }
  323. else if (strstr(editCommand, "ccmake")!=NULL)
  324. {
  325. insertTarget = false;
  326. }
  327. }
  328. }
  329. if (insertTarget)
  330. {
  331. this->AppendTarget(fout, ti->first.c_str(), 0,
  332. make.c_str(), makefile, compiler.c_str());
  333. }
  334. }
  335. break;
  336. case cmTarget::UTILITY:
  337. // Add all utility targets, except the Nightly/Continuous/
  338. // Experimental-"sub"targets as e.g. NightlyStart
  339. if (((ti->first.find("Nightly")==0) &&(ti->first!="Nightly"))
  340. || ((ti->first.find("Continuous")==0)&&(ti->first!="Continuous"))
  341. || ((ti->first.find("Experimental")==0)
  342. && (ti->first!="Experimental")))
  343. {
  344. break;
  345. }
  346. this->AppendTarget(fout, ti->first.c_str(), 0,
  347. make.c_str(), makefile, compiler.c_str());
  348. break;
  349. case cmTarget::EXECUTABLE:
  350. case cmTarget::STATIC_LIBRARY:
  351. case cmTarget::SHARED_LIBRARY:
  352. case cmTarget::MODULE_LIBRARY:
  353. {
  354. this->AppendTarget(fout, ti->first.c_str(), &ti->second,
  355. make.c_str(), makefile, compiler.c_str());
  356. std::string fastTarget = ti->first;
  357. fastTarget += "/fast";
  358. this->AppendTarget(fout, fastTarget.c_str(), &ti->second,
  359. make.c_str(), makefile, compiler.c_str());
  360. }
  361. break;
  362. // ignore these:
  363. case cmTarget::INSTALL_FILES:
  364. case cmTarget::INSTALL_PROGRAMS:
  365. case cmTarget::INSTALL_DIRECTORY:
  366. default:
  367. break;
  368. }
  369. }
  370. }
  371. fout<<" </Build>\n";
  372. // Collect all used source files in the project
  373. // Sort them into two containers, one for C/C++ implementation files
  374. // which may have an acompanying header, one for all other files
  375. std::map<std::string, cmSourceFile*> cFiles;
  376. std::set<std::string> otherFiles;
  377. for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin();
  378. lg!=lgs.end(); lg++)
  379. {
  380. cmMakefile* makefile=(*lg)->GetMakefile();
  381. cmTargets& targets=makefile->GetTargets();
  382. for (cmTargets::iterator ti = targets.begin();
  383. ti != targets.end(); ti++)
  384. {
  385. switch(ti->second.GetType())
  386. {
  387. case cmTarget::EXECUTABLE:
  388. case cmTarget::STATIC_LIBRARY:
  389. case cmTarget::SHARED_LIBRARY:
  390. case cmTarget::MODULE_LIBRARY:
  391. {
  392. const std::vector<cmSourceFile*>&sources=ti->second.GetSourceFiles();
  393. for (std::vector<cmSourceFile*>::const_iterator si=sources.begin();
  394. si!=sources.end(); si++)
  395. {
  396. // check whether it is a C/C++ implementation file
  397. bool isCFile = false;
  398. if ((*si)->GetLanguage() && (*(*si)->GetLanguage() == 'C'))
  399. {
  400. for(std::vector<std::string>::const_iterator
  401. ext = mf->GetSourceExtensions().begin();
  402. ext != mf->GetSourceExtensions().end();
  403. ++ext)
  404. {
  405. if ((*si)->GetExtension() == *ext)
  406. {
  407. isCFile = true;
  408. break;
  409. }
  410. }
  411. }
  412. // then put it accordingly into one of the two containers
  413. if (isCFile)
  414. {
  415. cFiles[(*si)->GetFullPath()] = *si ;
  416. }
  417. else
  418. {
  419. otherFiles.insert((*si)->GetFullPath());
  420. }
  421. }
  422. }
  423. default: // intended fallthrough
  424. break;
  425. }
  426. }
  427. }
  428. // The following loop tries to add header files matching to implementation
  429. // files to the project. It does that by iterating over all source files,
  430. // replacing the file name extension with ".h" and checks whether such a
  431. // file exists. If it does, it is inserted into the map of files.
  432. // A very similar version of that code exists also in the kdevelop
  433. // project generator.
  434. for (std::map<std::string, cmSourceFile*>::const_iterator
  435. sit=cFiles.begin();
  436. sit!=cFiles.end();
  437. ++sit)
  438. {
  439. std::string headerBasename=cmSystemTools::GetFilenamePath(sit->first);
  440. headerBasename+="/";
  441. headerBasename+=cmSystemTools::GetFilenameWithoutExtension(sit->first);
  442. // check if there's a matching header around
  443. for(std::vector<std::string>::const_iterator
  444. ext = mf->GetHeaderExtensions().begin();
  445. ext != mf->GetHeaderExtensions().end();
  446. ++ext)
  447. {
  448. std::string hname=headerBasename;
  449. hname += ".";
  450. hname += *ext;
  451. // if it's already in the set, don't check if it exists on disk
  452. std::set<std::string>::const_iterator headerIt=otherFiles.find(hname);
  453. if (headerIt != otherFiles.end())
  454. {
  455. break;
  456. }
  457. if(cmSystemTools::FileExists(hname.c_str()))
  458. {
  459. otherFiles.insert(hname);
  460. break;
  461. }
  462. }
  463. }
  464. // insert all source files in the CodeBlocks project
  465. // first the C/C++ implementation files, then all others
  466. for (std::map<std::string, cmSourceFile*>::const_iterator
  467. sit=cFiles.begin();
  468. sit!=cFiles.end();
  469. ++sit)
  470. {
  471. fout<<" <Unit filename=\""<< sit->first <<"\">\n"
  472. " </Unit>\n";
  473. }
  474. for (std::set<std::string>::const_iterator
  475. sit=otherFiles.begin();
  476. sit!=otherFiles.end();
  477. ++sit)
  478. {
  479. fout<<" <Unit filename=\""<< sit->c_str() <<"\">\n"
  480. " </Unit>\n";
  481. }
  482. // Add CMakeLists.txt
  483. fout<<unitFiles;
  484. fout<<" </Project>\n"
  485. "</CodeBlocks_project_file>\n";
  486. }
  487. // Generate the xml code for one target.
  488. void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
  489. const char* targetName,
  490. cmTarget* target,
  491. const char* make,
  492. const cmMakefile* makefile,
  493. const char* compiler)
  494. {
  495. std::string makefileName = makefile->GetStartOutputDirectory();
  496. makefileName += "/Makefile";
  497. fout<<" <Target title=\"" << targetName << "\">\n";
  498. if (target!=0)
  499. {
  500. int cbTargetType = this->GetCBTargetType(target);
  501. std::string workingDir = makefile->GetStartOutputDirectory();
  502. if ( target->GetType()==cmTarget::EXECUTABLE)
  503. {
  504. // Determine the directory where the executable target is created, and
  505. // set the working directory to this dir.
  506. const char* runtimeOutputDir = makefile->GetDefinition(
  507. "CMAKE_RUNTIME_OUTPUT_DIRECTORY");
  508. if (runtimeOutputDir != 0)
  509. {
  510. workingDir = runtimeOutputDir;
  511. }
  512. else
  513. {
  514. const char* executableOutputDir = makefile->GetDefinition(
  515. "EXECUTABLE_OUTPUT_PATH");
  516. if (executableOutputDir != 0)
  517. {
  518. workingDir = executableOutputDir;
  519. }
  520. }
  521. }
  522. const char* buildType = makefile->GetDefinition("CMAKE_BUILD_TYPE");
  523. fout<<" <Option output=\"" << target->GetLocation(buildType)
  524. << "\" prefix_auto=\"0\" extension_auto=\"0\" />\n"
  525. " <Option working_dir=\"" << workingDir << "\" />\n"
  526. " <Option object_output=\"./\" />\n"
  527. " <Option type=\"" << cbTargetType << "\" />\n"
  528. " <Option compiler=\"" << compiler << "\" />\n"
  529. " <Compiler>\n";
  530. // the include directories for this target
  531. const std::vector<std::string>& incDirs =
  532. target->GetMakefile()->GetIncludeDirectories();
  533. for(std::vector<std::string>::const_iterator dirIt=incDirs.begin();
  534. dirIt != incDirs.end();
  535. ++dirIt)
  536. {
  537. fout <<" <Add directory=\"" << dirIt->c_str() << "\" />\n";
  538. }
  539. fout<<" </Compiler>\n";
  540. }
  541. else // e.g. all and the GLOBAL and UTILITY targets
  542. {
  543. fout<<" <Option working_dir=\""
  544. << makefile->GetStartOutputDirectory() << "\" />\n"
  545. <<" <Option type=\"" << 4 << "\" />\n";
  546. }
  547. fout<<" <MakeCommands>\n"
  548. " <Build command=\""
  549. << this->BuildMakeCommand(make, makefileName.c_str(), targetName)
  550. << "\" />\n"
  551. " <CompileFile command=\""
  552. << this->BuildMakeCommand(make, makefileName.c_str(),"&quot;$file&quot;")
  553. << "\" />\n"
  554. " <Clean command=\""
  555. << this->BuildMakeCommand(make, makefileName.c_str(), "clean")
  556. << "\" />\n"
  557. " <DistClean command=\""
  558. << this->BuildMakeCommand(make, makefileName.c_str(), "clean")
  559. << "\" />\n"
  560. " </MakeCommands>\n"
  561. " </Target>\n";
  562. }
  563. // Translate the cmake compiler id into the CodeBlocks compiler id
  564. std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf)
  565. {
  566. // figure out which language to use
  567. // for now care only for C and C++
  568. std::string compilerIdVar = "CMAKE_CXX_COMPILER_ID";
  569. if (this->GlobalGenerator->GetLanguageEnabled("CXX") == false)
  570. {
  571. compilerIdVar = "CMAKE_C_COMPILER_ID";
  572. }
  573. std::string hostSystemName = mf->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME");
  574. std::string systemName = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
  575. std::string compilerId = mf->GetSafeDefinition(compilerIdVar.c_str());
  576. std::string compiler = "gcc"; // default to gcc
  577. if (compilerId == "MSVC")
  578. {
  579. compiler = "msvc8";
  580. }
  581. else if (compilerId == "Borland")
  582. {
  583. compiler = "bcc";
  584. }
  585. else if (compilerId == "SDCC")
  586. {
  587. compiler = "sdcc";
  588. }
  589. else if (compilerId == "Intel")
  590. {
  591. compiler = "icc";
  592. }
  593. else if (compilerId == "Watcom")
  594. {
  595. compiler = "ow";
  596. }
  597. else if (compilerId == "GNU")
  598. {
  599. compiler = "gcc";
  600. }
  601. return compiler;
  602. }
  603. // Translate the cmake target type into the CodeBlocks target type id
  604. int cmExtraCodeBlocksGenerator::GetCBTargetType(cmTarget* target)
  605. {
  606. if ( target->GetType()==cmTarget::EXECUTABLE)
  607. {
  608. if ((target->GetPropertyAsBool("WIN32_EXECUTABLE"))
  609. || (target->GetPropertyAsBool("MACOSX_BUNDLE")))
  610. {
  611. return 0;
  612. }
  613. else
  614. {
  615. return 1;
  616. }
  617. }
  618. else if ( target->GetType()==cmTarget::STATIC_LIBRARY)
  619. {
  620. return 2;
  621. }
  622. else if ((target->GetType()==cmTarget::SHARED_LIBRARY)
  623. || (target->GetType()==cmTarget::MODULE_LIBRARY))
  624. {
  625. return 3;
  626. }
  627. return 4;
  628. }
  629. // Create the command line for building the given target using the selected
  630. // make
  631. std::string cmExtraCodeBlocksGenerator::BuildMakeCommand(
  632. const std::string& make, const char* makefile, const char* target)
  633. {
  634. std::string command = make;
  635. if (strcmp(this->GlobalGenerator->GetName(), "NMake Makefiles")==0)
  636. {
  637. std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
  638. command += " /NOLOGO /f &quot;";
  639. command += makefileName;
  640. command += "&quot; ";
  641. command += target;
  642. }
  643. else if (strcmp(this->GlobalGenerator->GetName(), "MinGW Makefiles")==0)
  644. {
  645. // no escaping of spaces in this case, see
  646. // http://public.kitware.com/Bug/view.php?id=10014
  647. std::string makefileName = makefile;
  648. command += " -f &quot;";
  649. command += makefileName;
  650. command += "&quot; ";
  651. command += target;
  652. }
  653. else
  654. {
  655. std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
  656. command += " -f &quot;";
  657. command += makefileName;
  658. command += "&quot; ";
  659. command += target;
  660. }
  661. return command;
  662. }