cmGlobalXCodeGenerator.cxx 131 KB

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