cmExtraCodeBlocksGenerator.cxx 24 KB

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