cmGlobalXCodeGenerator.cxx 128 KB

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