cmGlobalXCodeGenerator.cxx 59 KB

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