cmGlobalXCodeGenerator.cxx 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214
  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 "cmGlobalXCode21Generator.h"
  15. #include "cmLocalXCodeGenerator.h"
  16. #include "cmMakefile.h"
  17. #include "cmXCodeObject.h"
  18. #include "cmXCode21Object.h"
  19. #include "cmake.h"
  20. #include "cmGeneratedFileStream.h"
  21. #include "cmSourceFile.h"
  22. #include "cmOrderLinkDirectories.h"
  23. #if defined(CMAKE_BUILD_WITH_CMAKE)
  24. #include "cmXMLParser.h"
  25. // parse the xml file storing the installed version of Xcode on
  26. // the machine
  27. class cmXcodeVersionParser : public cmXMLParser
  28. {
  29. public:
  30. void StartElement(const char* , const char** )
  31. {
  32. m_Data = "";
  33. }
  34. void EndElement(const char* name)
  35. {
  36. if(strcmp(name, "key") == 0)
  37. {
  38. m_Key = m_Data;
  39. }
  40. else if(strcmp(name, "string") == 0)
  41. {
  42. if(m_Key == "CFBundleShortVersionString")
  43. {
  44. m_Version = (int)(10.0 * atof(m_Data.c_str()));
  45. }
  46. }
  47. }
  48. void CharacterDataHandler(const char* data, int length)
  49. {
  50. m_Data.append(data, length);
  51. }
  52. int m_Version;
  53. std::string m_Key;
  54. std::string m_Data;
  55. };
  56. #endif
  57. //TODO
  58. // add OSX application stuff
  59. //----------------------------------------------------------------------------
  60. cmGlobalXCodeGenerator::cmGlobalXCodeGenerator()
  61. {
  62. m_FindMakeProgramFile = "CMakeFindXCode.cmake";
  63. m_RootObject = 0;
  64. m_MainGroupChildren = 0;
  65. m_SourcesGroupChildren = 0;
  66. m_CurrentMakefile = 0;
  67. m_CurrentLocalGenerator = 0;
  68. m_XcodeVersion = 15;
  69. }
  70. //----------------------------------------------------------------------------
  71. cmGlobalGenerator* cmGlobalXCodeGenerator::New()
  72. {
  73. #if defined(CMAKE_BUILD_WITH_CMAKE)
  74. cmXcodeVersionParser parser;
  75. parser.ParseFile("/Developer/Applications/Xcode.app/Contents/version.plist");
  76. if(parser.m_Version == 15)
  77. {
  78. return new cmGlobalXCodeGenerator;
  79. }
  80. else if (parser.m_Version == 20)
  81. {
  82. cmSystemTools::Message("Xcode 2.0 not really supported by cmake, "
  83. "using Xcode 15 generator\n");
  84. return new cmGlobalXCodeGenerator;
  85. }
  86. cmGlobalXCodeGenerator* ret = new cmGlobalXCode21Generator;
  87. ret->SetVersion(parser.m_Version);
  88. return ret;
  89. #else
  90. std::cerr
  91. << "CMake should be built with cmake to use XCode, default to Xcode 1.5\n";
  92. return new cmGlobalXCodeGenerator;
  93. #endif
  94. }
  95. //----------------------------------------------------------------------------
  96. void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
  97. lang,
  98. cmMakefile * mf)
  99. {
  100. mf->AddDefinition("XCODE","1");
  101. if(m_XcodeVersion == 15)
  102. {
  103. mf->AddDefinition("CMAKE_CFG_INTDIR",".");
  104. }
  105. else
  106. {
  107. mf->AddDefinition("CMAKE_CFG_INTDIR","$(CONFIGURATION)");
  108. mf->AddCacheDefinition(
  109. "CMAKE_CONFIGURATION_TYPES",
  110. "Debug;Release;MinSizeRel;RelWithDebInfo",
  111. "Semicolon separated list of supported configuration types, "
  112. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  113. "anything else will be ignored.",
  114. cmCacheManager::STRING);
  115. }
  116. mf->AddDefinition("CMAKE_GENERATOR_CC", "gcc");
  117. mf->AddDefinition("CMAKE_GENERATOR_CXX", "g++");
  118. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  119. this->cmGlobalGenerator::EnableLanguage(lang, mf);
  120. }
  121. //----------------------------------------------------------------------------
  122. std::string cmGlobalXCodeGenerator::GenerateBuildCommand(const char* makeProgram,
  123. const char *projectName, const char* additionalOptions, const char *targetName,
  124. const char* config, bool ignoreErrors)
  125. {
  126. // Config is not used yet
  127. (void) config;
  128. (void) ignoreErrors;
  129. // now build the test
  130. if(makeProgram == 0 || !strlen(makeProgram))
  131. {
  132. cmSystemTools::Error(
  133. "Generator cannot find the appropriate make command.");
  134. return "";
  135. }
  136. std::string makeCommand =
  137. cmSystemTools::ConvertToOutputPath(makeProgram);
  138. std::string lowerCaseCommand = makeCommand;
  139. cmSystemTools::LowerCase(lowerCaseCommand);
  140. makeCommand += " -project ";
  141. makeCommand += projectName;
  142. makeCommand += ".xcode";
  143. if(m_XcodeVersion > 20)
  144. {
  145. makeCommand += "proj";
  146. }
  147. bool clean = false;
  148. if ( targetName && strcmp(targetName, "clean") == 0 )
  149. {
  150. clean = true;
  151. targetName = "ALL_BUILD";
  152. }
  153. if(clean)
  154. {
  155. makeCommand += " clean";
  156. }
  157. else
  158. {
  159. makeCommand += " build";
  160. }
  161. makeCommand += " -target ";
  162. if (targetName && strlen(targetName))
  163. {
  164. makeCommand += targetName;
  165. }
  166. else
  167. {
  168. makeCommand += "ALL_BUILD";
  169. }
  170. if(m_XcodeVersion == 15)
  171. {
  172. makeCommand += " -buildstyle Development ";
  173. }
  174. else
  175. {
  176. makeCommand += " -configuration Debug";
  177. }
  178. if ( additionalOptions )
  179. {
  180. makeCommand += " ";
  181. makeCommand += additionalOptions;
  182. }
  183. makeCommand += " OBJROOT=.";
  184. return makeCommand;
  185. }
  186. //----------------------------------------------------------------------------
  187. void cmGlobalXCodeGenerator::ConfigureOutputPaths()
  188. {
  189. // Format the library and executable output paths.
  190. m_LibraryOutputPath =
  191. m_CurrentMakefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  192. if(m_LibraryOutputPath.size() == 0)
  193. {
  194. m_LibraryOutputPath = m_CurrentMakefile->GetCurrentOutputDirectory();
  195. }
  196. // make sure there is a trailing slash
  197. if(m_LibraryOutputPath.size() &&
  198. m_LibraryOutputPath[m_LibraryOutputPath.size()-1] != '/')
  199. {
  200. m_LibraryOutputPath += "/";
  201. if(!cmSystemTools::MakeDirectory(m_LibraryOutputPath.c_str()))
  202. {
  203. cmSystemTools::Error("Error creating directory ",
  204. m_LibraryOutputPath.c_str());
  205. }
  206. }
  207. m_CurrentMakefile->AddLinkDirectory(m_LibraryOutputPath.c_str());
  208. m_ExecutableOutputPath =
  209. m_CurrentMakefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  210. if(m_ExecutableOutputPath.size() == 0)
  211. {
  212. m_ExecutableOutputPath = m_CurrentMakefile->GetCurrentOutputDirectory();
  213. }
  214. // make sure there is a trailing slash
  215. if(m_ExecutableOutputPath.size() &&
  216. m_ExecutableOutputPath[m_ExecutableOutputPath.size()-1] != '/')
  217. {
  218. m_ExecutableOutputPath += "/";
  219. if(!cmSystemTools::MakeDirectory(m_ExecutableOutputPath.c_str()))
  220. {
  221. cmSystemTools::Error("Error creating directory ",
  222. m_ExecutableOutputPath.c_str());
  223. }
  224. }
  225. }
  226. //----------------------------------------------------------------------------
  227. ///! Create a local generator appropriate to this Global Generator
  228. cmLocalGenerator *cmGlobalXCodeGenerator::CreateLocalGenerator()
  229. {
  230. cmLocalGenerator *lg = new cmLocalXCodeGenerator;
  231. lg->SetGlobalGenerator(this);
  232. return lg;
  233. }
  234. //----------------------------------------------------------------------------
  235. void cmGlobalXCodeGenerator::Generate()
  236. {
  237. this->cmGlobalGenerator::Generate();
  238. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  239. for(it = m_ProjectMap.begin(); it!= m_ProjectMap.end(); ++it)
  240. {
  241. cmLocalGenerator* root = it->second[0];
  242. m_CurrentProject = root->GetMakefile()->GetProjectName();
  243. this->SetCurrentLocalGenerator(root);
  244. m_OutputDir = m_CurrentMakefile->GetHomeOutputDirectory();
  245. m_OutputDir = cmSystemTools::CollapseFullPath(m_OutputDir.c_str());
  246. cmSystemTools::SplitPath(m_OutputDir.c_str(),
  247. m_ProjectOutputDirectoryComponents);
  248. m_CurrentLocalGenerator = root;
  249. // add ALL_BUILD, INSTALL, etc
  250. this->AddExtraTargets(root, it->second);
  251. // now create the project
  252. this->OutputXCodeProject(root, it->second);
  253. }
  254. }
  255. //----------------------------------------------------------------------------
  256. void
  257. cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
  258. std::vector<cmLocalGenerator*>& gens)
  259. {
  260. cmMakefile* mf = root->GetMakefile();
  261. // Add ALL_BUILD
  262. const char* no_output = 0;
  263. std::vector<std::string> no_depends;
  264. mf->AddUtilityCommand("ALL_BUILD", false, no_output, no_depends,
  265. "echo", "Build all projects");
  266. cmTarget* allbuild = mf->FindTarget("ALL_BUILD");
  267. // ADD install
  268. std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
  269. if(m_XcodeVersion == 15)
  270. {
  271. mf->AddUtilityCommand("install", false, no_output, no_depends,
  272. cmake_command.c_str(),
  273. "-P", "cmake_install.cmake");
  274. }
  275. else
  276. {
  277. mf->AddUtilityCommand("install", false, no_output, no_depends,
  278. cmake_command.c_str(),
  279. "-DBUILD_TYPE=$(CONFIGURATION)",
  280. "-P", "cmake_install.cmake");
  281. }
  282. const char* noall =
  283. mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  284. if(!noall || cmSystemTools::IsOff(noall))
  285. {
  286. cmTarget* install = mf->FindTarget("install");
  287. install->AddUtility("ALL_BUILD");
  288. }
  289. // Add RUN_TESTS target if testing has been enabled
  290. std::string fname;
  291. fname = mf->GetStartOutputDirectory();
  292. fname += "/";
  293. fname += "DartTestfile.txt";
  294. if (cmSystemTools::FileExists(fname.c_str()))
  295. {
  296. std::string ctest_command =
  297. mf->GetRequiredDefinition("CMAKE_CTEST_COMMAND");
  298. mf->AddUtilityCommand("RUN_TESTS", false, no_output, no_depends,
  299. ctest_command.c_str());
  300. }
  301. // Add XCODE depend helper
  302. std::string dir = mf->GetCurrentOutputDirectory();
  303. m_CurrentXCodeHackMakefile = dir;
  304. m_CurrentXCodeHackMakefile += "/CMakeScripts";
  305. cmSystemTools::MakeDirectory(m_CurrentXCodeHackMakefile.c_str());
  306. m_CurrentXCodeHackMakefile += "/XCODE_DEPEND_HELPER.make";
  307. cmCustomCommandLine makecommand;
  308. makecommand.push_back("make");
  309. makecommand.push_back("-C");
  310. makecommand.push_back(dir.c_str());
  311. makecommand.push_back("-f");
  312. makecommand.push_back(m_CurrentXCodeHackMakefile.c_str());
  313. cmCustomCommandLines commandLines;
  314. commandLines.push_back(makecommand);
  315. mf->AddUtilityCommand("XCODE_DEPEND_HELPER", false, no_output, no_depends,
  316. commandLines);
  317. // Add Re-Run CMake rules
  318. this->CreateReRunCMakeFile(root);
  319. // now make the allbuild depend on all the non-utility targets
  320. // in the project
  321. for(std::vector<cmLocalGenerator*>::iterator i = gens.begin();
  322. i != gens.end(); ++i)
  323. {
  324. cmLocalGenerator* lg = *i;
  325. if(this->IsExcluded(root, *i))
  326. {
  327. continue;
  328. }
  329. cmTargets& tgts = lg->GetMakefile()->GetTargets();
  330. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  331. {
  332. cmTarget& target = l->second;
  333. // make all exe, shared libs and modules depend
  334. // on the XCODE_DEPEND_HELPER target
  335. if((target.GetType() == cmTarget::EXECUTABLE ||
  336. target.GetType() == cmTarget::SHARED_LIBRARY ||
  337. target.GetType() == cmTarget::MODULE_LIBRARY))
  338. {
  339. target.AddUtility("XCODE_DEPEND_HELPER");
  340. }
  341. if(target.IsInAll())
  342. {
  343. allbuild->AddUtility(target.GetName());
  344. }
  345. }
  346. }
  347. }
  348. //----------------------------------------------------------------------------
  349. void cmGlobalXCodeGenerator::CreateReRunCMakeFile(cmLocalGenerator* root)
  350. {
  351. cmMakefile* mf = root->GetMakefile();
  352. std::vector<std::string> lfiles = mf->GetListFiles();
  353. // sort the array
  354. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
  355. std::vector<std::string>::iterator new_end =
  356. std::unique(lfiles.begin(), lfiles.end());
  357. lfiles.erase(new_end, lfiles.end());
  358. std::string dir = mf->GetHomeOutputDirectory();
  359. m_CurrentReRunCMakeMakefile = dir;
  360. m_CurrentReRunCMakeMakefile += "/CMakeScripts";
  361. cmSystemTools::MakeDirectory(m_CurrentReRunCMakeMakefile.c_str());
  362. m_CurrentReRunCMakeMakefile += "/ReRunCMake.make";
  363. cmGeneratedFileStream makefileStream(m_CurrentReRunCMakeMakefile.c_str());
  364. makefileStream.SetCopyIfDifferent(true);
  365. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  366. makefileStream << "CMakeFiles/cmake.check_cache: ";
  367. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  368. i != lfiles.end(); ++i)
  369. {
  370. makefileStream << "\\\n" << this->ConvertToRelativeForMake(i->c_str());
  371. }
  372. std::string cmake = mf->GetRequiredDefinition("CMAKE_COMMAND");
  373. makefileStream << "\n\t" << this->ConvertToRelativeForMake(cmake.c_str())
  374. << " -H" << this->ConvertToRelativeForMake(
  375. mf->GetHomeDirectory())
  376. << " -B" << this->ConvertToRelativeForMake(
  377. mf->GetHomeOutputDirectory()) << "\n";
  378. }
  379. //----------------------------------------------------------------------------
  380. void cmGlobalXCodeGenerator::ClearXCodeObjects()
  381. {
  382. m_TargetDoneSet.clear();
  383. for(unsigned int i = 0; i < m_XCodeObjects.size(); ++i)
  384. {
  385. delete m_XCodeObjects[i];
  386. }
  387. m_XCodeObjects.clear();
  388. m_GroupMap.clear();
  389. m_GroupNameMap.clear();
  390. m_TargetGroup.clear();
  391. }
  392. //----------------------------------------------------------------------------
  393. cmXCodeObject*
  394. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
  395. {
  396. cmXCodeObject* obj;
  397. if(m_XcodeVersion == 15)
  398. {
  399. obj = new cmXCodeObject(ptype, cmXCodeObject::OBJECT);
  400. }
  401. else
  402. {
  403. obj = new cmXCode21Object(ptype, cmXCodeObject::OBJECT);
  404. }
  405. m_XCodeObjects.push_back(obj);
  406. return obj;
  407. }
  408. //----------------------------------------------------------------------------
  409. cmXCodeObject*
  410. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
  411. {
  412. cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, type);
  413. m_XCodeObjects.push_back(obj);
  414. return obj;
  415. }
  416. //----------------------------------------------------------------------------
  417. cmXCodeObject*
  418. cmGlobalXCodeGenerator::CreateString(const char* s)
  419. {
  420. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::STRING);
  421. obj->SetString(s);
  422. return obj;
  423. }
  424. //----------------------------------------------------------------------------
  425. cmXCodeObject* cmGlobalXCodeGenerator::CreateObjectReference(cmXCodeObject* ref)
  426. {
  427. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::OBJECT_REF);
  428. obj->SetObject(ref);
  429. return obj;
  430. }
  431. //----------------------------------------------------------------------------
  432. cmXCodeObject*
  433. cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
  434. cmSourceFile* sf)
  435. {
  436. std::string flags;
  437. // Add flags from source file properties.
  438. lg->AppendFlags(flags, sf->GetProperty("COMPILE_FLAGS"));
  439. cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  440. cmXCodeObject* group = m_GroupMap[sf];
  441. cmXCodeObject* children = group->GetObject("children");
  442. children->AddObject(fileRef);
  443. cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
  444. std::string fname = sf->GetSourceName();
  445. fname += ".";
  446. fname += sf->GetSourceExtension();
  447. std::string comment = fname;
  448. comment += " in ";
  449. std::string gname = group->GetObject("name")->GetString();
  450. comment += gname.substr(1, gname.size()-2);
  451. buildFile->SetComment(comment.c_str());
  452. fileRef->SetComment(fname.c_str());
  453. buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef));
  454. cmXCodeObject* settings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  455. settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags.c_str()));
  456. buildFile->AddAttribute("settings", settings);
  457. fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
  458. const char* lang =
  459. this->GetLanguageFromExtension(sf->GetSourceExtension().c_str());
  460. std::string sourcecode = "sourcecode";
  461. std::string ext = sf->GetSourceExtension();
  462. ext = cmSystemTools::LowerCase(ext);
  463. if(ext == "o")
  464. {
  465. sourcecode = "compiled.mach-o.objfile";
  466. }
  467. else if(ext == "mm")
  468. {
  469. sourcecode += ".cpp.objcpp";
  470. }
  471. else if(ext == "m")
  472. {
  473. sourcecode += ".cpp.objc";
  474. }
  475. else if(!lang)
  476. {
  477. sourcecode += ext;
  478. sourcecode += ".";
  479. sourcecode += ext;
  480. }
  481. else if(strcmp(lang, "C") == 0)
  482. {
  483. sourcecode += ".c.c";
  484. }
  485. else
  486. {
  487. sourcecode += ".cpp.cpp";
  488. }
  489. fileRef->AddAttribute("lastKnownFileType",
  490. this->CreateString(sourcecode.c_str()));
  491. std::string path =
  492. this->ConvertToRelativeForXCode(sf->GetFullPath().c_str());
  493. std::string dir;
  494. std::string file;
  495. cmSystemTools::SplitProgramPath(sf->GetFullPath().c_str(),
  496. dir, file);
  497. fileRef->AddAttribute("name", this->CreateString(file.c_str()));
  498. fileRef->AddAttribute("path", this->CreateString(path.c_str()));
  499. if(m_XcodeVersion == 15)
  500. {
  501. fileRef->AddAttribute("refType", this->CreateString("4"));
  502. }
  503. if(path.size() > 1 && path[0] == '.' && path[1] == '.')
  504. {
  505. fileRef->AddAttribute("sourceTree", this->CreateString("<group>"));
  506. }
  507. else
  508. {
  509. fileRef->AddAttribute("sourceTree", this->CreateString("<absolute>"));
  510. }
  511. return buildFile;
  512. }
  513. //----------------------------------------------------------------------------
  514. bool cmGlobalXCodeGenerator::SpecialTargetEmitted(std::string const& tname)
  515. {
  516. if(tname == "ALL_BUILD" || tname == "XCODE_DEPEND_HELPER" ||
  517. tname == "install" || tname == "RUN_TESTS" )
  518. {
  519. if(m_TargetDoneSet.find(tname) != m_TargetDoneSet.end())
  520. {
  521. return true;
  522. }
  523. m_TargetDoneSet.insert(tname);
  524. return false;
  525. }
  526. return false;
  527. }
  528. void cmGlobalXCodeGenerator::SetCurrentLocalGenerator(cmLocalGenerator* gen)
  529. {
  530. m_CurrentLocalGenerator = gen;
  531. m_CurrentMakefile = gen->GetMakefile();
  532. std::string outdir =
  533. cmSystemTools::CollapseFullPath(m_CurrentMakefile->
  534. GetCurrentOutputDirectory());
  535. cmSystemTools::SplitPath(outdir.c_str(), m_CurrentOutputDirectoryComponents);
  536. }
  537. //----------------------------------------------------------------------------
  538. void
  539. cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
  540. std::vector<cmXCodeObject*>&
  541. targets)
  542. {
  543. this->SetCurrentLocalGenerator(gen);
  544. cmTargets &tgts = gen->GetMakefile()->GetTargets();
  545. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  546. {
  547. cmTarget& cmtarget = l->second;
  548. // make sure ALL_BUILD, INSTALL, etc are only done once
  549. if(this->SpecialTargetEmitted(l->first.c_str()))
  550. {
  551. continue;
  552. }
  553. if(cmtarget.GetType() == cmTarget::UTILITY ||
  554. cmtarget.GetType() == cmTarget::INSTALL_FILES ||
  555. cmtarget.GetType() == cmTarget::INSTALL_PROGRAMS)
  556. {
  557. if(cmtarget.GetType() == cmTarget::UTILITY)
  558. {
  559. targets.push_back(this->CreateUtilityTarget(cmtarget));
  560. }
  561. continue;
  562. }
  563. // create source build phase
  564. cmXCodeObject* sourceBuildPhase =
  565. this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
  566. sourceBuildPhase->AddAttribute("buildActionMask",
  567. this->CreateString("2147483647"));
  568. sourceBuildPhase->SetComment("Sources");
  569. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  570. sourceBuildPhase->AddAttribute("files", buildFiles);
  571. sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  572. this->CreateString("0"));
  573. std::vector<cmSourceFile*> &classes = l->second.GetSourceFiles();
  574. // add all the sources
  575. std::vector<cmXCodeObject*> externalObjFiles;
  576. std::vector<cmXCodeObject*> headerFiles;
  577. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  578. i != classes.end(); ++i)
  579. {
  580. cmXCodeObject* xsf = this->CreateXCodeSourceFile(gen, *i);
  581. cmXCodeObject* fr = xsf->GetObject("fileRef");
  582. cmXCodeObject* filetype =
  583. fr->GetObject()->GetObject("lastKnownFileType");
  584. if(strcmp(filetype->GetString(), "\"compiled.mach-o.objfile\"") == 0)
  585. {
  586. externalObjFiles.push_back(xsf);
  587. }
  588. else if((*i)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  589. {
  590. headerFiles.push_back(xsf);
  591. }
  592. else
  593. {
  594. buildFiles->AddObject(xsf);
  595. }
  596. }
  597. // create header build phase
  598. cmXCodeObject* headerBuildPhase =
  599. this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase);
  600. headerBuildPhase->SetComment("Headers");
  601. headerBuildPhase->AddAttribute("buildActionMask",
  602. this->CreateString("2147483647"));
  603. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  604. for(std::vector<cmXCodeObject*>::iterator i = headerFiles.begin();
  605. i != headerFiles.end(); ++i)
  606. {
  607. buildFiles->AddObject(*i);
  608. }
  609. headerBuildPhase->AddAttribute("files", buildFiles);
  610. headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  611. this->CreateString("0"));
  612. // create framework build phase
  613. cmXCodeObject* frameworkBuildPhase =
  614. this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
  615. frameworkBuildPhase->SetComment("Frameworks");
  616. frameworkBuildPhase->AddAttribute("buildActionMask",
  617. this->CreateString("2147483647"));
  618. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  619. frameworkBuildPhase->AddAttribute("files", buildFiles);
  620. for(std::vector<cmXCodeObject*>::iterator i = externalObjFiles.begin();
  621. i != externalObjFiles.end(); ++i)
  622. {
  623. buildFiles->AddObject(*i);
  624. }
  625. frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  626. this->CreateString("0"));
  627. cmXCodeObject* buildPhases =
  628. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  629. this->CreateCustomCommands(buildPhases, sourceBuildPhase,
  630. headerBuildPhase, frameworkBuildPhase,
  631. cmtarget);
  632. targets.push_back(this->CreateXCodeTarget(l->second, buildPhases));
  633. }
  634. }
  635. //----------------------------------------------------------------------------
  636. cmXCodeObject*
  637. cmGlobalXCodeGenerator::CreateBuildPhase(const char* name,
  638. const char* name2,
  639. cmTarget& cmtarget,
  640. const std::vector<cmCustomCommand>&
  641. commands)
  642. {
  643. if(commands.size() == 0 && strcmp(name, "CMake ReRun") != 0)
  644. {
  645. return 0;
  646. }
  647. cmXCodeObject* buildPhase =
  648. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  649. buildPhase->AddAttribute("buildActionMask",
  650. this->CreateString("2147483647"));
  651. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  652. buildPhase->AddAttribute("files", buildFiles);
  653. buildPhase->AddAttribute("name",
  654. this->CreateString(name));
  655. buildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  656. this->CreateString("0"));
  657. buildPhase->AddAttribute("shellPath",
  658. this->CreateString("/bin/sh"));
  659. this->AddCommandsToBuildPhase(buildPhase, cmtarget, commands,
  660. name2);
  661. return buildPhase;
  662. }
  663. //----------------------------------------------------------------------------
  664. void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
  665. cmXCodeObject*
  666. sourceBuildPhase,
  667. cmXCodeObject*
  668. headerBuildPhase,
  669. cmXCodeObject*
  670. frameworkBuildPhase,
  671. cmTarget& cmtarget)
  672. {
  673. std::vector<cmCustomCommand> const & prebuild
  674. = cmtarget.GetPreBuildCommands();
  675. std::vector<cmCustomCommand> const & prelink
  676. = cmtarget.GetPreLinkCommands();
  677. std::vector<cmCustomCommand> const & postbuild
  678. = cmtarget.GetPostBuildCommands();
  679. cmtarget.TraceVSDependencies(cmtarget.GetName(), m_CurrentMakefile);
  680. std::vector<cmSourceFile*> &classes = cmtarget.GetSourceFiles();
  681. // add all the sources
  682. std::vector<cmCustomCommand> commands;
  683. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  684. i != classes.end(); ++i)
  685. {
  686. if((*i)->GetCustomCommand())
  687. {
  688. commands.push_back(*(*i)->GetCustomCommand());
  689. }
  690. }
  691. std::vector<cmCustomCommand> reruncom;
  692. cmXCodeObject* cmakeReRunPhase = this->CreateBuildPhase("CMake ReRun",
  693. "cmakeReRunPhase",
  694. cmtarget, reruncom);
  695. buildPhases->AddObject(cmakeReRunPhase);
  696. // create prebuild phase
  697. cmXCodeObject* cmakeRulesBuildPhase =
  698. this->CreateBuildPhase("CMake Rules",
  699. "cmakeRulesBuildPhase",
  700. cmtarget, commands);
  701. // create prebuild phase
  702. cmXCodeObject* preBuildPhase = this->CreateBuildPhase("CMake PreBuild Rules",
  703. "preBuildCommands",
  704. cmtarget, prebuild);
  705. // create prebuild phase
  706. cmXCodeObject* preLinkPhase = this->CreateBuildPhase("CMake PreLink Rules",
  707. "preLinkCommands",
  708. cmtarget, prelink);
  709. // create prebuild phase
  710. cmXCodeObject* postBuildPhase =
  711. this->CreateBuildPhase("CMake PostBuild Rules",
  712. "postBuildPhase",
  713. cmtarget, postbuild);
  714. // the order here is the order they will be built in
  715. if(preBuildPhase)
  716. {
  717. buildPhases->AddObject(preBuildPhase);
  718. }
  719. if(cmakeRulesBuildPhase)
  720. {
  721. buildPhases->AddObject(cmakeRulesBuildPhase);
  722. }
  723. if(sourceBuildPhase)
  724. {
  725. buildPhases->AddObject(sourceBuildPhase);
  726. }
  727. if(headerBuildPhase)
  728. {
  729. buildPhases->AddObject(headerBuildPhase);
  730. }
  731. if(preLinkPhase)
  732. {
  733. buildPhases->AddObject(preLinkPhase);
  734. }
  735. if(frameworkBuildPhase)
  736. {
  737. buildPhases->AddObject(frameworkBuildPhase);
  738. }
  739. if(postBuildPhase)
  740. {
  741. buildPhases->AddObject(postBuildPhase);
  742. }
  743. }
  744. //----------------------------------------------------------------------------
  745. std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
  746. std::string& flags)
  747. {
  748. std::string retFlag;
  749. std::string::size_type pos = flags.find(flag);
  750. if(pos != flags.npos)
  751. {
  752. retFlag = flag;
  753. // remove the flag
  754. flags[pos]=' ';
  755. flags[pos+1]=' ';
  756. char pos2 = flags[pos+2];
  757. // if the pos after the option
  758. if(pos2 != ' ' && pos2 != 0 )
  759. {
  760. retFlag += pos2;
  761. // remove the next part of the flag
  762. flags[pos+2] = ' ';
  763. }
  764. }
  765. return retFlag;
  766. }
  767. //----------------------------------------------------------------------------
  768. void
  769. cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  770. cmTarget& target,
  771. std::vector<cmCustomCommand>
  772. const & commands,
  773. const char* name)
  774. {
  775. if(strcmp(name, "cmakeReRunPhase") == 0)
  776. {
  777. std::string cdir = m_CurrentMakefile->GetHomeOutputDirectory();
  778. cdir = this->ConvertToRelativeForMake(cdir.c_str());
  779. std::string makecmd = "make -C ";
  780. makecmd += cdir;
  781. makecmd += " -f ";
  782. makecmd +=
  783. this->ConvertToRelativeForMake(m_CurrentReRunCMakeMakefile.c_str());
  784. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  785. buildphase->AddAttribute("shellScript",
  786. this->CreateString(makecmd.c_str()));
  787. return;
  788. }
  789. std::string dir = m_CurrentMakefile->GetCurrentOutputDirectory();
  790. dir += "/CMakeScripts";
  791. cmSystemTools::MakeDirectory(dir.c_str());
  792. std::string makefile = dir;
  793. makefile += "/";
  794. makefile += target.GetName();
  795. makefile += "_";
  796. makefile += name;
  797. makefile += ".make";
  798. cmGeneratedFileStream makefileStream(makefile.c_str());
  799. if(!makefileStream)
  800. {
  801. return;
  802. }
  803. makefileStream.SetCopyIfDifferent(true);
  804. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  805. makefileStream << "# Custom rules for " << target.GetName() << "\n";
  806. // have all depend on all outputs
  807. makefileStream << "all: ";
  808. std::map<const cmCustomCommand*, cmStdString> tname;
  809. int count = 0;
  810. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  811. i != commands.end(); ++i)
  812. {
  813. cmCustomCommand const& cc = *i;
  814. if(!cc.GetCommandLines().empty())
  815. {
  816. if(cc.GetOutput()[0])
  817. {
  818. makefileStream << "\\\n\t" << this->
  819. ConvertToRelativeForMake(cc.GetOutput());
  820. }
  821. else
  822. {
  823. char c = '1' + count++;
  824. tname[&cc] = std::string(target.GetName()) + c;
  825. makefileStream << "\\\n\t" << tname[&cc];
  826. }
  827. }
  828. }
  829. makefileStream << "\n\n";
  830. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  831. i != commands.end(); ++i)
  832. {
  833. cmCustomCommand const& cc = *i;
  834. if(!cc.GetCommandLines().empty())
  835. {
  836. makefileStream << "\n#" << "Custom command rule: " <<
  837. cc.GetComment() << "\n";
  838. if(cc.GetOutput()[0])
  839. {
  840. makefileStream << this
  841. ->ConvertToRelativeForMake(cc.GetOutput()) << ": ";
  842. }
  843. else
  844. {
  845. makefileStream << tname[&cc] << ": ";
  846. }
  847. for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
  848. d != cc.GetDepends().end(); ++d)
  849. {
  850. if(!this->FindTarget(m_CurrentProject.c_str(),
  851. d->c_str()))
  852. {
  853. // if the depend is not a target but
  854. // is a full path then use it, if not then
  855. // just skip it
  856. if(cmSystemTools::FileIsFullPath(d->c_str()))
  857. {
  858. makefileStream << "\\\n" << this
  859. ->ConvertToRelativeForMake(d->c_str());
  860. }
  861. }
  862. else
  863. {
  864. // if the depend is a target then make
  865. // the target with the source that is a custom command
  866. // depend on the that target via a AddUtility call
  867. target.AddUtility(d->c_str());
  868. }
  869. }
  870. makefileStream << "\n";
  871. // Add each command line to the set of commands.
  872. for(cmCustomCommandLines::const_iterator cl =
  873. cc.GetCommandLines().begin();
  874. cl != cc.GetCommandLines().end(); ++cl)
  875. {
  876. // Build the command line in a single string.
  877. const cmCustomCommandLine& commandLine = *cl;
  878. std::string cmd = commandLine[0];
  879. cmSystemTools::ReplaceString(cmd, "/./", "/");
  880. cmd = this->ConvertToRelativeForMake(cmd.c_str());
  881. for(unsigned int j=1; j < commandLine.size(); ++j)
  882. {
  883. cmd += " ";
  884. cmd += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
  885. }
  886. makefileStream << "\t" << cmd.c_str() << "\n";
  887. }
  888. }
  889. }
  890. std::string cdir = m_CurrentMakefile->GetCurrentOutputDirectory();
  891. cdir = this->ConvertToRelativeForXCode(cdir.c_str());
  892. std::string makecmd = "make -C ";
  893. makecmd += cdir;
  894. makecmd += " -f ";
  895. makecmd += this->ConvertToRelativeForMake(makefile.c_str());
  896. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  897. buildphase->AddAttribute("shellScript", this->CreateString(makecmd.c_str()));
  898. }
  899. //----------------------------------------------------------------------------
  900. void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
  901. cmXCodeObject* buildSettings,
  902. std::string& fileType,
  903. std::string& productType,
  904. std::string& productName,
  905. const char* buildtype)
  906. {
  907. this->ConfigureOutputPaths();
  908. std::string flags;
  909. std::string defFlags;
  910. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  911. (target.GetType() == cmTarget::MODULE_LIBRARY));
  912. if(shared)
  913. {
  914. defFlags += "-D";
  915. if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  916. {
  917. defFlags += custom_export_name;
  918. }
  919. else
  920. {
  921. std::string in = target.GetName();
  922. in += "_EXPORTS";
  923. defFlags += cmSystemTools::MakeCindentifier(in.c_str());
  924. }
  925. }
  926. const char* lang = target.GetLinkerLanguage(this);
  927. std::string cflags;
  928. if(lang)
  929. {
  930. if(buildtype)
  931. {
  932. m_CurrentMakefile->AddDefinition("CMAKE_BUILD_TYPE", buildtype);
  933. }
  934. // for c++ projects get the c flags as well
  935. if(strcmp(lang, "CXX") == 0)
  936. {
  937. m_CurrentLocalGenerator->AddLanguageFlags(cflags, "C");
  938. m_CurrentLocalGenerator->AddSharedFlags(cflags, lang, shared);
  939. }
  940. // Add language-specific flags.
  941. m_CurrentLocalGenerator->AddLanguageFlags(flags, lang);
  942. // Add shared-library flags if needed.
  943. m_CurrentLocalGenerator->AddSharedFlags(flags, lang, shared);
  944. m_CurrentMakefile->AddDefinition("CMAKE_BUILD_TYPE", "");
  945. }
  946. // Add define flags
  947. m_CurrentLocalGenerator->AppendFlags(defFlags,
  948. m_CurrentMakefile->GetDefineFlags());
  949. cmSystemTools::ReplaceString(defFlags, "\"", "\\\"");
  950. cmSystemTools::ReplaceString(flags, "\"", "\\\"");
  951. cmSystemTools::ReplaceString(cflags, "\"", "\\\"");
  952. if(m_XcodeVersion > 15)
  953. {
  954. buildSettings->
  955. AddAttribute("GCC_PREPROCESSOR_DEFINITIONS",
  956. this->CreateString("CMAKE_INTDIR=\\\\\\\"$(CONFIGURATION)\\\\\\\""));
  957. }
  958. productName = target.GetName();
  959. std::string extraLinkOptions;
  960. if(target.GetType() == cmTarget::EXECUTABLE)
  961. {
  962. extraLinkOptions =
  963. m_CurrentMakefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
  964. }
  965. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  966. {
  967. extraLinkOptions =
  968. m_CurrentMakefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
  969. }
  970. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  971. {
  972. extraLinkOptions =
  973. m_CurrentMakefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
  974. }
  975. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  976. if(targetLinkFlags)
  977. {
  978. extraLinkOptions += " ";
  979. extraLinkOptions += targetLinkFlags;
  980. }
  981. switch(target.GetType())
  982. {
  983. case cmTarget::STATIC_LIBRARY:
  984. {
  985. if(m_LibraryOutputPath.size())
  986. {
  987. buildSettings->AddAttribute("SYMROOT",
  988. this->CreateString
  989. (m_LibraryOutputPath.c_str()));
  990. }
  991. productName += ".a";
  992. std::string t = "lib";
  993. t += productName;
  994. productName = t;
  995. productType = "com.apple.product-type.library.static";
  996. fileType = "archive.ar";
  997. buildSettings->AddAttribute("LIBRARY_STYLE",
  998. this->CreateString("STATIC"));
  999. break;
  1000. }
  1001. case cmTarget::MODULE_LIBRARY:
  1002. {
  1003. if(m_LibraryOutputPath.size())
  1004. {
  1005. buildSettings->AddAttribute("SYMROOT",
  1006. this->CreateString
  1007. (m_LibraryOutputPath.c_str()));
  1008. }
  1009. buildSettings->AddAttribute("EXECUTABLE_PREFIX",
  1010. this->CreateString("lib"));
  1011. buildSettings->AddAttribute("EXECUTABLE_EXTENSION",
  1012. this->CreateString("so"));
  1013. buildSettings->AddAttribute("LIBRARY_STYLE",
  1014. this->CreateString("BUNDLE"));
  1015. productName += ".so";
  1016. std::string t = "lib";
  1017. t += productName;
  1018. productName = t;
  1019. if(m_XcodeVersion >= 22)
  1020. {
  1021. buildSettings->AddAttribute("MACH_O_TYPE",
  1022. this->CreateString("mh_bundle"));
  1023. buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
  1024. this->CreateString("NO"));
  1025. buildSettings->AddAttribute("GCC_SYMBOLS_PRIVATE_EXTERN",
  1026. this->CreateString("NO"));
  1027. buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
  1028. this->CreateString("NO"));
  1029. std::string outflag = "-o \\\"$(CONFIGURATION_BUILD_DIR)/";
  1030. outflag += productName;
  1031. outflag += "\\\"";
  1032. extraLinkOptions += " ";
  1033. extraLinkOptions += outflag;
  1034. productType = "com.apple.product-type.tool";
  1035. fileType = "compiled.mach-o.executable";
  1036. }
  1037. else
  1038. {
  1039. extraLinkOptions += " -bundle";
  1040. productType = "com.apple.product-type.library.dynamic";
  1041. fileType = "compiled.mach-o.dylib";
  1042. }
  1043. break;
  1044. }
  1045. case cmTarget::SHARED_LIBRARY:
  1046. {
  1047. if(m_LibraryOutputPath.size())
  1048. {
  1049. buildSettings->AddAttribute("SYMROOT",
  1050. this->CreateString
  1051. (m_LibraryOutputPath.c_str()));
  1052. }
  1053. buildSettings->AddAttribute("LIBRARY_STYLE",
  1054. this->CreateString("DYNAMIC"));
  1055. productName += ".dylib";
  1056. std::string t = "lib";
  1057. t += productName;
  1058. productName = t;
  1059. buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
  1060. this->CreateString("1"));
  1061. buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
  1062. this->CreateString("1"));
  1063. extraLinkOptions += " -dynamiclib";
  1064. productType = "com.apple.product-type.library.dynamic";
  1065. fileType = "compiled.mach-o.dylib";
  1066. break;
  1067. }
  1068. case cmTarget::EXECUTABLE:
  1069. {
  1070. const char* outname = target.GetProperty("OUTPUT_NAME");
  1071. std::string name;
  1072. if(outname)
  1073. {
  1074. productName = outname;
  1075. name = outname;
  1076. }
  1077. else
  1078. {
  1079. name = target.GetName();
  1080. }
  1081. std::string symRoot;
  1082. if(m_ExecutableOutputPath.size())
  1083. {
  1084. std::string path = m_ExecutableOutputPath;
  1085. symRoot = path;
  1086. }
  1087. fileType = "compiled.mach-o.executable";
  1088. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  1089. {
  1090. productType = "com.apple.product-type.application";
  1091. }
  1092. else
  1093. {
  1094. productType = "com.apple.product-type.tool";
  1095. }
  1096. if(symRoot.size())
  1097. {
  1098. buildSettings->AddAttribute("SYMROOT",
  1099. this->CreateString
  1100. (symRoot.c_str()));
  1101. }
  1102. }
  1103. break;
  1104. case cmTarget::UTILITY:
  1105. break;
  1106. case cmTarget::INSTALL_FILES:
  1107. break;
  1108. case cmTarget::INSTALL_PROGRAMS:
  1109. break;
  1110. }
  1111. std::string dirs;
  1112. std::vector<std::string>& includes =
  1113. m_CurrentMakefile->GetIncludeDirectories();
  1114. std::vector<std::string>::iterator i = includes.begin();
  1115. std::string fdirs;
  1116. std::set<cmStdString> emitted;
  1117. for(;i != includes.end(); ++i)
  1118. {
  1119. if(cmSystemTools::IsPathToFramework(i->c_str()))
  1120. {
  1121. std::string frameworkDir = *i;
  1122. frameworkDir += "/../";
  1123. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1124. if(emitted.insert(frameworkDir).second)
  1125. {
  1126. fdirs += this->XCodeEscapePath(frameworkDir.c_str());
  1127. fdirs += " ";
  1128. }
  1129. }
  1130. else
  1131. {
  1132. std::string incpath =
  1133. this->XCodeEscapePath(i->c_str());
  1134. dirs += incpath + " ";
  1135. }
  1136. }
  1137. std::vector<std::string>& frameworks = target.GetFrameworks();
  1138. if(frameworks.size())
  1139. {
  1140. for(std::vector<std::string>::iterator fmIt = frameworks.begin();
  1141. fmIt != frameworks.end(); ++fmIt)
  1142. {
  1143. if(emitted.insert(*fmIt).second)
  1144. {
  1145. fdirs += this->XCodeEscapePath(fmIt->c_str());
  1146. fdirs += " ";
  1147. }
  1148. }
  1149. }
  1150. if(fdirs.size())
  1151. {
  1152. buildSettings->AddAttribute("FRAMEWORK_SEARCH_PATHS",
  1153. this->CreateString(fdirs.c_str()));
  1154. }
  1155. if(dirs.size())
  1156. {
  1157. buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
  1158. this->CreateString(dirs.c_str()));
  1159. }
  1160. std::string oflagc = this->ExtractFlag("-O", cflags);
  1161. char optLevel[2];
  1162. optLevel[0] = '0';
  1163. optLevel[1] = 0;
  1164. if(oflagc.size() == 3)
  1165. {
  1166. optLevel[0] = oflagc[2];
  1167. }
  1168. if(oflagc.size() == 2)
  1169. {
  1170. optLevel[0] = '1';
  1171. }
  1172. std::string oflag = this->ExtractFlag("-O", flags);
  1173. if(oflag.size() == 3)
  1174. {
  1175. optLevel[0] = oflag[2];
  1176. }
  1177. if(oflag.size() == 2)
  1178. {
  1179. optLevel[0] = '1';
  1180. }
  1181. std::string gflagc = this->ExtractFlag("-g", cflags);
  1182. std::string gflag = this->ExtractFlag("-g", flags);
  1183. const char* debugStr = "YES";
  1184. if(gflagc.size() ==0 && gflag.size() == 0)
  1185. {
  1186. debugStr = "NO";
  1187. }
  1188. buildSettings->AddAttribute("GCC_GENERATE_DEBUGGING_SYMBOLS",
  1189. this->CreateString(debugStr));
  1190. buildSettings->AddAttribute("GCC_OPTIMIZATION_LEVEL",
  1191. this->CreateString(optLevel));
  1192. buildSettings->AddAttribute("INSTALL_PATH",
  1193. this->CreateString(""));
  1194. buildSettings->AddAttribute("OPTIMIZATION_CFLAGS",
  1195. this->CreateString(oflagc.c_str()));
  1196. if(lang && strcmp(lang, "CXX") == 0)
  1197. {
  1198. flags += " ";
  1199. flags += defFlags;
  1200. buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
  1201. this->CreateString(flags.c_str()));
  1202. cflags += " ";
  1203. cflags += defFlags;
  1204. buildSettings->AddAttribute("OTHER_CFLAGS",
  1205. this->CreateString(cflags.c_str()));
  1206. }
  1207. else
  1208. {
  1209. flags += " ";
  1210. flags += defFlags;
  1211. buildSettings->AddAttribute("OTHER_CFLAGS",
  1212. this->CreateString(flags.c_str()));
  1213. }
  1214. buildSettings->AddAttribute("OTHER_LDFLAGS",
  1215. this->CreateString(extraLinkOptions.c_str()));
  1216. buildSettings->AddAttribute("OTHER_REZFLAGS",
  1217. this->CreateString(""));
  1218. buildSettings->AddAttribute("SECTORDER_FLAGS",
  1219. this->CreateString(""));
  1220. buildSettings->AddAttribute("USE_HEADERMAP",
  1221. this->CreateString("NO"));
  1222. buildSettings->AddAttribute("WARNING_CFLAGS",
  1223. this->CreateString(
  1224. "-Wmost -Wno-four-char-constants"
  1225. " -Wno-unknown-pragmas"));
  1226. std::string pname;
  1227. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  1228. {
  1229. pname = "lib";
  1230. }
  1231. pname += target.GetName();
  1232. if(target.GetType() == cmTarget::EXECUTABLE
  1233. && target.GetProperty("OUTPUT_NAME") )
  1234. {
  1235. pname = target.GetProperty("OUTPUT_NAME");
  1236. }
  1237. buildSettings->AddAttribute("PRODUCT_NAME",
  1238. this->CreateString(pname.c_str()));
  1239. }
  1240. //----------------------------------------------------------------------------
  1241. cmXCodeObject*
  1242. cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
  1243. {
  1244. cmXCodeObject* shellBuildPhase =
  1245. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  1246. shellBuildPhase->AddAttribute("buildActionMask",
  1247. this->CreateString("2147483647"));
  1248. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1249. shellBuildPhase->AddAttribute("files", buildFiles);
  1250. cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1251. shellBuildPhase->AddAttribute("inputPaths", inputPaths);
  1252. cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1253. shellBuildPhase->AddAttribute("outputPaths", outputPaths);
  1254. shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1255. this->CreateString("0"));
  1256. shellBuildPhase->AddAttribute("shellPath",
  1257. this->CreateString("/bin/sh"));
  1258. shellBuildPhase->AddAttribute("shellScript",
  1259. this->CreateString(
  1260. "# shell script goes here\nexit 0"));
  1261. cmXCodeObject* target =
  1262. this->CreateObject(cmXCodeObject::PBXAggregateTarget);
  1263. target->SetComment(cmtarget.GetName());
  1264. cmXCodeObject* buildPhases =
  1265. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1266. this->CreateCustomCommands(buildPhases, 0, 0, 0, cmtarget);
  1267. target->AddAttribute("buildPhases", buildPhases);
  1268. cmXCodeObject* buildSettings =
  1269. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1270. std::string fileTypeString;
  1271. std::string productTypeString;
  1272. std::string productName;
  1273. this->CreateBuildSettings(cmtarget,
  1274. buildSettings, fileTypeString,
  1275. productTypeString, productName, 0);
  1276. if(m_XcodeVersion > 20)
  1277. {
  1278. this->AddConfigurations(target, cmtarget);
  1279. }
  1280. target->AddAttribute("buildSettings", buildSettings);
  1281. cmXCodeObject* dependencies = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1282. target->AddAttribute("dependencies", dependencies);
  1283. target->AddAttribute("name", this->CreateString(productName.c_str()));
  1284. target->AddAttribute("productName",this->CreateString(productName.c_str()));
  1285. target->SetcmTarget(&cmtarget);
  1286. return target;
  1287. }
  1288. //----------------------------------------------------------------------------
  1289. void cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
  1290. cmTarget& cmtarget)
  1291. {
  1292. std::string configTypes = m_CurrentMakefile->GetRequiredDefinition("CMAKE_CONFIGURATION_TYPES");
  1293. std::vector<std::string> configVectorIn;
  1294. std::vector<std::string> configVector;
  1295. configVectorIn.push_back(configTypes);
  1296. cmSystemTools::ExpandList(configVectorIn, configVector);
  1297. cmXCodeObject* configlist = this->CreateObject(cmXCodeObject::XCConfigurationList);
  1298. cmXCodeObject* buildConfigurations =
  1299. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1300. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  1301. std::string comment = "Build configuration list for ";
  1302. comment += cmXCodeObject::PBXTypeNames[target->GetIsA()];
  1303. comment += " \"";
  1304. comment += cmtarget.GetName();
  1305. comment += "\"";
  1306. configlist->SetComment(comment.c_str());
  1307. target->AddAttribute("buildConfigurationList",
  1308. this->CreateObjectReference(configlist));
  1309. for(unsigned int i = 0; i < configVector.size(); ++i)
  1310. {
  1311. cmXCodeObject* config = this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  1312. buildConfigurations->AddObject(config);
  1313. cmXCodeObject* buildSettings =
  1314. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1315. std::string fileTypeString;
  1316. std::string productTypeString;
  1317. std::string productName;
  1318. std::string buildtype = cmSystemTools::UpperCase(configVector[i]);
  1319. this->CreateBuildSettings(cmtarget,
  1320. buildSettings, fileTypeString,
  1321. productTypeString, productName, buildtype.c_str());
  1322. config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
  1323. config->SetComment(configVector[i].c_str());
  1324. config->AddAttribute("buildSettings", buildSettings);
  1325. }
  1326. if(configVector.size())
  1327. {
  1328. configlist->AddAttribute("defaultConfigurationName",
  1329. this->CreateString(configVector[0].c_str()));
  1330. configlist->AddAttribute("defaultConfigurationIsVisible", this->CreateString("0"));
  1331. }
  1332. }
  1333. //----------------------------------------------------------------------------
  1334. cmXCodeObject*
  1335. cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
  1336. cmXCodeObject* buildPhases)
  1337. {
  1338. cmXCodeObject* target =
  1339. this->CreateObject(cmXCodeObject::PBXNativeTarget);
  1340. target->AddAttribute("buildPhases", buildPhases);
  1341. cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1342. target->AddAttribute("buildRules", buildRules);
  1343. cmXCodeObject* buildSettings =
  1344. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1345. std::string fileTypeString;
  1346. std::string productTypeString;
  1347. std::string productName;
  1348. if(m_XcodeVersion > 20)
  1349. {
  1350. this->AddConfigurations(target, cmtarget);
  1351. }
  1352. this->CreateBuildSettings(cmtarget,
  1353. buildSettings, fileTypeString,
  1354. productTypeString, productName, 0);
  1355. target->AddAttribute("buildSettings", buildSettings);
  1356. cmXCodeObject* dependencies = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1357. target->AddAttribute("dependencies", dependencies);
  1358. target->AddAttribute("name", this->CreateString(productName.c_str()));
  1359. target->AddAttribute("productName",this->CreateString(productName.c_str()));
  1360. cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  1361. fileRef->AddAttribute("explicitFileType",
  1362. this->CreateString(fileTypeString.c_str()));
  1363. fileRef->AddAttribute("path", this->CreateString(productName.c_str()));
  1364. fileRef->AddAttribute("refType", this->CreateString("0"));
  1365. fileRef->AddAttribute("sourceTree",
  1366. this->CreateString("BUILT_PRODUCTS_DIR"));
  1367. fileRef->SetComment(cmtarget.GetName());
  1368. target->AddAttribute("productReference",
  1369. this->CreateObjectReference(fileRef));
  1370. target->AddAttribute("productType",
  1371. this->CreateString(productTypeString.c_str()));
  1372. target->SetcmTarget(&cmtarget);
  1373. return target;
  1374. }
  1375. //----------------------------------------------------------------------------
  1376. cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
  1377. {
  1378. if(!t)
  1379. {
  1380. return 0;
  1381. }
  1382. for(std::vector<cmXCodeObject*>::iterator i = m_XCodeObjects.begin();
  1383. i != m_XCodeObjects.end(); ++i)
  1384. {
  1385. cmXCodeObject* o = *i;
  1386. if(o->GetcmTarget() == t)
  1387. {
  1388. return o;
  1389. }
  1390. }
  1391. return 0;
  1392. }
  1393. //----------------------------------------------------------------------------
  1394. void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
  1395. cmXCodeObject* dependTarget)
  1396. {
  1397. // make sure a target does not depend on itself
  1398. if(target == dependTarget)
  1399. {
  1400. return;
  1401. }
  1402. // now avoid circular references if dependTarget already
  1403. // depends on target then skip it. Circular references crashes
  1404. // xcode
  1405. cmXCodeObject* dependTargetDepends = dependTarget->GetObject("dependencies");
  1406. if(dependTargetDepends)
  1407. {
  1408. if(dependTargetDepends->HasObject(target->GetPBXTargetDependency()))
  1409. {
  1410. return;
  1411. }
  1412. }
  1413. cmXCodeObject* targetdep = dependTarget->GetPBXTargetDependency();
  1414. if(!targetdep)
  1415. {
  1416. cmXCodeObject* container =
  1417. this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
  1418. container->SetComment("PBXContainerItemProxy");
  1419. container->AddAttribute("containerPortal",
  1420. this->CreateObjectReference(m_RootObject));
  1421. container->AddAttribute("proxyType", this->CreateString("1"));
  1422. container->AddAttribute("remoteGlobalIDString",
  1423. this->CreateObjectReference(dependTarget));
  1424. container->AddAttribute("remoteInfo",
  1425. this->CreateString(
  1426. dependTarget->GetcmTarget()->GetName()));
  1427. targetdep =
  1428. this->CreateObject(cmXCodeObject::PBXTargetDependency);
  1429. targetdep->SetComment("PBXTargetDependency");
  1430. targetdep->AddAttribute("target",
  1431. this->CreateObjectReference(dependTarget));
  1432. targetdep->AddAttribute("targetProxy",
  1433. this->CreateObjectReference(container));
  1434. dependTarget->SetPBXTargetDependency(targetdep);
  1435. }
  1436. cmXCodeObject* depends = target->GetObject("dependencies");
  1437. if(!depends)
  1438. {
  1439. cmSystemTools::
  1440. Error("target does not have dependencies attribute error..");
  1441. }
  1442. else
  1443. {
  1444. depends->AddUniqueObject(targetdep);
  1445. }
  1446. }
  1447. //----------------------------------------------------------------------------
  1448. void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings,
  1449. const char* attribute,
  1450. const char* value)
  1451. {
  1452. if(settings)
  1453. {
  1454. cmXCodeObject* attr = settings->GetObject(attribute);
  1455. if(!attr)
  1456. {
  1457. settings->AddAttribute(attribute, this->CreateString(value));
  1458. }
  1459. else
  1460. {
  1461. std::string oldValue = attr->GetString();
  1462. cmSystemTools::ReplaceString(oldValue, "\"", "");
  1463. oldValue += " ";
  1464. oldValue += value;
  1465. attr->SetString(oldValue.c_str());
  1466. }
  1467. }
  1468. }
  1469. //----------------------------------------------------------------------------
  1470. void cmGlobalXCodeGenerator::AppendBuildSettingAttribute(cmXCodeObject* target,
  1471. const char* attribute,
  1472. const char* value)
  1473. {
  1474. if(m_XcodeVersion < 21)
  1475. {
  1476. this->AppendOrAddBuildSetting(target->GetObject("buildSettings"),
  1477. attribute, value);
  1478. }
  1479. else
  1480. {
  1481. cmXCodeObject* configurationList = target->GetObject("buildConfigurationList")->GetObject();
  1482. cmXCodeObject* buildConfigs = configurationList->GetObject("buildConfigurations");
  1483. std::vector<cmXCodeObject*> list = buildConfigs->GetObjectList();
  1484. // each configuration and the target itself has a buildSettings in it
  1485. list.push_back(target);
  1486. for(std::vector<cmXCodeObject*>::iterator i = list.begin(); i != list.end(); ++i)
  1487. {
  1488. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  1489. this->AppendOrAddBuildSetting(settings, attribute, value);
  1490. }
  1491. }
  1492. }
  1493. //----------------------------------------------------------------------------
  1494. void cmGlobalXCodeGenerator::AddLinkLibrary(cmXCodeObject* target,
  1495. const char* library,
  1496. cmTarget* dtarget)
  1497. {
  1498. if(dtarget)
  1499. {
  1500. target->AddDependLibrary(this->GetTargetFullPath(dtarget).c_str());
  1501. }
  1502. // if the library is not a full path then add it with a -l flag
  1503. // to the settings of the target
  1504. cmsys::RegularExpression reg("^([ \t]*\\-[lLWRBF])|([ \t]*\\-framework)|(\\${)|([ \t]*\\-pthread)|([ \t]*`)");
  1505. // if the library is not already in the form required by the compiler
  1506. // add a -l infront of the name
  1507. std::string link;
  1508. if(!reg.find(library))
  1509. {
  1510. link += "-l";
  1511. }
  1512. link += library;
  1513. this->AppendBuildSettingAttribute(target, "OTHER_LDFLAGS", link.c_str());
  1514. }
  1515. //----------------------------------------------------------------------------
  1516. std::string cmGlobalXCodeGenerator::GetTargetFullPath(cmTarget* target)
  1517. {
  1518. std::string libPath;
  1519. cmXCodeObject* xtarget = this->FindXCodeTarget(target);
  1520. cmXCodeObject* bset = xtarget->GetObject("buildSettings");
  1521. cmXCodeObject* spath = bset->GetObject("SYMROOT");
  1522. if(m_XcodeVersion > 15)
  1523. {
  1524. libPath += "$(CONFIGURATION)/";
  1525. }
  1526. libPath = spath->GetString();
  1527. libPath = libPath.substr(1, libPath.size()-2);
  1528. if(target->GetType() == cmTarget::STATIC_LIBRARY)
  1529. {
  1530. libPath += "lib";
  1531. libPath += target->GetName();
  1532. libPath += ".a";
  1533. }
  1534. else if(target->GetType() == cmTarget::SHARED_LIBRARY)
  1535. {
  1536. libPath += "lib";
  1537. libPath += target->GetName();
  1538. libPath += ".dylib";
  1539. }
  1540. else
  1541. {
  1542. libPath += target->GetName();
  1543. }
  1544. return libPath;
  1545. }
  1546. //----------------------------------------------------------------------------
  1547. void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
  1548. {
  1549. cmTarget* cmtarget = target->GetcmTarget();
  1550. if(!cmtarget)
  1551. {
  1552. cmSystemTools::Error("Error no target on xobject\n");
  1553. return;
  1554. }
  1555. // compute the correct order for link libraries
  1556. cmOrderLinkDirectories orderLibs;
  1557. std::string ext =
  1558. m_CurrentMakefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1559. if(ext.size())
  1560. {
  1561. orderLibs.AddLinkExtension(ext.c_str());
  1562. }
  1563. ext =
  1564. m_CurrentMakefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
  1565. if(ext.size())
  1566. {
  1567. orderLibs.SetLinkPrefix(ext.c_str());
  1568. }
  1569. ext =
  1570. m_CurrentMakefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1571. if(ext.size())
  1572. {
  1573. orderLibs.AddLinkExtension(ext.c_str());
  1574. }
  1575. ext =
  1576. m_CurrentMakefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_SUFFIX");
  1577. if(ext.size())
  1578. {
  1579. orderLibs.AddLinkExtension(ext.c_str());
  1580. }
  1581. const char* targetLibrary = cmtarget->GetName();
  1582. if(cmtarget->GetType() == cmTarget::EXECUTABLE)
  1583. {
  1584. targetLibrary = 0;
  1585. }
  1586. orderLibs.SetLinkInformation(*cmtarget, cmTarget::GENERAL, targetLibrary);
  1587. orderLibs.DetermineLibraryPathOrder();
  1588. std::vector<cmStdString> libdirs;
  1589. std::vector<cmStdString> linkItems;
  1590. orderLibs.GetLinkerInformation(libdirs, linkItems);
  1591. std::string linkDirs;
  1592. // add the library search paths
  1593. for(std::vector<cmStdString>::const_iterator libDir = libdirs.begin();
  1594. libDir != libdirs.end(); ++libDir)
  1595. {
  1596. if(libDir->size() && *libDir != "/usr/lib")
  1597. {
  1598. if(m_XcodeVersion > 15)
  1599. {
  1600. // now add the same one but append $(CONFIGURATION) to it:
  1601. linkDirs += " ";
  1602. linkDirs += this->XCodeEscapePath(libDir->c_str());
  1603. linkDirs += "/$(CONFIGURATION)";
  1604. }
  1605. linkDirs += " ";
  1606. linkDirs += this->XCodeEscapePath(libDir->c_str());
  1607. }
  1608. }
  1609. this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS", linkDirs.c_str());
  1610. // now add the link libraries
  1611. for(std::vector<cmStdString>::iterator lib = linkItems.begin();
  1612. lib != linkItems.end(); ++lib)
  1613. {
  1614. cmTarget* t = this->FindTarget(m_CurrentProject.c_str(),
  1615. lib->c_str());
  1616. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  1617. if(dptarget)
  1618. {
  1619. this->AddDependTarget(target, dptarget);
  1620. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  1621. {
  1622. this->AddLinkLibrary(target, t->GetName(), t);
  1623. }
  1624. }
  1625. else
  1626. {
  1627. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  1628. {
  1629. this->AddLinkLibrary(target, lib->c_str());
  1630. }
  1631. }
  1632. }
  1633. // write utility dependencies.
  1634. for(std::set<cmStdString>::const_iterator i
  1635. = cmtarget->GetUtilities().begin();
  1636. i != cmtarget->GetUtilities().end(); ++i)
  1637. {
  1638. cmTarget* t = this->FindTarget(m_CurrentProject.c_str(),
  1639. i->c_str());
  1640. // if the target is in this project then make target depend
  1641. // on it. It may not be in this project if this is a sub
  1642. // project from the top.
  1643. if(t)
  1644. {
  1645. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  1646. if(dptarget)
  1647. {
  1648. this->AddDependTarget(target, dptarget);
  1649. }
  1650. else
  1651. {
  1652. std::string m = "Error Utility: ";
  1653. m += i->c_str();
  1654. m += "\n";
  1655. m += "cmtarget ";
  1656. if(t)
  1657. {
  1658. m += t->GetName();
  1659. }
  1660. m += "\n";
  1661. m += "Is on the target ";
  1662. m += cmtarget->GetName();
  1663. m += "\n";
  1664. m += "But it has no xcode target created yet??\n";
  1665. m += "Current project is ";
  1666. m += m_CurrentProject.c_str();
  1667. cmSystemTools::Error(m.c_str());
  1668. }
  1669. }
  1670. }
  1671. std::vector<cmStdString> fullPathLibs;
  1672. orderLibs.GetFullPathLibraries(fullPathLibs);
  1673. for(std::vector<cmStdString>::iterator i = fullPathLibs.begin();
  1674. i != fullPathLibs.end(); ++i)
  1675. {
  1676. target->AddDependLibrary(i->c_str());
  1677. }
  1678. }
  1679. //----------------------------------------------------------------------------
  1680. void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
  1681. std::vector<cmLocalGenerator*>&
  1682. generators)
  1683. {
  1684. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  1685. i != generators.end(); ++i)
  1686. {
  1687. if(this->IsExcluded(root, *i))
  1688. {
  1689. continue;
  1690. }
  1691. cmMakefile* mf = (*i)->GetMakefile();
  1692. std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
  1693. cmTargets &tgts = mf->GetTargets();
  1694. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1695. {
  1696. cmTarget& cmtarget = l->second;
  1697. std::vector<cmSourceFile*> & classes = cmtarget.GetSourceFiles();
  1698. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  1699. s != classes.end(); s++)
  1700. {
  1701. cmSourceFile* sf = *s;
  1702. // Add the file to the list of sources.
  1703. std::string const& source = sf->GetFullPath();
  1704. cmSourceGroup& sourceGroup =
  1705. mf->FindSourceGroup(source.c_str(), sourceGroups);
  1706. cmXCodeObject* pbxgroup = this->CreateOrGetPBXGroup(cmtarget, &sourceGroup);
  1707. m_GroupMap[sf] = pbxgroup;
  1708. }
  1709. }
  1710. }
  1711. }
  1712. //----------------------------------------------------------------------------
  1713. cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup(cmTarget& cmtarget,
  1714. cmSourceGroup* sg)
  1715. {
  1716. cmStdString s = cmtarget.GetName();
  1717. s += "/";
  1718. s += sg->GetName();
  1719. std::map<cmStdString, cmXCodeObject* >::iterator i = m_GroupNameMap.find(s);
  1720. if(i != m_GroupNameMap.end())
  1721. {
  1722. return i->second;
  1723. }
  1724. i = m_TargetGroup.find(cmtarget.GetName());
  1725. cmXCodeObject* tgroup = 0;
  1726. if(i != m_TargetGroup.end())
  1727. {
  1728. tgroup = i->second;
  1729. }
  1730. else
  1731. {
  1732. tgroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1733. m_TargetGroup[cmtarget.GetName()] = tgroup;
  1734. cmXCodeObject* tgroupChildren =
  1735. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1736. tgroup->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  1737. tgroup->AddAttribute("children", tgroupChildren);
  1738. if(m_XcodeVersion == 15)
  1739. {
  1740. tgroup->AddAttribute("refType", this->CreateString("4"));
  1741. }
  1742. tgroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1743. m_SourcesGroupChildren->AddObject(tgroup);
  1744. }
  1745. cmXCodeObject* tgroupChildren = tgroup->GetObject("children");
  1746. cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
  1747. cmXCodeObject* groupChildren =
  1748. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1749. group->AddAttribute("name", this->CreateString(sg->GetName()));
  1750. group->AddAttribute("children", groupChildren);
  1751. if(m_XcodeVersion == 15)
  1752. {
  1753. group->AddAttribute("refType", this->CreateString("4"));
  1754. }
  1755. group->AddAttribute("sourceTree", this->CreateString("<group>"));
  1756. tgroupChildren->AddObject(group);
  1757. m_GroupNameMap[s] = group;
  1758. return group;
  1759. }
  1760. //----------------------------------------------------------------------------
  1761. void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
  1762. std::vector<cmLocalGenerator*>&
  1763. generators
  1764. )
  1765. {
  1766. this->ClearXCodeObjects();
  1767. m_RootObject = 0;
  1768. m_SourcesGroupChildren = 0;
  1769. m_MainGroupChildren = 0;
  1770. cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1771. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  1772. cmXCodeObject* developBuildStyle =
  1773. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  1774. if(m_XcodeVersion == 15)
  1775. {
  1776. developBuildStyle->AddAttribute("name", this->CreateString("Development"));
  1777. }
  1778. else
  1779. {
  1780. developBuildStyle->AddAttribute("name", this->CreateString("Debug"));
  1781. developBuildStyle->SetComment("Debug");
  1782. }
  1783. developBuildStyle->AddAttribute("buildSettings", group);
  1784. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1785. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("YES"));
  1786. cmXCodeObject* deployBuildStyle =
  1787. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  1788. if(m_XcodeVersion == 15)
  1789. {
  1790. deployBuildStyle->AddAttribute("name", this->CreateString("Deployment"));
  1791. }
  1792. else
  1793. {
  1794. deployBuildStyle->AddAttribute("name", this->CreateString("Release"));
  1795. deployBuildStyle->SetComment("Release");
  1796. }
  1797. deployBuildStyle->AddAttribute("buildSettings", group);
  1798. cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1799. listObjs->AddObject(developBuildStyle);
  1800. listObjs->AddObject(deployBuildStyle);
  1801. cmXCodeObject* mainGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1802. m_MainGroupChildren =
  1803. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1804. mainGroup->AddAttribute("children", m_MainGroupChildren);
  1805. if(m_XcodeVersion == 15)
  1806. {
  1807. mainGroup->AddAttribute("refType", this->CreateString("4"));
  1808. }
  1809. mainGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1810. cmXCodeObject* sourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1811. m_SourcesGroupChildren =
  1812. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1813. sourcesGroup->AddAttribute("name", this->CreateString("Sources"));
  1814. sourcesGroup->AddAttribute("children", m_SourcesGroupChildren);
  1815. if(m_XcodeVersion == 15)
  1816. {
  1817. sourcesGroup->AddAttribute("refType", this->CreateString("4"));
  1818. }
  1819. sourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1820. m_MainGroupChildren->AddObject(sourcesGroup);
  1821. // now create the cmake groups
  1822. this->CreateGroups(root, generators);
  1823. cmXCodeObject* productGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  1824. productGroup->AddAttribute("name", this->CreateString("Products"));
  1825. if(m_XcodeVersion == 15)
  1826. {
  1827. productGroup->AddAttribute("refType", this->CreateString("4"));
  1828. }
  1829. productGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  1830. cmXCodeObject* productGroupChildren =
  1831. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1832. productGroup->AddAttribute("children", productGroupChildren);
  1833. m_MainGroupChildren->AddObject(productGroup);
  1834. m_RootObject = this->CreateObject(cmXCodeObject::PBXProject);
  1835. m_RootObject->SetComment("Project object");
  1836. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1837. m_RootObject->AddAttribute("mainGroup",
  1838. this->CreateObjectReference(mainGroup));
  1839. m_RootObject->AddAttribute("buildSettings", group);
  1840. m_RootObject->AddAttribute("buildStyles", listObjs);
  1841. m_RootObject->AddAttribute("hasScannedForEncodings",
  1842. this->CreateString("0"));
  1843. cmXCodeObject* configlist = this->CreateObject(cmXCodeObject::XCConfigurationList);
  1844. cmXCodeObject* configDebug = this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  1845. cmXCodeObject* configRelease = this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  1846. cmXCodeObject* buildConfigurations =
  1847. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1848. buildConfigurations->AddObject(configDebug);
  1849. buildConfigurations->AddObject(configRelease);
  1850. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  1851. std::string comment = "Build configuration list for PBXProject ";
  1852. comment += " \"";
  1853. comment += m_CurrentProject;
  1854. comment += "\"";
  1855. configlist->SetComment(comment.c_str());
  1856. configlist->AddAttribute("defaultConfigurationIsVisible", this->CreateString("0"));
  1857. configlist->AddAttribute("defaultConfigurationName", this->CreateString("Debug"));
  1858. cmXCodeObject* buildSettings =
  1859. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1860. configDebug->AddAttribute("name", this->CreateString("Debug"));
  1861. configDebug->AddAttribute("buildSettings", buildSettings);
  1862. configRelease->AddAttribute("name", this->CreateString("Release"));
  1863. configRelease->AddAttribute("buildSettings", buildSettings);
  1864. m_RootObject->AddAttribute("buildConfigurationList",
  1865. this->CreateObjectReference(configlist));
  1866. std::vector<cmXCodeObject*> targets;
  1867. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  1868. i != generators.end(); ++i)
  1869. {
  1870. if(!this->IsExcluded(root, *i))
  1871. {
  1872. this->CreateXCodeTargets(*i, targets);
  1873. }
  1874. }
  1875. // loop over all targets and add link and depend info
  1876. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1877. i != targets.end(); ++i)
  1878. {
  1879. cmXCodeObject* t = *i;
  1880. this->AddDependAndLinkInformation(t);
  1881. }
  1882. // now create xcode depend hack makefile
  1883. this->CreateXCodeDependHackTarget(targets);
  1884. // now add all targets to the root object
  1885. cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1886. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1887. i != targets.end(); ++i)
  1888. {
  1889. cmXCodeObject* t = *i;
  1890. allTargets->AddObject(t);
  1891. cmXCodeObject* productRef = t->GetObject("productReference");
  1892. if(productRef)
  1893. {
  1894. productGroupChildren->AddObject(productRef->GetObject());
  1895. }
  1896. }
  1897. m_RootObject->AddAttribute("targets", allTargets);
  1898. }
  1899. //----------------------------------------------------------------------------
  1900. void
  1901. cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
  1902. std::vector<cmXCodeObject*>& targets)
  1903. {
  1904. cmGeneratedFileStream makefileStream(m_CurrentXCodeHackMakefile.c_str());
  1905. if(!makefileStream)
  1906. {
  1907. cmSystemTools::Error("Could not create",
  1908. m_CurrentXCodeHackMakefile.c_str());
  1909. return;
  1910. }
  1911. makefileStream.SetCopyIfDifferent(true);
  1912. // one more pass for external depend information not handled
  1913. // correctly by xcode
  1914. makefileStream << "# DO NOT EDIT\n";
  1915. makefileStream << "# This makefile makes sure all linkable targets are \n";
  1916. makefileStream
  1917. << "# up-to-date with anything they link to,avoiding a bug in XCode 1.5\n";
  1918. makefileStream << "all: ";
  1919. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1920. i != targets.end(); ++i)
  1921. {
  1922. cmXCodeObject* target = *i;
  1923. cmTarget* t =target->GetcmTarget();
  1924. if(t->GetType() == cmTarget::EXECUTABLE ||
  1925. t->GetType() == cmTarget::SHARED_LIBRARY ||
  1926. t->GetType() == cmTarget::MODULE_LIBRARY)
  1927. {
  1928. makefileStream << "\\\n\t"
  1929. << this->AddConfigDir(this->
  1930. ConvertToRelativeForMake(this->GetTargetFullPath(target->GetcmTarget()).c_str()).c_str());
  1931. }
  1932. }
  1933. makefileStream << "\n\n";
  1934. makefileStream
  1935. << "# For each target create a dummy rule "
  1936. "so the target does not have to exist\n";
  1937. std::set<cmStdString> emitted;
  1938. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1939. i != targets.end(); ++i)
  1940. {
  1941. cmXCodeObject* target = *i;
  1942. std::vector<cmStdString> const& deplibs = target->GetDependLibraries();
  1943. for(std::vector<cmStdString>::const_iterator d = deplibs.begin();
  1944. d != deplibs.end(); ++d)
  1945. {
  1946. if(emitted.insert(*d).second)
  1947. {
  1948. makefileStream <<
  1949. this->AddConfigDir(this->ConvertToRelativeForMake(d->c_str()).c_str())
  1950. << ":\n";
  1951. }
  1952. }
  1953. }
  1954. makefileStream << "\n\n";
  1955. makefileStream <<
  1956. "# Each linkable target depends on everything it links to.\n";
  1957. makefileStream
  1958. << "#And the target is removed if it is older than what it linkes to\n";
  1959. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  1960. i != targets.end(); ++i)
  1961. {
  1962. cmXCodeObject* target = *i;
  1963. cmTarget* t =target->GetcmTarget();
  1964. if(t->GetType() == cmTarget::EXECUTABLE ||
  1965. t->GetType() == cmTarget::SHARED_LIBRARY ||
  1966. t->GetType() == cmTarget::MODULE_LIBRARY)
  1967. {
  1968. std::vector<cmStdString> const& deplibs = target->GetDependLibraries();
  1969. std::string tfull = this->GetTargetFullPath(target->GetcmTarget());
  1970. makefileStream << this->AddConfigDir(
  1971. this->ConvertToRelativeForMake(tfull.c_str()).c_str()) << ": ";
  1972. for(std::vector<cmStdString>::const_iterator d = deplibs.begin();
  1973. d != deplibs.end(); ++d)
  1974. {
  1975. makefileStream << "\\\n\t" <<
  1976. this->AddConfigDir(
  1977. this->ConvertToRelativeForMake(d->c_str()).c_str());
  1978. }
  1979. makefileStream << "\n";
  1980. makefileStream << "\t/bin/rm -f "
  1981. <<
  1982. this->AddConfigDir(
  1983. this->ConvertToRelativeForMake(tfull.c_str()).c_str())
  1984. << "\n";
  1985. makefileStream << "\n\n";
  1986. }
  1987. }
  1988. }
  1989. //----------------------------------------------------------------------------
  1990. std::string
  1991. cmGlobalXCodeGenerator::AddConfigDir(const char* d)
  1992. {
  1993. if(m_XcodeVersion == 15)
  1994. {
  1995. return std::string(d);
  1996. }
  1997. std::string dir = d;
  1998. if(cmSystemTools::FileExists(d))
  1999. {
  2000. return dir;
  2001. }
  2002. std::string::size_type pos = dir.rfind("/");
  2003. if(pos == dir.npos)
  2004. {
  2005. return dir;
  2006. }
  2007. std::string ret = dir.substr(0, pos);
  2008. ret += "/${CONFIGURATION}";
  2009. ret += dir.substr(pos);
  2010. return ret;
  2011. }
  2012. //----------------------------------------------------------------------------
  2013. void
  2014. cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
  2015. std::vector<cmLocalGenerator*>&
  2016. generators)
  2017. {
  2018. if(generators.size() == 0)
  2019. {
  2020. return;
  2021. }
  2022. this->CreateXCodeObjects(root,
  2023. generators);
  2024. std::string xcodeDir = root->GetMakefile()->GetStartOutputDirectory();
  2025. xcodeDir += "/";
  2026. xcodeDir += root->GetMakefile()->GetProjectName();
  2027. xcodeDir += ".xcode";
  2028. if(m_XcodeVersion > 20)
  2029. {
  2030. xcodeDir += "proj";
  2031. }
  2032. cmSystemTools::MakeDirectory(xcodeDir.c_str());
  2033. std::string xcodeProjFile = xcodeDir + "/project.pbxproj";
  2034. cmGeneratedFileStream fout(xcodeProjFile.c_str());
  2035. fout.SetCopyIfDifferent(true);
  2036. if(!fout)
  2037. {
  2038. return;
  2039. }
  2040. this->WriteXCodePBXProj(fout, root, generators);
  2041. this->ClearXCodeObjects();
  2042. }
  2043. //----------------------------------------------------------------------------
  2044. void
  2045. cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
  2046. cmLocalGenerator* ,
  2047. std::vector<cmLocalGenerator*>& )
  2048. {
  2049. fout << "// !$*UTF8*$!\n";
  2050. fout << "{\n";
  2051. cmXCodeObject::Indent(1, fout);
  2052. fout << "archiveVersion = 1;\n";
  2053. cmXCodeObject::Indent(1, fout);
  2054. fout << "classes = {\n";
  2055. cmXCodeObject::Indent(1, fout);
  2056. fout << "};\n";
  2057. cmXCodeObject::Indent(1, fout);
  2058. fout << "objectVersion = 39;\n";
  2059. cmXCodeObject::PrintList(m_XCodeObjects, fout);
  2060. cmXCodeObject::Indent(1, fout);
  2061. fout << "rootObject = " << m_RootObject->GetId() << ";\n";
  2062. fout << "}\n";
  2063. }
  2064. //----------------------------------------------------------------------------
  2065. void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry)
  2066. const
  2067. {
  2068. entry.name = this->GetName();
  2069. entry.brief = "Generate XCode project files.";
  2070. entry.full = "";
  2071. }
  2072. //----------------------------------------------------------------------------
  2073. std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(const char* p)
  2074. {
  2075. if ( !m_CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  2076. {
  2077. return cmSystemTools::ConvertToOutputPath(p);
  2078. }
  2079. else
  2080. {
  2081. std::string ret =
  2082. this->ConvertToRelativePath(m_CurrentOutputDirectoryComponents, p);
  2083. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  2084. }
  2085. }
  2086. //----------------------------------------------------------------------------
  2087. std::string cmGlobalXCodeGenerator::ConvertToRelativeForXCode(const char* p)
  2088. {
  2089. if ( !m_CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  2090. {
  2091. return cmSystemTools::ConvertToOutputPath(p);
  2092. }
  2093. else
  2094. {
  2095. std::string ret =
  2096. this->ConvertToRelativePath(m_ProjectOutputDirectoryComponents, p);
  2097. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  2098. }
  2099. }
  2100. std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p)
  2101. {
  2102. std::string ret = p;
  2103. if(ret.find(' ') != ret.npos)
  2104. {
  2105. std::string t = ret;
  2106. ret = "\\\"";
  2107. ret += t;
  2108. ret += "\\\"";
  2109. }
  2110. return ret;
  2111. }