cmGlobalXCodeGenerator.cxx 132 KB

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