cmGlobalXCodeGenerator.cxx 131 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 == "xib")
  713. {
  714. sourcecode += ".file.xib";
  715. }
  716. else if(ext == "plist")
  717. {
  718. sourcecode += ".text.plist";
  719. }
  720. else if(ext == "h")
  721. {
  722. sourcecode += ".c.h";
  723. }
  724. else if(ext == "hxx" || ext == "hpp" || ext == "txx"
  725. || ext == "pch" || ext == "hh")
  726. {
  727. sourcecode += ".cpp.h";
  728. }
  729. else if(ext == "png" || ext == "gif" || ext == "jpg")
  730. {
  731. sourcecode = "image";
  732. }
  733. else if(ext == "txt")
  734. {
  735. sourcecode += ".text";
  736. }
  737. else if(lang == "CXX")
  738. {
  739. sourcecode += ".cpp.cpp";
  740. }
  741. else if(lang == "C")
  742. {
  743. sourcecode += ".c.c";
  744. }
  745. else if(lang == "Fortran")
  746. {
  747. sourcecode += ".fortran.f90";
  748. }
  749. else if(lang == "ASM")
  750. {
  751. sourcecode += ".asm";
  752. }
  753. //else
  754. // {
  755. // // Already specialized above or we leave sourcecode == "sourcecode"
  756. // // which is probably the most correct choice. Extensionless headers,
  757. // // for example... Or file types unknown to Xcode that do not map to a
  758. // // valid explicitFileType value.
  759. // }
  760. return sourcecode;
  761. }
  762. //----------------------------------------------------------------------------
  763. cmXCodeObject*
  764. cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath(
  765. const std::string &fullpath,
  766. cmTarget& cmtarget,
  767. const std::string &lang)
  768. {
  769. std::string fname = fullpath;
  770. cmXCodeObject* fileRef = this->FileRefs[fname];
  771. if(!fileRef)
  772. {
  773. fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  774. std::string comment = fname;
  775. fileRef->SetComment(fname.c_str());
  776. this->FileRefs[fname] = fileRef;
  777. }
  778. cmStdString key = GetGroupMapKeyFromPath(cmtarget, fullpath);
  779. cmXCodeObject* group = this->GroupMap[key];
  780. cmXCodeObject* children = group->GetObject("children");
  781. if (!children->HasObject(fileRef))
  782. {
  783. children->AddObject(fileRef);
  784. }
  785. fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
  786. // Compute the extension.
  787. std::string ext;
  788. std::string realExt =
  789. cmSystemTools::GetFilenameLastExtension(fullpath);
  790. if(!realExt.empty())
  791. {
  792. // Extension without the leading '.'.
  793. ext = realExt.substr(1);
  794. }
  795. // If fullpath references a directory, then we need to specify
  796. // lastKnownFileType as folder in order for Xcode to be able to open the
  797. // contents of the folder (Xcode 4.6 does not like explicitFileType=folder).
  798. if(cmSystemTools::FileIsDirectory(fullpath.c_str()))
  799. {
  800. fileRef->AddAttribute("lastKnownFileType",
  801. this->CreateString("folder"));
  802. }
  803. else
  804. {
  805. std::string sourcecode = GetSourcecodeValueFromFileExtension(ext, lang);
  806. const char* attribute = (sourcecode == "file.storyboard") ?
  807. "lastKnownFileType" :
  808. "explicitFileType";
  809. fileRef->AddAttribute(attribute,
  810. this->CreateString(sourcecode.c_str()));
  811. }
  812. // Store the file path relative to the top of the source tree.
  813. std::string path = this->RelativeToSource(fullpath.c_str());
  814. std::string name = cmSystemTools::GetFilenameName(path.c_str());
  815. const char* sourceTree = (cmSystemTools::FileIsFullPath(path.c_str())?
  816. "<absolute>" : "SOURCE_ROOT");
  817. fileRef->AddAttribute("name", this->CreateString(name.c_str()));
  818. fileRef->AddAttribute("path", this->CreateString(path.c_str()));
  819. fileRef->AddAttribute("sourceTree", this->CreateString(sourceTree));
  820. if(this->XcodeVersion == 15)
  821. {
  822. fileRef->AddAttribute("refType", this->CreateString("4"));
  823. }
  824. return fileRef;
  825. }
  826. //----------------------------------------------------------------------------
  827. cmXCodeObject*
  828. cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf,
  829. cmTarget& cmtarget)
  830. {
  831. const char* lang =
  832. this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
  833. if (!lang)
  834. {
  835. lang = "";
  836. }
  837. return this->CreateXCodeFileReferenceFromPath(
  838. sf->GetFullPath(), cmtarget, lang);
  839. }
  840. //----------------------------------------------------------------------------
  841. bool cmGlobalXCodeGenerator::SpecialTargetEmitted(std::string const& tname)
  842. {
  843. if(tname == "ALL_BUILD" || tname == "XCODE_DEPEND_HELPER" ||
  844. tname == "install" || tname == "package" || tname == "RUN_TESTS" ||
  845. tname == CMAKE_CHECK_BUILD_SYSTEM_TARGET )
  846. {
  847. if(this->TargetDoneSet.find(tname) != this->TargetDoneSet.end())
  848. {
  849. return true;
  850. }
  851. this->TargetDoneSet.insert(tname);
  852. return false;
  853. }
  854. return false;
  855. }
  856. //----------------------------------------------------------------------------
  857. void cmGlobalXCodeGenerator::SetCurrentLocalGenerator(cmLocalGenerator* gen)
  858. {
  859. this->CurrentLocalGenerator = gen;
  860. this->CurrentMakefile = gen->GetMakefile();
  861. std::string outdir =
  862. cmSystemTools::CollapseFullPath(this->CurrentMakefile->
  863. GetCurrentOutputDirectory());
  864. cmSystemTools::SplitPath(outdir.c_str(),
  865. this->CurrentOutputDirectoryComponents);
  866. // Select the current set of configuration types.
  867. this->CurrentConfigurationTypes.clear();
  868. this->CurrentMakefile->GetConfigurations(this->CurrentConfigurationTypes);
  869. if(this->CurrentConfigurationTypes.empty())
  870. {
  871. this->CurrentConfigurationTypes.push_back("");
  872. }
  873. }
  874. //----------------------------------------------------------------------------
  875. struct cmSourceFilePathCompare
  876. {
  877. bool operator()(cmSourceFile* l, cmSourceFile* r)
  878. {
  879. return l->GetFullPath() < r->GetFullPath();
  880. }
  881. };
  882. //----------------------------------------------------------------------------
  883. void
  884. cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
  885. std::vector<cmXCodeObject*>&
  886. targets)
  887. {
  888. this->SetCurrentLocalGenerator(gen);
  889. cmTargets &tgts = this->CurrentMakefile->GetTargets();
  890. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  891. {
  892. cmTarget& cmtarget = l->second;
  893. // make sure ALL_BUILD, INSTALL, etc are only done once
  894. if(this->SpecialTargetEmitted(l->first.c_str()))
  895. {
  896. continue;
  897. }
  898. if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
  899. {
  900. continue;
  901. }
  902. if(cmtarget.GetType() == cmTarget::UTILITY ||
  903. cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
  904. {
  905. targets.push_back(this->CreateUtilityTarget(cmtarget));
  906. continue;
  907. }
  908. // organize the sources
  909. std::vector<cmSourceFile*> classes = cmtarget.GetSourceFiles();
  910. std::sort(classes.begin(), classes.end(), cmSourceFilePathCompare());
  911. std::vector<cmXCodeObject*> externalObjFiles;
  912. std::vector<cmXCodeObject*> headerFiles;
  913. std::vector<cmXCodeObject*> resourceFiles;
  914. std::vector<cmXCodeObject*> sourceFiles;
  915. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  916. i != classes.end(); ++i)
  917. {
  918. cmXCodeObject* xsf =
  919. this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
  920. *i, cmtarget);
  921. cmXCodeObject* fr = xsf->GetObject("fileRef");
  922. cmXCodeObject* filetype =
  923. fr->GetObject()->GetObject("explicitFileType");
  924. cmTarget::SourceFileFlags tsFlags =
  925. cmtarget.GetTargetSourceFileFlags(*i);
  926. if(filetype &&
  927. strcmp(filetype->GetString(), "compiled.mach-o.objfile") == 0)
  928. {
  929. externalObjFiles.push_back(xsf);
  930. }
  931. else if(this->IsHeaderFile(*i) ||
  932. (tsFlags.Type == cmTarget::SourceFileTypePrivateHeader) ||
  933. (tsFlags.Type == cmTarget::SourceFileTypePublicHeader))
  934. {
  935. headerFiles.push_back(xsf);
  936. }
  937. else if(tsFlags.Type == cmTarget::SourceFileTypeResource)
  938. {
  939. resourceFiles.push_back(xsf);
  940. }
  941. else if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  942. {
  943. // Include this file in the build if it has a known language
  944. // and has not been listed as an ignored extension for this
  945. // generator.
  946. if(this->CurrentLocalGenerator->GetSourceFileLanguage(**i) &&
  947. !this->IgnoreFile((*i)->GetExtension().c_str()))
  948. {
  949. sourceFiles.push_back(xsf);
  950. }
  951. }
  952. }
  953. if(this->XcodeVersion < 50)
  954. {
  955. // Add object library contents as external objects. (Equivalent to
  956. // the externalObjFiles above, except each one is not a cmSourceFile
  957. // within the target.)
  958. std::vector<std::string> objs;
  959. this->GetGeneratorTarget(&cmtarget)->UseObjectLibraries(objs);
  960. for(std::vector<std::string>::const_iterator
  961. oi = objs.begin(); oi != objs.end(); ++oi)
  962. {
  963. std::string obj = *oi;
  964. cmXCodeObject* xsf =
  965. this->CreateXCodeSourceFileFromPath(obj, cmtarget, "");
  966. externalObjFiles.push_back(xsf);
  967. }
  968. }
  969. // some build phases only apply to bundles and/or frameworks
  970. bool isFrameworkTarget = cmtarget.IsFrameworkOnApple();
  971. bool isBundleTarget = cmtarget.GetPropertyAsBool("MACOSX_BUNDLE");
  972. bool isCFBundleTarget = cmtarget.IsCFBundleOnApple();
  973. cmXCodeObject* buildFiles = 0;
  974. // create source build phase
  975. cmXCodeObject* sourceBuildPhase = 0;
  976. if (!sourceFiles.empty())
  977. {
  978. sourceBuildPhase =
  979. this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
  980. sourceBuildPhase->SetComment("Sources");
  981. sourceBuildPhase->AddAttribute("buildActionMask",
  982. this->CreateString("2147483647"));
  983. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  984. for(std::vector<cmXCodeObject*>::iterator i = sourceFiles.begin();
  985. i != sourceFiles.end(); ++i)
  986. {
  987. buildFiles->AddObject(*i);
  988. }
  989. sourceBuildPhase->AddAttribute("files", buildFiles);
  990. sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  991. this->CreateString("0"));
  992. }
  993. // create header build phase - only for framework targets
  994. cmXCodeObject* headerBuildPhase = 0;
  995. if (!headerFiles.empty() && isFrameworkTarget)
  996. {
  997. headerBuildPhase =
  998. this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase);
  999. headerBuildPhase->SetComment("Headers");
  1000. headerBuildPhase->AddAttribute("buildActionMask",
  1001. this->CreateString("2147483647"));
  1002. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1003. for(std::vector<cmXCodeObject*>::iterator i = headerFiles.begin();
  1004. i != headerFiles.end(); ++i)
  1005. {
  1006. buildFiles->AddObject(*i);
  1007. }
  1008. headerBuildPhase->AddAttribute("files", buildFiles);
  1009. headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1010. this->CreateString("0"));
  1011. }
  1012. // create resource build phase - only for framework or bundle targets
  1013. cmXCodeObject* resourceBuildPhase = 0;
  1014. if (!resourceFiles.empty() &&
  1015. (isFrameworkTarget || isBundleTarget || isCFBundleTarget))
  1016. {
  1017. resourceBuildPhase =
  1018. this->CreateObject(cmXCodeObject::PBXResourcesBuildPhase);
  1019. resourceBuildPhase->SetComment("Resources");
  1020. resourceBuildPhase->AddAttribute("buildActionMask",
  1021. this->CreateString("2147483647"));
  1022. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1023. for(std::vector<cmXCodeObject*>::iterator i = resourceFiles.begin();
  1024. i != resourceFiles.end(); ++i)
  1025. {
  1026. buildFiles->AddObject(*i);
  1027. }
  1028. resourceBuildPhase->AddAttribute("files", buildFiles);
  1029. resourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1030. this->CreateString("0"));
  1031. }
  1032. // create vector of "non-resource content file" build phases - only for
  1033. // framework or bundle targets
  1034. std::vector<cmXCodeObject*> contentBuildPhases;
  1035. if (isFrameworkTarget || isBundleTarget || isCFBundleTarget)
  1036. {
  1037. typedef std::map<cmStdString, std::vector<cmSourceFile*> >
  1038. mapOfVectorOfSourceFiles;
  1039. mapOfVectorOfSourceFiles bundleFiles;
  1040. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1041. i != classes.end(); ++i)
  1042. {
  1043. cmTarget::SourceFileFlags tsFlags =
  1044. cmtarget.GetTargetSourceFileFlags(*i);
  1045. if(tsFlags.Type == cmTarget::SourceFileTypeMacContent)
  1046. {
  1047. bundleFiles[tsFlags.MacFolder].push_back(*i);
  1048. }
  1049. }
  1050. mapOfVectorOfSourceFiles::iterator mit;
  1051. for ( mit = bundleFiles.begin(); mit != bundleFiles.end(); ++ mit )
  1052. {
  1053. cmXCodeObject* copyFilesBuildPhase =
  1054. this->CreateObject(cmXCodeObject::PBXCopyFilesBuildPhase);
  1055. copyFilesBuildPhase->SetComment("Copy files");
  1056. copyFilesBuildPhase->AddAttribute("buildActionMask",
  1057. this->CreateString("2147483647"));
  1058. copyFilesBuildPhase->AddAttribute("dstSubfolderSpec",
  1059. this->CreateString("6"));
  1060. cmOStringStream ostr;
  1061. if (cmtarget.IsFrameworkOnApple())
  1062. {
  1063. // dstPath in frameworks is relative to Versions/<version>
  1064. ostr << mit->first;
  1065. }
  1066. else if ( mit->first != "MacOS" )
  1067. {
  1068. // dstPath in bundles is relative to Contents/MacOS
  1069. ostr << "../" << mit->first.c_str();
  1070. }
  1071. copyFilesBuildPhase->AddAttribute("dstPath",
  1072. this->CreateString(ostr.str().c_str()));
  1073. copyFilesBuildPhase->AddAttribute(
  1074. "runOnlyForDeploymentPostprocessing", this->CreateString("0"));
  1075. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1076. copyFilesBuildPhase->AddAttribute("files", buildFiles);
  1077. std::vector<cmSourceFile*>::iterator sfIt;
  1078. for ( sfIt = mit->second.begin(); sfIt != mit->second.end(); ++ sfIt )
  1079. {
  1080. cmXCodeObject* xsf =
  1081. this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
  1082. *sfIt, cmtarget);
  1083. buildFiles->AddObject(xsf);
  1084. }
  1085. contentBuildPhases.push_back(copyFilesBuildPhase);
  1086. }
  1087. }
  1088. // create framework build phase
  1089. cmXCodeObject* frameworkBuildPhase = 0;
  1090. if (!externalObjFiles.empty())
  1091. {
  1092. frameworkBuildPhase =
  1093. this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
  1094. frameworkBuildPhase->SetComment("Frameworks");
  1095. frameworkBuildPhase->AddAttribute("buildActionMask",
  1096. this->CreateString("2147483647"));
  1097. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1098. frameworkBuildPhase->AddAttribute("files", buildFiles);
  1099. for(std::vector<cmXCodeObject*>::iterator i = externalObjFiles.begin();
  1100. i != externalObjFiles.end(); ++i)
  1101. {
  1102. buildFiles->AddObject(*i);
  1103. }
  1104. frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1105. this->CreateString("0"));
  1106. }
  1107. // create list of build phases and create the Xcode target
  1108. cmXCodeObject* buildPhases =
  1109. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1110. this->CreateCustomCommands(buildPhases, sourceBuildPhase,
  1111. headerBuildPhase, resourceBuildPhase,
  1112. contentBuildPhases,
  1113. frameworkBuildPhase, cmtarget);
  1114. targets.push_back(this->CreateXCodeTarget(cmtarget, buildPhases));
  1115. }
  1116. }
  1117. //----------------------------------------------------------------------------
  1118. void cmGlobalXCodeGenerator::ForceLinkerLanguages()
  1119. {
  1120. // This makes sure all targets link using the proper language.
  1121. for(std::map<cmStdString, cmTarget*>::const_iterator
  1122. ti = this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
  1123. {
  1124. this->ForceLinkerLanguage(*ti->second);
  1125. }
  1126. }
  1127. //----------------------------------------------------------------------------
  1128. void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
  1129. {
  1130. // This matters only for targets that link.
  1131. if(cmtarget.GetType() != cmTarget::EXECUTABLE &&
  1132. cmtarget.GetType() != cmTarget::SHARED_LIBRARY &&
  1133. cmtarget.GetType() != cmTarget::MODULE_LIBRARY)
  1134. {
  1135. return;
  1136. }
  1137. const char* llang = cmtarget.GetLinkerLanguage("NOCONFIG");
  1138. if(!llang) { return; }
  1139. // If the language is compiled as a source trust Xcode to link with it.
  1140. cmTarget::LinkImplementation const* impl =
  1141. cmtarget.GetLinkImplementation("NOCONFIG", &cmtarget);
  1142. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1143. li != impl->Languages.end(); ++li)
  1144. {
  1145. if(*li == llang) { return; }
  1146. }
  1147. // Add an empty source file to the target that compiles with the
  1148. // linker language. This should convince Xcode to choose the proper
  1149. // language.
  1150. cmMakefile* mf = cmtarget.GetMakefile();
  1151. std::string fname = mf->GetCurrentOutputDirectory();
  1152. fname += cmake::GetCMakeFilesDirectory();
  1153. fname += "/";
  1154. fname += cmtarget.GetName();
  1155. fname += "-CMakeForceLinker";
  1156. fname += ".";
  1157. fname += cmSystemTools::LowerCase(llang);
  1158. {
  1159. cmGeneratedFileStream fout(fname.c_str());
  1160. fout << "\n";
  1161. }
  1162. if(cmSourceFile* sf = mf->GetOrCreateSource(fname.c_str()))
  1163. {
  1164. sf->SetProperty("LANGUAGE", llang);
  1165. cmtarget.AddSourceFile(sf);
  1166. }
  1167. }
  1168. //----------------------------------------------------------------------------
  1169. bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf)
  1170. {
  1171. const std::vector<std::string>& hdrExts =
  1172. this->CurrentMakefile->GetHeaderExtensions();
  1173. return (std::find(hdrExts.begin(), hdrExts.end(), sf->GetExtension()) !=
  1174. hdrExts.end());
  1175. }
  1176. //----------------------------------------------------------------------------
  1177. cmXCodeObject*
  1178. cmGlobalXCodeGenerator::CreateBuildPhase(const char* name,
  1179. const char* name2,
  1180. cmTarget& cmtarget,
  1181. const std::vector<cmCustomCommand>&
  1182. commands)
  1183. {
  1184. if(commands.size() == 0 && strcmp(name, "CMake ReRun") != 0)
  1185. {
  1186. return 0;
  1187. }
  1188. cmXCodeObject* buildPhase =
  1189. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  1190. buildPhase->AddAttribute("buildActionMask",
  1191. this->CreateString("2147483647"));
  1192. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1193. buildPhase->AddAttribute("files", buildFiles);
  1194. buildPhase->AddAttribute("name",
  1195. this->CreateString(name));
  1196. buildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1197. this->CreateString("0"));
  1198. buildPhase->AddAttribute("shellPath",
  1199. this->CreateString("/bin/sh"));
  1200. this->AddCommandsToBuildPhase(buildPhase, cmtarget, commands,
  1201. name2);
  1202. return buildPhase;
  1203. }
  1204. //----------------------------------------------------------------------------
  1205. void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
  1206. cmXCodeObject*
  1207. sourceBuildPhase,
  1208. cmXCodeObject*
  1209. headerBuildPhase,
  1210. cmXCodeObject*
  1211. resourceBuildPhase,
  1212. std::vector<cmXCodeObject*>
  1213. contentBuildPhases,
  1214. cmXCodeObject*
  1215. frameworkBuildPhase,
  1216. cmTarget& cmtarget)
  1217. {
  1218. std::vector<cmCustomCommand> const & prebuild
  1219. = cmtarget.GetPreBuildCommands();
  1220. std::vector<cmCustomCommand> const & prelink
  1221. = cmtarget.GetPreLinkCommands();
  1222. std::vector<cmCustomCommand> postbuild
  1223. = cmtarget.GetPostBuildCommands();
  1224. if(cmtarget.GetType() == cmTarget::SHARED_LIBRARY &&
  1225. !cmtarget.IsFrameworkOnApple())
  1226. {
  1227. cmCustomCommandLines cmd;
  1228. cmd.resize(1);
  1229. cmd[0].push_back(this->CurrentMakefile->GetDefinition("CMAKE_COMMAND"));
  1230. cmd[0].push_back("-E");
  1231. cmd[0].push_back("cmake_symlink_library");
  1232. std::string str_file = "$<TARGET_FILE:";
  1233. str_file += cmtarget.GetName();
  1234. str_file += ">";
  1235. std::string str_so_file = "$<TARGET_SONAME_FILE:";
  1236. str_so_file += cmtarget.GetName();
  1237. str_so_file += ">";
  1238. std::string str_link_file = "$<TARGET_LINKER_FILE:";
  1239. str_link_file += cmtarget.GetName();
  1240. str_link_file += ">";
  1241. cmd[0].push_back(str_file);
  1242. cmd[0].push_back(str_so_file);
  1243. cmd[0].push_back(str_link_file);
  1244. cmCustomCommand command(this->CurrentMakefile,
  1245. std::vector<std::string>(),
  1246. std::vector<std::string>(),
  1247. cmd,
  1248. "Creating symlinks",
  1249. "");
  1250. postbuild.push_back(command);
  1251. }
  1252. std::vector<cmSourceFile*>const &classes = cmtarget.GetSourceFiles();
  1253. // add all the sources
  1254. std::vector<cmCustomCommand> commands;
  1255. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1256. i != classes.end(); ++i)
  1257. {
  1258. if((*i)->GetCustomCommand())
  1259. {
  1260. commands.push_back(*(*i)->GetCustomCommand());
  1261. }
  1262. }
  1263. // create prebuild phase
  1264. cmXCodeObject* cmakeRulesBuildPhase =
  1265. this->CreateBuildPhase("CMake Rules",
  1266. "cmakeRulesBuildPhase",
  1267. cmtarget, commands);
  1268. // create prebuild phase
  1269. cmXCodeObject* preBuildPhase =
  1270. this->CreateBuildPhase("CMake PreBuild Rules", "preBuildCommands",
  1271. cmtarget, prebuild);
  1272. // create prelink phase
  1273. cmXCodeObject* preLinkPhase =
  1274. this->CreateBuildPhase("CMake PreLink Rules", "preLinkCommands",
  1275. cmtarget, prelink);
  1276. // create postbuild phase
  1277. cmXCodeObject* postBuildPhase =
  1278. this->CreateBuildPhase("CMake PostBuild Rules", "postBuildPhase",
  1279. cmtarget, postbuild);
  1280. // The order here is the order they will be built in.
  1281. // The order "headers, resources, sources" mimics a native project generated
  1282. // from an xcode template...
  1283. //
  1284. if(preBuildPhase)
  1285. {
  1286. buildPhases->AddObject(preBuildPhase);
  1287. }
  1288. if(cmakeRulesBuildPhase)
  1289. {
  1290. buildPhases->AddObject(cmakeRulesBuildPhase);
  1291. }
  1292. if(headerBuildPhase)
  1293. {
  1294. buildPhases->AddObject(headerBuildPhase);
  1295. }
  1296. if(resourceBuildPhase)
  1297. {
  1298. buildPhases->AddObject(resourceBuildPhase);
  1299. }
  1300. std::vector<cmXCodeObject*>::iterator cit;
  1301. for (cit = contentBuildPhases.begin(); cit != contentBuildPhases.end();
  1302. ++cit)
  1303. {
  1304. buildPhases->AddObject(*cit);
  1305. }
  1306. if(sourceBuildPhase)
  1307. {
  1308. buildPhases->AddObject(sourceBuildPhase);
  1309. }
  1310. if(preLinkPhase)
  1311. {
  1312. buildPhases->AddObject(preLinkPhase);
  1313. }
  1314. if(frameworkBuildPhase)
  1315. {
  1316. buildPhases->AddObject(frameworkBuildPhase);
  1317. }
  1318. if(postBuildPhase)
  1319. {
  1320. buildPhases->AddObject(postBuildPhase);
  1321. }
  1322. }
  1323. //----------------------------------------------------------------------------
  1324. // This function removes each occurrence of the flag and returns the last one
  1325. // (i.e., the dominant flag in GCC)
  1326. std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
  1327. std::string& flags)
  1328. {
  1329. std::string retFlag;
  1330. std::string::size_type lastOccurancePos = flags.rfind(flag);
  1331. bool saved = false;
  1332. while(lastOccurancePos != flags.npos)
  1333. {
  1334. //increment pos, we use lastOccurancePos to reduce search space on next inc
  1335. std::string::size_type pos = lastOccurancePos;
  1336. if(pos == 0 || flags[pos-1]==' ')
  1337. {
  1338. while(pos < flags.size() && flags[pos] != ' ')
  1339. {
  1340. if(!saved)
  1341. {
  1342. retFlag += flags[pos];
  1343. }
  1344. flags[pos] = ' ';
  1345. pos++;
  1346. }
  1347. saved = true;
  1348. }
  1349. //decrement lastOccurancePos while making sure we don't loop around
  1350. //and become a very large positive number since size_type is unsigned
  1351. lastOccurancePos = lastOccurancePos == 0 ? 0 : lastOccurancePos-1;
  1352. lastOccurancePos = flags.rfind(flag,lastOccurancePos);
  1353. }
  1354. return retFlag;
  1355. }
  1356. //----------------------------------------------------------------------------
  1357. void
  1358. cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  1359. cmTarget& target,
  1360. std::vector<cmCustomCommand>
  1361. const & commands,
  1362. const char* name)
  1363. {
  1364. // collect multiple outputs of custom commands into a set
  1365. // which will be used for every configuration
  1366. std::map<cmStdString, cmStdString> multipleOutputPairs;
  1367. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1368. i != commands.end(); ++i)
  1369. {
  1370. cmCustomCommand const& cc = *i;
  1371. if(!cc.GetCommandLines().empty())
  1372. {
  1373. const std::vector<std::string>& outputs = cc.GetOutputs();
  1374. if(!outputs.empty())
  1375. {
  1376. // If there are more than one outputs treat the
  1377. // first as the primary output and make the rest depend on it.
  1378. std::vector<std::string>::const_iterator o = outputs.begin();
  1379. std::string primaryOutput = this->ConvertToRelativeForMake(o->c_str());
  1380. for(++o; o != outputs.end(); ++o)
  1381. {
  1382. std::string currentOutput=this->ConvertToRelativeForMake(o->c_str());
  1383. multipleOutputPairs[currentOutput] = primaryOutput;
  1384. }
  1385. }
  1386. }
  1387. }
  1388. std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1389. dir += "/CMakeScripts";
  1390. cmSystemTools::MakeDirectory(dir.c_str());
  1391. std::string makefile = dir;
  1392. makefile += "/";
  1393. makefile += target.GetName();
  1394. makefile += "_";
  1395. makefile += name;
  1396. makefile += ".make";
  1397. for (std::vector<std::string>::const_iterator currentConfig=
  1398. this->CurrentConfigurationTypes.begin();
  1399. currentConfig!=this->CurrentConfigurationTypes.end();
  1400. currentConfig++ )
  1401. {
  1402. this->CreateCustomRulesMakefile(makefile.c_str(),
  1403. target,
  1404. commands,
  1405. currentConfig->c_str(),
  1406. multipleOutputPairs);
  1407. }
  1408. std::string cdir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1409. cdir = this->ConvertToRelativeForXCode(cdir.c_str());
  1410. std::string makecmd = "make -C ";
  1411. makecmd += cdir;
  1412. makecmd += " -f ";
  1413. makecmd += this->ConvertToRelativeForMake(
  1414. (makefile+"$CONFIGURATION").c_str());
  1415. if(!multipleOutputPairs.empty())
  1416. {
  1417. makecmd += " cmake_check_multiple_outputs";
  1418. }
  1419. makecmd += " all";
  1420. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  1421. buildphase->AddAttribute("shellScript",
  1422. this->CreateString(makecmd.c_str()));
  1423. buildphase->AddAttribute("showEnvVarsInLog",
  1424. this->CreateString("0"));
  1425. }
  1426. //----------------------------------------------------------------------------
  1427. void cmGlobalXCodeGenerator
  1428. ::CreateCustomRulesMakefile(const char* makefileBasename,
  1429. cmTarget& target,
  1430. std::vector<cmCustomCommand>
  1431. const & commands,
  1432. const char* configName,
  1433. const std::map<cmStdString,
  1434. cmStdString>& multipleOutputPairs
  1435. )
  1436. {
  1437. std::string makefileName=makefileBasename;
  1438. if(this->XcodeVersion > 20)
  1439. {
  1440. makefileName+=configName;
  1441. }
  1442. cmGeneratedFileStream makefileStream(makefileName.c_str());
  1443. if(!makefileStream)
  1444. {
  1445. return;
  1446. }
  1447. makefileStream.SetCopyIfDifferent(true);
  1448. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  1449. makefileStream << "# Custom rules for " << target.GetName() << "\n";
  1450. // disable the implicit rules
  1451. makefileStream << ".SUFFIXES: " << "\n";
  1452. // have all depend on all outputs
  1453. makefileStream << "all: ";
  1454. std::map<const cmCustomCommand*, cmStdString> tname;
  1455. int count = 0;
  1456. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1457. i != commands.end(); ++i)
  1458. {
  1459. cmCustomCommand const& cc = *i;
  1460. if(!cc.GetCommandLines().empty())
  1461. {
  1462. const std::vector<std::string>& outputs = cc.GetOutputs();
  1463. if(!outputs.empty())
  1464. {
  1465. for(std::vector<std::string>::const_iterator o = outputs.begin();
  1466. o != outputs.end(); ++o)
  1467. {
  1468. makefileStream
  1469. << "\\\n\t" << this->ConvertToRelativeForMake(o->c_str());
  1470. }
  1471. }
  1472. else
  1473. {
  1474. cmOStringStream str;
  1475. str << "_buildpart_" << count++ ;
  1476. tname[&cc] = std::string(target.GetName()) + str.str();
  1477. makefileStream << "\\\n\t" << tname[&cc];
  1478. }
  1479. }
  1480. }
  1481. makefileStream << "\n\n";
  1482. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1483. i != commands.end(); ++i)
  1484. {
  1485. cmCustomCommand const& cc = *i;
  1486. if(!cc.GetCommandLines().empty())
  1487. {
  1488. cmCustomCommandGenerator ccg(cc, configName, this->CurrentMakefile);
  1489. makefileStream << "\n";
  1490. const std::vector<std::string>& outputs = cc.GetOutputs();
  1491. if(!outputs.empty())
  1492. {
  1493. // There is at least one output, start the rule for it
  1494. std::string primary_output =
  1495. this->ConvertToRelativeForMake(outputs.begin()->c_str());
  1496. makefileStream << primary_output << ": ";
  1497. }
  1498. else
  1499. {
  1500. // There are no outputs. Use the generated force rule name.
  1501. makefileStream << tname[&cc] << ": ";
  1502. }
  1503. for(std::vector<std::string>::const_iterator d =
  1504. cc.GetDepends().begin();
  1505. d != cc.GetDepends().end(); ++d)
  1506. {
  1507. std::string dep;
  1508. if(this->CurrentLocalGenerator
  1509. ->GetRealDependency(d->c_str(), configName, dep))
  1510. {
  1511. makefileStream << "\\\n" <<
  1512. this->ConvertToRelativeForMake(dep.c_str());
  1513. }
  1514. }
  1515. makefileStream << "\n";
  1516. if(const char* comment = cc.GetComment())
  1517. {
  1518. std::string echo_cmd = "echo ";
  1519. echo_cmd += (this->CurrentLocalGenerator->
  1520. EscapeForShell(comment, cc.GetEscapeAllowMakeVars()));
  1521. makefileStream << "\t" << echo_cmd.c_str() << "\n";
  1522. }
  1523. // Add each command line to the set of commands.
  1524. for(unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c)
  1525. {
  1526. // Build the command line in a single string.
  1527. std::string cmd2 = ccg.GetCommand(c);
  1528. cmSystemTools::ReplaceString(cmd2, "/./", "/");
  1529. cmd2 = this->ConvertToRelativeForMake(cmd2.c_str());
  1530. std::string cmd;
  1531. if(cc.GetWorkingDirectory())
  1532. {
  1533. cmd += "cd ";
  1534. cmd += this->ConvertToRelativeForMake(cc.GetWorkingDirectory());
  1535. cmd += " && ";
  1536. }
  1537. cmd += cmd2;
  1538. ccg.AppendArguments(c, cmd);
  1539. makefileStream << "\t" << cmd.c_str() << "\n";
  1540. }
  1541. }
  1542. }
  1543. // Add rules to deal with multiple outputs of custom commands.
  1544. if(!multipleOutputPairs.empty())
  1545. {
  1546. makefileStream <<
  1547. "\n# Dependencies of multiple outputs to their primary outputs \n";
  1548. for(std::map<cmStdString, cmStdString>::const_iterator o =
  1549. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1550. {
  1551. makefileStream << o->first << ": " << o->second << "\n";
  1552. }
  1553. makefileStream <<
  1554. "\n"
  1555. "cmake_check_multiple_outputs:\n";
  1556. for(std::map<cmStdString, cmStdString>::const_iterator o =
  1557. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1558. {
  1559. makefileStream << "\t@if [ ! -f "
  1560. << o->first << " ]; then rm -f "
  1561. << o->second << "; fi\n";
  1562. }
  1563. }
  1564. }
  1565. //----------------------------------------------------------------------------
  1566. void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
  1567. cmXCodeObject* buildSettings,
  1568. const char* configName)
  1569. {
  1570. if(target.GetType() == cmTarget::INTERFACE_LIBRARY)
  1571. {
  1572. return;
  1573. }
  1574. std::string flags;
  1575. std::string defFlags;
  1576. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  1577. (target.GetType() == cmTarget::MODULE_LIBRARY));
  1578. bool binary = ((target.GetType() == cmTarget::OBJECT_LIBRARY) ||
  1579. (target.GetType() == cmTarget::STATIC_LIBRARY) ||
  1580. (target.GetType() == cmTarget::EXECUTABLE) ||
  1581. shared);
  1582. const char* lang = target.GetLinkerLanguage(configName);
  1583. std::string cflags;
  1584. if(lang)
  1585. {
  1586. // for c++ projects get the c flags as well
  1587. if(strcmp(lang, "CXX") == 0)
  1588. {
  1589. this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName);
  1590. this->CurrentLocalGenerator->AddCMP0018Flags(cflags, &target,
  1591. "C", configName);
  1592. this->CurrentLocalGenerator->
  1593. AddCompileOptions(cflags, &target, "C", configName);
  1594. }
  1595. // Add language-specific flags.
  1596. this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName);
  1597. // Add shared-library flags if needed.
  1598. this->CurrentLocalGenerator->AddCMP0018Flags(flags, &target,
  1599. lang, configName);
  1600. this->CurrentLocalGenerator->AddVisibilityPresetFlags(flags, &target,
  1601. lang);
  1602. this->CurrentLocalGenerator->
  1603. AddCompileOptions(flags, &target, lang, configName);
  1604. }
  1605. else if(binary)
  1606. {
  1607. cmSystemTools::Error
  1608. ("CMake can not determine linker language for target: ",
  1609. target.GetName());
  1610. return;
  1611. }
  1612. // Add define flags
  1613. this->CurrentLocalGenerator->
  1614. AppendFlags(defFlags,
  1615. this->CurrentMakefile->GetDefineFlags());
  1616. // Add preprocessor definitions for this target and configuration.
  1617. BuildObjectListOrString ppDefs(this, this->XcodeVersion >= 30);
  1618. if(this->XcodeVersion > 15)
  1619. {
  1620. this->AppendDefines(ppDefs,
  1621. "CMAKE_INTDIR=\"$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)\"");
  1622. }
  1623. if(const char* exportMacro = target.GetExportMacro())
  1624. {
  1625. // Add the export symbol definition for shared library objects.
  1626. this->AppendDefines(ppDefs, exportMacro);
  1627. }
  1628. cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
  1629. std::vector<std::string> targetDefines;
  1630. target.GetCompileDefinitions(targetDefines, configName);
  1631. this->AppendDefines(ppDefs, targetDefines);
  1632. buildSettings->AddAttribute
  1633. ("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList());
  1634. std::string extraLinkOptionsVar;
  1635. std::string extraLinkOptions;
  1636. if(target.GetType() == cmTarget::EXECUTABLE)
  1637. {
  1638. extraLinkOptionsVar = "CMAKE_EXE_LINKER_FLAGS";
  1639. }
  1640. else if(target.GetType() == cmTarget::SHARED_LIBRARY)
  1641. {
  1642. extraLinkOptionsVar = "CMAKE_SHARED_LINKER_FLAGS";
  1643. }
  1644. else if(target.GetType() == cmTarget::MODULE_LIBRARY)
  1645. {
  1646. extraLinkOptionsVar = "CMAKE_MODULE_LINKER_FLAGS";
  1647. }
  1648. if(extraLinkOptionsVar.size())
  1649. {
  1650. this->CurrentLocalGenerator
  1651. ->AddConfigVariableFlags(extraLinkOptions,
  1652. extraLinkOptionsVar.c_str(),
  1653. configName);
  1654. }
  1655. if(target.GetType() == cmTarget::OBJECT_LIBRARY ||
  1656. target.GetType() == cmTarget::STATIC_LIBRARY)
  1657. {
  1658. this->CurrentLocalGenerator
  1659. ->GetStaticLibraryFlags(extraLinkOptions,
  1660. cmSystemTools::UpperCase(configName),
  1661. &target);
  1662. }
  1663. else
  1664. {
  1665. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1666. if(targetLinkFlags)
  1667. {
  1668. this->CurrentLocalGenerator->
  1669. AppendFlags(extraLinkOptions, targetLinkFlags);
  1670. }
  1671. if(configName && *configName)
  1672. {
  1673. std::string linkFlagsVar = "LINK_FLAGS_";
  1674. linkFlagsVar += cmSystemTools::UpperCase(configName);
  1675. if(const char* linkFlags = target.GetProperty(linkFlagsVar.c_str()))
  1676. {
  1677. this->CurrentLocalGenerator->
  1678. AppendFlags(extraLinkOptions, linkFlags);
  1679. }
  1680. }
  1681. }
  1682. // Set target-specific architectures.
  1683. std::vector<std::string> archs;
  1684. gtgt->GetAppleArchs(configName, archs);
  1685. if(!archs.empty())
  1686. {
  1687. // Enable ARCHS attribute.
  1688. buildSettings->AddAttribute("ONLY_ACTIVE_ARCH",
  1689. this->CreateString("NO"));
  1690. // Store ARCHS value.
  1691. if(archs.size() == 1)
  1692. {
  1693. buildSettings->AddAttribute("ARCHS",
  1694. this->CreateString(archs[0].c_str()));
  1695. }
  1696. else
  1697. {
  1698. cmXCodeObject* archObjects =
  1699. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1700. for(std::vector<std::string>::iterator i = archs.begin();
  1701. i != archs.end(); i++)
  1702. {
  1703. archObjects->AddObject(this->CreateString((*i).c_str()));
  1704. }
  1705. buildSettings->AddAttribute("ARCHS", archObjects);
  1706. }
  1707. }
  1708. // Get the product name components.
  1709. std::string pnprefix;
  1710. std::string pnbase;
  1711. std::string pnsuffix;
  1712. target.GetFullNameComponents(pnprefix, pnbase, pnsuffix, configName);
  1713. const char* version = target.GetProperty("VERSION");
  1714. const char* soversion = target.GetProperty("SOVERSION");
  1715. if(!target.HasSOName(configName) || target.IsFrameworkOnApple())
  1716. {
  1717. version = 0;
  1718. soversion = 0;
  1719. }
  1720. if(version && !soversion)
  1721. {
  1722. soversion = version;
  1723. }
  1724. if(!version && soversion)
  1725. {
  1726. version = soversion;
  1727. }
  1728. std::string realName = pnbase;
  1729. std::string soName = pnbase;
  1730. if(version && soversion)
  1731. {
  1732. realName += ".";
  1733. realName += version;
  1734. soName += ".";
  1735. soName += soversion;
  1736. }
  1737. // Set attributes to specify the proper name for the target.
  1738. std::string pndir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1739. if(target.GetType() == cmTarget::STATIC_LIBRARY ||
  1740. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1741. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1742. target.GetType() == cmTarget::EXECUTABLE)
  1743. {
  1744. if(this->XcodeVersion >= 21)
  1745. {
  1746. if(!target.UsesDefaultOutputDir(configName, false))
  1747. {
  1748. std::string pncdir = target.GetDirectory(configName);
  1749. buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR",
  1750. this->CreateString(pncdir.c_str()));
  1751. }
  1752. }
  1753. else
  1754. {
  1755. buildSettings->AddAttribute("OBJROOT",
  1756. this->CreateString(pndir.c_str()));
  1757. pndir = target.GetDirectory(configName);
  1758. }
  1759. if(target.IsFrameworkOnApple() || target.IsCFBundleOnApple())
  1760. {
  1761. pnprefix = "";
  1762. }
  1763. buildSettings->AddAttribute("EXECUTABLE_PREFIX",
  1764. this->CreateString(pnprefix.c_str()));
  1765. buildSettings->AddAttribute("EXECUTABLE_SUFFIX",
  1766. this->CreateString(pnsuffix.c_str()));
  1767. }
  1768. else if(target.GetType() == cmTarget::OBJECT_LIBRARY)
  1769. {
  1770. pnprefix = "lib";
  1771. pnbase = target.GetName();
  1772. pnsuffix = ".a";
  1773. if(this->XcodeVersion >= 21)
  1774. {
  1775. std::string pncdir = this->GetObjectsNormalDirectory(
  1776. this->CurrentProject, configName, &target);
  1777. buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR",
  1778. this->CreateString(pncdir.c_str()));
  1779. }
  1780. else
  1781. {
  1782. buildSettings->AddAttribute("OBJROOT",
  1783. this->CreateString(pndir.c_str()));
  1784. pndir = this->GetObjectsNormalDirectory(
  1785. this->CurrentProject, configName, &target);
  1786. }
  1787. }
  1788. // Store the product name for all target types.
  1789. buildSettings->AddAttribute("PRODUCT_NAME",
  1790. this->CreateString(realName.c_str()));
  1791. buildSettings->AddAttribute("SYMROOT",
  1792. this->CreateString(pndir.c_str()));
  1793. // Handle settings for each target type.
  1794. switch(target.GetType())
  1795. {
  1796. case cmTarget::OBJECT_LIBRARY:
  1797. case cmTarget::STATIC_LIBRARY:
  1798. {
  1799. buildSettings->AddAttribute("LIBRARY_STYLE",
  1800. this->CreateString("STATIC"));
  1801. break;
  1802. }
  1803. case cmTarget::MODULE_LIBRARY:
  1804. {
  1805. buildSettings->AddAttribute("LIBRARY_STYLE",
  1806. this->CreateString("BUNDLE"));
  1807. if (target.GetPropertyAsBool("BUNDLE"))
  1808. {
  1809. // It turns out that a BUNDLE is basically the same
  1810. // in many ways as an application bundle, as far as
  1811. // link flags go
  1812. std::string createFlags =
  1813. this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
  1814. "-bundle");
  1815. if(!createFlags.empty())
  1816. {
  1817. extraLinkOptions += " ";
  1818. extraLinkOptions += createFlags;
  1819. }
  1820. std::string plist = this->ComputeInfoPListLocation(target);
  1821. // Xcode will create the final version of Info.plist at build time,
  1822. // so let it replace the cfbundle name. This avoids creating
  1823. // a per-configuration Info.plist file. The cfbundle plist
  1824. // is very similar to the application bundle plist
  1825. this->CurrentLocalGenerator
  1826. ->GenerateAppleInfoPList(&target, "$(EXECUTABLE_NAME)",
  1827. plist.c_str());
  1828. std::string path =
  1829. this->ConvertToRelativeForXCode(plist.c_str());
  1830. buildSettings->AddAttribute("INFOPLIST_FILE",
  1831. this->CreateString(path.c_str()));
  1832. }
  1833. else if(this->XcodeVersion >= 22)
  1834. {
  1835. buildSettings->AddAttribute("MACH_O_TYPE",
  1836. this->CreateString("mh_bundle"));
  1837. buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
  1838. this->CreateString("NO"));
  1839. // Add the flags to create an executable.
  1840. std::string createFlags =
  1841. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1842. if(!createFlags.empty())
  1843. {
  1844. extraLinkOptions += " ";
  1845. extraLinkOptions += createFlags;
  1846. }
  1847. }
  1848. else
  1849. {
  1850. // Add the flags to create a module.
  1851. std::string createFlags =
  1852. this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
  1853. "-bundle");
  1854. if(!createFlags.empty())
  1855. {
  1856. extraLinkOptions += " ";
  1857. extraLinkOptions += createFlags;
  1858. }
  1859. }
  1860. break;
  1861. }
  1862. case cmTarget::SHARED_LIBRARY:
  1863. {
  1864. if(target.GetPropertyAsBool("FRAMEWORK"))
  1865. {
  1866. std::string fw_version = target.GetFrameworkVersion();
  1867. buildSettings->AddAttribute("FRAMEWORK_VERSION",
  1868. this->CreateString(fw_version.c_str()));
  1869. std::string plist = this->ComputeInfoPListLocation(target);
  1870. // Xcode will create the final version of Info.plist at build time,
  1871. // so let it replace the framework name. This avoids creating
  1872. // a per-configuration Info.plist file.
  1873. this->CurrentLocalGenerator
  1874. ->GenerateFrameworkInfoPList(&target, "$(EXECUTABLE_NAME)",
  1875. plist.c_str());
  1876. std::string path =
  1877. this->ConvertToRelativeForXCode(plist.c_str());
  1878. buildSettings->AddAttribute("INFOPLIST_FILE",
  1879. this->CreateString(path.c_str()));
  1880. }
  1881. else
  1882. {
  1883. // Add the flags to create a shared library.
  1884. std::string createFlags =
  1885. this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", lang, "_FLAGS",
  1886. "-dynamiclib");
  1887. if(!createFlags.empty())
  1888. {
  1889. extraLinkOptions += " ";
  1890. extraLinkOptions += createFlags;
  1891. }
  1892. }
  1893. buildSettings->AddAttribute("LIBRARY_STYLE",
  1894. this->CreateString("DYNAMIC"));
  1895. break;
  1896. }
  1897. case cmTarget::EXECUTABLE:
  1898. {
  1899. // Add the flags to create an executable.
  1900. std::string createFlags =
  1901. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1902. if(!createFlags.empty())
  1903. {
  1904. extraLinkOptions += " ";
  1905. extraLinkOptions += createFlags;
  1906. }
  1907. // Handle bundles and normal executables separately.
  1908. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  1909. {
  1910. std::string plist = this->ComputeInfoPListLocation(target);
  1911. // Xcode will create the final version of Info.plist at build time,
  1912. // so let it replace the executable name. This avoids creating
  1913. // a per-configuration Info.plist file.
  1914. this->CurrentLocalGenerator
  1915. ->GenerateAppleInfoPList(&target, "$(EXECUTABLE_NAME)",
  1916. plist.c_str());
  1917. std::string path =
  1918. this->ConvertToRelativeForXCode(plist.c_str());
  1919. buildSettings->AddAttribute("INFOPLIST_FILE",
  1920. this->CreateString(path.c_str()));
  1921. }
  1922. }
  1923. break;
  1924. default:
  1925. break;
  1926. }
  1927. if(this->XcodeVersion >= 22 && this->XcodeVersion < 40)
  1928. {
  1929. buildSettings->AddAttribute("PREBINDING",
  1930. this->CreateString("NO"));
  1931. }
  1932. BuildObjectListOrString dirs(this, this->XcodeVersion >= 30);
  1933. BuildObjectListOrString fdirs(this, this->XcodeVersion >= 30);
  1934. std::vector<std::string> includes;
  1935. this->CurrentLocalGenerator->GetIncludeDirectories(includes, gtgt,
  1936. "C", configName);
  1937. std::set<cmStdString> emitted;
  1938. emitted.insert("/System/Library/Frameworks");
  1939. for(std::vector<std::string>::iterator i = includes.begin();
  1940. i != includes.end(); ++i)
  1941. {
  1942. if(this->NameResolvesToFramework(i->c_str()))
  1943. {
  1944. std::string frameworkDir = *i;
  1945. frameworkDir += "/../";
  1946. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1947. if(emitted.insert(frameworkDir).second)
  1948. {
  1949. fdirs.Add(this->XCodeEscapePath(frameworkDir.c_str()).c_str());
  1950. }
  1951. }
  1952. else
  1953. {
  1954. std::string incpath =
  1955. this->XCodeEscapePath(i->c_str());
  1956. dirs.Add(incpath.c_str());
  1957. }
  1958. }
  1959. // Add framework search paths needed for linking.
  1960. if(cmComputeLinkInformation* cli = target.GetLinkInformation(configName))
  1961. {
  1962. std::vector<std::string> const& fwDirs = cli->GetFrameworkPaths();
  1963. for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1964. fdi != fwDirs.end(); ++fdi)
  1965. {
  1966. if(emitted.insert(*fdi).second)
  1967. {
  1968. fdirs.Add(this->XCodeEscapePath(fdi->c_str()).c_str());
  1969. }
  1970. }
  1971. }
  1972. if(!fdirs.IsEmpty())
  1973. {
  1974. buildSettings->AddAttribute("FRAMEWORK_SEARCH_PATHS",
  1975. fdirs.CreateList());
  1976. }
  1977. if(!dirs.IsEmpty())
  1978. {
  1979. buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
  1980. dirs.CreateList());
  1981. }
  1982. std::string oflagc = this->ExtractFlag("-O", cflags);
  1983. char optLevel[2];
  1984. optLevel[0] = '0';
  1985. optLevel[1] = 0;
  1986. if(oflagc.size() == 3)
  1987. {
  1988. optLevel[0] = oflagc[2];
  1989. }
  1990. if(oflagc.size() == 2)
  1991. {
  1992. optLevel[0] = '1';
  1993. }
  1994. std::string oflag = this->ExtractFlag("-O", flags);
  1995. if(oflag.size() == 3)
  1996. {
  1997. optLevel[0] = oflag[2];
  1998. }
  1999. if(oflag.size() == 2)
  2000. {
  2001. optLevel[0] = '1';
  2002. }
  2003. std::string gflagc = this->ExtractFlag("-g", cflags);
  2004. // put back gdwarf-2 if used since there is no way
  2005. // to represent it in the gui, but we still want debug yes
  2006. if(gflagc == "-gdwarf-2")
  2007. {
  2008. cflags += " ";
  2009. cflags += gflagc;
  2010. }
  2011. std::string gflag = this->ExtractFlag("-g", flags);
  2012. if(gflag == "-gdwarf-2")
  2013. {
  2014. flags += " ";
  2015. flags += gflag;
  2016. }
  2017. const char* debugStr = "YES";
  2018. // We can't set the Xcode flag differently depending on the language,
  2019. // so put them back in this case.
  2020. if( (lang && strcmp(lang, "CXX") == 0) && gflag != gflagc )
  2021. {
  2022. cflags += " ";
  2023. cflags += gflagc;
  2024. flags += " ";
  2025. flags += gflag;
  2026. debugStr = "NO";
  2027. }
  2028. if( gflag == "-g0" || gflag.size() == 0 )
  2029. {
  2030. debugStr = "NO";
  2031. }
  2032. buildSettings->AddAttribute("COMBINE_HIDPI_IMAGES",
  2033. this->CreateString("YES"));
  2034. buildSettings->AddAttribute("GCC_GENERATE_DEBUGGING_SYMBOLS",
  2035. this->CreateString(debugStr));
  2036. buildSettings->AddAttribute("GCC_OPTIMIZATION_LEVEL",
  2037. this->CreateString(optLevel));
  2038. buildSettings->AddAttribute("GCC_SYMBOLS_PRIVATE_EXTERN",
  2039. this->CreateString("NO"));
  2040. buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
  2041. this->CreateString("NO"));
  2042. if(lang && strcmp(lang, "CXX") == 0)
  2043. {
  2044. flags += " ";
  2045. flags += defFlags;
  2046. buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
  2047. this->CreateString(flags.c_str()));
  2048. cflags += " ";
  2049. cflags += defFlags;
  2050. buildSettings->AddAttribute("OTHER_CFLAGS",
  2051. this->CreateString(cflags.c_str()));
  2052. }
  2053. else
  2054. {
  2055. flags += " ";
  2056. flags += defFlags;
  2057. buildSettings->AddAttribute("OTHER_CFLAGS",
  2058. this->CreateString(flags.c_str()));
  2059. }
  2060. // Add Fortran source format attribute if property is set.
  2061. const char* format = 0;
  2062. const char* tgtfmt = target.GetProperty("Fortran_FORMAT");
  2063. switch(this->CurrentLocalGenerator->GetFortranFormat(tgtfmt))
  2064. {
  2065. case cmLocalGenerator::FortranFormatFixed: format = "fixed"; break;
  2066. case cmLocalGenerator::FortranFormatFree: format = "free"; break;
  2067. default: break;
  2068. }
  2069. if(format)
  2070. {
  2071. buildSettings->AddAttribute("IFORT_LANG_SRCFMT",
  2072. this->CreateString(format));
  2073. }
  2074. // Create the INSTALL_PATH attribute.
  2075. std::string install_name_dir;
  2076. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  2077. {
  2078. // Get the install_name directory for the build tree.
  2079. install_name_dir = target.GetInstallNameDirForBuildTree(configName);
  2080. // Xcode doesn't create the correct install_name in some cases.
  2081. // That is, if the INSTALL_PATH is empty, or if we have versioning
  2082. // of dylib libraries, we want to specify the install_name.
  2083. // This is done by adding a link flag to create an install_name
  2084. // with just the library soname.
  2085. std::string install_name;
  2086. if(!install_name_dir.empty())
  2087. {
  2088. // Convert to a path for the native build tool.
  2089. cmSystemTools::ConvertToUnixSlashes(install_name_dir);
  2090. install_name += install_name_dir;
  2091. install_name += "/";
  2092. }
  2093. install_name += target.GetSOName(configName);
  2094. if((realName != soName) || install_name_dir.empty())
  2095. {
  2096. install_name_dir = "";
  2097. extraLinkOptions += " -install_name ";
  2098. extraLinkOptions += XCodeEscapePath(install_name.c_str());
  2099. }
  2100. }
  2101. buildSettings->AddAttribute("INSTALL_PATH",
  2102. this->CreateString(install_name_dir.c_str()));
  2103. // Create the LD_RUNPATH_SEARCH_PATHS
  2104. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  2105. if(pcli)
  2106. {
  2107. std::string search_paths;
  2108. std::vector<std::string> runtimeDirs;
  2109. pcli->GetRPath(runtimeDirs, false);
  2110. for(std::vector<std::string>::const_iterator i = runtimeDirs.begin();
  2111. i != runtimeDirs.end(); ++i)
  2112. {
  2113. if(!search_paths.empty())
  2114. {
  2115. search_paths += " ";
  2116. }
  2117. search_paths += this->XCodeEscapePath((*i).c_str());
  2118. }
  2119. if(!search_paths.empty())
  2120. {
  2121. buildSettings->AddAttribute("LD_RUNPATH_SEARCH_PATHS",
  2122. this->CreateString(search_paths.c_str()));
  2123. }
  2124. }
  2125. buildSettings->AddAttribute("OTHER_LDFLAGS",
  2126. this->CreateString(extraLinkOptions.c_str()));
  2127. buildSettings->AddAttribute("OTHER_REZFLAGS",
  2128. this->CreateString(""));
  2129. buildSettings->AddAttribute("SECTORDER_FLAGS",
  2130. this->CreateString(""));
  2131. buildSettings->AddAttribute("USE_HEADERMAP",
  2132. this->CreateString("NO"));
  2133. if (this->XcodeVersion >= 30)
  2134. {
  2135. cmXCodeObject *group = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2136. group->AddObject(this->CreateString("-Wmost"));
  2137. group->AddObject(this->CreateString("-Wno-four-char-constants"));
  2138. group->AddObject(this->CreateString("-Wno-unknown-pragmas"));
  2139. buildSettings->AddAttribute("WARNING_CFLAGS", group);
  2140. }
  2141. else
  2142. {
  2143. buildSettings->AddAttribute("WARNING_CFLAGS",
  2144. this->CreateString(
  2145. "-Wmost -Wno-four-char-constants"
  2146. " -Wno-unknown-pragmas"));
  2147. }
  2148. // Runtime version information.
  2149. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  2150. {
  2151. int major;
  2152. int minor;
  2153. int patch;
  2154. // VERSION -> current_version
  2155. target.GetTargetVersion(false, major, minor, patch);
  2156. cmOStringStream v;
  2157. // Xcode always wants at least 1.0.0 or nothing
  2158. if(!(major == 0 && minor == 0 && patch == 0))
  2159. {
  2160. v << major << "." << minor << "." << patch;
  2161. }
  2162. buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
  2163. this->CreateString(v.str().c_str()));
  2164. // SOVERSION -> compatibility_version
  2165. target.GetTargetVersion(true, major, minor, patch);
  2166. cmOStringStream vso;
  2167. // Xcode always wants at least 1.0.0 or nothing
  2168. if(!(major == 0 && minor == 0 && patch == 0))
  2169. {
  2170. vso << major << "." << minor << "." << patch;
  2171. }
  2172. buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
  2173. this->CreateString(vso.str().c_str()));
  2174. }
  2175. // put this last so it can override existing settings
  2176. // Convert "XCODE_ATTRIBUTE_*" properties directly.
  2177. {
  2178. cmPropertyMap const& props = target.GetProperties();
  2179. for(cmPropertyMap::const_iterator i = props.begin();
  2180. i != props.end(); ++i)
  2181. {
  2182. if(i->first.find("XCODE_ATTRIBUTE_") == 0)
  2183. {
  2184. cmStdString attribute = i->first.substr(16);
  2185. // Handle [variant=<config>] condition explicitly here.
  2186. cmStdString::size_type beginVariant =
  2187. attribute.find("[variant=");
  2188. if (beginVariant != cmStdString::npos)
  2189. {
  2190. cmStdString::size_type endVariant =
  2191. attribute.find("]", beginVariant+9);
  2192. if (endVariant != cmStdString::npos)
  2193. {
  2194. // Compare the variant to the configuration.
  2195. cmStdString variant =
  2196. attribute.substr(beginVariant+9, endVariant-beginVariant-9);
  2197. if (variant == configName)
  2198. {
  2199. // The variant matches the configuration so use this
  2200. // attribute but drop the [variant=<config>] condition.
  2201. attribute.erase(beginVariant, endVariant-beginVariant+1);
  2202. }
  2203. else
  2204. {
  2205. // The variant does not match the configuration so
  2206. // do not use this attribute.
  2207. attribute.clear();
  2208. }
  2209. }
  2210. }
  2211. if (!attribute.empty())
  2212. {
  2213. buildSettings->AddAttribute(attribute.c_str(),
  2214. this->CreateString(i->second.GetValue()));
  2215. }
  2216. }
  2217. }
  2218. }
  2219. }
  2220. //----------------------------------------------------------------------------
  2221. cmXCodeObject*
  2222. cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
  2223. {
  2224. cmXCodeObject* shellBuildPhase =
  2225. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  2226. shellBuildPhase->AddAttribute("buildActionMask",
  2227. this->CreateString("2147483647"));
  2228. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2229. shellBuildPhase->AddAttribute("files", buildFiles);
  2230. cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2231. shellBuildPhase->AddAttribute("inputPaths", inputPaths);
  2232. cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2233. shellBuildPhase->AddAttribute("outputPaths", outputPaths);
  2234. shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  2235. this->CreateString("0"));
  2236. shellBuildPhase->AddAttribute("shellPath",
  2237. this->CreateString("/bin/sh"));
  2238. shellBuildPhase->AddAttribute("shellScript",
  2239. this->CreateString(
  2240. "# shell script goes here\nexit 0"));
  2241. shellBuildPhase->AddAttribute("showEnvVarsInLog",
  2242. this->CreateString("0"));
  2243. cmXCodeObject* target =
  2244. this->CreateObject(cmXCodeObject::PBXAggregateTarget);
  2245. target->SetComment(cmtarget.GetName());
  2246. cmXCodeObject* buildPhases =
  2247. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2248. std::vector<cmXCodeObject*> emptyContentVector;
  2249. this->CreateCustomCommands(buildPhases, 0, 0, 0, emptyContentVector, 0,
  2250. cmtarget);
  2251. target->AddAttribute("buildPhases", buildPhases);
  2252. if(this->XcodeVersion > 20)
  2253. {
  2254. this->AddConfigurations(target, cmtarget);
  2255. }
  2256. else
  2257. {
  2258. const char* theConfig =
  2259. this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
  2260. cmXCodeObject* buildSettings =
  2261. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2262. this->CreateBuildSettings(cmtarget, buildSettings, theConfig);
  2263. target->AddAttribute("buildSettings", buildSettings);
  2264. }
  2265. cmXCodeObject* dependencies =
  2266. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2267. target->AddAttribute("dependencies", dependencies);
  2268. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  2269. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  2270. target->SetTarget(&cmtarget);
  2271. // Add source files without build rules for editing convenience.
  2272. if(cmtarget.GetType() == cmTarget::UTILITY)
  2273. {
  2274. std::vector<cmSourceFile*> const& sources = cmtarget.GetSourceFiles();
  2275. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  2276. i != sources.end(); ++i)
  2277. {
  2278. if(!(*i)->GetPropertyAsBool("GENERATED"))
  2279. {
  2280. this->CreateXCodeFileReference(*i, cmtarget);
  2281. }
  2282. }
  2283. }
  2284. target->SetId(this->GetOrCreateId(
  2285. cmtarget.GetName(), target->GetId()).c_str());
  2286. return target;
  2287. }
  2288. //----------------------------------------------------------------------------
  2289. std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
  2290. cmTarget& cmtarget)
  2291. {
  2292. std::string configTypes =
  2293. this->CurrentMakefile->GetRequiredDefinition("CMAKE_CONFIGURATION_TYPES");
  2294. std::vector<std::string> configVectorIn;
  2295. std::vector<std::string> configVector;
  2296. configVectorIn.push_back(configTypes);
  2297. cmSystemTools::ExpandList(configVectorIn, configVector);
  2298. cmXCodeObject* configlist =
  2299. this->CreateObject(cmXCodeObject::XCConfigurationList);
  2300. cmXCodeObject* buildConfigurations =
  2301. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2302. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  2303. std::string comment = "Build configuration list for ";
  2304. comment += cmXCodeObject::PBXTypeNames[target->GetIsA()];
  2305. comment += " \"";
  2306. comment += cmtarget.GetName();
  2307. comment += "\"";
  2308. configlist->SetComment(comment.c_str());
  2309. target->AddAttribute("buildConfigurationList",
  2310. this->CreateObjectReference(configlist));
  2311. for(unsigned int i = 0; i < configVector.size(); ++i)
  2312. {
  2313. cmXCodeObject* config =
  2314. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  2315. buildConfigurations->AddObject(config);
  2316. cmXCodeObject* buildSettings =
  2317. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2318. this->CreateBuildSettings(cmtarget, buildSettings,
  2319. configVector[i].c_str());
  2320. config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
  2321. config->SetComment(configVector[i].c_str());
  2322. config->AddAttribute("buildSettings", buildSettings);
  2323. }
  2324. if(configVector.size())
  2325. {
  2326. configlist->AddAttribute("defaultConfigurationName",
  2327. this->CreateString(configVector[0].c_str()));
  2328. configlist->AddAttribute("defaultConfigurationIsVisible",
  2329. this->CreateString("0"));
  2330. return configVector[0];
  2331. }
  2332. return "";
  2333. }
  2334. //----------------------------------------------------------------------------
  2335. const char* cmGlobalXCodeGenerator::GetTargetFileType(cmTarget& cmtarget)
  2336. {
  2337. switch(cmtarget.GetType())
  2338. {
  2339. case cmTarget::OBJECT_LIBRARY:
  2340. case cmTarget::STATIC_LIBRARY:
  2341. return "archive.ar";
  2342. case cmTarget::MODULE_LIBRARY:
  2343. if (cmtarget.IsCFBundleOnApple())
  2344. return "wrapper.plug-in";
  2345. else
  2346. return ((this->XcodeVersion >= 22)?
  2347. "compiled.mach-o.executable" : "compiled.mach-o.dylib");
  2348. case cmTarget::SHARED_LIBRARY:
  2349. return (cmtarget.GetPropertyAsBool("FRAMEWORK")?
  2350. "wrapper.framework" : "compiled.mach-o.dylib");
  2351. case cmTarget::EXECUTABLE:
  2352. return "compiled.mach-o.executable";
  2353. default: break;
  2354. }
  2355. return 0;
  2356. }
  2357. //----------------------------------------------------------------------------
  2358. const char* cmGlobalXCodeGenerator::GetTargetProductType(cmTarget& cmtarget)
  2359. {
  2360. switch(cmtarget.GetType())
  2361. {
  2362. case cmTarget::OBJECT_LIBRARY:
  2363. case cmTarget::STATIC_LIBRARY:
  2364. return "com.apple.product-type.library.static";
  2365. case cmTarget::MODULE_LIBRARY:
  2366. if (cmtarget.IsCFBundleOnApple())
  2367. return "com.apple.product-type.bundle";
  2368. else
  2369. return ((this->XcodeVersion >= 22)?
  2370. "com.apple.product-type.tool" :
  2371. "com.apple.product-type.library.dynamic");
  2372. case cmTarget::SHARED_LIBRARY:
  2373. return (cmtarget.GetPropertyAsBool("FRAMEWORK")?
  2374. "com.apple.product-type.framework" :
  2375. "com.apple.product-type.library.dynamic");
  2376. case cmTarget::EXECUTABLE:
  2377. return (cmtarget.GetPropertyAsBool("MACOSX_BUNDLE")?
  2378. "com.apple.product-type.application" :
  2379. "com.apple.product-type.tool");
  2380. default: break;
  2381. }
  2382. return 0;
  2383. }
  2384. //----------------------------------------------------------------------------
  2385. cmXCodeObject*
  2386. cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
  2387. cmXCodeObject* buildPhases)
  2388. {
  2389. if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
  2390. {
  2391. return 0;
  2392. }
  2393. cmXCodeObject* target =
  2394. this->CreateObject(cmXCodeObject::PBXNativeTarget);
  2395. target->AddAttribute("buildPhases", buildPhases);
  2396. cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2397. target->AddAttribute("buildRules", buildRules);
  2398. std::string defConfig;
  2399. if(this->XcodeVersion > 20)
  2400. {
  2401. defConfig = this->AddConfigurations(target, cmtarget);
  2402. }
  2403. else
  2404. {
  2405. cmXCodeObject* buildSettings =
  2406. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2407. defConfig = this->CurrentMakefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  2408. this->CreateBuildSettings(cmtarget, buildSettings, defConfig.c_str());
  2409. target->AddAttribute("buildSettings", buildSettings);
  2410. }
  2411. cmXCodeObject* dependencies =
  2412. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2413. target->AddAttribute("dependencies", dependencies);
  2414. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  2415. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  2416. cmXCodeObject* fileRef =
  2417. this->CreateObject(cmXCodeObject::PBXFileReference);
  2418. if(const char* fileType = this->GetTargetFileType(cmtarget))
  2419. {
  2420. fileRef->AddAttribute("explicitFileType", this->CreateString(fileType));
  2421. }
  2422. std::string fullName;
  2423. if(cmtarget.GetType() == cmTarget::OBJECT_LIBRARY)
  2424. {
  2425. fullName = "lib";
  2426. fullName += cmtarget.GetName();
  2427. fullName += ".a";
  2428. }
  2429. else
  2430. {
  2431. fullName = cmtarget.GetFullName(defConfig.c_str());
  2432. }
  2433. fileRef->AddAttribute("path", this->CreateString(fullName.c_str()));
  2434. fileRef->AddAttribute("refType", this->CreateString("0"));
  2435. fileRef->AddAttribute("sourceTree",
  2436. this->CreateString("BUILT_PRODUCTS_DIR"));
  2437. fileRef->SetComment(cmtarget.GetName());
  2438. target->AddAttribute("productReference",
  2439. this->CreateObjectReference(fileRef));
  2440. if(const char* productType = this->GetTargetProductType(cmtarget))
  2441. {
  2442. target->AddAttribute("productType", this->CreateString(productType));
  2443. }
  2444. target->SetTarget(&cmtarget);
  2445. target->SetId(this->GetOrCreateId(
  2446. cmtarget.GetName(), target->GetId()).c_str());
  2447. return target;
  2448. }
  2449. //----------------------------------------------------------------------------
  2450. cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget const* t)
  2451. {
  2452. if(!t)
  2453. {
  2454. return 0;
  2455. }
  2456. for(std::vector<cmXCodeObject*>::iterator i = this->XCodeObjects.begin();
  2457. i != this->XCodeObjects.end(); ++i)
  2458. {
  2459. cmXCodeObject* o = *i;
  2460. if(o->GetTarget() == t)
  2461. {
  2462. return o;
  2463. }
  2464. }
  2465. return 0;
  2466. }
  2467. //----------------------------------------------------------------------------
  2468. std::string cmGlobalXCodeGenerator::GetOrCreateId(const char* name,
  2469. const char* id)
  2470. {
  2471. std::string guidStoreName = name;
  2472. guidStoreName += "_GUID_CMAKE";
  2473. const char* storedGUID =
  2474. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  2475. if(storedGUID)
  2476. {
  2477. return storedGUID;
  2478. }
  2479. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
  2480. id, "Stored Xcode object GUID", cmCacheManager::INTERNAL);
  2481. return id;
  2482. }
  2483. //----------------------------------------------------------------------------
  2484. void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
  2485. cmXCodeObject* dependTarget)
  2486. {
  2487. // This is called once for every edge in the target dependency graph.
  2488. cmXCodeObject* container =
  2489. this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
  2490. container->SetComment("PBXContainerItemProxy");
  2491. container->AddAttribute("containerPortal",
  2492. this->CreateObjectReference(this->RootObject));
  2493. container->AddAttribute("proxyType", this->CreateString("1"));
  2494. container->AddAttribute("remoteGlobalIDString",
  2495. this->CreateObjectReference(dependTarget));
  2496. container->AddAttribute("remoteInfo",
  2497. this->CreateString(
  2498. dependTarget->GetTarget()->GetName()));
  2499. cmXCodeObject* targetdep =
  2500. this->CreateObject(cmXCodeObject::PBXTargetDependency);
  2501. targetdep->SetComment("PBXTargetDependency");
  2502. targetdep->AddAttribute("target",
  2503. this->CreateObjectReference(dependTarget));
  2504. targetdep->AddAttribute("targetProxy",
  2505. this->CreateObjectReference(container));
  2506. cmXCodeObject* depends = target->GetObject("dependencies");
  2507. if(!depends)
  2508. {
  2509. cmSystemTools::
  2510. Error("target does not have dependencies attribute error..");
  2511. }
  2512. else
  2513. {
  2514. depends->AddUniqueObject(targetdep);
  2515. }
  2516. }
  2517. //----------------------------------------------------------------------------
  2518. void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings,
  2519. const char* attribute,
  2520. const char* value)
  2521. {
  2522. if(settings)
  2523. {
  2524. cmXCodeObject* attr = settings->GetObject(attribute);
  2525. if(!attr)
  2526. {
  2527. settings->AddAttribute(attribute, this->CreateString(value));
  2528. }
  2529. else
  2530. {
  2531. std::string oldValue = attr->GetString();
  2532. oldValue += " ";
  2533. oldValue += value;
  2534. attr->SetString(oldValue.c_str());
  2535. }
  2536. }
  2537. }
  2538. //----------------------------------------------------------------------------
  2539. void cmGlobalXCodeGenerator
  2540. ::AppendBuildSettingAttribute(cmXCodeObject* target,
  2541. const char* attribute,
  2542. const char* value,
  2543. const char* configName)
  2544. {
  2545. if(this->XcodeVersion < 21)
  2546. {
  2547. // There is only one configuration. Add the setting to the buildSettings
  2548. // of the target.
  2549. this->AppendOrAddBuildSetting(target->GetObject("buildSettings"),
  2550. attribute, value);
  2551. }
  2552. else
  2553. {
  2554. // There are multiple configurations. Add the setting to the
  2555. // buildSettings of the configuration name given.
  2556. cmXCodeObject* configurationList =
  2557. target->GetObject("buildConfigurationList")->GetObject();
  2558. cmXCodeObject* buildConfigs =
  2559. configurationList->GetObject("buildConfigurations");
  2560. std::vector<cmXCodeObject*> list = buildConfigs->GetObjectList();
  2561. // each configuration and the target itself has a buildSettings in it
  2562. //list.push_back(target);
  2563. for(std::vector<cmXCodeObject*>::iterator i = list.begin();
  2564. i != list.end(); ++i)
  2565. {
  2566. if(configName)
  2567. {
  2568. if(strcmp((*i)->GetObject("name")->GetString(), configName) == 0)
  2569. {
  2570. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  2571. this->AppendOrAddBuildSetting(settings, attribute, value);
  2572. }
  2573. }
  2574. else
  2575. {
  2576. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  2577. this->AppendOrAddBuildSetting(settings, attribute, value);
  2578. }
  2579. }
  2580. }
  2581. }
  2582. //----------------------------------------------------------------------------
  2583. void cmGlobalXCodeGenerator
  2584. ::AddDependAndLinkInformation(cmXCodeObject* target)
  2585. {
  2586. cmTarget* cmtarget = target->GetTarget();
  2587. if(cmtarget->GetType() == cmTarget::INTERFACE_LIBRARY)
  2588. {
  2589. return;
  2590. }
  2591. if(!cmtarget)
  2592. {
  2593. cmSystemTools::Error("Error no target on xobject\n");
  2594. return;
  2595. }
  2596. // Add dependencies on other CMake targets.
  2597. TargetDependSet const& deps = this->GetTargetDirectDepends(*cmtarget);
  2598. for(TargetDependSet::const_iterator i = deps.begin(); i != deps.end(); ++i)
  2599. {
  2600. if(cmXCodeObject* dptarget = this->FindXCodeTarget(*i))
  2601. {
  2602. this->AddDependTarget(target, dptarget);
  2603. }
  2604. }
  2605. // Loop over configuration types and set per-configuration info.
  2606. for(std::vector<std::string>::iterator i =
  2607. this->CurrentConfigurationTypes.begin();
  2608. i != this->CurrentConfigurationTypes.end(); ++i)
  2609. {
  2610. // Get the current configuration name.
  2611. const char* configName = i->c_str();
  2612. if(!*configName)
  2613. {
  2614. configName = 0;
  2615. }
  2616. if(this->XcodeVersion >= 50)
  2617. {
  2618. // Add object library contents as link flags.
  2619. std::string linkObjs;
  2620. const char* sep = "";
  2621. std::vector<std::string> objs;
  2622. this->GetGeneratorTarget(cmtarget)->UseObjectLibraries(objs);
  2623. for(std::vector<std::string>::const_iterator
  2624. oi = objs.begin(); oi != objs.end(); ++oi)
  2625. {
  2626. linkObjs += sep;
  2627. sep = " ";
  2628. linkObjs += this->XCodeEscapePath(oi->c_str());
  2629. }
  2630. this->AppendBuildSettingAttribute(target, "OTHER_LDFLAGS",
  2631. linkObjs.c_str(), configName);
  2632. }
  2633. // Skip link information for object libraries.
  2634. if(cmtarget->GetType() == cmTarget::OBJECT_LIBRARY ||
  2635. cmtarget->GetType() == cmTarget::STATIC_LIBRARY)
  2636. {
  2637. continue;
  2638. }
  2639. // Compute the link library and directory information.
  2640. cmComputeLinkInformation* pcli = cmtarget->GetLinkInformation(configName);
  2641. if(!pcli)
  2642. {
  2643. continue;
  2644. }
  2645. cmComputeLinkInformation& cli = *pcli;
  2646. // Add dependencies directly on library files.
  2647. {
  2648. std::vector<std::string> const& libDeps = cli.GetDepends();
  2649. for(std::vector<std::string>::const_iterator j = libDeps.begin();
  2650. j != libDeps.end(); ++j)
  2651. {
  2652. target->AddDependLibrary(configName, j->c_str());
  2653. }
  2654. }
  2655. // add the library search paths
  2656. {
  2657. std::vector<std::string> const& libDirs = cli.GetDirectories();
  2658. std::string linkDirs;
  2659. for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
  2660. libDir != libDirs.end(); ++libDir)
  2661. {
  2662. if(libDir->size() && *libDir != "/usr/lib")
  2663. {
  2664. if(this->XcodeVersion > 15)
  2665. {
  2666. // Now add the same one but append
  2667. // $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) to it:
  2668. linkDirs += " ";
  2669. linkDirs += this->XCodeEscapePath(
  2670. (*libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)").c_str());
  2671. }
  2672. linkDirs += " ";
  2673. linkDirs += this->XCodeEscapePath(libDir->c_str());
  2674. }
  2675. }
  2676. this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS",
  2677. linkDirs.c_str(), configName);
  2678. }
  2679. // now add the link libraries
  2680. {
  2681. std::string linkLibs;
  2682. const char* sep = "";
  2683. typedef cmComputeLinkInformation::ItemVector ItemVector;
  2684. ItemVector const& libNames = cli.GetItems();
  2685. for(ItemVector::const_iterator li = libNames.begin();
  2686. li != libNames.end(); ++li)
  2687. {
  2688. linkLibs += sep;
  2689. sep = " ";
  2690. if(li->IsPath)
  2691. {
  2692. linkLibs += this->XCodeEscapePath(li->Value.c_str());
  2693. }
  2694. else if (!li->Target
  2695. || li->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  2696. {
  2697. linkLibs += li->Value;
  2698. }
  2699. if(li->Target && !li->Target->IsImported())
  2700. {
  2701. target->AddDependTarget(configName, li->Target->GetName());
  2702. }
  2703. }
  2704. this->AppendBuildSettingAttribute(target, "OTHER_LDFLAGS",
  2705. linkLibs.c_str(), configName);
  2706. }
  2707. }
  2708. }
  2709. //----------------------------------------------------------------------------
  2710. void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
  2711. std::vector<cmLocalGenerator*>&
  2712. generators)
  2713. {
  2714. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  2715. i != generators.end(); ++i)
  2716. {
  2717. if(this->IsExcluded(root, *i))
  2718. {
  2719. continue;
  2720. }
  2721. cmMakefile* mf = (*i)->GetMakefile();
  2722. std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
  2723. cmTargets &tgts = mf->GetTargets();
  2724. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  2725. {
  2726. cmTarget& cmtarget = l->second;
  2727. // Same skipping logic here as in CreateXCodeTargets so that we do not
  2728. // end up with (empty anyhow) ALL_BUILD and XCODE_DEPEND_HELPER source
  2729. // groups:
  2730. //
  2731. if(cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
  2732. {
  2733. continue;
  2734. }
  2735. if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
  2736. {
  2737. continue;
  2738. }
  2739. // add the soon to be generated Info.plist file as a source for a
  2740. // MACOSX_BUNDLE file
  2741. if(cmtarget.GetPropertyAsBool("MACOSX_BUNDLE"))
  2742. {
  2743. std::string plist = this->ComputeInfoPListLocation(cmtarget);
  2744. cmSourceFile* sf = mf->GetOrCreateSource(plist.c_str(), true);
  2745. cmtarget.AddSourceFile(sf);
  2746. }
  2747. std::vector<cmSourceFile*> classes = cmtarget.GetSourceFiles();
  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. }