cmGlobalXCodeGenerator.cxx 113 KB

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