cmGlobalXCodeGenerator.cxx 132 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014
  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. bool
  888. cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
  889. std::vector<cmXCodeObject*>&
  890. targets)
  891. {
  892. this->SetCurrentLocalGenerator(gen);
  893. cmTargets &tgts = this->CurrentMakefile->GetTargets();
  894. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  895. {
  896. cmTarget& cmtarget = l->second;
  897. cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&cmtarget);
  898. // make sure ALL_BUILD, INSTALL, etc are only done once
  899. if(this->SpecialTargetEmitted(l->first.c_str()))
  900. {
  901. continue;
  902. }
  903. if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
  904. {
  905. continue;
  906. }
  907. if(cmtarget.GetType() == cmTarget::UTILITY ||
  908. cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
  909. {
  910. cmXCodeObject* t = this->CreateUtilityTarget(cmtarget);
  911. if (!t)
  912. {
  913. return false;
  914. }
  915. targets.push_back(t);
  916. continue;
  917. }
  918. // organize the sources
  919. std::vector<cmSourceFile*> classes;
  920. if (!cmtarget.GetConfigCommonSourceFiles(classes))
  921. {
  922. return false;
  923. }
  924. std::sort(classes.begin(), classes.end(), cmSourceFilePathCompare());
  925. gtgt->ComputeObjectMapping();
  926. std::vector<cmXCodeObject*> externalObjFiles;
  927. std::vector<cmXCodeObject*> headerFiles;
  928. std::vector<cmXCodeObject*> resourceFiles;
  929. std::vector<cmXCodeObject*> sourceFiles;
  930. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  931. i != classes.end(); ++i)
  932. {
  933. cmXCodeObject* xsf =
  934. this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
  935. *i, cmtarget);
  936. cmXCodeObject* fr = xsf->GetObject("fileRef");
  937. cmXCodeObject* filetype =
  938. fr->GetObject()->GetObject("explicitFileType");
  939. cmGeneratorTarget::SourceFileFlags tsFlags =
  940. gtgt->GetTargetSourceFileFlags(*i);
  941. if(filetype &&
  942. filetype->GetString() == "compiled.mach-o.objfile")
  943. {
  944. if ((*i)->GetObjectLibrary().empty())
  945. {
  946. externalObjFiles.push_back(xsf);
  947. }
  948. }
  949. else if(this->IsHeaderFile(*i) ||
  950. (tsFlags.Type == cmGeneratorTarget::SourceFileTypePrivateHeader) ||
  951. (tsFlags.Type == cmGeneratorTarget::SourceFileTypePublicHeader))
  952. {
  953. headerFiles.push_back(xsf);
  954. }
  955. else if(tsFlags.Type == cmGeneratorTarget::SourceFileTypeResource)
  956. {
  957. resourceFiles.push_back(xsf);
  958. }
  959. else if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  960. {
  961. // Include this file in the build if it has a known language
  962. // and has not been listed as an ignored extension for this
  963. // generator.
  964. if(!this->CurrentLocalGenerator->GetSourceFileLanguage(**i).empty() &&
  965. !this->IgnoreFile((*i)->GetExtension().c_str()))
  966. {
  967. sourceFiles.push_back(xsf);
  968. }
  969. }
  970. }
  971. if(this->XcodeVersion < 50)
  972. {
  973. // Add object library contents as external objects. (Equivalent to
  974. // the externalObjFiles above, except each one is not a cmSourceFile
  975. // within the target.)
  976. std::vector<std::string> objs;
  977. gtgt->UseObjectLibraries(objs, "");
  978. for(std::vector<std::string>::const_iterator
  979. oi = objs.begin(); oi != objs.end(); ++oi)
  980. {
  981. std::string obj = *oi;
  982. cmXCodeObject* xsf =
  983. this->CreateXCodeSourceFileFromPath(obj, cmtarget, "", 0);
  984. externalObjFiles.push_back(xsf);
  985. }
  986. }
  987. // some build phases only apply to bundles and/or frameworks
  988. bool isFrameworkTarget = cmtarget.IsFrameworkOnApple();
  989. bool isBundleTarget = cmtarget.GetPropertyAsBool("MACOSX_BUNDLE");
  990. bool isCFBundleTarget = cmtarget.IsCFBundleOnApple();
  991. cmXCodeObject* buildFiles = 0;
  992. // create source build phase
  993. cmXCodeObject* sourceBuildPhase = 0;
  994. if (!sourceFiles.empty())
  995. {
  996. sourceBuildPhase =
  997. this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
  998. sourceBuildPhase->SetComment("Sources");
  999. sourceBuildPhase->AddAttribute("buildActionMask",
  1000. this->CreateString("2147483647"));
  1001. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1002. for(std::vector<cmXCodeObject*>::iterator i = sourceFiles.begin();
  1003. i != sourceFiles.end(); ++i)
  1004. {
  1005. buildFiles->AddObject(*i);
  1006. }
  1007. sourceBuildPhase->AddAttribute("files", buildFiles);
  1008. sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1009. this->CreateString("0"));
  1010. }
  1011. // create header build phase - only for framework targets
  1012. cmXCodeObject* headerBuildPhase = 0;
  1013. if (!headerFiles.empty() && isFrameworkTarget)
  1014. {
  1015. headerBuildPhase =
  1016. this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase);
  1017. headerBuildPhase->SetComment("Headers");
  1018. headerBuildPhase->AddAttribute("buildActionMask",
  1019. this->CreateString("2147483647"));
  1020. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1021. for(std::vector<cmXCodeObject*>::iterator i = headerFiles.begin();
  1022. i != headerFiles.end(); ++i)
  1023. {
  1024. buildFiles->AddObject(*i);
  1025. }
  1026. headerBuildPhase->AddAttribute("files", buildFiles);
  1027. headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1028. this->CreateString("0"));
  1029. }
  1030. // create resource build phase - only for framework or bundle targets
  1031. cmXCodeObject* resourceBuildPhase = 0;
  1032. if (!resourceFiles.empty() &&
  1033. (isFrameworkTarget || isBundleTarget || isCFBundleTarget))
  1034. {
  1035. resourceBuildPhase =
  1036. this->CreateObject(cmXCodeObject::PBXResourcesBuildPhase);
  1037. resourceBuildPhase->SetComment("Resources");
  1038. resourceBuildPhase->AddAttribute("buildActionMask",
  1039. this->CreateString("2147483647"));
  1040. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1041. for(std::vector<cmXCodeObject*>::iterator i = resourceFiles.begin();
  1042. i != resourceFiles.end(); ++i)
  1043. {
  1044. buildFiles->AddObject(*i);
  1045. }
  1046. resourceBuildPhase->AddAttribute("files", buildFiles);
  1047. resourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1048. this->CreateString("0"));
  1049. }
  1050. // create vector of "non-resource content file" build phases - only for
  1051. // framework or bundle targets
  1052. std::vector<cmXCodeObject*> contentBuildPhases;
  1053. if (isFrameworkTarget || isBundleTarget || isCFBundleTarget)
  1054. {
  1055. typedef std::map<std::string, std::vector<cmSourceFile*> >
  1056. mapOfVectorOfSourceFiles;
  1057. mapOfVectorOfSourceFiles bundleFiles;
  1058. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1059. i != classes.end(); ++i)
  1060. {
  1061. cmGeneratorTarget::SourceFileFlags tsFlags =
  1062. gtgt->GetTargetSourceFileFlags(*i);
  1063. if(tsFlags.Type == cmGeneratorTarget::SourceFileTypeMacContent)
  1064. {
  1065. bundleFiles[tsFlags.MacFolder].push_back(*i);
  1066. }
  1067. }
  1068. mapOfVectorOfSourceFiles::iterator mit;
  1069. for ( mit = bundleFiles.begin(); mit != bundleFiles.end(); ++ mit )
  1070. {
  1071. cmXCodeObject* copyFilesBuildPhase =
  1072. this->CreateObject(cmXCodeObject::PBXCopyFilesBuildPhase);
  1073. copyFilesBuildPhase->SetComment("Copy files");
  1074. copyFilesBuildPhase->AddAttribute("buildActionMask",
  1075. this->CreateString("2147483647"));
  1076. copyFilesBuildPhase->AddAttribute("dstSubfolderSpec",
  1077. this->CreateString("6"));
  1078. cmOStringStream ostr;
  1079. if (cmtarget.IsFrameworkOnApple())
  1080. {
  1081. // dstPath in frameworks is relative to Versions/<version>
  1082. ostr << mit->first;
  1083. }
  1084. else if ( mit->first != "MacOS" )
  1085. {
  1086. // dstPath in bundles is relative to Contents/MacOS
  1087. ostr << "../" << mit->first.c_str();
  1088. }
  1089. copyFilesBuildPhase->AddAttribute("dstPath",
  1090. this->CreateString(ostr.str().c_str()));
  1091. copyFilesBuildPhase->AddAttribute(
  1092. "runOnlyForDeploymentPostprocessing", this->CreateString("0"));
  1093. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1094. copyFilesBuildPhase->AddAttribute("files", buildFiles);
  1095. std::vector<cmSourceFile*>::iterator sfIt;
  1096. for ( sfIt = mit->second.begin(); sfIt != mit->second.end(); ++ sfIt )
  1097. {
  1098. cmXCodeObject* xsf =
  1099. this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
  1100. *sfIt, cmtarget);
  1101. buildFiles->AddObject(xsf);
  1102. }
  1103. contentBuildPhases.push_back(copyFilesBuildPhase);
  1104. }
  1105. }
  1106. // create framework build phase
  1107. cmXCodeObject* frameworkBuildPhase = 0;
  1108. if (!externalObjFiles.empty())
  1109. {
  1110. frameworkBuildPhase =
  1111. this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
  1112. frameworkBuildPhase->SetComment("Frameworks");
  1113. frameworkBuildPhase->AddAttribute("buildActionMask",
  1114. this->CreateString("2147483647"));
  1115. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1116. frameworkBuildPhase->AddAttribute("files", buildFiles);
  1117. for(std::vector<cmXCodeObject*>::iterator i = externalObjFiles.begin();
  1118. i != externalObjFiles.end(); ++i)
  1119. {
  1120. buildFiles->AddObject(*i);
  1121. }
  1122. frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1123. this->CreateString("0"));
  1124. }
  1125. // create list of build phases and create the Xcode target
  1126. cmXCodeObject* buildPhases =
  1127. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1128. this->CreateCustomCommands(buildPhases, sourceBuildPhase,
  1129. headerBuildPhase, resourceBuildPhase,
  1130. contentBuildPhases,
  1131. frameworkBuildPhase, cmtarget);
  1132. targets.push_back(this->CreateXCodeTarget(cmtarget, buildPhases));
  1133. }
  1134. return true;
  1135. }
  1136. //----------------------------------------------------------------------------
  1137. void cmGlobalXCodeGenerator::ForceLinkerLanguages()
  1138. {
  1139. // This makes sure all targets link using the proper language.
  1140. for(TargetMap::const_iterator
  1141. ti = this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
  1142. {
  1143. this->ForceLinkerLanguage(*ti->second);
  1144. }
  1145. }
  1146. //----------------------------------------------------------------------------
  1147. void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
  1148. {
  1149. // This matters only for targets that link.
  1150. if(cmtarget.GetType() != cmTarget::EXECUTABLE &&
  1151. cmtarget.GetType() != cmTarget::SHARED_LIBRARY &&
  1152. cmtarget.GetType() != cmTarget::MODULE_LIBRARY)
  1153. {
  1154. return;
  1155. }
  1156. std::string llang = cmtarget.GetLinkerLanguage("NOCONFIG");
  1157. if(llang.empty()) { return; }
  1158. // If the language is compiled as a source trust Xcode to link with it.
  1159. cmTarget::LinkImplementation const* impl =
  1160. cmtarget.GetLinkImplementation("NOCONFIG");
  1161. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1162. li != impl->Languages.end(); ++li)
  1163. {
  1164. if(*li == llang) { return; }
  1165. }
  1166. // Add an empty source file to the target that compiles with the
  1167. // linker language. This should convince Xcode to choose the proper
  1168. // language.
  1169. cmMakefile* mf = cmtarget.GetMakefile();
  1170. std::string fname = mf->GetCurrentOutputDirectory();
  1171. fname += cmake::GetCMakeFilesDirectory();
  1172. fname += "/";
  1173. fname += cmtarget.GetName();
  1174. fname += "-CMakeForceLinker";
  1175. fname += ".";
  1176. fname += cmSystemTools::LowerCase(llang);
  1177. {
  1178. cmGeneratedFileStream fout(fname.c_str());
  1179. fout << "\n";
  1180. }
  1181. if(cmSourceFile* sf = mf->GetOrCreateSource(fname.c_str()))
  1182. {
  1183. sf->SetProperty("LANGUAGE", llang.c_str());
  1184. cmtarget.AddSource(fname);
  1185. }
  1186. }
  1187. //----------------------------------------------------------------------------
  1188. bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf)
  1189. {
  1190. const std::vector<std::string>& hdrExts =
  1191. this->CurrentMakefile->GetHeaderExtensions();
  1192. return (std::find(hdrExts.begin(), hdrExts.end(), sf->GetExtension()) !=
  1193. hdrExts.end());
  1194. }
  1195. //----------------------------------------------------------------------------
  1196. cmXCodeObject*
  1197. cmGlobalXCodeGenerator::CreateBuildPhase(const char* name,
  1198. const char* name2,
  1199. cmTarget& cmtarget,
  1200. const std::vector<cmCustomCommand>&
  1201. commands)
  1202. {
  1203. if(commands.size() == 0 && strcmp(name, "CMake ReRun") != 0)
  1204. {
  1205. return 0;
  1206. }
  1207. cmXCodeObject* buildPhase =
  1208. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  1209. buildPhase->AddAttribute("buildActionMask",
  1210. this->CreateString("2147483647"));
  1211. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1212. buildPhase->AddAttribute("files", buildFiles);
  1213. buildPhase->AddAttribute("name",
  1214. this->CreateString(name));
  1215. buildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1216. this->CreateString("0"));
  1217. buildPhase->AddAttribute("shellPath",
  1218. this->CreateString("/bin/sh"));
  1219. this->AddCommandsToBuildPhase(buildPhase, cmtarget, commands,
  1220. name2);
  1221. return buildPhase;
  1222. }
  1223. //----------------------------------------------------------------------------
  1224. void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
  1225. cmXCodeObject*
  1226. sourceBuildPhase,
  1227. cmXCodeObject*
  1228. headerBuildPhase,
  1229. cmXCodeObject*
  1230. resourceBuildPhase,
  1231. std::vector<cmXCodeObject*>
  1232. contentBuildPhases,
  1233. cmXCodeObject*
  1234. frameworkBuildPhase,
  1235. cmTarget& cmtarget)
  1236. {
  1237. std::vector<cmCustomCommand> const & prebuild
  1238. = cmtarget.GetPreBuildCommands();
  1239. std::vector<cmCustomCommand> const & prelink
  1240. = cmtarget.GetPreLinkCommands();
  1241. std::vector<cmCustomCommand> postbuild
  1242. = cmtarget.GetPostBuildCommands();
  1243. if(cmtarget.GetType() == cmTarget::SHARED_LIBRARY &&
  1244. !cmtarget.IsFrameworkOnApple())
  1245. {
  1246. cmCustomCommandLines cmd;
  1247. cmd.resize(1);
  1248. cmd[0].push_back(this->CurrentMakefile->GetDefinition("CMAKE_COMMAND"));
  1249. cmd[0].push_back("-E");
  1250. cmd[0].push_back("cmake_symlink_library");
  1251. std::string str_file = "$<TARGET_FILE:";
  1252. str_file += cmtarget.GetName();
  1253. str_file += ">";
  1254. std::string str_so_file = "$<TARGET_SONAME_FILE:";
  1255. str_so_file += cmtarget.GetName();
  1256. str_so_file += ">";
  1257. std::string str_link_file = "$<TARGET_LINKER_FILE:";
  1258. str_link_file += cmtarget.GetName();
  1259. str_link_file += ">";
  1260. cmd[0].push_back(str_file);
  1261. cmd[0].push_back(str_so_file);
  1262. cmd[0].push_back(str_link_file);
  1263. cmCustomCommand command(this->CurrentMakefile,
  1264. std::vector<std::string>(),
  1265. std::vector<std::string>(),
  1266. cmd,
  1267. "Creating symlinks",
  1268. "");
  1269. postbuild.push_back(command);
  1270. }
  1271. std::vector<cmSourceFile*> classes;
  1272. if (!cmtarget.GetConfigCommonSourceFiles(classes))
  1273. {
  1274. return;
  1275. }
  1276. // add all the sources
  1277. std::vector<cmCustomCommand> commands;
  1278. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1279. i != classes.end(); ++i)
  1280. {
  1281. if((*i)->GetCustomCommand())
  1282. {
  1283. commands.push_back(*(*i)->GetCustomCommand());
  1284. }
  1285. }
  1286. // create prebuild phase
  1287. cmXCodeObject* cmakeRulesBuildPhase =
  1288. this->CreateBuildPhase("CMake Rules",
  1289. "cmakeRulesBuildPhase",
  1290. cmtarget, commands);
  1291. // create prebuild phase
  1292. cmXCodeObject* preBuildPhase =
  1293. this->CreateBuildPhase("CMake PreBuild Rules", "preBuildCommands",
  1294. cmtarget, prebuild);
  1295. // create prelink phase
  1296. cmXCodeObject* preLinkPhase =
  1297. this->CreateBuildPhase("CMake PreLink Rules", "preLinkCommands",
  1298. cmtarget, prelink);
  1299. // create postbuild phase
  1300. cmXCodeObject* postBuildPhase =
  1301. this->CreateBuildPhase("CMake PostBuild Rules", "postBuildPhase",
  1302. cmtarget, postbuild);
  1303. // The order here is the order they will be built in.
  1304. // The order "headers, resources, sources" mimics a native project generated
  1305. // from an xcode template...
  1306. //
  1307. if(preBuildPhase)
  1308. {
  1309. buildPhases->AddObject(preBuildPhase);
  1310. }
  1311. if(cmakeRulesBuildPhase)
  1312. {
  1313. buildPhases->AddObject(cmakeRulesBuildPhase);
  1314. }
  1315. if(headerBuildPhase)
  1316. {
  1317. buildPhases->AddObject(headerBuildPhase);
  1318. }
  1319. if(resourceBuildPhase)
  1320. {
  1321. buildPhases->AddObject(resourceBuildPhase);
  1322. }
  1323. std::vector<cmXCodeObject*>::iterator cit;
  1324. for (cit = contentBuildPhases.begin(); cit != contentBuildPhases.end();
  1325. ++cit)
  1326. {
  1327. buildPhases->AddObject(*cit);
  1328. }
  1329. if(sourceBuildPhase)
  1330. {
  1331. buildPhases->AddObject(sourceBuildPhase);
  1332. }
  1333. if(preLinkPhase)
  1334. {
  1335. buildPhases->AddObject(preLinkPhase);
  1336. }
  1337. if(frameworkBuildPhase)
  1338. {
  1339. buildPhases->AddObject(frameworkBuildPhase);
  1340. }
  1341. if(postBuildPhase)
  1342. {
  1343. buildPhases->AddObject(postBuildPhase);
  1344. }
  1345. }
  1346. //----------------------------------------------------------------------------
  1347. // This function removes each occurrence of the flag and returns the last one
  1348. // (i.e., the dominant flag in GCC)
  1349. std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
  1350. std::string& flags)
  1351. {
  1352. std::string retFlag;
  1353. std::string::size_type lastOccurancePos = flags.rfind(flag);
  1354. bool saved = false;
  1355. while(lastOccurancePos != flags.npos)
  1356. {
  1357. //increment pos, we use lastOccurancePos to reduce search space on next inc
  1358. std::string::size_type pos = lastOccurancePos;
  1359. if(pos == 0 || flags[pos-1]==' ')
  1360. {
  1361. while(pos < flags.size() && flags[pos] != ' ')
  1362. {
  1363. if(!saved)
  1364. {
  1365. retFlag += flags[pos];
  1366. }
  1367. flags[pos] = ' ';
  1368. pos++;
  1369. }
  1370. saved = true;
  1371. }
  1372. //decrement lastOccurancePos while making sure we don't loop around
  1373. //and become a very large positive number since size_type is unsigned
  1374. lastOccurancePos = lastOccurancePos == 0 ? 0 : lastOccurancePos-1;
  1375. lastOccurancePos = flags.rfind(flag,lastOccurancePos);
  1376. }
  1377. return retFlag;
  1378. }
  1379. //----------------------------------------------------------------------------
  1380. void
  1381. cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  1382. cmTarget& target,
  1383. std::vector<cmCustomCommand>
  1384. const & commands,
  1385. const char* name)
  1386. {
  1387. bool haveMultipleOutputPairs = false;
  1388. std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1389. dir += "/CMakeScripts";
  1390. cmSystemTools::MakeDirectory(dir.c_str());
  1391. std::string makefile = dir;
  1392. makefile += "/";
  1393. makefile += target.GetName();
  1394. makefile += "_";
  1395. makefile += name;
  1396. makefile += ".make";
  1397. for (std::vector<std::string>::const_iterator currentConfig=
  1398. this->CurrentConfigurationTypes.begin();
  1399. currentConfig!=this->CurrentConfigurationTypes.end();
  1400. currentConfig++ )
  1401. {
  1402. this->CreateCustomRulesMakefile(makefile.c_str(),
  1403. target,
  1404. commands,
  1405. currentConfig->c_str(),
  1406. haveMultipleOutputPairs);
  1407. }
  1408. std::string cdir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1409. cdir = this->ConvertToRelativeForXCode(cdir.c_str());
  1410. std::string makecmd = "make -C ";
  1411. makecmd += cdir;
  1412. makecmd += " -f ";
  1413. makecmd += this->ConvertToRelativeForMake(
  1414. (makefile+"$CONFIGURATION").c_str());
  1415. if(haveMultipleOutputPairs)
  1416. {
  1417. makecmd += " cmake_check_multiple_outputs";
  1418. }
  1419. makecmd += " all";
  1420. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  1421. buildphase->AddAttribute("shellScript",
  1422. this->CreateString(makecmd.c_str()));
  1423. buildphase->AddAttribute("showEnvVarsInLog",
  1424. this->CreateString("0"));
  1425. }
  1426. //----------------------------------------------------------------------------
  1427. void cmGlobalXCodeGenerator
  1428. ::CreateCustomRulesMakefile(const char* makefileBasename,
  1429. cmTarget& target,
  1430. std::vector<cmCustomCommand>
  1431. const & commands,
  1432. const std::string& configName,
  1433. bool& haveMultipleOutputPairs)
  1434. {
  1435. std::string makefileName=makefileBasename;
  1436. if(this->XcodeVersion > 20)
  1437. {
  1438. makefileName+=configName;
  1439. }
  1440. cmGeneratedFileStream makefileStream(makefileName.c_str());
  1441. if(!makefileStream)
  1442. {
  1443. return;
  1444. }
  1445. makefileStream.SetCopyIfDifferent(true);
  1446. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  1447. makefileStream << "# Custom rules for " << target.GetName() << "\n";
  1448. // disable the implicit rules
  1449. makefileStream << ".SUFFIXES: " << "\n";
  1450. // have all depend on all outputs
  1451. makefileStream << "all: ";
  1452. std::map<const cmCustomCommand*, std::string> tname;
  1453. int count = 0;
  1454. std::map<std::string, std::string> multipleOutputPairs;
  1455. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1456. i != commands.end(); ++i)
  1457. {
  1458. cmCustomCommandGenerator ccg(*i, configName, this->CurrentMakefile);
  1459. if(ccg.GetNumberOfCommands() > 0)
  1460. {
  1461. const std::vector<std::string>& outputs = ccg.GetOutputs();
  1462. if(!outputs.empty())
  1463. {
  1464. for(std::vector<std::string>::const_iterator o = outputs.begin();
  1465. o != outputs.end(); ++o)
  1466. {
  1467. makefileStream
  1468. << "\\\n\t" << this->ConvertToRelativeForMake(o->c_str());
  1469. }
  1470. // If there is more than one output treat the first as the
  1471. // primary output and make the rest depend on it.
  1472. std::vector<std::string>::const_iterator o = outputs.begin();
  1473. std::string primaryOutput = this->ConvertToRelativeForMake(o->c_str());
  1474. for(++o; o != outputs.end(); ++o)
  1475. {
  1476. std::string currentOutput=this->ConvertToRelativeForMake(o->c_str());
  1477. multipleOutputPairs[currentOutput] = primaryOutput;
  1478. }
  1479. }
  1480. else
  1481. {
  1482. cmOStringStream str;
  1483. str << "_buildpart_" << count++ ;
  1484. tname[&ccg.GetCC()] = std::string(target.GetName()) + str.str();
  1485. makefileStream << "\\\n\t" << tname[&ccg.GetCC()];
  1486. }
  1487. }
  1488. }
  1489. makefileStream << "\n\n";
  1490. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1491. i != commands.end(); ++i)
  1492. {
  1493. cmCustomCommandGenerator ccg(*i, configName, this->CurrentMakefile);
  1494. if(ccg.GetNumberOfCommands() > 0)
  1495. {
  1496. makefileStream << "\n";
  1497. const std::vector<std::string>& outputs = ccg.GetOutputs();
  1498. if(!outputs.empty())
  1499. {
  1500. // There is at least one output, start the rule for it
  1501. std::string primary_output =
  1502. this->ConvertToRelativeForMake(outputs.begin()->c_str());
  1503. makefileStream << primary_output << ": ";
  1504. }
  1505. else
  1506. {
  1507. // There are no outputs. Use the generated force rule name.
  1508. makefileStream << tname[&ccg.GetCC()] << ": ";
  1509. }
  1510. for(std::vector<std::string>::const_iterator d =
  1511. ccg.GetDepends().begin();
  1512. d != ccg.GetDepends().end(); ++d)
  1513. {
  1514. std::string dep;
  1515. if(this->CurrentLocalGenerator
  1516. ->GetRealDependency(d->c_str(), configName, dep))
  1517. {
  1518. makefileStream << "\\\n" <<
  1519. this->ConvertToRelativeForMake(dep.c_str());
  1520. }
  1521. }
  1522. makefileStream << "\n";
  1523. if(const char* comment = ccg.GetComment())
  1524. {
  1525. std::string echo_cmd = "echo ";
  1526. echo_cmd += (this->CurrentLocalGenerator->
  1527. EscapeForShell(comment, ccg.GetCC().GetEscapeAllowMakeVars()));
  1528. makefileStream << "\t" << echo_cmd.c_str() << "\n";
  1529. }
  1530. // Add each command line to the set of commands.
  1531. for(unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c)
  1532. {
  1533. // Build the command line in a single string.
  1534. std::string cmd2 = ccg.GetCommand(c);
  1535. cmSystemTools::ReplaceString(cmd2, "/./", "/");
  1536. cmd2 = this->ConvertToRelativeForMake(cmd2.c_str());
  1537. std::string cmd;
  1538. std::string wd = ccg.GetWorkingDirectory();
  1539. if(!wd.empty())
  1540. {
  1541. cmd += "cd ";
  1542. cmd += this->ConvertToRelativeForMake(wd.c_str());
  1543. cmd += " && ";
  1544. }
  1545. cmd += cmd2;
  1546. ccg.AppendArguments(c, cmd);
  1547. makefileStream << "\t" << cmd.c_str() << "\n";
  1548. }
  1549. }
  1550. }
  1551. // Add rules to deal with multiple outputs of custom commands.
  1552. if(!multipleOutputPairs.empty())
  1553. {
  1554. makefileStream <<
  1555. "\n# Dependencies of multiple outputs to their primary outputs \n";
  1556. for(std::map<std::string, std::string>::const_iterator o =
  1557. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1558. {
  1559. makefileStream << o->first << ": " << o->second << "\n";
  1560. }
  1561. makefileStream <<
  1562. "\n"
  1563. "cmake_check_multiple_outputs:\n";
  1564. for(std::map<std::string, std::string>::const_iterator o =
  1565. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1566. {
  1567. makefileStream << "\t@if [ ! -f "
  1568. << o->first << " ]; then rm -f "
  1569. << o->second << "; fi\n";
  1570. }
  1571. }
  1572. haveMultipleOutputPairs =
  1573. haveMultipleOutputPairs || !multipleOutputPairs.empty();
  1574. }
  1575. //----------------------------------------------------------------------------
  1576. void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
  1577. cmXCodeObject* buildSettings,
  1578. const std::string& configName)
  1579. {
  1580. if(target.GetType() == cmTarget::INTERFACE_LIBRARY)
  1581. {
  1582. return;
  1583. }
  1584. std::string flags;
  1585. std::string defFlags;
  1586. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  1587. (target.GetType() == cmTarget::MODULE_LIBRARY));
  1588. bool binary = ((target.GetType() == cmTarget::OBJECT_LIBRARY) ||
  1589. (target.GetType() == cmTarget::STATIC_LIBRARY) ||
  1590. (target.GetType() == cmTarget::EXECUTABLE) ||
  1591. shared);
  1592. std::string lang = target.GetLinkerLanguage(configName);
  1593. std::string cflags;
  1594. if(!lang.empty())
  1595. {
  1596. // for c++ projects get the c flags as well
  1597. if(lang == "CXX")
  1598. {
  1599. this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName);
  1600. this->CurrentLocalGenerator->AddCMP0018Flags(cflags, &target,
  1601. "C", configName);
  1602. this->CurrentLocalGenerator->
  1603. AddCompileOptions(cflags, &target, "C", configName);
  1604. }
  1605. // Add language-specific flags.
  1606. this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName);
  1607. // Add shared-library flags if needed.
  1608. this->CurrentLocalGenerator->AddCMP0018Flags(flags, &target,
  1609. lang, configName);
  1610. this->CurrentLocalGenerator->AddVisibilityPresetFlags(flags, &target,
  1611. lang);
  1612. this->CurrentLocalGenerator->
  1613. AddCompileOptions(flags, &target, lang, configName);
  1614. }
  1615. else if(binary)
  1616. {
  1617. cmSystemTools::Error
  1618. ("CMake can not determine linker language for target: ",
  1619. target.GetName().c_str());
  1620. return;
  1621. }
  1622. // Add define flags
  1623. this->CurrentLocalGenerator->
  1624. AppendFlags(defFlags,
  1625. this->CurrentMakefile->GetDefineFlags());
  1626. // Add preprocessor definitions for this target and configuration.
  1627. BuildObjectListOrString ppDefs(this, this->XcodeVersion >= 30);
  1628. if(this->XcodeVersion > 15)
  1629. {
  1630. this->AppendDefines(ppDefs,
  1631. "CMAKE_INTDIR=\"$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)\"");
  1632. }
  1633. if(const char* exportMacro = target.GetExportMacro())
  1634. {
  1635. // Add the export symbol definition for shared library objects.
  1636. this->AppendDefines(ppDefs, exportMacro);
  1637. }
  1638. cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
  1639. std::vector<std::string> targetDefines;
  1640. target.GetCompileDefinitions(targetDefines, configName);
  1641. this->AppendDefines(ppDefs, targetDefines);
  1642. buildSettings->AddAttribute
  1643. ("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList());
  1644. std::string extraLinkOptionsVar;
  1645. std::string extraLinkOptions;
  1646. if(target.GetType() == cmTarget::EXECUTABLE)
  1647. {
  1648. extraLinkOptionsVar = "CMAKE_EXE_LINKER_FLAGS";
  1649. }
  1650. else if(target.GetType() == cmTarget::SHARED_LIBRARY)
  1651. {
  1652. extraLinkOptionsVar = "CMAKE_SHARED_LINKER_FLAGS";
  1653. }
  1654. else if(target.GetType() == cmTarget::MODULE_LIBRARY)
  1655. {
  1656. extraLinkOptionsVar = "CMAKE_MODULE_LINKER_FLAGS";
  1657. }
  1658. if(extraLinkOptionsVar.size())
  1659. {
  1660. this->CurrentLocalGenerator
  1661. ->AddConfigVariableFlags(extraLinkOptions,
  1662. extraLinkOptionsVar.c_str(),
  1663. configName);
  1664. }
  1665. if(target.GetType() == cmTarget::OBJECT_LIBRARY ||
  1666. target.GetType() == cmTarget::STATIC_LIBRARY)
  1667. {
  1668. this->CurrentLocalGenerator
  1669. ->GetStaticLibraryFlags(extraLinkOptions,
  1670. cmSystemTools::UpperCase(configName),
  1671. &target);
  1672. }
  1673. else
  1674. {
  1675. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1676. if(targetLinkFlags)
  1677. {
  1678. this->CurrentLocalGenerator->
  1679. AppendFlags(extraLinkOptions, targetLinkFlags);
  1680. }
  1681. if(!configName.empty())
  1682. {
  1683. std::string linkFlagsVar = "LINK_FLAGS_";
  1684. linkFlagsVar += cmSystemTools::UpperCase(configName);
  1685. if(const char* linkFlags = target.GetProperty(linkFlagsVar.c_str()))
  1686. {
  1687. this->CurrentLocalGenerator->
  1688. AppendFlags(extraLinkOptions, linkFlags);
  1689. }
  1690. }
  1691. }
  1692. // Set target-specific architectures.
  1693. std::vector<std::string> archs;
  1694. gtgt->GetAppleArchs(configName, archs);
  1695. if(!archs.empty())
  1696. {
  1697. // Enable ARCHS attribute.
  1698. buildSettings->AddAttribute("ONLY_ACTIVE_ARCH",
  1699. this->CreateString("NO"));
  1700. // Store ARCHS value.
  1701. if(archs.size() == 1)
  1702. {
  1703. buildSettings->AddAttribute("ARCHS",
  1704. this->CreateString(archs[0].c_str()));
  1705. }
  1706. else
  1707. {
  1708. cmXCodeObject* archObjects =
  1709. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1710. for(std::vector<std::string>::iterator i = archs.begin();
  1711. i != archs.end(); i++)
  1712. {
  1713. archObjects->AddObject(this->CreateString((*i).c_str()));
  1714. }
  1715. buildSettings->AddAttribute("ARCHS", archObjects);
  1716. }
  1717. }
  1718. // Get the product name components.
  1719. std::string pnprefix;
  1720. std::string pnbase;
  1721. std::string pnsuffix;
  1722. target.GetFullNameComponents(pnprefix, pnbase, pnsuffix, configName);
  1723. const char* version = target.GetProperty("VERSION");
  1724. const char* soversion = target.GetProperty("SOVERSION");
  1725. if(!target.HasSOName(configName) || target.IsFrameworkOnApple())
  1726. {
  1727. version = 0;
  1728. soversion = 0;
  1729. }
  1730. if(version && !soversion)
  1731. {
  1732. soversion = version;
  1733. }
  1734. if(!version && soversion)
  1735. {
  1736. version = soversion;
  1737. }
  1738. std::string realName = pnbase;
  1739. std::string soName = pnbase;
  1740. if(version && soversion)
  1741. {
  1742. realName += ".";
  1743. realName += version;
  1744. soName += ".";
  1745. soName += soversion;
  1746. }
  1747. // Set attributes to specify the proper name for the target.
  1748. std::string pndir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1749. if(target.GetType() == cmTarget::STATIC_LIBRARY ||
  1750. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1751. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1752. target.GetType() == cmTarget::EXECUTABLE)
  1753. {
  1754. if(this->XcodeVersion >= 21)
  1755. {
  1756. if(!target.UsesDefaultOutputDir(configName, false))
  1757. {
  1758. std::string pncdir = target.GetDirectory(configName);
  1759. buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR",
  1760. this->CreateString(pncdir.c_str()));
  1761. }
  1762. }
  1763. else
  1764. {
  1765. buildSettings->AddAttribute("OBJROOT",
  1766. this->CreateString(pndir.c_str()));
  1767. pndir = target.GetDirectory(configName);
  1768. }
  1769. if(target.IsFrameworkOnApple() || target.IsCFBundleOnApple())
  1770. {
  1771. pnprefix = "";
  1772. }
  1773. buildSettings->AddAttribute("EXECUTABLE_PREFIX",
  1774. this->CreateString(pnprefix.c_str()));
  1775. buildSettings->AddAttribute("EXECUTABLE_SUFFIX",
  1776. this->CreateString(pnsuffix.c_str()));
  1777. }
  1778. else if(target.GetType() == cmTarget::OBJECT_LIBRARY)
  1779. {
  1780. pnprefix = "lib";
  1781. pnbase = target.GetName();
  1782. pnsuffix = ".a";
  1783. if(this->XcodeVersion >= 21)
  1784. {
  1785. std::string pncdir = this->GetObjectsNormalDirectory(
  1786. this->CurrentProject, configName, &target);
  1787. buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR",
  1788. this->CreateString(pncdir.c_str()));
  1789. }
  1790. else
  1791. {
  1792. buildSettings->AddAttribute("OBJROOT",
  1793. this->CreateString(pndir.c_str()));
  1794. pndir = this->GetObjectsNormalDirectory(
  1795. this->CurrentProject, configName, &target);
  1796. }
  1797. }
  1798. // Store the product name for all target types.
  1799. buildSettings->AddAttribute("PRODUCT_NAME",
  1800. this->CreateString(realName.c_str()));
  1801. buildSettings->AddAttribute("SYMROOT",
  1802. this->CreateString(pndir.c_str()));
  1803. // Handle settings for each target type.
  1804. switch(target.GetType())
  1805. {
  1806. case cmTarget::OBJECT_LIBRARY:
  1807. case cmTarget::STATIC_LIBRARY:
  1808. {
  1809. buildSettings->AddAttribute("LIBRARY_STYLE",
  1810. this->CreateString("STATIC"));
  1811. break;
  1812. }
  1813. case cmTarget::MODULE_LIBRARY:
  1814. {
  1815. buildSettings->AddAttribute("LIBRARY_STYLE",
  1816. this->CreateString("BUNDLE"));
  1817. if (target.GetPropertyAsBool("BUNDLE"))
  1818. {
  1819. // It turns out that a BUNDLE is basically the same
  1820. // in many ways as an application bundle, as far as
  1821. // link flags go
  1822. std::string createFlags =
  1823. this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
  1824. "-bundle");
  1825. if(!createFlags.empty())
  1826. {
  1827. extraLinkOptions += " ";
  1828. extraLinkOptions += createFlags;
  1829. }
  1830. std::string plist = this->ComputeInfoPListLocation(target);
  1831. // Xcode will create the final version of Info.plist at build time,
  1832. // so let it replace the cfbundle name. This avoids creating
  1833. // a per-configuration Info.plist file. The cfbundle plist
  1834. // is very similar to the application bundle plist
  1835. this->CurrentLocalGenerator
  1836. ->GenerateAppleInfoPList(&target, "$(EXECUTABLE_NAME)",
  1837. plist.c_str());
  1838. std::string path =
  1839. this->ConvertToRelativeForXCode(plist.c_str());
  1840. buildSettings->AddAttribute("INFOPLIST_FILE",
  1841. this->CreateString(path.c_str()));
  1842. }
  1843. else if(this->XcodeVersion >= 22)
  1844. {
  1845. buildSettings->AddAttribute("MACH_O_TYPE",
  1846. this->CreateString("mh_bundle"));
  1847. buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
  1848. this->CreateString("NO"));
  1849. // Add the flags to create an executable.
  1850. std::string createFlags =
  1851. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1852. if(!createFlags.empty())
  1853. {
  1854. extraLinkOptions += " ";
  1855. extraLinkOptions += createFlags;
  1856. }
  1857. }
  1858. else
  1859. {
  1860. // Add the flags to create a module.
  1861. std::string createFlags =
  1862. this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
  1863. "-bundle");
  1864. if(!createFlags.empty())
  1865. {
  1866. extraLinkOptions += " ";
  1867. extraLinkOptions += createFlags;
  1868. }
  1869. }
  1870. break;
  1871. }
  1872. case cmTarget::SHARED_LIBRARY:
  1873. {
  1874. if(target.GetPropertyAsBool("FRAMEWORK"))
  1875. {
  1876. std::string fw_version = target.GetFrameworkVersion();
  1877. buildSettings->AddAttribute("FRAMEWORK_VERSION",
  1878. this->CreateString(fw_version.c_str()));
  1879. std::string plist = this->ComputeInfoPListLocation(target);
  1880. // Xcode will create the final version of Info.plist at build time,
  1881. // so let it replace the framework name. This avoids creating
  1882. // a per-configuration Info.plist file.
  1883. this->CurrentLocalGenerator
  1884. ->GenerateFrameworkInfoPList(&target, "$(EXECUTABLE_NAME)",
  1885. plist.c_str());
  1886. std::string path =
  1887. this->ConvertToRelativeForXCode(plist.c_str());
  1888. buildSettings->AddAttribute("INFOPLIST_FILE",
  1889. this->CreateString(path.c_str()));
  1890. }
  1891. else
  1892. {
  1893. // Add the flags to create a shared library.
  1894. std::string createFlags =
  1895. this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", lang, "_FLAGS",
  1896. "-dynamiclib");
  1897. if(!createFlags.empty())
  1898. {
  1899. extraLinkOptions += " ";
  1900. extraLinkOptions += createFlags;
  1901. }
  1902. }
  1903. buildSettings->AddAttribute("LIBRARY_STYLE",
  1904. this->CreateString("DYNAMIC"));
  1905. break;
  1906. }
  1907. case cmTarget::EXECUTABLE:
  1908. {
  1909. // Add the flags to create an executable.
  1910. std::string createFlags =
  1911. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1912. if(!createFlags.empty())
  1913. {
  1914. extraLinkOptions += " ";
  1915. extraLinkOptions += createFlags;
  1916. }
  1917. // Handle bundles and normal executables separately.
  1918. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  1919. {
  1920. std::string plist = this->ComputeInfoPListLocation(target);
  1921. // Xcode will create the final version of Info.plist at build time,
  1922. // so let it replace the executable name. This avoids creating
  1923. // a per-configuration Info.plist file.
  1924. this->CurrentLocalGenerator
  1925. ->GenerateAppleInfoPList(&target, "$(EXECUTABLE_NAME)",
  1926. plist.c_str());
  1927. std::string path =
  1928. this->ConvertToRelativeForXCode(plist.c_str());
  1929. buildSettings->AddAttribute("INFOPLIST_FILE",
  1930. this->CreateString(path.c_str()));
  1931. }
  1932. }
  1933. break;
  1934. default:
  1935. break;
  1936. }
  1937. if(this->XcodeVersion >= 22 && this->XcodeVersion < 40)
  1938. {
  1939. buildSettings->AddAttribute("PREBINDING",
  1940. this->CreateString("NO"));
  1941. }
  1942. BuildObjectListOrString dirs(this, this->XcodeVersion >= 30);
  1943. BuildObjectListOrString fdirs(this, this->XcodeVersion >= 30);
  1944. std::vector<std::string> includes;
  1945. this->CurrentLocalGenerator->GetIncludeDirectories(includes, gtgt,
  1946. "C", configName);
  1947. std::set<std::string> emitted;
  1948. emitted.insert("/System/Library/Frameworks");
  1949. for(std::vector<std::string>::iterator i = includes.begin();
  1950. i != includes.end(); ++i)
  1951. {
  1952. if(this->NameResolvesToFramework(i->c_str()))
  1953. {
  1954. std::string frameworkDir = *i;
  1955. frameworkDir += "/../";
  1956. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1957. if(emitted.insert(frameworkDir).second)
  1958. {
  1959. fdirs.Add(this->XCodeEscapePath(frameworkDir.c_str()).c_str());
  1960. }
  1961. }
  1962. else
  1963. {
  1964. std::string incpath =
  1965. this->XCodeEscapePath(i->c_str());
  1966. dirs.Add(incpath.c_str());
  1967. }
  1968. }
  1969. // Add framework search paths needed for linking.
  1970. if(cmComputeLinkInformation* cli = target.GetLinkInformation(configName))
  1971. {
  1972. std::vector<std::string> const& fwDirs = cli->GetFrameworkPaths();
  1973. for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1974. fdi != fwDirs.end(); ++fdi)
  1975. {
  1976. if(emitted.insert(*fdi).second)
  1977. {
  1978. fdirs.Add(this->XCodeEscapePath(fdi->c_str()).c_str());
  1979. }
  1980. }
  1981. }
  1982. if(!fdirs.IsEmpty())
  1983. {
  1984. buildSettings->AddAttribute("FRAMEWORK_SEARCH_PATHS",
  1985. fdirs.CreateList());
  1986. }
  1987. if(!dirs.IsEmpty())
  1988. {
  1989. buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
  1990. dirs.CreateList());
  1991. }
  1992. std::string oflagc = this->ExtractFlag("-O", cflags);
  1993. char optLevel[2];
  1994. optLevel[0] = '0';
  1995. optLevel[1] = 0;
  1996. if(oflagc.size() == 3)
  1997. {
  1998. optLevel[0] = oflagc[2];
  1999. }
  2000. if(oflagc.size() == 2)
  2001. {
  2002. optLevel[0] = '1';
  2003. }
  2004. std::string oflag = this->ExtractFlag("-O", flags);
  2005. if(oflag.size() == 3)
  2006. {
  2007. optLevel[0] = oflag[2];
  2008. }
  2009. if(oflag.size() == 2)
  2010. {
  2011. optLevel[0] = '1';
  2012. }
  2013. std::string gflagc = this->ExtractFlag("-g", cflags);
  2014. // put back gdwarf-2 if used since there is no way
  2015. // to represent it in the gui, but we still want debug yes
  2016. if(gflagc == "-gdwarf-2")
  2017. {
  2018. cflags += " ";
  2019. cflags += gflagc;
  2020. }
  2021. std::string gflag = this->ExtractFlag("-g", flags);
  2022. if(gflag == "-gdwarf-2")
  2023. {
  2024. flags += " ";
  2025. flags += gflag;
  2026. }
  2027. const char* debugStr = "YES";
  2028. // We can't set the Xcode flag differently depending on the language,
  2029. // so put them back in this case.
  2030. if( (lang == "CXX") && gflag != gflagc )
  2031. {
  2032. cflags += " ";
  2033. cflags += gflagc;
  2034. flags += " ";
  2035. flags += gflag;
  2036. debugStr = "NO";
  2037. }
  2038. if( gflag == "-g0" || gflag.size() == 0 )
  2039. {
  2040. debugStr = "NO";
  2041. }
  2042. buildSettings->AddAttribute("COMBINE_HIDPI_IMAGES",
  2043. this->CreateString("YES"));
  2044. buildSettings->AddAttribute("GCC_GENERATE_DEBUGGING_SYMBOLS",
  2045. this->CreateString(debugStr));
  2046. buildSettings->AddAttribute("GCC_OPTIMIZATION_LEVEL",
  2047. this->CreateString(optLevel));
  2048. buildSettings->AddAttribute("GCC_SYMBOLS_PRIVATE_EXTERN",
  2049. this->CreateString("NO"));
  2050. buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
  2051. this->CreateString("NO"));
  2052. if(lang == "CXX")
  2053. {
  2054. flags += " ";
  2055. flags += defFlags;
  2056. buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
  2057. this->CreateString(flags.c_str()));
  2058. cflags += " ";
  2059. cflags += defFlags;
  2060. buildSettings->AddAttribute("OTHER_CFLAGS",
  2061. this->CreateString(cflags.c_str()));
  2062. }
  2063. else
  2064. {
  2065. flags += " ";
  2066. flags += defFlags;
  2067. buildSettings->AddAttribute("OTHER_CFLAGS",
  2068. this->CreateString(flags.c_str()));
  2069. }
  2070. // Add Fortran source format attribute if property is set.
  2071. const char* format = 0;
  2072. const char* tgtfmt = target.GetProperty("Fortran_FORMAT");
  2073. switch(this->CurrentLocalGenerator->GetFortranFormat(tgtfmt))
  2074. {
  2075. case cmLocalGenerator::FortranFormatFixed: format = "fixed"; break;
  2076. case cmLocalGenerator::FortranFormatFree: format = "free"; break;
  2077. default: break;
  2078. }
  2079. if(format)
  2080. {
  2081. buildSettings->AddAttribute("IFORT_LANG_SRCFMT",
  2082. this->CreateString(format));
  2083. }
  2084. // Create the INSTALL_PATH attribute.
  2085. std::string install_name_dir;
  2086. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  2087. {
  2088. // Get the install_name directory for the build tree.
  2089. install_name_dir = target.GetInstallNameDirForBuildTree(configName);
  2090. // Xcode doesn't create the correct install_name in some cases.
  2091. // That is, if the INSTALL_PATH is empty, or if we have versioning
  2092. // of dylib libraries, we want to specify the install_name.
  2093. // This is done by adding a link flag to create an install_name
  2094. // with just the library soname.
  2095. std::string install_name;
  2096. if(!install_name_dir.empty())
  2097. {
  2098. // Convert to a path for the native build tool.
  2099. cmSystemTools::ConvertToUnixSlashes(install_name_dir);
  2100. install_name += install_name_dir;
  2101. install_name += "/";
  2102. }
  2103. install_name += target.GetSOName(configName);
  2104. if((realName != soName) || install_name_dir.empty())
  2105. {
  2106. install_name_dir = "";
  2107. extraLinkOptions += " -install_name ";
  2108. extraLinkOptions += XCodeEscapePath(install_name.c_str());
  2109. }
  2110. }
  2111. buildSettings->AddAttribute("INSTALL_PATH",
  2112. this->CreateString(install_name_dir.c_str()));
  2113. // Create the LD_RUNPATH_SEARCH_PATHS
  2114. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  2115. if(pcli)
  2116. {
  2117. std::string search_paths;
  2118. std::vector<std::string> runtimeDirs;
  2119. pcli->GetRPath(runtimeDirs, false);
  2120. // runpath dirs needs to be unique to prevent corruption
  2121. std::set<std::string> unique_dirs;
  2122. for(std::vector<std::string>::const_iterator i = runtimeDirs.begin();
  2123. i != runtimeDirs.end(); ++i)
  2124. {
  2125. std::string runpath = *i;
  2126. runpath = this->ExpandCFGIntDir(runpath, configName);
  2127. if(unique_dirs.find(runpath) == unique_dirs.end())
  2128. {
  2129. unique_dirs.insert(runpath);
  2130. if(!search_paths.empty())
  2131. {
  2132. search_paths += " ";
  2133. }
  2134. search_paths += this->XCodeEscapePath(runpath.c_str());
  2135. }
  2136. }
  2137. if(!search_paths.empty())
  2138. {
  2139. buildSettings->AddAttribute("LD_RUNPATH_SEARCH_PATHS",
  2140. this->CreateString(search_paths.c_str()));
  2141. }
  2142. }
  2143. buildSettings->AddAttribute(this->GetTargetLinkFlagsVar(target),
  2144. this->CreateString(extraLinkOptions.c_str()));
  2145. buildSettings->AddAttribute("OTHER_REZFLAGS",
  2146. this->CreateString(""));
  2147. buildSettings->AddAttribute("SECTORDER_FLAGS",
  2148. this->CreateString(""));
  2149. buildSettings->AddAttribute("USE_HEADERMAP",
  2150. this->CreateString("NO"));
  2151. if (this->XcodeVersion >= 30)
  2152. {
  2153. cmXCodeObject *group = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2154. group->AddObject(this->CreateString("-Wmost"));
  2155. group->AddObject(this->CreateString("-Wno-four-char-constants"));
  2156. group->AddObject(this->CreateString("-Wno-unknown-pragmas"));
  2157. buildSettings->AddAttribute("WARNING_CFLAGS", group);
  2158. }
  2159. else
  2160. {
  2161. buildSettings->AddAttribute("WARNING_CFLAGS",
  2162. this->CreateString(
  2163. "-Wmost -Wno-four-char-constants"
  2164. " -Wno-unknown-pragmas"));
  2165. }
  2166. // Runtime version information.
  2167. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  2168. {
  2169. int major;
  2170. int minor;
  2171. int patch;
  2172. // VERSION -> current_version
  2173. target.GetTargetVersion(false, major, minor, patch);
  2174. cmOStringStream v;
  2175. // Xcode always wants at least 1.0.0 or nothing
  2176. if(!(major == 0 && minor == 0 && patch == 0))
  2177. {
  2178. v << major << "." << minor << "." << patch;
  2179. }
  2180. buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
  2181. this->CreateString(v.str().c_str()));
  2182. // SOVERSION -> compatibility_version
  2183. target.GetTargetVersion(true, major, minor, patch);
  2184. cmOStringStream vso;
  2185. // Xcode always wants at least 1.0.0 or nothing
  2186. if(!(major == 0 && minor == 0 && patch == 0))
  2187. {
  2188. vso << major << "." << minor << "." << patch;
  2189. }
  2190. buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
  2191. this->CreateString(vso.str().c_str()));
  2192. }
  2193. // put this last so it can override existing settings
  2194. // Convert "XCODE_ATTRIBUTE_*" properties directly.
  2195. {
  2196. cmPropertyMap const& props = target.GetProperties();
  2197. for(cmPropertyMap::const_iterator i = props.begin();
  2198. i != props.end(); ++i)
  2199. {
  2200. if(i->first.find("XCODE_ATTRIBUTE_") == 0)
  2201. {
  2202. std::string attribute = i->first.substr(16);
  2203. // Handle [variant=<config>] condition explicitly here.
  2204. std::string::size_type beginVariant =
  2205. attribute.find("[variant=");
  2206. if (beginVariant != std::string::npos)
  2207. {
  2208. std::string::size_type endVariant =
  2209. attribute.find("]", beginVariant+9);
  2210. if (endVariant != std::string::npos)
  2211. {
  2212. // Compare the variant to the configuration.
  2213. std::string variant =
  2214. attribute.substr(beginVariant+9, endVariant-beginVariant-9);
  2215. if (variant == configName)
  2216. {
  2217. // The variant matches the configuration so use this
  2218. // attribute but drop the [variant=<config>] condition.
  2219. attribute.erase(beginVariant, endVariant-beginVariant+1);
  2220. }
  2221. else
  2222. {
  2223. // The variant does not match the configuration so
  2224. // do not use this attribute.
  2225. attribute.clear();
  2226. }
  2227. }
  2228. }
  2229. if (!attribute.empty())
  2230. {
  2231. buildSettings->AddAttribute(attribute.c_str(),
  2232. this->CreateString(i->second.GetValue()));
  2233. }
  2234. }
  2235. }
  2236. }
  2237. }
  2238. //----------------------------------------------------------------------------
  2239. cmXCodeObject*
  2240. cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
  2241. {
  2242. cmXCodeObject* shellBuildPhase =
  2243. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  2244. shellBuildPhase->AddAttribute("buildActionMask",
  2245. this->CreateString("2147483647"));
  2246. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2247. shellBuildPhase->AddAttribute("files", buildFiles);
  2248. cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2249. shellBuildPhase->AddAttribute("inputPaths", inputPaths);
  2250. cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2251. shellBuildPhase->AddAttribute("outputPaths", outputPaths);
  2252. shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  2253. this->CreateString("0"));
  2254. shellBuildPhase->AddAttribute("shellPath",
  2255. this->CreateString("/bin/sh"));
  2256. shellBuildPhase->AddAttribute("shellScript",
  2257. this->CreateString(
  2258. "# shell script goes here\nexit 0"));
  2259. shellBuildPhase->AddAttribute("showEnvVarsInLog",
  2260. this->CreateString("0"));
  2261. cmXCodeObject* target =
  2262. this->CreateObject(cmXCodeObject::PBXAggregateTarget);
  2263. target->SetComment(cmtarget.GetName().c_str());
  2264. cmXCodeObject* buildPhases =
  2265. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2266. std::vector<cmXCodeObject*> emptyContentVector;
  2267. this->CreateCustomCommands(buildPhases, 0, 0, 0, emptyContentVector, 0,
  2268. cmtarget);
  2269. target->AddAttribute("buildPhases", buildPhases);
  2270. if(this->XcodeVersion > 20)
  2271. {
  2272. this->AddConfigurations(target, cmtarget);
  2273. }
  2274. else
  2275. {
  2276. std::string theConfig =
  2277. this->CurrentMakefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  2278. cmXCodeObject* buildSettings =
  2279. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2280. this->CreateBuildSettings(cmtarget, buildSettings, theConfig);
  2281. target->AddAttribute("buildSettings", buildSettings);
  2282. }
  2283. cmXCodeObject* dependencies =
  2284. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2285. target->AddAttribute("dependencies", dependencies);
  2286. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  2287. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  2288. target->SetTarget(&cmtarget);
  2289. // Add source files without build rules for editing convenience.
  2290. if(cmtarget.GetType() == cmTarget::UTILITY)
  2291. {
  2292. std::vector<cmSourceFile*> sources;
  2293. if (!cmtarget.GetConfigCommonSourceFiles(sources))
  2294. {
  2295. return 0;
  2296. }
  2297. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  2298. i != sources.end(); ++i)
  2299. {
  2300. if(!(*i)->GetPropertyAsBool("GENERATED"))
  2301. {
  2302. this->CreateXCodeFileReference(*i, cmtarget);
  2303. }
  2304. }
  2305. }
  2306. target->SetId(this->GetOrCreateId(
  2307. cmtarget.GetName(), target->GetId()).c_str());
  2308. return target;
  2309. }
  2310. //----------------------------------------------------------------------------
  2311. std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
  2312. cmTarget& cmtarget)
  2313. {
  2314. std::string configTypes =
  2315. this->CurrentMakefile->GetRequiredDefinition("CMAKE_CONFIGURATION_TYPES");
  2316. std::vector<std::string> configVectorIn;
  2317. std::vector<std::string> configVector;
  2318. configVectorIn.push_back(configTypes);
  2319. cmSystemTools::ExpandList(configVectorIn, configVector);
  2320. cmXCodeObject* configlist =
  2321. this->CreateObject(cmXCodeObject::XCConfigurationList);
  2322. cmXCodeObject* buildConfigurations =
  2323. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2324. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  2325. std::string comment = "Build configuration list for ";
  2326. comment += cmXCodeObject::PBXTypeNames[target->GetIsA()];
  2327. comment += " \"";
  2328. comment += cmtarget.GetName();
  2329. comment += "\"";
  2330. configlist->SetComment(comment.c_str());
  2331. target->AddAttribute("buildConfigurationList",
  2332. this->CreateObjectReference(configlist));
  2333. for(unsigned int i = 0; i < configVector.size(); ++i)
  2334. {
  2335. cmXCodeObject* config =
  2336. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  2337. buildConfigurations->AddObject(config);
  2338. cmXCodeObject* buildSettings =
  2339. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2340. this->CreateBuildSettings(cmtarget, buildSettings,
  2341. configVector[i].c_str());
  2342. config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
  2343. config->SetComment(configVector[i].c_str());
  2344. config->AddAttribute("buildSettings", buildSettings);
  2345. }
  2346. if(configVector.size())
  2347. {
  2348. configlist->AddAttribute("defaultConfigurationName",
  2349. this->CreateString(configVector[0].c_str()));
  2350. configlist->AddAttribute("defaultConfigurationIsVisible",
  2351. this->CreateString("0"));
  2352. return configVector[0];
  2353. }
  2354. return "";
  2355. }
  2356. //----------------------------------------------------------------------------
  2357. const char*
  2358. cmGlobalXCodeGenerator::GetTargetLinkFlagsVar(cmTarget const& cmtarget) const
  2359. {
  2360. if(this->XcodeVersion >= 60 &&
  2361. (cmtarget.GetType() == cmTarget::STATIC_LIBRARY ||
  2362. cmtarget.GetType() == cmTarget::OBJECT_LIBRARY))
  2363. {
  2364. return "OTHER_LIBTOOLFLAGS";
  2365. }
  2366. else
  2367. {
  2368. return "OTHER_LDFLAGS";
  2369. }
  2370. }
  2371. //----------------------------------------------------------------------------
  2372. const char* cmGlobalXCodeGenerator::GetTargetFileType(cmTarget& cmtarget)
  2373. {
  2374. switch(cmtarget.GetType())
  2375. {
  2376. case cmTarget::OBJECT_LIBRARY:
  2377. case cmTarget::STATIC_LIBRARY:
  2378. return "archive.ar";
  2379. case cmTarget::MODULE_LIBRARY:
  2380. if (cmtarget.IsCFBundleOnApple())
  2381. return "wrapper.plug-in";
  2382. else
  2383. return ((this->XcodeVersion >= 22)?
  2384. "compiled.mach-o.executable" : "compiled.mach-o.dylib");
  2385. case cmTarget::SHARED_LIBRARY:
  2386. return (cmtarget.GetPropertyAsBool("FRAMEWORK")?
  2387. "wrapper.framework" : "compiled.mach-o.dylib");
  2388. case cmTarget::EXECUTABLE:
  2389. return "compiled.mach-o.executable";
  2390. default: break;
  2391. }
  2392. return 0;
  2393. }
  2394. //----------------------------------------------------------------------------
  2395. const char* cmGlobalXCodeGenerator::GetTargetProductType(cmTarget& cmtarget)
  2396. {
  2397. switch(cmtarget.GetType())
  2398. {
  2399. case cmTarget::OBJECT_LIBRARY:
  2400. case cmTarget::STATIC_LIBRARY:
  2401. return "com.apple.product-type.library.static";
  2402. case cmTarget::MODULE_LIBRARY:
  2403. if (cmtarget.IsCFBundleOnApple())
  2404. return "com.apple.product-type.bundle";
  2405. else
  2406. return ((this->XcodeVersion >= 22)?
  2407. "com.apple.product-type.tool" :
  2408. "com.apple.product-type.library.dynamic");
  2409. case cmTarget::SHARED_LIBRARY:
  2410. return (cmtarget.GetPropertyAsBool("FRAMEWORK")?
  2411. "com.apple.product-type.framework" :
  2412. "com.apple.product-type.library.dynamic");
  2413. case cmTarget::EXECUTABLE:
  2414. return (cmtarget.GetPropertyAsBool("MACOSX_BUNDLE")?
  2415. "com.apple.product-type.application" :
  2416. "com.apple.product-type.tool");
  2417. default: break;
  2418. }
  2419. return 0;
  2420. }
  2421. //----------------------------------------------------------------------------
  2422. cmXCodeObject*
  2423. cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
  2424. cmXCodeObject* buildPhases)
  2425. {
  2426. if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
  2427. {
  2428. return 0;
  2429. }
  2430. cmXCodeObject* target =
  2431. this->CreateObject(cmXCodeObject::PBXNativeTarget);
  2432. target->AddAttribute("buildPhases", buildPhases);
  2433. cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2434. target->AddAttribute("buildRules", buildRules);
  2435. std::string defConfig;
  2436. if(this->XcodeVersion > 20)
  2437. {
  2438. defConfig = this->AddConfigurations(target, cmtarget);
  2439. }
  2440. else
  2441. {
  2442. cmXCodeObject* buildSettings =
  2443. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2444. defConfig = this->CurrentMakefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  2445. this->CreateBuildSettings(cmtarget, buildSettings, defConfig.c_str());
  2446. target->AddAttribute("buildSettings", buildSettings);
  2447. }
  2448. cmXCodeObject* dependencies =
  2449. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2450. target->AddAttribute("dependencies", dependencies);
  2451. target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  2452. target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
  2453. cmXCodeObject* fileRef =
  2454. this->CreateObject(cmXCodeObject::PBXFileReference);
  2455. if(const char* fileType = this->GetTargetFileType(cmtarget))
  2456. {
  2457. fileRef->AddAttribute("explicitFileType", this->CreateString(fileType));
  2458. }
  2459. std::string fullName;
  2460. if(cmtarget.GetType() == cmTarget::OBJECT_LIBRARY)
  2461. {
  2462. fullName = "lib";
  2463. fullName += cmtarget.GetName();
  2464. fullName += ".a";
  2465. }
  2466. else
  2467. {
  2468. fullName = cmtarget.GetFullName(defConfig.c_str());
  2469. }
  2470. fileRef->AddAttribute("path", this->CreateString(fullName.c_str()));
  2471. fileRef->AddAttribute("refType", this->CreateString("0"));
  2472. fileRef->AddAttribute("sourceTree",
  2473. this->CreateString("BUILT_PRODUCTS_DIR"));
  2474. fileRef->SetComment(cmtarget.GetName().c_str());
  2475. target->AddAttribute("productReference",
  2476. this->CreateObjectReference(fileRef));
  2477. if(const char* productType = this->GetTargetProductType(cmtarget))
  2478. {
  2479. target->AddAttribute("productType", this->CreateString(productType));
  2480. }
  2481. target->SetTarget(&cmtarget);
  2482. target->SetId(this->GetOrCreateId(
  2483. cmtarget.GetName(), target->GetId()).c_str());
  2484. return target;
  2485. }
  2486. //----------------------------------------------------------------------------
  2487. cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget const* t)
  2488. {
  2489. if(!t)
  2490. {
  2491. return 0;
  2492. }
  2493. for(std::vector<cmXCodeObject*>::iterator i = this->XCodeObjects.begin();
  2494. i != this->XCodeObjects.end(); ++i)
  2495. {
  2496. cmXCodeObject* o = *i;
  2497. if(o->GetTarget() == t)
  2498. {
  2499. return o;
  2500. }
  2501. }
  2502. return 0;
  2503. }
  2504. //----------------------------------------------------------------------------
  2505. std::string cmGlobalXCodeGenerator::GetOrCreateId(const std::string& name,
  2506. const std::string& id)
  2507. {
  2508. std::string guidStoreName = name;
  2509. guidStoreName += "_GUID_CMAKE";
  2510. const char* storedGUID =
  2511. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  2512. if(storedGUID)
  2513. {
  2514. return storedGUID;
  2515. }
  2516. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
  2517. id.c_str(), "Stored Xcode object GUID", cmCacheManager::INTERNAL);
  2518. return id;
  2519. }
  2520. //----------------------------------------------------------------------------
  2521. void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
  2522. cmXCodeObject* dependTarget)
  2523. {
  2524. // This is called once for every edge in the target dependency graph.
  2525. cmXCodeObject* container =
  2526. this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
  2527. container->SetComment("PBXContainerItemProxy");
  2528. container->AddAttribute("containerPortal",
  2529. this->CreateObjectReference(this->RootObject));
  2530. container->AddAttribute("proxyType", this->CreateString("1"));
  2531. container->AddAttribute("remoteGlobalIDString",
  2532. this->CreateObjectReference(dependTarget));
  2533. container->AddAttribute("remoteInfo",
  2534. this->CreateString(
  2535. dependTarget->GetTarget()->GetName()));
  2536. cmXCodeObject* targetdep =
  2537. this->CreateObject(cmXCodeObject::PBXTargetDependency);
  2538. targetdep->SetComment("PBXTargetDependency");
  2539. targetdep->AddAttribute("target",
  2540. this->CreateObjectReference(dependTarget));
  2541. targetdep->AddAttribute("targetProxy",
  2542. this->CreateObjectReference(container));
  2543. cmXCodeObject* depends = target->GetObject("dependencies");
  2544. if(!depends)
  2545. {
  2546. cmSystemTools::
  2547. Error("target does not have dependencies attribute error..");
  2548. }
  2549. else
  2550. {
  2551. depends->AddUniqueObject(targetdep);
  2552. }
  2553. }
  2554. //----------------------------------------------------------------------------
  2555. void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings,
  2556. const char* attribute,
  2557. const char* value)
  2558. {
  2559. if(settings)
  2560. {
  2561. cmXCodeObject* attr = settings->GetObject(attribute);
  2562. if(!attr)
  2563. {
  2564. settings->AddAttribute(attribute, this->CreateString(value));
  2565. }
  2566. else
  2567. {
  2568. std::string oldValue = attr->GetString();
  2569. oldValue += " ";
  2570. oldValue += value;
  2571. attr->SetString(oldValue.c_str());
  2572. }
  2573. }
  2574. }
  2575. //----------------------------------------------------------------------------
  2576. void cmGlobalXCodeGenerator
  2577. ::AppendBuildSettingAttribute(cmXCodeObject* target,
  2578. const char* attribute,
  2579. const char* value,
  2580. const std::string& configName)
  2581. {
  2582. if(this->XcodeVersion < 21)
  2583. {
  2584. // There is only one configuration. Add the setting to the buildSettings
  2585. // of the target.
  2586. this->AppendOrAddBuildSetting(target->GetObject("buildSettings"),
  2587. attribute, value);
  2588. }
  2589. else
  2590. {
  2591. // There are multiple configurations. Add the setting to the
  2592. // buildSettings of the configuration name given.
  2593. cmXCodeObject* configurationList =
  2594. target->GetObject("buildConfigurationList")->GetObject();
  2595. cmXCodeObject* buildConfigs =
  2596. configurationList->GetObject("buildConfigurations");
  2597. std::vector<cmXCodeObject*> list = buildConfigs->GetObjectList();
  2598. // each configuration and the target itself has a buildSettings in it
  2599. //list.push_back(target);
  2600. for(std::vector<cmXCodeObject*>::iterator i = list.begin();
  2601. i != list.end(); ++i)
  2602. {
  2603. if(!configName.empty())
  2604. {
  2605. if((*i)->GetObject("name")->GetString() == configName)
  2606. {
  2607. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  2608. this->AppendOrAddBuildSetting(settings, attribute, value);
  2609. }
  2610. }
  2611. else
  2612. {
  2613. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  2614. this->AppendOrAddBuildSetting(settings, attribute, value);
  2615. }
  2616. }
  2617. }
  2618. }
  2619. //----------------------------------------------------------------------------
  2620. void cmGlobalXCodeGenerator
  2621. ::AddDependAndLinkInformation(cmXCodeObject* target)
  2622. {
  2623. cmTarget* cmtarget = target->GetTarget();
  2624. if(cmtarget->GetType() == cmTarget::INTERFACE_LIBRARY)
  2625. {
  2626. return;
  2627. }
  2628. if(!cmtarget)
  2629. {
  2630. cmSystemTools::Error("Error no target on xobject\n");
  2631. return;
  2632. }
  2633. // Add dependencies on other CMake targets.
  2634. TargetDependSet const& deps = this->GetTargetDirectDepends(*cmtarget);
  2635. for(TargetDependSet::const_iterator i = deps.begin(); i != deps.end(); ++i)
  2636. {
  2637. if(cmXCodeObject* dptarget = this->FindXCodeTarget(*i))
  2638. {
  2639. this->AddDependTarget(target, dptarget);
  2640. }
  2641. }
  2642. // Loop over configuration types and set per-configuration info.
  2643. for(std::vector<std::string>::iterator i =
  2644. this->CurrentConfigurationTypes.begin();
  2645. i != this->CurrentConfigurationTypes.end(); ++i)
  2646. {
  2647. // Get the current configuration name.
  2648. std::string configName = *i;
  2649. if(this->XcodeVersion >= 50)
  2650. {
  2651. // Add object library contents as link flags.
  2652. std::string linkObjs;
  2653. const char* sep = "";
  2654. std::vector<std::string> objs;
  2655. this->GetGeneratorTarget(cmtarget)->UseObjectLibraries(objs, "");
  2656. for(std::vector<std::string>::const_iterator
  2657. oi = objs.begin(); oi != objs.end(); ++oi)
  2658. {
  2659. linkObjs += sep;
  2660. sep = " ";
  2661. linkObjs += this->XCodeEscapePath(oi->c_str());
  2662. }
  2663. this->AppendBuildSettingAttribute(
  2664. target, this->GetTargetLinkFlagsVar(*cmtarget),
  2665. linkObjs.c_str(), configName);
  2666. }
  2667. // Skip link information for object libraries.
  2668. if(cmtarget->GetType() == cmTarget::OBJECT_LIBRARY ||
  2669. cmtarget->GetType() == cmTarget::STATIC_LIBRARY)
  2670. {
  2671. continue;
  2672. }
  2673. // Compute the link library and directory information.
  2674. cmComputeLinkInformation* pcli = cmtarget->GetLinkInformation(configName);
  2675. if(!pcli)
  2676. {
  2677. continue;
  2678. }
  2679. cmComputeLinkInformation& cli = *pcli;
  2680. // Add dependencies directly on library files.
  2681. {
  2682. std::vector<std::string> const& libDeps = cli.GetDepends();
  2683. for(std::vector<std::string>::const_iterator j = libDeps.begin();
  2684. j != libDeps.end(); ++j)
  2685. {
  2686. target->AddDependLibrary(configName, j->c_str());
  2687. }
  2688. }
  2689. // add the library search paths
  2690. {
  2691. std::vector<std::string> const& libDirs = cli.GetDirectories();
  2692. std::string linkDirs;
  2693. for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
  2694. libDir != libDirs.end(); ++libDir)
  2695. {
  2696. if(libDir->size() && *libDir != "/usr/lib")
  2697. {
  2698. if(this->XcodeVersion > 15)
  2699. {
  2700. // Now add the same one but append
  2701. // $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) to it:
  2702. linkDirs += " ";
  2703. linkDirs += this->XCodeEscapePath(
  2704. (*libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)").c_str());
  2705. }
  2706. linkDirs += " ";
  2707. linkDirs += this->XCodeEscapePath(libDir->c_str());
  2708. }
  2709. }
  2710. this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS",
  2711. linkDirs.c_str(), configName);
  2712. }
  2713. // now add the link libraries
  2714. {
  2715. std::string linkLibs;
  2716. const char* sep = "";
  2717. typedef cmComputeLinkInformation::ItemVector ItemVector;
  2718. ItemVector const& libNames = cli.GetItems();
  2719. for(ItemVector::const_iterator li = libNames.begin();
  2720. li != libNames.end(); ++li)
  2721. {
  2722. linkLibs += sep;
  2723. sep = " ";
  2724. if(li->IsPath)
  2725. {
  2726. linkLibs += this->XCodeEscapePath(li->Value.c_str());
  2727. }
  2728. else if (!li->Target
  2729. || li->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  2730. {
  2731. linkLibs += li->Value;
  2732. }
  2733. if(li->Target && !li->Target->IsImported())
  2734. {
  2735. target->AddDependTarget(configName, li->Target->GetName());
  2736. }
  2737. }
  2738. this->AppendBuildSettingAttribute(
  2739. target, this->GetTargetLinkFlagsVar(*cmtarget),
  2740. linkLibs.c_str(), configName);
  2741. }
  2742. }
  2743. }
  2744. //----------------------------------------------------------------------------
  2745. bool cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
  2746. std::vector<cmLocalGenerator*>&
  2747. generators)
  2748. {
  2749. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  2750. i != generators.end(); ++i)
  2751. {
  2752. if(this->IsExcluded(root, *i))
  2753. {
  2754. continue;
  2755. }
  2756. cmMakefile* mf = (*i)->GetMakefile();
  2757. std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
  2758. cmTargets &tgts = mf->GetTargets();
  2759. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  2760. {
  2761. cmTarget& cmtarget = l->second;
  2762. // Same skipping logic here as in CreateXCodeTargets so that we do not
  2763. // end up with (empty anyhow) ALL_BUILD and XCODE_DEPEND_HELPER source
  2764. // groups:
  2765. //
  2766. if(cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
  2767. {
  2768. continue;
  2769. }
  2770. if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
  2771. {
  2772. continue;
  2773. }
  2774. // add the soon to be generated Info.plist file as a source for a
  2775. // MACOSX_BUNDLE file
  2776. if(cmtarget.GetPropertyAsBool("MACOSX_BUNDLE"))
  2777. {
  2778. std::string plist = this->ComputeInfoPListLocation(cmtarget);
  2779. mf->GetOrCreateSource(plist, true);
  2780. cmtarget.AddSource(plist);
  2781. }
  2782. std::vector<cmSourceFile*> classes;
  2783. if (!cmtarget.GetConfigCommonSourceFiles(classes))
  2784. {
  2785. return false;
  2786. }
  2787. // Put cmSourceFile instances in proper groups:
  2788. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  2789. s != classes.end(); s++)
  2790. {
  2791. cmSourceFile* sf = *s;
  2792. // Add the file to the list of sources.
  2793. std::string const& source = sf->GetFullPath();
  2794. cmSourceGroup* sourceGroup =
  2795. mf->FindSourceGroup(source.c_str(), sourceGroups);
  2796. cmXCodeObject* pbxgroup =
  2797. this->CreateOrGetPBXGroup(cmtarget, sourceGroup);
  2798. std::string key = GetGroupMapKey(cmtarget, sf);
  2799. this->GroupMap[key] = pbxgroup;
  2800. }
  2801. // Put OBJECT_LIBRARY objects in proper groups:
  2802. std::vector<std::string> objs;
  2803. this->GetGeneratorTarget(&cmtarget)->UseObjectLibraries(objs, "");
  2804. for(std::vector<std::string>::const_iterator
  2805. oi = objs.begin(); oi != objs.end(); ++oi)
  2806. {
  2807. std::string const& source = *oi;
  2808. cmSourceGroup* sourceGroup =
  2809. mf->FindSourceGroup(source.c_str(), sourceGroups);
  2810. cmXCodeObject* pbxgroup =
  2811. this->CreateOrGetPBXGroup(cmtarget, sourceGroup);
  2812. std::string key = GetGroupMapKeyFromPath(cmtarget, source);
  2813. this->GroupMap[key] = pbxgroup;
  2814. }
  2815. }
  2816. }
  2817. return true;
  2818. }
  2819. cmXCodeObject *cmGlobalXCodeGenerator
  2820. ::CreatePBXGroup(cmXCodeObject *parent, std::string name)
  2821. {
  2822. cmXCodeObject* parentChildren = NULL;
  2823. if(parent)
  2824. parentChildren = parent->GetObject("children");
  2825. cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
  2826. cmXCodeObject* groupChildren =
  2827. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2828. group->AddAttribute("name", this->CreateString(name.c_str()));
  2829. group->AddAttribute("children", groupChildren);
  2830. if(this->XcodeVersion == 15)
  2831. {
  2832. group->AddAttribute("refType", this->CreateString("4"));
  2833. }
  2834. group->AddAttribute("sourceTree", this->CreateString("<group>"));
  2835. if(parentChildren)
  2836. parentChildren->AddObject(group);
  2837. return group;
  2838. }
  2839. //----------------------------------------------------------------------------
  2840. cmXCodeObject* cmGlobalXCodeGenerator
  2841. ::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg)
  2842. {
  2843. std::string s;
  2844. std::string target;
  2845. const char *targetFolder= cmtarget.GetProperty("FOLDER");
  2846. if(targetFolder) {
  2847. target = targetFolder;
  2848. target += "/";
  2849. }
  2850. target += cmtarget.GetName();
  2851. s = target + "/";
  2852. s += sg->GetFullName();
  2853. std::map<std::string, cmXCodeObject* >::iterator it =
  2854. this->GroupNameMap.find(s);
  2855. if(it != this->GroupNameMap.end())
  2856. {
  2857. return it->second;
  2858. }
  2859. it = this->TargetGroup.find(target);
  2860. cmXCodeObject* tgroup = 0;
  2861. if(it != this->TargetGroup.end())
  2862. {
  2863. tgroup = it->second;
  2864. }
  2865. else
  2866. {
  2867. std::vector<std::string> tgt_folders =
  2868. cmSystemTools::tokenize(target, "/");
  2869. std::string curr_tgt_folder;
  2870. for(std::vector<std::string>::size_type i = 0; i < tgt_folders.size();i++)
  2871. {
  2872. if (i != 0)
  2873. {
  2874. curr_tgt_folder += "/";
  2875. }
  2876. curr_tgt_folder += tgt_folders[i];
  2877. it = this->TargetGroup.find(curr_tgt_folder);
  2878. if(it != this->TargetGroup.end())
  2879. {
  2880. tgroup = it->second;
  2881. continue;
  2882. }
  2883. tgroup = this->CreatePBXGroup(tgroup,tgt_folders[i]);
  2884. this->TargetGroup[curr_tgt_folder] = tgroup;
  2885. if(i == 0)
  2886. {
  2887. this->SourcesGroupChildren->AddObject(tgroup);
  2888. }
  2889. }
  2890. }
  2891. this->TargetGroup[target] = tgroup;
  2892. // If it's the default source group (empty name) then put the source file
  2893. // directly in the tgroup...
  2894. //
  2895. if (std::string(sg->GetFullName()) == "")
  2896. {
  2897. this->GroupNameMap[s] = tgroup;
  2898. return tgroup;
  2899. }
  2900. //It's a recursive folder structure, let's find the real parent group
  2901. if(std::string(sg->GetFullName()) != std::string(sg->GetName()))
  2902. {
  2903. std::vector<std::string> folders =
  2904. cmSystemTools::tokenize(sg->GetFullName(), "\\");
  2905. std::string curr_folder = target;
  2906. curr_folder += "/";
  2907. for(std::vector<std::string>::size_type i = 0; i < folders.size();i++)
  2908. {
  2909. curr_folder += folders[i];
  2910. std::map<std::string, cmXCodeObject* >::iterator i_folder =
  2911. this->GroupNameMap.find(curr_folder);
  2912. //Create new folder
  2913. if(i_folder == this->GroupNameMap.end())
  2914. {
  2915. cmXCodeObject *group = this->CreatePBXGroup(tgroup,folders[i]);
  2916. this->GroupNameMap[curr_folder] = group;
  2917. tgroup = group;
  2918. }
  2919. else
  2920. {
  2921. tgroup = i_folder->second;
  2922. }
  2923. curr_folder = curr_folder + "\\";
  2924. }
  2925. return tgroup;
  2926. }
  2927. cmXCodeObject *group = this->CreatePBXGroup(tgroup,sg->GetName());
  2928. this->GroupNameMap[s] = group;
  2929. return group;
  2930. }
  2931. //----------------------------------------------------------------------------
  2932. bool cmGlobalXCodeGenerator
  2933. ::CreateXCodeObjects(cmLocalGenerator* root,
  2934. std::vector<cmLocalGenerator*>&
  2935. generators)
  2936. {
  2937. this->ClearXCodeObjects();
  2938. this->RootObject = 0;
  2939. this->SourcesGroupChildren = 0;
  2940. this->ResourcesGroupChildren = 0;
  2941. this->MainGroupChildren = 0;
  2942. cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2943. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  2944. cmXCodeObject* developBuildStyle =
  2945. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2946. cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2947. if(this->XcodeVersion == 15)
  2948. {
  2949. developBuildStyle->AddAttribute("name",
  2950. this->CreateString("Development"));
  2951. developBuildStyle->AddAttribute("buildSettings", group);
  2952. listObjs->AddObject(developBuildStyle);
  2953. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2954. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("YES"));
  2955. cmXCodeObject* deployBuildStyle =
  2956. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2957. deployBuildStyle->AddAttribute("name", this->CreateString("Deployment"));
  2958. deployBuildStyle->AddAttribute("buildSettings", group);
  2959. listObjs->AddObject(deployBuildStyle);
  2960. }
  2961. else
  2962. {
  2963. for(unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i)
  2964. {
  2965. cmXCodeObject* buildStyle =
  2966. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2967. const char* name = this->CurrentConfigurationTypes[i].c_str();
  2968. buildStyle->AddAttribute("name", this->CreateString(name));
  2969. buildStyle->SetComment(name);
  2970. cmXCodeObject* sgroup =
  2971. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2972. sgroup->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  2973. buildStyle->AddAttribute("buildSettings", sgroup);
  2974. listObjs->AddObject(buildStyle);
  2975. }
  2976. }
  2977. cmXCodeObject* mainGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2978. this->MainGroupChildren =
  2979. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2980. mainGroup->AddAttribute("children", this->MainGroupChildren);
  2981. if(this->XcodeVersion == 15)
  2982. {
  2983. mainGroup->AddAttribute("refType", this->CreateString("4"));
  2984. }
  2985. mainGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2986. cmXCodeObject* sourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2987. this->SourcesGroupChildren =
  2988. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2989. sourcesGroup->AddAttribute("name", this->CreateString("Sources"));
  2990. sourcesGroup->AddAttribute("children", this->SourcesGroupChildren);
  2991. if(this->XcodeVersion == 15)
  2992. {
  2993. sourcesGroup->AddAttribute("refType", this->CreateString("4"));
  2994. }
  2995. sourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2996. this->MainGroupChildren->AddObject(sourcesGroup);
  2997. cmXCodeObject* resourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2998. this->ResourcesGroupChildren =
  2999. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  3000. resourcesGroup->AddAttribute("name", this->CreateString("Resources"));
  3001. resourcesGroup->AddAttribute("children", this->ResourcesGroupChildren);
  3002. if(this->XcodeVersion == 15)
  3003. {
  3004. resourcesGroup->AddAttribute("refType", this->CreateString("4"));
  3005. }
  3006. resourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  3007. this->MainGroupChildren->AddObject(resourcesGroup);
  3008. // now create the cmake groups
  3009. if (!this->CreateGroups(root, generators))
  3010. {
  3011. return false;
  3012. }
  3013. cmXCodeObject* productGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  3014. productGroup->AddAttribute("name", this->CreateString("Products"));
  3015. if(this->XcodeVersion == 15)
  3016. {
  3017. productGroup->AddAttribute("refType", this->CreateString("4"));
  3018. }
  3019. productGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  3020. cmXCodeObject* productGroupChildren =
  3021. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  3022. productGroup->AddAttribute("children", productGroupChildren);
  3023. this->MainGroupChildren->AddObject(productGroup);
  3024. this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
  3025. this->RootObject->SetComment("Project object");
  3026. std::string project_id = "PROJECT_";
  3027. project_id += root->GetMakefile()->GetProjectName();
  3028. this->RootObject->SetId(this->GetOrCreateId(
  3029. project_id.c_str(), this->RootObject->GetId()).c_str());
  3030. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  3031. this->RootObject->AddAttribute("mainGroup",
  3032. this->CreateObjectReference(mainGroup));
  3033. this->RootObject->AddAttribute("buildSettings", group);
  3034. this->RootObject->AddAttribute("buildStyles", listObjs);
  3035. this->RootObject->AddAttribute("hasScannedForEncodings",
  3036. this->CreateString("0"));
  3037. if (this->XcodeVersion >= 30)
  3038. {
  3039. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  3040. group->AddAttribute("BuildIndependentTargetsInParallel",
  3041. this->CreateString("YES"));
  3042. this->RootObject->AddAttribute("attributes", group);
  3043. if (this->XcodeVersion >= 32)
  3044. this->RootObject->AddAttribute("compatibilityVersion",
  3045. this->CreateString("Xcode 3.2"));
  3046. else if (this->XcodeVersion >= 31)
  3047. this->RootObject->AddAttribute("compatibilityVersion",
  3048. this->CreateString("Xcode 3.1"));
  3049. else
  3050. this->RootObject->AddAttribute("compatibilityVersion",
  3051. this->CreateString("Xcode 3.0"));
  3052. }
  3053. // Point Xcode at the top of the source tree.
  3054. {
  3055. std::string pdir =
  3056. this->RelativeToBinary(root->GetMakefile()->GetCurrentDirectory());
  3057. this->RootObject->AddAttribute("projectDirPath",
  3058. this->CreateString(pdir.c_str()));
  3059. this->RootObject->AddAttribute("projectRoot", this->CreateString(""));
  3060. }
  3061. cmXCodeObject* configlist =
  3062. this->CreateObject(cmXCodeObject::XCConfigurationList);
  3063. cmXCodeObject* buildConfigurations =
  3064. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  3065. std::vector<cmXCodeObject*> configs;
  3066. const char *defaultConfigName = "Debug";
  3067. if(this->XcodeVersion == 15)
  3068. {
  3069. cmXCodeObject* configDebug =
  3070. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  3071. configDebug->AddAttribute("name", this->CreateString("Debug"));
  3072. configs.push_back(configDebug);
  3073. cmXCodeObject* configRelease =
  3074. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  3075. configRelease->AddAttribute("name", this->CreateString("Release"));
  3076. configs.push_back(configRelease);
  3077. }
  3078. else
  3079. {
  3080. for(unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i)
  3081. {
  3082. const char* name = this->CurrentConfigurationTypes[i].c_str();
  3083. if (0 == i)
  3084. {
  3085. defaultConfigName = name;
  3086. }
  3087. cmXCodeObject* config =
  3088. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  3089. config->AddAttribute("name", this->CreateString(name));
  3090. configs.push_back(config);
  3091. }
  3092. }
  3093. for(std::vector<cmXCodeObject*>::iterator c = configs.begin();
  3094. c != configs.end(); ++c)
  3095. {
  3096. buildConfigurations->AddObject(*c);
  3097. }
  3098. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  3099. std::string comment = "Build configuration list for PBXProject ";
  3100. comment += " \"";
  3101. comment += this->CurrentProject;
  3102. comment += "\"";
  3103. configlist->SetComment(comment.c_str());
  3104. configlist->AddAttribute("defaultConfigurationIsVisible",
  3105. this->CreateString("0"));
  3106. configlist->AddAttribute("defaultConfigurationName",
  3107. this->CreateString(defaultConfigName));
  3108. cmXCodeObject* buildSettings =
  3109. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  3110. const char* osxArch =
  3111. this->CurrentMakefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
  3112. if(!osxArch || strlen(osxArch) == 0)
  3113. {
  3114. if(this->XcodeVersion >= 32)
  3115. {
  3116. osxArch = "$(ARCHS_STANDARD_32_64_BIT)";
  3117. }
  3118. else if(this->XcodeVersion == 31)
  3119. {
  3120. osxArch = "$(ARCHS_STANDARD_32_BIT)";
  3121. }
  3122. else if(this->XcodeVersion <= 30)
  3123. {
  3124. #ifdef __ppc__
  3125. osxArch = "ppc";
  3126. #endif
  3127. #ifdef __i386
  3128. osxArch = "i386";
  3129. #endif
  3130. }
  3131. buildSettings->AddAttribute("ONLY_ACTIVE_ARCH",
  3132. this->CreateString("YES"));
  3133. }
  3134. const char* sysroot =
  3135. this->CurrentMakefile->GetDefinition("CMAKE_OSX_SYSROOT");
  3136. const char* deploymentTarget =
  3137. this->CurrentMakefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
  3138. if(osxArch && sysroot)
  3139. {
  3140. // recompute this as it may have been changed since enable language
  3141. this->Architectures.clear();
  3142. cmSystemTools::ExpandListArgument(std::string(osxArch),
  3143. this->Architectures);
  3144. buildSettings->AddAttribute("SDKROOT",
  3145. this->CreateString(sysroot));
  3146. std::string archString;
  3147. const char* sep = "";
  3148. for( std::vector<std::string>::iterator i =
  3149. this->Architectures.begin();
  3150. i != this->Architectures.end(); ++i)
  3151. {
  3152. archString += sep;
  3153. archString += *i;
  3154. sep = " ";
  3155. }
  3156. buildSettings->AddAttribute("ARCHS",
  3157. this->CreateString(archString.c_str()));
  3158. }
  3159. if(deploymentTarget && *deploymentTarget)
  3160. {
  3161. buildSettings->AddAttribute("MACOSX_DEPLOYMENT_TARGET",
  3162. this->CreateString(deploymentTarget));
  3163. }
  3164. if(!this->GeneratorToolset.empty())
  3165. {
  3166. buildSettings->AddAttribute("GCC_VERSION",
  3167. this->CreateString(this->GeneratorToolset.c_str()));
  3168. }
  3169. // Put this last so it can override existing settings
  3170. // Convert "CMAKE_XCODE_ATTRIBUTE_*" variables directly.
  3171. {
  3172. std::vector<std::string> vars = this->CurrentMakefile->GetDefinitions();
  3173. for(std::vector<std::string>::const_iterator i = vars.begin();
  3174. i != vars.end(); ++i)
  3175. {
  3176. if(i->find("CMAKE_XCODE_ATTRIBUTE_") == 0)
  3177. {
  3178. buildSettings->AddAttribute(i->substr(22).c_str(),
  3179. this->CreateString(
  3180. this->CurrentMakefile->GetDefinition(i->c_str())));
  3181. }
  3182. }
  3183. }
  3184. std::string symroot = root->GetMakefile()->GetCurrentOutputDirectory();
  3185. symroot += "/build";
  3186. buildSettings->AddAttribute("SYMROOT", this->CreateString(symroot.c_str()));
  3187. for( std::vector<cmXCodeObject*>::iterator i = configs.begin();
  3188. i != configs.end(); ++i)
  3189. {
  3190. (*i)->AddAttribute("buildSettings", buildSettings);
  3191. }
  3192. this->RootObject->AddAttribute("buildConfigurationList",
  3193. this->CreateObjectReference(configlist));
  3194. std::vector<cmXCodeObject*> targets;
  3195. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  3196. i != generators.end(); ++i)
  3197. {
  3198. if(!this->IsExcluded(root, *i))
  3199. {
  3200. if (!this->CreateXCodeTargets(*i, targets))
  3201. {
  3202. return false;
  3203. }
  3204. }
  3205. }
  3206. // loop over all targets and add link and depend info
  3207. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  3208. i != targets.end(); ++i)
  3209. {
  3210. cmXCodeObject* t = *i;
  3211. this->AddDependAndLinkInformation(t);
  3212. }
  3213. if(this->XcodeVersion < 50)
  3214. {
  3215. // now create xcode depend hack makefile
  3216. this->CreateXCodeDependHackTarget(targets);
  3217. }
  3218. // now add all targets to the root object
  3219. cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  3220. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  3221. i != targets.end(); ++i)
  3222. {
  3223. cmXCodeObject* t = *i;
  3224. allTargets->AddObject(t);
  3225. cmXCodeObject* productRef = t->GetObject("productReference");
  3226. if(productRef)
  3227. {
  3228. productGroupChildren->AddObject(productRef->GetObject());
  3229. }
  3230. }
  3231. this->RootObject->AddAttribute("targets", allTargets);
  3232. return true;
  3233. }
  3234. //----------------------------------------------------------------------------
  3235. std::string
  3236. cmGlobalXCodeGenerator::GetObjectsNormalDirectory(
  3237. const std::string &projName,
  3238. const std::string &configName,
  3239. const cmTarget *t) const
  3240. {
  3241. std::string dir =
  3242. t->GetMakefile()->GetCurrentOutputDirectory();
  3243. dir += "/";
  3244. dir += projName;
  3245. dir += ".build/";
  3246. dir += configName;
  3247. dir += "/";
  3248. dir += t->GetName();
  3249. dir += ".build/Objects-normal/";
  3250. return dir;
  3251. }
  3252. //----------------------------------------------------------------------------
  3253. void
  3254. cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
  3255. std::vector<cmXCodeObject*>& targets)
  3256. {
  3257. cmGeneratedFileStream
  3258. makefileStream(this->CurrentXCodeHackMakefile.c_str());
  3259. if(!makefileStream)
  3260. {
  3261. cmSystemTools::Error("Could not create",
  3262. this->CurrentXCodeHackMakefile.c_str());
  3263. return;
  3264. }
  3265. makefileStream.SetCopyIfDifferent(true);
  3266. // one more pass for external depend information not handled
  3267. // correctly by xcode
  3268. makefileStream << "# DO NOT EDIT\n";
  3269. makefileStream << "# This makefile makes sure all linkable targets are\n";
  3270. makefileStream << "# up-to-date with anything they link to\n"
  3271. "default:\n"
  3272. "\techo \"Do not invoke directly\"\n"
  3273. "\n";
  3274. makefileStream
  3275. << "# For each target create a dummy rule "
  3276. "so the target does not have to exist\n";
  3277. std::set<std::string> emitted;
  3278. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  3279. i != targets.end(); ++i)
  3280. {
  3281. cmXCodeObject* target = *i;
  3282. std::map<std::string, cmXCodeObject::StringVec> const& deplibs =
  3283. target->GetDependLibraries();
  3284. for(std::map<std::string, cmXCodeObject::StringVec>::const_iterator ci
  3285. = deplibs.begin(); ci != deplibs.end(); ++ci)
  3286. {
  3287. for(cmXCodeObject::StringVec::const_iterator d = ci->second.begin();
  3288. d != ci->second.end(); ++d)
  3289. {
  3290. if(emitted.insert(*d).second)
  3291. {
  3292. makefileStream <<
  3293. this->ConvertToRelativeForMake(d->c_str()) << ":\n";
  3294. }
  3295. }
  3296. }
  3297. }
  3298. makefileStream << "\n\n";
  3299. // Write rules to help Xcode relink things at the right time.
  3300. makefileStream <<
  3301. "# Rules to remove targets that are older than anything to which they\n"
  3302. "# link. This forces Xcode to relink the targets from scratch. It\n"
  3303. "# does not seem to check these dependencies itself.\n";
  3304. for(std::vector<std::string>::const_iterator
  3305. ct = this->CurrentConfigurationTypes.begin();
  3306. ct != this->CurrentConfigurationTypes.end(); ++ct)
  3307. {
  3308. std::string configName = *ct;
  3309. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  3310. i != targets.end(); ++i)
  3311. {
  3312. cmXCodeObject* target = *i;
  3313. cmTarget* t =target->GetTarget();
  3314. if(t->GetType() == cmTarget::EXECUTABLE ||
  3315. // Nope - no post-build for OBJECT_LIRBRARY
  3316. // t->GetType() == cmTarget::OBJECT_LIBRARY ||
  3317. t->GetType() == cmTarget::STATIC_LIBRARY ||
  3318. t->GetType() == cmTarget::SHARED_LIBRARY ||
  3319. t->GetType() == cmTarget::MODULE_LIBRARY)
  3320. {
  3321. // Declare an entry point for the target post-build phase.
  3322. makefileStream << this->PostBuildMakeTarget(t->GetName(), *ct)
  3323. << ":\n";
  3324. }
  3325. if(t->GetType() == cmTarget::EXECUTABLE ||
  3326. t->GetType() == cmTarget::SHARED_LIBRARY ||
  3327. t->GetType() == cmTarget::MODULE_LIBRARY)
  3328. {
  3329. std::string tfull = t->GetFullPath(configName);
  3330. std::string trel = this->ConvertToRelativeForMake(tfull.c_str());
  3331. // Add this target to the post-build phases of its dependencies.
  3332. std::map<std::string, cmXCodeObject::StringVec>::const_iterator
  3333. y = target->GetDependTargets().find(*ct);
  3334. if(y != target->GetDependTargets().end())
  3335. {
  3336. std::vector<std::string> const& deptgts = y->second;
  3337. for(std::vector<std::string>::const_iterator d = deptgts.begin();
  3338. d != deptgts.end(); ++d)
  3339. {
  3340. makefileStream << this->PostBuildMakeTarget(*d, *ct) << ": "
  3341. << trel << "\n";
  3342. }
  3343. }
  3344. // Create a rule for this target.
  3345. makefileStream << trel << ":";
  3346. // List dependencies if any exist.
  3347. std::map<std::string, cmXCodeObject::StringVec>::const_iterator
  3348. x = target->GetDependLibraries().find(*ct);
  3349. if(x != target->GetDependLibraries().end())
  3350. {
  3351. std::vector<std::string> const& deplibs = x->second;
  3352. for(std::vector<std::string>::const_iterator d = deplibs.begin();
  3353. d != deplibs.end(); ++d)
  3354. {
  3355. makefileStream << "\\\n\t" <<
  3356. this->ConvertToRelativeForMake(d->c_str());
  3357. }
  3358. }
  3359. // Write the action to remove the target if it is out of date.
  3360. makefileStream << "\n";
  3361. makefileStream << "\t/bin/rm -f "
  3362. << this->ConvertToRelativeForMake(tfull.c_str())
  3363. << "\n";
  3364. // if building for more than one architecture
  3365. // then remove those exectuables as well
  3366. if(this->Architectures.size() > 1)
  3367. {
  3368. std::string universal = this->GetObjectsNormalDirectory(
  3369. this->CurrentProject, configName, t);
  3370. for( std::vector<std::string>::iterator arch =
  3371. this->Architectures.begin();
  3372. arch != this->Architectures.end(); ++arch)
  3373. {
  3374. std::string universalFile = universal;
  3375. universalFile += *arch;
  3376. universalFile += "/";
  3377. universalFile += t->GetFullName(configName);
  3378. makefileStream << "\t/bin/rm -f "
  3379. <<
  3380. this->ConvertToRelativeForMake(universalFile.c_str())
  3381. << "\n";
  3382. }
  3383. }
  3384. makefileStream << "\n\n";
  3385. }
  3386. }
  3387. }
  3388. }
  3389. //----------------------------------------------------------------------------
  3390. void
  3391. cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
  3392. std::vector<cmLocalGenerator*>&
  3393. generators)
  3394. {
  3395. if(generators.size() == 0)
  3396. {
  3397. return;
  3398. }
  3399. // Skip local generators that are excluded from this project.
  3400. for(std::vector<cmLocalGenerator*>::iterator g = generators.begin();
  3401. g != generators.end(); ++g)
  3402. {
  3403. if(this->IsExcluded(root, *g))
  3404. {
  3405. continue;
  3406. }
  3407. }
  3408. if (!this->CreateXCodeObjects(root, generators))
  3409. {
  3410. return;
  3411. }
  3412. std::string xcodeDir = root->GetMakefile()->GetStartOutputDirectory();
  3413. xcodeDir += "/";
  3414. xcodeDir += root->GetMakefile()->GetProjectName();
  3415. xcodeDir += ".xcode";
  3416. if(this->XcodeVersion > 20)
  3417. {
  3418. xcodeDir += "proj";
  3419. }
  3420. cmSystemTools::MakeDirectory(xcodeDir.c_str());
  3421. std::string xcodeProjFile = xcodeDir + "/project.pbxproj";
  3422. cmGeneratedFileStream fout(xcodeProjFile.c_str());
  3423. fout.SetCopyIfDifferent(true);
  3424. if(!fout)
  3425. {
  3426. return;
  3427. }
  3428. this->WriteXCodePBXProj(fout, root, generators);
  3429. this->ClearXCodeObjects();
  3430. // Since this call may have created new cache entries, save the cache:
  3431. //
  3432. root->GetMakefile()->GetCacheManager()->SaveCache(
  3433. root->GetMakefile()->GetHomeOutputDirectory());
  3434. }
  3435. //----------------------------------------------------------------------------
  3436. void
  3437. cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
  3438. cmLocalGenerator* ,
  3439. std::vector<cmLocalGenerator*>& )
  3440. {
  3441. fout << "// !$*UTF8*$!\n";
  3442. fout << "{\n";
  3443. cmXCodeObject::Indent(1, fout);
  3444. fout << "archiveVersion = 1;\n";
  3445. cmXCodeObject::Indent(1, fout);
  3446. fout << "classes = {\n";
  3447. cmXCodeObject::Indent(1, fout);
  3448. fout << "};\n";
  3449. cmXCodeObject::Indent(1, fout);
  3450. if(this->XcodeVersion >= 21)
  3451. {
  3452. if (this->XcodeVersion >= 32)
  3453. fout << "objectVersion = 46;\n";
  3454. else if (this->XcodeVersion >= 31)
  3455. fout << "objectVersion = 45;\n";
  3456. else if (this->XcodeVersion >= 30)
  3457. fout << "objectVersion = 44;\n";
  3458. else
  3459. fout << "objectVersion = 42;\n";
  3460. cmXCode21Object::PrintList(this->XCodeObjects, fout);
  3461. }
  3462. else
  3463. {
  3464. fout << "objectVersion = 39;\n";
  3465. cmXCodeObject::PrintList(this->XCodeObjects, fout);
  3466. }
  3467. cmXCodeObject::Indent(1, fout);
  3468. fout << "rootObject = " << this->RootObject->GetId() << ";\n";
  3469. fout << "}\n";
  3470. }
  3471. //----------------------------------------------------------------------------
  3472. const char* cmGlobalXCodeGenerator::GetCMakeCFGIntDir() const
  3473. {
  3474. return this->XcodeVersion >= 21 ?
  3475. "$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)" : ".";
  3476. }
  3477. std::string cmGlobalXCodeGenerator::ExpandCFGIntDir(const std::string& str,
  3478. const std::string& config) const
  3479. {
  3480. std::string replace1 = "$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
  3481. std::string replace2 = "$(CONFIGURATION)";
  3482. std::string tmp = str;
  3483. for(std::string::size_type i = tmp.find(replace1);
  3484. i != std::string::npos;
  3485. i = tmp.find(replace1, i))
  3486. {
  3487. tmp.replace(i, replace1.size(), config);
  3488. i += config.size();
  3489. }
  3490. for(std::string::size_type i = tmp.find(replace2);
  3491. i != std::string::npos;
  3492. i = tmp.find(replace2, i))
  3493. {
  3494. tmp.replace(i, replace2.size(), config);
  3495. i += config.size();
  3496. }
  3497. return tmp;
  3498. }
  3499. //----------------------------------------------------------------------------
  3500. void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry)
  3501. {
  3502. entry.Name = cmGlobalXCodeGenerator::GetActualName();
  3503. entry.Brief = "Generate Xcode project files.";
  3504. }
  3505. //----------------------------------------------------------------------------
  3506. std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(const char* p)
  3507. {
  3508. if ( !this->CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  3509. {
  3510. return cmSystemTools::ConvertToOutputPath(p);
  3511. }
  3512. else
  3513. {
  3514. std::string ret =
  3515. this->CurrentLocalGenerator->
  3516. ConvertToRelativePath(this->CurrentOutputDirectoryComponents, p);
  3517. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  3518. }
  3519. }
  3520. //----------------------------------------------------------------------------
  3521. std::string cmGlobalXCodeGenerator::ConvertToRelativeForXCode(const char* p)
  3522. {
  3523. if ( !this->CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  3524. {
  3525. return cmSystemTools::ConvertToOutputPath(p);
  3526. }
  3527. else
  3528. {
  3529. std::string ret =
  3530. this->CurrentLocalGenerator->
  3531. ConvertToRelativePath(this->ProjectOutputDirectoryComponents, p);
  3532. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  3533. }
  3534. }
  3535. //----------------------------------------------------------------------------
  3536. std::string cmGlobalXCodeGenerator::RelativeToSource(const char* p)
  3537. {
  3538. // We force conversion because Xcode breakpoints do not work unless
  3539. // they are in a file named relative to the source tree.
  3540. return this->CurrentLocalGenerator->
  3541. ConvertToRelativePath(this->ProjectSourceDirectoryComponents, p, true);
  3542. }
  3543. //----------------------------------------------------------------------------
  3544. std::string cmGlobalXCodeGenerator::RelativeToBinary(const char* p)
  3545. {
  3546. return this->CurrentLocalGenerator->
  3547. ConvertToRelativePath(this->ProjectOutputDirectoryComponents, p);
  3548. }
  3549. //----------------------------------------------------------------------------
  3550. std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p)
  3551. {
  3552. std::string ret = p;
  3553. if(ret.find(' ') != ret.npos)
  3554. {
  3555. std::string t = ret;
  3556. ret = "\"";
  3557. ret += t;
  3558. ret += "\"";
  3559. }
  3560. return ret;
  3561. }
  3562. //----------------------------------------------------------------------------
  3563. void
  3564. cmGlobalXCodeGenerator
  3565. ::AppendDirectoryForConfig(const std::string& prefix,
  3566. const std::string& config,
  3567. const std::string& suffix,
  3568. std::string& dir)
  3569. {
  3570. if(this->XcodeVersion > 20)
  3571. {
  3572. if(!config.empty())
  3573. {
  3574. dir += prefix;
  3575. dir += config;
  3576. dir += suffix;
  3577. }
  3578. }
  3579. }
  3580. //----------------------------------------------------------------------------
  3581. std::string cmGlobalXCodeGenerator::LookupFlags(
  3582. const std::string& varNamePrefix,
  3583. const std::string& varNameLang,
  3584. const std::string& varNameSuffix,
  3585. const std::string& default_flags)
  3586. {
  3587. if(!varNameLang.empty())
  3588. {
  3589. std::string varName = varNamePrefix;
  3590. varName += varNameLang;
  3591. varName += varNameSuffix;
  3592. if(const char* varValue =
  3593. this->CurrentMakefile->GetDefinition(varName.c_str()))
  3594. {
  3595. if(*varValue)
  3596. {
  3597. return varValue;
  3598. }
  3599. }
  3600. }
  3601. return default_flags;
  3602. }
  3603. //----------------------------------------------------------------------------
  3604. void cmGlobalXCodeGenerator::AppendDefines(BuildObjectListOrString& defs,
  3605. const char* defines_list,
  3606. bool dflag)
  3607. {
  3608. // Skip this if there are no definitions.
  3609. if(!defines_list)
  3610. {
  3611. return;
  3612. }
  3613. // Expand the list of definitions.
  3614. std::vector<std::string> defines;
  3615. cmSystemTools::ExpandListArgument(defines_list, defines);
  3616. // Store the definitions in the string.
  3617. this->AppendDefines(defs, defines, dflag);
  3618. }
  3619. //----------------------------------------------------------------------------
  3620. void
  3621. cmGlobalXCodeGenerator::AppendDefines(BuildObjectListOrString& defs,
  3622. std::vector<std::string> const& defines,
  3623. bool dflag)
  3624. {
  3625. // GCC_PREPROCESSOR_DEFINITIONS is a space-separated list of definitions.
  3626. std::string def;
  3627. for(std::vector<std::string>::const_iterator di = defines.begin();
  3628. di != defines.end(); ++di)
  3629. {
  3630. // Start with -D if requested.
  3631. def = dflag? "-D": "";
  3632. def += *di;
  3633. // Append the flag with needed escapes.
  3634. std::string tmp;
  3635. this->AppendFlag(tmp, def);
  3636. defs.Add(tmp.c_str());
  3637. }
  3638. }
  3639. //----------------------------------------------------------------------------
  3640. void cmGlobalXCodeGenerator::AppendFlag(std::string& flags,
  3641. std::string const& flag)
  3642. {
  3643. // Short-circuit for an empty flag.
  3644. if(flag.empty())
  3645. {
  3646. return;
  3647. }
  3648. // Separate from previous flags.
  3649. if(!flags.empty())
  3650. {
  3651. flags += " ";
  3652. }
  3653. // Check if the flag needs quoting.
  3654. bool quoteFlag =
  3655. flag.find_first_of("`~!@#$%^&*()+={}[]|:;\"'<>,.? ") != flag.npos;
  3656. // We escape a flag as follows:
  3657. // - Place each flag in single quotes ''
  3658. // - Escape a single quote as \\'
  3659. // - Escape a backslash as \\\\ since it itself is an escape
  3660. // Note that in the code below we need one more level of escapes for
  3661. // C string syntax in this source file.
  3662. //
  3663. // The final level of escaping is done when the string is stored
  3664. // into the project file by cmXCodeObject::PrintString.
  3665. if(quoteFlag)
  3666. {
  3667. // Open single quote.
  3668. flags += "'";
  3669. }
  3670. // Flag value with escaped quotes and backslashes.
  3671. for(const char* c = flag.c_str(); *c; ++c)
  3672. {
  3673. if(*c == '\'')
  3674. {
  3675. if (this->XcodeVersion >= 40)
  3676. {
  3677. flags += "'\\\\''";
  3678. }
  3679. else
  3680. {
  3681. flags += "\\\\'";
  3682. }
  3683. }
  3684. else if(*c == '\\')
  3685. {
  3686. flags += "\\\\\\\\";
  3687. }
  3688. else
  3689. {
  3690. flags += *c;
  3691. }
  3692. }
  3693. if(quoteFlag)
  3694. {
  3695. // Close single quote.
  3696. flags += "'";
  3697. }
  3698. }
  3699. //----------------------------------------------------------------------------
  3700. std::string
  3701. cmGlobalXCodeGenerator::ComputeInfoPListLocation(cmTarget& target)
  3702. {
  3703. std::string plist = target.GetMakefile()->GetCurrentOutputDirectory();
  3704. plist += cmake::GetCMakeFilesDirectory();
  3705. plist += "/";
  3706. plist += target.GetName();
  3707. plist += ".dir/Info.plist";
  3708. return plist;
  3709. }
  3710. //----------------------------------------------------------------------------
  3711. // Return true if the generated build tree may contain multiple builds.
  3712. // i.e. "Can I build Debug and Release in the same tree?"
  3713. bool cmGlobalXCodeGenerator::IsMultiConfig()
  3714. {
  3715. // Old Xcode 1.5 is single config:
  3716. if(this->XcodeVersion == 15)
  3717. {
  3718. return false;
  3719. }
  3720. // Newer Xcode versions are multi config:
  3721. return true;
  3722. }
  3723. //----------------------------------------------------------------------------
  3724. void cmGlobalXCodeGenerator
  3725. ::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const
  3726. {
  3727. std::string configName = this->GetCMakeCFGIntDir();
  3728. std::string dir = this->GetObjectsNormalDirectory(
  3729. "$(PROJECT_NAME)", configName, gt->Target);
  3730. if(this->XcodeVersion >= 21)
  3731. {
  3732. dir += "$(CURRENT_ARCH)/";
  3733. }
  3734. else
  3735. {
  3736. #ifdef __ppc__
  3737. dir += "ppc/";
  3738. #endif
  3739. #ifdef __i386
  3740. dir += "i386/";
  3741. #endif
  3742. }
  3743. gt->ObjectDirectory = dir;
  3744. }