cmGlobalXCodeGenerator.cxx 131 KB

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