cmGlobalXCodeGenerator.cxx 132 KB

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