cmGlobalXCodeGenerator.cxx 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668
  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. #include "cmOrderLinkDirectories.h"
  21. //TODO
  22. // add OSX application stuff
  23. //----------------------------------------------------------------------------
  24. cmGlobalXCodeGenerator::cmGlobalXCodeGenerator()
  25. {
  26. m_FindMakeProgramFile = "CMakeFindXCode.cmake";
  27. m_RootObject = 0;
  28. m_MainGroupChildren = 0;
  29. m_SourcesGroupChildren = 0;
  30. m_CurrentMakefile = 0;
  31. m_CurrentLocalGenerator = 0;
  32. }
  33. //----------------------------------------------------------------------------
  34. void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
  35. lang,
  36. cmMakefile * mf)
  37. {
  38. mf->AddDefinition("XCODE","1");
  39. mf->AddDefinition("CMAKE_CFG_INTDIR",".");
  40. mf->AddDefinition("CMAKE_GENERATOR_CC", "gcc");
  41. mf->AddDefinition("CMAKE_GENERATOR_CXX", "g++");
  42. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  43. this->cmGlobalGenerator::EnableLanguage(lang, mf);
  44. }
  45. //----------------------------------------------------------------------------
  46. int cmGlobalXCodeGenerator::Build(
  47. const char *,
  48. const char *bindir,
  49. const char *projectName,
  50. const char *targetName,
  51. std::string *output,
  52. const char *makeCommandCSTR,
  53. const char *,
  54. bool clean)
  55. {
  56. // now build the test
  57. if(makeCommandCSTR == 0 || !strlen(makeCommandCSTR))
  58. {
  59. cmSystemTools::Error(
  60. "Generator cannot find the appropriate make command.");
  61. return 1;
  62. }
  63. std::string makeCommand =
  64. cmSystemTools::ConvertToOutputPath(makeCommandCSTR);
  65. std::string lowerCaseCommand = makeCommand;
  66. cmSystemTools::LowerCase(lowerCaseCommand);
  67. /**
  68. * Run an executable command and put the stdout in output.
  69. */
  70. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  71. cmSystemTools::ChangeDirectory(bindir);
  72. makeCommand += " -project ";
  73. makeCommand += projectName;
  74. makeCommand += ".xcode";
  75. if(clean)
  76. {
  77. makeCommand += " clean ";
  78. }
  79. makeCommand += " build -target ";
  80. if (targetName && strlen(targetName))
  81. {
  82. makeCommand += targetName;
  83. }
  84. else
  85. {
  86. makeCommand += "ALL_BUILD";
  87. }
  88. makeCommand += " -buildstyle Development ";
  89. int retVal;
  90. int timeout = cmGlobalGenerator::s_TryCompileTimeout;
  91. if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), output, &retVal,
  92. 0, false, timeout))
  93. {
  94. cmSystemTools::Error("Generator: execution of xcodebuild failed.");
  95. // return to the original directory
  96. cmSystemTools::ChangeDirectory(cwd.c_str());
  97. return 1;
  98. }
  99. cmSystemTools::ChangeDirectory(cwd.c_str());
  100. return retVal;
  101. }
  102. //----------------------------------------------------------------------------
  103. void cmGlobalXCodeGenerator::ConfigureOutputPaths()
  104. {
  105. // Format the library and executable output paths.
  106. m_LibraryOutputPath =
  107. m_CurrentMakefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  108. if(m_LibraryOutputPath.size() == 0)
  109. {
  110. m_LibraryOutputPath = m_CurrentMakefile->GetCurrentOutputDirectory();
  111. }
  112. // make sure there is a trailing slash
  113. if(m_LibraryOutputPath.size() &&
  114. m_LibraryOutputPath[m_LibraryOutputPath.size()-1] != '/')
  115. {
  116. m_LibraryOutputPath += "/";
  117. if(!cmSystemTools::MakeDirectory(m_LibraryOutputPath.c_str()))
  118. {
  119. cmSystemTools::Error("Error creating directory ",
  120. m_LibraryOutputPath.c_str());
  121. }
  122. }
  123. m_CurrentMakefile->AddLinkDirectory(m_LibraryOutputPath.c_str());
  124. m_ExecutableOutputPath =
  125. m_CurrentMakefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  126. if(m_ExecutableOutputPath.size() == 0)
  127. {
  128. m_ExecutableOutputPath = m_CurrentMakefile->GetCurrentOutputDirectory();
  129. }
  130. // make sure there is a trailing slash
  131. if(m_ExecutableOutputPath.size() &&
  132. m_ExecutableOutputPath[m_ExecutableOutputPath.size()-1] != '/')
  133. {
  134. m_ExecutableOutputPath += "/";
  135. if(!cmSystemTools::MakeDirectory(m_ExecutableOutputPath.c_str()))
  136. {
  137. cmSystemTools::Error("Error creating directory ",
  138. m_ExecutableOutputPath.c_str());
  139. }
  140. }
  141. }
  142. //----------------------------------------------------------------------------
  143. ///! Create a local generator appropriate to this Global Generator
  144. cmLocalGenerator *cmGlobalXCodeGenerator::CreateLocalGenerator()
  145. {
  146. cmLocalGenerator *lg = new cmLocalXCodeGenerator;
  147. lg->SetGlobalGenerator(this);
  148. return lg;
  149. }
  150. //----------------------------------------------------------------------------
  151. void cmGlobalXCodeGenerator::Generate()
  152. {
  153. this->cmGlobalGenerator::Generate();
  154. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  155. for(it = m_ProjectMap.begin(); it!= m_ProjectMap.end(); ++it)
  156. {
  157. cmLocalGenerator* root = it->second[0];
  158. m_CurrentProject = root->GetMakefile()->GetProjectName();
  159. this->SetCurrentLocalGenerator(root);
  160. m_OutputDir = m_CurrentMakefile->GetHomeOutputDirectory();
  161. m_OutputDir = cmSystemTools::CollapseFullPath(m_OutputDir.c_str());
  162. cmSystemTools::SplitPath(m_OutputDir.c_str(),
  163. m_ProjectOutputDirectoryComponents);
  164. m_CurrentLocalGenerator = root;
  165. // add ALL_BUILD, INSTALL, etc
  166. this->AddExtraTargets(root, it->second);
  167. // now create the project
  168. this->OutputXCodeProject(root, it->second);
  169. }
  170. }
  171. //----------------------------------------------------------------------------
  172. void
  173. cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
  174. std::vector<cmLocalGenerator*>& gens)
  175. {
  176. cmMakefile* mf = root->GetMakefile();
  177. // Add ALL_BUILD
  178. const char* no_output = 0;
  179. std::vector<std::string> no_depends;
  180. mf->AddUtilityCommand("ALL_BUILD", false, no_output, no_depends,
  181. "echo", "Build all projects");
  182. cmTarget* allbuild = mf->FindTarget("ALL_BUILD");
  183. // ADD install
  184. std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
  185. mf->AddUtilityCommand("install", false, no_output, no_depends,
  186. cmake_command.c_str(),
  187. "-P", "cmake_install.cmake");
  188. // Add RUN_TESTS target if testing has been enabled
  189. std::string fname;
  190. fname = mf->GetStartOutputDirectory();
  191. fname += "/";
  192. fname += "DartTestfile.txt";
  193. if (cmSystemTools::FileExists(fname.c_str()))
  194. {
  195. std::string ctest_command =
  196. mf->GetRequiredDefinition("CMAKE_CTEST_COMMAND");
  197. mf->AddUtilityCommand("RUN_TESTS", false, no_output, no_depends,
  198. ctest_command.c_str());
  199. }
  200. // Add XCODE depend helper
  201. std::string dir = mf->GetCurrentOutputDirectory();
  202. m_CurrentXCodeHackMakefile = dir;
  203. m_CurrentXCodeHackMakefile += "/CMakeScripts";
  204. cmSystemTools::MakeDirectory(m_CurrentXCodeHackMakefile.c_str());
  205. m_CurrentXCodeHackMakefile += "/XCODE_DEPEND_HELPER.make";
  206. cmCustomCommandLine makecommand;
  207. makecommand.push_back("make");
  208. makecommand.push_back("-C");
  209. makecommand.push_back(dir.c_str());
  210. makecommand.push_back("-f");
  211. makecommand.push_back(m_CurrentXCodeHackMakefile.c_str());
  212. cmCustomCommandLines commandLines;
  213. commandLines.push_back(makecommand);
  214. mf->AddUtilityCommand("XCODE_DEPEND_HELPER", false, no_output, no_depends,
  215. commandLines);
  216. // Add Re-Run CMake rules
  217. this->CreateReRunCMakeFile(root);
  218. // now make the allbuild depend on all the non-utility targets
  219. // in the project
  220. for(std::vector<cmLocalGenerator*>::iterator i = gens.begin();
  221. i != gens.end(); ++i)
  222. {
  223. cmLocalGenerator* lg = *i;
  224. if(this->IsExcluded(root, *i))
  225. {
  226. continue;
  227. }
  228. cmTargets& tgts = lg->GetMakefile()->GetTargets();
  229. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  230. {
  231. cmTarget& target = l->second;
  232. // make all exe, shared libs and modules depend
  233. // on the XCODE_DEPEND_HELPER target
  234. if((target.GetType() == cmTarget::EXECUTABLE ||
  235. target.GetType() == cmTarget::SHARED_LIBRARY ||
  236. target.GetType() == cmTarget::MODULE_LIBRARY))
  237. {
  238. target.AddUtility("XCODE_DEPEND_HELPER");
  239. }
  240. if(target.IsInAll())
  241. {
  242. allbuild->AddUtility(target.GetName());
  243. }
  244. }
  245. }
  246. }
  247. //----------------------------------------------------------------------------
  248. void cmGlobalXCodeGenerator::CreateReRunCMakeFile(cmLocalGenerator* root)
  249. {
  250. cmMakefile* mf = root->GetMakefile();
  251. std::vector<std::string> lfiles = mf->GetListFiles();
  252. // sort the array
  253. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
  254. std::vector<std::string>::iterator new_end =
  255. std::unique(lfiles.begin(), lfiles.end());
  256. lfiles.erase(new_end, lfiles.end());
  257. std::string dir = mf->GetHomeOutputDirectory();
  258. m_CurrentReRunCMakeMakefile = dir;
  259. m_CurrentReRunCMakeMakefile += "/CMakeScripts";
  260. cmSystemTools::MakeDirectory(m_CurrentReRunCMakeMakefile.c_str());
  261. m_CurrentReRunCMakeMakefile += "/ReRunCMake.make";
  262. cmGeneratedFileStream makefileStream(m_CurrentReRunCMakeMakefile.c_str());
  263. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  264. makefileStream << "cmake.check_cache: ";
  265. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  266. i != lfiles.end(); ++i)
  267. {
  268. makefileStream << "\\\n" << this->ConvertToRelativeForMake(i->c_str());
  269. }
  270. std::string cmake = mf->GetRequiredDefinition("CMAKE_COMMAND");
  271. makefileStream << "\n\t" << this->ConvertToRelativeForMake(cmake.c_str())
  272. << " -H" << this->ConvertToRelativeForMake(
  273. mf->GetHomeDirectory())
  274. << " -B" << this->ConvertToRelativeForMake(
  275. mf->GetHomeOutputDirectory()) << "\n";
  276. }
  277. //----------------------------------------------------------------------------
  278. void cmGlobalXCodeGenerator::ClearXCodeObjects()
  279. {
  280. m_TargetDoneSet.clear();
  281. for(unsigned int i = 0; i < m_XCodeObjects.size(); ++i)
  282. {
  283. delete m_XCodeObjects[i];
  284. }
  285. m_XCodeObjects.clear();
  286. m_GroupMap.clear();
  287. m_GroupNameMap.clear();
  288. m_TargetGroup.clear();
  289. }
  290. //----------------------------------------------------------------------------
  291. cmXCodeObject*
  292. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
  293. {
  294. cmXCodeObject* obj = new cmXCodeObject(ptype, cmXCodeObject::OBJECT);
  295. m_XCodeObjects.push_back(obj);
  296. return obj;
  297. }
  298. //----------------------------------------------------------------------------
  299. cmXCodeObject*
  300. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
  301. {
  302. cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, type);
  303. m_XCodeObjects.push_back(obj);
  304. return obj;
  305. }
  306. //----------------------------------------------------------------------------
  307. cmXCodeObject*
  308. cmGlobalXCodeGenerator::CreateString(const char* s)
  309. {
  310. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::STRING);
  311. obj->SetString(s);
  312. return obj;
  313. }
  314. //----------------------------------------------------------------------------
  315. cmXCodeObject* cmGlobalXCodeGenerator::CreateObjectReference(cmXCodeObject* ref)
  316. {
  317. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::OBJECT_REF);
  318. obj->SetObject(ref);
  319. return obj;
  320. }
  321. //----------------------------------------------------------------------------
  322. cmXCodeObject*
  323. cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
  324. cmSourceFile* sf)
  325. {
  326. std::string flags;
  327. // Add flags from source file properties.
  328. lg->AppendFlags(flags, sf->GetProperty("COMPILE_FLAGS"));
  329. cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  330. cmXCodeObject* group = m_GroupMap[sf];
  331. cmXCodeObject* children = group->GetObject("children");
  332. children->AddObject(fileRef);
  333. // m_SourcesGroupChildren->AddObject(fileRef);
  334. cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
  335. buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef));
  336. cmXCodeObject* settings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  337. settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags.c_str()));
  338. buildFile->AddAttribute("settings", settings);
  339. fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
  340. const char* lang =
  341. this->GetLanguageFromExtension(sf->GetSourceExtension().c_str());
  342. std::string sourcecode = "sourcecode";
  343. std::string ext = sf->GetSourceExtension();
  344. ext = cmSystemTools::LowerCase(ext);
  345. if(ext == "o")
  346. {
  347. sourcecode = "compiled.mach-o.objfile";
  348. }
  349. else if(ext == "mm")
  350. {
  351. sourcecode += ".cpp.objcpp";
  352. }
  353. else if(ext == "m")
  354. {
  355. sourcecode += ".cpp.objc";
  356. }
  357. else if(!lang)
  358. {
  359. sourcecode += ext;
  360. sourcecode += ".";
  361. sourcecode += ext;
  362. }
  363. else if(strcmp(lang, "C") == 0)
  364. {
  365. sourcecode += ".c.c";
  366. }
  367. else
  368. {
  369. sourcecode += ".cpp.cpp";
  370. }
  371. fileRef->AddAttribute("lastKnownFileType",
  372. this->CreateString(sourcecode.c_str()));
  373. std::string path =
  374. this->ConvertToRelativeForXCode(sf->GetFullPath().c_str());
  375. // std::string file =
  376. // cmSystemTools::RelativePath(m_CurrentMakefile->GetHomeDirectory(),
  377. // sf->GetFullPath().c_str());
  378. std::string dir;
  379. std::string file;
  380. cmSystemTools::SplitProgramPath(sf->GetFullPath().c_str(),
  381. dir, file);
  382. fileRef->AddAttribute("name", this->CreateString(file.c_str()));
  383. fileRef->AddAttribute("path", this->CreateString(path.c_str()));
  384. fileRef->AddAttribute("refType", this->CreateString("4"));
  385. if(path.size() > 1 && path[0] == '.' && path[1] == '.')
  386. {
  387. fileRef->AddAttribute("sourceTree", this->CreateString("<group>"));
  388. }
  389. else
  390. {
  391. fileRef->AddAttribute("sourceTree", this->CreateString("<absolute>"));
  392. }
  393. return buildFile;
  394. }
  395. //----------------------------------------------------------------------------
  396. bool cmGlobalXCodeGenerator::SpecialTargetEmitted(std::string const& tname)
  397. {
  398. if(tname == "ALL_BUILD" || tname == "XCODE_DEPEND_HELPER" ||
  399. tname == "install" || tname == "RUN_TESTS" )
  400. {
  401. if(m_TargetDoneSet.find(tname) != m_TargetDoneSet.end())
  402. {
  403. return true;
  404. }
  405. m_TargetDoneSet.insert(tname);
  406. return false;
  407. }
  408. return false;
  409. }
  410. void cmGlobalXCodeGenerator::SetCurrentLocalGenerator(cmLocalGenerator* gen)
  411. {
  412. m_CurrentLocalGenerator = gen;
  413. m_CurrentMakefile = gen->GetMakefile();
  414. std::string outdir =
  415. cmSystemTools::CollapseFullPath(m_CurrentMakefile->
  416. GetCurrentOutputDirectory());
  417. cmSystemTools::SplitPath(outdir.c_str(), m_CurrentOutputDirectoryComponents);
  418. }
  419. //----------------------------------------------------------------------------
  420. void
  421. cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
  422. std::vector<cmXCodeObject*>&
  423. targets)
  424. {
  425. this->SetCurrentLocalGenerator(gen);
  426. cmTargets &tgts = gen->GetMakefile()->GetTargets();
  427. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  428. {
  429. cmTarget& cmtarget = l->second;
  430. // make sure ALL_BUILD, INSTALL, etc are only done once
  431. if(this->SpecialTargetEmitted(l->first.c_str()))
  432. {
  433. continue;
  434. }
  435. if(cmtarget.GetType() == cmTarget::UTILITY ||
  436. cmtarget.GetType() == cmTarget::INSTALL_FILES ||
  437. cmtarget.GetType() == cmTarget::INSTALL_PROGRAMS)
  438. {
  439. if(cmtarget.GetType() == cmTarget::UTILITY)
  440. {
  441. targets.push_back(this->CreateUtilityTarget(cmtarget));
  442. }
  443. continue;
  444. }
  445. // create source build phase
  446. cmXCodeObject* sourceBuildPhase =
  447. this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
  448. sourceBuildPhase->AddAttribute("buildActionMask",
  449. this->CreateString("2147483647"));
  450. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  451. sourceBuildPhase->AddAttribute("files", buildFiles);
  452. sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  453. this->CreateString("0"));
  454. std::vector<cmSourceFile*> &classes = l->second.GetSourceFiles();
  455. // add all the sources
  456. std::vector<cmXCodeObject*> externalObjFiles;
  457. std::vector<cmXCodeObject*> headerFiles;
  458. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  459. i != classes.end(); ++i)
  460. {
  461. cmXCodeObject* xsf = this->CreateXCodeSourceFile(gen, *i);
  462. cmXCodeObject* fr = xsf->GetObject("fileRef");
  463. cmXCodeObject* filetype =
  464. fr->GetObject()->GetObject("lastKnownFileType");
  465. if(strcmp(filetype->GetString(), "\"compiled.mach-o.objfile\"") == 0)
  466. {
  467. externalObjFiles.push_back(xsf);
  468. }
  469. else if((*i)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  470. {
  471. headerFiles.push_back(xsf);
  472. }
  473. else
  474. {
  475. buildFiles->AddObject(xsf);
  476. }
  477. }
  478. // create header build phase
  479. cmXCodeObject* headerBuildPhase =
  480. this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase);
  481. headerBuildPhase->AddAttribute("buildActionMask",
  482. this->CreateString("2147483647"));
  483. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  484. for(std::vector<cmXCodeObject*>::iterator i = headerFiles.begin();
  485. i != headerFiles.end(); ++i)
  486. {
  487. buildFiles->AddObject(*i);
  488. }
  489. headerBuildPhase->AddAttribute("files", buildFiles);
  490. headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  491. this->CreateString("0"));
  492. // create framework build phase
  493. cmXCodeObject* frameworkBuildPhase =
  494. this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
  495. frameworkBuildPhase->AddAttribute("buildActionMask",
  496. this->CreateString("2147483647"));
  497. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  498. frameworkBuildPhase->AddAttribute("files", buildFiles);
  499. for(std::vector<cmXCodeObject*>::iterator i = externalObjFiles.begin();
  500. i != externalObjFiles.end(); ++i)
  501. {
  502. buildFiles->AddObject(*i);
  503. }
  504. frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  505. this->CreateString("0"));
  506. cmXCodeObject* buildPhases =
  507. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  508. this->CreateCustomCommands(buildPhases, sourceBuildPhase,
  509. headerBuildPhase, frameworkBuildPhase,
  510. cmtarget);
  511. targets.push_back(this->CreateXCodeTarget(l->second, buildPhases));
  512. }
  513. }
  514. //----------------------------------------------------------------------------
  515. cmXCodeObject*
  516. cmGlobalXCodeGenerator::CreateBuildPhase(const char* name,
  517. const char* name2,
  518. cmTarget& cmtarget,
  519. const std::vector<cmCustomCommand>&
  520. commands)
  521. {
  522. if(commands.size() == 0 && strcmp(name, "CMake ReRun") != 0)
  523. {
  524. return 0;
  525. }
  526. cmXCodeObject* buildPhase =
  527. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  528. buildPhase->AddAttribute("buildActionMask",
  529. this->CreateString("2147483647"));
  530. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  531. buildPhase->AddAttribute("files", buildFiles);
  532. buildPhase->AddAttribute("name",
  533. this->CreateString(name));
  534. buildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  535. this->CreateString("0"));
  536. buildPhase->AddAttribute("shellPath",
  537. this->CreateString("/bin/sh"));
  538. this->AddCommandsToBuildPhase(buildPhase, cmtarget, commands,
  539. name2);
  540. return buildPhase;
  541. }
  542. //----------------------------------------------------------------------------
  543. void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
  544. cmXCodeObject*
  545. sourceBuildPhase,
  546. cmXCodeObject*
  547. headerBuildPhase,
  548. cmXCodeObject*
  549. frameworkBuildPhase,
  550. cmTarget& cmtarget)
  551. {
  552. std::vector<cmCustomCommand> const & prebuild
  553. = cmtarget.GetPreBuildCommands();
  554. std::vector<cmCustomCommand> const & prelink
  555. = cmtarget.GetPreLinkCommands();
  556. std::vector<cmCustomCommand> const & postbuild
  557. = cmtarget.GetPostBuildCommands();
  558. cmtarget.TraceVSDependencies(cmtarget.GetName(), m_CurrentMakefile);
  559. std::vector<cmSourceFile*> &classes = cmtarget.GetSourceFiles();
  560. // add all the sources
  561. std::vector<cmCustomCommand> commands;
  562. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  563. i != classes.end(); ++i)
  564. {
  565. if((*i)->GetCustomCommand())
  566. {
  567. commands.push_back(*(*i)->GetCustomCommand());
  568. }
  569. }
  570. std::vector<cmCustomCommand> reruncom;
  571. cmXCodeObject* cmakeReRunPhase = this->CreateBuildPhase("CMake ReRun",
  572. "cmakeReRunPhase",
  573. cmtarget, reruncom);
  574. buildPhases->AddObject(cmakeReRunPhase);
  575. // create prebuild phase
  576. cmXCodeObject* cmakeRulesBuildPhase =
  577. this->CreateBuildPhase("CMake Rules",
  578. "cmakeRulesBuildPhase",
  579. cmtarget, commands);
  580. // create prebuild phase
  581. cmXCodeObject* preBuildPhase = this->CreateBuildPhase("CMake PreBuild Rules",
  582. "preBuildCommands",
  583. cmtarget, prebuild);
  584. // create prebuild phase
  585. cmXCodeObject* preLinkPhase = this->CreateBuildPhase("CMake PreLink Rules",
  586. "preLinkCommands",
  587. cmtarget, prelink);
  588. // create prebuild phase
  589. cmXCodeObject* postBuildPhase =
  590. this->CreateBuildPhase("CMake PostBuild Rules",
  591. "postBuildPhase",
  592. cmtarget, postbuild);
  593. // the order here is the order they will be built in
  594. if(preBuildPhase)
  595. {
  596. buildPhases->AddObject(preBuildPhase);
  597. }
  598. if(cmakeRulesBuildPhase)
  599. {
  600. buildPhases->AddObject(cmakeRulesBuildPhase);
  601. }
  602. if(sourceBuildPhase)
  603. {
  604. buildPhases->AddObject(sourceBuildPhase);
  605. }
  606. if(headerBuildPhase)
  607. {
  608. buildPhases->AddObject(headerBuildPhase);
  609. }
  610. if(preLinkPhase)
  611. {
  612. buildPhases->AddObject(preLinkPhase);
  613. }
  614. if(frameworkBuildPhase)
  615. {
  616. buildPhases->AddObject(frameworkBuildPhase);
  617. }
  618. if(postBuildPhase)
  619. {
  620. buildPhases->AddObject(postBuildPhase);
  621. }
  622. }
  623. //----------------------------------------------------------------------------
  624. void
  625. cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  626. cmTarget& target,
  627. std::vector<cmCustomCommand>
  628. const & commands,
  629. const char* name)
  630. {
  631. if(strcmp(name, "cmakeReRunPhase") == 0)
  632. {
  633. std::string cdir = m_CurrentMakefile->GetHomeOutputDirectory();
  634. cdir = this->ConvertToRelativeForMake(cdir.c_str());
  635. std::string makecmd = "make -C ";
  636. makecmd += cdir;
  637. makecmd += " -f ";
  638. makecmd +=
  639. this->ConvertToRelativeForMake(m_CurrentReRunCMakeMakefile.c_str());
  640. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  641. buildphase->AddAttribute("shellScript",
  642. this->CreateString(makecmd.c_str()));
  643. return;
  644. }
  645. std::string dir = m_CurrentMakefile->GetCurrentOutputDirectory();
  646. dir += "/CMakeScripts";
  647. cmSystemTools::MakeDirectory(dir.c_str());
  648. std::string makefile = dir;
  649. makefile += "/";
  650. makefile += target.GetName();
  651. makefile += "_";
  652. makefile += name;
  653. makefile += ".make";
  654. cmGeneratedFileStream makefileStream(makefile.c_str());
  655. if(!makefileStream)
  656. {
  657. return;
  658. }
  659. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  660. makefileStream << "# Custom rules for " << target.GetName() << "\n";
  661. // have all depend on all outputs
  662. makefileStream << "all: ";
  663. std::map<const cmCustomCommand*, cmStdString> tname;
  664. int count = 0;
  665. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  666. i != commands.end(); ++i)
  667. {
  668. cmCustomCommand const& cc = *i;
  669. if(!cc.GetCommandLines().empty())
  670. {
  671. if(cc.GetOutput()[0])
  672. {
  673. makefileStream << "\\\n\t" << this->
  674. ConvertToRelativeForMake(cc.GetOutput());
  675. }
  676. else
  677. {
  678. char c = '1' + count++;
  679. tname[&cc] = std::string(target.GetName()) + c;
  680. makefileStream << "\\\n\t" << tname[&cc];
  681. }
  682. }
  683. }
  684. makefileStream << "\n\n";
  685. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  686. i != commands.end(); ++i)
  687. {
  688. cmCustomCommand const& cc = *i;
  689. if(!cc.GetCommandLines().empty())
  690. {
  691. makefileStream << "\n#" << "Custom command rule: " <<
  692. cc.GetComment() << "\n";
  693. if(cc.GetOutput()[0])
  694. {
  695. makefileStream << this
  696. ->ConvertToRelativeForMake(cc.GetOutput()) << ": ";
  697. }
  698. else
  699. {
  700. makefileStream << tname[&cc] << ": ";
  701. }
  702. for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
  703. d != cc.GetDepends().end(); ++d)
  704. {
  705. if(!this->FindTarget(m_CurrentProject.c_str(),
  706. d->c_str()))
  707. {
  708. makefileStream << "\\\n" << this
  709. ->ConvertToRelativeForMake(d->c_str());
  710. }
  711. else
  712. {
  713. // if the depend is a target then make
  714. // the target with the source that is a custom command
  715. // depend on the that target via a AddUtility call
  716. std::cerr << "AddUtility " << target.GetName() << " " << *d << "\n";
  717. target.AddUtility(d->c_str());
  718. }
  719. }
  720. makefileStream << "\n";
  721. // Add each command line to the set of commands.
  722. for(cmCustomCommandLines::const_iterator cl =
  723. cc.GetCommandLines().begin();
  724. cl != cc.GetCommandLines().end(); ++cl)
  725. {
  726. // Build the command line in a single string.
  727. const cmCustomCommandLine& commandLine = *cl;
  728. std::string cmd = commandLine[0];
  729. cmSystemTools::ReplaceString(cmd, "/./", "/");
  730. cmd = this->ConvertToRelativeForMake(cmd.c_str());
  731. for(unsigned int j=1; j < commandLine.size(); ++j)
  732. {
  733. cmd += " ";
  734. cmd += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
  735. }
  736. makefileStream << "\t" << cmd.c_str() << "\n";
  737. }
  738. }
  739. }
  740. std::string cdir = m_CurrentMakefile->GetCurrentOutputDirectory();
  741. cdir = this->ConvertToRelativeForXCode(cdir.c_str());
  742. std::string makecmd = "make -C ";
  743. makecmd += cdir;
  744. makecmd += " -f ";
  745. makecmd += this->ConvertToRelativeForMake(makefile.c_str());
  746. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  747. buildphase->AddAttribute("shellScript", this->CreateString(makecmd.c_str()));
  748. }
  749. //----------------------------------------------------------------------------
  750. void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
  751. cmXCodeObject* buildSettings,
  752. std::string& fileType,
  753. std::string& productType,
  754. std::string& productName)
  755. {
  756. this->ConfigureOutputPaths();
  757. std::string flags;
  758. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  759. (target.GetType() == cmTarget::MODULE_LIBRARY));
  760. if(shared)
  761. {
  762. flags += "-D";
  763. if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  764. {
  765. flags += custom_export_name;
  766. }
  767. else
  768. {
  769. std::string in = target.GetName();
  770. in += "_EXPORTS";
  771. flags += cmSystemTools::MakeCindentifier(in.c_str());
  772. }
  773. }
  774. const char* lang = target.GetLinkerLanguage(this);
  775. if(lang)
  776. {
  777. // Add language-specific flags.
  778. m_CurrentLocalGenerator->AddLanguageFlags(flags, lang);
  779. // Add shared-library flags if needed.
  780. m_CurrentLocalGenerator->AddSharedFlags(flags, lang, shared);
  781. }
  782. // Add define flags
  783. m_CurrentLocalGenerator->AppendFlags(flags,
  784. m_CurrentMakefile->GetDefineFlags());
  785. cmSystemTools::ReplaceString(flags, "\"", "\\\"");
  786. productName = target.GetName();
  787. switch(target.GetType())
  788. {
  789. case cmTarget::STATIC_LIBRARY:
  790. {
  791. if(m_LibraryOutputPath.size())
  792. {
  793. buildSettings->AddAttribute("SYMROOT",
  794. this->CreateString
  795. (m_LibraryOutputPath.c_str()));
  796. }
  797. productName += ".a";
  798. std::string t = "lib";
  799. t += productName;
  800. productName = t;
  801. productType = "com.apple.product-type.library.static";
  802. fileType = "archive.ar";
  803. buildSettings->AddAttribute("LIBRARY_STYLE",
  804. this->CreateString("STATIC"));
  805. break;
  806. }
  807. case cmTarget::MODULE_LIBRARY:
  808. {
  809. if(m_LibraryOutputPath.size())
  810. {
  811. buildSettings->AddAttribute("SYMROOT",
  812. this->CreateString
  813. (m_LibraryOutputPath.c_str()));
  814. }
  815. buildSettings->AddAttribute("EXECUTABLE_PREFIX",
  816. this->CreateString("lib"));
  817. buildSettings->AddAttribute("EXECUTABLE_EXTENSION",
  818. this->CreateString("so"));
  819. buildSettings->AddAttribute("LIBRARY_STYLE",
  820. this->CreateString("BUNDLE"));
  821. productName += ".so";
  822. std::string t = "lib";
  823. t += productName;
  824. productName = t;
  825. buildSettings->AddAttribute("OTHER_LDFLAGS",
  826. this->CreateString("-bundle"));
  827. productType = "com.apple.product-type.library.dynamic";
  828. fileType = "compiled.mach-o.dylib";
  829. break;
  830. }
  831. case cmTarget::SHARED_LIBRARY:
  832. {
  833. if(m_LibraryOutputPath.size())
  834. {
  835. buildSettings->AddAttribute("SYMROOT",
  836. this->CreateString
  837. (m_LibraryOutputPath.c_str()));
  838. }
  839. buildSettings->AddAttribute("LIBRARY_STYLE",
  840. this->CreateString("DYNAMIC"));
  841. productName += ".dylib";
  842. std::string t = "lib";
  843. t += productName;
  844. productName = t;
  845. buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
  846. this->CreateString("1"));
  847. buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
  848. this->CreateString("1"));
  849. buildSettings->AddAttribute("OTHER_LDFLAGS",
  850. this->CreateString("-dynamiclib"));
  851. productType = "com.apple.product-type.library.dynamic";
  852. fileType = "compiled.mach-o.dylib";
  853. break;
  854. }
  855. case cmTarget::EXECUTABLE:
  856. if(m_ExecutableOutputPath.size())
  857. {
  858. buildSettings->AddAttribute("SYMROOT",
  859. this->CreateString
  860. (m_ExecutableOutputPath.c_str()));
  861. }
  862. fileType = "compiled.mach-o.executable";
  863. productType = "com.apple.product-type.tool";
  864. break;
  865. case cmTarget::UTILITY:
  866. break;
  867. case cmTarget::INSTALL_FILES:
  868. break;
  869. case cmTarget::INSTALL_PROGRAMS:
  870. break;
  871. }
  872. std::string dirs;
  873. std::vector<std::string>& includes =
  874. m_CurrentMakefile->GetIncludeDirectories();
  875. std::vector<std::string>::iterator i = includes.begin();
  876. for(;i != includes.end(); ++i)
  877. {
  878. std::string incpath =
  879. this->XCodeEscapePath(i->c_str());
  880. dirs += incpath + " ";
  881. }
  882. if(dirs.size())
  883. {
  884. buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
  885. this->CreateString(dirs.c_str()));
  886. }
  887. buildSettings->AddAttribute("GCC_OPTIMIZATION_LEVEL",
  888. this->CreateString("0"));
  889. buildSettings->AddAttribute("INSTALL_PATH",
  890. this->CreateString(""));
  891. buildSettings->AddAttribute("OPTIMIZATION_CFLAGS",
  892. this->CreateString(""));
  893. buildSettings->AddAttribute("OTHER_CFLAGS",
  894. this->CreateString(flags.c_str()));
  895. buildSettings->AddAttribute("OTHER_LDFLAGS",
  896. this->CreateString(""));
  897. buildSettings->AddAttribute("OTHER_REZFLAGS",
  898. this->CreateString(""));
  899. buildSettings->AddAttribute("SECTORDER_FLAGS",
  900. this->CreateString(""));
  901. buildSettings->AddAttribute("USE_HEADERMAP",
  902. this->CreateString("NO"));
  903. buildSettings->AddAttribute("WARNING_CFLAGS",
  904. this->CreateString(
  905. "-Wmost -Wno-four-char-constants"
  906. " -Wno-unknown-pragmas"));
  907. std::string pname;
  908. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  909. {
  910. pname = "lib";
  911. }
  912. pname += target.GetName();
  913. buildSettings->AddAttribute("PRODUCT_NAME",
  914. this->CreateString(pname.c_str()));
  915. }
  916. //----------------------------------------------------------------------------
  917. cmXCodeObject*
  918. cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
  919. {
  920. cmXCodeObject* shellBuildPhase =
  921. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  922. shellBuildPhase->AddAttribute("buildActionMask",
  923. this->CreateString("2147483647"));
  924. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  925. shellBuildPhase->AddAttribute("files", buildFiles);
  926. cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  927. shellBuildPhase->AddAttribute("inputPaths", inputPaths);
  928. cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  929. shellBuildPhase->AddAttribute("outputPaths", outputPaths);
  930. shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  931. this->CreateString("0"));
  932. shellBuildPhase->AddAttribute("shellPath",
  933. this->CreateString("/bin/sh"));
  934. shellBuildPhase->AddAttribute("shellScript",
  935. this->CreateString(
  936. "# shell script goes here\nexit 0"));
  937. cmXCodeObject* target =
  938. this->CreateObject(cmXCodeObject::PBXAggregateTarget);
  939. cmXCodeObject* buildPhases =
  940. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  941. this->CreateCustomCommands(buildPhases, 0, 0, 0, cmtarget);
  942. target->AddAttribute("buildPhases", buildPhases);
  943. cmXCodeObject* buildSettings =
  944. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  945. std::string fileTypeString;
  946. std::string productTypeString;
  947. std::string productName;
  948. this->CreateBuildSettings(cmtarget,
  949. buildSettings, fileTypeString,
  950. productTypeString, productName);
  951. target->AddAttribute("buildSettings", buildSettings);
  952. cmXCodeObject* dependencies = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  953. target->AddAttribute("dependencies", dependencies);
  954. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  955. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  956. target->SetcmTarget(&cmtarget);
  957. return target;
  958. }
  959. //----------------------------------------------------------------------------
  960. cmXCodeObject*
  961. cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
  962. cmXCodeObject* buildPhases)
  963. {
  964. cmXCodeObject* target =
  965. this->CreateObject(cmXCodeObject::PBXNativeTarget);
  966. target->AddAttribute("buildPhases", buildPhases);
  967. cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  968. target->AddAttribute("buildRules", buildRules);
  969. cmXCodeObject* buildSettings =
  970. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  971. std::string fileTypeString;
  972. std::string productTypeString;
  973. std::string productName;
  974. this->CreateBuildSettings(cmtarget,
  975. buildSettings, fileTypeString,
  976. productTypeString, productName);
  977. target->AddAttribute("buildSettings", buildSettings);
  978. cmXCodeObject* dependencies = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  979. target->AddAttribute("dependencies", dependencies);
  980. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  981. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  982. cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  983. fileRef->AddAttribute("explicitFileType",
  984. this->CreateString(fileTypeString.c_str()));
  985. fileRef->AddAttribute("path", this->CreateString(productName.c_str()));
  986. fileRef->AddAttribute("refType", this->CreateString("0"));
  987. fileRef->AddAttribute("sourceTree",
  988. this->CreateString("BUILT_PRODUCTS_DIR"));
  989. target->AddAttribute("productReference",
  990. this->CreateObjectReference(fileRef));
  991. target->AddAttribute("productType",
  992. this->CreateString(productTypeString.c_str()));
  993. target->SetcmTarget(&cmtarget);
  994. return target;
  995. }
  996. //----------------------------------------------------------------------------
  997. cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
  998. {
  999. if(!t)
  1000. {
  1001. return 0;
  1002. }
  1003. for(std::vector<cmXCodeObject*>::iterator i = m_XCodeObjects.begin();
  1004. i != m_XCodeObjects.end(); ++i)
  1005. {
  1006. cmXCodeObject* o = *i;
  1007. if(o->GetcmTarget() == t)
  1008. {
  1009. return o;
  1010. }
  1011. }
  1012. return 0;
  1013. }
  1014. //----------------------------------------------------------------------------
  1015. void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
  1016. cmXCodeObject* dependTarget)
  1017. {
  1018. // make sure a target does not depend on itself
  1019. if(target == dependTarget)
  1020. {
  1021. return;
  1022. }
  1023. // now avoid circular references if dependTarget already
  1024. // depends on target then skip it. Circular references crashes
  1025. // xcode
  1026. cmXCodeObject* dependTargetDepends = dependTarget->GetObject("dependencies");
  1027. if(dependTargetDepends)
  1028. {
  1029. if(dependTargetDepends->HasObject(target->GetPBXTargetDependency()))
  1030. {
  1031. return;
  1032. }
  1033. }
  1034. cmXCodeObject* targetdep = dependTarget->GetPBXTargetDependency();
  1035. if(!targetdep)
  1036. {
  1037. cmXCodeObject* container =
  1038. this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
  1039. container->AddAttribute("containerPortal",
  1040. this->CreateObjectReference(m_RootObject));
  1041. container->AddAttribute("proxyType", this->CreateString("1"));
  1042. container->AddAttribute("remoteGlobalIDString",
  1043. this->CreateObjectReference(dependTarget));
  1044. container->AddAttribute("remoteInfo",
  1045. this->CreateString(
  1046. dependTarget->GetcmTarget()->GetName()));
  1047. targetdep =
  1048. this->CreateObject(cmXCodeObject::PBXTargetDependency);
  1049. targetdep->AddAttribute("target",
  1050. this->CreateObjectReference(dependTarget));
  1051. targetdep->AddAttribute("targetProxy",
  1052. this->CreateObjectReference(container));
  1053. dependTarget->SetPBXTargetDependency(targetdep);
  1054. }
  1055. cmXCodeObject* depends = target->GetObject("dependencies");
  1056. if(!depends)
  1057. {
  1058. cmSystemTools::
  1059. Error("target does not have dependencies attribute error..");
  1060. }
  1061. else
  1062. {
  1063. depends->AddUniqueObject(targetdep);
  1064. }
  1065. }
  1066. //----------------------------------------------------------------------------
  1067. void cmGlobalXCodeGenerator::AddLinkLibrary(cmXCodeObject* target,
  1068. const char* library,
  1069. cmTarget* dtarget)
  1070. {
  1071. if(dtarget)
  1072. {
  1073. target->AddDependLibrary(this->GetTargetFullPath(dtarget).c_str());
  1074. }
  1075. // if the library is not a full path then add it with a -l flag
  1076. // to the settings of the target
  1077. cmXCodeObject* settings = target->GetObject("buildSettings");
  1078. cmXCodeObject* ldflags = settings->GetObject("OTHER_LDFLAGS");
  1079. std::string link = ldflags->GetString();
  1080. cmSystemTools::ReplaceString(link, "\"", "");
  1081. cmsys::RegularExpression reg("^([ \t]*\\-[lWRB])|([ \t]*\\-framework)|(\\${)|([ \t]*\\-pthread)|([ \t]*`)");
  1082. // if the library is not already in the form required by the compiler
  1083. // add a -l infront of the name
  1084. link += " ";
  1085. if(!reg.find(library))
  1086. {
  1087. link += "-l";
  1088. }
  1089. link += library;
  1090. ldflags->SetString(link.c_str());
  1091. }
  1092. //----------------------------------------------------------------------------
  1093. std::string cmGlobalXCodeGenerator::GetTargetFullPath(cmTarget* target)
  1094. {
  1095. std::string libPath;
  1096. cmXCodeObject* xtarget = this->FindXCodeTarget(target);
  1097. cmXCodeObject* bset = xtarget->GetObject("buildSettings");
  1098. cmXCodeObject* spath = bset->GetObject("SYMROOT");
  1099. libPath = spath->GetString();
  1100. libPath = libPath.substr(1, libPath.size()-2);
  1101. if(target->GetType() == cmTarget::STATIC_LIBRARY)
  1102. {
  1103. libPath += "lib";
  1104. libPath += target->GetName();
  1105. libPath += ".a";
  1106. }
  1107. else if(target->GetType() == cmTarget::SHARED_LIBRARY)
  1108. {
  1109. libPath += "lib";
  1110. libPath += target->GetName();
  1111. libPath += ".dylib";
  1112. }
  1113. else
  1114. {
  1115. libPath += target->GetName();
  1116. }
  1117. return libPath;
  1118. }
  1119. //----------------------------------------------------------------------------
  1120. void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
  1121. {
  1122. cmTarget* cmtarget = target->GetcmTarget();
  1123. if(!cmtarget)
  1124. {
  1125. cmSystemTools::Error("Error no target on xobject\n");
  1126. return;
  1127. }
  1128. // compute the correct order for link libraries
  1129. cmOrderLinkDirectories orderLibs;
  1130. std::string ext =
  1131. m_CurrentMakefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1132. if(ext.size())
  1133. {
  1134. orderLibs.AddLinkExtension(ext.c_str());
  1135. }
  1136. ext =
  1137. m_CurrentMakefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1138. if(ext.size())
  1139. {
  1140. orderLibs.AddLinkExtension(ext.c_str());
  1141. }
  1142. ext =
  1143. m_CurrentMakefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_SUFFIX");
  1144. if(ext.size())
  1145. {
  1146. orderLibs.AddLinkExtension(ext.c_str());
  1147. }
  1148. const char* targetLibrary = cmtarget->GetName();
  1149. if(cmtarget->GetType() == cmTarget::EXECUTABLE)
  1150. {
  1151. targetLibrary = 0;
  1152. }
  1153. orderLibs.SetLinkInformation(*cmtarget, cmTarget::GENERAL, targetLibrary);
  1154. orderLibs.DetermineLibraryPathOrder();
  1155. std::vector<cmStdString> libdirs;
  1156. std::vector<cmStdString> linkItems;
  1157. orderLibs.GetLinkerInformation(libdirs, linkItems);
  1158. std::string linkDirs;
  1159. // add the library search paths
  1160. for(std::vector<cmStdString>::const_iterator libDir = libdirs.begin();
  1161. libDir != libdirs.end(); ++libDir)
  1162. {
  1163. if(libDir->size() && *libDir != "/usr/lib")
  1164. {
  1165. linkDirs += " ";
  1166. linkDirs += this->XCodeEscapePath(libDir->c_str());
  1167. }
  1168. }
  1169. cmXCodeObject* bset = target->GetObject("buildSettings");
  1170. if(bset)
  1171. {
  1172. bset->AddAttribute("LIBRARY_SEARCH_PATHS",
  1173. this->CreateString(linkDirs.c_str()));
  1174. }
  1175. // now add the link libraries
  1176. for(std::vector<cmStdString>::iterator lib = linkItems.begin();
  1177. lib != linkItems.end(); ++lib)
  1178. {
  1179. cmTarget* t = this->FindTarget(m_CurrentProject.c_str(),
  1180. lib->c_str());
  1181. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  1182. if(dptarget)
  1183. {
  1184. this->AddDependTarget(target, dptarget);
  1185. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  1186. {
  1187. this->AddLinkLibrary(target, t->GetName(), t);
  1188. }
  1189. }
  1190. else
  1191. {
  1192. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  1193. {
  1194. this->AddLinkLibrary(target, lib->c_str());
  1195. }
  1196. }
  1197. }
  1198. // write utility dependencies.
  1199. for(std::set<cmStdString>::const_iterator i
  1200. = cmtarget->GetUtilities().begin();
  1201. i != cmtarget->GetUtilities().end(); ++i)
  1202. {
  1203. cmTarget* t = this->FindTarget(m_CurrentProject.c_str(),
  1204. i->c_str());
  1205. // if the target is in this project then make target depend
  1206. // on it. It may not be in this project if this is a sub
  1207. // project from the top.
  1208. if(t)
  1209. {
  1210. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  1211. if(dptarget)
  1212. {
  1213. this->AddDependTarget(target, dptarget);
  1214. }
  1215. else
  1216. {
  1217. std::string m = "Error Utility: ";
  1218. m += i->c_str();
  1219. m += "\n";
  1220. m += "cmtarget ";
  1221. if(t)
  1222. {
  1223. m += t->GetName();
  1224. }
  1225. m += "\n";
  1226. m += "Is on the target ";
  1227. m += cmtarget->GetName();
  1228. m += "\n";
  1229. m += "But it has no xcode target created yet??\n";
  1230. m += "Current project is ";
  1231. m += m_CurrentProject.c_str();
  1232. cmSystemTools::Error(m.c_str());
  1233. }
  1234. }
  1235. }
  1236. std::vector<cmStdString> fullPathLibs;
  1237. orderLibs.GetFullPathLibraries(fullPathLibs);
  1238. for(std::vector<cmStdString>::iterator i = fullPathLibs.begin();
  1239. i != fullPathLibs.end(); ++i)
  1240. {
  1241. target->AddDependLibrary(i->c_str());
  1242. }
  1243. }
  1244. //----------------------------------------------------------------------------
  1245. void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
  1246. std::vector<cmLocalGenerator*>&
  1247. generators)
  1248. {
  1249. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  1250. i != generators.end(); ++i)
  1251. {
  1252. if(this->IsExcluded(root, *i))
  1253. {
  1254. continue;
  1255. }
  1256. cmMakefile* mf = (*i)->GetMakefile();
  1257. std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
  1258. cmTargets &tgts = mf->GetTargets();
  1259. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1260. {
  1261. cmTarget& cmtarget = l->second;
  1262. std::vector<cmSourceFile*> & classes = cmtarget.GetSourceFiles();
  1263. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  1264. s != classes.end(); s++)
  1265. {
  1266. cmSourceFile* sf = *s;
  1267. // Add the file to the list of sources.
  1268. std::string const& source = sf->GetFullPath();
  1269. cmSourceGroup& sourceGroup =
  1270. mf->FindSourceGroup(source.c_str(), sourceGroups);
  1271. cmXCodeObject* pbxgroup = this->CreateOrGetPBXGroup(cmtarget, &sourceGroup);
  1272. m_GroupMap[sf] = pbxgroup;
  1273. }
  1274. }
  1275. }
  1276. }
  1277. //----------------------------------------------------------------------------
  1278. cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup(cmTarget& cmtarget,
  1279. cmSourceGroup* sg)
  1280. {
  1281. cmStdString s = cmtarget.GetName();
  1282. s += "/";
  1283. s += sg->GetName();
  1284. std::map<cmStdString, cmXCodeObject* >::iterator i = m_GroupNameMap.find(s);
  1285. if(i != m_GroupNameMap.end())
  1286. {
  1287. return i->second;
  1288. }
  1289. i = m_TargetGroup.find(cmtarget.GetName());
  1290. cmXCodeObject* tgroup = 0;
  1291. if(i != m_TargetGroup.end())
  1292. {
  1293. tgroup = i->second;
  1294. }
  1295. else
  1296. {
  1297. tgroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1298. m_TargetGroup[cmtarget.GetName()] = tgroup;
  1299. cmXCodeObject* tgroupChildren =
  1300. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1301. tgroup->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  1302. tgroup->AddAttribute("children", tgroupChildren);
  1303. tgroup->AddAttribute("refType", this->CreateString("4"));
  1304. tgroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1305. m_SourcesGroupChildren->AddObject(tgroup);
  1306. }
  1307. cmXCodeObject* tgroupChildren = tgroup->GetObject("children");
  1308. cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
  1309. cmXCodeObject* groupChildren =
  1310. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1311. group->AddAttribute("name", this->CreateString(sg->GetName()));
  1312. group->AddAttribute("children", groupChildren);
  1313. group->AddAttribute("refType", this->CreateString("4"));
  1314. group->AddAttribute("sourceTree", this->CreateString("<group>"));
  1315. tgroupChildren->AddObject(group);
  1316. m_GroupNameMap[s] = group;
  1317. return group;
  1318. }
  1319. //----------------------------------------------------------------------------
  1320. void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
  1321. std::vector<cmLocalGenerator*>&
  1322. generators
  1323. )
  1324. {
  1325. this->ClearXCodeObjects();
  1326. m_RootObject = 0;
  1327. m_SourcesGroupChildren = 0;
  1328. m_MainGroupChildren = 0;
  1329. cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1330. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  1331. cmXCodeObject* developBuildStyle =
  1332. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  1333. developBuildStyle->AddAttribute("name", this->CreateString("Development"));
  1334. developBuildStyle->AddAttribute("buildSettings", group);
  1335. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1336. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("YES"));
  1337. cmXCodeObject* deployBuildStyle =
  1338. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  1339. deployBuildStyle->AddAttribute("name", this->CreateString("Deployment"));
  1340. deployBuildStyle->AddAttribute("buildSettings", group);
  1341. cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1342. listObjs->AddObject(developBuildStyle);
  1343. listObjs->AddObject(deployBuildStyle);
  1344. cmXCodeObject* mainGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1345. m_MainGroupChildren =
  1346. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1347. mainGroup->AddAttribute("children", m_MainGroupChildren);
  1348. mainGroup->AddAttribute("refType", this->CreateString("4"));
  1349. mainGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1350. cmXCodeObject* sourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1351. m_SourcesGroupChildren =
  1352. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1353. sourcesGroup->AddAttribute("name", this->CreateString("Sources"));
  1354. sourcesGroup->AddAttribute("children", m_SourcesGroupChildren);
  1355. sourcesGroup->AddAttribute("refType", this->CreateString("4"));
  1356. sourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1357. m_MainGroupChildren->AddObject(sourcesGroup);
  1358. // now create the cmake groups
  1359. this->CreateGroups(root, generators);
  1360. cmXCodeObject* productGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1361. productGroup->AddAttribute("name", this->CreateString("Products"));
  1362. productGroup->AddAttribute("refType", this->CreateString("4"));
  1363. productGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1364. cmXCodeObject* productGroupChildren =
  1365. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1366. productGroup->AddAttribute("children", productGroupChildren);
  1367. m_MainGroupChildren->AddObject(productGroup);
  1368. m_RootObject = this->CreateObject(cmXCodeObject::PBXProject);
  1369. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1370. m_RootObject->AddAttribute("mainGroup",
  1371. this->CreateObjectReference(mainGroup));
  1372. m_RootObject->AddAttribute("buildSettings", group);
  1373. m_RootObject->AddAttribute("buildSyles", listObjs);
  1374. m_RootObject->AddAttribute("hasScannedForEncodings",
  1375. this->CreateString("0"));
  1376. std::vector<cmXCodeObject*> targets;
  1377. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  1378. i != generators.end(); ++i)
  1379. {
  1380. if(!this->IsExcluded(root, *i))
  1381. {
  1382. this->CreateXCodeTargets(*i, targets);
  1383. }
  1384. }
  1385. // loop over all targets and add link and depend info
  1386. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1387. i != targets.end(); ++i)
  1388. {
  1389. cmXCodeObject* t = *i;
  1390. this->AddDependAndLinkInformation(t);
  1391. }
  1392. // now create xcode depend hack makefile
  1393. this->CreateXCodeDependHackTarget(targets);
  1394. // now add all targets to the root object
  1395. cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1396. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1397. i != targets.end(); ++i)
  1398. {
  1399. cmXCodeObject* t = *i;
  1400. allTargets->AddObject(t);
  1401. cmXCodeObject* productRef = t->GetObject("productReference");
  1402. if(productRef)
  1403. {
  1404. productGroupChildren->AddObject(productRef->GetObject());
  1405. }
  1406. }
  1407. m_RootObject->AddAttribute("targets", allTargets);
  1408. }
  1409. //----------------------------------------------------------------------------
  1410. void
  1411. cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
  1412. std::vector<cmXCodeObject*>& targets)
  1413. {
  1414. cmGeneratedFileStream makefileStream(m_CurrentXCodeHackMakefile.c_str());
  1415. if(!makefileStream)
  1416. {
  1417. cmSystemTools::Error("Could not create",
  1418. m_CurrentXCodeHackMakefile.c_str());
  1419. return;
  1420. }
  1421. // one more pass for external depend information not handled
  1422. // correctly by xcode
  1423. makefileStream << "# DO NOT EDIT\n";
  1424. makefileStream << "# This makefile makes sure all linkable targets are \n";
  1425. makefileStream
  1426. << "# up-to-date with anything they link to,avoiding a bug in XCode 1.5\n";
  1427. makefileStream << "all: ";
  1428. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1429. i != targets.end(); ++i)
  1430. {
  1431. cmXCodeObject* target = *i;
  1432. cmTarget* t =target->GetcmTarget();
  1433. if(t->GetType() == cmTarget::EXECUTABLE ||
  1434. t->GetType() == cmTarget::SHARED_LIBRARY ||
  1435. t->GetType() == cmTarget::MODULE_LIBRARY)
  1436. {
  1437. makefileStream << "\\\n\t"
  1438. << this->
  1439. ConvertToRelativeForMake(this->GetTargetFullPath(target->GetcmTarget()).c_str());
  1440. }
  1441. }
  1442. makefileStream << "\n\n";
  1443. makefileStream
  1444. << "# For each target create a dummy rule "
  1445. "so the target does not have to exist\n";
  1446. std::set<cmStdString> emitted;
  1447. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1448. i != targets.end(); ++i)
  1449. {
  1450. cmXCodeObject* target = *i;
  1451. std::vector<cmStdString> const& deplibs = target->GetDependLibraries();
  1452. for(std::vector<cmStdString>::const_iterator d = deplibs.begin();
  1453. d != deplibs.end(); ++d)
  1454. {
  1455. if(emitted.insert(*d).second)
  1456. {
  1457. makefileStream << this->ConvertToRelativeForMake(d->c_str()) << ":\n";
  1458. }
  1459. }
  1460. }
  1461. makefileStream << "\n\n";
  1462. makefileStream <<
  1463. "# Each linkable target depends on everything it links to.\n";
  1464. makefileStream
  1465. << "#And the target is removed if it is older than what it linkes to\n";
  1466. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1467. i != targets.end(); ++i)
  1468. {
  1469. cmXCodeObject* target = *i;
  1470. cmTarget* t =target->GetcmTarget();
  1471. if(t->GetType() == cmTarget::EXECUTABLE ||
  1472. t->GetType() == cmTarget::SHARED_LIBRARY ||
  1473. t->GetType() == cmTarget::MODULE_LIBRARY)
  1474. {
  1475. std::vector<cmStdString> const& deplibs = target->GetDependLibraries();
  1476. std::string tfull = this->GetTargetFullPath(target->GetcmTarget());
  1477. makefileStream << this->ConvertToRelativeForMake(tfull.c_str()) << ": ";
  1478. for(std::vector<cmStdString>::const_iterator d = deplibs.begin();
  1479. d != deplibs.end(); ++d)
  1480. {
  1481. makefileStream << "\\\n\t" << this->ConvertToRelativeForMake(d->c_str());
  1482. }
  1483. makefileStream << "\n";
  1484. makefileStream << "\t/bin/rm -f "
  1485. << this->ConvertToRelativeForMake(tfull.c_str()) << "\n";
  1486. makefileStream << "\n\n";
  1487. }
  1488. }
  1489. }
  1490. //----------------------------------------------------------------------------
  1491. void
  1492. cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
  1493. std::vector<cmLocalGenerator*>&
  1494. generators)
  1495. {
  1496. if(generators.size() == 0)
  1497. {
  1498. return;
  1499. }
  1500. this->CreateXCodeObjects(root,
  1501. generators);
  1502. std::string xcodeDir = root->GetMakefile()->GetStartOutputDirectory();
  1503. xcodeDir += "/";
  1504. xcodeDir += root->GetMakefile()->GetProjectName();
  1505. xcodeDir += ".xcode";
  1506. cmSystemTools::MakeDirectory(xcodeDir.c_str());
  1507. xcodeDir += "/project.pbxproj";
  1508. cmGeneratedFileStream fout(xcodeDir.c_str());
  1509. fout.SetCopyIfDifferent(true);
  1510. if(!fout)
  1511. {
  1512. return;
  1513. }
  1514. this->WriteXCodePBXProj(fout, root, generators);
  1515. this->ClearXCodeObjects();
  1516. }
  1517. //----------------------------------------------------------------------------
  1518. void
  1519. cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
  1520. cmLocalGenerator* ,
  1521. std::vector<cmLocalGenerator*>& )
  1522. {
  1523. fout << "// !$*UTF8*$!\n";
  1524. fout << "{\n";
  1525. cmXCodeObject::Indent(1, fout);
  1526. fout << "archiveVersion = 1;\n";
  1527. cmXCodeObject::Indent(1, fout);
  1528. fout << "classes = {\n";
  1529. cmXCodeObject::Indent(1, fout);
  1530. fout << "};\n";
  1531. cmXCodeObject::Indent(1, fout);
  1532. fout << "objectVersion = 39;\n";
  1533. cmXCodeObject::PrintList(m_XCodeObjects, fout);
  1534. cmXCodeObject::Indent(1, fout);
  1535. fout << "rootObject = " << m_RootObject->GetId() << ";\n";
  1536. fout << "}\n";
  1537. }
  1538. //----------------------------------------------------------------------------
  1539. void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry)
  1540. const
  1541. {
  1542. entry.name = this->GetName();
  1543. entry.brief = "Generate XCode project files.";
  1544. entry.full = "";
  1545. }
  1546. //----------------------------------------------------------------------------
  1547. std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(const char* p)
  1548. {
  1549. if ( !m_CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  1550. {
  1551. return cmSystemTools::ConvertToOutputPath(p);
  1552. }
  1553. else
  1554. {
  1555. std::string ret = this->ConvertToRelativePath(m_CurrentOutputDirectoryComponents, p);
  1556. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  1557. }
  1558. }
  1559. //----------------------------------------------------------------------------
  1560. std::string cmGlobalXCodeGenerator::ConvertToRelativeForXCode(const char* p)
  1561. {
  1562. if ( !m_CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  1563. {
  1564. return cmSystemTools::ConvertToOutputPath(p);
  1565. }
  1566. else
  1567. {
  1568. std::string ret = this->ConvertToRelativePath(m_ProjectOutputDirectoryComponents, p);
  1569. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  1570. }
  1571. }
  1572. std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p)
  1573. {
  1574. std::string ret = p;
  1575. if(ret.find(' ') != ret.npos)
  1576. {
  1577. std::string t = ret;
  1578. ret = "\\\"";
  1579. ret += t;
  1580. ret += "\\\"";
  1581. }
  1582. return ret;
  1583. }