cmGlobalXCodeGenerator.cxx 131 KB

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