cmGlobalXCodeGenerator.cxx 132 KB

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