cmGlobalXCodeGenerator.cxx 131 KB

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