cmExtraCodeBlocksGenerator.cxx 22 KB

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