cmExtraCodeBlocksGenerator.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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. const char* cmakeRoot = mf->GetDefinition("CMAKE_ROOT");
  239. for (std::vector<std::string>::const_iterator jt = listFiles.begin();
  240. jt != listFiles.end();
  241. ++jt)
  242. {
  243. // don't put cmake's own files into the project (#12110):
  244. if (jt->find(cmakeRoot) == 0)
  245. {
  246. continue;
  247. }
  248. const std::string &relative = cmSystemTools::RelativePath(
  249. it->second[0]->GetMakefile()->GetHomeDirectory(),
  250. jt->c_str());
  251. std::vector<std::string> splitted;
  252. cmSystemTools::SplitPath(relative.c_str(), splitted, false);
  253. // Split filename from path
  254. std::string fileName = *(splitted.end()-1);
  255. splitted.erase(splitted.end() - 1, splitted.end());
  256. // We don't want paths with CMakeFiles in them
  257. // or do we?
  258. // In speedcrunch those where purely internal
  259. if (splitted.size() >= 1
  260. && relative.find("CMakeFiles") == std::string::npos)
  261. {
  262. tree.InsertPath(splitted, 1, fileName);
  263. }
  264. }
  265. }
  266. // Now build a virtual tree string
  267. std::string virtualFolders;
  268. tree.BuildVirtualFolder(virtualFolders);
  269. // And one for <Unit>
  270. std::string unitFiles;
  271. tree.BuildUnit(unitFiles, std::string(mf->GetHomeDirectory()) + "/");
  272. // figure out the compiler
  273. std::string compiler = this->GetCBCompilerId(mf);
  274. std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  275. fout<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"
  276. "<CodeBlocks_project_file>\n"
  277. " <FileVersion major=\"1\" minor=\"6\" />\n"
  278. " <Project>\n"
  279. " <Option title=\"" << mf->GetProjectName()<<"\" />\n"
  280. " <Option makefile_is_custom=\"1\" />\n"
  281. " <Option compiler=\"" << compiler << "\" />\n"
  282. " "<<virtualFolders<<"\n"
  283. " <Build>\n";
  284. this->AppendTarget(fout, "all", 0, make.c_str(), mf, compiler.c_str());
  285. // add all executable and library targets and some of the GLOBAL
  286. // and UTILITY targets
  287. for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin();
  288. lg!=lgs.end(); lg++)
  289. {
  290. cmMakefile* makefile=(*lg)->GetMakefile();
  291. cmTargets& targets=makefile->GetTargets();
  292. for (cmTargets::iterator ti = targets.begin();
  293. ti != targets.end(); ti++)
  294. {
  295. switch(ti->second.GetType())
  296. {
  297. case cmTarget::GLOBAL_TARGET:
  298. {
  299. bool insertTarget = false;
  300. // Only add the global targets from CMAKE_BINARY_DIR,
  301. // not from the subdirs
  302. if (strcmp(makefile->GetStartOutputDirectory(),
  303. makefile->GetHomeOutputDirectory())==0)
  304. {
  305. insertTarget = true;
  306. // only add the "edit_cache" target if it's not ccmake, because
  307. // this will not work within the IDE
  308. if (ti->first == "edit_cache")
  309. {
  310. const char* editCommand = makefile->GetDefinition
  311. ("CMAKE_EDIT_COMMAND");
  312. if (editCommand == 0)
  313. {
  314. insertTarget = false;
  315. }
  316. else if (strstr(editCommand, "ccmake")!=NULL)
  317. {
  318. insertTarget = false;
  319. }
  320. }
  321. }
  322. if (insertTarget)
  323. {
  324. this->AppendTarget(fout, ti->first.c_str(), 0,
  325. make.c_str(), makefile, compiler.c_str());
  326. }
  327. }
  328. break;
  329. case cmTarget::UTILITY:
  330. // Add all utility targets, except the Nightly/Continuous/
  331. // Experimental-"sub"targets as e.g. NightlyStart
  332. if (((ti->first.find("Nightly")==0) &&(ti->first!="Nightly"))
  333. || ((ti->first.find("Continuous")==0)&&(ti->first!="Continuous"))
  334. || ((ti->first.find("Experimental")==0)
  335. && (ti->first!="Experimental")))
  336. {
  337. break;
  338. }
  339. this->AppendTarget(fout, ti->first.c_str(), 0,
  340. make.c_str(), makefile, compiler.c_str());
  341. break;
  342. case cmTarget::EXECUTABLE:
  343. case cmTarget::STATIC_LIBRARY:
  344. case cmTarget::SHARED_LIBRARY:
  345. case cmTarget::MODULE_LIBRARY:
  346. {
  347. this->AppendTarget(fout, ti->first.c_str(), &ti->second,
  348. make.c_str(), makefile, compiler.c_str());
  349. std::string fastTarget = ti->first;
  350. fastTarget += "/fast";
  351. this->AppendTarget(fout, fastTarget.c_str(), &ti->second,
  352. make.c_str(), makefile, compiler.c_str());
  353. }
  354. break;
  355. // ignore these:
  356. case cmTarget::INSTALL_FILES:
  357. case cmTarget::INSTALL_PROGRAMS:
  358. case cmTarget::INSTALL_DIRECTORY:
  359. default:
  360. break;
  361. }
  362. }
  363. }
  364. fout<<" </Build>\n";
  365. // Collect all used source files in the project
  366. // Sort them into two containers, one for C/C++ implementation files
  367. // which may have an acompanying header, one for all other files
  368. std::map<std::string, cmSourceFile*> cFiles;
  369. std::set<std::string> otherFiles;
  370. for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin();
  371. lg!=lgs.end(); lg++)
  372. {
  373. cmMakefile* makefile=(*lg)->GetMakefile();
  374. cmTargets& targets=makefile->GetTargets();
  375. for (cmTargets::iterator ti = targets.begin();
  376. ti != targets.end(); ti++)
  377. {
  378. switch(ti->second.GetType())
  379. {
  380. case cmTarget::EXECUTABLE:
  381. case cmTarget::STATIC_LIBRARY:
  382. case cmTarget::SHARED_LIBRARY:
  383. case cmTarget::MODULE_LIBRARY:
  384. case cmTarget::UTILITY: // can have sources since 2.6.3
  385. {
  386. const std::vector<cmSourceFile*>&sources=ti->second.GetSourceFiles();
  387. for (std::vector<cmSourceFile*>::const_iterator si=sources.begin();
  388. si!=sources.end(); si++)
  389. {
  390. // don't add source files which have the GENERATED property set:
  391. if ((*si)->GetPropertyAsBool("GENERATED"))
  392. {
  393. continue;
  394. }
  395. // check whether it is a C/C++ implementation file
  396. bool isCFile = false;
  397. if ((*si)->GetLanguage() && (*(*si)->GetLanguage() == 'C'))
  398. {
  399. for(std::vector<std::string>::const_iterator
  400. ext = mf->GetSourceExtensions().begin();
  401. ext != mf->GetSourceExtensions().end();
  402. ++ext)
  403. {
  404. if ((*si)->GetExtension() == *ext)
  405. {
  406. isCFile = true;
  407. break;
  408. }
  409. }
  410. }
  411. // then put it accordingly into one of the two containers
  412. if (isCFile)
  413. {
  414. cFiles[(*si)->GetFullPath()] = *si ;
  415. }
  416. else
  417. {
  418. otherFiles.insert((*si)->GetFullPath());
  419. }
  420. }
  421. }
  422. default: // intended fallthrough
  423. break;
  424. }
  425. }
  426. }
  427. // The following loop tries to add header files matching to implementation
  428. // files to the project. It does that by iterating over all source files,
  429. // replacing the file name extension with ".h" and checks whether such a
  430. // file exists. If it does, it is inserted into the map of files.
  431. // A very similar version of that code exists also in the kdevelop
  432. // project generator.
  433. for (std::map<std::string, cmSourceFile*>::const_iterator
  434. sit=cFiles.begin();
  435. sit!=cFiles.end();
  436. ++sit)
  437. {
  438. std::string headerBasename=cmSystemTools::GetFilenamePath(sit->first);
  439. headerBasename+="/";
  440. headerBasename+=cmSystemTools::GetFilenameWithoutExtension(sit->first);
  441. // check if there's a matching header around
  442. for(std::vector<std::string>::const_iterator
  443. ext = mf->GetHeaderExtensions().begin();
  444. ext != mf->GetHeaderExtensions().end();
  445. ++ext)
  446. {
  447. std::string hname=headerBasename;
  448. hname += ".";
  449. hname += *ext;
  450. // if it's already in the set, don't check if it exists on disk
  451. std::set<std::string>::const_iterator headerIt=otherFiles.find(hname);
  452. if (headerIt != otherFiles.end())
  453. {
  454. break;
  455. }
  456. if(cmSystemTools::FileExists(hname.c_str()))
  457. {
  458. otherFiles.insert(hname);
  459. break;
  460. }
  461. }
  462. }
  463. // insert all source files in the CodeBlocks project
  464. // first the C/C++ implementation files, then all others
  465. for (std::map<std::string, cmSourceFile*>::const_iterator
  466. sit=cFiles.begin();
  467. sit!=cFiles.end();
  468. ++sit)
  469. {
  470. fout<<" <Unit filename=\""<< sit->first <<"\">\n"
  471. " </Unit>\n";
  472. }
  473. for (std::set<std::string>::const_iterator
  474. sit=otherFiles.begin();
  475. sit!=otherFiles.end();
  476. ++sit)
  477. {
  478. fout<<" <Unit filename=\""<< sit->c_str() <<"\">\n"
  479. " </Unit>\n";
  480. }
  481. // Add CMakeLists.txt
  482. fout<<unitFiles;
  483. fout<<" </Project>\n"
  484. "</CodeBlocks_project_file>\n";
  485. }
  486. // Generate the xml code for one target.
  487. void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
  488. const char* targetName,
  489. cmTarget* target,
  490. const char* make,
  491. const cmMakefile* makefile,
  492. const char* compiler)
  493. {
  494. std::string makefileName = makefile->GetStartOutputDirectory();
  495. makefileName += "/Makefile";
  496. fout<<" <Target title=\"" << targetName << "\">\n";
  497. if (target!=0)
  498. {
  499. int cbTargetType = this->GetCBTargetType(target);
  500. std::string workingDir = makefile->GetStartOutputDirectory();
  501. if ( target->GetType()==cmTarget::EXECUTABLE)
  502. {
  503. // Determine the directory where the executable target is created, and
  504. // set the working directory to this dir.
  505. const char* runtimeOutputDir = makefile->GetDefinition(
  506. "CMAKE_RUNTIME_OUTPUT_DIRECTORY");
  507. if (runtimeOutputDir != 0)
  508. {
  509. workingDir = runtimeOutputDir;
  510. }
  511. else
  512. {
  513. const char* executableOutputDir = makefile->GetDefinition(
  514. "EXECUTABLE_OUTPUT_PATH");
  515. if (executableOutputDir != 0)
  516. {
  517. workingDir = executableOutputDir;
  518. }
  519. }
  520. }
  521. const char* buildType = makefile->GetDefinition("CMAKE_BUILD_TYPE");
  522. fout<<" <Option output=\"" << target->GetLocation(buildType)
  523. << "\" prefix_auto=\"0\" extension_auto=\"0\" />\n"
  524. " <Option working_dir=\"" << workingDir << "\" />\n"
  525. " <Option object_output=\"./\" />\n"
  526. " <Option type=\"" << cbTargetType << "\" />\n"
  527. " <Option compiler=\"" << compiler << "\" />\n"
  528. " <Compiler>\n";
  529. // the include directories for this target
  530. const std::vector<std::string>& incDirs =
  531. target->GetMakefile()->GetIncludeDirectories();
  532. for(std::vector<std::string>::const_iterator dirIt=incDirs.begin();
  533. dirIt != incDirs.end();
  534. ++dirIt)
  535. {
  536. fout <<" <Add directory=\"" << dirIt->c_str() << "\" />\n";
  537. }
  538. fout<<" </Compiler>\n";
  539. }
  540. else // e.g. all and the GLOBAL and UTILITY targets
  541. {
  542. fout<<" <Option working_dir=\""
  543. << makefile->GetStartOutputDirectory() << "\" />\n"
  544. <<" <Option type=\"" << 4 << "\" />\n";
  545. }
  546. fout<<" <MakeCommands>\n"
  547. " <Build command=\""
  548. << this->BuildMakeCommand(make, makefileName.c_str(), targetName)
  549. << "\" />\n"
  550. " <CompileFile command=\""
  551. << this->BuildMakeCommand(make, makefileName.c_str(),"&quot;$file&quot;")
  552. << "\" />\n"
  553. " <Clean command=\""
  554. << this->BuildMakeCommand(make, makefileName.c_str(), "clean")
  555. << "\" />\n"
  556. " <DistClean command=\""
  557. << this->BuildMakeCommand(make, makefileName.c_str(), "clean")
  558. << "\" />\n"
  559. " </MakeCommands>\n"
  560. " </Target>\n";
  561. }
  562. // Translate the cmake compiler id into the CodeBlocks compiler id
  563. std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf)
  564. {
  565. // figure out which language to use
  566. // for now care only for C and C++
  567. std::string compilerIdVar = "CMAKE_CXX_COMPILER_ID";
  568. if (this->GlobalGenerator->GetLanguageEnabled("CXX") == false)
  569. {
  570. compilerIdVar = "CMAKE_C_COMPILER_ID";
  571. }
  572. std::string hostSystemName = mf->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME");
  573. std::string systemName = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
  574. std::string compilerId = mf->GetSafeDefinition(compilerIdVar.c_str());
  575. std::string compiler = "gcc"; // default to gcc
  576. if (compilerId == "MSVC")
  577. {
  578. compiler = "msvc8";
  579. }
  580. else if (compilerId == "Borland")
  581. {
  582. compiler = "bcc";
  583. }
  584. else if (compilerId == "SDCC")
  585. {
  586. compiler = "sdcc";
  587. }
  588. else if (compilerId == "Intel")
  589. {
  590. compiler = "icc";
  591. }
  592. else if (compilerId == "Watcom")
  593. {
  594. compiler = "ow";
  595. }
  596. else if (compilerId == "GNU")
  597. {
  598. compiler = "gcc";
  599. }
  600. return compiler;
  601. }
  602. // Translate the cmake target type into the CodeBlocks target type id
  603. int cmExtraCodeBlocksGenerator::GetCBTargetType(cmTarget* target)
  604. {
  605. if ( target->GetType()==cmTarget::EXECUTABLE)
  606. {
  607. if ((target->GetPropertyAsBool("WIN32_EXECUTABLE"))
  608. || (target->GetPropertyAsBool("MACOSX_BUNDLE")))
  609. {
  610. return 0;
  611. }
  612. else
  613. {
  614. return 1;
  615. }
  616. }
  617. else if ( target->GetType()==cmTarget::STATIC_LIBRARY)
  618. {
  619. return 2;
  620. }
  621. else if ((target->GetType()==cmTarget::SHARED_LIBRARY)
  622. || (target->GetType()==cmTarget::MODULE_LIBRARY))
  623. {
  624. return 3;
  625. }
  626. return 4;
  627. }
  628. // Create the command line for building the given target using the selected
  629. // make
  630. std::string cmExtraCodeBlocksGenerator::BuildMakeCommand(
  631. const std::string& make, const char* makefile, const char* target)
  632. {
  633. std::string command = make;
  634. if (strcmp(this->GlobalGenerator->GetName(), "NMake Makefiles")==0)
  635. {
  636. std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
  637. command += " /NOLOGO /f &quot;";
  638. command += makefileName;
  639. command += "&quot; ";
  640. command += " VERBOSE=1 ";
  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 += " VERBOSE=1 ";
  652. command += target;
  653. }
  654. else
  655. {
  656. std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
  657. command += " -f &quot;";
  658. command += makefileName;
  659. command += "&quot; ";
  660. command += " VERBOSE=1 ";
  661. command += target;
  662. }
  663. return command;
  664. }