cmGlobalXCodeGenerator.cxx 131 KB

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