cmGlobalXCodeGenerator.cxx 131 KB

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