cmGlobalXCodeGenerator.cxx 114 KB

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