cmGlobalXCodeGenerator.cxx 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  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("CMAKE_CFG_INTDIR",".");
  39. mf->AddDefinition("CMAKE_GENERATOR_CC", "gcc");
  40. mf->AddDefinition("CMAKE_GENERATOR_CXX", "g++");
  41. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  42. this->cmGlobalGenerator::EnableLanguage(lang, mf);
  43. }
  44. //----------------------------------------------------------------------------
  45. int cmGlobalXCodeGenerator::Build(
  46. const char *,
  47. const char *bindir,
  48. const char *projectName,
  49. const char *targetName,
  50. std::string *output,
  51. const char *makeCommandCSTR,
  52. const char *,
  53. bool clean)
  54. {
  55. // now build the test
  56. if(makeCommandCSTR == 0 || !strlen(makeCommandCSTR))
  57. {
  58. cmSystemTools::Error(
  59. "Generator cannot find the appropriate make command.");
  60. return 1;
  61. }
  62. std::string makeCommand =
  63. cmSystemTools::ConvertToOutputPath(makeCommandCSTR);
  64. std::string lowerCaseCommand = makeCommand;
  65. cmSystemTools::LowerCase(lowerCaseCommand);
  66. /**
  67. * Run an executable command and put the stdout in output.
  68. */
  69. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  70. cmSystemTools::ChangeDirectory(bindir);
  71. makeCommand += " -project ";
  72. makeCommand += projectName;
  73. makeCommand += ".xcode";
  74. if(clean)
  75. {
  76. makeCommand += " clean ";
  77. }
  78. makeCommand += " build -target ";
  79. if (targetName && strlen(targetName))
  80. {
  81. makeCommand += targetName;
  82. }
  83. else
  84. {
  85. makeCommand += "ALL_BUILD";
  86. }
  87. makeCommand += " -buildstyle Development ";
  88. int retVal;
  89. int timeout = cmGlobalGenerator::s_TryCompileTimeout;
  90. if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), output, &retVal,
  91. 0, false, timeout))
  92. {
  93. cmSystemTools::Error("Generator: execution of xcodebuild failed.");
  94. // return to the original directory
  95. cmSystemTools::ChangeDirectory(cwd.c_str());
  96. return 1;
  97. }
  98. cmSystemTools::ChangeDirectory(cwd.c_str());
  99. return retVal;
  100. }
  101. //----------------------------------------------------------------------------
  102. void cmGlobalXCodeGenerator::ConfigureOutputPaths()
  103. {
  104. // Format the library and executable output paths.
  105. m_LibraryOutputPath =
  106. m_CurrentMakefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  107. if(m_LibraryOutputPath.size() == 0)
  108. {
  109. m_LibraryOutputPath = m_CurrentMakefile->GetCurrentOutputDirectory();
  110. }
  111. // make sure there is a trailing slash
  112. if(m_LibraryOutputPath.size() &&
  113. m_LibraryOutputPath[m_LibraryOutputPath.size()-1] != '/')
  114. {
  115. m_LibraryOutputPath += "/";
  116. if(!cmSystemTools::MakeDirectory(m_LibraryOutputPath.c_str()))
  117. {
  118. cmSystemTools::Error("Error creating directory ",
  119. m_LibraryOutputPath.c_str());
  120. }
  121. }
  122. m_CurrentMakefile->AddLinkDirectory(m_LibraryOutputPath.c_str());
  123. m_ExecutableOutputPath =
  124. m_CurrentMakefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  125. if(m_ExecutableOutputPath.size() == 0)
  126. {
  127. m_ExecutableOutputPath = m_CurrentMakefile->GetCurrentOutputDirectory();
  128. }
  129. // make sure there is a trailing slash
  130. if(m_ExecutableOutputPath.size() &&
  131. m_ExecutableOutputPath[m_ExecutableOutputPath.size()-1] != '/')
  132. {
  133. m_ExecutableOutputPath += "/";
  134. if(!cmSystemTools::MakeDirectory(m_ExecutableOutputPath.c_str()))
  135. {
  136. cmSystemTools::Error("Error creating directory ",
  137. m_ExecutableOutputPath.c_str());
  138. }
  139. }
  140. }
  141. //----------------------------------------------------------------------------
  142. ///! Create a local generator appropriate to this Global Generator
  143. cmLocalGenerator *cmGlobalXCodeGenerator::CreateLocalGenerator()
  144. {
  145. cmLocalGenerator *lg = new cmLocalXCodeGenerator;
  146. lg->SetGlobalGenerator(this);
  147. return lg;
  148. }
  149. //----------------------------------------------------------------------------
  150. void cmGlobalXCodeGenerator::Generate()
  151. {
  152. this->cmGlobalGenerator::Generate();
  153. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  154. for(it = m_ProjectMap.begin(); it!= m_ProjectMap.end(); ++it)
  155. {
  156. cmLocalGenerator* root = it->second[0];
  157. m_CurrentProject = root->GetMakefile()->GetProjectName();
  158. this->SetCurrentLocalGenerator(root);
  159. m_OutputDir = m_CurrentMakefile->GetHomeOutputDirectory();
  160. m_OutputDir = cmSystemTools::CollapseFullPath(m_OutputDir.c_str());
  161. cmSystemTools::SplitPath(m_OutputDir.c_str(),
  162. m_ProjectOutputDirectoryComponents);
  163. m_CurrentLocalGenerator = root;
  164. // add ALL_BUILD, INSTALL, etc
  165. this->AddExtraTargets(root, it->second);
  166. // now create the project
  167. this->OutputXCodeProject(root, it->second);
  168. }
  169. }
  170. //----------------------------------------------------------------------------
  171. void
  172. cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
  173. std::vector<cmLocalGenerator*>& gens)
  174. {
  175. cmMakefile* mf = root->GetMakefile();
  176. // Add ALL_BUILD
  177. const char* no_output = 0;
  178. std::vector<std::string> no_depends;
  179. mf->AddUtilityCommand("ALL_BUILD", false, no_output, no_depends,
  180. "echo", "Build all projects");
  181. cmTarget* allbuild = mf->FindTarget("ALL_BUILD");
  182. // ADD install
  183. std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
  184. mf->AddUtilityCommand("install", false, no_output, no_depends,
  185. cmake_command.c_str(),
  186. "-P", "cmake_install.cmake");
  187. // Add RUN_TESTS target if testing has been enabled
  188. std::string fname;
  189. fname = mf->GetStartOutputDirectory();
  190. fname += "/";
  191. fname += "DartTestfile.txt";
  192. if (cmSystemTools::FileExists(fname.c_str()))
  193. {
  194. std::string ctest_command =
  195. mf->GetRequiredDefinition("CMAKE_CTEST_COMMAND");
  196. mf->AddUtilityCommand("RUN_TESTS", false, no_output, no_depends,
  197. ctest_command.c_str());
  198. }
  199. // Add XCODE depend helper
  200. std::string dir = mf->GetCurrentOutputDirectory();
  201. m_CurrentXCodeHackMakefile = dir;
  202. m_CurrentXCodeHackMakefile += "/CMakeScripts";
  203. cmSystemTools::MakeDirectory(m_CurrentXCodeHackMakefile.c_str());
  204. m_CurrentXCodeHackMakefile += "/XCODE_DEPEND_HELPER.make";
  205. cmCustomCommandLine makecommand;
  206. makecommand.push_back("make");
  207. makecommand.push_back("-C");
  208. makecommand.push_back(dir.c_str());
  209. makecommand.push_back("-f");
  210. makecommand.push_back(m_CurrentXCodeHackMakefile.c_str());
  211. cmCustomCommandLines commandLines;
  212. commandLines.push_back(makecommand);
  213. mf->AddUtilityCommand("XCODE_DEPEND_HELPER", false, no_output, no_depends,
  214. commandLines);
  215. // Add Re-Run CMake rules
  216. this->CreateReRunCMakeFile(root);
  217. // now make the allbuild depend on all the non-utility targets
  218. // in the project
  219. for(std::vector<cmLocalGenerator*>::iterator i = gens.begin();
  220. i != gens.end(); ++i)
  221. {
  222. cmLocalGenerator* lg = *i;
  223. if(this->IsExcluded(root, *i))
  224. {
  225. continue;
  226. }
  227. cmTargets& tgts = lg->GetMakefile()->GetTargets();
  228. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  229. {
  230. cmTarget& target = l->second;
  231. // make all exe, shared libs and modules depend
  232. // on the XCODE_DEPEND_HELPER target
  233. if((target.GetType() == cmTarget::EXECUTABLE ||
  234. target.GetType() == cmTarget::SHARED_LIBRARY ||
  235. target.GetType() == cmTarget::MODULE_LIBRARY))
  236. {
  237. target.AddUtility("XCODE_DEPEND_HELPER");
  238. }
  239. if(target.IsInAll())
  240. {
  241. allbuild->AddUtility(target.GetName());
  242. }
  243. }
  244. }
  245. }
  246. //----------------------------------------------------------------------------
  247. void cmGlobalXCodeGenerator::CreateReRunCMakeFile(cmLocalGenerator* root)
  248. {
  249. cmMakefile* mf = root->GetMakefile();
  250. std::vector<std::string> lfiles = mf->GetListFiles();
  251. // sort the array
  252. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
  253. std::vector<std::string>::iterator new_end =
  254. std::unique(lfiles.begin(), lfiles.end());
  255. lfiles.erase(new_end, lfiles.end());
  256. std::string dir = mf->GetHomeOutputDirectory();
  257. m_CurrentReRunCMakeMakefile = dir;
  258. m_CurrentReRunCMakeMakefile += "/CMakeScripts";
  259. cmSystemTools::MakeDirectory(m_CurrentReRunCMakeMakefile.c_str());
  260. m_CurrentReRunCMakeMakefile += "/ReRunCMake.make";
  261. cmGeneratedFileStream makefileStream(m_CurrentReRunCMakeMakefile.c_str());
  262. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  263. makefileStream << "cmake.check_cache: ";
  264. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  265. i != lfiles.end(); ++i)
  266. {
  267. makefileStream << "\\\n" << this->ConvertToRelativeForMake(i->c_str());
  268. }
  269. std::string cmake = mf->GetRequiredDefinition("CMAKE_COMMAND");
  270. makefileStream << "\n\t" << this->ConvertToRelativeForMake(cmake.c_str())
  271. << " -H" << this->ConvertToRelativeForMake(
  272. mf->GetHomeDirectory())
  273. << " -B" << this->ConvertToRelativeForMake(
  274. mf->GetHomeOutputDirectory()) << "\n";
  275. }
  276. //----------------------------------------------------------------------------
  277. void cmGlobalXCodeGenerator::ClearXCodeObjects()
  278. {
  279. m_TargetDoneSet.clear();
  280. for(unsigned int i = 0; i < m_XCodeObjects.size(); ++i)
  281. {
  282. delete m_XCodeObjects[i];
  283. }
  284. m_XCodeObjects.clear();
  285. m_GroupMap.clear();
  286. m_GroupNameMap.clear();
  287. m_TargetGroup.clear();
  288. }
  289. //----------------------------------------------------------------------------
  290. cmXCodeObject*
  291. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
  292. {
  293. cmXCodeObject* obj = new cmXCodeObject(ptype, cmXCodeObject::OBJECT);
  294. m_XCodeObjects.push_back(obj);
  295. return obj;
  296. }
  297. //----------------------------------------------------------------------------
  298. cmXCodeObject*
  299. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
  300. {
  301. cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, type);
  302. m_XCodeObjects.push_back(obj);
  303. return obj;
  304. }
  305. //----------------------------------------------------------------------------
  306. cmXCodeObject*
  307. cmGlobalXCodeGenerator::CreateString(const char* s)
  308. {
  309. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::STRING);
  310. obj->SetString(s);
  311. return obj;
  312. }
  313. //----------------------------------------------------------------------------
  314. cmXCodeObject* cmGlobalXCodeGenerator::CreateObjectReference(cmXCodeObject* ref)
  315. {
  316. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::OBJECT_REF);
  317. obj->SetObject(ref);
  318. return obj;
  319. }
  320. //----------------------------------------------------------------------------
  321. cmXCodeObject*
  322. cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
  323. cmSourceFile* sf)
  324. {
  325. std::string flags;
  326. // Add flags from source file properties.
  327. lg->AppendFlags(flags, sf->GetProperty("COMPILE_FLAGS"));
  328. cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  329. cmXCodeObject* group = m_GroupMap[sf];
  330. cmXCodeObject* children = group->GetObject("children");
  331. children->AddObject(fileRef);
  332. // m_SourcesGroupChildren->AddObject(fileRef);
  333. cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
  334. buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef));
  335. cmXCodeObject* settings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  336. settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags.c_str()));
  337. buildFile->AddAttribute("settings", settings);
  338. fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
  339. const char* lang =
  340. this->GetLanguageFromExtension(sf->GetSourceExtension().c_str());
  341. std::string sourcecode = "sourcecode";
  342. if(sf->GetSourceExtension() == "o")
  343. {
  344. sourcecode = "compiled.mach-o.objfile";
  345. }
  346. else if(sf->GetSourceExtension() == "mm")
  347. {
  348. sourcecode += ".cpp.objcpp";
  349. }
  350. else if(!lang)
  351. {
  352. std::string ext = ".";
  353. ext = sf->GetSourceExtension();
  354. sourcecode += ext;
  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. target.AddUtility(d->c_str());
  711. }
  712. }
  713. makefileStream << "\n";
  714. // Add each command line to the set of commands.
  715. for(cmCustomCommandLines::const_iterator cl =
  716. cc.GetCommandLines().begin();
  717. cl != cc.GetCommandLines().end(); ++cl)
  718. {
  719. // Build the command line in a single string.
  720. const cmCustomCommandLine& commandLine = *cl;
  721. std::string cmd = commandLine[0];
  722. cmSystemTools::ReplaceString(cmd, "/./", "/");
  723. cmd = this->ConvertToRelativeForMake(cmd.c_str());
  724. for(unsigned int j=1; j < commandLine.size(); ++j)
  725. {
  726. cmd += " ";
  727. cmd += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
  728. }
  729. makefileStream << "\t" << cmd.c_str() << "\n";
  730. }
  731. }
  732. }
  733. std::string cdir = m_CurrentMakefile->GetCurrentOutputDirectory();
  734. cdir = this->ConvertToRelativeForXCode(cdir.c_str());
  735. std::string makecmd = "make -C ";
  736. makecmd += cdir;
  737. makecmd += " -f ";
  738. makecmd += this->ConvertToRelativeForMake(makefile.c_str());
  739. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  740. buildphase->AddAttribute("shellScript", this->CreateString(makecmd.c_str()));
  741. }
  742. //----------------------------------------------------------------------------
  743. void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
  744. cmXCodeObject* buildSettings,
  745. std::string& fileType,
  746. std::string& productType,
  747. std::string& productName)
  748. {
  749. this->ConfigureOutputPaths();
  750. std::string flags;
  751. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  752. (target.GetType() == cmTarget::MODULE_LIBRARY));
  753. if(shared)
  754. {
  755. flags += "-D";
  756. if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  757. {
  758. flags += custom_export_name;
  759. }
  760. else
  761. {
  762. std::string in = target.GetName();
  763. in += "_EXPORTS";
  764. flags += cmSystemTools::MakeCindentifier(in.c_str());
  765. }
  766. }
  767. const char* lang = target.GetLinkerLanguage(this);
  768. if(lang)
  769. {
  770. // Add language-specific flags.
  771. m_CurrentLocalGenerator->AddLanguageFlags(flags, lang);
  772. // Add shared-library flags if needed.
  773. m_CurrentLocalGenerator->AddSharedFlags(flags, lang, shared);
  774. }
  775. // Add define flags
  776. m_CurrentLocalGenerator->AppendFlags(flags,
  777. m_CurrentMakefile->GetDefineFlags());
  778. cmSystemTools::ReplaceString(flags, "\"", "\\\"");
  779. productName = target.GetName();
  780. switch(target.GetType())
  781. {
  782. case cmTarget::STATIC_LIBRARY:
  783. {
  784. if(m_LibraryOutputPath.size())
  785. {
  786. buildSettings->AddAttribute("SYMROOT",
  787. this->CreateString
  788. (m_LibraryOutputPath.c_str()));
  789. }
  790. productName += ".a";
  791. std::string t = "lib";
  792. t += productName;
  793. productName = t;
  794. productType = "com.apple.product-type.library.static";
  795. fileType = "archive.ar";
  796. buildSettings->AddAttribute("LIBRARY_STYLE",
  797. this->CreateString("STATIC"));
  798. break;
  799. }
  800. case cmTarget::MODULE_LIBRARY:
  801. {
  802. if(m_LibraryOutputPath.size())
  803. {
  804. buildSettings->AddAttribute("SYMROOT",
  805. this->CreateString
  806. (m_LibraryOutputPath.c_str()));
  807. }
  808. buildSettings->AddAttribute("EXECUTABLE_PREFIX",
  809. this->CreateString("lib"));
  810. buildSettings->AddAttribute("EXECUTABLE_EXTENSION",
  811. this->CreateString("so"));
  812. buildSettings->AddAttribute("LIBRARY_STYLE",
  813. this->CreateString("BUNDLE"));
  814. productName += ".so";
  815. std::string t = "lib";
  816. t += productName;
  817. productName = t;
  818. buildSettings->AddAttribute("OTHER_LDFLAGS",
  819. this->CreateString("-bundle"));
  820. productType = "com.apple.product-type.library.dynamic";
  821. fileType = "compiled.mach-o.dylib";
  822. break;
  823. }
  824. case cmTarget::SHARED_LIBRARY:
  825. {
  826. if(m_LibraryOutputPath.size())
  827. {
  828. buildSettings->AddAttribute("SYMROOT",
  829. this->CreateString
  830. (m_LibraryOutputPath.c_str()));
  831. }
  832. buildSettings->AddAttribute("LIBRARY_STYLE",
  833. this->CreateString("DYNAMIC"));
  834. productName += ".dylib";
  835. std::string t = "lib";
  836. t += productName;
  837. productName = t;
  838. buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
  839. this->CreateString("1"));
  840. buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
  841. this->CreateString("1"));
  842. buildSettings->AddAttribute("OTHER_LDFLAGS",
  843. this->CreateString("-dynamiclib"));
  844. productType = "com.apple.product-type.library.dynamic";
  845. fileType = "compiled.mach-o.dylib";
  846. break;
  847. }
  848. case cmTarget::EXECUTABLE:
  849. if(m_ExecutableOutputPath.size())
  850. {
  851. buildSettings->AddAttribute("SYMROOT",
  852. this->CreateString
  853. (m_ExecutableOutputPath.c_str()));
  854. }
  855. fileType = "compiled.mach-o.executable";
  856. productType = "com.apple.product-type.tool";
  857. break;
  858. case cmTarget::UTILITY:
  859. break;
  860. case cmTarget::INSTALL_FILES:
  861. break;
  862. case cmTarget::INSTALL_PROGRAMS:
  863. break;
  864. }
  865. std::string dirs;
  866. std::vector<std::string>& includes =
  867. m_CurrentMakefile->GetIncludeDirectories();
  868. std::vector<std::string>::iterator i = includes.begin();
  869. for(;i != includes.end(); ++i)
  870. {
  871. std::string incpath =
  872. this->XCodeEscapePath(i->c_str());
  873. dirs += incpath + " ";
  874. }
  875. if(dirs.size())
  876. {
  877. buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
  878. this->CreateString(dirs.c_str()));
  879. }
  880. buildSettings->AddAttribute("GCC_OPTIMIZATION_LEVEL",
  881. this->CreateString("0"));
  882. buildSettings->AddAttribute("INSTALL_PATH",
  883. this->CreateString(""));
  884. buildSettings->AddAttribute("OPTIMIZATION_CFLAGS",
  885. this->CreateString(""));
  886. buildSettings->AddAttribute("OTHER_CFLAGS",
  887. this->CreateString(flags.c_str()));
  888. buildSettings->AddAttribute("OTHER_LDFLAGS",
  889. this->CreateString(""));
  890. buildSettings->AddAttribute("OTHER_REZFLAGS",
  891. this->CreateString(""));
  892. buildSettings->AddAttribute("SECTORDER_FLAGS",
  893. this->CreateString(""));
  894. buildSettings->AddAttribute("WARNING_CFLAGS",
  895. this->CreateString(
  896. "-Wmost -Wno-four-char-constants"
  897. " -Wno-unknown-pragmas"));
  898. std::string pname;
  899. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  900. {
  901. pname = "lib";
  902. }
  903. pname += target.GetName();
  904. buildSettings->AddAttribute("PRODUCT_NAME",
  905. this->CreateString(pname.c_str()));
  906. }
  907. //----------------------------------------------------------------------------
  908. cmXCodeObject*
  909. cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
  910. {
  911. cmXCodeObject* shellBuildPhase =
  912. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  913. shellBuildPhase->AddAttribute("buildActionMask",
  914. this->CreateString("2147483647"));
  915. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  916. shellBuildPhase->AddAttribute("files", buildFiles);
  917. cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  918. shellBuildPhase->AddAttribute("inputPaths", inputPaths);
  919. cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  920. shellBuildPhase->AddAttribute("outputPaths", outputPaths);
  921. shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  922. this->CreateString("0"));
  923. shellBuildPhase->AddAttribute("shellPath",
  924. this->CreateString("/bin/sh"));
  925. shellBuildPhase->AddAttribute("shellScript",
  926. this->CreateString(
  927. "# shell script goes here\nexit 0"));
  928. cmXCodeObject* target =
  929. this->CreateObject(cmXCodeObject::PBXAggregateTarget);
  930. cmXCodeObject* buildPhases =
  931. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  932. this->CreateCustomCommands(buildPhases, 0, 0, 0, cmtarget);
  933. target->AddAttribute("buildPhases", buildPhases);
  934. cmXCodeObject* buildSettings =
  935. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  936. std::string fileTypeString;
  937. std::string productTypeString;
  938. std::string productName;
  939. this->CreateBuildSettings(cmtarget,
  940. buildSettings, fileTypeString,
  941. productTypeString, productName);
  942. target->AddAttribute("buildSettings", buildSettings);
  943. cmXCodeObject* dependencies = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  944. target->AddAttribute("dependencies", dependencies);
  945. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  946. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  947. target->SetcmTarget(&cmtarget);
  948. return target;
  949. }
  950. //----------------------------------------------------------------------------
  951. cmXCodeObject*
  952. cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
  953. cmXCodeObject* buildPhases)
  954. {
  955. cmXCodeObject* target =
  956. this->CreateObject(cmXCodeObject::PBXNativeTarget);
  957. target->AddAttribute("buildPhases", buildPhases);
  958. cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  959. target->AddAttribute("buildRules", buildRules);
  960. cmXCodeObject* buildSettings =
  961. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  962. std::string fileTypeString;
  963. std::string productTypeString;
  964. std::string productName;
  965. this->CreateBuildSettings(cmtarget,
  966. buildSettings, fileTypeString,
  967. productTypeString, productName);
  968. target->AddAttribute("buildSettings", buildSettings);
  969. cmXCodeObject* dependencies = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  970. target->AddAttribute("dependencies", dependencies);
  971. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  972. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  973. cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  974. fileRef->AddAttribute("explicitFileType",
  975. this->CreateString(fileTypeString.c_str()));
  976. fileRef->AddAttribute("path", this->CreateString(productName.c_str()));
  977. fileRef->AddAttribute("refType", this->CreateString("0"));
  978. fileRef->AddAttribute("sourceTree",
  979. this->CreateString("BUILT_PRODUCTS_DIR"));
  980. target->AddAttribute("productReference",
  981. this->CreateObjectReference(fileRef));
  982. target->AddAttribute("productType",
  983. this->CreateString(productTypeString.c_str()));
  984. target->SetcmTarget(&cmtarget);
  985. return target;
  986. }
  987. //----------------------------------------------------------------------------
  988. cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
  989. {
  990. if(!t)
  991. {
  992. return 0;
  993. }
  994. for(std::vector<cmXCodeObject*>::iterator i = m_XCodeObjects.begin();
  995. i != m_XCodeObjects.end(); ++i)
  996. {
  997. cmXCodeObject* o = *i;
  998. if(o->GetcmTarget() == t)
  999. {
  1000. return o;
  1001. }
  1002. }
  1003. return 0;
  1004. }
  1005. //----------------------------------------------------------------------------
  1006. void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
  1007. cmXCodeObject* dependTarget)
  1008. {
  1009. // make sure a target does not depend on itself
  1010. if(target == dependTarget)
  1011. {
  1012. return;
  1013. }
  1014. // now avoid circular references if dependTarget already
  1015. // depends on target then skip it. Circular references crashes
  1016. // xcode
  1017. cmXCodeObject* dependTargetDepends = dependTarget->GetObject("dependencies");
  1018. if(dependTargetDepends)
  1019. {
  1020. if(dependTargetDepends->HasObject(target->GetPBXTargetDependency()))
  1021. {
  1022. return;
  1023. }
  1024. }
  1025. cmXCodeObject* targetdep = dependTarget->GetPBXTargetDependency();
  1026. if(!targetdep)
  1027. {
  1028. cmXCodeObject* container =
  1029. this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
  1030. container->AddAttribute("containerPortal",
  1031. this->CreateObjectReference(m_RootObject));
  1032. container->AddAttribute("proxyType", this->CreateString("1"));
  1033. container->AddAttribute("remoteGlobalIDString",
  1034. this->CreateObjectReference(dependTarget));
  1035. container->AddAttribute("remoteInfo",
  1036. this->CreateString(
  1037. dependTarget->GetcmTarget()->GetName()));
  1038. targetdep =
  1039. this->CreateObject(cmXCodeObject::PBXTargetDependency);
  1040. targetdep->AddAttribute("target",
  1041. this->CreateObjectReference(dependTarget));
  1042. targetdep->AddAttribute("targetProxy",
  1043. this->CreateObjectReference(container));
  1044. dependTarget->SetPBXTargetDependency(targetdep);
  1045. }
  1046. cmXCodeObject* depends = target->GetObject("dependencies");
  1047. if(!depends)
  1048. {
  1049. cmSystemTools::
  1050. Error("target does not have dependencies attribute error..");
  1051. }
  1052. else
  1053. {
  1054. depends->AddUniqueObject(targetdep);
  1055. }
  1056. }
  1057. //----------------------------------------------------------------------------
  1058. void cmGlobalXCodeGenerator::AddLinkLibrary(cmXCodeObject* target,
  1059. const char* library,
  1060. cmTarget* dtarget)
  1061. {
  1062. if(dtarget)
  1063. {
  1064. target->AddDependLibrary(this->GetTargetFullPath(dtarget).c_str());
  1065. }
  1066. // if the library is not a full path then add it with a -l flag
  1067. // to the settings of the target
  1068. cmXCodeObject* settings = target->GetObject("buildSettings");
  1069. cmXCodeObject* ldflags = settings->GetObject("OTHER_LDFLAGS");
  1070. std::string link = ldflags->GetString();
  1071. cmSystemTools::ReplaceString(link, "\"", "");
  1072. cmsys::RegularExpression reg("^([ \t]*\\-[lWRB])|([ \t]*\\-framework)|(\\${)|([ \t]*\\-pthread)|([ \t]*`)");
  1073. // if the library is not already in the form required by the compiler
  1074. // add a -l infront of the name
  1075. link += " ";
  1076. if(!reg.find(library))
  1077. {
  1078. link += "-l";
  1079. }
  1080. link += library;
  1081. ldflags->SetString(link.c_str());
  1082. }
  1083. //----------------------------------------------------------------------------
  1084. std::string cmGlobalXCodeGenerator::GetTargetFullPath(cmTarget* target)
  1085. {
  1086. std::string libPath;
  1087. cmXCodeObject* xtarget = this->FindXCodeTarget(target);
  1088. cmXCodeObject* bset = xtarget->GetObject("buildSettings");
  1089. cmXCodeObject* spath = bset->GetObject("SYMROOT");
  1090. libPath = spath->GetString();
  1091. libPath = libPath.substr(1, libPath.size()-2);
  1092. if(target->GetType() == cmTarget::STATIC_LIBRARY)
  1093. {
  1094. libPath += "lib";
  1095. libPath += target->GetName();
  1096. libPath += ".a";
  1097. }
  1098. else if(target->GetType() == cmTarget::SHARED_LIBRARY)
  1099. {
  1100. libPath += "lib";
  1101. libPath += target->GetName();
  1102. libPath += ".dylib";
  1103. }
  1104. else
  1105. {
  1106. libPath += target->GetName();
  1107. }
  1108. return libPath;
  1109. }
  1110. //----------------------------------------------------------------------------
  1111. void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
  1112. {
  1113. cmTarget* cmtarget = target->GetcmTarget();
  1114. if(!cmtarget)
  1115. {
  1116. cmSystemTools::Error("Error no target on xobject\n");
  1117. return;
  1118. }
  1119. // compute the correct order for link libraries
  1120. cmOrderLinkDirectories orderLibs;
  1121. std::string ext =
  1122. m_CurrentMakefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1123. if(ext.size())
  1124. {
  1125. orderLibs.AddLinkExtension(ext.c_str());
  1126. }
  1127. ext =
  1128. m_CurrentMakefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1129. if(ext.size())
  1130. {
  1131. orderLibs.AddLinkExtension(ext.c_str());
  1132. }
  1133. ext =
  1134. m_CurrentMakefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_SUFFIX");
  1135. if(ext.size())
  1136. {
  1137. orderLibs.AddLinkExtension(ext.c_str());
  1138. }
  1139. const char* targetLibrary = cmtarget->GetName();
  1140. if(cmtarget->GetType() == cmTarget::EXECUTABLE)
  1141. {
  1142. targetLibrary = 0;
  1143. }
  1144. orderLibs.SetLinkInformation(*cmtarget, cmTarget::GENERAL, targetLibrary);
  1145. orderLibs.DetermineLibraryPathOrder();
  1146. std::vector<cmStdString> libdirs;
  1147. std::vector<cmStdString> linkItems;
  1148. orderLibs.GetLinkerInformation(libdirs, linkItems);
  1149. std::string linkDirs;
  1150. // add the library search paths
  1151. for(std::vector<cmStdString>::const_iterator libDir = libdirs.begin();
  1152. libDir != libdirs.end(); ++libDir)
  1153. {
  1154. if(libDir->size() && *libDir != "/usr/lib")
  1155. {
  1156. linkDirs += " ";
  1157. linkDirs += this->XCodeEscapePath(libDir->c_str());
  1158. }
  1159. }
  1160. cmXCodeObject* bset = target->GetObject("buildSettings");
  1161. if(bset)
  1162. {
  1163. bset->AddAttribute("LIBRARY_SEARCH_PATHS",
  1164. this->CreateString(linkDirs.c_str()));
  1165. }
  1166. // now add the link libraries
  1167. for(std::vector<cmStdString>::iterator lib = linkItems.begin();
  1168. lib != linkItems.end(); ++lib)
  1169. {
  1170. cmTarget* t = this->FindTarget(m_CurrentProject.c_str(),
  1171. lib->c_str());
  1172. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  1173. if(dptarget)
  1174. {
  1175. this->AddDependTarget(target, dptarget);
  1176. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  1177. {
  1178. this->AddLinkLibrary(target, t->GetName(), t);
  1179. }
  1180. }
  1181. else
  1182. {
  1183. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  1184. {
  1185. this->AddLinkLibrary(target, lib->c_str());
  1186. }
  1187. }
  1188. }
  1189. // write utility dependencies.
  1190. for(std::set<cmStdString>::const_iterator i
  1191. = cmtarget->GetUtilities().begin();
  1192. i != cmtarget->GetUtilities().end(); ++i)
  1193. {
  1194. cmTarget* t = this->FindTarget(m_CurrentProject.c_str(),
  1195. i->c_str());
  1196. if(!t)
  1197. {
  1198. std::string m = "Error Utility: ";
  1199. m += *i;
  1200. m += " not found in project ";
  1201. m += m_CurrentProject.c_str();
  1202. m += " it is a utility of ";
  1203. m += cmtarget->GetName();
  1204. cmSystemTools::Error(m.c_str());
  1205. }
  1206. else
  1207. {
  1208. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  1209. if(dptarget)
  1210. {
  1211. this->AddDependTarget(target, dptarget);
  1212. }
  1213. else
  1214. {
  1215. std::string m = "Error Utility: ";
  1216. m += i->c_str();
  1217. m += "\n";
  1218. m += "cmtarget ";
  1219. if(t)
  1220. {
  1221. m += t->GetName();
  1222. }
  1223. m += "\n";
  1224. m += "Is on the target ";
  1225. m += cmtarget->GetName();
  1226. m += "\n";
  1227. m += "But it has no xcode target created yet??\n";
  1228. m += "Current project is ";
  1229. m += m_CurrentProject.c_str();
  1230. cmSystemTools::Error(m.c_str());
  1231. }
  1232. }
  1233. }
  1234. std::vector<cmStdString> fullPathLibs;
  1235. orderLibs.GetFullPathLibraries(fullPathLibs);
  1236. for(std::vector<cmStdString>::iterator i = fullPathLibs.begin();
  1237. i != fullPathLibs.end(); ++i)
  1238. {
  1239. target->AddDependLibrary(i->c_str());
  1240. }
  1241. }
  1242. //----------------------------------------------------------------------------
  1243. void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
  1244. std::vector<cmLocalGenerator*>&
  1245. generators)
  1246. {
  1247. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  1248. i != generators.end(); ++i)
  1249. {
  1250. if(this->IsExcluded(root, *i))
  1251. {
  1252. continue;
  1253. }
  1254. cmMakefile* mf = (*i)->GetMakefile();
  1255. std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
  1256. cmTargets &tgts = mf->GetTargets();
  1257. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1258. {
  1259. cmTarget& cmtarget = l->second;
  1260. std::vector<cmSourceFile*> & classes = cmtarget.GetSourceFiles();
  1261. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  1262. s != classes.end(); s++)
  1263. {
  1264. cmSourceFile* sf = *s;
  1265. // Add the file to the list of sources.
  1266. std::string const& source = sf->GetFullPath();
  1267. cmSourceGroup& sourceGroup =
  1268. mf->FindSourceGroup(source.c_str(), sourceGroups);
  1269. cmXCodeObject* pbxgroup = this->CreateOrGetPBXGroup(cmtarget, &sourceGroup);
  1270. m_GroupMap[sf] = pbxgroup;
  1271. }
  1272. }
  1273. }
  1274. }
  1275. //----------------------------------------------------------------------------
  1276. cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup(cmTarget& cmtarget,
  1277. cmSourceGroup* sg)
  1278. {
  1279. cmStdString s = cmtarget.GetName();
  1280. s += "/";
  1281. s += sg->GetName();
  1282. std::map<cmStdString, cmXCodeObject* >::iterator i = m_GroupNameMap.find(s);
  1283. if(i != m_GroupNameMap.end())
  1284. {
  1285. return i->second;
  1286. }
  1287. i = m_TargetGroup.find(cmtarget.GetName());
  1288. cmXCodeObject* tgroup = 0;
  1289. if(i != m_TargetGroup.end())
  1290. {
  1291. tgroup = i->second;
  1292. }
  1293. else
  1294. {
  1295. tgroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1296. m_TargetGroup[cmtarget.GetName()] = tgroup;
  1297. cmXCodeObject* tgroupChildren =
  1298. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1299. tgroup->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  1300. tgroup->AddAttribute("children", tgroupChildren);
  1301. tgroup->AddAttribute("refType", this->CreateString("4"));
  1302. tgroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1303. m_SourcesGroupChildren->AddObject(tgroup);
  1304. }
  1305. cmXCodeObject* tgroupChildren = tgroup->GetObject("children");
  1306. cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
  1307. cmXCodeObject* groupChildren =
  1308. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1309. group->AddAttribute("name", this->CreateString(sg->GetName()));
  1310. group->AddAttribute("children", groupChildren);
  1311. group->AddAttribute("refType", this->CreateString("4"));
  1312. group->AddAttribute("sourceTree", this->CreateString("<group>"));
  1313. tgroupChildren->AddObject(group);
  1314. m_GroupNameMap[s] = group;
  1315. return group;
  1316. }
  1317. //----------------------------------------------------------------------------
  1318. void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
  1319. std::vector<cmLocalGenerator*>&
  1320. generators
  1321. )
  1322. {
  1323. this->ClearXCodeObjects();
  1324. m_RootObject = 0;
  1325. m_SourcesGroupChildren = 0;
  1326. m_MainGroupChildren = 0;
  1327. cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1328. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  1329. cmXCodeObject* developBuildStyle =
  1330. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  1331. developBuildStyle->AddAttribute("name", this->CreateString("Development"));
  1332. developBuildStyle->AddAttribute("buildSettings", group);
  1333. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1334. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("YES"));
  1335. cmXCodeObject* deployBuildStyle =
  1336. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  1337. deployBuildStyle->AddAttribute("name", this->CreateString("Deployment"));
  1338. deployBuildStyle->AddAttribute("buildSettings", group);
  1339. cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1340. listObjs->AddObject(developBuildStyle);
  1341. listObjs->AddObject(deployBuildStyle);
  1342. cmXCodeObject* mainGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1343. m_MainGroupChildren =
  1344. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1345. mainGroup->AddAttribute("children", m_MainGroupChildren);
  1346. mainGroup->AddAttribute("refType", this->CreateString("4"));
  1347. mainGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1348. cmXCodeObject* sourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1349. m_SourcesGroupChildren =
  1350. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1351. sourcesGroup->AddAttribute("name", this->CreateString("Sources"));
  1352. sourcesGroup->AddAttribute("children", m_SourcesGroupChildren);
  1353. sourcesGroup->AddAttribute("refType", this->CreateString("4"));
  1354. sourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1355. m_MainGroupChildren->AddObject(sourcesGroup);
  1356. // now create the cmake groups
  1357. this->CreateGroups(root, generators);
  1358. cmXCodeObject* productGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1359. productGroup->AddAttribute("name", this->CreateString("Products"));
  1360. productGroup->AddAttribute("refType", this->CreateString("4"));
  1361. productGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1362. cmXCodeObject* productGroupChildren =
  1363. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1364. productGroup->AddAttribute("children", productGroupChildren);
  1365. m_MainGroupChildren->AddObject(productGroup);
  1366. m_RootObject = this->CreateObject(cmXCodeObject::PBXProject);
  1367. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1368. m_RootObject->AddAttribute("mainGroup",
  1369. this->CreateObjectReference(mainGroup));
  1370. m_RootObject->AddAttribute("buildSettings", group);
  1371. m_RootObject->AddAttribute("buildSyles", listObjs);
  1372. m_RootObject->AddAttribute("hasScannedForEncodings",
  1373. this->CreateString("0"));
  1374. std::vector<cmXCodeObject*> targets;
  1375. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  1376. i != generators.end(); ++i)
  1377. {
  1378. if(!this->IsExcluded(root, *i))
  1379. {
  1380. this->CreateXCodeTargets(*i, targets);
  1381. }
  1382. }
  1383. // loop over all targets and add link and depend info
  1384. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1385. i != targets.end(); ++i)
  1386. {
  1387. cmXCodeObject* t = *i;
  1388. this->AddDependAndLinkInformation(t);
  1389. }
  1390. // now create xcode depend hack makefile
  1391. this->CreateXCodeDependHackTarget(targets);
  1392. // now add all targets to the root object
  1393. cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1394. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1395. i != targets.end(); ++i)
  1396. {
  1397. cmXCodeObject* t = *i;
  1398. allTargets->AddObject(t);
  1399. cmXCodeObject* productRef = t->GetObject("productReference");
  1400. if(productRef)
  1401. {
  1402. productGroupChildren->AddObject(productRef->GetObject());
  1403. }
  1404. }
  1405. m_RootObject->AddAttribute("targets", allTargets);
  1406. }
  1407. //----------------------------------------------------------------------------
  1408. void
  1409. cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
  1410. std::vector<cmXCodeObject*>& targets)
  1411. {
  1412. cmGeneratedFileStream makefileStream(m_CurrentXCodeHackMakefile.c_str());
  1413. if(!makefileStream)
  1414. {
  1415. cmSystemTools::Error("Could not create",
  1416. m_CurrentXCodeHackMakefile.c_str());
  1417. return;
  1418. }
  1419. // one more pass for external depend information not handled
  1420. // correctly by xcode
  1421. makefileStream << "# DO NOT EDIT\n";
  1422. makefileStream << "# This makefile makes sure all linkable targets are \n";
  1423. makefileStream
  1424. << "# up-to-date with anything they link to,avoiding a bug in XCode 1.5\n";
  1425. makefileStream << "all: ";
  1426. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1427. i != targets.end(); ++i)
  1428. {
  1429. cmXCodeObject* target = *i;
  1430. cmTarget* t =target->GetcmTarget();
  1431. if(t->GetType() == cmTarget::EXECUTABLE ||
  1432. t->GetType() == cmTarget::SHARED_LIBRARY ||
  1433. t->GetType() == cmTarget::MODULE_LIBRARY)
  1434. {
  1435. makefileStream << "\\\n\t"
  1436. << this->
  1437. ConvertToRelativeForMake(this->GetTargetFullPath(target->GetcmTarget()).c_str());
  1438. }
  1439. }
  1440. makefileStream << "\n\n";
  1441. makefileStream
  1442. << "# For each target create a dummy rule "
  1443. "so the target does not have to exist\n";
  1444. std::set<cmStdString> emitted;
  1445. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1446. i != targets.end(); ++i)
  1447. {
  1448. cmXCodeObject* target = *i;
  1449. std::vector<cmStdString> const& deplibs = target->GetDependLibraries();
  1450. for(std::vector<cmStdString>::const_iterator d = deplibs.begin();
  1451. d != deplibs.end(); ++d)
  1452. {
  1453. if(emitted.insert(*d).second)
  1454. {
  1455. makefileStream << this->ConvertToRelativeForMake(d->c_str()) << ":\n";
  1456. }
  1457. }
  1458. }
  1459. makefileStream << "\n\n";
  1460. makefileStream <<
  1461. "# Each linkable target depends on everything it links to.\n";
  1462. makefileStream
  1463. << "#And the target is removed if it is older than what it linkes to\n";
  1464. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1465. i != targets.end(); ++i)
  1466. {
  1467. cmXCodeObject* target = *i;
  1468. cmTarget* t =target->GetcmTarget();
  1469. if(t->GetType() == cmTarget::EXECUTABLE ||
  1470. t->GetType() == cmTarget::SHARED_LIBRARY ||
  1471. t->GetType() == cmTarget::MODULE_LIBRARY)
  1472. {
  1473. std::vector<cmStdString> const& deplibs = target->GetDependLibraries();
  1474. std::string tfull = this->GetTargetFullPath(target->GetcmTarget());
  1475. makefileStream << this->ConvertToRelativeForMake(tfull.c_str()) << ": ";
  1476. for(std::vector<cmStdString>::const_iterator d = deplibs.begin();
  1477. d != deplibs.end(); ++d)
  1478. {
  1479. makefileStream << "\\\n\t" << this->ConvertToRelativeForMake(d->c_str());
  1480. }
  1481. makefileStream << "\n";
  1482. makefileStream << "\t/bin/rm -f "
  1483. << this->ConvertToRelativeForMake(tfull.c_str()) << "\n";
  1484. makefileStream << "\n\n";
  1485. }
  1486. }
  1487. }
  1488. //----------------------------------------------------------------------------
  1489. void
  1490. cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
  1491. std::vector<cmLocalGenerator*>&
  1492. generators)
  1493. {
  1494. if(generators.size() == 0)
  1495. {
  1496. return;
  1497. }
  1498. this->CreateXCodeObjects(root,
  1499. generators);
  1500. std::string xcodeDir = root->GetMakefile()->GetStartOutputDirectory();
  1501. xcodeDir += "/";
  1502. xcodeDir += root->GetMakefile()->GetProjectName();
  1503. xcodeDir += ".xcode";
  1504. cmSystemTools::MakeDirectory(xcodeDir.c_str());
  1505. xcodeDir += "/project.pbxproj";
  1506. cmGeneratedFileStream fout(xcodeDir.c_str());
  1507. fout.SetCopyIfDifferent(true);
  1508. if(!fout)
  1509. {
  1510. return;
  1511. }
  1512. this->WriteXCodePBXProj(fout, root, generators);
  1513. this->ClearXCodeObjects();
  1514. }
  1515. //----------------------------------------------------------------------------
  1516. void
  1517. cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
  1518. cmLocalGenerator* ,
  1519. std::vector<cmLocalGenerator*>& )
  1520. {
  1521. fout << "// !$*UTF8*$!\n";
  1522. fout << "{\n";
  1523. cmXCodeObject::Indent(1, fout);
  1524. fout << "archiveVersion = 1;\n";
  1525. cmXCodeObject::Indent(1, fout);
  1526. fout << "classes = {\n";
  1527. cmXCodeObject::Indent(1, fout);
  1528. fout << "};\n";
  1529. cmXCodeObject::Indent(1, fout);
  1530. fout << "objectVersion = 39;\n";
  1531. cmXCodeObject::PrintList(m_XCodeObjects, fout);
  1532. cmXCodeObject::Indent(1, fout);
  1533. fout << "rootObject = " << m_RootObject->GetId() << ";\n";
  1534. fout << "}\n";
  1535. }
  1536. //----------------------------------------------------------------------------
  1537. void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry)
  1538. const
  1539. {
  1540. entry.name = this->GetName();
  1541. entry.brief = "Generate XCode project files.";
  1542. entry.full = "";
  1543. }
  1544. //----------------------------------------------------------------------------
  1545. std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(const char* p)
  1546. {
  1547. if ( !m_CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  1548. {
  1549. return cmSystemTools::ConvertToOutputPath(p);
  1550. }
  1551. else
  1552. {
  1553. std::string ret = this->ConvertToRelativePath(m_CurrentOutputDirectoryComponents, p);
  1554. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  1555. }
  1556. }
  1557. //----------------------------------------------------------------------------
  1558. std::string cmGlobalXCodeGenerator::ConvertToRelativeForXCode(const char* p)
  1559. {
  1560. if ( !m_CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  1561. {
  1562. return cmSystemTools::ConvertToOutputPath(p);
  1563. }
  1564. else
  1565. {
  1566. std::string ret = this->ConvertToRelativePath(m_ProjectOutputDirectoryComponents, p);
  1567. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  1568. }
  1569. }
  1570. std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p)
  1571. {
  1572. std::string ret = p;
  1573. if(ret.find(' ') != ret.npos)
  1574. {
  1575. std::string t = ret;
  1576. ret = "\\\"";
  1577. ret += t;
  1578. ret += "\\\"";
  1579. }
  1580. return ret;
  1581. }