cmGlobalXCodeGenerator.cxx 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  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. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmGlobalXCodeGenerator.h"
  14. #include "cmLocalXCodeGenerator.h"
  15. #include "cmMakefile.h"
  16. #include "cmXCodeObject.h"
  17. #include "cmake.h"
  18. #include "cmGeneratedFileStream.h"
  19. #include "cmSourceFile.h"
  20. //TODO
  21. // custom commands
  22. // custom targets
  23. // ALL_BUILD
  24. // RUN_TESTS
  25. // add a group for Sources Headers, and other cmake group stuff
  26. // for each target create a custom build phase that is run first
  27. // it can have inputs and outputs should just be a makefile
  28. // per file flags howto
  29. // 115281011528101152810000 = {
  30. // fileEncoding = 4;
  31. // isa = PBXFileReference;
  32. // lastKnownFileType = sourcecode.cpp.cpp;
  33. // path = /Users/kitware/Bill/CMake/Source/cmakemain.cxx;
  34. // refType = 0;
  35. // sourceTree = "<absolute>";
  36. // };
  37. // 115285011528501152850000 = {
  38. // fileRef = 115281011528101152810000;
  39. // isa = PBXBuildFile;
  40. // settings = {
  41. // COMPILER_FLAGS = "-Dcmakemakeindefflag";
  42. // };
  43. // };
  44. // custom commands and clean up custom targets
  45. // do I need an ALL_BUILD yes
  46. // exe/lib output paths
  47. //----------------------------------------------------------------------------
  48. cmGlobalXCodeGenerator::cmGlobalXCodeGenerator()
  49. {
  50. m_FindMakeProgramFile = "CMakeFindXCode.cmake";
  51. m_RootObject = 0;
  52. m_MainGroupChildren = 0;
  53. m_SourcesGroupChildren = 0;
  54. m_ExternalGroupChildren = 0;
  55. }
  56. //----------------------------------------------------------------------------
  57. void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
  58. lang,
  59. cmMakefile * mf)
  60. {
  61. mf->AddDefinition("CMAKE_GENERATOR_CC", "gcc");
  62. mf->AddDefinition("CMAKE_GENERATOR_CXX", "g++");
  63. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  64. this->cmGlobalGenerator::EnableLanguage(lang, mf);
  65. }
  66. //----------------------------------------------------------------------------
  67. int cmGlobalXCodeGenerator::TryCompile(const char *,
  68. const char * bindir,
  69. const char * projectName,
  70. const char * targetName,
  71. std::string * output,
  72. cmMakefile*)
  73. {
  74. // now build the test
  75. std::string makeCommand =
  76. m_CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_MAKE_PROGRAM");
  77. if(makeCommand.size() == 0)
  78. {
  79. cmSystemTools::Error(
  80. "Generator cannot find the appropriate make command.");
  81. return 1;
  82. }
  83. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  84. std::string lowerCaseCommand = makeCommand;
  85. cmSystemTools::LowerCase(lowerCaseCommand);
  86. /**
  87. * Run an executable command and put the stdout in output.
  88. */
  89. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  90. cmSystemTools::ChangeDirectory(bindir);
  91. // Usage: xcodebuild [-project <projectname>] [-activetarget]
  92. // [-alltargets] [-target <targetname>]... [-activebuildstyle]
  93. // [-buildstyle <buildstylename>] [-optionalbuildstyle <buildstylename>]
  94. // [<buildsetting>=<value>]... [<buildaction>]...
  95. // xcodebuild [-list]
  96. makeCommand += " -project ";
  97. makeCommand += projectName;
  98. makeCommand += ".xcode";
  99. makeCommand += " build ";
  100. if (targetName)
  101. {
  102. makeCommand += "-target ";
  103. makeCommand += targetName;
  104. }
  105. makeCommand += " -buildstyle Development ";
  106. makeCommand += " SYMROOT=";
  107. makeCommand += cmSystemTools::ConvertToOutputPath(bindir);
  108. int retVal;
  109. int timeout = cmGlobalGenerator::s_TryCompileTimeout;
  110. if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), output, &retVal,
  111. 0, false, timeout))
  112. {
  113. cmSystemTools::Error("Generator: execution of xcodebuild failed.");
  114. // return to the original directory
  115. cmSystemTools::ChangeDirectory(cwd.c_str());
  116. return 1;
  117. }
  118. cmSystemTools::ChangeDirectory(cwd.c_str());
  119. return retVal;
  120. }
  121. void cmGlobalXCodeGenerator::ConfigureOutputPaths()
  122. {
  123. // Format the library and executable output paths.
  124. m_LibraryOutputPath =
  125. m_CurrentMakefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  126. if(m_LibraryOutputPath.size() == 0)
  127. {
  128. m_LibraryOutputPath = m_CurrentMakefile->GetCurrentOutputDirectory();
  129. }
  130. // make sure there is a trailing slash
  131. if(m_LibraryOutputPath.size() &&
  132. m_LibraryOutputPath[m_LibraryOutputPath.size()-1] != '/')
  133. {
  134. m_LibraryOutputPath += "/";
  135. if(!cmSystemTools::MakeDirectory(m_LibraryOutputPath.c_str()))
  136. {
  137. cmSystemTools::Error("Error creating directory ",
  138. m_LibraryOutputPath.c_str());
  139. }
  140. }
  141. m_CurrentMakefile->AddLinkDirectory(m_LibraryOutputPath.c_str());
  142. m_ExecutableOutputPath =
  143. m_CurrentMakefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  144. if(m_ExecutableOutputPath.size() == 0)
  145. {
  146. m_ExecutableOutputPath = m_CurrentMakefile->GetCurrentOutputDirectory();
  147. }
  148. // make sure there is a trailing slash
  149. if(m_ExecutableOutputPath.size() &&
  150. m_ExecutableOutputPath[m_ExecutableOutputPath.size()-1] != '/')
  151. {
  152. m_ExecutableOutputPath += "/";
  153. if(!cmSystemTools::MakeDirectory(m_ExecutableOutputPath.c_str()))
  154. {
  155. cmSystemTools::Error("Error creating directory ",
  156. m_ExecutableOutputPath.c_str());
  157. }
  158. }
  159. }
  160. //----------------------------------------------------------------------------
  161. ///! Create a local generator appropriate to this Global Generator
  162. cmLocalGenerator *cmGlobalXCodeGenerator::CreateLocalGenerator()
  163. {
  164. cmLocalGenerator *lg = new cmLocalXCodeGenerator;
  165. lg->SetGlobalGenerator(this);
  166. return lg;
  167. }
  168. //----------------------------------------------------------------------------
  169. void cmGlobalXCodeGenerator::Generate()
  170. {
  171. this->cmGlobalGenerator::Generate();
  172. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  173. for(it = m_ProjectMap.begin(); it!= m_ProjectMap.end(); ++it)
  174. {
  175. this->OutputXCodeProject(it->second[0], it->second);
  176. }
  177. }
  178. //----------------------------------------------------------------------------
  179. void cmGlobalXCodeGenerator::ClearXCodeObjects()
  180. {
  181. for(unsigned int i = 0; i < m_XCodeObjects.size(); ++i)
  182. {
  183. delete m_XCodeObjects[i];
  184. }
  185. m_XCodeObjects.clear();
  186. }
  187. //----------------------------------------------------------------------------
  188. cmXCodeObject*
  189. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
  190. {
  191. cmXCodeObject* obj = new cmXCodeObject(ptype, cmXCodeObject::OBJECT);
  192. m_XCodeObjects.push_back(obj);
  193. return obj;
  194. }
  195. //----------------------------------------------------------------------------
  196. cmXCodeObject*
  197. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
  198. {
  199. cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, type);
  200. m_XCodeObjects.push_back(obj);
  201. return obj;
  202. }
  203. cmXCodeObject*
  204. cmGlobalXCodeGenerator::CreateString(const char* s)
  205. {
  206. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::STRING);
  207. obj->SetString(s);
  208. return obj;
  209. }
  210. cmXCodeObject* cmGlobalXCodeGenerator::CreateObjectReference(cmXCodeObject* ref)
  211. {
  212. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::OBJECT_REF);
  213. obj->SetObject(ref);
  214. return obj;
  215. }
  216. cmXCodeObject*
  217. cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
  218. cmSourceFile* sf)
  219. {
  220. std::string flags;
  221. // Add flags from source file properties.
  222. m_CurrentLocalGenerator
  223. ->AppendFlags(flags, sf->GetProperty("COMPILE_FLAGS"));
  224. cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  225. m_SourcesGroupChildren->AddObject(fileRef);
  226. cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
  227. buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef));
  228. cmXCodeObject* settings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  229. settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags.c_str()));
  230. buildFile->AddAttribute("settings", settings);
  231. fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
  232. const char* lang =
  233. this->GetLanguageFromExtension(sf->GetSourceExtension().c_str());
  234. std::string sourcecode = "sourcecode";
  235. if(!lang)
  236. {
  237. std::string ext = ".";
  238. ext = sf->GetSourceExtension();
  239. sourcecode += ext;
  240. sourcecode += ext;
  241. }
  242. else if(strcmp(lang, "C") == 0)
  243. {
  244. sourcecode += ".c.c";
  245. }
  246. // default to c++
  247. else
  248. {
  249. sourcecode += ".cpp.cpp";
  250. }
  251. fileRef->AddAttribute("lastKnownFileType",
  252. this->CreateString(sourcecode.c_str()));
  253. fileRef->AddAttribute("path", this->CreateString(
  254. lg->ConvertToRelativeOutputPath(sf->GetFullPath().c_str()).c_str()));
  255. fileRef->AddAttribute("refType", this->CreateString("4"));
  256. fileRef->AddAttribute("sourceTree", this->CreateString("<absolute>"));
  257. return buildFile;
  258. }
  259. //----------------------------------------------------------------------------
  260. void
  261. cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
  262. std::vector<cmXCodeObject*>&
  263. targets)
  264. {
  265. m_CurrentLocalGenerator = gen;
  266. m_CurrentMakefile = gen->GetMakefile();
  267. cmTargets &tgts = gen->GetMakefile()->GetTargets();
  268. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  269. {
  270. cmTarget& cmtarget = l->second;
  271. if(cmtarget.GetType() == cmTarget::UTILITY ||
  272. cmtarget.GetType() == cmTarget::INSTALL_FILES ||
  273. cmtarget.GetType() == cmTarget::INSTALL_PROGRAMS)
  274. {
  275. if(cmtarget.GetType() == cmTarget::UTILITY)
  276. {
  277. targets.push_back(this->CreateUtilityTarget(cmtarget));
  278. }
  279. continue;
  280. }
  281. // create source build phase
  282. cmXCodeObject* sourceBuildPhase =
  283. this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
  284. sourceBuildPhase->AddAttribute("buildActionMask",
  285. this->CreateString("2147483647"));
  286. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  287. sourceBuildPhase->AddAttribute("files", buildFiles);
  288. sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  289. this->CreateString("0"));
  290. std::vector<cmSourceFile*> &classes = l->second.GetSourceFiles();
  291. // add all the sources
  292. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  293. i != classes.end(); ++i)
  294. {
  295. buildFiles->AddObject(this->CreateXCodeSourceFile(gen, *i));
  296. }
  297. // create header build phase
  298. cmXCodeObject* headerBuildPhase =
  299. this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase);
  300. headerBuildPhase->AddAttribute("buildActionMask",
  301. this->CreateString("2147483647"));
  302. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  303. headerBuildPhase->AddAttribute("files", buildFiles);
  304. headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  305. this->CreateString("0"));
  306. // create framework build phase
  307. cmXCodeObject* frameworkBuildPhase =
  308. this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
  309. frameworkBuildPhase->AddAttribute("buildActionMask",
  310. this->CreateString("2147483647"));
  311. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  312. frameworkBuildPhase->AddAttribute("files", buildFiles);
  313. frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  314. this->CreateString("0"));
  315. cmXCodeObject* buildPhases =
  316. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  317. this->CreateCustomCommands(buildPhases, sourceBuildPhase,
  318. headerBuildPhase, frameworkBuildPhase,
  319. cmtarget);
  320. targets.push_back(this->CreateXCodeTarget(l->second, buildPhases));
  321. }
  322. }
  323. void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
  324. cmXCodeObject*
  325. sourceBuildPhase,
  326. cmXCodeObject*
  327. headerBuildPhase,
  328. cmXCodeObject*
  329. frameworkBuildPhase,
  330. cmTarget& cmtarget)
  331. {
  332. std::vector<cmCustomCommand> const & prebuild
  333. = cmtarget.GetPreBuildCommands();
  334. std::vector<cmCustomCommand> const & prelink
  335. = cmtarget.GetPreLinkCommands();
  336. std::vector<cmCustomCommand> const & postbuild
  337. = cmtarget.GetPostBuildCommands();
  338. cmtarget.TraceVSDependencies(cmtarget.GetName(), m_CurrentMakefile);
  339. std::vector<cmSourceFile*> &classes = cmtarget.GetSourceFiles();
  340. // add all the sources
  341. std::vector<cmCustomCommand> commands;
  342. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  343. i != classes.end(); ++i)
  344. {
  345. if((*i)->GetCustomCommand())
  346. {
  347. commands.push_back(*(*i)->GetCustomCommand());
  348. }
  349. }
  350. // create prebuild phase
  351. cmXCodeObject* cmakeRulesBuildPhase = 0;
  352. if(commands.size())
  353. {
  354. cmakeRulesBuildPhase =
  355. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  356. cmakeRulesBuildPhase->AddAttribute("buildActionMask",
  357. this->CreateString("2147483647"));
  358. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  359. cmakeRulesBuildPhase->AddAttribute("files", buildFiles);
  360. cmakeRulesBuildPhase->AddAttribute("name",
  361. this->CreateString("CMake Rules"));
  362. cmakeRulesBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  363. this->CreateString("0"));
  364. cmakeRulesBuildPhase->AddAttribute("shellPath",
  365. this->CreateString("/bin/sh"));
  366. this->AddCommandsToBuildPhase(cmakeRulesBuildPhase, cmtarget, commands,
  367. "cmakeRulesCommands");
  368. }
  369. // create prebuild phase
  370. cmXCodeObject* preBuildPhase = 0;
  371. if(prebuild.size())
  372. {
  373. preBuildPhase =
  374. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  375. preBuildPhase->AddAttribute("buildActionMask",
  376. this->CreateString("2147483647"));
  377. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  378. preBuildPhase->AddAttribute("files", buildFiles);
  379. preBuildPhase->AddAttribute("name",
  380. this->CreateString("CMake PreBuild Rules"));
  381. preBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  382. this->CreateString("0"));
  383. preBuildPhase->AddAttribute("shellPath", this->CreateString("/bin/sh"));
  384. this->AddCommandsToBuildPhase(preBuildPhase, cmtarget, prebuild,
  385. "preBuildCommands");
  386. }
  387. // create prebuild phase
  388. cmXCodeObject* preLinkPhase = 0;
  389. if(prelink.size())
  390. {
  391. preLinkPhase =
  392. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  393. preLinkPhase->AddAttribute("buildActionMask",
  394. this->CreateString("2147483647"));
  395. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  396. preLinkPhase->AddAttribute("files", buildFiles);
  397. preLinkPhase->AddAttribute("name",
  398. this->CreateString("CMake PreLink Rules"));
  399. preLinkPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  400. this->CreateString("0"));
  401. preLinkPhase->AddAttribute("shellPath", this->CreateString("/bin/sh"));
  402. this->AddCommandsToBuildPhase(preLinkPhase, cmtarget, prelink,
  403. "preLinkCommands");
  404. }
  405. // create prebuild phase
  406. cmXCodeObject* postBuildPhase = 0;
  407. if(postbuild.size())
  408. {
  409. postBuildPhase =
  410. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  411. postBuildPhase->AddAttribute("buildActionMask",
  412. this->CreateString("2147483647"));
  413. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  414. postBuildPhase->AddAttribute("files", buildFiles);
  415. postBuildPhase->AddAttribute("name",
  416. this->CreateString("CMake PostBuild Rules"));
  417. postBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  418. this->CreateString("0"));
  419. postBuildPhase->AddAttribute("shellPath", this->CreateString("/bin/sh"));
  420. this->AddCommandsToBuildPhase(postBuildPhase, cmtarget, postbuild,
  421. "postBuildCommands");
  422. }
  423. // the order here is the order they will be built in
  424. if(preBuildPhase)
  425. {
  426. buildPhases->AddObject(preBuildPhase);
  427. }
  428. if(cmakeRulesBuildPhase)
  429. {
  430. buildPhases->AddObject(cmakeRulesBuildPhase);
  431. }
  432. if(sourceBuildPhase)
  433. {
  434. buildPhases->AddObject(sourceBuildPhase);
  435. }
  436. if(headerBuildPhase)
  437. {
  438. buildPhases->AddObject(headerBuildPhase);
  439. }
  440. if(preLinkPhase)
  441. {
  442. buildPhases->AddObject(preLinkPhase);
  443. }
  444. if(frameworkBuildPhase)
  445. {
  446. buildPhases->AddObject(frameworkBuildPhase);
  447. }
  448. if(postBuildPhase)
  449. {
  450. buildPhases->AddObject(postBuildPhase);
  451. }
  452. }
  453. void
  454. cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  455. cmTarget& target,
  456. std::vector<cmCustomCommand>
  457. const & commands,
  458. const char* name)
  459. {
  460. std::string makefile = m_CurrentMakefile->GetCurrentOutputDirectory();
  461. cmSystemTools::MakeDirectory(makefile.c_str());
  462. makefile += "/";
  463. makefile += target.GetName();
  464. makefile += "_";
  465. makefile += name;
  466. makefile += ".make";
  467. cmGeneratedFileStream makefileStream(makefile.c_str());
  468. if(!makefileStream)
  469. {
  470. return;
  471. }
  472. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  473. makefileStream << "# Custom rules for " << target.GetName() << "\n";
  474. // have all depend on all outputs
  475. makefileStream << "all: ";
  476. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  477. i != commands.end(); ++i)
  478. {
  479. cmCustomCommand const& cc = *i;
  480. if(cc.GetCommand().size())
  481. {
  482. if(cc.GetOutput().size())
  483. {
  484. makefileStream << "\\\n\t" << m_CurrentLocalGenerator
  485. ->ConvertToRelativeOutputPath(cc.GetOutput().c_str());
  486. }
  487. else
  488. {
  489. makefileStream << "\\\n\t" << target.GetName();
  490. }
  491. }
  492. }
  493. makefileStream << "\n\n";
  494. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  495. i != commands.end(); ++i)
  496. {
  497. cmCustomCommand const& cc = *i;
  498. if(cc.GetCommand().size())
  499. {
  500. makefileStream << "\n#" << "Custom command rule: " <<
  501. cc.GetComment() << "\n";
  502. if(cc.GetOutput().size())
  503. {
  504. makefileStream << m_CurrentLocalGenerator
  505. ->ConvertToRelativeOutputPath(cc.GetOutput().c_str()) << ": ";
  506. }
  507. else
  508. {
  509. // if no outputs then use the target name as this must
  510. // be a utility target
  511. makefileStream << target.GetName() << ": ";
  512. }
  513. for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
  514. d != cc.GetDepends().end(); ++d)
  515. {
  516. if(!this->FindTarget(d->c_str()))
  517. {
  518. makefileStream << "\\\n" << *d;
  519. }
  520. else
  521. {
  522. // if the depend is a target then make
  523. // the target with the source that is a custom command
  524. // depend on the that target via a AddUtility call
  525. target.AddUtility(d->c_str());
  526. }
  527. }
  528. makefileStream << "\n";
  529. makefileStream << "\t" << cc.GetCommand() << " "
  530. << cc.GetArguments() << "\n";
  531. }
  532. }
  533. std::string dir = cmSystemTools::ConvertToOutputPath(
  534. m_CurrentMakefile->GetCurrentOutputDirectory());
  535. std::string makecmd = "make -C ";
  536. makecmd += dir;
  537. makecmd += " -f ";
  538. makecmd += makefile;
  539. buildphase->AddAttribute("shellScript", this->CreateString(makecmd.c_str()));
  540. }
  541. void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
  542. cmXCodeObject* buildSettings,
  543. std::string& fileType,
  544. std::string& productType,
  545. std::string& productName)
  546. {
  547. this->ConfigureOutputPaths();
  548. std::string flags;
  549. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  550. (target.GetType() == cmTarget::MODULE_LIBRARY));
  551. if(shared)
  552. {
  553. flags += "-D";
  554. if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  555. {
  556. flags += custom_export_name;
  557. }
  558. else
  559. {
  560. std::string in = target.GetName();
  561. in += "_EXPORTS";
  562. flags += cmSystemTools::MakeCindentifier(in.c_str());
  563. }
  564. }
  565. const char* lang = target.GetLinkerLanguage(this);
  566. if(lang)
  567. {
  568. // Add language-specific flags.
  569. m_CurrentLocalGenerator->AddLanguageFlags(flags, lang);
  570. // Add shared-library flags if needed.
  571. m_CurrentLocalGenerator->AddSharedFlags(flags, lang, shared);
  572. }
  573. // Add define flags
  574. m_CurrentLocalGenerator->AppendFlags(flags,
  575. m_CurrentMakefile->GetDefineFlags());
  576. cmSystemTools::ReplaceString(flags, "\"", "\\\"");
  577. productName = target.GetName();
  578. bool needLinkDirs = true;
  579. switch(target.GetType())
  580. {
  581. case cmTarget::STATIC_LIBRARY:
  582. {
  583. needLinkDirs = false;
  584. if(m_LibraryOutputPath.size())
  585. {
  586. buildSettings->AddAttribute("SYMROOT",
  587. this->CreateString
  588. (m_LibraryOutputPath.c_str()));
  589. }
  590. productName += ".a";
  591. std::string t = "lib";
  592. t += productName;
  593. productName = t;
  594. productType = "com.apple.product-type.library.static";
  595. fileType = "archive.ar";
  596. buildSettings->AddAttribute("LIBRARY_STYLE",
  597. this->CreateString("STATIC"));
  598. break;
  599. }
  600. case cmTarget::MODULE_LIBRARY:
  601. {
  602. if(m_LibraryOutputPath.size())
  603. {
  604. buildSettings->AddAttribute("SYMROOT",
  605. this->CreateString
  606. (m_LibraryOutputPath.c_str()));
  607. }
  608. buildSettings->AddAttribute("LIBRARY_STYLE",
  609. this->CreateString("DYNAMIC"));
  610. productName += ".so";
  611. std::string t = "lib";
  612. t += productName;
  613. productName = t;
  614. buildSettings->AddAttribute("OTHER_LDFLAGS",
  615. this->CreateString("-bundle"));
  616. productType = "com.apple.product-type.library.dynamic";
  617. fileType = "compiled.mach-o.dylib";
  618. break;
  619. }
  620. case cmTarget::SHARED_LIBRARY:
  621. {
  622. if(m_LibraryOutputPath.size())
  623. {
  624. buildSettings->AddAttribute("SYMROOT",
  625. this->CreateString
  626. (m_LibraryOutputPath.c_str()));
  627. }
  628. buildSettings->AddAttribute("LIBRARY_STYLE",
  629. this->CreateString("DYNAMIC"));
  630. productName += ".dylib";
  631. std::string t = "lib";
  632. t += productName;
  633. productName = t;
  634. buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
  635. this->CreateString("1"));
  636. buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
  637. this->CreateString("1"));
  638. buildSettings->AddAttribute("OTHER_LDFLAGS",
  639. this->CreateString("-dynamiclib"));
  640. productType = "com.apple.product-type.library.dynamic";
  641. fileType = "compiled.mach-o.dylib";
  642. break;
  643. }
  644. case cmTarget::EXECUTABLE:
  645. if(m_ExecutableOutputPath.size())
  646. {
  647. buildSettings->AddAttribute("SYMROOT",
  648. this->CreateString
  649. (m_ExecutableOutputPath.c_str()));
  650. }
  651. fileType = "compiled.mach-o.executable";
  652. productType = "com.apple.product-type.tool";
  653. break;
  654. case cmTarget::UTILITY:
  655. break;
  656. case cmTarget::INSTALL_FILES:
  657. break;
  658. case cmTarget::INSTALL_PROGRAMS:
  659. break;
  660. }
  661. std::string dirs;
  662. if(needLinkDirs)
  663. {
  664. // Try to emit each search path once
  665. std::set<cmStdString> emitted;
  666. // Some search paths should never be emitted
  667. emitted.insert("");
  668. emitted.insert("/usr/lib");
  669. std::vector<std::string> const& linkdirs =
  670. target.GetLinkDirectories();
  671. for(std::vector<std::string>::const_iterator l = linkdirs.begin();
  672. l != linkdirs.end(); ++l)
  673. {
  674. std::string libpath =
  675. m_CurrentLocalGenerator->ConvertToOutputForExisting(l->c_str());
  676. if(emitted.insert(libpath).second)
  677. {
  678. dirs += libpath + " ";
  679. }
  680. }
  681. if(dirs.size())
  682. {
  683. buildSettings->AddAttribute("LIBRARY_SEARCH_PATHS",
  684. this->CreateString(dirs.c_str()));
  685. }
  686. }
  687. dirs = "";
  688. std::vector<std::string>& includes =
  689. m_CurrentMakefile->GetIncludeDirectories();
  690. std::vector<std::string>::iterator i = includes.begin();
  691. for(;i != includes.end(); ++i)
  692. {
  693. std::string incpath =
  694. m_CurrentLocalGenerator->ConvertToOutputForExisting(i->c_str());
  695. dirs += incpath + " ";
  696. }
  697. if(dirs.size())
  698. {
  699. buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
  700. this->CreateString(dirs.c_str()));
  701. }
  702. buildSettings->AddAttribute("GCC_OPTIMIZATION_LEVEL",
  703. this->CreateString("0"));
  704. buildSettings->AddAttribute("INSTALL_PATH",
  705. this->CreateString("/usr/local/bin"));
  706. buildSettings->AddAttribute("OPTIMIZATION_CFLAGS",
  707. this->CreateString(""));
  708. buildSettings->AddAttribute("OTHER_CFLAGS",
  709. this->CreateString(flags.c_str()));
  710. buildSettings->AddAttribute("OTHER_LDFLAGS",
  711. this->CreateString(""));
  712. buildSettings->AddAttribute("OTHER_REZFLAGS",
  713. this->CreateString(""));
  714. buildSettings->AddAttribute("SECTORDER_FLAGS",
  715. this->CreateString(""));
  716. buildSettings->AddAttribute("WARNING_CFLAGS",
  717. this->CreateString(
  718. "-Wmost -Wno-four-char-constants"
  719. " -Wno-unknown-pragmas"));
  720. buildSettings->AddAttribute("PRODUCT_NAME",
  721. this->CreateString(target.GetName()));
  722. }
  723. cmXCodeObject*
  724. cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
  725. {
  726. cmXCodeObject* shellBuildPhase =
  727. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  728. shellBuildPhase->AddAttribute("buildActionMask",
  729. this->CreateString("2147483647"));
  730. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  731. shellBuildPhase->AddAttribute("files", buildFiles);
  732. cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  733. shellBuildPhase->AddAttribute("inputPaths", inputPaths);
  734. cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  735. shellBuildPhase->AddAttribute("outputPaths", outputPaths);
  736. shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  737. this->CreateString("0"));
  738. shellBuildPhase->AddAttribute("shellPath",
  739. this->CreateString("/bin/sh"));
  740. shellBuildPhase->AddAttribute("shellScript",
  741. this->CreateString(
  742. "# shell script goes here\nexit 0"));
  743. cmXCodeObject* target =
  744. this->CreateObject(cmXCodeObject::PBXAggregateTarget);
  745. cmXCodeObject* buildPhases =
  746. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  747. this->CreateCustomCommands(buildPhases, 0, 0, 0, cmtarget);
  748. target->AddAttribute("buildPhases", buildPhases);
  749. cmXCodeObject* buildSettings =
  750. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  751. std::string fileTypeString;
  752. std::string productTypeString;
  753. std::string productName;
  754. this->CreateBuildSettings(cmtarget,
  755. buildSettings, fileTypeString,
  756. productTypeString, productName);
  757. target->AddAttribute("buildSettings", buildSettings);
  758. cmXCodeObject* dependencies = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  759. target->AddAttribute("dependencies", dependencies);
  760. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  761. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  762. target->SetcmTarget(&cmtarget);
  763. return target;
  764. }
  765. cmXCodeObject*
  766. cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
  767. cmXCodeObject* buildPhases)
  768. {
  769. cmXCodeObject* target =
  770. this->CreateObject(cmXCodeObject::PBXNativeTarget);
  771. target->AddAttribute("buildPhases", buildPhases);
  772. cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  773. target->AddAttribute("buildRules", buildRules);
  774. cmXCodeObject* buildSettings =
  775. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  776. std::string fileTypeString;
  777. std::string productTypeString;
  778. std::string productName;
  779. this->CreateBuildSettings(cmtarget,
  780. buildSettings, fileTypeString,
  781. productTypeString, productName);
  782. target->AddAttribute("buildSettings", buildSettings);
  783. cmXCodeObject* dependencies = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  784. target->AddAttribute("dependencies", dependencies);
  785. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  786. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  787. cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  788. fileRef->AddAttribute("explicitFileType",
  789. this->CreateString(fileTypeString.c_str()));
  790. fileRef->AddAttribute("path", this->CreateString(productName.c_str()));
  791. fileRef->AddAttribute("refType", this->CreateString("0"));
  792. fileRef->AddAttribute("sourceTree",
  793. this->CreateString("BUILT_PRODUCTS_DIR"));
  794. target->AddAttribute("productReference",
  795. this->CreateObjectReference(fileRef));
  796. target->AddAttribute("productType",
  797. this->CreateString(productTypeString.c_str()));
  798. target->SetcmTarget(&cmtarget);
  799. return target;
  800. }
  801. cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
  802. {
  803. if(!t)
  804. {
  805. return 0;
  806. }
  807. for(std::vector<cmXCodeObject*>::iterator i = m_XCodeObjects.begin();
  808. i != m_XCodeObjects.end(); ++i)
  809. {
  810. cmXCodeObject* o = *i;
  811. if(o->GetcmTarget() == t)
  812. {
  813. return o;
  814. }
  815. }
  816. return 0;
  817. }
  818. void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
  819. cmXCodeObject* dependTarget)
  820. {
  821. cmXCodeObject* targetdep = dependTarget->GetPBXTargetDependency();
  822. if(!targetdep)
  823. {
  824. cmXCodeObject* container =
  825. this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
  826. container->AddAttribute("containerPortal",
  827. this->CreateObjectReference(m_RootObject));
  828. container->AddAttribute("proxyType", this->CreateString("1"));
  829. container->AddAttribute("remoteGlobalIDString",
  830. this->CreateObjectReference(dependTarget));
  831. container->AddAttribute("remoteInfo",
  832. this->CreateString(
  833. dependTarget->GetcmTarget()->GetName()));
  834. targetdep =
  835. this->CreateObject(cmXCodeObject::PBXTargetDependency);
  836. targetdep->AddAttribute("target",
  837. this->CreateObjectReference(dependTarget));
  838. targetdep->AddAttribute("targetProxy",
  839. this->CreateObjectReference(container));
  840. dependTarget->SetPBXTargetDependency(targetdep);
  841. }
  842. cmXCodeObject* depends = target->GetObject("dependencies");
  843. if(!depends)
  844. {
  845. std::cerr << "target does not have dependencies attribute error...\n";
  846. }
  847. else
  848. {
  849. depends->AddObject(targetdep);
  850. }
  851. }
  852. void cmGlobalXCodeGenerator::AddLinkTarget(cmXCodeObject* target ,
  853. cmXCodeObject* dependTarget )
  854. {
  855. cmXCodeObject* ref = dependTarget->GetObject("productReference");
  856. cmXCodeObject* buildfile = this->CreateObject(cmXCodeObject::PBXBuildFile);
  857. buildfile->AddAttribute("fileRef", ref);
  858. cmXCodeObject* settings =
  859. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  860. buildfile->AddAttribute("settings", settings);
  861. cmXCodeObject* buildPhases = target->GetObject("buildPhases");
  862. cmXCodeObject* frameworkBuildPhase =
  863. buildPhases->GetObject(cmXCodeObject::PBXFrameworksBuildPhase);
  864. cmXCodeObject* files = frameworkBuildPhase->GetObject("files");
  865. files->AddObject(buildfile);
  866. }
  867. void cmGlobalXCodeGenerator::AddLinkLibrary(cmXCodeObject* target,
  868. const char* library)
  869. {
  870. // if the library is a full path then create a file reference
  871. // and build file and add them to the PBXFrameworksBuildPhase
  872. // for the target
  873. if(cmSystemTools::FileIsFullPath(library))
  874. {
  875. std::string libPath = library;
  876. cmXCodeObject* fileRef =
  877. this->CreateObject(cmXCodeObject::PBXFileReference);
  878. if(libPath[libPath.size()-1] == 'a')
  879. {
  880. fileRef->AddAttribute("lastKnownFileType",
  881. this->CreateString("archive.ar"));
  882. }
  883. else
  884. {
  885. fileRef->AddAttribute("lastKnownFileType",
  886. this->CreateString("compiled.mach-o.dylib"));
  887. }
  888. fileRef->AddAttribute("name",
  889. this->CreateString(
  890. cmSystemTools::GetFilenameName(libPath).c_str()));
  891. fileRef->AddAttribute("path", this->CreateString(libPath.c_str()));
  892. fileRef->AddAttribute("refType", this->CreateString("0"));
  893. fileRef->AddAttribute("sourceTree", this->CreateString("<absolute>"));
  894. cmXCodeObject* buildfile = this->CreateObject(cmXCodeObject::PBXBuildFile);
  895. buildfile->AddAttribute("fileRef", this->CreateObjectReference(fileRef));
  896. cmXCodeObject* settings =
  897. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  898. buildfile->AddAttribute("settings", settings);
  899. // get the framework build phase from the target
  900. cmXCodeObject* buildPhases = target->GetObject("buildPhases");
  901. cmXCodeObject* frameworkBuildPhase =
  902. buildPhases->GetObject(cmXCodeObject::PBXFrameworksBuildPhase);
  903. cmXCodeObject* files = frameworkBuildPhase->GetObject("files");
  904. files->AddObject(buildfile);
  905. m_ExternalGroupChildren->AddObject(fileRef);
  906. }
  907. else
  908. {
  909. // if the library is not a full path then add it with a -l flag
  910. // to the settings of the target
  911. cmXCodeObject* settings = target->GetObject("buildSettings");
  912. cmXCodeObject* ldflags = settings->GetObject("OTHER_LDFLAGS");
  913. std::string link = ldflags->GetString();
  914. cmSystemTools::ReplaceString(link, "\"", "");
  915. cmsys::RegularExpression reg("^([ \t]*\\-[lWRB])|([ \t]*\\-framework)|(\\${)|([ \t]*\\-pthread)|([ \t]*`)");
  916. // if the library is not already in the form required by the compiler
  917. // add a -l infront of the name
  918. if(!reg.find(library))
  919. {
  920. link += " -l";
  921. }
  922. link += library;
  923. ldflags->SetString(link.c_str());
  924. }
  925. }
  926. void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
  927. {
  928. cmTarget* cmtarget = target->GetcmTarget();
  929. if(!cmtarget)
  930. {
  931. std::cerr << "Error no target on xobject\n";
  932. return;
  933. }
  934. cmTarget::LinkLibraries::const_iterator j, jend;
  935. j = cmtarget->GetLinkLibraries().begin();
  936. jend = cmtarget->GetLinkLibraries().end();
  937. for(;j!= jend; ++j)
  938. {
  939. cmTarget* t = this->FindTarget(j->first.c_str());
  940. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  941. if(dptarget)
  942. {
  943. this->AddDependTarget(target, dptarget);
  944. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  945. {
  946. this->AddLinkTarget(target, dptarget);
  947. }
  948. }
  949. else
  950. {
  951. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  952. {
  953. this->AddLinkLibrary(target, j->first.c_str());
  954. }
  955. }
  956. }
  957. std::set<cmStdString>::const_iterator i, end;
  958. // write utility dependencies.
  959. i = cmtarget->GetUtilities().begin();
  960. end = cmtarget->GetUtilities().end();
  961. for(;i!= end; ++i)
  962. {
  963. cmTarget* t = this->FindTarget(i->c_str());
  964. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  965. if(dptarget)
  966. {
  967. this->AddDependTarget(target, dptarget);
  968. }
  969. else
  970. {
  971. std::cerr << "Error External Util???: " << i->c_str() << "\n";
  972. }
  973. }
  974. }
  975. // to force the location of a target
  976. // add this to build settings of target SYMROOT = /tmp/;
  977. //----------------------------------------------------------------------------
  978. void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* ,
  979. std::vector<cmLocalGenerator*>&
  980. generators
  981. )
  982. {
  983. this->ClearXCodeObjects();
  984. m_RootObject = 0;
  985. m_ExternalGroupChildren = 0;
  986. m_SourcesGroupChildren = 0;
  987. m_MainGroupChildren = 0;
  988. cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  989. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  990. cmXCodeObject* developBuildStyle =
  991. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  992. developBuildStyle->AddAttribute("name", this->CreateString("Development"));
  993. developBuildStyle->AddAttribute("buildSettings", group);
  994. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  995. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("YES"));
  996. cmXCodeObject* deployBuildStyle =
  997. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  998. deployBuildStyle->AddAttribute("name", this->CreateString("Deployment"));
  999. deployBuildStyle->AddAttribute("buildSettings", group);
  1000. cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1001. listObjs->AddObject(developBuildStyle);
  1002. listObjs->AddObject(deployBuildStyle);
  1003. cmXCodeObject* mainGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1004. m_MainGroupChildren =
  1005. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1006. mainGroup->AddAttribute("children", m_MainGroupChildren);
  1007. mainGroup->AddAttribute("refType", this->CreateString("4"));
  1008. mainGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1009. cmXCodeObject* sourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1010. m_SourcesGroupChildren =
  1011. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1012. sourcesGroup->AddAttribute("name", this->CreateString("Sources"));
  1013. sourcesGroup->AddAttribute("children", m_SourcesGroupChildren);
  1014. sourcesGroup->AddAttribute("refType", this->CreateString("4"));
  1015. sourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1016. m_MainGroupChildren->AddObject(sourcesGroup);
  1017. cmXCodeObject* externalGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1018. m_ExternalGroupChildren =
  1019. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1020. externalGroup->AddAttribute("name",
  1021. this->CreateString("External Libraries and Frameworks"));
  1022. externalGroup->AddAttribute("children", m_ExternalGroupChildren);
  1023. externalGroup->AddAttribute("refType", this->CreateString("4"));
  1024. externalGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1025. m_MainGroupChildren->AddObject(externalGroup);
  1026. cmXCodeObject* productGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1027. productGroup->AddAttribute("name", this->CreateString("Products"));
  1028. productGroup->AddAttribute("refType", this->CreateString("4"));
  1029. productGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1030. cmXCodeObject* productGroupChildren =
  1031. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1032. productGroup->AddAttribute("children", productGroupChildren);
  1033. m_MainGroupChildren->AddObject(productGroup);
  1034. m_RootObject = this->CreateObject(cmXCodeObject::PBXProject);
  1035. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1036. m_RootObject->AddAttribute("mainGroup",
  1037. this->CreateObjectReference(mainGroup));
  1038. m_RootObject->AddAttribute("buildSettings", group);
  1039. m_RootObject->AddAttribute("buildSyles", listObjs);
  1040. m_RootObject->AddAttribute("hasScannedForEncodings",
  1041. this->CreateString("0"));
  1042. std::vector<cmXCodeObject*> targets;
  1043. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  1044. i != generators.end(); ++i)
  1045. {
  1046. this->CreateXCodeTargets(*i, targets);
  1047. }
  1048. cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1049. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1050. i != targets.end(); ++i)
  1051. {
  1052. cmXCodeObject* t = *i;
  1053. this->AddDependAndLinkInformation(t);
  1054. allTargets->AddObject(t);
  1055. cmXCodeObject* productRef = t->GetObject("productReference");
  1056. if(productRef)
  1057. {
  1058. productGroupChildren->AddObject(productRef->GetObject());
  1059. }
  1060. }
  1061. m_RootObject->AddAttribute("targets", allTargets);
  1062. }
  1063. //----------------------------------------------------------------------------
  1064. void
  1065. cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
  1066. std::vector<cmLocalGenerator*>&
  1067. generators)
  1068. {
  1069. if(generators.size() == 0)
  1070. {
  1071. return;
  1072. }
  1073. this->CreateXCodeObjects(root,
  1074. generators);
  1075. std::string xcodeDir = root->GetMakefile()->GetStartOutputDirectory();
  1076. xcodeDir += "/";
  1077. xcodeDir += root->GetMakefile()->GetProjectName();
  1078. xcodeDir += ".xcode";
  1079. cmSystemTools::MakeDirectory(xcodeDir.c_str());
  1080. xcodeDir += "/project.pbxproj";
  1081. cmGeneratedFileStream fout(xcodeDir.c_str());
  1082. fout.SetCopyIfDifferent(true);
  1083. if(!fout)
  1084. {
  1085. return;
  1086. }
  1087. this->WriteXCodePBXProj(fout, root, generators);
  1088. this->ClearXCodeObjects();
  1089. }
  1090. //----------------------------------------------------------------------------
  1091. void
  1092. cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
  1093. cmLocalGenerator* ,
  1094. std::vector<cmLocalGenerator*>& )
  1095. {
  1096. fout << "// !$*UTF8*$!\n";
  1097. fout << "{\n";
  1098. cmXCodeObject::Indent(1, fout);
  1099. fout << "archiveVersion = 1;\n";
  1100. cmXCodeObject::Indent(1, fout);
  1101. fout << "classes = {\n";
  1102. cmXCodeObject::Indent(1, fout);
  1103. fout << "};\n";
  1104. cmXCodeObject::Indent(1, fout);
  1105. fout << "objectVersion = 39;\n";
  1106. cmXCodeObject::PrintList(m_XCodeObjects, fout);
  1107. cmXCodeObject::Indent(1, fout);
  1108. fout << "rootObject = " << m_RootObject->GetId() << ";\n";
  1109. fout << "}\n";
  1110. }
  1111. //----------------------------------------------------------------------------
  1112. void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry)
  1113. const
  1114. {
  1115. entry.name = this->GetName();
  1116. entry.brief = "Generate XCode project files.";
  1117. entry.full = "";
  1118. }