cmGlobalXCodeGenerator.cxx 132 KB

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