cmGlobalXCodeGenerator.cxx 132 KB

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