cmExtraCodeBlocksGenerator.cxx 23 KB

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