cmGlobalXCodeGenerator.cxx 132 KB

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