cmGlobalXCodeGenerator.cxx 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmGlobalXCodeGenerator.h"
  11. #include "cmLocalXCodeGenerator.h"
  12. #include "cmMakefile.h"
  13. #include "cmXCodeObject.h"
  14. #include "cmXCode21Object.h"
  15. #include "cmake.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmComputeLinkInformation.h"
  18. #include "cmSourceFile.h"
  19. #include "cmCustomCommandGenerator.h"
  20. #include "cmGeneratorTarget.h"
  21. #include "cmGlobalGeneratorFactory.h"
  22. #include <cmsys/auto_ptr.hxx>
  23. //----------------------------------------------------------------------------
  24. #if defined(CMAKE_BUILD_WITH_CMAKE)
  25. #include "cmXMLParser.h"
  26. // parse the xml file storing the installed version of Xcode on
  27. // the machine
  28. class cmXcodeVersionParser : public cmXMLParser
  29. {
  30. public:
  31. cmXcodeVersionParser(): Version("1.5") {}
  32. void StartElement(const std::string&, const char**)
  33. {
  34. this->Data = "";
  35. }
  36. void EndElement(const std::string& name)
  37. {
  38. if(name == "key")
  39. {
  40. this->Key = this->Data;
  41. }
  42. else if(name == "string")
  43. {
  44. if(this->Key == "CFBundleShortVersionString")
  45. {
  46. this->Version = this->Data;
  47. }
  48. }
  49. }
  50. void CharacterDataHandler(const char* data, int length)
  51. {
  52. this->Data.append(data, length);
  53. }
  54. std::string Version;
  55. std::string Key;
  56. std::string Data;
  57. };
  58. #endif
  59. // Builds either an object list or a space-separated string from the
  60. // given inputs.
  61. class cmGlobalXCodeGenerator::BuildObjectListOrString
  62. {
  63. cmGlobalXCodeGenerator *Generator;
  64. cmXCodeObject *Group;
  65. bool Empty;
  66. std::string String;
  67. public:
  68. BuildObjectListOrString(cmGlobalXCodeGenerator *gen, bool buildObjectList)
  69. : Generator(gen), Group(0), Empty(true)
  70. {
  71. if (buildObjectList)
  72. {
  73. this->Group = this->Generator->CreateObject(cmXCodeObject::OBJECT_LIST);
  74. }
  75. }
  76. bool IsEmpty() const { return this->Empty; }
  77. void Add(const char *newString)
  78. {
  79. this->Empty = false;
  80. if (this->Group)
  81. {
  82. this->Group->AddObject(this->Generator->CreateString(newString));
  83. }
  84. else
  85. {
  86. this->String += newString;
  87. this->String += ' ';
  88. }
  89. }
  90. const std::string &GetString() const { return this->String; }
  91. cmXCodeObject *CreateList()
  92. {
  93. if (this->Group)
  94. {
  95. return this->Group;
  96. }
  97. else
  98. {
  99. return this->Generator->CreateString(this->String.c_str());
  100. }
  101. }
  102. };
  103. class cmGlobalXCodeGenerator::Factory : public cmGlobalGeneratorFactory
  104. {
  105. public:
  106. virtual cmGlobalGenerator* CreateGlobalGenerator(
  107. const std::string& name) const;
  108. virtual void GetDocumentation(cmDocumentationEntry& entry) const {
  109. cmGlobalXCodeGenerator::GetDocumentation(entry); }
  110. virtual void GetGenerators(std::vector<std::string>& names) const {
  111. names.push_back(cmGlobalXCodeGenerator::GetActualName()); }
  112. };
  113. //----------------------------------------------------------------------------
  114. cmGlobalXCodeGenerator::cmGlobalXCodeGenerator(std::string const& version)
  115. {
  116. this->VersionString = version;
  117. // Compute an integer form of the version number.
  118. unsigned int v[2] = {0,0};
  119. sscanf(this->VersionString.c_str(), "%u.%u", &v[0], &v[1]);
  120. this->XcodeVersion = 10*v[0] + v[1];
  121. this->FindMakeProgramFile = "CMakeFindXCode.cmake";
  122. this->RootObject = 0;
  123. this->MainGroupChildren = 0;
  124. this->SourcesGroupChildren = 0;
  125. this->ResourcesGroupChildren = 0;
  126. this->CurrentMakefile = 0;
  127. this->CurrentLocalGenerator = 0;
  128. }
  129. //----------------------------------------------------------------------------
  130. cmGlobalGeneratorFactory* cmGlobalXCodeGenerator::NewFactory()
  131. {
  132. return new Factory;
  133. }
  134. //----------------------------------------------------------------------------
  135. cmGlobalGenerator* cmGlobalXCodeGenerator::Factory
  136. ::CreateGlobalGenerator(const std::string& name) const
  137. {
  138. if (name != GetActualName())
  139. return 0;
  140. #if defined(CMAKE_BUILD_WITH_CMAKE)
  141. cmXcodeVersionParser parser;
  142. std::string versionFile;
  143. {
  144. std::string out;
  145. std::string::size_type pos;
  146. if(cmSystemTools::RunSingleCommand("xcode-select --print-path", &out, 0, 0,
  147. cmSystemTools::OUTPUT_NONE) &&
  148. (pos = out.find(".app/"), pos != out.npos))
  149. {
  150. versionFile = out.substr(0, pos+5)+"Contents/version.plist";
  151. }
  152. }
  153. if(!versionFile.empty() && cmSystemTools::FileExists(versionFile.c_str()))
  154. {
  155. parser.ParseFile(versionFile.c_str());
  156. }
  157. else if (cmSystemTools::FileExists(
  158. "/Applications/Xcode.app/Contents/version.plist"))
  159. {
  160. parser.ParseFile
  161. ("/Applications/Xcode.app/Contents/version.plist");
  162. }
  163. else
  164. {
  165. parser.ParseFile
  166. ("/Developer/Applications/Xcode.app/Contents/version.plist");
  167. }
  168. cmsys::auto_ptr<cmGlobalXCodeGenerator>
  169. gg(new cmGlobalXCodeGenerator(parser.Version));
  170. if (gg->XcodeVersion == 20)
  171. {
  172. cmSystemTools::Message("Xcode 2.0 not really supported by cmake, "
  173. "using Xcode 15 generator\n");
  174. gg->XcodeVersion = 15;
  175. }
  176. return gg.release();
  177. #else
  178. std::cerr << "CMake should be built with cmake to use Xcode, "
  179. "default to Xcode 1.5\n";
  180. return new cmGlobalXCodeGenerator;
  181. #endif
  182. }
  183. //----------------------------------------------------------------------------
  184. bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts)
  185. {
  186. if(this->XcodeVersion >= 30)
  187. {
  188. this->PlatformToolset = ts;
  189. return true;
  190. }
  191. else
  192. {
  193. return cmGlobalGenerator::SetGeneratorToolset(ts);
  194. }
  195. }
  196. //----------------------------------------------------------------------------
  197. void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
  198. lang,
  199. cmMakefile * mf, bool optional)
  200. {
  201. mf->AddDefinition("XCODE","1");
  202. mf->AddDefinition("XCODE_VERSION", this->VersionString.c_str());
  203. if(this->XcodeVersion == 15)
  204. {
  205. }
  206. else
  207. {
  208. if(!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  209. {
  210. mf->AddCacheDefinition(
  211. "CMAKE_CONFIGURATION_TYPES",
  212. "Debug;Release;MinSizeRel;RelWithDebInfo",
  213. "Semicolon separated list of supported configuration types, "
  214. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  215. "anything else will be ignored.",
  216. cmCacheManager::STRING);
  217. }
  218. }
  219. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  220. if(!this->PlatformToolset.empty())
  221. {
  222. mf->AddDefinition("CMAKE_XCODE_PLATFORM_TOOLSET",
  223. this->PlatformToolset.c_str());
  224. }
  225. this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
  226. const char* osxArch =
  227. mf->GetDefinition("CMAKE_OSX_ARCHITECTURES");
  228. const char* sysroot =
  229. mf->GetDefinition("CMAKE_OSX_SYSROOT");
  230. if(osxArch && sysroot)
  231. {
  232. this->Architectures.clear();
  233. cmSystemTools::ExpandListArgument(std::string(osxArch),
  234. this->Architectures);
  235. }
  236. }
  237. //----------------------------------------------------------------------------
  238. void
  239. cmGlobalXCodeGenerator::GenerateBuildCommand(
  240. std::vector<std::string>& makeCommand,
  241. const std::string& makeProgram,
  242. const std::string& projectName,
  243. const std::string& /*projectDir*/,
  244. const std::string& targetName,
  245. const std::string& config,
  246. bool /*fast*/,
  247. std::vector<std::string> const& makeOptions)
  248. {
  249. // now build the test
  250. makeCommand.push_back(
  251. this->SelectMakeProgram(makeProgram, "xcodebuild")
  252. );
  253. makeCommand.push_back("-project");
  254. std::string projectArg = projectName;
  255. projectArg += ".xcode";
  256. if(this->XcodeVersion > 20)
  257. {
  258. projectArg += "proj";
  259. }
  260. makeCommand.push_back(projectArg);
  261. bool clean = false;
  262. std::string realTarget = targetName;
  263. if ( realTarget == "clean" )
  264. {
  265. clean = true;
  266. realTarget = "ALL_BUILD";
  267. }
  268. if(clean)
  269. {
  270. makeCommand.push_back("clean");
  271. }
  272. else
  273. {
  274. makeCommand.push_back("build");
  275. }
  276. makeCommand.push_back("-target");
  277. if (!realTarget.empty())
  278. {
  279. makeCommand.push_back(realTarget);
  280. }
  281. else
  282. {
  283. makeCommand.push_back("ALL_BUILD");
  284. }
  285. if(this->XcodeVersion == 15)
  286. {
  287. makeCommand.push_back("-buildstyle");
  288. makeCommand.push_back("Development");
  289. }
  290. else
  291. {
  292. makeCommand.push_back("-configuration");
  293. makeCommand.push_back(!config.empty()?config:"Debug");
  294. }
  295. makeCommand.insert(makeCommand.end(),
  296. makeOptions.begin(), makeOptions.end());
  297. }
  298. //----------------------------------------------------------------------------
  299. ///! Create a local generator appropriate to this Global Generator
  300. cmLocalGenerator *cmGlobalXCodeGenerator::CreateLocalGenerator()
  301. {
  302. cmLocalGenerator *lg = new cmLocalXCodeGenerator;
  303. lg->SetGlobalGenerator(this);
  304. return lg;
  305. }
  306. //----------------------------------------------------------------------------
  307. void cmGlobalXCodeGenerator::Generate()
  308. {
  309. std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
  310. // make sure extra targets are added before calling
  311. // the parent generate which will call trace depends
  312. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  313. {
  314. cmLocalGenerator* root = it->second[0];
  315. this->SetGenerationRoot(root);
  316. // add ALL_BUILD, INSTALL, etc
  317. this->AddExtraTargets(root, it->second);
  318. }
  319. this->cmGlobalGenerator::Generate();
  320. if(cmSystemTools::GetErrorOccuredFlag())
  321. {
  322. return;
  323. }
  324. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  325. {
  326. cmLocalGenerator* root = it->second[0];
  327. this->SetGenerationRoot(root);
  328. // now create the project
  329. this->OutputXCodeProject(root, it->second);
  330. }
  331. }
  332. //----------------------------------------------------------------------------
  333. void cmGlobalXCodeGenerator::SetGenerationRoot(cmLocalGenerator* root)
  334. {
  335. this->CurrentProject = root->GetMakefile()->GetProjectName();
  336. this->SetCurrentLocalGenerator(root);
  337. cmSystemTools::SplitPath(this->CurrentMakefile->GetCurrentDirectory(),
  338. this->ProjectSourceDirectoryComponents);
  339. cmSystemTools::SplitPath(this->CurrentMakefile->GetCurrentOutputDirectory(),
  340. this->ProjectOutputDirectoryComponents);
  341. this->CurrentXCodeHackMakefile =
  342. root->GetMakefile()->GetCurrentOutputDirectory();
  343. this->CurrentXCodeHackMakefile += "/CMakeScripts";
  344. cmSystemTools::MakeDirectory(this->CurrentXCodeHackMakefile.c_str());
  345. this->CurrentXCodeHackMakefile += "/XCODE_DEPEND_HELPER.make";
  346. }
  347. //----------------------------------------------------------------------------
  348. std::string
  349. cmGlobalXCodeGenerator::PostBuildMakeTarget(std::string const& tName,
  350. std::string const& configName)
  351. {
  352. std::string target = tName;
  353. cmSystemTools::ReplaceString(target, " ", "_");
  354. std::string out = "PostBuild." + target;
  355. if(this->XcodeVersion > 20)
  356. {
  357. out += "." + configName;
  358. }
  359. return out;
  360. }
  361. //----------------------------------------------------------------------------
  362. #define CMAKE_CHECK_BUILD_SYSTEM_TARGET "ZERO_CHECK"
  363. //----------------------------------------------------------------------------
  364. void
  365. cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
  366. std::vector<cmLocalGenerator*>& gens)
  367. {
  368. cmMakefile* mf = root->GetMakefile();
  369. // Add ALL_BUILD
  370. const char* no_working_directory = 0;
  371. std::vector<std::string> no_depends;
  372. mf->AddUtilityCommand("ALL_BUILD", true, no_depends,
  373. no_working_directory,
  374. "echo", "Build all projects");
  375. cmTarget* allbuild = mf->FindTarget("ALL_BUILD");
  376. // Refer to the main build configuration file for easy editing.
  377. std::string listfile = mf->GetStartDirectory();
  378. listfile += "/";
  379. listfile += "CMakeLists.txt";
  380. allbuild->AddSourceCMP0049(listfile.c_str());
  381. // Add XCODE depend helper
  382. std::string dir = mf->GetCurrentOutputDirectory();
  383. cmCustomCommandLine makeHelper;
  384. if(this->XcodeVersion < 50)
  385. {
  386. makeHelper.push_back("make");
  387. makeHelper.push_back("-C");
  388. makeHelper.push_back(dir.c_str());
  389. makeHelper.push_back("-f");
  390. makeHelper.push_back(this->CurrentXCodeHackMakefile.c_str());
  391. makeHelper.push_back(""); // placeholder, see below
  392. }
  393. // Add ZERO_CHECK
  394. bool regenerate = !mf->IsOn("CMAKE_SUPPRESS_REGENERATION");
  395. if (regenerate)
  396. {
  397. this->CreateReRunCMakeFile(root, gens);
  398. std::string file = this->ConvertToRelativeForMake(
  399. this->CurrentReRunCMakeMakefile.c_str());
  400. cmSystemTools::ReplaceString(file, "\\ ", " ");
  401. mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, true, no_depends,
  402. no_working_directory,
  403. "make", "-f", file.c_str());
  404. }
  405. // now make the allbuild depend on all the non-utility targets
  406. // in the project
  407. for(std::vector<cmLocalGenerator*>::iterator i = gens.begin();
  408. i != gens.end(); ++i)
  409. {
  410. cmLocalGenerator* lg = *i;
  411. if(this->IsExcluded(root, *i))
  412. {
  413. continue;
  414. }
  415. cmTargets& tgts = lg->GetMakefile()->GetTargets();
  416. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  417. {
  418. cmTarget& target = l->second;
  419. if (regenerate && (l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET))
  420. {
  421. target.AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  422. }
  423. // make all exe, shared libs and modules
  424. // run the depend check makefile as a post build rule
  425. // this will make sure that when the next target is built
  426. // things are up-to-date
  427. if(!makeHelper.empty() &&
  428. (target.GetType() == cmTarget::EXECUTABLE ||
  429. // Nope - no post-build for OBJECT_LIRBRARY
  430. // target.GetType() == cmTarget::OBJECT_LIBRARY ||
  431. target.GetType() == cmTarget::STATIC_LIBRARY ||
  432. target.GetType() == cmTarget::SHARED_LIBRARY ||
  433. target.GetType() == cmTarget::MODULE_LIBRARY))
  434. {
  435. makeHelper[makeHelper.size()-1] = // fill placeholder
  436. this->PostBuildMakeTarget(target.GetName(), "$(CONFIGURATION)");
  437. cmCustomCommandLines commandLines;
  438. commandLines.push_back(makeHelper);
  439. lg->GetMakefile()->AddCustomCommandToTarget(target.GetName(),
  440. no_depends,
  441. commandLines,
  442. cmTarget::POST_BUILD,
  443. "Depend check for xcode",
  444. dir.c_str());
  445. }
  446. if(target.GetType() != cmTarget::INTERFACE_LIBRARY
  447. && !target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  448. {
  449. allbuild->AddUtility(target.GetName());
  450. }
  451. // Refer to the build configuration file for easy editing.
  452. listfile = lg->GetMakefile()->GetStartDirectory();
  453. listfile += "/";
  454. listfile += "CMakeLists.txt";
  455. target.AddSourceCMP0049(listfile.c_str());
  456. }
  457. }
  458. }
  459. //----------------------------------------------------------------------------
  460. void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
  461. cmLocalGenerator* root, std::vector<cmLocalGenerator*> const& gens)
  462. {
  463. cmMakefile* mf = root->GetMakefile();
  464. std::vector<std::string> lfiles;
  465. for(std::vector<cmLocalGenerator*>::const_iterator gi = gens.begin();
  466. gi != gens.end(); ++gi)
  467. {
  468. std::vector<std::string> const& lf = (*gi)->GetMakefile()->GetListFiles();
  469. lfiles.insert(lfiles.end(), lf.begin(), lf.end());
  470. }
  471. // sort the array
  472. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
  473. std::vector<std::string>::iterator new_end =
  474. std::unique(lfiles.begin(), lfiles.end());
  475. lfiles.erase(new_end, lfiles.end());
  476. this->CurrentReRunCMakeMakefile = mf->GetStartOutputDirectory();
  477. this->CurrentReRunCMakeMakefile += "/CMakeScripts";
  478. cmSystemTools::MakeDirectory(this->CurrentReRunCMakeMakefile.c_str());
  479. this->CurrentReRunCMakeMakefile += "/ReRunCMake.make";
  480. cmGeneratedFileStream makefileStream
  481. (this->CurrentReRunCMakeMakefile.c_str());
  482. makefileStream.SetCopyIfDifferent(true);
  483. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  484. std::string checkCache = mf->GetHomeOutputDirectory();
  485. checkCache += "/";
  486. checkCache += cmake::GetCMakeFilesDirectoryPostSlash();
  487. checkCache += "cmake.check_cache";
  488. makefileStream << this->ConvertToRelativeForMake(checkCache.c_str())
  489. << ": ";
  490. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  491. i != lfiles.end(); ++i)
  492. {
  493. makefileStream << "\\\n" << this->ConvertToRelativeForMake(i->c_str());
  494. }
  495. std::string cmake = mf->GetRequiredDefinition("CMAKE_COMMAND");
  496. makefileStream << "\n\t" << this->ConvertToRelativeForMake(cmake.c_str())
  497. << " -H" << this->ConvertToRelativeForMake(
  498. mf->GetHomeDirectory())
  499. << " -B" << this->ConvertToRelativeForMake(
  500. mf->GetHomeOutputDirectory()) << "\n";
  501. }
  502. //----------------------------------------------------------------------------
  503. void cmGlobalXCodeGenerator::ClearXCodeObjects()
  504. {
  505. this->TargetDoneSet.clear();
  506. for(unsigned int i = 0; i < this->XCodeObjects.size(); ++i)
  507. {
  508. delete this->XCodeObjects[i];
  509. }
  510. this->XCodeObjects.clear();
  511. this->XCodeObjectIDs.clear();
  512. this->GroupMap.clear();
  513. this->GroupNameMap.clear();
  514. this->TargetGroup.clear();
  515. this->FileRefs.clear();
  516. }
  517. //----------------------------------------------------------------------------
  518. void cmGlobalXCodeGenerator::addObject(cmXCodeObject *obj)
  519. {
  520. if(obj->GetType() == cmXCodeObject::OBJECT)
  521. {
  522. std::string id = obj->GetId();
  523. // If this is a duplicate id, it's an error:
  524. //
  525. if(this->XCodeObjectIDs.count(id))
  526. {
  527. cmSystemTools::Error(
  528. "Xcode generator: duplicate object ids not allowed");
  529. }
  530. this->XCodeObjectIDs.insert(id);
  531. }
  532. this->XCodeObjects.push_back(obj);
  533. }
  534. //----------------------------------------------------------------------------
  535. cmXCodeObject*
  536. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
  537. {
  538. cmXCodeObject* obj;
  539. if(this->XcodeVersion == 15)
  540. {
  541. obj = new cmXCodeObject(ptype, cmXCodeObject::OBJECT);
  542. }
  543. else
  544. {
  545. obj = new cmXCode21Object(ptype, cmXCodeObject::OBJECT);
  546. }
  547. this->addObject(obj);
  548. return obj;
  549. }
  550. //----------------------------------------------------------------------------
  551. cmXCodeObject*
  552. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
  553. {
  554. cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, type);
  555. this->addObject(obj);
  556. return obj;
  557. }
  558. //----------------------------------------------------------------------------
  559. cmXCodeObject*
  560. cmGlobalXCodeGenerator::CreateString(const std::string& s)
  561. {
  562. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::STRING);
  563. obj->SetString(s);
  564. return obj;
  565. }
  566. //----------------------------------------------------------------------------
  567. cmXCodeObject* cmGlobalXCodeGenerator
  568. ::CreateObjectReference(cmXCodeObject* ref)
  569. {
  570. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::OBJECT_REF);
  571. obj->SetObject(ref);
  572. return obj;
  573. }
  574. //----------------------------------------------------------------------------
  575. std::string
  576. GetGroupMapKeyFromPath(cmTarget& cmtarget, const std::string& fullpath)
  577. {
  578. std::string key(cmtarget.GetName());
  579. key += "-";
  580. key += fullpath;
  581. return key;
  582. }
  583. //----------------------------------------------------------------------------
  584. std::string
  585. GetGroupMapKey(cmTarget& cmtarget, cmSourceFile* sf)
  586. {
  587. return GetGroupMapKeyFromPath(cmtarget, sf->GetFullPath());
  588. }
  589. //----------------------------------------------------------------------------
  590. cmXCodeObject*
  591. cmGlobalXCodeGenerator::CreateXCodeSourceFileFromPath(
  592. const std::string &fullpath,
  593. cmTarget& cmtarget,
  594. const std::string &lang)
  595. {
  596. // Using a map and the full path guarantees that we will always get the same
  597. // fileRef object for any given full path.
  598. //
  599. cmXCodeObject* fileRef =
  600. this->CreateXCodeFileReferenceFromPath(fullpath, cmtarget, lang);
  601. cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
  602. buildFile->SetComment(fileRef->GetComment());
  603. buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef));
  604. return buildFile;
  605. }
  606. //----------------------------------------------------------------------------
  607. cmXCodeObject*
  608. cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
  609. cmSourceFile* sf,
  610. cmTarget& cmtarget)
  611. {
  612. // Add flags from target and source file properties.
  613. std::string flags;
  614. const char* srcfmt = sf->GetProperty("Fortran_FORMAT");
  615. switch(this->CurrentLocalGenerator->GetFortranFormat(srcfmt))
  616. {
  617. case cmLocalGenerator::FortranFormatFixed: flags="-fixed "+flags; break;
  618. case cmLocalGenerator::FortranFormatFree: flags="-free "+flags; break;
  619. default: break;
  620. }
  621. lg->AppendFlags(flags, sf->GetProperty("COMPILE_FLAGS"));
  622. // Add per-source definitions.
  623. BuildObjectListOrString flagsBuild(this, false);
  624. this->AppendDefines(flagsBuild,
  625. sf->GetProperty("COMPILE_DEFINITIONS"), true);
  626. if (!flagsBuild.IsEmpty())
  627. {
  628. if (flags.size())
  629. {
  630. flags += ' ';
  631. }
  632. flags += flagsBuild.GetString();
  633. }
  634. std::string lang =
  635. this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
  636. cmXCodeObject* buildFile =
  637. this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), cmtarget, lang);
  638. cmXCodeObject* fileRef = buildFile->GetObject("fileRef")->GetObject();
  639. cmXCodeObject* settings =
  640. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  641. settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags.c_str()));
  642. // Is this a resource file in this target? Add it to the resources group...
  643. //
  644. cmGeneratorTarget::SourceFileFlags tsFlags =
  645. this->GetGeneratorTarget(&cmtarget)->GetTargetSourceFileFlags(sf);
  646. bool isResource = tsFlags.Type == cmGeneratorTarget::SourceFileTypeResource;
  647. // Is this a "private" or "public" framework header file?
  648. // Set the ATTRIBUTES attribute appropriately...
  649. //
  650. if(cmtarget.IsFrameworkOnApple())
  651. {
  652. if(tsFlags.Type == cmGeneratorTarget::SourceFileTypePrivateHeader)
  653. {
  654. cmXCodeObject* attrs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  655. attrs->AddObject(this->CreateString("Private"));
  656. settings->AddAttribute("ATTRIBUTES", attrs);
  657. isResource = true;
  658. }
  659. else if(tsFlags.Type == cmGeneratorTarget::SourceFileTypePublicHeader)
  660. {
  661. cmXCodeObject* attrs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  662. attrs->AddObject(this->CreateString("Public"));
  663. settings->AddAttribute("ATTRIBUTES", attrs);
  664. isResource = true;
  665. }
  666. }
  667. // Add the fileRef to the top level Resources group/folder if it is not
  668. // already there.
  669. //
  670. if(isResource && this->ResourcesGroupChildren &&
  671. !this->ResourcesGroupChildren->HasObject(fileRef))
  672. {
  673. this->ResourcesGroupChildren->AddObject(fileRef);
  674. }
  675. buildFile->AddAttribute("settings", settings);
  676. return buildFile;
  677. }
  678. //----------------------------------------------------------------------------
  679. std::string
  680. GetSourcecodeValueFromFileExtension(const std::string& _ext,
  681. const std::string& lang,
  682. bool& keepLastKnownFileType)
  683. {
  684. std::string ext = cmSystemTools::LowerCase(_ext);
  685. std::string sourcecode = "sourcecode";
  686. if(ext == "o")
  687. {
  688. sourcecode = "compiled.mach-o.objfile";
  689. }
  690. else if(ext == "xib")
  691. {
  692. keepLastKnownFileType = true;
  693. sourcecode = "file.xib";
  694. }
  695. else if(ext == "storyboard")
  696. {
  697. keepLastKnownFileType = true;
  698. sourcecode = "file.storyboard";
  699. }
  700. else if(ext == "mm")
  701. {
  702. sourcecode += ".cpp.objcpp";
  703. }
  704. else if(ext == "m")
  705. {
  706. sourcecode += ".c.objc";
  707. }
  708. else if(ext == "plist")
  709. {
  710. sourcecode += ".text.plist";
  711. }
  712. else if(ext == "h")
  713. {
  714. sourcecode += ".c.h";
  715. }
  716. else if(ext == "hxx" || ext == "hpp" || ext == "txx"
  717. || ext == "pch" || ext == "hh")
  718. {
  719. sourcecode += ".cpp.h";
  720. }
  721. else if(ext == "png" || ext == "gif" || ext == "jpg")
  722. {
  723. keepLastKnownFileType = true;
  724. sourcecode = "image";
  725. }
  726. else if(ext == "txt")
  727. {
  728. sourcecode += ".text";
  729. }
  730. else if(lang == "CXX")
  731. {
  732. sourcecode += ".cpp.cpp";
  733. }
  734. else if(lang == "C")
  735. {
  736. sourcecode += ".c.c";
  737. }
  738. else if(lang == "Fortran")
  739. {
  740. sourcecode += ".fortran.f90";
  741. }
  742. else if(lang == "ASM")
  743. {
  744. sourcecode += ".asm";
  745. }
  746. //else
  747. // {
  748. // // Already specialized above or we leave sourcecode == "sourcecode"
  749. // // which is probably the most correct choice. Extensionless headers,
  750. // // for example... Or file types unknown to Xcode that do not map to a
  751. // // valid explicitFileType value.
  752. // }
  753. return sourcecode;
  754. }
  755. //----------------------------------------------------------------------------
  756. cmXCodeObject*
  757. cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath(
  758. const std::string &fullpath,
  759. cmTarget& cmtarget,
  760. const std::string &lang)
  761. {
  762. std::string fname = fullpath;
  763. cmXCodeObject* fileRef = this->FileRefs[fname];
  764. if(!fileRef)
  765. {
  766. fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  767. std::string comment = fname;
  768. fileRef->SetComment(fname.c_str());
  769. this->FileRefs[fname] = fileRef;
  770. }
  771. std::string key = GetGroupMapKeyFromPath(cmtarget, fullpath);
  772. cmXCodeObject* group = this->GroupMap[key];
  773. cmXCodeObject* children = group->GetObject("children");
  774. if (!children->HasObject(fileRef))
  775. {
  776. children->AddObject(fileRef);
  777. }
  778. fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
  779. // Compute the extension.
  780. std::string ext;
  781. std::string realExt =
  782. cmSystemTools::GetFilenameLastExtension(fullpath);
  783. if(!realExt.empty())
  784. {
  785. // Extension without the leading '.'.
  786. ext = realExt.substr(1);
  787. }
  788. // If fullpath references a directory, then we need to specify
  789. // lastKnownFileType as folder in order for Xcode to be able to open the
  790. // contents of the folder (Xcode 4.6 does not like explicitFileType=folder).
  791. if(cmSystemTools::FileIsDirectory(fullpath.c_str()))
  792. {
  793. fileRef->AddAttribute("lastKnownFileType",
  794. this->CreateString("folder"));
  795. }
  796. else
  797. {
  798. bool keepLastKnownFileType = false;
  799. std::string sourcecode = GetSourcecodeValueFromFileExtension(ext,
  800. lang, keepLastKnownFileType);
  801. const char* attribute = keepLastKnownFileType ?
  802. "lastKnownFileType" :
  803. "explicitFileType";
  804. fileRef->AddAttribute(attribute,
  805. this->CreateString(sourcecode.c_str()));
  806. }
  807. // Store the file path relative to the top of the source tree.
  808. std::string path = this->RelativeToSource(fullpath.c_str());
  809. std::string name = cmSystemTools::GetFilenameName(path.c_str());
  810. const char* sourceTree = (cmSystemTools::FileIsFullPath(path.c_str())?
  811. "<absolute>" : "SOURCE_ROOT");
  812. fileRef->AddAttribute("name", this->CreateString(name.c_str()));
  813. fileRef->AddAttribute("path", this->CreateString(path.c_str()));
  814. fileRef->AddAttribute("sourceTree", this->CreateString(sourceTree));
  815. if(this->XcodeVersion == 15)
  816. {
  817. fileRef->AddAttribute("refType", this->CreateString("4"));
  818. }
  819. return fileRef;
  820. }
  821. //----------------------------------------------------------------------------
  822. cmXCodeObject*
  823. cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf,
  824. cmTarget& cmtarget)
  825. {
  826. std::string lang =
  827. this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
  828. return this->CreateXCodeFileReferenceFromPath(
  829. sf->GetFullPath(), cmtarget, lang);
  830. }
  831. //----------------------------------------------------------------------------
  832. bool cmGlobalXCodeGenerator::SpecialTargetEmitted(std::string const& tname)
  833. {
  834. if(tname == "ALL_BUILD" || tname == "XCODE_DEPEND_HELPER" ||
  835. tname == "install" || tname == "package" || tname == "RUN_TESTS" ||
  836. tname == CMAKE_CHECK_BUILD_SYSTEM_TARGET )
  837. {
  838. if(this->TargetDoneSet.find(tname) != this->TargetDoneSet.end())
  839. {
  840. return true;
  841. }
  842. this->TargetDoneSet.insert(tname);
  843. return false;
  844. }
  845. return false;
  846. }
  847. //----------------------------------------------------------------------------
  848. void cmGlobalXCodeGenerator::SetCurrentLocalGenerator(cmLocalGenerator* gen)
  849. {
  850. this->CurrentLocalGenerator = gen;
  851. this->CurrentMakefile = gen->GetMakefile();
  852. std::string outdir =
  853. cmSystemTools::CollapseFullPath(this->CurrentMakefile->
  854. GetCurrentOutputDirectory());
  855. cmSystemTools::SplitPath(outdir.c_str(),
  856. this->CurrentOutputDirectoryComponents);
  857. // Select the current set of configuration types.
  858. this->CurrentConfigurationTypes.clear();
  859. this->CurrentMakefile->GetConfigurations(this->CurrentConfigurationTypes);
  860. if(this->CurrentConfigurationTypes.empty())
  861. {
  862. this->CurrentConfigurationTypes.push_back("");
  863. }
  864. }
  865. //----------------------------------------------------------------------------
  866. struct cmSourceFilePathCompare
  867. {
  868. bool operator()(cmSourceFile* l, cmSourceFile* r)
  869. {
  870. return l->GetFullPath() < r->GetFullPath();
  871. }
  872. };
  873. //----------------------------------------------------------------------------
  874. void
  875. cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
  876. std::vector<cmXCodeObject*>&
  877. targets)
  878. {
  879. this->SetCurrentLocalGenerator(gen);
  880. cmTargets &tgts = this->CurrentMakefile->GetTargets();
  881. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  882. {
  883. cmTarget& cmtarget = l->second;
  884. cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&cmtarget);
  885. // make sure ALL_BUILD, INSTALL, etc are only done once
  886. if(this->SpecialTargetEmitted(l->first.c_str()))
  887. {
  888. continue;
  889. }
  890. if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
  891. {
  892. continue;
  893. }
  894. if(cmtarget.GetType() == cmTarget::UTILITY ||
  895. cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
  896. {
  897. targets.push_back(this->CreateUtilityTarget(cmtarget));
  898. continue;
  899. }
  900. // organize the sources
  901. std::vector<cmSourceFile*> classes;
  902. cmtarget.GetSourceFiles(classes);
  903. std::sort(classes.begin(), classes.end(), cmSourceFilePathCompare());
  904. std::vector<cmXCodeObject*> externalObjFiles;
  905. std::vector<cmXCodeObject*> headerFiles;
  906. std::vector<cmXCodeObject*> resourceFiles;
  907. std::vector<cmXCodeObject*> sourceFiles;
  908. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  909. i != classes.end(); ++i)
  910. {
  911. cmXCodeObject* xsf =
  912. this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
  913. *i, cmtarget);
  914. cmXCodeObject* fr = xsf->GetObject("fileRef");
  915. cmXCodeObject* filetype =
  916. fr->GetObject()->GetObject("explicitFileType");
  917. cmGeneratorTarget::SourceFileFlags tsFlags =
  918. gtgt->GetTargetSourceFileFlags(*i);
  919. if(filetype &&
  920. filetype->GetString() == "compiled.mach-o.objfile")
  921. {
  922. if ((*i)->GetObjectLibrary().empty())
  923. {
  924. externalObjFiles.push_back(xsf);
  925. }
  926. }
  927. else if(this->IsHeaderFile(*i) ||
  928. (tsFlags.Type == cmGeneratorTarget::SourceFileTypePrivateHeader) ||
  929. (tsFlags.Type == cmGeneratorTarget::SourceFileTypePublicHeader))
  930. {
  931. headerFiles.push_back(xsf);
  932. }
  933. else if(tsFlags.Type == cmGeneratorTarget::SourceFileTypeResource)
  934. {
  935. resourceFiles.push_back(xsf);
  936. }
  937. else if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  938. {
  939. // Include this file in the build if it has a known language
  940. // and has not been listed as an ignored extension for this
  941. // generator.
  942. if(!this->CurrentLocalGenerator->GetSourceFileLanguage(**i).empty() &&
  943. !this->IgnoreFile((*i)->GetExtension().c_str()))
  944. {
  945. sourceFiles.push_back(xsf);
  946. }
  947. }
  948. }
  949. if(this->XcodeVersion < 50)
  950. {
  951. // Add object library contents as external objects. (Equivalent to
  952. // the externalObjFiles above, except each one is not a cmSourceFile
  953. // within the target.)
  954. std::vector<std::string> objs;
  955. gtgt->UseObjectLibraries(objs);
  956. for(std::vector<std::string>::const_iterator
  957. oi = objs.begin(); oi != objs.end(); ++oi)
  958. {
  959. std::string obj = *oi;
  960. cmXCodeObject* xsf =
  961. this->CreateXCodeSourceFileFromPath(obj, cmtarget, "");
  962. externalObjFiles.push_back(xsf);
  963. }
  964. }
  965. // some build phases only apply to bundles and/or frameworks
  966. bool isFrameworkTarget = cmtarget.IsFrameworkOnApple();
  967. bool isBundleTarget = cmtarget.GetPropertyAsBool("MACOSX_BUNDLE");
  968. bool isCFBundleTarget = cmtarget.IsCFBundleOnApple();
  969. cmXCodeObject* buildFiles = 0;
  970. // create source build phase
  971. cmXCodeObject* sourceBuildPhase = 0;
  972. if (!sourceFiles.empty())
  973. {
  974. sourceBuildPhase =
  975. this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
  976. sourceBuildPhase->SetComment("Sources");
  977. sourceBuildPhase->AddAttribute("buildActionMask",
  978. this->CreateString("2147483647"));
  979. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  980. for(std::vector<cmXCodeObject*>::iterator i = sourceFiles.begin();
  981. i != sourceFiles.end(); ++i)
  982. {
  983. buildFiles->AddObject(*i);
  984. }
  985. sourceBuildPhase->AddAttribute("files", buildFiles);
  986. sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  987. this->CreateString("0"));
  988. }
  989. // create header build phase - only for framework targets
  990. cmXCodeObject* headerBuildPhase = 0;
  991. if (!headerFiles.empty() && isFrameworkTarget)
  992. {
  993. headerBuildPhase =
  994. this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase);
  995. headerBuildPhase->SetComment("Headers");
  996. headerBuildPhase->AddAttribute("buildActionMask",
  997. this->CreateString("2147483647"));
  998. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  999. for(std::vector<cmXCodeObject*>::iterator i = headerFiles.begin();
  1000. i != headerFiles.end(); ++i)
  1001. {
  1002. buildFiles->AddObject(*i);
  1003. }
  1004. headerBuildPhase->AddAttribute("files", buildFiles);
  1005. headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1006. this->CreateString("0"));
  1007. }
  1008. // create resource build phase - only for framework or bundle targets
  1009. cmXCodeObject* resourceBuildPhase = 0;
  1010. if (!resourceFiles.empty() &&
  1011. (isFrameworkTarget || isBundleTarget || isCFBundleTarget))
  1012. {
  1013. resourceBuildPhase =
  1014. this->CreateObject(cmXCodeObject::PBXResourcesBuildPhase);
  1015. resourceBuildPhase->SetComment("Resources");
  1016. resourceBuildPhase->AddAttribute("buildActionMask",
  1017. this->CreateString("2147483647"));
  1018. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1019. for(std::vector<cmXCodeObject*>::iterator i = resourceFiles.begin();
  1020. i != resourceFiles.end(); ++i)
  1021. {
  1022. buildFiles->AddObject(*i);
  1023. }
  1024. resourceBuildPhase->AddAttribute("files", buildFiles);
  1025. resourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1026. this->CreateString("0"));
  1027. }
  1028. // create vector of "non-resource content file" build phases - only for
  1029. // framework or bundle targets
  1030. std::vector<cmXCodeObject*> contentBuildPhases;
  1031. if (isFrameworkTarget || isBundleTarget || isCFBundleTarget)
  1032. {
  1033. typedef std::map<std::string, std::vector<cmSourceFile*> >
  1034. mapOfVectorOfSourceFiles;
  1035. mapOfVectorOfSourceFiles bundleFiles;
  1036. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1037. i != classes.end(); ++i)
  1038. {
  1039. cmGeneratorTarget::SourceFileFlags tsFlags =
  1040. gtgt->GetTargetSourceFileFlags(*i);
  1041. if(tsFlags.Type == cmGeneratorTarget::SourceFileTypeMacContent)
  1042. {
  1043. bundleFiles[tsFlags.MacFolder].push_back(*i);
  1044. }
  1045. }
  1046. mapOfVectorOfSourceFiles::iterator mit;
  1047. for ( mit = bundleFiles.begin(); mit != bundleFiles.end(); ++ mit )
  1048. {
  1049. cmXCodeObject* copyFilesBuildPhase =
  1050. this->CreateObject(cmXCodeObject::PBXCopyFilesBuildPhase);
  1051. copyFilesBuildPhase->SetComment("Copy files");
  1052. copyFilesBuildPhase->AddAttribute("buildActionMask",
  1053. this->CreateString("2147483647"));
  1054. copyFilesBuildPhase->AddAttribute("dstSubfolderSpec",
  1055. this->CreateString("6"));
  1056. cmOStringStream ostr;
  1057. if (cmtarget.IsFrameworkOnApple())
  1058. {
  1059. // dstPath in frameworks is relative to Versions/<version>
  1060. ostr << mit->first;
  1061. }
  1062. else if ( mit->first != "MacOS" )
  1063. {
  1064. // dstPath in bundles is relative to Contents/MacOS
  1065. ostr << "../" << mit->first.c_str();
  1066. }
  1067. copyFilesBuildPhase->AddAttribute("dstPath",
  1068. this->CreateString(ostr.str().c_str()));
  1069. copyFilesBuildPhase->AddAttribute(
  1070. "runOnlyForDeploymentPostprocessing", this->CreateString("0"));
  1071. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1072. copyFilesBuildPhase->AddAttribute("files", buildFiles);
  1073. std::vector<cmSourceFile*>::iterator sfIt;
  1074. for ( sfIt = mit->second.begin(); sfIt != mit->second.end(); ++ sfIt )
  1075. {
  1076. cmXCodeObject* xsf =
  1077. this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
  1078. *sfIt, cmtarget);
  1079. buildFiles->AddObject(xsf);
  1080. }
  1081. contentBuildPhases.push_back(copyFilesBuildPhase);
  1082. }
  1083. }
  1084. // create framework build phase
  1085. cmXCodeObject* frameworkBuildPhase = 0;
  1086. if (!externalObjFiles.empty())
  1087. {
  1088. frameworkBuildPhase =
  1089. this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
  1090. frameworkBuildPhase->SetComment("Frameworks");
  1091. frameworkBuildPhase->AddAttribute("buildActionMask",
  1092. this->CreateString("2147483647"));
  1093. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1094. frameworkBuildPhase->AddAttribute("files", buildFiles);
  1095. for(std::vector<cmXCodeObject*>::iterator i = externalObjFiles.begin();
  1096. i != externalObjFiles.end(); ++i)
  1097. {
  1098. buildFiles->AddObject(*i);
  1099. }
  1100. frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1101. this->CreateString("0"));
  1102. }
  1103. // create list of build phases and create the Xcode target
  1104. cmXCodeObject* buildPhases =
  1105. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1106. this->CreateCustomCommands(buildPhases, sourceBuildPhase,
  1107. headerBuildPhase, resourceBuildPhase,
  1108. contentBuildPhases,
  1109. frameworkBuildPhase, cmtarget);
  1110. targets.push_back(this->CreateXCodeTarget(cmtarget, buildPhases));
  1111. }
  1112. }
  1113. //----------------------------------------------------------------------------
  1114. void cmGlobalXCodeGenerator::ForceLinkerLanguages()
  1115. {
  1116. // This makes sure all targets link using the proper language.
  1117. for(std::map<std::string, cmTarget*>::const_iterator
  1118. ti = this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
  1119. {
  1120. this->ForceLinkerLanguage(*ti->second);
  1121. }
  1122. }
  1123. //----------------------------------------------------------------------------
  1124. void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
  1125. {
  1126. // This matters only for targets that link.
  1127. if(cmtarget.GetType() != cmTarget::EXECUTABLE &&
  1128. cmtarget.GetType() != cmTarget::SHARED_LIBRARY &&
  1129. cmtarget.GetType() != cmTarget::MODULE_LIBRARY)
  1130. {
  1131. return;
  1132. }
  1133. std::string llang = cmtarget.GetLinkerLanguage("NOCONFIG");
  1134. if(llang.empty()) { return; }
  1135. // If the language is compiled as a source trust Xcode to link with it.
  1136. cmTarget::LinkImplementation const* impl =
  1137. cmtarget.GetLinkImplementation("NOCONFIG", &cmtarget);
  1138. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1139. li != impl->Languages.end(); ++li)
  1140. {
  1141. if(*li == llang) { return; }
  1142. }
  1143. // Add an empty source file to the target that compiles with the
  1144. // linker language. This should convince Xcode to choose the proper
  1145. // language.
  1146. cmMakefile* mf = cmtarget.GetMakefile();
  1147. std::string fname = mf->GetCurrentOutputDirectory();
  1148. fname += cmake::GetCMakeFilesDirectory();
  1149. fname += "/";
  1150. fname += cmtarget.GetName();
  1151. fname += "-CMakeForceLinker";
  1152. fname += ".";
  1153. fname += cmSystemTools::LowerCase(llang);
  1154. {
  1155. cmGeneratedFileStream fout(fname.c_str());
  1156. fout << "\n";
  1157. }
  1158. if(cmSourceFile* sf = mf->GetOrCreateSource(fname.c_str()))
  1159. {
  1160. sf->SetProperty("LANGUAGE", llang.c_str());
  1161. cmtarget.AddSource(fname);
  1162. }
  1163. }
  1164. //----------------------------------------------------------------------------
  1165. bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf)
  1166. {
  1167. const std::vector<std::string>& hdrExts =
  1168. this->CurrentMakefile->GetHeaderExtensions();
  1169. return (std::find(hdrExts.begin(), hdrExts.end(), sf->GetExtension()) !=
  1170. hdrExts.end());
  1171. }
  1172. //----------------------------------------------------------------------------
  1173. cmXCodeObject*
  1174. cmGlobalXCodeGenerator::CreateBuildPhase(const char* name,
  1175. const char* name2,
  1176. cmTarget& cmtarget,
  1177. const std::vector<cmCustomCommand>&
  1178. commands)
  1179. {
  1180. if(commands.size() == 0 && strcmp(name, "CMake ReRun") != 0)
  1181. {
  1182. return 0;
  1183. }
  1184. cmXCodeObject* buildPhase =
  1185. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  1186. buildPhase->AddAttribute("buildActionMask",
  1187. this->CreateString("2147483647"));
  1188. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1189. buildPhase->AddAttribute("files", buildFiles);
  1190. buildPhase->AddAttribute("name",
  1191. this->CreateString(name));
  1192. buildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1193. this->CreateString("0"));
  1194. buildPhase->AddAttribute("shellPath",
  1195. this->CreateString("/bin/sh"));
  1196. this->AddCommandsToBuildPhase(buildPhase, cmtarget, commands,
  1197. name2);
  1198. return buildPhase;
  1199. }
  1200. //----------------------------------------------------------------------------
  1201. void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
  1202. cmXCodeObject*
  1203. sourceBuildPhase,
  1204. cmXCodeObject*
  1205. headerBuildPhase,
  1206. cmXCodeObject*
  1207. resourceBuildPhase,
  1208. std::vector<cmXCodeObject*>
  1209. contentBuildPhases,
  1210. cmXCodeObject*
  1211. frameworkBuildPhase,
  1212. cmTarget& cmtarget)
  1213. {
  1214. std::vector<cmCustomCommand> const & prebuild
  1215. = cmtarget.GetPreBuildCommands();
  1216. std::vector<cmCustomCommand> const & prelink
  1217. = cmtarget.GetPreLinkCommands();
  1218. std::vector<cmCustomCommand> postbuild
  1219. = cmtarget.GetPostBuildCommands();
  1220. if(cmtarget.GetType() == cmTarget::SHARED_LIBRARY &&
  1221. !cmtarget.IsFrameworkOnApple())
  1222. {
  1223. cmCustomCommandLines cmd;
  1224. cmd.resize(1);
  1225. cmd[0].push_back(this->CurrentMakefile->GetDefinition("CMAKE_COMMAND"));
  1226. cmd[0].push_back("-E");
  1227. cmd[0].push_back("cmake_symlink_library");
  1228. std::string str_file = "$<TARGET_FILE:";
  1229. str_file += cmtarget.GetName();
  1230. str_file += ">";
  1231. std::string str_so_file = "$<TARGET_SONAME_FILE:";
  1232. str_so_file += cmtarget.GetName();
  1233. str_so_file += ">";
  1234. std::string str_link_file = "$<TARGET_LINKER_FILE:";
  1235. str_link_file += cmtarget.GetName();
  1236. str_link_file += ">";
  1237. cmd[0].push_back(str_file);
  1238. cmd[0].push_back(str_so_file);
  1239. cmd[0].push_back(str_link_file);
  1240. cmCustomCommand command(this->CurrentMakefile,
  1241. std::vector<std::string>(),
  1242. std::vector<std::string>(),
  1243. cmd,
  1244. "Creating symlinks",
  1245. "");
  1246. postbuild.push_back(command);
  1247. }
  1248. std::vector<cmSourceFile*> classes;
  1249. cmtarget.GetSourceFiles(classes);
  1250. // add all the sources
  1251. std::vector<cmCustomCommand> commands;
  1252. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1253. i != classes.end(); ++i)
  1254. {
  1255. if((*i)->GetCustomCommand())
  1256. {
  1257. commands.push_back(*(*i)->GetCustomCommand());
  1258. }
  1259. }
  1260. // create prebuild phase
  1261. cmXCodeObject* cmakeRulesBuildPhase =
  1262. this->CreateBuildPhase("CMake Rules",
  1263. "cmakeRulesBuildPhase",
  1264. cmtarget, commands);
  1265. // create prebuild phase
  1266. cmXCodeObject* preBuildPhase =
  1267. this->CreateBuildPhase("CMake PreBuild Rules", "preBuildCommands",
  1268. cmtarget, prebuild);
  1269. // create prelink phase
  1270. cmXCodeObject* preLinkPhase =
  1271. this->CreateBuildPhase("CMake PreLink Rules", "preLinkCommands",
  1272. cmtarget, prelink);
  1273. // create postbuild phase
  1274. cmXCodeObject* postBuildPhase =
  1275. this->CreateBuildPhase("CMake PostBuild Rules", "postBuildPhase",
  1276. cmtarget, postbuild);
  1277. // The order here is the order they will be built in.
  1278. // The order "headers, resources, sources" mimics a native project generated
  1279. // from an xcode template...
  1280. //
  1281. if(preBuildPhase)
  1282. {
  1283. buildPhases->AddObject(preBuildPhase);
  1284. }
  1285. if(cmakeRulesBuildPhase)
  1286. {
  1287. buildPhases->AddObject(cmakeRulesBuildPhase);
  1288. }
  1289. if(headerBuildPhase)
  1290. {
  1291. buildPhases->AddObject(headerBuildPhase);
  1292. }
  1293. if(resourceBuildPhase)
  1294. {
  1295. buildPhases->AddObject(resourceBuildPhase);
  1296. }
  1297. std::vector<cmXCodeObject*>::iterator cit;
  1298. for (cit = contentBuildPhases.begin(); cit != contentBuildPhases.end();
  1299. ++cit)
  1300. {
  1301. buildPhases->AddObject(*cit);
  1302. }
  1303. if(sourceBuildPhase)
  1304. {
  1305. buildPhases->AddObject(sourceBuildPhase);
  1306. }
  1307. if(preLinkPhase)
  1308. {
  1309. buildPhases->AddObject(preLinkPhase);
  1310. }
  1311. if(frameworkBuildPhase)
  1312. {
  1313. buildPhases->AddObject(frameworkBuildPhase);
  1314. }
  1315. if(postBuildPhase)
  1316. {
  1317. buildPhases->AddObject(postBuildPhase);
  1318. }
  1319. }
  1320. //----------------------------------------------------------------------------
  1321. // This function removes each occurrence of the flag and returns the last one
  1322. // (i.e., the dominant flag in GCC)
  1323. std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
  1324. std::string& flags)
  1325. {
  1326. std::string retFlag;
  1327. std::string::size_type lastOccurancePos = flags.rfind(flag);
  1328. bool saved = false;
  1329. while(lastOccurancePos != flags.npos)
  1330. {
  1331. //increment pos, we use lastOccurancePos to reduce search space on next inc
  1332. std::string::size_type pos = lastOccurancePos;
  1333. if(pos == 0 || flags[pos-1]==' ')
  1334. {
  1335. while(pos < flags.size() && flags[pos] != ' ')
  1336. {
  1337. if(!saved)
  1338. {
  1339. retFlag += flags[pos];
  1340. }
  1341. flags[pos] = ' ';
  1342. pos++;
  1343. }
  1344. saved = true;
  1345. }
  1346. //decrement lastOccurancePos while making sure we don't loop around
  1347. //and become a very large positive number since size_type is unsigned
  1348. lastOccurancePos = lastOccurancePos == 0 ? 0 : lastOccurancePos-1;
  1349. lastOccurancePos = flags.rfind(flag,lastOccurancePos);
  1350. }
  1351. return retFlag;
  1352. }
  1353. //----------------------------------------------------------------------------
  1354. void
  1355. cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  1356. cmTarget& target,
  1357. std::vector<cmCustomCommand>
  1358. const & commands,
  1359. const char* name)
  1360. {
  1361. bool haveMultipleOutputPairs = false;
  1362. std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1363. dir += "/CMakeScripts";
  1364. cmSystemTools::MakeDirectory(dir.c_str());
  1365. std::string makefile = dir;
  1366. makefile += "/";
  1367. makefile += target.GetName();
  1368. makefile += "_";
  1369. makefile += name;
  1370. makefile += ".make";
  1371. for (std::vector<std::string>::const_iterator currentConfig=
  1372. this->CurrentConfigurationTypes.begin();
  1373. currentConfig!=this->CurrentConfigurationTypes.end();
  1374. currentConfig++ )
  1375. {
  1376. this->CreateCustomRulesMakefile(makefile.c_str(),
  1377. target,
  1378. commands,
  1379. currentConfig->c_str(),
  1380. haveMultipleOutputPairs);
  1381. }
  1382. std::string cdir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1383. cdir = this->ConvertToRelativeForXCode(cdir.c_str());
  1384. std::string makecmd = "make -C ";
  1385. makecmd += cdir;
  1386. makecmd += " -f ";
  1387. makecmd += this->ConvertToRelativeForMake(
  1388. (makefile+"$CONFIGURATION").c_str());
  1389. if(haveMultipleOutputPairs)
  1390. {
  1391. makecmd += " cmake_check_multiple_outputs";
  1392. }
  1393. makecmd += " all";
  1394. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  1395. buildphase->AddAttribute("shellScript",
  1396. this->CreateString(makecmd.c_str()));
  1397. buildphase->AddAttribute("showEnvVarsInLog",
  1398. this->CreateString("0"));
  1399. }
  1400. //----------------------------------------------------------------------------
  1401. void cmGlobalXCodeGenerator
  1402. ::CreateCustomRulesMakefile(const char* makefileBasename,
  1403. cmTarget& target,
  1404. std::vector<cmCustomCommand>
  1405. const & commands,
  1406. const std::string& configName,
  1407. bool& haveMultipleOutputPairs)
  1408. {
  1409. std::string makefileName=makefileBasename;
  1410. if(this->XcodeVersion > 20)
  1411. {
  1412. makefileName+=configName;
  1413. }
  1414. cmGeneratedFileStream makefileStream(makefileName.c_str());
  1415. if(!makefileStream)
  1416. {
  1417. return;
  1418. }
  1419. makefileStream.SetCopyIfDifferent(true);
  1420. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  1421. makefileStream << "# Custom rules for " << target.GetName() << "\n";
  1422. // disable the implicit rules
  1423. makefileStream << ".SUFFIXES: " << "\n";
  1424. // have all depend on all outputs
  1425. makefileStream << "all: ";
  1426. std::map<const cmCustomCommand*, std::string> tname;
  1427. int count = 0;
  1428. std::map<std::string, std::string> multipleOutputPairs;
  1429. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1430. i != commands.end(); ++i)
  1431. {
  1432. cmCustomCommandGenerator ccg(*i, configName, this->CurrentMakefile);
  1433. if(ccg.GetNumberOfCommands() > 0)
  1434. {
  1435. const std::vector<std::string>& outputs = ccg.GetOutputs();
  1436. if(!outputs.empty())
  1437. {
  1438. for(std::vector<std::string>::const_iterator o = outputs.begin();
  1439. o != outputs.end(); ++o)
  1440. {
  1441. makefileStream
  1442. << "\\\n\t" << this->ConvertToRelativeForMake(o->c_str());
  1443. }
  1444. // If there is more than one output treat the first as the
  1445. // primary output and make the rest depend on it.
  1446. std::vector<std::string>::const_iterator o = outputs.begin();
  1447. std::string primaryOutput = this->ConvertToRelativeForMake(o->c_str());
  1448. for(++o; o != outputs.end(); ++o)
  1449. {
  1450. std::string currentOutput=this->ConvertToRelativeForMake(o->c_str());
  1451. multipleOutputPairs[currentOutput] = primaryOutput;
  1452. }
  1453. }
  1454. else
  1455. {
  1456. cmOStringStream str;
  1457. str << "_buildpart_" << count++ ;
  1458. tname[&ccg.GetCC()] = std::string(target.GetName()) + str.str();
  1459. makefileStream << "\\\n\t" << tname[&ccg.GetCC()];
  1460. }
  1461. }
  1462. }
  1463. makefileStream << "\n\n";
  1464. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1465. i != commands.end(); ++i)
  1466. {
  1467. cmCustomCommandGenerator ccg(*i, configName, this->CurrentMakefile);
  1468. if(ccg.GetNumberOfCommands() > 0)
  1469. {
  1470. makefileStream << "\n";
  1471. const std::vector<std::string>& outputs = ccg.GetOutputs();
  1472. if(!outputs.empty())
  1473. {
  1474. // There is at least one output, start the rule for it
  1475. std::string primary_output =
  1476. this->ConvertToRelativeForMake(outputs.begin()->c_str());
  1477. makefileStream << primary_output << ": ";
  1478. }
  1479. else
  1480. {
  1481. // There are no outputs. Use the generated force rule name.
  1482. makefileStream << tname[&ccg.GetCC()] << ": ";
  1483. }
  1484. for(std::vector<std::string>::const_iterator d =
  1485. ccg.GetDepends().begin();
  1486. d != ccg.GetDepends().end(); ++d)
  1487. {
  1488. std::string dep;
  1489. if(this->CurrentLocalGenerator
  1490. ->GetRealDependency(d->c_str(), configName, dep))
  1491. {
  1492. makefileStream << "\\\n" <<
  1493. this->ConvertToRelativeForMake(dep.c_str());
  1494. }
  1495. }
  1496. makefileStream << "\n";
  1497. if(const char* comment = ccg.GetComment())
  1498. {
  1499. std::string echo_cmd = "echo ";
  1500. echo_cmd += (this->CurrentLocalGenerator->
  1501. EscapeForShell(comment, ccg.GetCC().GetEscapeAllowMakeVars()));
  1502. makefileStream << "\t" << echo_cmd.c_str() << "\n";
  1503. }
  1504. // Add each command line to the set of commands.
  1505. for(unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c)
  1506. {
  1507. // Build the command line in a single string.
  1508. std::string cmd2 = ccg.GetCommand(c);
  1509. cmSystemTools::ReplaceString(cmd2, "/./", "/");
  1510. cmd2 = this->ConvertToRelativeForMake(cmd2.c_str());
  1511. std::string cmd;
  1512. std::string wd = ccg.GetWorkingDirectory();
  1513. if(!wd.empty())
  1514. {
  1515. cmd += "cd ";
  1516. cmd += this->ConvertToRelativeForMake(wd.c_str());
  1517. cmd += " && ";
  1518. }
  1519. cmd += cmd2;
  1520. ccg.AppendArguments(c, cmd);
  1521. makefileStream << "\t" << cmd.c_str() << "\n";
  1522. }
  1523. }
  1524. }
  1525. // Add rules to deal with multiple outputs of custom commands.
  1526. if(!multipleOutputPairs.empty())
  1527. {
  1528. makefileStream <<
  1529. "\n# Dependencies of multiple outputs to their primary outputs \n";
  1530. for(std::map<std::string, std::string>::const_iterator o =
  1531. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1532. {
  1533. makefileStream << o->first << ": " << o->second << "\n";
  1534. }
  1535. makefileStream <<
  1536. "\n"
  1537. "cmake_check_multiple_outputs:\n";
  1538. for(std::map<std::string, std::string>::const_iterator o =
  1539. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1540. {
  1541. makefileStream << "\t@if [ ! -f "
  1542. << o->first << " ]; then rm -f "
  1543. << o->second << "; fi\n";
  1544. }
  1545. }
  1546. haveMultipleOutputPairs =
  1547. haveMultipleOutputPairs || !multipleOutputPairs.empty();
  1548. }
  1549. //----------------------------------------------------------------------------
  1550. void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
  1551. cmXCodeObject* buildSettings,
  1552. const std::string& configName)
  1553. {
  1554. if(target.GetType() == cmTarget::INTERFACE_LIBRARY)
  1555. {
  1556. return;
  1557. }
  1558. std::string flags;
  1559. std::string defFlags;
  1560. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  1561. (target.GetType() == cmTarget::MODULE_LIBRARY));
  1562. bool binary = ((target.GetType() == cmTarget::OBJECT_LIBRARY) ||
  1563. (target.GetType() == cmTarget::STATIC_LIBRARY) ||
  1564. (target.GetType() == cmTarget::EXECUTABLE) ||
  1565. shared);
  1566. std::string lang = target.GetLinkerLanguage(configName);
  1567. std::string cflags;
  1568. if(!lang.empty())
  1569. {
  1570. // for c++ projects get the c flags as well
  1571. if(lang == "CXX")
  1572. {
  1573. this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName);
  1574. this->CurrentLocalGenerator->AddCMP0018Flags(cflags, &target,
  1575. "C", configName);
  1576. this->CurrentLocalGenerator->
  1577. AddCompileOptions(cflags, &target, "C", configName);
  1578. }
  1579. // Add language-specific flags.
  1580. this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName);
  1581. // Add shared-library flags if needed.
  1582. this->CurrentLocalGenerator->AddCMP0018Flags(flags, &target,
  1583. lang, configName);
  1584. this->CurrentLocalGenerator->AddVisibilityPresetFlags(flags, &target,
  1585. lang);
  1586. this->CurrentLocalGenerator->
  1587. AddCompileOptions(flags, &target, lang, configName);
  1588. }
  1589. else if(binary)
  1590. {
  1591. cmSystemTools::Error
  1592. ("CMake can not determine linker language for target: ",
  1593. target.GetName().c_str());
  1594. return;
  1595. }
  1596. // Add define flags
  1597. this->CurrentLocalGenerator->
  1598. AppendFlags(defFlags,
  1599. this->CurrentMakefile->GetDefineFlags());
  1600. // Add preprocessor definitions for this target and configuration.
  1601. BuildObjectListOrString ppDefs(this, this->XcodeVersion >= 30);
  1602. if(this->XcodeVersion > 15)
  1603. {
  1604. this->AppendDefines(ppDefs,
  1605. "CMAKE_INTDIR=\"$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)\"");
  1606. }
  1607. if(const char* exportMacro = target.GetExportMacro())
  1608. {
  1609. // Add the export symbol definition for shared library objects.
  1610. this->AppendDefines(ppDefs, exportMacro);
  1611. }
  1612. cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
  1613. std::vector<std::string> targetDefines;
  1614. target.GetCompileDefinitions(targetDefines, configName);
  1615. this->AppendDefines(ppDefs, targetDefines);
  1616. buildSettings->AddAttribute
  1617. ("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList());
  1618. std::string extraLinkOptionsVar;
  1619. std::string extraLinkOptions;
  1620. if(target.GetType() == cmTarget::EXECUTABLE)
  1621. {
  1622. extraLinkOptionsVar = "CMAKE_EXE_LINKER_FLAGS";
  1623. }
  1624. else if(target.GetType() == cmTarget::SHARED_LIBRARY)
  1625. {
  1626. extraLinkOptionsVar = "CMAKE_SHARED_LINKER_FLAGS";
  1627. }
  1628. else if(target.GetType() == cmTarget::MODULE_LIBRARY)
  1629. {
  1630. extraLinkOptionsVar = "CMAKE_MODULE_LINKER_FLAGS";
  1631. }
  1632. if(extraLinkOptionsVar.size())
  1633. {
  1634. this->CurrentLocalGenerator
  1635. ->AddConfigVariableFlags(extraLinkOptions,
  1636. extraLinkOptionsVar.c_str(),
  1637. configName);
  1638. }
  1639. if(target.GetType() == cmTarget::OBJECT_LIBRARY ||
  1640. target.GetType() == cmTarget::STATIC_LIBRARY)
  1641. {
  1642. this->CurrentLocalGenerator
  1643. ->GetStaticLibraryFlags(extraLinkOptions,
  1644. cmSystemTools::UpperCase(configName),
  1645. &target);
  1646. }
  1647. else
  1648. {
  1649. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1650. if(targetLinkFlags)
  1651. {
  1652. this->CurrentLocalGenerator->
  1653. AppendFlags(extraLinkOptions, targetLinkFlags);
  1654. }
  1655. if(!configName.empty())
  1656. {
  1657. std::string linkFlagsVar = "LINK_FLAGS_";
  1658. linkFlagsVar += cmSystemTools::UpperCase(configName);
  1659. if(const char* linkFlags = target.GetProperty(linkFlagsVar.c_str()))
  1660. {
  1661. this->CurrentLocalGenerator->
  1662. AppendFlags(extraLinkOptions, linkFlags);
  1663. }
  1664. }
  1665. }
  1666. // Set target-specific architectures.
  1667. std::vector<std::string> archs;
  1668. gtgt->GetAppleArchs(configName, archs);
  1669. if(!archs.empty())
  1670. {
  1671. // Enable ARCHS attribute.
  1672. buildSettings->AddAttribute("ONLY_ACTIVE_ARCH",
  1673. this->CreateString("NO"));
  1674. // Store ARCHS value.
  1675. if(archs.size() == 1)
  1676. {
  1677. buildSettings->AddAttribute("ARCHS",
  1678. this->CreateString(archs[0].c_str()));
  1679. }
  1680. else
  1681. {
  1682. cmXCodeObject* archObjects =
  1683. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1684. for(std::vector<std::string>::iterator i = archs.begin();
  1685. i != archs.end(); i++)
  1686. {
  1687. archObjects->AddObject(this->CreateString((*i).c_str()));
  1688. }
  1689. buildSettings->AddAttribute("ARCHS", archObjects);
  1690. }
  1691. }
  1692. // Get the product name components.
  1693. std::string pnprefix;
  1694. std::string pnbase;
  1695. std::string pnsuffix;
  1696. target.GetFullNameComponents(pnprefix, pnbase, pnsuffix, configName);
  1697. const char* version = target.GetProperty("VERSION");
  1698. const char* soversion = target.GetProperty("SOVERSION");
  1699. if(!target.HasSOName(configName) || target.IsFrameworkOnApple())
  1700. {
  1701. version = 0;
  1702. soversion = 0;
  1703. }
  1704. if(version && !soversion)
  1705. {
  1706. soversion = version;
  1707. }
  1708. if(!version && soversion)
  1709. {
  1710. version = soversion;
  1711. }
  1712. std::string realName = pnbase;
  1713. std::string soName = pnbase;
  1714. if(version && soversion)
  1715. {
  1716. realName += ".";
  1717. realName += version;
  1718. soName += ".";
  1719. soName += soversion;
  1720. }
  1721. // Set attributes to specify the proper name for the target.
  1722. std::string pndir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1723. if(target.GetType() == cmTarget::STATIC_LIBRARY ||
  1724. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1725. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1726. target.GetType() == cmTarget::EXECUTABLE)
  1727. {
  1728. if(this->XcodeVersion >= 21)
  1729. {
  1730. if(!target.UsesDefaultOutputDir(configName, false))
  1731. {
  1732. std::string pncdir = target.GetDirectory(configName);
  1733. buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR",
  1734. this->CreateString(pncdir.c_str()));
  1735. }
  1736. }
  1737. else
  1738. {
  1739. buildSettings->AddAttribute("OBJROOT",
  1740. this->CreateString(pndir.c_str()));
  1741. pndir = target.GetDirectory(configName);
  1742. }
  1743. if(target.IsFrameworkOnApple() || target.IsCFBundleOnApple())
  1744. {
  1745. pnprefix = "";
  1746. }
  1747. buildSettings->AddAttribute("EXECUTABLE_PREFIX",
  1748. this->CreateString(pnprefix.c_str()));
  1749. buildSettings->AddAttribute("EXECUTABLE_SUFFIX",
  1750. this->CreateString(pnsuffix.c_str()));
  1751. }
  1752. else if(target.GetType() == cmTarget::OBJECT_LIBRARY)
  1753. {
  1754. pnprefix = "lib";
  1755. pnbase = target.GetName();
  1756. pnsuffix = ".a";
  1757. if(this->XcodeVersion >= 21)
  1758. {
  1759. std::string pncdir = this->GetObjectsNormalDirectory(
  1760. this->CurrentProject, configName, &target);
  1761. buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR",
  1762. this->CreateString(pncdir.c_str()));
  1763. }
  1764. else
  1765. {
  1766. buildSettings->AddAttribute("OBJROOT",
  1767. this->CreateString(pndir.c_str()));
  1768. pndir = this->GetObjectsNormalDirectory(
  1769. this->CurrentProject, configName, &target);
  1770. }
  1771. }
  1772. // Store the product name for all target types.
  1773. buildSettings->AddAttribute("PRODUCT_NAME",
  1774. this->CreateString(realName.c_str()));
  1775. buildSettings->AddAttribute("SYMROOT",
  1776. this->CreateString(pndir.c_str()));
  1777. // Handle settings for each target type.
  1778. switch(target.GetType())
  1779. {
  1780. case cmTarget::OBJECT_LIBRARY:
  1781. case cmTarget::STATIC_LIBRARY:
  1782. {
  1783. buildSettings->AddAttribute("LIBRARY_STYLE",
  1784. this->CreateString("STATIC"));
  1785. break;
  1786. }
  1787. case cmTarget::MODULE_LIBRARY:
  1788. {
  1789. buildSettings->AddAttribute("LIBRARY_STYLE",
  1790. this->CreateString("BUNDLE"));
  1791. if (target.GetPropertyAsBool("BUNDLE"))
  1792. {
  1793. // It turns out that a BUNDLE is basically the same
  1794. // in many ways as an application bundle, as far as
  1795. // link flags go
  1796. std::string createFlags =
  1797. this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
  1798. "-bundle");
  1799. if(!createFlags.empty())
  1800. {
  1801. extraLinkOptions += " ";
  1802. extraLinkOptions += createFlags;
  1803. }
  1804. std::string plist = this->ComputeInfoPListLocation(target);
  1805. // Xcode will create the final version of Info.plist at build time,
  1806. // so let it replace the cfbundle name. This avoids creating
  1807. // a per-configuration Info.plist file. The cfbundle plist
  1808. // is very similar to the application bundle plist
  1809. this->CurrentLocalGenerator
  1810. ->GenerateAppleInfoPList(&target, "$(EXECUTABLE_NAME)",
  1811. plist.c_str());
  1812. std::string path =
  1813. this->ConvertToRelativeForXCode(plist.c_str());
  1814. buildSettings->AddAttribute("INFOPLIST_FILE",
  1815. this->CreateString(path.c_str()));
  1816. }
  1817. else if(this->XcodeVersion >= 22)
  1818. {
  1819. buildSettings->AddAttribute("MACH_O_TYPE",
  1820. this->CreateString("mh_bundle"));
  1821. buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
  1822. this->CreateString("NO"));
  1823. // Add the flags to create an executable.
  1824. std::string createFlags =
  1825. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1826. if(!createFlags.empty())
  1827. {
  1828. extraLinkOptions += " ";
  1829. extraLinkOptions += createFlags;
  1830. }
  1831. }
  1832. else
  1833. {
  1834. // Add the flags to create a module.
  1835. std::string createFlags =
  1836. this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
  1837. "-bundle");
  1838. if(!createFlags.empty())
  1839. {
  1840. extraLinkOptions += " ";
  1841. extraLinkOptions += createFlags;
  1842. }
  1843. }
  1844. break;
  1845. }
  1846. case cmTarget::SHARED_LIBRARY:
  1847. {
  1848. if(target.GetPropertyAsBool("FRAMEWORK"))
  1849. {
  1850. std::string fw_version = target.GetFrameworkVersion();
  1851. buildSettings->AddAttribute("FRAMEWORK_VERSION",
  1852. this->CreateString(fw_version.c_str()));
  1853. std::string plist = this->ComputeInfoPListLocation(target);
  1854. // Xcode will create the final version of Info.plist at build time,
  1855. // so let it replace the framework name. This avoids creating
  1856. // a per-configuration Info.plist file.
  1857. this->CurrentLocalGenerator
  1858. ->GenerateFrameworkInfoPList(&target, "$(EXECUTABLE_NAME)",
  1859. plist.c_str());
  1860. std::string path =
  1861. this->ConvertToRelativeForXCode(plist.c_str());
  1862. buildSettings->AddAttribute("INFOPLIST_FILE",
  1863. this->CreateString(path.c_str()));
  1864. }
  1865. else
  1866. {
  1867. // Add the flags to create a shared library.
  1868. std::string createFlags =
  1869. this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", lang, "_FLAGS",
  1870. "-dynamiclib");
  1871. if(!createFlags.empty())
  1872. {
  1873. extraLinkOptions += " ";
  1874. extraLinkOptions += createFlags;
  1875. }
  1876. }
  1877. buildSettings->AddAttribute("LIBRARY_STYLE",
  1878. this->CreateString("DYNAMIC"));
  1879. break;
  1880. }
  1881. case cmTarget::EXECUTABLE:
  1882. {
  1883. // Add the flags to create an executable.
  1884. std::string createFlags =
  1885. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1886. if(!createFlags.empty())
  1887. {
  1888. extraLinkOptions += " ";
  1889. extraLinkOptions += createFlags;
  1890. }
  1891. // Handle bundles and normal executables separately.
  1892. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  1893. {
  1894. std::string plist = this->ComputeInfoPListLocation(target);
  1895. // Xcode will create the final version of Info.plist at build time,
  1896. // so let it replace the executable name. This avoids creating
  1897. // a per-configuration Info.plist file.
  1898. this->CurrentLocalGenerator
  1899. ->GenerateAppleInfoPList(&target, "$(EXECUTABLE_NAME)",
  1900. plist.c_str());
  1901. std::string path =
  1902. this->ConvertToRelativeForXCode(plist.c_str());
  1903. buildSettings->AddAttribute("INFOPLIST_FILE",
  1904. this->CreateString(path.c_str()));
  1905. }
  1906. }
  1907. break;
  1908. default:
  1909. break;
  1910. }
  1911. if(this->XcodeVersion >= 22 && this->XcodeVersion < 40)
  1912. {
  1913. buildSettings->AddAttribute("PREBINDING",
  1914. this->CreateString("NO"));
  1915. }
  1916. BuildObjectListOrString dirs(this, this->XcodeVersion >= 30);
  1917. BuildObjectListOrString fdirs(this, this->XcodeVersion >= 30);
  1918. std::vector<std::string> includes;
  1919. this->CurrentLocalGenerator->GetIncludeDirectories(includes, gtgt,
  1920. "C", configName);
  1921. std::set<std::string> emitted;
  1922. emitted.insert("/System/Library/Frameworks");
  1923. for(std::vector<std::string>::iterator i = includes.begin();
  1924. i != includes.end(); ++i)
  1925. {
  1926. if(this->NameResolvesToFramework(i->c_str()))
  1927. {
  1928. std::string frameworkDir = *i;
  1929. frameworkDir += "/../";
  1930. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1931. if(emitted.insert(frameworkDir).second)
  1932. {
  1933. fdirs.Add(this->XCodeEscapePath(frameworkDir.c_str()).c_str());
  1934. }
  1935. }
  1936. else
  1937. {
  1938. std::string incpath =
  1939. this->XCodeEscapePath(i->c_str());
  1940. dirs.Add(incpath.c_str());
  1941. }
  1942. }
  1943. // Add framework search paths needed for linking.
  1944. if(cmComputeLinkInformation* cli = target.GetLinkInformation(configName))
  1945. {
  1946. std::vector<std::string> const& fwDirs = cli->GetFrameworkPaths();
  1947. for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1948. fdi != fwDirs.end(); ++fdi)
  1949. {
  1950. if(emitted.insert(*fdi).second)
  1951. {
  1952. fdirs.Add(this->XCodeEscapePath(fdi->c_str()).c_str());
  1953. }
  1954. }
  1955. }
  1956. if(!fdirs.IsEmpty())
  1957. {
  1958. buildSettings->AddAttribute("FRAMEWORK_SEARCH_PATHS",
  1959. fdirs.CreateList());
  1960. }
  1961. if(!dirs.IsEmpty())
  1962. {
  1963. buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
  1964. dirs.CreateList());
  1965. }
  1966. std::string oflagc = this->ExtractFlag("-O", cflags);
  1967. char optLevel[2];
  1968. optLevel[0] = '0';
  1969. optLevel[1] = 0;
  1970. if(oflagc.size() == 3)
  1971. {
  1972. optLevel[0] = oflagc[2];
  1973. }
  1974. if(oflagc.size() == 2)
  1975. {
  1976. optLevel[0] = '1';
  1977. }
  1978. std::string oflag = this->ExtractFlag("-O", flags);
  1979. if(oflag.size() == 3)
  1980. {
  1981. optLevel[0] = oflag[2];
  1982. }
  1983. if(oflag.size() == 2)
  1984. {
  1985. optLevel[0] = '1';
  1986. }
  1987. std::string gflagc = this->ExtractFlag("-g", cflags);
  1988. // put back gdwarf-2 if used since there is no way
  1989. // to represent it in the gui, but we still want debug yes
  1990. if(gflagc == "-gdwarf-2")
  1991. {
  1992. cflags += " ";
  1993. cflags += gflagc;
  1994. }
  1995. std::string gflag = this->ExtractFlag("-g", flags);
  1996. if(gflag == "-gdwarf-2")
  1997. {
  1998. flags += " ";
  1999. flags += gflag;
  2000. }
  2001. const char* debugStr = "YES";
  2002. // We can't set the Xcode flag differently depending on the language,
  2003. // so put them back in this case.
  2004. if( (lang == "CXX") && gflag != gflagc )
  2005. {
  2006. cflags += " ";
  2007. cflags += gflagc;
  2008. flags += " ";
  2009. flags += gflag;
  2010. debugStr = "NO";
  2011. }
  2012. if( gflag == "-g0" || gflag.size() == 0 )
  2013. {
  2014. debugStr = "NO";
  2015. }
  2016. buildSettings->AddAttribute("COMBINE_HIDPI_IMAGES",
  2017. this->CreateString("YES"));
  2018. buildSettings->AddAttribute("GCC_GENERATE_DEBUGGING_SYMBOLS",
  2019. this->CreateString(debugStr));
  2020. buildSettings->AddAttribute("GCC_OPTIMIZATION_LEVEL",
  2021. this->CreateString(optLevel));
  2022. buildSettings->AddAttribute("GCC_SYMBOLS_PRIVATE_EXTERN",
  2023. this->CreateString("NO"));
  2024. buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
  2025. this->CreateString("NO"));
  2026. if(lang == "CXX")
  2027. {
  2028. flags += " ";
  2029. flags += defFlags;
  2030. buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
  2031. this->CreateString(flags.c_str()));
  2032. cflags += " ";
  2033. cflags += defFlags;
  2034. buildSettings->AddAttribute("OTHER_CFLAGS",
  2035. this->CreateString(cflags.c_str()));
  2036. }
  2037. else
  2038. {
  2039. flags += " ";
  2040. flags += defFlags;
  2041. buildSettings->AddAttribute("OTHER_CFLAGS",
  2042. this->CreateString(flags.c_str()));
  2043. }
  2044. // Add Fortran source format attribute if property is set.
  2045. const char* format = 0;
  2046. const char* tgtfmt = target.GetProperty("Fortran_FORMAT");
  2047. switch(this->CurrentLocalGenerator->GetFortranFormat(tgtfmt))
  2048. {
  2049. case cmLocalGenerator::FortranFormatFixed: format = "fixed"; break;
  2050. case cmLocalGenerator::FortranFormatFree: format = "free"; break;
  2051. default: break;
  2052. }
  2053. if(format)
  2054. {
  2055. buildSettings->AddAttribute("IFORT_LANG_SRCFMT",
  2056. this->CreateString(format));
  2057. }
  2058. // Create the INSTALL_PATH attribute.
  2059. std::string install_name_dir;
  2060. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  2061. {
  2062. // Get the install_name directory for the build tree.
  2063. install_name_dir = target.GetInstallNameDirForBuildTree(configName);
  2064. // Xcode doesn't create the correct install_name in some cases.
  2065. // That is, if the INSTALL_PATH is empty, or if we have versioning
  2066. // of dylib libraries, we want to specify the install_name.
  2067. // This is done by adding a link flag to create an install_name
  2068. // with just the library soname.
  2069. std::string install_name;
  2070. if(!install_name_dir.empty())
  2071. {
  2072. // Convert to a path for the native build tool.
  2073. cmSystemTools::ConvertToUnixSlashes(install_name_dir);
  2074. install_name += install_name_dir;
  2075. install_name += "/";
  2076. }
  2077. install_name += target.GetSOName(configName);
  2078. if((realName != soName) || install_name_dir.empty())
  2079. {
  2080. install_name_dir = "";
  2081. extraLinkOptions += " -install_name ";
  2082. extraLinkOptions += XCodeEscapePath(install_name.c_str());
  2083. }
  2084. }
  2085. buildSettings->AddAttribute("INSTALL_PATH",
  2086. this->CreateString(install_name_dir.c_str()));
  2087. // Create the LD_RUNPATH_SEARCH_PATHS
  2088. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  2089. if(pcli)
  2090. {
  2091. std::string search_paths;
  2092. std::vector<std::string> runtimeDirs;
  2093. pcli->GetRPath(runtimeDirs, false);
  2094. // runpath dirs needs to be unique to prevent corruption
  2095. std::set<std::string> unique_dirs;
  2096. for(std::vector<std::string>::const_iterator i = runtimeDirs.begin();
  2097. i != runtimeDirs.end(); ++i)
  2098. {
  2099. std::string runpath = *i;
  2100. runpath = this->ExpandCFGIntDir(runpath, configName);
  2101. if(unique_dirs.find(runpath) == unique_dirs.end())
  2102. {
  2103. unique_dirs.insert(runpath);
  2104. if(!search_paths.empty())
  2105. {
  2106. search_paths += " ";
  2107. }
  2108. search_paths += this->XCodeEscapePath(runpath.c_str());
  2109. }
  2110. }
  2111. if(!search_paths.empty())
  2112. {
  2113. buildSettings->AddAttribute("LD_RUNPATH_SEARCH_PATHS",
  2114. this->CreateString(search_paths.c_str()));
  2115. }
  2116. }
  2117. buildSettings->AddAttribute("OTHER_LDFLAGS",
  2118. this->CreateString(extraLinkOptions.c_str()));
  2119. buildSettings->AddAttribute("OTHER_REZFLAGS",
  2120. this->CreateString(""));
  2121. buildSettings->AddAttribute("SECTORDER_FLAGS",
  2122. this->CreateString(""));
  2123. buildSettings->AddAttribute("USE_HEADERMAP",
  2124. this->CreateString("NO"));
  2125. if (this->XcodeVersion >= 30)
  2126. {
  2127. cmXCodeObject *group = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2128. group->AddObject(this->CreateString("-Wmost"));
  2129. group->AddObject(this->CreateString("-Wno-four-char-constants"));
  2130. group->AddObject(this->CreateString("-Wno-unknown-pragmas"));
  2131. buildSettings->AddAttribute("WARNING_CFLAGS", group);
  2132. }
  2133. else
  2134. {
  2135. buildSettings->AddAttribute("WARNING_CFLAGS",
  2136. this->CreateString(
  2137. "-Wmost -Wno-four-char-constants"
  2138. " -Wno-unknown-pragmas"));
  2139. }
  2140. // Runtime version information.
  2141. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  2142. {
  2143. int major;
  2144. int minor;
  2145. int patch;
  2146. // VERSION -> current_version
  2147. target.GetTargetVersion(false, major, minor, patch);
  2148. cmOStringStream v;
  2149. // Xcode always wants at least 1.0.0 or nothing
  2150. if(!(major == 0 && minor == 0 && patch == 0))
  2151. {
  2152. v << major << "." << minor << "." << patch;
  2153. }
  2154. buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
  2155. this->CreateString(v.str().c_str()));
  2156. // SOVERSION -> compatibility_version
  2157. target.GetTargetVersion(true, major, minor, patch);
  2158. cmOStringStream vso;
  2159. // Xcode always wants at least 1.0.0 or nothing
  2160. if(!(major == 0 && minor == 0 && patch == 0))
  2161. {
  2162. vso << major << "." << minor << "." << patch;
  2163. }
  2164. buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
  2165. this->CreateString(vso.str().c_str()));
  2166. }
  2167. // put this last so it can override existing settings
  2168. // Convert "XCODE_ATTRIBUTE_*" properties directly.
  2169. {
  2170. cmPropertyMap const& props = target.GetProperties();
  2171. for(cmPropertyMap::const_iterator i = props.begin();
  2172. i != props.end(); ++i)
  2173. {
  2174. if(i->first.find("XCODE_ATTRIBUTE_") == 0)
  2175. {
  2176. std::string attribute = i->first.substr(16);
  2177. // Handle [variant=<config>] condition explicitly here.
  2178. std::string::size_type beginVariant =
  2179. attribute.find("[variant=");
  2180. if (beginVariant != std::string::npos)
  2181. {
  2182. std::string::size_type endVariant =
  2183. attribute.find("]", beginVariant+9);
  2184. if (endVariant != std::string::npos)
  2185. {
  2186. // Compare the variant to the configuration.
  2187. std::string variant =
  2188. attribute.substr(beginVariant+9, endVariant-beginVariant-9);
  2189. if (variant == configName)
  2190. {
  2191. // The variant matches the configuration so use this
  2192. // attribute but drop the [variant=<config>] condition.
  2193. attribute.erase(beginVariant, endVariant-beginVariant+1);
  2194. }
  2195. else
  2196. {
  2197. // The variant does not match the configuration so
  2198. // do not use this attribute.
  2199. attribute.clear();
  2200. }
  2201. }
  2202. }
  2203. if (!attribute.empty())
  2204. {
  2205. buildSettings->AddAttribute(attribute.c_str(),
  2206. this->CreateString(i->second.GetValue()));
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. //----------------------------------------------------------------------------
  2213. cmXCodeObject*
  2214. cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
  2215. {
  2216. cmXCodeObject* shellBuildPhase =
  2217. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  2218. shellBuildPhase->AddAttribute("buildActionMask",
  2219. this->CreateString("2147483647"));
  2220. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2221. shellBuildPhase->AddAttribute("files", buildFiles);
  2222. cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2223. shellBuildPhase->AddAttribute("inputPaths", inputPaths);
  2224. cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2225. shellBuildPhase->AddAttribute("outputPaths", outputPaths);
  2226. shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  2227. this->CreateString("0"));
  2228. shellBuildPhase->AddAttribute("shellPath",
  2229. this->CreateString("/bin/sh"));
  2230. shellBuildPhase->AddAttribute("shellScript",
  2231. this->CreateString(
  2232. "# shell script goes here\nexit 0"));
  2233. shellBuildPhase->AddAttribute("showEnvVarsInLog",
  2234. this->CreateString("0"));
  2235. cmXCodeObject* target =
  2236. this->CreateObject(cmXCodeObject::PBXAggregateTarget);
  2237. target->SetComment(cmtarget.GetName().c_str());
  2238. cmXCodeObject* buildPhases =
  2239. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2240. std::vector<cmXCodeObject*> emptyContentVector;
  2241. this->CreateCustomCommands(buildPhases, 0, 0, 0, emptyContentVector, 0,
  2242. cmtarget);
  2243. target->AddAttribute("buildPhases", buildPhases);
  2244. if(this->XcodeVersion > 20)
  2245. {
  2246. this->AddConfigurations(target, cmtarget);
  2247. }
  2248. else
  2249. {
  2250. const char* theConfig =
  2251. this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
  2252. cmXCodeObject* buildSettings =
  2253. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2254. this->CreateBuildSettings(cmtarget, buildSettings, theConfig);
  2255. target->AddAttribute("buildSettings", buildSettings);
  2256. }
  2257. cmXCodeObject* dependencies =
  2258. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2259. target->AddAttribute("dependencies", dependencies);
  2260. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  2261. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  2262. target->SetTarget(&cmtarget);
  2263. // Add source files without build rules for editing convenience.
  2264. if(cmtarget.GetType() == cmTarget::UTILITY)
  2265. {
  2266. std::vector<cmSourceFile*> sources;
  2267. cmtarget.GetSourceFiles(sources);
  2268. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  2269. i != sources.end(); ++i)
  2270. {
  2271. if(!(*i)->GetPropertyAsBool("GENERATED"))
  2272. {
  2273. this->CreateXCodeFileReference(*i, cmtarget);
  2274. }
  2275. }
  2276. }
  2277. target->SetId(this->GetOrCreateId(
  2278. cmtarget.GetName(), target->GetId()).c_str());
  2279. return target;
  2280. }
  2281. //----------------------------------------------------------------------------
  2282. std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
  2283. cmTarget& cmtarget)
  2284. {
  2285. std::string configTypes =
  2286. this->CurrentMakefile->GetRequiredDefinition("CMAKE_CONFIGURATION_TYPES");
  2287. std::vector<std::string> configVectorIn;
  2288. std::vector<std::string> configVector;
  2289. configVectorIn.push_back(configTypes);
  2290. cmSystemTools::ExpandList(configVectorIn, configVector);
  2291. cmXCodeObject* configlist =
  2292. this->CreateObject(cmXCodeObject::XCConfigurationList);
  2293. cmXCodeObject* buildConfigurations =
  2294. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2295. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  2296. std::string comment = "Build configuration list for ";
  2297. comment += cmXCodeObject::PBXTypeNames[target->GetIsA()];
  2298. comment += " \"";
  2299. comment += cmtarget.GetName();
  2300. comment += "\"";
  2301. configlist->SetComment(comment.c_str());
  2302. target->AddAttribute("buildConfigurationList",
  2303. this->CreateObjectReference(configlist));
  2304. for(unsigned int i = 0; i < configVector.size(); ++i)
  2305. {
  2306. cmXCodeObject* config =
  2307. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  2308. buildConfigurations->AddObject(config);
  2309. cmXCodeObject* buildSettings =
  2310. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2311. this->CreateBuildSettings(cmtarget, buildSettings,
  2312. configVector[i].c_str());
  2313. config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
  2314. config->SetComment(configVector[i].c_str());
  2315. config->AddAttribute("buildSettings", buildSettings);
  2316. }
  2317. if(configVector.size())
  2318. {
  2319. configlist->AddAttribute("defaultConfigurationName",
  2320. this->CreateString(configVector[0].c_str()));
  2321. configlist->AddAttribute("defaultConfigurationIsVisible",
  2322. this->CreateString("0"));
  2323. return configVector[0];
  2324. }
  2325. return "";
  2326. }
  2327. //----------------------------------------------------------------------------
  2328. const char* cmGlobalXCodeGenerator::GetTargetFileType(cmTarget& cmtarget)
  2329. {
  2330. switch(cmtarget.GetType())
  2331. {
  2332. case cmTarget::OBJECT_LIBRARY:
  2333. case cmTarget::STATIC_LIBRARY:
  2334. return "archive.ar";
  2335. case cmTarget::MODULE_LIBRARY:
  2336. if (cmtarget.IsCFBundleOnApple())
  2337. return "wrapper.plug-in";
  2338. else
  2339. return ((this->XcodeVersion >= 22)?
  2340. "compiled.mach-o.executable" : "compiled.mach-o.dylib");
  2341. case cmTarget::SHARED_LIBRARY:
  2342. return (cmtarget.GetPropertyAsBool("FRAMEWORK")?
  2343. "wrapper.framework" : "compiled.mach-o.dylib");
  2344. case cmTarget::EXECUTABLE:
  2345. return "compiled.mach-o.executable";
  2346. default: break;
  2347. }
  2348. return 0;
  2349. }
  2350. //----------------------------------------------------------------------------
  2351. const char* cmGlobalXCodeGenerator::GetTargetProductType(cmTarget& cmtarget)
  2352. {
  2353. switch(cmtarget.GetType())
  2354. {
  2355. case cmTarget::OBJECT_LIBRARY:
  2356. case cmTarget::STATIC_LIBRARY:
  2357. return "com.apple.product-type.library.static";
  2358. case cmTarget::MODULE_LIBRARY:
  2359. if (cmtarget.IsCFBundleOnApple())
  2360. return "com.apple.product-type.bundle";
  2361. else
  2362. return ((this->XcodeVersion >= 22)?
  2363. "com.apple.product-type.tool" :
  2364. "com.apple.product-type.library.dynamic");
  2365. case cmTarget::SHARED_LIBRARY:
  2366. return (cmtarget.GetPropertyAsBool("FRAMEWORK")?
  2367. "com.apple.product-type.framework" :
  2368. "com.apple.product-type.library.dynamic");
  2369. case cmTarget::EXECUTABLE:
  2370. return (cmtarget.GetPropertyAsBool("MACOSX_BUNDLE")?
  2371. "com.apple.product-type.application" :
  2372. "com.apple.product-type.tool");
  2373. default: break;
  2374. }
  2375. return 0;
  2376. }
  2377. //----------------------------------------------------------------------------
  2378. cmXCodeObject*
  2379. cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
  2380. cmXCodeObject* buildPhases)
  2381. {
  2382. if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
  2383. {
  2384. return 0;
  2385. }
  2386. cmXCodeObject* target =
  2387. this->CreateObject(cmXCodeObject::PBXNativeTarget);
  2388. target->AddAttribute("buildPhases", buildPhases);
  2389. cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2390. target->AddAttribute("buildRules", buildRules);
  2391. std::string defConfig;
  2392. if(this->XcodeVersion > 20)
  2393. {
  2394. defConfig = this->AddConfigurations(target, cmtarget);
  2395. }
  2396. else
  2397. {
  2398. cmXCodeObject* buildSettings =
  2399. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2400. defConfig = this->CurrentMakefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  2401. this->CreateBuildSettings(cmtarget, buildSettings, defConfig.c_str());
  2402. target->AddAttribute("buildSettings", buildSettings);
  2403. }
  2404. cmXCodeObject* dependencies =
  2405. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2406. target->AddAttribute("dependencies", dependencies);
  2407. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  2408. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  2409. cmXCodeObject* fileRef =
  2410. this->CreateObject(cmXCodeObject::PBXFileReference);
  2411. if(const char* fileType = this->GetTargetFileType(cmtarget))
  2412. {
  2413. fileRef->AddAttribute("explicitFileType", this->CreateString(fileType));
  2414. }
  2415. std::string fullName;
  2416. if(cmtarget.GetType() == cmTarget::OBJECT_LIBRARY)
  2417. {
  2418. fullName = "lib";
  2419. fullName += cmtarget.GetName();
  2420. fullName += ".a";
  2421. }
  2422. else
  2423. {
  2424. fullName = cmtarget.GetFullName(defConfig.c_str());
  2425. }
  2426. fileRef->AddAttribute("path", this->CreateString(fullName.c_str()));
  2427. fileRef->AddAttribute("refType", this->CreateString("0"));
  2428. fileRef->AddAttribute("sourceTree",
  2429. this->CreateString("BUILT_PRODUCTS_DIR"));
  2430. fileRef->SetComment(cmtarget.GetName().c_str());
  2431. target->AddAttribute("productReference",
  2432. this->CreateObjectReference(fileRef));
  2433. if(const char* productType = this->GetTargetProductType(cmtarget))
  2434. {
  2435. target->AddAttribute("productType", this->CreateString(productType));
  2436. }
  2437. target->SetTarget(&cmtarget);
  2438. target->SetId(this->GetOrCreateId(
  2439. cmtarget.GetName(), target->GetId()).c_str());
  2440. return target;
  2441. }
  2442. //----------------------------------------------------------------------------
  2443. cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget const* t)
  2444. {
  2445. if(!t)
  2446. {
  2447. return 0;
  2448. }
  2449. for(std::vector<cmXCodeObject*>::iterator i = this->XCodeObjects.begin();
  2450. i != this->XCodeObjects.end(); ++i)
  2451. {
  2452. cmXCodeObject* o = *i;
  2453. if(o->GetTarget() == t)
  2454. {
  2455. return o;
  2456. }
  2457. }
  2458. return 0;
  2459. }
  2460. //----------------------------------------------------------------------------
  2461. std::string cmGlobalXCodeGenerator::GetOrCreateId(const std::string& name,
  2462. const std::string& id)
  2463. {
  2464. std::string guidStoreName = name;
  2465. guidStoreName += "_GUID_CMAKE";
  2466. const char* storedGUID =
  2467. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  2468. if(storedGUID)
  2469. {
  2470. return storedGUID;
  2471. }
  2472. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
  2473. id.c_str(), "Stored Xcode object GUID", cmCacheManager::INTERNAL);
  2474. return id;
  2475. }
  2476. //----------------------------------------------------------------------------
  2477. void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
  2478. cmXCodeObject* dependTarget)
  2479. {
  2480. // This is called once for every edge in the target dependency graph.
  2481. cmXCodeObject* container =
  2482. this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
  2483. container->SetComment("PBXContainerItemProxy");
  2484. container->AddAttribute("containerPortal",
  2485. this->CreateObjectReference(this->RootObject));
  2486. container->AddAttribute("proxyType", this->CreateString("1"));
  2487. container->AddAttribute("remoteGlobalIDString",
  2488. this->CreateObjectReference(dependTarget));
  2489. container->AddAttribute("remoteInfo",
  2490. this->CreateString(
  2491. dependTarget->GetTarget()->GetName()));
  2492. cmXCodeObject* targetdep =
  2493. this->CreateObject(cmXCodeObject::PBXTargetDependency);
  2494. targetdep->SetComment("PBXTargetDependency");
  2495. targetdep->AddAttribute("target",
  2496. this->CreateObjectReference(dependTarget));
  2497. targetdep->AddAttribute("targetProxy",
  2498. this->CreateObjectReference(container));
  2499. cmXCodeObject* depends = target->GetObject("dependencies");
  2500. if(!depends)
  2501. {
  2502. cmSystemTools::
  2503. Error("target does not have dependencies attribute error..");
  2504. }
  2505. else
  2506. {
  2507. depends->AddUniqueObject(targetdep);
  2508. }
  2509. }
  2510. //----------------------------------------------------------------------------
  2511. void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings,
  2512. const char* attribute,
  2513. const char* value)
  2514. {
  2515. if(settings)
  2516. {
  2517. cmXCodeObject* attr = settings->GetObject(attribute);
  2518. if(!attr)
  2519. {
  2520. settings->AddAttribute(attribute, this->CreateString(value));
  2521. }
  2522. else
  2523. {
  2524. std::string oldValue = attr->GetString();
  2525. oldValue += " ";
  2526. oldValue += value;
  2527. attr->SetString(oldValue.c_str());
  2528. }
  2529. }
  2530. }
  2531. //----------------------------------------------------------------------------
  2532. void cmGlobalXCodeGenerator
  2533. ::AppendBuildSettingAttribute(cmXCodeObject* target,
  2534. const char* attribute,
  2535. const char* value,
  2536. const std::string& configName)
  2537. {
  2538. if(this->XcodeVersion < 21)
  2539. {
  2540. // There is only one configuration. Add the setting to the buildSettings
  2541. // of the target.
  2542. this->AppendOrAddBuildSetting(target->GetObject("buildSettings"),
  2543. attribute, value);
  2544. }
  2545. else
  2546. {
  2547. // There are multiple configurations. Add the setting to the
  2548. // buildSettings of the configuration name given.
  2549. cmXCodeObject* configurationList =
  2550. target->GetObject("buildConfigurationList")->GetObject();
  2551. cmXCodeObject* buildConfigs =
  2552. configurationList->GetObject("buildConfigurations");
  2553. std::vector<cmXCodeObject*> list = buildConfigs->GetObjectList();
  2554. // each configuration and the target itself has a buildSettings in it
  2555. //list.push_back(target);
  2556. for(std::vector<cmXCodeObject*>::iterator i = list.begin();
  2557. i != list.end(); ++i)
  2558. {
  2559. if(!configName.empty())
  2560. {
  2561. if((*i)->GetObject("name")->GetString() == configName)
  2562. {
  2563. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  2564. this->AppendOrAddBuildSetting(settings, attribute, value);
  2565. }
  2566. }
  2567. else
  2568. {
  2569. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  2570. this->AppendOrAddBuildSetting(settings, attribute, value);
  2571. }
  2572. }
  2573. }
  2574. }
  2575. //----------------------------------------------------------------------------
  2576. void cmGlobalXCodeGenerator
  2577. ::AddDependAndLinkInformation(cmXCodeObject* target)
  2578. {
  2579. cmTarget* cmtarget = target->GetTarget();
  2580. if(cmtarget->GetType() == cmTarget::INTERFACE_LIBRARY)
  2581. {
  2582. return;
  2583. }
  2584. if(!cmtarget)
  2585. {
  2586. cmSystemTools::Error("Error no target on xobject\n");
  2587. return;
  2588. }
  2589. // Add dependencies on other CMake targets.
  2590. TargetDependSet const& deps = this->GetTargetDirectDepends(*cmtarget);
  2591. for(TargetDependSet::const_iterator i = deps.begin(); i != deps.end(); ++i)
  2592. {
  2593. if(cmXCodeObject* dptarget = this->FindXCodeTarget(*i))
  2594. {
  2595. this->AddDependTarget(target, dptarget);
  2596. }
  2597. }
  2598. // Loop over configuration types and set per-configuration info.
  2599. for(std::vector<std::string>::iterator i =
  2600. this->CurrentConfigurationTypes.begin();
  2601. i != this->CurrentConfigurationTypes.end(); ++i)
  2602. {
  2603. // Get the current configuration name.
  2604. const char* configName = i->c_str();
  2605. if(!*configName)
  2606. {
  2607. configName = 0;
  2608. }
  2609. if(this->XcodeVersion >= 50)
  2610. {
  2611. // Add object library contents as link flags.
  2612. std::string linkObjs;
  2613. const char* sep = "";
  2614. std::vector<std::string> objs;
  2615. this->GetGeneratorTarget(cmtarget)->UseObjectLibraries(objs);
  2616. for(std::vector<std::string>::const_iterator
  2617. oi = objs.begin(); oi != objs.end(); ++oi)
  2618. {
  2619. linkObjs += sep;
  2620. sep = " ";
  2621. linkObjs += this->XCodeEscapePath(oi->c_str());
  2622. }
  2623. this->AppendBuildSettingAttribute(target, "OTHER_LDFLAGS",
  2624. linkObjs.c_str(), configName);
  2625. }
  2626. // Skip link information for object libraries.
  2627. if(cmtarget->GetType() == cmTarget::OBJECT_LIBRARY ||
  2628. cmtarget->GetType() == cmTarget::STATIC_LIBRARY)
  2629. {
  2630. continue;
  2631. }
  2632. // Compute the link library and directory information.
  2633. cmComputeLinkInformation* pcli = cmtarget->GetLinkInformation(configName);
  2634. if(!pcli)
  2635. {
  2636. continue;
  2637. }
  2638. cmComputeLinkInformation& cli = *pcli;
  2639. // Add dependencies directly on library files.
  2640. {
  2641. std::vector<std::string> const& libDeps = cli.GetDepends();
  2642. for(std::vector<std::string>::const_iterator j = libDeps.begin();
  2643. j != libDeps.end(); ++j)
  2644. {
  2645. target->AddDependLibrary(configName, j->c_str());
  2646. }
  2647. }
  2648. // add the library search paths
  2649. {
  2650. std::vector<std::string> const& libDirs = cli.GetDirectories();
  2651. std::string linkDirs;
  2652. for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
  2653. libDir != libDirs.end(); ++libDir)
  2654. {
  2655. if(libDir->size() && *libDir != "/usr/lib")
  2656. {
  2657. if(this->XcodeVersion > 15)
  2658. {
  2659. // Now add the same one but append
  2660. // $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) to it:
  2661. linkDirs += " ";
  2662. linkDirs += this->XCodeEscapePath(
  2663. (*libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)").c_str());
  2664. }
  2665. linkDirs += " ";
  2666. linkDirs += this->XCodeEscapePath(libDir->c_str());
  2667. }
  2668. }
  2669. this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS",
  2670. linkDirs.c_str(), configName);
  2671. }
  2672. // now add the link libraries
  2673. {
  2674. std::string linkLibs;
  2675. const char* sep = "";
  2676. typedef cmComputeLinkInformation::ItemVector ItemVector;
  2677. ItemVector const& libNames = cli.GetItems();
  2678. for(ItemVector::const_iterator li = libNames.begin();
  2679. li != libNames.end(); ++li)
  2680. {
  2681. linkLibs += sep;
  2682. sep = " ";
  2683. if(li->IsPath)
  2684. {
  2685. linkLibs += this->XCodeEscapePath(li->Value.c_str());
  2686. }
  2687. else if (!li->Target
  2688. || li->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  2689. {
  2690. linkLibs += li->Value;
  2691. }
  2692. if(li->Target && !li->Target->IsImported())
  2693. {
  2694. target->AddDependTarget(configName, li->Target->GetName());
  2695. }
  2696. }
  2697. this->AppendBuildSettingAttribute(target, "OTHER_LDFLAGS",
  2698. linkLibs.c_str(), configName);
  2699. }
  2700. }
  2701. }
  2702. //----------------------------------------------------------------------------
  2703. void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
  2704. std::vector<cmLocalGenerator*>&
  2705. generators)
  2706. {
  2707. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  2708. i != generators.end(); ++i)
  2709. {
  2710. if(this->IsExcluded(root, *i))
  2711. {
  2712. continue;
  2713. }
  2714. cmMakefile* mf = (*i)->GetMakefile();
  2715. std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
  2716. cmTargets &tgts = mf->GetTargets();
  2717. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  2718. {
  2719. cmTarget& cmtarget = l->second;
  2720. // Same skipping logic here as in CreateXCodeTargets so that we do not
  2721. // end up with (empty anyhow) ALL_BUILD and XCODE_DEPEND_HELPER source
  2722. // groups:
  2723. //
  2724. if(cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
  2725. {
  2726. continue;
  2727. }
  2728. if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
  2729. {
  2730. continue;
  2731. }
  2732. // add the soon to be generated Info.plist file as a source for a
  2733. // MACOSX_BUNDLE file
  2734. if(cmtarget.GetPropertyAsBool("MACOSX_BUNDLE"))
  2735. {
  2736. std::string plist = this->ComputeInfoPListLocation(cmtarget);
  2737. mf->GetOrCreateSource(plist, true);
  2738. cmtarget.AddSource(plist);
  2739. }
  2740. std::vector<cmSourceFile*> classes;
  2741. cmtarget.GetSourceFiles(classes);
  2742. // Put cmSourceFile instances in proper groups:
  2743. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  2744. s != classes.end(); s++)
  2745. {
  2746. cmSourceFile* sf = *s;
  2747. // Add the file to the list of sources.
  2748. std::string const& source = sf->GetFullPath();
  2749. cmSourceGroup* sourceGroup =
  2750. mf->FindSourceGroup(source.c_str(), sourceGroups);
  2751. cmXCodeObject* pbxgroup =
  2752. this->CreateOrGetPBXGroup(cmtarget, sourceGroup);
  2753. std::string key = GetGroupMapKey(cmtarget, sf);
  2754. this->GroupMap[key] = pbxgroup;
  2755. }
  2756. // Put OBJECT_LIBRARY objects in proper groups:
  2757. std::vector<std::string> objs;
  2758. this->GetGeneratorTarget(&cmtarget)->UseObjectLibraries(objs);
  2759. for(std::vector<std::string>::const_iterator
  2760. oi = objs.begin(); oi != objs.end(); ++oi)
  2761. {
  2762. std::string const& source = *oi;
  2763. cmSourceGroup* sourceGroup =
  2764. mf->FindSourceGroup(source.c_str(), sourceGroups);
  2765. cmXCodeObject* pbxgroup =
  2766. this->CreateOrGetPBXGroup(cmtarget, sourceGroup);
  2767. std::string key = GetGroupMapKeyFromPath(cmtarget, source);
  2768. this->GroupMap[key] = pbxgroup;
  2769. }
  2770. }
  2771. }
  2772. }
  2773. cmXCodeObject *cmGlobalXCodeGenerator
  2774. ::CreatePBXGroup(cmXCodeObject *parent, std::string name)
  2775. {
  2776. cmXCodeObject* parentChildren = NULL;
  2777. if(parent)
  2778. parentChildren = parent->GetObject("children");
  2779. cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
  2780. cmXCodeObject* groupChildren =
  2781. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2782. group->AddAttribute("name", this->CreateString(name.c_str()));
  2783. group->AddAttribute("children", groupChildren);
  2784. if(this->XcodeVersion == 15)
  2785. {
  2786. group->AddAttribute("refType", this->CreateString("4"));
  2787. }
  2788. group->AddAttribute("sourceTree", this->CreateString("<group>"));
  2789. if(parentChildren)
  2790. parentChildren->AddObject(group);
  2791. return group;
  2792. }
  2793. //----------------------------------------------------------------------------
  2794. cmXCodeObject* cmGlobalXCodeGenerator
  2795. ::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg)
  2796. {
  2797. std::string s;
  2798. std::string target;
  2799. const char *targetFolder= cmtarget.GetProperty("FOLDER");
  2800. if(targetFolder) {
  2801. target = targetFolder;
  2802. target += "/";
  2803. }
  2804. target += cmtarget.GetName();
  2805. s = target + "/";
  2806. s += sg->GetFullName();
  2807. std::map<std::string, cmXCodeObject* >::iterator it =
  2808. this->GroupNameMap.find(s);
  2809. if(it != this->GroupNameMap.end())
  2810. {
  2811. return it->second;
  2812. }
  2813. it = this->TargetGroup.find(target);
  2814. cmXCodeObject* tgroup = 0;
  2815. if(it != this->TargetGroup.end())
  2816. {
  2817. tgroup = it->second;
  2818. }
  2819. else
  2820. {
  2821. std::vector<std::string> tgt_folders =
  2822. cmSystemTools::tokenize(target, "/");
  2823. std::string curr_tgt_folder;
  2824. for(std::vector<std::string>::size_type i = 0; i < tgt_folders.size();i++)
  2825. {
  2826. if (i != 0)
  2827. {
  2828. curr_tgt_folder += "/";
  2829. }
  2830. curr_tgt_folder += tgt_folders[i];
  2831. it = this->TargetGroup.find(curr_tgt_folder);
  2832. if(it != this->TargetGroup.end())
  2833. {
  2834. tgroup = it->second;
  2835. continue;
  2836. }
  2837. tgroup = this->CreatePBXGroup(tgroup,tgt_folders[i]);
  2838. this->TargetGroup[curr_tgt_folder] = tgroup;
  2839. if(i == 0)
  2840. {
  2841. this->SourcesGroupChildren->AddObject(tgroup);
  2842. }
  2843. }
  2844. }
  2845. this->TargetGroup[target] = tgroup;
  2846. // If it's the default source group (empty name) then put the source file
  2847. // directly in the tgroup...
  2848. //
  2849. if (std::string(sg->GetFullName()) == "")
  2850. {
  2851. this->GroupNameMap[s] = tgroup;
  2852. return tgroup;
  2853. }
  2854. //It's a recursive folder structure, let's find the real parent group
  2855. if(std::string(sg->GetFullName()) != std::string(sg->GetName()))
  2856. {
  2857. std::vector<std::string> folders =
  2858. cmSystemTools::tokenize(sg->GetFullName(), "\\");
  2859. std::string curr_folder = target;
  2860. curr_folder += "/";
  2861. for(std::vector<std::string>::size_type i = 0; i < folders.size();i++)
  2862. {
  2863. curr_folder += folders[i];
  2864. std::map<std::string, cmXCodeObject* >::iterator i_folder =
  2865. this->GroupNameMap.find(curr_folder);
  2866. //Create new folder
  2867. if(i_folder == this->GroupNameMap.end())
  2868. {
  2869. cmXCodeObject *group = this->CreatePBXGroup(tgroup,folders[i]);
  2870. this->GroupNameMap[curr_folder] = group;
  2871. tgroup = group;
  2872. }
  2873. else
  2874. {
  2875. tgroup = i_folder->second;
  2876. }
  2877. curr_folder = curr_folder + "\\";
  2878. }
  2879. return tgroup;
  2880. }
  2881. cmXCodeObject *group = this->CreatePBXGroup(tgroup,sg->GetName());
  2882. this->GroupNameMap[s] = group;
  2883. return group;
  2884. }
  2885. //----------------------------------------------------------------------------
  2886. void cmGlobalXCodeGenerator
  2887. ::CreateXCodeObjects(cmLocalGenerator* root,
  2888. std::vector<cmLocalGenerator*>&
  2889. generators)
  2890. {
  2891. this->ClearXCodeObjects();
  2892. this->RootObject = 0;
  2893. this->SourcesGroupChildren = 0;
  2894. this->ResourcesGroupChildren = 0;
  2895. this->MainGroupChildren = 0;
  2896. cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2897. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  2898. cmXCodeObject* developBuildStyle =
  2899. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2900. cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2901. if(this->XcodeVersion == 15)
  2902. {
  2903. developBuildStyle->AddAttribute("name",
  2904. this->CreateString("Development"));
  2905. developBuildStyle->AddAttribute("buildSettings", group);
  2906. listObjs->AddObject(developBuildStyle);
  2907. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2908. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("YES"));
  2909. cmXCodeObject* deployBuildStyle =
  2910. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2911. deployBuildStyle->AddAttribute("name", this->CreateString("Deployment"));
  2912. deployBuildStyle->AddAttribute("buildSettings", group);
  2913. listObjs->AddObject(deployBuildStyle);
  2914. }
  2915. else
  2916. {
  2917. for(unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i)
  2918. {
  2919. cmXCodeObject* buildStyle =
  2920. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2921. const char* name = this->CurrentConfigurationTypes[i].c_str();
  2922. buildStyle->AddAttribute("name", this->CreateString(name));
  2923. buildStyle->SetComment(name);
  2924. cmXCodeObject* sgroup =
  2925. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2926. sgroup->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  2927. buildStyle->AddAttribute("buildSettings", sgroup);
  2928. listObjs->AddObject(buildStyle);
  2929. }
  2930. }
  2931. cmXCodeObject* mainGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2932. this->MainGroupChildren =
  2933. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2934. mainGroup->AddAttribute("children", this->MainGroupChildren);
  2935. if(this->XcodeVersion == 15)
  2936. {
  2937. mainGroup->AddAttribute("refType", this->CreateString("4"));
  2938. }
  2939. mainGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2940. cmXCodeObject* sourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2941. this->SourcesGroupChildren =
  2942. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2943. sourcesGroup->AddAttribute("name", this->CreateString("Sources"));
  2944. sourcesGroup->AddAttribute("children", this->SourcesGroupChildren);
  2945. if(this->XcodeVersion == 15)
  2946. {
  2947. sourcesGroup->AddAttribute("refType", this->CreateString("4"));
  2948. }
  2949. sourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2950. this->MainGroupChildren->AddObject(sourcesGroup);
  2951. cmXCodeObject* resourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2952. this->ResourcesGroupChildren =
  2953. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2954. resourcesGroup->AddAttribute("name", this->CreateString("Resources"));
  2955. resourcesGroup->AddAttribute("children", this->ResourcesGroupChildren);
  2956. if(this->XcodeVersion == 15)
  2957. {
  2958. resourcesGroup->AddAttribute("refType", this->CreateString("4"));
  2959. }
  2960. resourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2961. this->MainGroupChildren->AddObject(resourcesGroup);
  2962. // now create the cmake groups
  2963. this->CreateGroups(root, generators);
  2964. cmXCodeObject* productGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2965. productGroup->AddAttribute("name", this->CreateString("Products"));
  2966. if(this->XcodeVersion == 15)
  2967. {
  2968. productGroup->AddAttribute("refType", this->CreateString("4"));
  2969. }
  2970. productGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2971. cmXCodeObject* productGroupChildren =
  2972. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2973. productGroup->AddAttribute("children", productGroupChildren);
  2974. this->MainGroupChildren->AddObject(productGroup);
  2975. this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
  2976. this->RootObject->SetComment("Project object");
  2977. std::string project_id = "PROJECT_";
  2978. project_id += root->GetMakefile()->GetProjectName();
  2979. this->RootObject->SetId(this->GetOrCreateId(
  2980. project_id.c_str(), this->RootObject->GetId()).c_str());
  2981. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2982. this->RootObject->AddAttribute("mainGroup",
  2983. this->CreateObjectReference(mainGroup));
  2984. this->RootObject->AddAttribute("buildSettings", group);
  2985. this->RootObject->AddAttribute("buildStyles", listObjs);
  2986. this->RootObject->AddAttribute("hasScannedForEncodings",
  2987. this->CreateString("0"));
  2988. if (this->XcodeVersion >= 30)
  2989. {
  2990. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2991. group->AddAttribute("BuildIndependentTargetsInParallel",
  2992. this->CreateString("YES"));
  2993. this->RootObject->AddAttribute("attributes", group);
  2994. if (this->XcodeVersion >= 32)
  2995. this->RootObject->AddAttribute("compatibilityVersion",
  2996. this->CreateString("Xcode 3.2"));
  2997. else if (this->XcodeVersion >= 31)
  2998. this->RootObject->AddAttribute("compatibilityVersion",
  2999. this->CreateString("Xcode 3.1"));
  3000. else
  3001. this->RootObject->AddAttribute("compatibilityVersion",
  3002. this->CreateString("Xcode 3.0"));
  3003. }
  3004. // Point Xcode at the top of the source tree.
  3005. {
  3006. std::string pdir =
  3007. this->RelativeToBinary(root->GetMakefile()->GetCurrentDirectory());
  3008. this->RootObject->AddAttribute("projectDirPath",
  3009. this->CreateString(pdir.c_str()));
  3010. this->RootObject->AddAttribute("projectRoot", this->CreateString(""));
  3011. }
  3012. cmXCodeObject* configlist =
  3013. this->CreateObject(cmXCodeObject::XCConfigurationList);
  3014. cmXCodeObject* buildConfigurations =
  3015. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  3016. std::vector<cmXCodeObject*> configs;
  3017. const char *defaultConfigName = "Debug";
  3018. if(this->XcodeVersion == 15)
  3019. {
  3020. cmXCodeObject* configDebug =
  3021. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  3022. configDebug->AddAttribute("name", this->CreateString("Debug"));
  3023. configs.push_back(configDebug);
  3024. cmXCodeObject* configRelease =
  3025. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  3026. configRelease->AddAttribute("name", this->CreateString("Release"));
  3027. configs.push_back(configRelease);
  3028. }
  3029. else
  3030. {
  3031. for(unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i)
  3032. {
  3033. const char* name = this->CurrentConfigurationTypes[i].c_str();
  3034. if (0 == i)
  3035. {
  3036. defaultConfigName = name;
  3037. }
  3038. cmXCodeObject* config =
  3039. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  3040. config->AddAttribute("name", this->CreateString(name));
  3041. configs.push_back(config);
  3042. }
  3043. }
  3044. for(std::vector<cmXCodeObject*>::iterator c = configs.begin();
  3045. c != configs.end(); ++c)
  3046. {
  3047. buildConfigurations->AddObject(*c);
  3048. }
  3049. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  3050. std::string comment = "Build configuration list for PBXProject ";
  3051. comment += " \"";
  3052. comment += this->CurrentProject;
  3053. comment += "\"";
  3054. configlist->SetComment(comment.c_str());
  3055. configlist->AddAttribute("defaultConfigurationIsVisible",
  3056. this->CreateString("0"));
  3057. configlist->AddAttribute("defaultConfigurationName",
  3058. this->CreateString(defaultConfigName));
  3059. cmXCodeObject* buildSettings =
  3060. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  3061. const char* osxArch =
  3062. this->CurrentMakefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
  3063. if(!osxArch || strlen(osxArch) == 0)
  3064. {
  3065. if(this->XcodeVersion >= 32)
  3066. {
  3067. osxArch = "$(ARCHS_STANDARD_32_64_BIT)";
  3068. }
  3069. else if(this->XcodeVersion == 31)
  3070. {
  3071. osxArch = "$(ARCHS_STANDARD_32_BIT)";
  3072. }
  3073. else if(this->XcodeVersion <= 30)
  3074. {
  3075. #ifdef __ppc__
  3076. osxArch = "ppc";
  3077. #endif
  3078. #ifdef __i386
  3079. osxArch = "i386";
  3080. #endif
  3081. }
  3082. buildSettings->AddAttribute("ONLY_ACTIVE_ARCH",
  3083. this->CreateString("YES"));
  3084. }
  3085. const char* sysroot =
  3086. this->CurrentMakefile->GetDefinition("CMAKE_OSX_SYSROOT");
  3087. const char* deploymentTarget =
  3088. this->CurrentMakefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
  3089. if(osxArch && sysroot)
  3090. {
  3091. // recompute this as it may have been changed since enable language
  3092. this->Architectures.clear();
  3093. cmSystemTools::ExpandListArgument(std::string(osxArch),
  3094. this->Architectures);
  3095. buildSettings->AddAttribute("SDKROOT",
  3096. this->CreateString(sysroot));
  3097. std::string archString;
  3098. const char* sep = "";
  3099. for( std::vector<std::string>::iterator i =
  3100. this->Architectures.begin();
  3101. i != this->Architectures.end(); ++i)
  3102. {
  3103. archString += sep;
  3104. archString += *i;
  3105. sep = " ";
  3106. }
  3107. buildSettings->AddAttribute("ARCHS",
  3108. this->CreateString(archString.c_str()));
  3109. }
  3110. if(deploymentTarget && *deploymentTarget)
  3111. {
  3112. buildSettings->AddAttribute("MACOSX_DEPLOYMENT_TARGET",
  3113. this->CreateString(deploymentTarget));
  3114. }
  3115. if(!this->PlatformToolset.empty())
  3116. {
  3117. buildSettings->AddAttribute("GCC_VERSION",
  3118. this->CreateString(this->PlatformToolset.c_str()));
  3119. }
  3120. // Put this last so it can override existing settings
  3121. // Convert "CMAKE_XCODE_ATTRIBUTE_*" variables directly.
  3122. {
  3123. std::vector<std::string> vars = this->CurrentMakefile->GetDefinitions();
  3124. for(std::vector<std::string>::const_iterator i = vars.begin();
  3125. i != vars.end(); ++i)
  3126. {
  3127. if(i->find("CMAKE_XCODE_ATTRIBUTE_") == 0)
  3128. {
  3129. buildSettings->AddAttribute(i->substr(22).c_str(),
  3130. this->CreateString(
  3131. this->CurrentMakefile->GetDefinition(i->c_str())));
  3132. }
  3133. }
  3134. }
  3135. std::string symroot = root->GetMakefile()->GetCurrentOutputDirectory();
  3136. symroot += "/build";
  3137. buildSettings->AddAttribute("SYMROOT", this->CreateString(symroot.c_str()));
  3138. for( std::vector<cmXCodeObject*>::iterator i = configs.begin();
  3139. i != configs.end(); ++i)
  3140. {
  3141. (*i)->AddAttribute("buildSettings", buildSettings);
  3142. }
  3143. this->RootObject->AddAttribute("buildConfigurationList",
  3144. this->CreateObjectReference(configlist));
  3145. std::vector<cmXCodeObject*> targets;
  3146. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  3147. i != generators.end(); ++i)
  3148. {
  3149. if(!this->IsExcluded(root, *i))
  3150. {
  3151. this->CreateXCodeTargets(*i, targets);
  3152. }
  3153. }
  3154. // loop over all targets and add link and depend info
  3155. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  3156. i != targets.end(); ++i)
  3157. {
  3158. cmXCodeObject* t = *i;
  3159. this->AddDependAndLinkInformation(t);
  3160. }
  3161. if(this->XcodeVersion < 50)
  3162. {
  3163. // now create xcode depend hack makefile
  3164. this->CreateXCodeDependHackTarget(targets);
  3165. }
  3166. // now add all targets to the root object
  3167. cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  3168. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  3169. i != targets.end(); ++i)
  3170. {
  3171. cmXCodeObject* t = *i;
  3172. allTargets->AddObject(t);
  3173. cmXCodeObject* productRef = t->GetObject("productReference");
  3174. if(productRef)
  3175. {
  3176. productGroupChildren->AddObject(productRef->GetObject());
  3177. }
  3178. }
  3179. this->RootObject->AddAttribute("targets", allTargets);
  3180. }
  3181. //----------------------------------------------------------------------------
  3182. std::string
  3183. cmGlobalXCodeGenerator::GetObjectsNormalDirectory(
  3184. const std::string &projName,
  3185. const std::string &configName,
  3186. const cmTarget *t) const
  3187. {
  3188. std::string dir =
  3189. t->GetMakefile()->GetCurrentOutputDirectory();
  3190. dir += "/";
  3191. dir += projName;
  3192. dir += ".build/";
  3193. dir += configName;
  3194. dir += "/";
  3195. dir += t->GetName();
  3196. dir += ".build/Objects-normal/";
  3197. return dir;
  3198. }
  3199. //----------------------------------------------------------------------------
  3200. void
  3201. cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
  3202. std::vector<cmXCodeObject*>& targets)
  3203. {
  3204. cmGeneratedFileStream
  3205. makefileStream(this->CurrentXCodeHackMakefile.c_str());
  3206. if(!makefileStream)
  3207. {
  3208. cmSystemTools::Error("Could not create",
  3209. this->CurrentXCodeHackMakefile.c_str());
  3210. return;
  3211. }
  3212. makefileStream.SetCopyIfDifferent(true);
  3213. // one more pass for external depend information not handled
  3214. // correctly by xcode
  3215. makefileStream << "# DO NOT EDIT\n";
  3216. makefileStream << "# This makefile makes sure all linkable targets are\n";
  3217. makefileStream << "# up-to-date with anything they link to\n"
  3218. "default:\n"
  3219. "\techo \"Do not invoke directly\"\n"
  3220. "\n";
  3221. makefileStream
  3222. << "# For each target create a dummy rule "
  3223. "so the target does not have to exist\n";
  3224. std::set<std::string> emitted;
  3225. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  3226. i != targets.end(); ++i)
  3227. {
  3228. cmXCodeObject* target = *i;
  3229. std::map<std::string, cmXCodeObject::StringVec> const& deplibs =
  3230. target->GetDependLibraries();
  3231. for(std::map<std::string, cmXCodeObject::StringVec>::const_iterator ci
  3232. = deplibs.begin(); ci != deplibs.end(); ++ci)
  3233. {
  3234. for(cmXCodeObject::StringVec::const_iterator d = ci->second.begin();
  3235. d != ci->second.end(); ++d)
  3236. {
  3237. if(emitted.insert(*d).second)
  3238. {
  3239. makefileStream <<
  3240. this->ConvertToRelativeForMake(d->c_str()) << ":\n";
  3241. }
  3242. }
  3243. }
  3244. }
  3245. makefileStream << "\n\n";
  3246. // Write rules to help Xcode relink things at the right time.
  3247. makefileStream <<
  3248. "# Rules to remove targets that are older than anything to which they\n"
  3249. "# link. This forces Xcode to relink the targets from scratch. It\n"
  3250. "# does not seem to check these dependencies itself.\n";
  3251. for(std::vector<std::string>::const_iterator
  3252. ct = this->CurrentConfigurationTypes.begin();
  3253. ct != this->CurrentConfigurationTypes.end(); ++ct)
  3254. {
  3255. const char* configName = 0;
  3256. if(!ct->empty())
  3257. {
  3258. configName = ct->c_str();
  3259. }
  3260. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  3261. i != targets.end(); ++i)
  3262. {
  3263. cmXCodeObject* target = *i;
  3264. cmTarget* t =target->GetTarget();
  3265. if(t->GetType() == cmTarget::EXECUTABLE ||
  3266. // Nope - no post-build for OBJECT_LIRBRARY
  3267. // t->GetType() == cmTarget::OBJECT_LIBRARY ||
  3268. t->GetType() == cmTarget::STATIC_LIBRARY ||
  3269. t->GetType() == cmTarget::SHARED_LIBRARY ||
  3270. t->GetType() == cmTarget::MODULE_LIBRARY)
  3271. {
  3272. // Declare an entry point for the target post-build phase.
  3273. makefileStream << this->PostBuildMakeTarget(t->GetName(), *ct)
  3274. << ":\n";
  3275. }
  3276. if(t->GetType() == cmTarget::EXECUTABLE ||
  3277. t->GetType() == cmTarget::SHARED_LIBRARY ||
  3278. t->GetType() == cmTarget::MODULE_LIBRARY)
  3279. {
  3280. std::string tfull = t->GetFullPath(configName);
  3281. std::string trel = this->ConvertToRelativeForMake(tfull.c_str());
  3282. // Add this target to the post-build phases of its dependencies.
  3283. std::map<std::string, cmXCodeObject::StringVec>::const_iterator
  3284. y = target->GetDependTargets().find(*ct);
  3285. if(y != target->GetDependTargets().end())
  3286. {
  3287. std::vector<std::string> const& deptgts = y->second;
  3288. for(std::vector<std::string>::const_iterator d = deptgts.begin();
  3289. d != deptgts.end(); ++d)
  3290. {
  3291. makefileStream << this->PostBuildMakeTarget(*d, *ct) << ": "
  3292. << trel << "\n";
  3293. }
  3294. }
  3295. // Create a rule for this target.
  3296. makefileStream << trel << ":";
  3297. // List dependencies if any exist.
  3298. std::map<std::string, cmXCodeObject::StringVec>::const_iterator
  3299. x = target->GetDependLibraries().find(*ct);
  3300. if(x != target->GetDependLibraries().end())
  3301. {
  3302. std::vector<std::string> const& deplibs = x->second;
  3303. for(std::vector<std::string>::const_iterator d = deplibs.begin();
  3304. d != deplibs.end(); ++d)
  3305. {
  3306. makefileStream << "\\\n\t" <<
  3307. this->ConvertToRelativeForMake(d->c_str());
  3308. }
  3309. }
  3310. // Write the action to remove the target if it is out of date.
  3311. makefileStream << "\n";
  3312. makefileStream << "\t/bin/rm -f "
  3313. << this->ConvertToRelativeForMake(tfull.c_str())
  3314. << "\n";
  3315. // if building for more than one architecture
  3316. // then remove those exectuables as well
  3317. if(this->Architectures.size() > 1)
  3318. {
  3319. std::string universal = this->GetObjectsNormalDirectory(
  3320. this->CurrentProject, configName, t);
  3321. for( std::vector<std::string>::iterator arch =
  3322. this->Architectures.begin();
  3323. arch != this->Architectures.end(); ++arch)
  3324. {
  3325. std::string universalFile = universal;
  3326. universalFile += *arch;
  3327. universalFile += "/";
  3328. universalFile += t->GetFullName(configName);
  3329. makefileStream << "\t/bin/rm -f "
  3330. <<
  3331. this->ConvertToRelativeForMake(universalFile.c_str())
  3332. << "\n";
  3333. }
  3334. }
  3335. makefileStream << "\n\n";
  3336. }
  3337. }
  3338. }
  3339. }
  3340. //----------------------------------------------------------------------------
  3341. void
  3342. cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
  3343. std::vector<cmLocalGenerator*>&
  3344. generators)
  3345. {
  3346. if(generators.size() == 0)
  3347. {
  3348. return;
  3349. }
  3350. // Skip local generators that are excluded from this project.
  3351. for(std::vector<cmLocalGenerator*>::iterator g = generators.begin();
  3352. g != generators.end(); ++g)
  3353. {
  3354. if(this->IsExcluded(root, *g))
  3355. {
  3356. continue;
  3357. }
  3358. }
  3359. this->CreateXCodeObjects(root,
  3360. generators);
  3361. std::string xcodeDir = root->GetMakefile()->GetStartOutputDirectory();
  3362. xcodeDir += "/";
  3363. xcodeDir += root->GetMakefile()->GetProjectName();
  3364. xcodeDir += ".xcode";
  3365. if(this->XcodeVersion > 20)
  3366. {
  3367. xcodeDir += "proj";
  3368. }
  3369. cmSystemTools::MakeDirectory(xcodeDir.c_str());
  3370. std::string xcodeProjFile = xcodeDir + "/project.pbxproj";
  3371. cmGeneratedFileStream fout(xcodeProjFile.c_str());
  3372. fout.SetCopyIfDifferent(true);
  3373. if(!fout)
  3374. {
  3375. return;
  3376. }
  3377. this->WriteXCodePBXProj(fout, root, generators);
  3378. this->ClearXCodeObjects();
  3379. // Since this call may have created new cache entries, save the cache:
  3380. //
  3381. root->GetMakefile()->GetCacheManager()->SaveCache(
  3382. root->GetMakefile()->GetHomeOutputDirectory());
  3383. }
  3384. //----------------------------------------------------------------------------
  3385. void
  3386. cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
  3387. cmLocalGenerator* ,
  3388. std::vector<cmLocalGenerator*>& )
  3389. {
  3390. fout << "// !$*UTF8*$!\n";
  3391. fout << "{\n";
  3392. cmXCodeObject::Indent(1, fout);
  3393. fout << "archiveVersion = 1;\n";
  3394. cmXCodeObject::Indent(1, fout);
  3395. fout << "classes = {\n";
  3396. cmXCodeObject::Indent(1, fout);
  3397. fout << "};\n";
  3398. cmXCodeObject::Indent(1, fout);
  3399. if(this->XcodeVersion >= 21)
  3400. {
  3401. if (this->XcodeVersion >= 32)
  3402. fout << "objectVersion = 46;\n";
  3403. else if (this->XcodeVersion >= 31)
  3404. fout << "objectVersion = 45;\n";
  3405. else if (this->XcodeVersion >= 30)
  3406. fout << "objectVersion = 44;\n";
  3407. else
  3408. fout << "objectVersion = 42;\n";
  3409. cmXCode21Object::PrintList(this->XCodeObjects, fout);
  3410. }
  3411. else
  3412. {
  3413. fout << "objectVersion = 39;\n";
  3414. cmXCodeObject::PrintList(this->XCodeObjects, fout);
  3415. }
  3416. cmXCodeObject::Indent(1, fout);
  3417. fout << "rootObject = " << this->RootObject->GetId() << ";\n";
  3418. fout << "}\n";
  3419. }
  3420. //----------------------------------------------------------------------------
  3421. const char* cmGlobalXCodeGenerator::GetCMakeCFGIntDir() const
  3422. {
  3423. return this->XcodeVersion >= 21 ?
  3424. "$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)" : ".";
  3425. }
  3426. std::string cmGlobalXCodeGenerator::ExpandCFGIntDir(const std::string& str,
  3427. const std::string& config) const
  3428. {
  3429. std::string replace1 = "$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
  3430. std::string replace2 = "$(CONFIGURATION)";
  3431. std::string tmp = str;
  3432. for(std::string::size_type i = tmp.find(replace1);
  3433. i != std::string::npos;
  3434. i = tmp.find(replace1, i))
  3435. {
  3436. tmp.replace(i, replace1.size(), config);
  3437. i += config.size();
  3438. }
  3439. for(std::string::size_type i = tmp.find(replace2);
  3440. i != std::string::npos;
  3441. i = tmp.find(replace2, i))
  3442. {
  3443. tmp.replace(i, replace2.size(), config);
  3444. i += config.size();
  3445. }
  3446. return tmp;
  3447. }
  3448. //----------------------------------------------------------------------------
  3449. void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry)
  3450. {
  3451. entry.Name = cmGlobalXCodeGenerator::GetActualName();
  3452. entry.Brief = "Generate Xcode project files.";
  3453. }
  3454. //----------------------------------------------------------------------------
  3455. std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(const char* p)
  3456. {
  3457. if ( !this->CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  3458. {
  3459. return cmSystemTools::ConvertToOutputPath(p);
  3460. }
  3461. else
  3462. {
  3463. std::string ret =
  3464. this->CurrentLocalGenerator->
  3465. ConvertToRelativePath(this->CurrentOutputDirectoryComponents, p);
  3466. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  3467. }
  3468. }
  3469. //----------------------------------------------------------------------------
  3470. std::string cmGlobalXCodeGenerator::ConvertToRelativeForXCode(const char* p)
  3471. {
  3472. if ( !this->CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  3473. {
  3474. return cmSystemTools::ConvertToOutputPath(p);
  3475. }
  3476. else
  3477. {
  3478. std::string ret =
  3479. this->CurrentLocalGenerator->
  3480. ConvertToRelativePath(this->ProjectOutputDirectoryComponents, p);
  3481. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  3482. }
  3483. }
  3484. //----------------------------------------------------------------------------
  3485. std::string cmGlobalXCodeGenerator::RelativeToSource(const char* p)
  3486. {
  3487. // We force conversion because Xcode breakpoints do not work unless
  3488. // they are in a file named relative to the source tree.
  3489. return this->CurrentLocalGenerator->
  3490. ConvertToRelativePath(this->ProjectSourceDirectoryComponents, p, true);
  3491. }
  3492. //----------------------------------------------------------------------------
  3493. std::string cmGlobalXCodeGenerator::RelativeToBinary(const char* p)
  3494. {
  3495. return this->CurrentLocalGenerator->
  3496. ConvertToRelativePath(this->ProjectOutputDirectoryComponents, p);
  3497. }
  3498. //----------------------------------------------------------------------------
  3499. std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p)
  3500. {
  3501. std::string ret = p;
  3502. if(ret.find(' ') != ret.npos)
  3503. {
  3504. std::string t = ret;
  3505. ret = "\"";
  3506. ret += t;
  3507. ret += "\"";
  3508. }
  3509. return ret;
  3510. }
  3511. //----------------------------------------------------------------------------
  3512. void
  3513. cmGlobalXCodeGenerator
  3514. ::AppendDirectoryForConfig(const std::string& prefix,
  3515. const std::string& config,
  3516. const std::string& suffix,
  3517. std::string& dir)
  3518. {
  3519. if(this->XcodeVersion > 20)
  3520. {
  3521. if(!config.empty())
  3522. {
  3523. dir += prefix;
  3524. dir += config;
  3525. dir += suffix;
  3526. }
  3527. }
  3528. }
  3529. //----------------------------------------------------------------------------
  3530. std::string cmGlobalXCodeGenerator::LookupFlags(
  3531. const std::string& varNamePrefix,
  3532. const std::string& varNameLang,
  3533. const std::string& varNameSuffix,
  3534. const std::string& default_flags)
  3535. {
  3536. if(!varNameLang.empty())
  3537. {
  3538. std::string varName = varNamePrefix;
  3539. varName += varNameLang;
  3540. varName += varNameSuffix;
  3541. if(const char* varValue =
  3542. this->CurrentMakefile->GetDefinition(varName.c_str()))
  3543. {
  3544. if(*varValue)
  3545. {
  3546. return varValue;
  3547. }
  3548. }
  3549. }
  3550. return default_flags;
  3551. }
  3552. //----------------------------------------------------------------------------
  3553. void cmGlobalXCodeGenerator::AppendDefines(BuildObjectListOrString& defs,
  3554. const char* defines_list,
  3555. bool dflag)
  3556. {
  3557. // Skip this if there are no definitions.
  3558. if(!defines_list)
  3559. {
  3560. return;
  3561. }
  3562. // Expand the list of definitions.
  3563. std::vector<std::string> defines;
  3564. cmSystemTools::ExpandListArgument(defines_list, defines);
  3565. // Store the definitions in the string.
  3566. this->AppendDefines(defs, defines, dflag);
  3567. }
  3568. //----------------------------------------------------------------------------
  3569. void
  3570. cmGlobalXCodeGenerator::AppendDefines(BuildObjectListOrString& defs,
  3571. std::vector<std::string> const& defines,
  3572. bool dflag)
  3573. {
  3574. // GCC_PREPROCESSOR_DEFINITIONS is a space-separated list of definitions.
  3575. std::string def;
  3576. for(std::vector<std::string>::const_iterator di = defines.begin();
  3577. di != defines.end(); ++di)
  3578. {
  3579. // Start with -D if requested.
  3580. def = dflag? "-D": "";
  3581. def += *di;
  3582. // Append the flag with needed escapes.
  3583. std::string tmp;
  3584. this->AppendFlag(tmp, def);
  3585. defs.Add(tmp.c_str());
  3586. }
  3587. }
  3588. //----------------------------------------------------------------------------
  3589. void cmGlobalXCodeGenerator::AppendFlag(std::string& flags,
  3590. std::string const& flag)
  3591. {
  3592. // Short-circuit for an empty flag.
  3593. if(flag.empty())
  3594. {
  3595. return;
  3596. }
  3597. // Separate from previous flags.
  3598. if(!flags.empty())
  3599. {
  3600. flags += " ";
  3601. }
  3602. // Check if the flag needs quoting.
  3603. bool quoteFlag =
  3604. flag.find_first_of("`~!@#$%^&*()+={}[]|:;\"'<>,.? ") != flag.npos;
  3605. // We escape a flag as follows:
  3606. // - Place each flag in single quotes ''
  3607. // - Escape a single quote as \\'
  3608. // - Escape a backslash as \\\\ since it itself is an escape
  3609. // Note that in the code below we need one more level of escapes for
  3610. // C string syntax in this source file.
  3611. //
  3612. // The final level of escaping is done when the string is stored
  3613. // into the project file by cmXCodeObject::PrintString.
  3614. if(quoteFlag)
  3615. {
  3616. // Open single quote.
  3617. flags += "'";
  3618. }
  3619. // Flag value with escaped quotes and backslashes.
  3620. for(const char* c = flag.c_str(); *c; ++c)
  3621. {
  3622. if(*c == '\'')
  3623. {
  3624. if (this->XcodeVersion >= 40)
  3625. {
  3626. flags += "'\\\\''";
  3627. }
  3628. else
  3629. {
  3630. flags += "\\\\'";
  3631. }
  3632. }
  3633. else if(*c == '\\')
  3634. {
  3635. flags += "\\\\\\\\";
  3636. }
  3637. else
  3638. {
  3639. flags += *c;
  3640. }
  3641. }
  3642. if(quoteFlag)
  3643. {
  3644. // Close single quote.
  3645. flags += "'";
  3646. }
  3647. }
  3648. //----------------------------------------------------------------------------
  3649. std::string
  3650. cmGlobalXCodeGenerator::ComputeInfoPListLocation(cmTarget& target)
  3651. {
  3652. std::string plist = target.GetMakefile()->GetCurrentOutputDirectory();
  3653. plist += cmake::GetCMakeFilesDirectory();
  3654. plist += "/";
  3655. plist += target.GetName();
  3656. plist += ".dir/Info.plist";
  3657. return plist;
  3658. }
  3659. //----------------------------------------------------------------------------
  3660. // Return true if the generated build tree may contain multiple builds.
  3661. // i.e. "Can I build Debug and Release in the same tree?"
  3662. bool cmGlobalXCodeGenerator::IsMultiConfig()
  3663. {
  3664. // Old Xcode 1.5 is single config:
  3665. if(this->XcodeVersion == 15)
  3666. {
  3667. return false;
  3668. }
  3669. // Newer Xcode versions are multi config:
  3670. return true;
  3671. }
  3672. //----------------------------------------------------------------------------
  3673. void cmGlobalXCodeGenerator
  3674. ::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const
  3675. {
  3676. const char* configName = this->GetCMakeCFGIntDir();
  3677. std::string dir = this->GetObjectsNormalDirectory(
  3678. "$(PROJECT_NAME)", configName, gt->Target);
  3679. if(this->XcodeVersion >= 21)
  3680. {
  3681. dir += "$(CURRENT_ARCH)/";
  3682. }
  3683. else
  3684. {
  3685. #ifdef __ppc__
  3686. dir += "ppc/";
  3687. #endif
  3688. #ifdef __i386
  3689. dir += "i386/";
  3690. #endif
  3691. }
  3692. gt->ObjectDirectory = dir;
  3693. }