cmGlobalXCodeGenerator.cxx 130 KB

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