cmGlobalXCodeGenerator.cxx 132 KB

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