cmGlobalXCodeGenerator.cxx 131 KB

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