cmGlobalXCodeGenerator.cxx 132 KB

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