cmGlobalXCodeGenerator.cxx 59 KB

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