cmGlobalXCodeGenerator.cxx 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmGlobalXCodeGenerator.h"
  14. #include "cmGlobalXCode21Generator.h"
  15. #include "cmLocalXCodeGenerator.h"
  16. #include "cmMakefile.h"
  17. #include "cmXCodeObject.h"
  18. #include "cmXCode21Object.h"
  19. #include "cmake.h"
  20. #include "cmGeneratedFileStream.h"
  21. #include "cmSourceFile.h"
  22. #include "cmOrderLinkDirectories.h"
  23. //----------------------------------------------------------------------------
  24. #if defined(CMAKE_BUILD_WITH_CMAKE)
  25. #include "cmXMLParser.h"
  26. // parse the xml file storing the installed version of Xcode on
  27. // the machine
  28. class cmXcodeVersionParser : public cmXMLParser
  29. {
  30. public:
  31. void StartElement(const char* , const char** )
  32. {
  33. this->Data = "";
  34. }
  35. void EndElement(const char* name)
  36. {
  37. if(strcmp(name, "key") == 0)
  38. {
  39. this->Key = this->Data;
  40. }
  41. else if(strcmp(name, "string") == 0)
  42. {
  43. if(this->Key == "CFBundleShortVersionString")
  44. {
  45. this->Version = (int)(10.0 * atof(this->Data.c_str()));
  46. }
  47. }
  48. }
  49. void CharacterDataHandler(const char* data, int length)
  50. {
  51. this->Data.append(data, length);
  52. }
  53. int Version;
  54. std::string Key;
  55. std::string Data;
  56. };
  57. #endif
  58. //----------------------------------------------------------------------------
  59. cmGlobalXCodeGenerator::cmGlobalXCodeGenerator()
  60. {
  61. this->FindMakeProgramFile = "CMakeFindXCode.cmake";
  62. this->RootObject = 0;
  63. this->MainGroupChildren = 0;
  64. this->SourcesGroupChildren = 0;
  65. this->ResourcesGroupChildren = 0;
  66. this->CurrentMakefile = 0;
  67. this->CurrentLocalGenerator = 0;
  68. this->XcodeVersion = 15;
  69. }
  70. //----------------------------------------------------------------------------
  71. cmGlobalGenerator* cmGlobalXCodeGenerator::New()
  72. {
  73. #if defined(CMAKE_BUILD_WITH_CMAKE)
  74. cmXcodeVersionParser parser;
  75. parser.ParseFile
  76. ("/Developer/Applications/Xcode.app/Contents/version.plist");
  77. if(parser.Version == 15)
  78. {
  79. return new cmGlobalXCodeGenerator;
  80. }
  81. else if (parser.Version == 20)
  82. {
  83. cmSystemTools::Message("Xcode 2.0 not really supported by cmake, "
  84. "using Xcode 15 generator\n");
  85. return new cmGlobalXCodeGenerator;
  86. }
  87. cmGlobalXCodeGenerator* ret = new cmGlobalXCode21Generator;
  88. ret->SetVersion(parser.Version);
  89. return ret;
  90. #else
  91. std::cerr << "CMake should be built with cmake to use XCode, "
  92. "default to Xcode 1.5\n";
  93. return new cmGlobalXCodeGenerator;
  94. #endif
  95. }
  96. //----------------------------------------------------------------------------
  97. void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
  98. lang,
  99. cmMakefile * mf, bool optional)
  100. {
  101. mf->AddDefinition("XCODE","1");
  102. if(this->XcodeVersion == 15)
  103. {
  104. }
  105. else
  106. {
  107. mf->AddCacheDefinition(
  108. "CMAKE_CONFIGURATION_TYPES",
  109. "Debug;Release;MinSizeRel;RelWithDebInfo",
  110. "Semicolon separated list of supported configuration types, "
  111. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  112. "anything else will be ignored.",
  113. cmCacheManager::STRING);
  114. }
  115. mf->AddDefinition("CMAKE_GENERATOR_CC", "gcc");
  116. mf->AddDefinition("CMAKE_GENERATOR_CXX", "g++");
  117. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  118. // initialize Architectures so it can be used by
  119. // GetTargetObjectFileDirectories
  120. this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
  121. const char* osxArch =
  122. mf->GetDefinition("CMAKE_OSX_ARCHITECTURES");
  123. const char* sysroot =
  124. mf->GetDefinition("CMAKE_OSX_SYSROOT");
  125. if(osxArch && sysroot)
  126. {
  127. this->Architectures.clear();
  128. cmSystemTools::ExpandListArgument(std::string(osxArch),
  129. this->Architectures);
  130. }
  131. }
  132. //----------------------------------------------------------------------------
  133. std::string cmGlobalXCodeGenerator
  134. ::GenerateBuildCommand(const char* makeProgram,
  135. const char *projectName,
  136. const char* additionalOptions,
  137. const char *targetName,
  138. const char* config,
  139. bool ignoreErrors,
  140. bool)
  141. {
  142. // Config is not used yet
  143. (void) ignoreErrors;
  144. // now build the test
  145. if(makeProgram == 0 || !strlen(makeProgram))
  146. {
  147. cmSystemTools::Error(
  148. "Generator cannot find the appropriate make command.");
  149. return "";
  150. }
  151. std::string makeCommand =
  152. cmSystemTools::ConvertToOutputPath(makeProgram);
  153. std::string lowerCaseCommand = makeCommand;
  154. cmSystemTools::LowerCase(lowerCaseCommand);
  155. makeCommand += " -project ";
  156. makeCommand += projectName;
  157. makeCommand += ".xcode";
  158. if(this->XcodeVersion > 20)
  159. {
  160. makeCommand += "proj";
  161. }
  162. bool clean = false;
  163. if ( targetName && strcmp(targetName, "clean") == 0 )
  164. {
  165. clean = true;
  166. targetName = "ALL_BUILD";
  167. }
  168. if(clean)
  169. {
  170. makeCommand += " clean";
  171. }
  172. else
  173. {
  174. makeCommand += " build";
  175. }
  176. makeCommand += " -target ";
  177. if (targetName && strlen(targetName))
  178. {
  179. makeCommand += targetName;
  180. }
  181. else
  182. {
  183. makeCommand += "ALL_BUILD";
  184. }
  185. if(this->XcodeVersion == 15)
  186. {
  187. makeCommand += " -buildstyle Development ";
  188. }
  189. else
  190. {
  191. makeCommand += " -configuration ";
  192. makeCommand += config?config:"Debug";
  193. }
  194. if ( additionalOptions )
  195. {
  196. makeCommand += " ";
  197. makeCommand += additionalOptions;
  198. }
  199. return makeCommand;
  200. }
  201. //----------------------------------------------------------------------------
  202. ///! Create a local generator appropriate to this Global Generator
  203. cmLocalGenerator *cmGlobalXCodeGenerator::CreateLocalGenerator()
  204. {
  205. cmLocalGenerator *lg = new cmLocalXCodeGenerator;
  206. lg->SetGlobalGenerator(this);
  207. return lg;
  208. }
  209. //----------------------------------------------------------------------------
  210. void cmGlobalXCodeGenerator::Generate()
  211. {
  212. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  213. // make sure extra targets are added before calling
  214. // the parent generate which will call trace depends
  215. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  216. {
  217. cmLocalGenerator* root = it->second[0];
  218. this->SetGenerationRoot(root);
  219. // add ALL_BUILD, INSTALL, etc
  220. this->AddExtraTargets(root, it->second);
  221. }
  222. this->cmGlobalGenerator::Generate();
  223. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  224. {
  225. cmLocalGenerator* root = it->second[0];
  226. this->SetGenerationRoot(root);
  227. // now create the project
  228. this->OutputXCodeProject(root, it->second);
  229. }
  230. }
  231. //----------------------------------------------------------------------------
  232. void cmGlobalXCodeGenerator::SetGenerationRoot(cmLocalGenerator* root)
  233. {
  234. this->CurrentProject = root->GetMakefile()->GetProjectName();
  235. this->SetCurrentLocalGenerator(root);
  236. std::string outDir = this->CurrentMakefile->GetHomeOutputDirectory();
  237. outDir =cmSystemTools::CollapseFullPath(outDir.c_str());
  238. cmSystemTools::SplitPath(outDir.c_str(),
  239. this->ProjectOutputDirectoryComponents);
  240. this->CurrentXCodeHackMakefile =
  241. root->GetMakefile()->GetCurrentOutputDirectory();
  242. this->CurrentXCodeHackMakefile += "/CMakeScripts";
  243. cmSystemTools::MakeDirectory(this->CurrentXCodeHackMakefile.c_str());
  244. this->CurrentXCodeHackMakefile += "/XCODE_DEPEND_HELPER.make";
  245. }
  246. //----------------------------------------------------------------------------
  247. void
  248. cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
  249. std::vector<cmLocalGenerator*>& gens)
  250. {
  251. cmMakefile* mf = root->GetMakefile();
  252. // Add ALL_BUILD
  253. const char* no_working_directory = 0;
  254. std::vector<std::string> no_depends;
  255. mf->AddUtilityCommand("ALL_BUILD", true, no_depends,
  256. no_working_directory,
  257. "echo", "Build all projects");
  258. cmTarget* allbuild = mf->FindTarget("ALL_BUILD", false);
  259. // Add XCODE depend helper
  260. std::string dir = mf->GetCurrentOutputDirectory();
  261. cmCustomCommandLine makecommand;
  262. makecommand.push_back("make");
  263. makecommand.push_back("-C");
  264. makecommand.push_back(dir.c_str());
  265. makecommand.push_back("-f");
  266. makecommand.push_back(this->CurrentXCodeHackMakefile.c_str());
  267. if(this->XcodeVersion > 20)
  268. {
  269. makecommand.push_back("all.$(CONFIGURATION)");
  270. }
  271. cmCustomCommandLines commandLines;
  272. commandLines.push_back(makecommand);
  273. mf->AddUtilityCommand("XCODE_DEPEND_HELPER", true,
  274. no_working_directory,
  275. no_depends,
  276. commandLines);
  277. // Add Re-Run CMake rules
  278. this->CreateReRunCMakeFile(root);
  279. // now make the allbuild depend on all the non-utility targets
  280. // in the project
  281. for(std::vector<cmLocalGenerator*>::iterator i = gens.begin();
  282. i != gens.end(); ++i)
  283. {
  284. cmLocalGenerator* lg = *i;
  285. if(this->IsExcluded(root, *i))
  286. {
  287. continue;
  288. }
  289. cmTargets& tgts = lg->GetMakefile()->GetTargets();
  290. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  291. {
  292. cmTarget& target = l->second;
  293. // make all exe, shared libs and modules depend
  294. // on the XCODE_DEPEND_HELPER target
  295. if((target.GetType() == cmTarget::EXECUTABLE ||
  296. target.GetType() == cmTarget::SHARED_LIBRARY ||
  297. target.GetType() == cmTarget::MODULE_LIBRARY))
  298. {
  299. target.AddUtility("XCODE_DEPEND_HELPER");
  300. }
  301. if(!target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  302. {
  303. allbuild->AddUtility(target.GetName());
  304. }
  305. }
  306. }
  307. }
  308. //----------------------------------------------------------------------------
  309. void cmGlobalXCodeGenerator::CreateReRunCMakeFile(cmLocalGenerator* root)
  310. {
  311. cmMakefile* mf = root->GetMakefile();
  312. std::vector<std::string> lfiles = mf->GetListFiles();
  313. // sort the array
  314. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
  315. std::vector<std::string>::iterator new_end =
  316. std::unique(lfiles.begin(), lfiles.end());
  317. lfiles.erase(new_end, lfiles.end());
  318. std::string dir = mf->GetHomeOutputDirectory();
  319. this->CurrentReRunCMakeMakefile = dir;
  320. this->CurrentReRunCMakeMakefile += "/CMakeScripts";
  321. cmSystemTools::MakeDirectory(this->CurrentReRunCMakeMakefile.c_str());
  322. this->CurrentReRunCMakeMakefile += "/ReRunCMake.make";
  323. cmGeneratedFileStream makefileStream
  324. (this->CurrentReRunCMakeMakefile.c_str());
  325. makefileStream.SetCopyIfDifferent(true);
  326. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  327. makefileStream << cmake::GetCMakeFilesDirectoryPostSlash();
  328. makefileStream << "cmake.check_cache: ";
  329. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  330. i != lfiles.end(); ++i)
  331. {
  332. makefileStream << "\\\n" << this->ConvertToRelativeForMake(i->c_str());
  333. }
  334. std::string cmake = mf->GetRequiredDefinition("CMAKE_COMMAND");
  335. makefileStream << "\n\t" << this->ConvertToRelativeForMake(cmake.c_str())
  336. << " -H" << this->ConvertToRelativeForMake(
  337. mf->GetHomeDirectory())
  338. << " -B" << this->ConvertToRelativeForMake(
  339. mf->GetHomeOutputDirectory()) << "\n";
  340. }
  341. //----------------------------------------------------------------------------
  342. void cmGlobalXCodeGenerator::ClearXCodeObjects()
  343. {
  344. this->TargetDoneSet.clear();
  345. for(unsigned int i = 0; i < this->XCodeObjects.size(); ++i)
  346. {
  347. delete this->XCodeObjects[i];
  348. }
  349. this->XCodeObjects.clear();
  350. this->GroupMap.clear();
  351. this->GroupNameMap.clear();
  352. this->TargetGroup.clear();
  353. this->FileRefs.clear();
  354. }
  355. //----------------------------------------------------------------------------
  356. cmXCodeObject*
  357. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
  358. {
  359. cmXCodeObject* obj;
  360. if(this->XcodeVersion == 15)
  361. {
  362. obj = new cmXCodeObject(ptype, cmXCodeObject::OBJECT);
  363. }
  364. else
  365. {
  366. obj = new cmXCode21Object(ptype, cmXCodeObject::OBJECT);
  367. }
  368. this->XCodeObjects.push_back(obj);
  369. return obj;
  370. }
  371. //----------------------------------------------------------------------------
  372. cmXCodeObject*
  373. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
  374. {
  375. cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, type);
  376. this->XCodeObjects.push_back(obj);
  377. return obj;
  378. }
  379. //----------------------------------------------------------------------------
  380. cmXCodeObject*
  381. cmGlobalXCodeGenerator::CreateString(const char* s)
  382. {
  383. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::STRING);
  384. obj->SetString(s);
  385. return obj;
  386. }
  387. //----------------------------------------------------------------------------
  388. cmXCodeObject* cmGlobalXCodeGenerator
  389. ::CreateObjectReference(cmXCodeObject* ref)
  390. {
  391. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::OBJECT_REF);
  392. obj->SetObject(ref);
  393. return obj;
  394. }
  395. //----------------------------------------------------------------------------
  396. bool IsResource(cmSourceFile* sf)
  397. {
  398. const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION");
  399. bool isResource =
  400. (sf->GetPropertyAsBool("FRAMEWORK_RESOURCE") ||
  401. (location && cmStdString(location) == "Resources"));
  402. return isResource;
  403. }
  404. //----------------------------------------------------------------------------
  405. cmStdString GetGroupMapKey(cmTarget& cmtarget, cmSourceFile* sf)
  406. {
  407. cmStdString key(cmtarget.GetName());
  408. key += "-";
  409. key += sf->GetFullPath();
  410. return key;
  411. }
  412. //----------------------------------------------------------------------------
  413. cmXCodeObject*
  414. cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
  415. cmSourceFile* sf,
  416. cmTarget& cmtarget)
  417. {
  418. // Add flags from target and source file properties.
  419. std::string flags;
  420. if(cmtarget.GetProperty("COMPILE_FLAGS"))
  421. {
  422. lg->AppendFlags(flags, cmtarget.GetProperty("COMPILE_FLAGS"));
  423. }
  424. lg->AppendFlags(flags, sf->GetProperty("COMPILE_FLAGS"));
  425. cmSystemTools::ReplaceString(flags, "\"", "\\\"");
  426. // Using a map and the full path guarantees that we will always get the same
  427. // fileRef object for any given full path.
  428. //
  429. std::string fname = sf->GetFullPath();
  430. cmXCodeObject* fileRef = this->FileRefs[fname];
  431. if(!fileRef)
  432. {
  433. fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  434. std::string comment = fname;
  435. comment += " in ";
  436. //std::string gname = group->GetObject("name")->GetString();
  437. //comment += gname.substr(1, gname.size()-2);
  438. fileRef->SetComment(fname.c_str());
  439. this->FileRefs[fname] = fileRef;
  440. }
  441. cmStdString key = GetGroupMapKey(cmtarget, sf);
  442. cmXCodeObject* group = this->GroupMap[key];
  443. cmXCodeObject* children = group->GetObject("children");
  444. if (!children->HasObject(fileRef))
  445. {
  446. children->AddObject(fileRef);
  447. }
  448. cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
  449. buildFile->SetComment(fileRef->GetComment());
  450. buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef));
  451. cmXCodeObject* settings =
  452. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  453. settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags.c_str()));
  454. // Is this a resource file in this target? Add it to the resources group...
  455. //
  456. bool isResource = IsResource(sf);
  457. // Is this a "private" or "public" framework header file?
  458. // Set the ATTRIBUTES attribute appropriately...
  459. //
  460. if(cmtarget.GetType() == cmTarget::SHARED_LIBRARY &&
  461. cmtarget.GetPropertyAsBool("FRAMEWORK"))
  462. {
  463. if(sf->GetPropertyAsBool("FRAMEWORK_PRIVATE_HEADER"))
  464. {
  465. cmXCodeObject* attrs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  466. attrs->AddObject(this->CreateString("Private"));
  467. settings->AddAttribute("ATTRIBUTES", attrs);
  468. isResource = true;
  469. }
  470. else if(sf->GetPropertyAsBool("FRAMEWORK_PUBLIC_HEADER"))
  471. {
  472. cmXCodeObject* attrs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  473. attrs->AddObject(this->CreateString("Public"));
  474. settings->AddAttribute("ATTRIBUTES", attrs);
  475. isResource = true;
  476. }
  477. }
  478. // Add the fileRef to the top level Resources group/folder if it is not
  479. // already there.
  480. //
  481. if(isResource && this->ResourcesGroupChildren &&
  482. !this->ResourcesGroupChildren->HasObject(fileRef))
  483. {
  484. this->ResourcesGroupChildren->AddObject(fileRef);
  485. }
  486. buildFile->AddAttribute("settings", settings);
  487. fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
  488. const char* lang =
  489. this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
  490. std::string sourcecode = "sourcecode";
  491. std::string ext = sf->GetExtension();
  492. ext = cmSystemTools::LowerCase(ext);
  493. if(ext == "o")
  494. {
  495. sourcecode = "compiled.mach-o.objfile";
  496. }
  497. else if(ext == "mm")
  498. {
  499. sourcecode += ".cpp.objcpp";
  500. }
  501. else if(ext == "m")
  502. {
  503. sourcecode += ".cpp.objc";
  504. }
  505. else if(ext == "plist")
  506. {
  507. sourcecode += ".text.plist";
  508. }
  509. else if(!lang)
  510. {
  511. sourcecode += ext;
  512. sourcecode += ".";
  513. sourcecode += ext;
  514. }
  515. else if(strcmp(lang, "C") == 0)
  516. {
  517. sourcecode += ".c.c";
  518. }
  519. else if(strcmp(lang, "CXX") == 0)
  520. {
  521. sourcecode += ".cpp.cpp";
  522. }
  523. else
  524. {
  525. sourcecode += ext;
  526. sourcecode += ".";
  527. sourcecode += ext;
  528. }
  529. fileRef->AddAttribute("lastKnownFileType",
  530. this->CreateString(sourcecode.c_str()));
  531. std::string path =
  532. this->ConvertToRelativeForXCode(sf->GetFullPath().c_str());
  533. std::string dir;
  534. std::string file;
  535. cmSystemTools::SplitProgramPath(sf->GetFullPath().c_str(),
  536. dir, file);
  537. fileRef->AddAttribute("name", this->CreateString(file.c_str()));
  538. fileRef->AddAttribute("path", this->CreateString(path.c_str()));
  539. if(this->XcodeVersion == 15)
  540. {
  541. fileRef->AddAttribute("refType", this->CreateString("4"));
  542. }
  543. if(path.size() > 1 && path[0] == '.' && path[1] == '.')
  544. {
  545. fileRef->AddAttribute("sourceTree", this->CreateString("<group>"));
  546. }
  547. else
  548. {
  549. fileRef->AddAttribute("sourceTree", this->CreateString("<absolute>"));
  550. }
  551. return buildFile;
  552. }
  553. //----------------------------------------------------------------------------
  554. bool cmGlobalXCodeGenerator::SpecialTargetEmitted(std::string const& tname)
  555. {
  556. if(tname == "ALL_BUILD" || tname == "XCODE_DEPEND_HELPER" ||
  557. tname == "install" || tname == "package" || tname == "RUN_TESTS" )
  558. {
  559. if(this->TargetDoneSet.find(tname) != this->TargetDoneSet.end())
  560. {
  561. return true;
  562. }
  563. this->TargetDoneSet.insert(tname);
  564. return false;
  565. }
  566. return false;
  567. }
  568. //----------------------------------------------------------------------------
  569. void cmGlobalXCodeGenerator::SetCurrentLocalGenerator(cmLocalGenerator* gen)
  570. {
  571. this->CurrentLocalGenerator = gen;
  572. this->CurrentMakefile = gen->GetMakefile();
  573. std::string outdir =
  574. cmSystemTools::CollapseFullPath(this->CurrentMakefile->
  575. GetCurrentOutputDirectory());
  576. cmSystemTools::SplitPath(outdir.c_str(),
  577. this->CurrentOutputDirectoryComponents);
  578. // Select the current set of configuration types.
  579. this->CurrentConfigurationTypes.clear();
  580. if(this->XcodeVersion > 20)
  581. {
  582. if(const char* types =
  583. this->CurrentMakefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  584. {
  585. cmSystemTools::ExpandListArgument(types,
  586. this->CurrentConfigurationTypes);
  587. }
  588. }
  589. if(this->CurrentConfigurationTypes.empty())
  590. {
  591. if(const char* buildType =
  592. this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE"))
  593. {
  594. this->CurrentConfigurationTypes.push_back(buildType);
  595. }
  596. else
  597. {
  598. this->CurrentConfigurationTypes.push_back("");
  599. }
  600. }
  601. }
  602. //----------------------------------------------------------------------------
  603. void
  604. cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
  605. std::vector<cmXCodeObject*>&
  606. targets)
  607. {
  608. this->SetCurrentLocalGenerator(gen);
  609. cmTargets &tgts = this->CurrentMakefile->GetTargets();
  610. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  611. {
  612. cmTarget& cmtarget = l->second;
  613. // make sure ALL_BUILD, INSTALL, etc are only done once
  614. if(this->SpecialTargetEmitted(l->first.c_str()))
  615. {
  616. continue;
  617. }
  618. if(cmtarget.GetType() == cmTarget::UTILITY ||
  619. cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
  620. {
  621. targets.push_back(this->CreateUtilityTarget(cmtarget));
  622. continue;
  623. }
  624. // organize the sources
  625. std::vector<cmSourceFile*> const &classes = cmtarget.GetSourceFiles();
  626. std::vector<cmXCodeObject*> externalObjFiles;
  627. std::vector<cmXCodeObject*> headerFiles;
  628. std::vector<cmXCodeObject*> resourceFiles;
  629. std::vector<cmXCodeObject*> sourceFiles;
  630. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  631. i != classes.end(); ++i)
  632. {
  633. cmXCodeObject* xsf =
  634. this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
  635. *i, cmtarget);
  636. cmXCodeObject* fr = xsf->GetObject("fileRef");
  637. cmXCodeObject* filetype =
  638. fr->GetObject()->GetObject("lastKnownFileType");
  639. if(strcmp(filetype->GetString(), "\"compiled.mach-o.objfile\"") == 0)
  640. {
  641. externalObjFiles.push_back(xsf);
  642. }
  643. else if((*i)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  644. {
  645. headerFiles.push_back(xsf);
  646. }
  647. else if(IsResource(*i))
  648. {
  649. resourceFiles.push_back(xsf);
  650. }
  651. else
  652. {
  653. sourceFiles.push_back(xsf);
  654. }
  655. }
  656. // some build phases only apply to bundles and/or frameworks
  657. bool isFrameworkTarget = cmtarget.GetType() == cmTarget::SHARED_LIBRARY &&
  658. cmtarget.GetPropertyAsBool("FRAMEWORK");
  659. bool isBundleTarget = cmtarget.GetPropertyAsBool("MACOSX_BUNDLE");
  660. cmXCodeObject* buildFiles = 0;
  661. // create source build phase
  662. cmXCodeObject* sourceBuildPhase = 0;
  663. if (!sourceFiles.empty())
  664. {
  665. sourceBuildPhase =
  666. this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
  667. sourceBuildPhase->SetComment("Sources");
  668. sourceBuildPhase->AddAttribute("buildActionMask",
  669. this->CreateString("2147483647"));
  670. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  671. for(std::vector<cmXCodeObject*>::iterator i = sourceFiles.begin();
  672. i != sourceFiles.end(); ++i)
  673. {
  674. buildFiles->AddObject(*i);
  675. }
  676. sourceBuildPhase->AddAttribute("files", buildFiles);
  677. sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  678. this->CreateString("0"));
  679. }
  680. // create header build phase - only for framework targets
  681. cmXCodeObject* headerBuildPhase = 0;
  682. if (!headerFiles.empty() && isFrameworkTarget)
  683. {
  684. headerBuildPhase =
  685. this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase);
  686. headerBuildPhase->SetComment("Headers");
  687. headerBuildPhase->AddAttribute("buildActionMask",
  688. this->CreateString("2147483647"));
  689. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  690. for(std::vector<cmXCodeObject*>::iterator i = headerFiles.begin();
  691. i != headerFiles.end(); ++i)
  692. {
  693. buildFiles->AddObject(*i);
  694. }
  695. headerBuildPhase->AddAttribute("files", buildFiles);
  696. headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  697. this->CreateString("0"));
  698. }
  699. // create resource build phase - only for framework or bundle targets
  700. cmXCodeObject* resourceBuildPhase = 0;
  701. if (!resourceFiles.empty() && (isFrameworkTarget || isBundleTarget))
  702. {
  703. resourceBuildPhase =
  704. this->CreateObject(cmXCodeObject::PBXResourcesBuildPhase);
  705. resourceBuildPhase->SetComment("Resources");
  706. resourceBuildPhase->AddAttribute("buildActionMask",
  707. this->CreateString("2147483647"));
  708. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  709. for(std::vector<cmXCodeObject*>::iterator i = resourceFiles.begin();
  710. i != resourceFiles.end(); ++i)
  711. {
  712. buildFiles->AddObject(*i);
  713. }
  714. resourceBuildPhase->AddAttribute("files", buildFiles);
  715. resourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  716. this->CreateString("0"));
  717. }
  718. // create vector of "non-resource content file" build phases - only for
  719. // framework or bundle targets
  720. std::vector<cmXCodeObject*> contentBuildPhases;
  721. if (isFrameworkTarget || isBundleTarget)
  722. {
  723. typedef std::map<cmStdString, std::vector<cmSourceFile*> >
  724. mapOfVectorOfSourceFiles;
  725. mapOfVectorOfSourceFiles bundleFiles;
  726. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  727. i != classes.end(); ++i)
  728. {
  729. const char* contentLoc = (*i)->GetProperty("MACOSX_PACKAGE_LOCATION");
  730. if ( !contentLoc || cmStdString(contentLoc) == "Resources" )
  731. {
  732. continue;
  733. }
  734. bundleFiles[contentLoc].push_back(*i);
  735. }
  736. mapOfVectorOfSourceFiles::iterator mit;
  737. for ( mit = bundleFiles.begin(); mit != bundleFiles.end(); ++ mit )
  738. {
  739. cmXCodeObject* copyFilesBuildPhase =
  740. this->CreateObject(cmXCodeObject::PBXCopyFilesBuildPhase);
  741. copyFilesBuildPhase->SetComment("Copy files");
  742. copyFilesBuildPhase->AddAttribute("buildActionMask",
  743. this->CreateString("2147483647"));
  744. copyFilesBuildPhase->AddAttribute("dstSubfolderSpec",
  745. this->CreateString("6"));
  746. cmOStringStream ostr;
  747. if ( mit->first != "MacOS" )
  748. {
  749. ostr << "../" << mit->first.c_str();
  750. }
  751. copyFilesBuildPhase->AddAttribute("dstPath",
  752. this->CreateString(ostr.str().c_str()));
  753. copyFilesBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  754. this->CreateString("0"));
  755. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  756. copyFilesBuildPhase->AddAttribute("files", buildFiles);
  757. std::vector<cmSourceFile*>::iterator sfIt;
  758. for ( sfIt = mit->second.begin(); sfIt != mit->second.end(); ++ sfIt )
  759. {
  760. cmXCodeObject* xsf =
  761. this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
  762. *sfIt, cmtarget);
  763. buildFiles->AddObject(xsf);
  764. }
  765. contentBuildPhases.push_back(copyFilesBuildPhase);
  766. }
  767. }
  768. // create framework build phase
  769. cmXCodeObject* frameworkBuildPhase = 0;
  770. if (!externalObjFiles.empty())
  771. {
  772. frameworkBuildPhase =
  773. this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
  774. frameworkBuildPhase->SetComment("Frameworks");
  775. frameworkBuildPhase->AddAttribute("buildActionMask",
  776. this->CreateString("2147483647"));
  777. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  778. frameworkBuildPhase->AddAttribute("files", buildFiles);
  779. for(std::vector<cmXCodeObject*>::iterator i = externalObjFiles.begin();
  780. i != externalObjFiles.end(); ++i)
  781. {
  782. buildFiles->AddObject(*i);
  783. }
  784. frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  785. this->CreateString("0"));
  786. }
  787. // create list of build phases and create the XCode target
  788. cmXCodeObject* buildPhases =
  789. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  790. this->CreateCustomCommands(buildPhases, sourceBuildPhase,
  791. headerBuildPhase, resourceBuildPhase,
  792. contentBuildPhases,
  793. frameworkBuildPhase, cmtarget);
  794. targets.push_back(this->CreateXCodeTarget(cmtarget, buildPhases));
  795. }
  796. }
  797. //----------------------------------------------------------------------------
  798. cmXCodeObject*
  799. cmGlobalXCodeGenerator::CreateBuildPhase(const char* name,
  800. const char* name2,
  801. cmTarget& cmtarget,
  802. const std::vector<cmCustomCommand>&
  803. commands)
  804. {
  805. if(commands.size() == 0 && strcmp(name, "CMake ReRun") != 0)
  806. {
  807. return 0;
  808. }
  809. cmXCodeObject* buildPhase =
  810. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  811. buildPhase->AddAttribute("buildActionMask",
  812. this->CreateString("2147483647"));
  813. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  814. buildPhase->AddAttribute("files", buildFiles);
  815. buildPhase->AddAttribute("name",
  816. this->CreateString(name));
  817. buildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  818. this->CreateString("0"));
  819. buildPhase->AddAttribute("shellPath",
  820. this->CreateString("/bin/sh"));
  821. this->AddCommandsToBuildPhase(buildPhase, cmtarget, commands,
  822. name2);
  823. return buildPhase;
  824. }
  825. //----------------------------------------------------------------------------
  826. void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
  827. cmXCodeObject*
  828. sourceBuildPhase,
  829. cmXCodeObject*
  830. headerBuildPhase,
  831. cmXCodeObject*
  832. resourceBuildPhase,
  833. std::vector<cmXCodeObject*>
  834. contentBuildPhases,
  835. cmXCodeObject*
  836. frameworkBuildPhase,
  837. cmTarget& cmtarget)
  838. {
  839. std::vector<cmCustomCommand> const & prebuild
  840. = cmtarget.GetPreBuildCommands();
  841. std::vector<cmCustomCommand> const & prelink
  842. = cmtarget.GetPreLinkCommands();
  843. std::vector<cmCustomCommand> const & postbuild
  844. = cmtarget.GetPostBuildCommands();
  845. std::vector<cmSourceFile*>const &classes = cmtarget.GetSourceFiles();
  846. // add all the sources
  847. std::vector<cmCustomCommand> commands;
  848. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  849. i != classes.end(); ++i)
  850. {
  851. if((*i)->GetCustomCommand())
  852. {
  853. commands.push_back(*(*i)->GetCustomCommand());
  854. }
  855. }
  856. std::vector<cmCustomCommand> reruncom;
  857. cmXCodeObject* cmakeReRunPhase =
  858. this->CreateBuildPhase("CMake ReRun", "cmakeReRunPhase",
  859. cmtarget, reruncom);
  860. buildPhases->AddObject(cmakeReRunPhase);
  861. // create prebuild phase
  862. cmXCodeObject* cmakeRulesBuildPhase =
  863. this->CreateBuildPhase("CMake Rules",
  864. "cmakeRulesBuildPhase",
  865. cmtarget, commands);
  866. // create prebuild phase
  867. cmXCodeObject* preBuildPhase =
  868. this->CreateBuildPhase("CMake PreBuild Rules", "preBuildCommands",
  869. cmtarget, prebuild);
  870. // create prelink phase
  871. cmXCodeObject* preLinkPhase =
  872. this->CreateBuildPhase("CMake PreLink Rules", "preLinkCommands",
  873. cmtarget, prelink);
  874. // create postbuild phase
  875. cmXCodeObject* postBuildPhase =
  876. this->CreateBuildPhase("CMake PostBuild Rules", "postBuildPhase",
  877. cmtarget, postbuild);
  878. // The order here is the order they will be built in.
  879. // The order "headers, resources, sources" mimics a native project generated
  880. // from an xcode template...
  881. //
  882. if(preBuildPhase)
  883. {
  884. buildPhases->AddObject(preBuildPhase);
  885. }
  886. if(cmakeRulesBuildPhase)
  887. {
  888. buildPhases->AddObject(cmakeRulesBuildPhase);
  889. }
  890. if(headerBuildPhase)
  891. {
  892. buildPhases->AddObject(headerBuildPhase);
  893. }
  894. if(resourceBuildPhase)
  895. {
  896. buildPhases->AddObject(resourceBuildPhase);
  897. }
  898. std::vector<cmXCodeObject*>::iterator cit;
  899. for (cit = contentBuildPhases.begin(); cit != contentBuildPhases.end();
  900. ++cit)
  901. {
  902. buildPhases->AddObject(*cit);
  903. }
  904. if(sourceBuildPhase)
  905. {
  906. buildPhases->AddObject(sourceBuildPhase);
  907. }
  908. if(preLinkPhase)
  909. {
  910. buildPhases->AddObject(preLinkPhase);
  911. }
  912. if(frameworkBuildPhase)
  913. {
  914. buildPhases->AddObject(frameworkBuildPhase);
  915. }
  916. if(postBuildPhase)
  917. {
  918. buildPhases->AddObject(postBuildPhase);
  919. }
  920. }
  921. //----------------------------------------------------------------------------
  922. std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
  923. std::string& flags)
  924. {
  925. std::string retFlag;
  926. std::string::size_type pos = flags.find(flag);
  927. if(pos != flags.npos)
  928. {
  929. while(pos < flags.size() && flags[pos] != ' ')
  930. {
  931. retFlag += flags[pos];
  932. flags[pos] = ' ';
  933. pos++;
  934. }
  935. }
  936. return retFlag;
  937. }
  938. //----------------------------------------------------------------------------
  939. void
  940. cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  941. cmTarget& target,
  942. std::vector<cmCustomCommand>
  943. const & commands,
  944. const char* name)
  945. {
  946. if(strcmp(name, "cmakeReRunPhase") == 0)
  947. {
  948. std::string cdir = this->CurrentMakefile->GetHomeOutputDirectory();
  949. cdir = this->ConvertToRelativeForMake(cdir.c_str());
  950. std::string makecmd = "make -C ";
  951. makecmd += cdir;
  952. makecmd += " -f ";
  953. makecmd +=
  954. this->ConvertToRelativeForMake(this->CurrentReRunCMakeMakefile.c_str());
  955. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  956. buildphase->AddAttribute("shellScript",
  957. this->CreateString(makecmd.c_str()));
  958. return;
  959. }
  960. // collect multiple outputs of custom commands into a set
  961. // which will be used for every configuration
  962. std::map<cmStdString, cmStdString> multipleOutputPairs;
  963. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  964. i != commands.end(); ++i)
  965. {
  966. cmCustomCommand const& cc = *i;
  967. if(!cc.GetCommandLines().empty())
  968. {
  969. const std::vector<std::string>& outputs = cc.GetOutputs();
  970. if(!outputs.empty())
  971. {
  972. // If there are more than one outputs treat the
  973. // first as the primary output and make the rest depend on it.
  974. std::vector<std::string>::const_iterator o = outputs.begin();
  975. std::string primaryOutput = this->ConvertToRelativeForMake(o->c_str());
  976. for(++o; o != outputs.end(); ++o)
  977. {
  978. std::string currentOutput=this->ConvertToRelativeForMake(o->c_str());
  979. multipleOutputPairs[currentOutput] = primaryOutput;
  980. }
  981. }
  982. }
  983. }
  984. std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory();
  985. dir += "/CMakeScripts";
  986. cmSystemTools::MakeDirectory(dir.c_str());
  987. std::string makefile = dir;
  988. makefile += "/";
  989. makefile += target.GetName();
  990. makefile += "_";
  991. makefile += name;
  992. makefile += ".make";
  993. for (std::vector<std::string>::const_iterator currentConfig=
  994. this->CurrentConfigurationTypes.begin();
  995. currentConfig!=this->CurrentConfigurationTypes.end();
  996. currentConfig++ )
  997. {
  998. this->CreateCustomRulesMakefile(makefile.c_str(),
  999. target,
  1000. commands,
  1001. currentConfig->c_str(),
  1002. multipleOutputPairs);
  1003. }
  1004. std::string cdir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1005. cdir = this->ConvertToRelativeForXCode(cdir.c_str());
  1006. std::string makecmd = "make -C ";
  1007. makecmd += cdir;
  1008. makecmd += " -f ";
  1009. makecmd += this->ConvertToRelativeForMake(
  1010. (makefile+"$CONFIGURATION").c_str());
  1011. if(!multipleOutputPairs.empty())
  1012. {
  1013. makecmd += " cmake_check_multiple_outputs";
  1014. }
  1015. makecmd += " all";
  1016. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  1017. buildphase->AddAttribute("shellScript",
  1018. this->CreateString(makecmd.c_str()));
  1019. }
  1020. //----------------------------------------------------------------------------
  1021. void cmGlobalXCodeGenerator
  1022. ::CreateCustomRulesMakefile(const char* makefileBasename,
  1023. cmTarget& target,
  1024. std::vector<cmCustomCommand>
  1025. const & commands,
  1026. const char* configName,
  1027. const std::map<cmStdString,
  1028. cmStdString>& multipleOutputPairs
  1029. )
  1030. {
  1031. std::string makefileName=makefileBasename;
  1032. makefileName+=configName;
  1033. cmGeneratedFileStream makefileStream(makefileName.c_str());
  1034. if(!makefileStream)
  1035. {
  1036. return;
  1037. }
  1038. makefileStream.SetCopyIfDifferent(true);
  1039. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  1040. makefileStream << "# Custom rules for " << target.GetName() << "\n";
  1041. // have all depend on all outputs
  1042. makefileStream << "all: ";
  1043. std::map<const cmCustomCommand*, cmStdString> tname;
  1044. int count = 0;
  1045. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1046. i != commands.end(); ++i)
  1047. {
  1048. cmCustomCommand const& cc = *i;
  1049. if(!cc.GetCommandLines().empty())
  1050. {
  1051. const std::vector<std::string>& outputs = cc.GetOutputs();
  1052. if(!outputs.empty())
  1053. {
  1054. for(std::vector<std::string>::const_iterator o = outputs.begin();
  1055. o != outputs.end(); ++o)
  1056. {
  1057. makefileStream
  1058. << "\\\n\t" << this->ConvertToRelativeForMake(o->c_str());
  1059. }
  1060. }
  1061. else
  1062. {
  1063. cmOStringStream str;
  1064. str << "_buildpart_" << count++ ;
  1065. tname[&cc] = std::string(target.GetName()) + str.str();
  1066. makefileStream << "\\\n\t" << tname[&cc];
  1067. }
  1068. }
  1069. }
  1070. makefileStream << "\n\n";
  1071. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1072. i != commands.end(); ++i)
  1073. {
  1074. cmCustomCommand const& cc = *i;
  1075. if(!cc.GetCommandLines().empty())
  1076. {
  1077. bool escapeOldStyle = cc.GetEscapeOldStyle();
  1078. bool escapeAllowMakeVars = cc.GetEscapeAllowMakeVars();
  1079. makefileStream << "\n#" << "Custom command rule: ";
  1080. if(cc.GetComment())
  1081. {
  1082. makefileStream << cc.GetComment();
  1083. }
  1084. makefileStream << "\n";
  1085. const std::vector<std::string>& outputs = cc.GetOutputs();
  1086. if(!outputs.empty())
  1087. {
  1088. // There is at least one output, start the rule for it
  1089. std::string primary_output =
  1090. this->ConvertToRelativeForMake(outputs.begin()->c_str());
  1091. makefileStream << primary_output << ": ";
  1092. }
  1093. else
  1094. {
  1095. // There are no outputs. Use the generated force rule name.
  1096. makefileStream << tname[&cc] << ": ";
  1097. }
  1098. for(std::vector<std::string>::const_iterator d =
  1099. cc.GetDepends().begin();
  1100. d != cc.GetDepends().end(); ++d)
  1101. {
  1102. std::string dep =
  1103. this->CurrentLocalGenerator->GetRealDependency(d->c_str(),
  1104. configName);
  1105. makefileStream << "\\\n" << this
  1106. ->ConvertToRelativeForMake(dep.c_str());
  1107. }
  1108. makefileStream << "\n";
  1109. // Add each command line to the set of commands.
  1110. for(cmCustomCommandLines::const_iterator cl =
  1111. cc.GetCommandLines().begin();
  1112. cl != cc.GetCommandLines().end(); ++cl)
  1113. {
  1114. // Build the command line in a single string.
  1115. const cmCustomCommandLine& commandLine = *cl;
  1116. std::string cmd2 = this->CurrentLocalGenerator
  1117. ->GetRealLocation(commandLine[0].c_str(), configName);
  1118. cmSystemTools::ReplaceString(cmd2, "/./", "/");
  1119. cmd2 = this->ConvertToRelativeForMake(cmd2.c_str());
  1120. std::string cmd;
  1121. if(cc.GetWorkingDirectory())
  1122. {
  1123. cmd += "cd ";
  1124. cmd += this->ConvertToRelativeForMake(cc.GetWorkingDirectory());
  1125. cmd += " && ";
  1126. }
  1127. cmd += cmd2;
  1128. for(unsigned int j=1; j < commandLine.size(); ++j)
  1129. {
  1130. cmd += " ";
  1131. if(escapeOldStyle)
  1132. {
  1133. cmd += (this->CurrentLocalGenerator
  1134. ->EscapeForShellOldStyle(commandLine[j].c_str()));
  1135. }
  1136. else
  1137. {
  1138. cmd += (this->CurrentLocalGenerator->
  1139. EscapeForShell(commandLine[j].c_str(),
  1140. escapeAllowMakeVars));
  1141. }
  1142. }
  1143. makefileStream << "\t" << cmd.c_str() << "\n";
  1144. }
  1145. }
  1146. }
  1147. // Add rules to deal with multiple outputs of custom commands.
  1148. if(!multipleOutputPairs.empty())
  1149. {
  1150. makefileStream <<
  1151. "\n# Dependencies of multiple outputs to their primary outputs \n";
  1152. for(std::map<cmStdString, cmStdString>::const_iterator o =
  1153. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1154. {
  1155. makefileStream << o->first << ": " << o->second << "\n";
  1156. }
  1157. makefileStream <<
  1158. "\n"
  1159. "cmake_check_multiple_outputs:\n";
  1160. for(std::map<cmStdString, cmStdString>::const_iterator o =
  1161. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1162. {
  1163. makefileStream << "\t@if [ ! -f "
  1164. << o->first << " ]; then rm -f "
  1165. << o->second << "; fi\n";
  1166. }
  1167. }
  1168. }
  1169. //----------------------------------------------------------------------------
  1170. void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
  1171. cmXCodeObject* buildSettings,
  1172. std::string& fileType,
  1173. std::string& productType,
  1174. std::string& productName,
  1175. const char* configName)
  1176. {
  1177. std::string flags;
  1178. std::string defFlags;
  1179. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  1180. (target.GetType() == cmTarget::MODULE_LIBRARY));
  1181. // Add the export symbol definition for shared library objects.
  1182. if(const char* exportMacro = target.GetExportMacro())
  1183. {
  1184. defFlags += "-D";
  1185. defFlags += exportMacro;
  1186. }
  1187. const char* lang = target.GetLinkerLanguage(this);
  1188. std::string cflags;
  1189. if(lang)
  1190. {
  1191. // for c++ projects get the c flags as well
  1192. if(strcmp(lang, "CXX") == 0)
  1193. {
  1194. this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName);
  1195. this->CurrentLocalGenerator->AddSharedFlags(cflags, lang, shared);
  1196. }
  1197. // Add language-specific flags.
  1198. this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName);
  1199. // Add shared-library flags if needed.
  1200. this->CurrentLocalGenerator->AddSharedFlags(flags, lang, shared);
  1201. }
  1202. // Add define flags
  1203. this->CurrentLocalGenerator->
  1204. AppendFlags(defFlags,
  1205. this->CurrentMakefile->GetDefineFlags());
  1206. cmSystemTools::ReplaceString(defFlags, "\"", "\\\"");
  1207. cmSystemTools::ReplaceString(flags, "\"", "\\\"");
  1208. cmSystemTools::ReplaceString(cflags, "\"", "\\\"");
  1209. if(this->XcodeVersion > 15)
  1210. {
  1211. buildSettings->AddAttribute
  1212. ("GCC_PREPROCESSOR_DEFINITIONS",
  1213. this->CreateString("CMAKE_INTDIR=\\\\\"$(CONFIGURATION)\\\\\""));
  1214. }
  1215. std::string extraLinkOptions;
  1216. if(target.GetType() == cmTarget::EXECUTABLE)
  1217. {
  1218. extraLinkOptions =
  1219. this->CurrentMakefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
  1220. }
  1221. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  1222. {
  1223. extraLinkOptions = this->CurrentMakefile->
  1224. GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
  1225. }
  1226. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  1227. {
  1228. extraLinkOptions = this->CurrentMakefile->
  1229. GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
  1230. }
  1231. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1232. if(targetLinkFlags)
  1233. {
  1234. extraLinkOptions += " ";
  1235. extraLinkOptions += targetLinkFlags;
  1236. }
  1237. // The product name is the full name of the target for this configuration.
  1238. productName = target.GetFullName(configName);
  1239. // Get the product name components.
  1240. std::string pnprefix;
  1241. std::string pnbase;
  1242. std::string pnsuffix;
  1243. target.GetFullName(pnprefix, pnbase, pnsuffix, configName);
  1244. // Store the product name for all target types.
  1245. buildSettings->AddAttribute("PRODUCT_NAME",
  1246. this->CreateString(pnbase.c_str()));
  1247. // Set attributes to specify the proper name for the target.
  1248. if(target.GetType() == cmTarget::STATIC_LIBRARY ||
  1249. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1250. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1251. target.GetType() == cmTarget::EXECUTABLE)
  1252. {
  1253. std::string pndir = target.GetDirectory();
  1254. if (target.GetType() == cmTarget::SHARED_LIBRARY &&
  1255. target.GetPropertyAsBool("FRAMEWORK"))
  1256. {
  1257. pndir += "/..";
  1258. pndir = cmSystemTools::CollapseFullPath(pndir.c_str());
  1259. }
  1260. buildSettings->AddAttribute("SYMROOT",
  1261. this->CreateString(pndir.c_str()));
  1262. buildSettings->AddAttribute("EXECUTABLE_PREFIX",
  1263. this->CreateString(pnprefix.c_str()));
  1264. buildSettings->AddAttribute("EXECUTABLE_SUFFIX",
  1265. this->CreateString(pnsuffix.c_str()));
  1266. }
  1267. // Handle settings for each target type.
  1268. switch(target.GetType())
  1269. {
  1270. case cmTarget::STATIC_LIBRARY:
  1271. {
  1272. fileType = "archive.ar";
  1273. productType = "com.apple.product-type.library.static";
  1274. buildSettings->AddAttribute("LIBRARY_STYLE",
  1275. this->CreateString("STATIC"));
  1276. break;
  1277. }
  1278. case cmTarget::MODULE_LIBRARY:
  1279. {
  1280. buildSettings->AddAttribute("LIBRARY_STYLE",
  1281. this->CreateString("BUNDLE"));
  1282. if(this->XcodeVersion >= 22)
  1283. {
  1284. fileType = "compiled.mach-o.executable";
  1285. productType = "com.apple.product-type.tool";
  1286. buildSettings->AddAttribute("MACH_O_TYPE",
  1287. this->CreateString("mh_bundle"));
  1288. buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
  1289. this->CreateString("NO"));
  1290. // Add the flags to create an executable.
  1291. std::string createFlags =
  1292. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1293. if(!createFlags.empty())
  1294. {
  1295. extraLinkOptions += " ";
  1296. extraLinkOptions += createFlags;
  1297. }
  1298. }
  1299. else
  1300. {
  1301. fileType = "compiled.mach-o.dylib";
  1302. productType = "com.apple.product-type.library.dynamic";
  1303. // Add the flags to create a module.
  1304. std::string createFlags =
  1305. this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
  1306. "-bundle");
  1307. if(!createFlags.empty())
  1308. {
  1309. extraLinkOptions += " ";
  1310. extraLinkOptions += createFlags;
  1311. }
  1312. }
  1313. break;
  1314. }
  1315. case cmTarget::SHARED_LIBRARY:
  1316. {
  1317. if(target.GetPropertyAsBool("FRAMEWORK"))
  1318. {
  1319. fileType = "wrapper.framework";
  1320. productType = "com.apple.product-type.framework";
  1321. const char* version = target.GetProperty("FRAMEWORK_VERSION");
  1322. buildSettings->AddAttribute("FRAMEWORK_VERSION",
  1323. this->CreateString(version));
  1324. }
  1325. else
  1326. {
  1327. fileType = "compiled.mach-o.dylib";
  1328. productType = "com.apple.product-type.library.dynamic";
  1329. // Add the flags to create a shared library.
  1330. std::string createFlags =
  1331. this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", lang, "_FLAGS",
  1332. "-dynamiclib");
  1333. if(!createFlags.empty())
  1334. {
  1335. extraLinkOptions += " ";
  1336. extraLinkOptions += createFlags;
  1337. }
  1338. }
  1339. buildSettings->AddAttribute("LIBRARY_STYLE",
  1340. this->CreateString("DYNAMIC"));
  1341. buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
  1342. this->CreateString("1"));
  1343. buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
  1344. this->CreateString("1"));
  1345. break;
  1346. }
  1347. case cmTarget::EXECUTABLE:
  1348. {
  1349. fileType = "compiled.mach-o.executable";
  1350. // Add the flags to create an executable.
  1351. std::string createFlags =
  1352. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1353. if(!createFlags.empty())
  1354. {
  1355. extraLinkOptions += " ";
  1356. extraLinkOptions += createFlags;
  1357. }
  1358. // Handle bundles and normal executables separately.
  1359. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  1360. {
  1361. productType = "com.apple.product-type.application";
  1362. std::string f1 =
  1363. this->CurrentMakefile->GetModulesFile("MacOSXBundleInfo.plist.in");
  1364. if ( f1.size() == 0 )
  1365. {
  1366. cmSystemTools::Error("could not find Mac OSX bundle template file.");
  1367. }
  1368. std::string f2 = this->CurrentMakefile->GetCurrentOutputDirectory();
  1369. f2 += "/Info.plist";
  1370. this->CurrentMakefile->ConfigureFile(f1.c_str(), f2.c_str(),
  1371. false, false, false);
  1372. std::string path =
  1373. this->ConvertToRelativeForXCode(f2.c_str());
  1374. buildSettings->AddAttribute("INFOPLIST_FILE",
  1375. this->CreateString(path.c_str()));
  1376. }
  1377. else
  1378. {
  1379. productType = "com.apple.product-type.tool";
  1380. }
  1381. }
  1382. break;
  1383. default:
  1384. break;
  1385. }
  1386. if(this->XcodeVersion >= 22)
  1387. {
  1388. buildSettings->AddAttribute("PREBINDING",
  1389. this->CreateString("NO"));
  1390. }
  1391. std::string dirs;
  1392. std::vector<std::string> includes;
  1393. this->CurrentLocalGenerator->GetIncludeDirectories(includes);
  1394. std::vector<std::string>::iterator i = includes.begin();
  1395. std::string fdirs;
  1396. std::set<cmStdString> emitted;
  1397. emitted.insert("/System/Library/Frameworks");
  1398. for(;i != includes.end(); ++i)
  1399. {
  1400. if(cmSystemTools::IsPathToFramework(i->c_str()))
  1401. {
  1402. std::string frameworkDir = *i;
  1403. frameworkDir += "/../";
  1404. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1405. if(emitted.insert(frameworkDir).second)
  1406. {
  1407. fdirs += this->XCodeEscapePath(frameworkDir.c_str());
  1408. fdirs += " ";
  1409. }
  1410. }
  1411. else
  1412. {
  1413. std::string incpath =
  1414. this->XCodeEscapePath(i->c_str());
  1415. dirs += incpath + " ";
  1416. }
  1417. }
  1418. std::vector<std::string>& frameworks = target.GetFrameworks();
  1419. if(frameworks.size())
  1420. {
  1421. for(std::vector<std::string>::iterator fmIt = frameworks.begin();
  1422. fmIt != frameworks.end(); ++fmIt)
  1423. {
  1424. if(emitted.insert(*fmIt).second)
  1425. {
  1426. fdirs += this->XCodeEscapePath(fmIt->c_str());
  1427. fdirs += " ";
  1428. }
  1429. }
  1430. }
  1431. if(fdirs.size())
  1432. {
  1433. buildSettings->AddAttribute("FRAMEWORK_SEARCH_PATHS",
  1434. this->CreateString(fdirs.c_str()));
  1435. }
  1436. if(dirs.size())
  1437. {
  1438. buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
  1439. this->CreateString(dirs.c_str()));
  1440. }
  1441. std::string oflagc = this->ExtractFlag("-O", cflags);
  1442. char optLevel[2];
  1443. optLevel[0] = '0';
  1444. optLevel[1] = 0;
  1445. if(oflagc.size() == 3)
  1446. {
  1447. optLevel[0] = oflagc[2];
  1448. }
  1449. if(oflagc.size() == 2)
  1450. {
  1451. optLevel[0] = '1';
  1452. }
  1453. std::string oflag = this->ExtractFlag("-O", flags);
  1454. if(oflag.size() == 3)
  1455. {
  1456. optLevel[0] = oflag[2];
  1457. }
  1458. if(oflag.size() == 2)
  1459. {
  1460. optLevel[0] = '1';
  1461. }
  1462. std::string gflagc = this->ExtractFlag("-g", cflags);
  1463. // put back gdwarf-2 if used since there is no way
  1464. // to represent it in the gui, but we still want debug yes
  1465. if(gflagc == "-gdwarf-2")
  1466. {
  1467. cflags += " ";
  1468. cflags += gflagc;
  1469. }
  1470. std::string gflag = this->ExtractFlag("-g", flags);
  1471. if(gflag == "-gdwarf-2")
  1472. {
  1473. flags += " ";
  1474. flags += gflag;
  1475. }
  1476. const char* debugStr = "YES";
  1477. if(gflagc.size() ==0 && gflag.size() == 0)
  1478. {
  1479. debugStr = "NO";
  1480. }
  1481. buildSettings->AddAttribute("GCC_GENERATE_DEBUGGING_SYMBOLS",
  1482. this->CreateString(debugStr));
  1483. buildSettings->AddAttribute("GCC_OPTIMIZATION_LEVEL",
  1484. this->CreateString(optLevel));
  1485. buildSettings->AddAttribute("OPTIMIZATION_CFLAGS",
  1486. this->CreateString(oflagc.c_str()));
  1487. buildSettings->AddAttribute("GCC_SYMBOLS_PRIVATE_EXTERN",
  1488. this->CreateString("NO"));
  1489. buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
  1490. this->CreateString("NO"));
  1491. if(lang && strcmp(lang, "CXX") == 0)
  1492. {
  1493. flags += " ";
  1494. flags += defFlags;
  1495. buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
  1496. this->CreateString(flags.c_str()));
  1497. cflags += " ";
  1498. cflags += defFlags;
  1499. buildSettings->AddAttribute("OTHER_CFLAGS",
  1500. this->CreateString(cflags.c_str()));
  1501. }
  1502. else
  1503. {
  1504. flags += " ";
  1505. flags += defFlags;
  1506. buildSettings->AddAttribute("OTHER_CFLAGS",
  1507. this->CreateString(flags.c_str()));
  1508. }
  1509. // Create the INSTALL_PATH attribute.
  1510. std::string install_name_dir;
  1511. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  1512. {
  1513. // Get the install_name directory for the build tree.
  1514. install_name_dir = target.GetInstallNameDirForBuildTree(configName);
  1515. if(target.GetPropertyAsBool("FRAMEWORK"))
  1516. {
  1517. if(install_name_dir.find(".framework") != install_name_dir.npos)
  1518. {
  1519. install_name_dir = install_name_dir + "/..";
  1520. install_name_dir =
  1521. cmSystemTools::CollapseFullPath(install_name_dir.c_str());
  1522. //std::cerr << "new install name " << install_name_dir << "\n";
  1523. }
  1524. }
  1525. if(install_name_dir.empty())
  1526. {
  1527. // Xcode will not pass the -install_name option at all if INSTALL_PATH
  1528. // is not given or is empty. We must explicitly put the flag in the
  1529. // link flags to create an install_name with just the library soname.
  1530. extraLinkOptions += " -install_name ";
  1531. extraLinkOptions += productName;
  1532. }
  1533. else
  1534. {
  1535. // Convert to a path for the native build tool.
  1536. cmSystemTools::ConvertToUnixSlashes(install_name_dir);
  1537. // do not escape spaces on this since it is only a single path
  1538. }
  1539. }
  1540. buildSettings->AddAttribute("INSTALL_PATH",
  1541. this->CreateString(install_name_dir.c_str()));
  1542. buildSettings->AddAttribute("OTHER_LDFLAGS",
  1543. this->CreateString(extraLinkOptions.c_str()));
  1544. buildSettings->AddAttribute("OTHER_REZFLAGS",
  1545. this->CreateString(""));
  1546. buildSettings->AddAttribute("SECTORDER_FLAGS",
  1547. this->CreateString(""));
  1548. buildSettings->AddAttribute("USE_HEADERMAP",
  1549. this->CreateString("NO"));
  1550. buildSettings->AddAttribute("WARNING_CFLAGS",
  1551. this->CreateString(
  1552. "-Wmost -Wno-four-char-constants"
  1553. " -Wno-unknown-pragmas"));
  1554. }
  1555. //----------------------------------------------------------------------------
  1556. cmXCodeObject*
  1557. cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
  1558. {
  1559. cmXCodeObject* shellBuildPhase =
  1560. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  1561. shellBuildPhase->AddAttribute("buildActionMask",
  1562. this->CreateString("2147483647"));
  1563. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1564. shellBuildPhase->AddAttribute("files", buildFiles);
  1565. cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1566. shellBuildPhase->AddAttribute("inputPaths", inputPaths);
  1567. cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1568. shellBuildPhase->AddAttribute("outputPaths", outputPaths);
  1569. shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1570. this->CreateString("0"));
  1571. shellBuildPhase->AddAttribute("shellPath",
  1572. this->CreateString("/bin/sh"));
  1573. shellBuildPhase->AddAttribute("shellScript",
  1574. this->CreateString(
  1575. "# shell script goes here\nexit 0"));
  1576. cmXCodeObject* target =
  1577. this->CreateObject(cmXCodeObject::PBXAggregateTarget);
  1578. target->SetComment(cmtarget.GetName());
  1579. cmXCodeObject* buildPhases =
  1580. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1581. std::vector<cmXCodeObject*> emptyContentVector;
  1582. this->CreateCustomCommands(buildPhases, 0, 0, 0, emptyContentVector, 0,
  1583. cmtarget);
  1584. target->AddAttribute("buildPhases", buildPhases);
  1585. cmXCodeObject* buildSettings =
  1586. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1587. std::string fileTypeString;
  1588. std::string productTypeString;
  1589. std::string productName;
  1590. const char* globalConfig = 0;
  1591. if(this->XcodeVersion > 20)
  1592. {
  1593. this->AddConfigurations(target, cmtarget);
  1594. }
  1595. else
  1596. {
  1597. globalConfig = this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
  1598. }
  1599. this->CreateBuildSettings(cmtarget,
  1600. buildSettings, fileTypeString,
  1601. productTypeString, productName, globalConfig);
  1602. target->AddAttribute("buildSettings", buildSettings);
  1603. cmXCodeObject* dependencies =
  1604. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1605. target->AddAttribute("dependencies", dependencies);
  1606. target->AddAttribute("name", this->CreateString(productName.c_str()));
  1607. target->AddAttribute("productName",this->CreateString(productName.c_str()));
  1608. target->SetTarget(&cmtarget);
  1609. return target;
  1610. }
  1611. //----------------------------------------------------------------------------
  1612. void cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
  1613. cmTarget& cmtarget)
  1614. {
  1615. std::string configTypes =
  1616. this->CurrentMakefile->GetRequiredDefinition("CMAKE_CONFIGURATION_TYPES");
  1617. std::vector<std::string> configVectorIn;
  1618. std::vector<std::string> configVector;
  1619. configVectorIn.push_back(configTypes);
  1620. cmSystemTools::ExpandList(configVectorIn, configVector);
  1621. cmXCodeObject* configlist =
  1622. this->CreateObject(cmXCodeObject::XCConfigurationList);
  1623. cmXCodeObject* buildConfigurations =
  1624. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1625. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  1626. std::string comment = "Build configuration list for ";
  1627. comment += cmXCodeObject::PBXTypeNames[target->GetIsA()];
  1628. comment += " \"";
  1629. comment += cmtarget.GetName();
  1630. comment += "\"";
  1631. configlist->SetComment(comment.c_str());
  1632. target->AddAttribute("buildConfigurationList",
  1633. this->CreateObjectReference(configlist));
  1634. for(unsigned int i = 0; i < configVector.size(); ++i)
  1635. {
  1636. cmXCodeObject* config =
  1637. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  1638. buildConfigurations->AddObject(config);
  1639. cmXCodeObject* buildSettings =
  1640. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1641. std::string fileTypeString;
  1642. std::string productTypeString;
  1643. std::string productName;
  1644. this->CreateBuildSettings(cmtarget,
  1645. buildSettings, fileTypeString,
  1646. productTypeString, productName,
  1647. configVector[i].c_str());
  1648. config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
  1649. config->SetComment(configVector[i].c_str());
  1650. config->AddAttribute("buildSettings", buildSettings);
  1651. }
  1652. if(configVector.size())
  1653. {
  1654. configlist->AddAttribute("defaultConfigurationName",
  1655. this->CreateString(configVector[0].c_str()));
  1656. configlist->AddAttribute("defaultConfigurationIsVisible",
  1657. this->CreateString("0"));
  1658. }
  1659. }
  1660. //----------------------------------------------------------------------------
  1661. cmXCodeObject*
  1662. cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
  1663. cmXCodeObject* buildPhases)
  1664. {
  1665. cmXCodeObject* target =
  1666. this->CreateObject(cmXCodeObject::PBXNativeTarget);
  1667. target->AddAttribute("buildPhases", buildPhases);
  1668. cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1669. target->AddAttribute("buildRules", buildRules);
  1670. cmXCodeObject* buildSettings =
  1671. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1672. std::string fileTypeString;
  1673. std::string productTypeString;
  1674. std::string productName;
  1675. const char* globalConfig = 0;
  1676. if(this->XcodeVersion > 20)
  1677. {
  1678. this->AddConfigurations(target, cmtarget);
  1679. }
  1680. else
  1681. {
  1682. globalConfig = this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
  1683. }
  1684. this->CreateBuildSettings(cmtarget,
  1685. buildSettings, fileTypeString,
  1686. productTypeString, productName, globalConfig);
  1687. target->AddAttribute("buildSettings", buildSettings);
  1688. cmXCodeObject* dependencies =
  1689. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1690. target->AddAttribute("dependencies", dependencies);
  1691. target->AddAttribute("name", this->CreateString(productName.c_str()));
  1692. target->AddAttribute("productName",this->CreateString(productName.c_str()));
  1693. cmXCodeObject* fileRef =
  1694. this->CreateObject(cmXCodeObject::PBXFileReference);
  1695. fileRef->AddAttribute("explicitFileType",
  1696. this->CreateString(fileTypeString.c_str()));
  1697. fileRef->AddAttribute("path", this->CreateString(productName.c_str()));
  1698. fileRef->AddAttribute("refType", this->CreateString("0"));
  1699. fileRef->AddAttribute("sourceTree",
  1700. this->CreateString("BUILT_PRODUCTS_DIR"));
  1701. fileRef->SetComment(cmtarget.GetName());
  1702. target->AddAttribute("productReference",
  1703. this->CreateObjectReference(fileRef));
  1704. target->AddAttribute("productType",
  1705. this->CreateString(productTypeString.c_str()));
  1706. target->SetTarget(&cmtarget);
  1707. return target;
  1708. }
  1709. //----------------------------------------------------------------------------
  1710. cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
  1711. {
  1712. if(!t)
  1713. {
  1714. return 0;
  1715. }
  1716. for(std::vector<cmXCodeObject*>::iterator i = this->XCodeObjects.begin();
  1717. i != this->XCodeObjects.end(); ++i)
  1718. {
  1719. cmXCodeObject* o = *i;
  1720. if(o->GetTarget() == t)
  1721. {
  1722. return o;
  1723. }
  1724. }
  1725. return 0;
  1726. }
  1727. //----------------------------------------------------------------------------
  1728. void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
  1729. cmXCodeObject* dependTarget)
  1730. {
  1731. // make sure a target does not depend on itself
  1732. if(target == dependTarget)
  1733. {
  1734. return;
  1735. }
  1736. // now avoid circular references if dependTarget already
  1737. // depends on target then skip it. Circular references crashes
  1738. // xcode
  1739. cmXCodeObject* dependTargetDepends =
  1740. dependTarget->GetObject("dependencies");
  1741. if(dependTargetDepends)
  1742. {
  1743. if(dependTargetDepends->HasObject(target->GetPBXTargetDependency()))
  1744. {
  1745. return;
  1746. }
  1747. }
  1748. cmXCodeObject* targetdep = dependTarget->GetPBXTargetDependency();
  1749. if(!targetdep)
  1750. {
  1751. cmXCodeObject* container =
  1752. this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
  1753. container->SetComment("PBXContainerItemProxy");
  1754. container->AddAttribute("containerPortal",
  1755. this->CreateObjectReference(this->RootObject));
  1756. container->AddAttribute("proxyType", this->CreateString("1"));
  1757. container->AddAttribute("remoteGlobalIDString",
  1758. this->CreateObjectReference(dependTarget));
  1759. container->AddAttribute("remoteInfo",
  1760. this->CreateString(
  1761. dependTarget->GetTarget()->GetName()));
  1762. targetdep =
  1763. this->CreateObject(cmXCodeObject::PBXTargetDependency);
  1764. targetdep->SetComment("PBXTargetDependency");
  1765. targetdep->AddAttribute("target",
  1766. this->CreateObjectReference(dependTarget));
  1767. targetdep->AddAttribute("targetProxy",
  1768. this->CreateObjectReference(container));
  1769. dependTarget->SetPBXTargetDependency(targetdep);
  1770. }
  1771. cmXCodeObject* depends = target->GetObject("dependencies");
  1772. if(!depends)
  1773. {
  1774. cmSystemTools::
  1775. Error("target does not have dependencies attribute error..");
  1776. }
  1777. else
  1778. {
  1779. depends->AddUniqueObject(targetdep);
  1780. }
  1781. }
  1782. //----------------------------------------------------------------------------
  1783. void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings,
  1784. const char* attribute,
  1785. const char* value)
  1786. {
  1787. if(settings)
  1788. {
  1789. cmXCodeObject* attr = settings->GetObject(attribute);
  1790. if(!attr)
  1791. {
  1792. settings->AddAttribute(attribute, this->CreateString(value));
  1793. }
  1794. else
  1795. {
  1796. std::string oldValue = attr->GetString();
  1797. cmSystemTools::ReplaceString(oldValue, "\"", "");
  1798. oldValue += " ";
  1799. oldValue += value;
  1800. attr->SetString(oldValue.c_str());
  1801. }
  1802. }
  1803. }
  1804. //----------------------------------------------------------------------------
  1805. void cmGlobalXCodeGenerator
  1806. ::AppendBuildSettingAttribute(cmXCodeObject* target,
  1807. const char* attribute,
  1808. const char* value,
  1809. const char* configName)
  1810. {
  1811. if(this->XcodeVersion < 21)
  1812. {
  1813. // There is only one configuration. Add the setting to the buildSettings
  1814. // of the target.
  1815. this->AppendOrAddBuildSetting(target->GetObject("buildSettings"),
  1816. attribute, value);
  1817. }
  1818. else
  1819. {
  1820. // There are multiple configurations. Add the setting to the
  1821. // buildSettings of the configuration name given.
  1822. cmXCodeObject* configurationList =
  1823. target->GetObject("buildConfigurationList")->GetObject();
  1824. cmXCodeObject* buildConfigs =
  1825. configurationList->GetObject("buildConfigurations");
  1826. std::vector<cmXCodeObject*> list = buildConfigs->GetObjectList();
  1827. // each configuration and the target itself has a buildSettings in it
  1828. //list.push_back(target);
  1829. for(std::vector<cmXCodeObject*>::iterator i = list.begin();
  1830. i != list.end(); ++i)
  1831. {
  1832. if(configName)
  1833. {
  1834. if(strcmp((*i)->GetObject("name")->GetString(), configName) == 0)
  1835. {
  1836. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  1837. this->AppendOrAddBuildSetting(settings, attribute, value);
  1838. }
  1839. }
  1840. else
  1841. {
  1842. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  1843. this->AppendOrAddBuildSetting(settings, attribute, value);
  1844. }
  1845. }
  1846. }
  1847. }
  1848. //----------------------------------------------------------------------------
  1849. void cmGlobalXCodeGenerator
  1850. ::AddDependAndLinkInformation(cmXCodeObject* target)
  1851. {
  1852. cmTarget* cmtarget = target->GetTarget();
  1853. if(!cmtarget)
  1854. {
  1855. cmSystemTools::Error("Error no target on xobject\n");
  1856. return;
  1857. }
  1858. // Add dependencies on other CMake targets.
  1859. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  1860. {
  1861. // Keep track of dependencies already listed.
  1862. std::set<cmStdString> emitted;
  1863. // A target should not depend on itself.
  1864. emitted.insert(cmtarget->GetName());
  1865. // Loop over all library dependencies.
  1866. const cmTarget::LinkLibraryVectorType& tlibs =
  1867. cmtarget->GetLinkLibraries();
  1868. for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
  1869. lib != tlibs.end(); ++lib)
  1870. {
  1871. // Don't emit the same library twice for this target.
  1872. if(emitted.insert(lib->first).second)
  1873. {
  1874. // Add this dependency.
  1875. cmTarget* t = this->FindTarget(this->CurrentProject.c_str(),
  1876. lib->first.c_str(), false);
  1877. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  1878. if(dptarget)
  1879. {
  1880. this->AddDependTarget(target, dptarget);
  1881. }
  1882. }
  1883. }
  1884. }
  1885. // write utility dependencies.
  1886. for(std::set<cmStdString>::const_iterator i
  1887. = cmtarget->GetUtilities().begin();
  1888. i != cmtarget->GetUtilities().end(); ++i)
  1889. {
  1890. cmTarget* t = this->FindTarget(this->CurrentProject.c_str(),
  1891. i->c_str(), false);
  1892. // if the target is in this project then make target depend
  1893. // on it. It may not be in this project if this is a sub
  1894. // project from the top.
  1895. if(t)
  1896. {
  1897. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  1898. if(dptarget)
  1899. {
  1900. this->AddDependTarget(target, dptarget);
  1901. }
  1902. else
  1903. {
  1904. std::string m = "Error Utility: ";
  1905. m += i->c_str();
  1906. m += "\n";
  1907. m += "cmtarget ";
  1908. if(t)
  1909. {
  1910. m += t->GetName();
  1911. }
  1912. m += "\n";
  1913. m += "Is on the target ";
  1914. m += cmtarget->GetName();
  1915. m += "\n";
  1916. m += "But it has no xcode target created yet??\n";
  1917. m += "Current project is ";
  1918. m += this->CurrentProject.c_str();
  1919. cmSystemTools::Error(m.c_str());
  1920. }
  1921. }
  1922. }
  1923. // Loop over configuration types and set per-configuration info.
  1924. for(std::vector<std::string>::iterator i =
  1925. this->CurrentConfigurationTypes.begin();
  1926. i != this->CurrentConfigurationTypes.end(); ++i)
  1927. {
  1928. // Get the current configuration name.
  1929. const char* configName = i->c_str();
  1930. if(!*configName)
  1931. {
  1932. configName = 0;
  1933. }
  1934. // Compute the link library and directory information.
  1935. std::vector<cmStdString> libNames;
  1936. std::vector<cmStdString> libDirs;
  1937. std::vector<cmStdString> fullPathLibs;
  1938. this->CurrentLocalGenerator->ComputeLinkInformation(*cmtarget, configName,
  1939. libNames, libDirs,
  1940. &fullPathLibs);
  1941. // Add dependencies directly on library files.
  1942. for(std::vector<cmStdString>::iterator j = fullPathLibs.begin();
  1943. j != fullPathLibs.end(); ++j)
  1944. {
  1945. target->AddDependLibrary(configName, j->c_str());
  1946. }
  1947. std::string linkDirs;
  1948. // add the library search paths
  1949. for(std::vector<cmStdString>::const_iterator libDir = libDirs.begin();
  1950. libDir != libDirs.end(); ++libDir)
  1951. {
  1952. if(libDir->size() && *libDir != "/usr/lib")
  1953. {
  1954. if(this->XcodeVersion > 15)
  1955. {
  1956. // now add the same one but append $(CONFIGURATION) to it:
  1957. linkDirs += " ";
  1958. linkDirs += this->XCodeEscapePath(libDir->c_str());
  1959. linkDirs += "/$(CONFIGURATION)";
  1960. }
  1961. linkDirs += " ";
  1962. linkDirs += this->XCodeEscapePath(libDir->c_str());
  1963. }
  1964. }
  1965. this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS",
  1966. linkDirs.c_str(), configName);
  1967. // now add the link libraries
  1968. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  1969. {
  1970. std::string fdirs;
  1971. std::set<cmStdString> emitted;
  1972. emitted.insert("/System/Library/Frameworks");
  1973. for(std::vector<cmStdString>::iterator lib = libNames.begin();
  1974. lib != libNames.end(); ++lib)
  1975. {
  1976. std::string& libString = *lib;
  1977. // check to see if this is a -F framework path and extract it if it is
  1978. // -F framework stuff should be in the FRAMEWORK_SEARCH_PATHS and not
  1979. // OTHER_LDFLAGS
  1980. if(libString.size() > 2 && libString[0] == '-'
  1981. && libString[1] == 'F')
  1982. {
  1983. std::string path = libString.substr(2);
  1984. // remove escaped spaces from the path
  1985. cmSystemTools::ReplaceString(path, "\\ ", " ");
  1986. if(emitted.insert(path).second)
  1987. {
  1988. if(fdirs.size())
  1989. {
  1990. fdirs += " ";
  1991. }
  1992. fdirs += this->XCodeEscapePath(path.c_str());
  1993. }
  1994. }
  1995. else
  1996. {
  1997. this->AppendBuildSettingAttribute(target, "OTHER_LDFLAGS",
  1998. lib->c_str(), configName);
  1999. }
  2000. }
  2001. if(fdirs.size())
  2002. {
  2003. this->AppendBuildSettingAttribute(target, "FRAMEWORK_SEARCH_PATHS",
  2004. fdirs.c_str(), configName);
  2005. }
  2006. }
  2007. }
  2008. }
  2009. //----------------------------------------------------------------------------
  2010. void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
  2011. std::vector<cmLocalGenerator*>&
  2012. generators)
  2013. {
  2014. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  2015. i != generators.end(); ++i)
  2016. {
  2017. if(this->IsExcluded(root, *i))
  2018. {
  2019. continue;
  2020. }
  2021. cmMakefile* mf = (*i)->GetMakefile();
  2022. std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
  2023. cmTargets &tgts = mf->GetTargets();
  2024. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  2025. {
  2026. cmTarget& cmtarget = l->second;
  2027. // Same skipping logic here as in CreateXCodeTargets so that we do not
  2028. // end up with (empty anyhow) ALL_BUILD and XCODE_DEPEND_HELPER source
  2029. // groups:
  2030. //
  2031. if(cmtarget.GetType() == cmTarget::UTILITY ||
  2032. cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
  2033. {
  2034. continue;
  2035. }
  2036. // add the soon to be generated Info.plist file as a source for a
  2037. // MACOSX_BUNDLE file
  2038. if(cmtarget.GetPropertyAsBool("MACOSX_BUNDLE"))
  2039. {
  2040. std::string plistFile =
  2041. this->CurrentMakefile->GetCurrentOutputDirectory();
  2042. plistFile += "/Info.plist";
  2043. cmSourceFile* sf =
  2044. this->CurrentMakefile->GetOrCreateSource(plistFile.c_str(), true);
  2045. cmtarget.AddSourceFile(sf);
  2046. }
  2047. std::vector<cmSourceFile*> classes = cmtarget.GetSourceFiles();
  2048. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  2049. s != classes.end(); s++)
  2050. {
  2051. cmSourceFile* sf = *s;
  2052. // Add the file to the list of sources.
  2053. std::string const& source = sf->GetFullPath();
  2054. cmSourceGroup& sourceGroup =
  2055. mf->FindSourceGroup(source.c_str(), sourceGroups);
  2056. cmXCodeObject* pbxgroup =
  2057. this->CreateOrGetPBXGroup(cmtarget, &sourceGroup);
  2058. cmStdString key = GetGroupMapKey(cmtarget, sf);
  2059. this->GroupMap[key] = pbxgroup;
  2060. }
  2061. }
  2062. }
  2063. }
  2064. //----------------------------------------------------------------------------
  2065. cmXCodeObject* cmGlobalXCodeGenerator
  2066. ::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg)
  2067. {
  2068. cmStdString s = cmtarget.GetName();
  2069. s += "/";
  2070. s += sg->GetName();
  2071. std::map<cmStdString, cmXCodeObject* >::iterator i =
  2072. this->GroupNameMap.find(s);
  2073. if(i != this->GroupNameMap.end())
  2074. {
  2075. return i->second;
  2076. }
  2077. i = this->TargetGroup.find(cmtarget.GetName());
  2078. cmXCodeObject* tgroup = 0;
  2079. if(i != this->TargetGroup.end())
  2080. {
  2081. tgroup = i->second;
  2082. }
  2083. else
  2084. {
  2085. tgroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2086. this->TargetGroup[cmtarget.GetName()] = tgroup;
  2087. cmXCodeObject* tgroupChildren =
  2088. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2089. tgroup->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  2090. tgroup->AddAttribute("children", tgroupChildren);
  2091. if(this->XcodeVersion == 15)
  2092. {
  2093. tgroup->AddAttribute("refType", this->CreateString("4"));
  2094. }
  2095. tgroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2096. this->SourcesGroupChildren->AddObject(tgroup);
  2097. }
  2098. // If it's the default source group (empty name) then put the source file
  2099. // directly in the tgroup...
  2100. //
  2101. if (cmStdString(sg->GetName()) == "")
  2102. {
  2103. this->GroupNameMap[s] = tgroup;
  2104. return tgroup;
  2105. }
  2106. cmXCodeObject* tgroupChildren = tgroup->GetObject("children");
  2107. cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
  2108. cmXCodeObject* groupChildren =
  2109. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2110. group->AddAttribute("name", this->CreateString(sg->GetName()));
  2111. group->AddAttribute("children", groupChildren);
  2112. if(this->XcodeVersion == 15)
  2113. {
  2114. group->AddAttribute("refType", this->CreateString("4"));
  2115. }
  2116. group->AddAttribute("sourceTree", this->CreateString("<group>"));
  2117. tgroupChildren->AddObject(group);
  2118. this->GroupNameMap[s] = group;
  2119. return group;
  2120. }
  2121. //----------------------------------------------------------------------------
  2122. void cmGlobalXCodeGenerator
  2123. ::CreateXCodeObjects(cmLocalGenerator* root,
  2124. std::vector<cmLocalGenerator*>&
  2125. generators)
  2126. {
  2127. this->ClearXCodeObjects();
  2128. this->RootObject = 0;
  2129. this->SourcesGroupChildren = 0;
  2130. this->ResourcesGroupChildren = 0;
  2131. this->MainGroupChildren = 0;
  2132. cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2133. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  2134. cmXCodeObject* developBuildStyle =
  2135. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2136. cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2137. if(this->XcodeVersion == 15)
  2138. {
  2139. developBuildStyle->AddAttribute("name",
  2140. this->CreateString("Development"));
  2141. developBuildStyle->AddAttribute("buildSettings", group);
  2142. listObjs->AddObject(developBuildStyle);
  2143. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2144. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("YES"));
  2145. cmXCodeObject* deployBuildStyle =
  2146. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2147. deployBuildStyle->AddAttribute("name", this->CreateString("Deployment"));
  2148. deployBuildStyle->AddAttribute("buildSettings", group);
  2149. listObjs->AddObject(deployBuildStyle);
  2150. }
  2151. else
  2152. {
  2153. for(unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i)
  2154. {
  2155. cmXCodeObject* buildStyle =
  2156. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2157. const char* name = this->CurrentConfigurationTypes[i].c_str();
  2158. buildStyle->AddAttribute("name", this->CreateString(name));
  2159. buildStyle->SetComment(name);
  2160. cmXCodeObject* sgroup =
  2161. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2162. sgroup->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  2163. buildStyle->AddAttribute("buildSettings", sgroup);
  2164. listObjs->AddObject(buildStyle);
  2165. }
  2166. }
  2167. cmXCodeObject* mainGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2168. this->MainGroupChildren =
  2169. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2170. mainGroup->AddAttribute("children", this->MainGroupChildren);
  2171. if(this->XcodeVersion == 15)
  2172. {
  2173. mainGroup->AddAttribute("refType", this->CreateString("4"));
  2174. }
  2175. mainGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2176. cmXCodeObject* sourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2177. this->SourcesGroupChildren =
  2178. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2179. sourcesGroup->AddAttribute("name", this->CreateString("Sources"));
  2180. sourcesGroup->AddAttribute("children", this->SourcesGroupChildren);
  2181. if(this->XcodeVersion == 15)
  2182. {
  2183. sourcesGroup->AddAttribute("refType", this->CreateString("4"));
  2184. }
  2185. sourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2186. this->MainGroupChildren->AddObject(sourcesGroup);
  2187. cmXCodeObject* resourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2188. this->ResourcesGroupChildren =
  2189. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2190. resourcesGroup->AddAttribute("name", this->CreateString("Resources"));
  2191. resourcesGroup->AddAttribute("children", this->ResourcesGroupChildren);
  2192. if(this->XcodeVersion == 15)
  2193. {
  2194. resourcesGroup->AddAttribute("refType", this->CreateString("4"));
  2195. }
  2196. resourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2197. this->MainGroupChildren->AddObject(resourcesGroup);
  2198. // now create the cmake groups
  2199. this->CreateGroups(root, generators);
  2200. cmXCodeObject* productGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2201. productGroup->AddAttribute("name", this->CreateString("Products"));
  2202. if(this->XcodeVersion == 15)
  2203. {
  2204. productGroup->AddAttribute("refType", this->CreateString("4"));
  2205. }
  2206. productGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2207. cmXCodeObject* productGroupChildren =
  2208. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2209. productGroup->AddAttribute("children", productGroupChildren);
  2210. this->MainGroupChildren->AddObject(productGroup);
  2211. this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
  2212. this->RootObject->SetComment("Project object");
  2213. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2214. this->RootObject->AddAttribute("mainGroup",
  2215. this->CreateObjectReference(mainGroup));
  2216. this->RootObject->AddAttribute("buildSettings", group);
  2217. this->RootObject->AddAttribute("buildStyles", listObjs);
  2218. this->RootObject->AddAttribute("hasScannedForEncodings",
  2219. this->CreateString("0"));
  2220. cmXCodeObject* configlist =
  2221. this->CreateObject(cmXCodeObject::XCConfigurationList);
  2222. cmXCodeObject* buildConfigurations =
  2223. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2224. std::vector<cmXCodeObject*> configs;
  2225. if(this->XcodeVersion == 15)
  2226. {
  2227. cmXCodeObject* configDebug =
  2228. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  2229. configDebug->AddAttribute("name", this->CreateString("Debug"));
  2230. configs.push_back(configDebug);
  2231. cmXCodeObject* configRelease =
  2232. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  2233. configRelease->AddAttribute("name", this->CreateString("Release"));
  2234. configs.push_back(configRelease);
  2235. }
  2236. else
  2237. {
  2238. for(unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i)
  2239. {
  2240. const char* name = this->CurrentConfigurationTypes[i].c_str();
  2241. cmXCodeObject* config =
  2242. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  2243. config->AddAttribute("name", this->CreateString(name));
  2244. configs.push_back(config);
  2245. }
  2246. }
  2247. for(std::vector<cmXCodeObject*>::iterator c = configs.begin();
  2248. c != configs.end(); ++c)
  2249. {
  2250. buildConfigurations->AddObject(*c);
  2251. }
  2252. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  2253. std::string comment = "Build configuration list for PBXProject ";
  2254. comment += " \"";
  2255. comment += this->CurrentProject;
  2256. comment += "\"";
  2257. configlist->SetComment(comment.c_str());
  2258. configlist->AddAttribute("defaultConfigurationIsVisible",
  2259. this->CreateString("0"));
  2260. configlist->AddAttribute("defaultConfigurationName",
  2261. this->CreateString("Debug"));
  2262. cmXCodeObject* buildSettings =
  2263. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2264. const char* osxArch =
  2265. this->CurrentMakefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
  2266. const char* sysroot =
  2267. this->CurrentMakefile->GetDefinition("CMAKE_OSX_SYSROOT");
  2268. if(osxArch && sysroot)
  2269. {
  2270. // recompute this as it may have been changed since enable language
  2271. this->Architectures.clear();
  2272. cmSystemTools::ExpandListArgument(std::string(osxArch),
  2273. this->Architectures);
  2274. if(this->Architectures.size() > 1)
  2275. {
  2276. buildSettings->AddAttribute("SDKROOT",
  2277. this->CreateString(sysroot));
  2278. std::string archString;
  2279. for( std::vector<std::string>::iterator i =
  2280. this->Architectures.begin();
  2281. i != this->Architectures.end(); ++i)
  2282. {
  2283. archString += *i;
  2284. archString += " ";
  2285. }
  2286. buildSettings->AddAttribute("ARCHS",
  2287. this->CreateString(archString.c_str()));
  2288. }
  2289. }
  2290. for( std::vector<cmXCodeObject*>::iterator i = configs.begin();
  2291. i != configs.end(); ++i)
  2292. {
  2293. (*i)->AddAttribute("buildSettings", buildSettings);
  2294. }
  2295. this->RootObject->AddAttribute("buildConfigurationList",
  2296. this->CreateObjectReference(configlist));
  2297. std::vector<cmXCodeObject*> targets;
  2298. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  2299. i != generators.end(); ++i)
  2300. {
  2301. if(!this->IsExcluded(root, *i))
  2302. {
  2303. this->CreateXCodeTargets(*i, targets);
  2304. }
  2305. }
  2306. // loop over all targets and add link and depend info
  2307. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  2308. i != targets.end(); ++i)
  2309. {
  2310. cmXCodeObject* t = *i;
  2311. this->AddDependAndLinkInformation(t);
  2312. }
  2313. // now create xcode depend hack makefile
  2314. this->CreateXCodeDependHackTarget(targets);
  2315. // now add all targets to the root object
  2316. cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2317. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  2318. i != targets.end(); ++i)
  2319. {
  2320. cmXCodeObject* t = *i;
  2321. allTargets->AddObject(t);
  2322. cmXCodeObject* productRef = t->GetObject("productReference");
  2323. if(productRef)
  2324. {
  2325. productGroupChildren->AddObject(productRef->GetObject());
  2326. }
  2327. }
  2328. this->RootObject->AddAttribute("targets", allTargets);
  2329. }
  2330. //----------------------------------------------------------------------------
  2331. void
  2332. cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
  2333. std::vector<cmXCodeObject*>& targets)
  2334. {
  2335. cmGeneratedFileStream
  2336. makefileStream(this->CurrentXCodeHackMakefile.c_str());
  2337. if(!makefileStream)
  2338. {
  2339. cmSystemTools::Error("Could not create",
  2340. this->CurrentXCodeHackMakefile.c_str());
  2341. return;
  2342. }
  2343. makefileStream.SetCopyIfDifferent(true);
  2344. // one more pass for external depend information not handled
  2345. // correctly by xcode
  2346. makefileStream << "# DO NOT EDIT\n";
  2347. makefileStream << "# This makefile makes sure all linkable targets are \n";
  2348. makefileStream << "# up-to-date with anything they link to,avoiding a "
  2349. "bug in XCode 1.5\n";
  2350. for(std::vector<std::string>::const_iterator
  2351. ct = this->CurrentConfigurationTypes.begin();
  2352. ct != this->CurrentConfigurationTypes.end(); ++ct)
  2353. {
  2354. if(this->XcodeVersion < 21 || ct->empty())
  2355. {
  2356. makefileStream << "all: ";
  2357. }
  2358. else
  2359. {
  2360. makefileStream << "all." << *ct << ": ";
  2361. }
  2362. const char* configName = 0;
  2363. if(!ct->empty())
  2364. {
  2365. configName = ct->c_str();
  2366. }
  2367. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  2368. i != targets.end(); ++i)
  2369. {
  2370. cmXCodeObject* target = *i;
  2371. cmTarget* t =target->GetTarget();
  2372. if(t->GetType() == cmTarget::EXECUTABLE ||
  2373. t->GetType() == cmTarget::SHARED_LIBRARY ||
  2374. t->GetType() == cmTarget::MODULE_LIBRARY)
  2375. {
  2376. makefileStream << "\\\n\t" <<
  2377. this->ConvertToRelativeForMake(
  2378. t->GetFullPath(configName).c_str());
  2379. }
  2380. }
  2381. makefileStream << "\n\n";
  2382. }
  2383. makefileStream
  2384. << "# For each target create a dummy rule "
  2385. "so the target does not have to exist\n";
  2386. std::set<cmStdString> emitted;
  2387. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  2388. i != targets.end(); ++i)
  2389. {
  2390. cmXCodeObject* target = *i;
  2391. std::map<cmStdString, cmXCodeObject::StringVec> const& deplibs =
  2392. target->GetDependLibraries();
  2393. for(std::map<cmStdString, cmXCodeObject::StringVec>::const_iterator ci
  2394. = deplibs.begin(); ci != deplibs.end(); ++ci)
  2395. {
  2396. for(cmXCodeObject::StringVec::const_iterator d = ci->second.begin();
  2397. d != ci->second.end(); ++d)
  2398. {
  2399. if(emitted.insert(*d).second)
  2400. {
  2401. makefileStream <<
  2402. this->ConvertToRelativeForMake(d->c_str()) << ":\n";
  2403. }
  2404. }
  2405. }
  2406. }
  2407. makefileStream << "\n\n";
  2408. // Write rules to help Xcode relink things at the right time.
  2409. makefileStream <<
  2410. "# Rules to remove targets that are older than anything to which they\n"
  2411. "# link. This forces Xcode to relink the targets from scratch. It\n"
  2412. "# does not seem to check these dependencies itself.\n";
  2413. for(std::vector<std::string>::const_iterator
  2414. ct = this->CurrentConfigurationTypes.begin();
  2415. ct != this->CurrentConfigurationTypes.end(); ++ct)
  2416. {
  2417. const char* configName = 0;
  2418. if(!ct->empty())
  2419. {
  2420. configName = ct->c_str();
  2421. }
  2422. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  2423. i != targets.end(); ++i)
  2424. {
  2425. cmXCodeObject* target = *i;
  2426. cmTarget* t =target->GetTarget();
  2427. if(t->GetType() == cmTarget::EXECUTABLE ||
  2428. t->GetType() == cmTarget::SHARED_LIBRARY ||
  2429. t->GetType() == cmTarget::MODULE_LIBRARY)
  2430. {
  2431. // Create a rule for this target.
  2432. std::string tfull = t->GetFullPath(configName);
  2433. makefileStream << this->ConvertToRelativeForMake(tfull.c_str())
  2434. << ":";
  2435. // List dependencies if any exist.
  2436. std::map<cmStdString, cmXCodeObject::StringVec>::const_iterator
  2437. x = target->GetDependLibraries().find(*ct);
  2438. if(x != target->GetDependLibraries().end())
  2439. {
  2440. std::vector<cmStdString> const& deplibs = x->second;
  2441. for(std::vector<cmStdString>::const_iterator d = deplibs.begin();
  2442. d != deplibs.end(); ++d)
  2443. {
  2444. makefileStream << "\\\n\t" <<
  2445. this->ConvertToRelativeForMake(d->c_str());
  2446. }
  2447. }
  2448. // Write the action to remove the target if it is out of date.
  2449. makefileStream << "\n";
  2450. makefileStream << "\t/bin/rm -f "
  2451. << this->ConvertToRelativeForMake(tfull.c_str())
  2452. << "\n";
  2453. // if building for more than one architecture
  2454. // then remove those exectuables as well
  2455. if(this->Architectures.size() > 1)
  2456. {
  2457. std::string universal = t->GetDirectory();
  2458. universal += "/";
  2459. universal += this->CurrentMakefile->GetProjectName();
  2460. universal += ".build/";
  2461. universal += configName;
  2462. universal += "/";
  2463. universal += t->GetName();
  2464. universal += ".build/Objects-normal/";
  2465. for( std::vector<std::string>::iterator arch =
  2466. this->Architectures.begin();
  2467. arch != this->Architectures.end(); ++arch)
  2468. {
  2469. std::string universalFile = universal;
  2470. universalFile += *arch;
  2471. universalFile += "/";
  2472. universalFile += t->GetName();
  2473. makefileStream << "\t/bin/rm -f "
  2474. <<
  2475. this->ConvertToRelativeForMake(universalFile.c_str())
  2476. << "\n";
  2477. }
  2478. }
  2479. makefileStream << "\n\n";
  2480. }
  2481. }
  2482. }
  2483. }
  2484. //----------------------------------------------------------------------------
  2485. void
  2486. cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
  2487. std::vector<cmLocalGenerator*>&
  2488. generators)
  2489. {
  2490. if(generators.size() == 0)
  2491. {
  2492. return;
  2493. }
  2494. // Skip local generators that are excluded from this project.
  2495. for(std::vector<cmLocalGenerator*>::iterator g = generators.begin();
  2496. g != generators.end(); ++g)
  2497. {
  2498. if(this->IsExcluded(root, *g))
  2499. {
  2500. continue;
  2501. }
  2502. }
  2503. this->CreateXCodeObjects(root,
  2504. generators);
  2505. std::string xcodeDir = root->GetMakefile()->GetStartOutputDirectory();
  2506. xcodeDir += "/";
  2507. xcodeDir += root->GetMakefile()->GetProjectName();
  2508. xcodeDir += ".xcode";
  2509. if(this->XcodeVersion > 20)
  2510. {
  2511. xcodeDir += "proj";
  2512. }
  2513. cmSystemTools::MakeDirectory(xcodeDir.c_str());
  2514. std::string xcodeProjFile = xcodeDir + "/project.pbxproj";
  2515. cmGeneratedFileStream fout(xcodeProjFile.c_str());
  2516. fout.SetCopyIfDifferent(true);
  2517. if(!fout)
  2518. {
  2519. return;
  2520. }
  2521. this->WriteXCodePBXProj(fout, root, generators);
  2522. this->ClearXCodeObjects();
  2523. }
  2524. //----------------------------------------------------------------------------
  2525. void
  2526. cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
  2527. cmLocalGenerator* ,
  2528. std::vector<cmLocalGenerator*>& )
  2529. {
  2530. fout << "// !$*UTF8*$!\n";
  2531. fout << "{\n";
  2532. cmXCodeObject::Indent(1, fout);
  2533. fout << "archiveVersion = 1;\n";
  2534. cmXCodeObject::Indent(1, fout);
  2535. fout << "classes = {\n";
  2536. cmXCodeObject::Indent(1, fout);
  2537. fout << "};\n";
  2538. cmXCodeObject::Indent(1, fout);
  2539. fout << "objectVersion = 39;\n";
  2540. cmXCodeObject::PrintList(this->XCodeObjects, fout);
  2541. cmXCodeObject::Indent(1, fout);
  2542. fout << "rootObject = " << this->RootObject->GetId() << ";\n";
  2543. fout << "}\n";
  2544. }
  2545. //----------------------------------------------------------------------------
  2546. void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry)
  2547. const
  2548. {
  2549. entry.name = this->GetName();
  2550. entry.brief = "Generate XCode project files.";
  2551. entry.full = "";
  2552. }
  2553. //----------------------------------------------------------------------------
  2554. std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(const char* p)
  2555. {
  2556. if ( !this->CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  2557. {
  2558. return cmSystemTools::ConvertToOutputPath(p);
  2559. }
  2560. else
  2561. {
  2562. std::string ret =
  2563. this->CurrentLocalGenerator->
  2564. ConvertToRelativePath(this->CurrentOutputDirectoryComponents, p);
  2565. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  2566. }
  2567. }
  2568. //----------------------------------------------------------------------------
  2569. std::string cmGlobalXCodeGenerator::ConvertToRelativeForXCode(const char* p)
  2570. {
  2571. if ( !this->CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  2572. {
  2573. return cmSystemTools::ConvertToOutputPath(p);
  2574. }
  2575. else
  2576. {
  2577. std::string ret =
  2578. this->CurrentLocalGenerator->
  2579. ConvertToRelativePath(this->ProjectOutputDirectoryComponents, p);
  2580. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  2581. }
  2582. }
  2583. //----------------------------------------------------------------------------
  2584. std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p)
  2585. {
  2586. std::string ret = p;
  2587. if(ret.find(' ') != ret.npos)
  2588. {
  2589. std::string t = ret;
  2590. ret = "\"";
  2591. ret += t;
  2592. ret += "\"";
  2593. }
  2594. return ret;
  2595. }
  2596. //----------------------------------------------------------------------------
  2597. void cmGlobalXCodeGenerator::
  2598. GetTargetObjectFileDirectories(cmTarget* target,
  2599. std::vector<std::string>&
  2600. dirs)
  2601. {
  2602. std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory();
  2603. dir += "/";
  2604. dir += this->CurrentMakefile->GetProjectName();
  2605. dir += ".build/";
  2606. dir += this->GetCMakeCFGInitDirectory();
  2607. dir += "/";
  2608. if(target->GetType() != cmTarget::EXECUTABLE)
  2609. {
  2610. dir += "lib";
  2611. }
  2612. dir += target->GetName();
  2613. if(target->GetType() == cmTarget::STATIC_LIBRARY)
  2614. {
  2615. dir += ".a";
  2616. }
  2617. if(target->GetType() == cmTarget::SHARED_LIBRARY)
  2618. {
  2619. dir += ".dylib";
  2620. }
  2621. if(target->GetType() == cmTarget::MODULE_LIBRARY)
  2622. {
  2623. dir += ".so";
  2624. }
  2625. dir += ".build/Objects-normal/";
  2626. std::string dirsave = dir;
  2627. if(this->Architectures.size())
  2628. {
  2629. for(std::vector<std::string>::iterator i = this->Architectures.begin();
  2630. i != this->Architectures.end(); ++i)
  2631. {
  2632. dir += *i;
  2633. dirs.push_back(dir);
  2634. dir = dirsave;
  2635. }
  2636. }
  2637. else
  2638. {
  2639. dirs.push_back(dir);
  2640. }
  2641. }
  2642. //----------------------------------------------------------------------------
  2643. void
  2644. cmGlobalXCodeGenerator
  2645. ::AppendDirectoryForConfig(const char* prefix,
  2646. const char* config,
  2647. const char* suffix,
  2648. std::string& dir)
  2649. {
  2650. if(this->XcodeVersion > 20)
  2651. {
  2652. if(config)
  2653. {
  2654. if(dir.find(".framework") != dir.npos)
  2655. {
  2656. std::string::size_type pos = dir.rfind("/");
  2657. std::string framework = dir.substr(pos);
  2658. std::string newDir;
  2659. newDir = dir.substr(0, pos);
  2660. newDir += "/";
  2661. newDir += config;
  2662. dir = newDir;
  2663. }
  2664. else
  2665. {
  2666. dir += prefix;
  2667. dir += config;
  2668. dir += suffix;
  2669. }
  2670. }
  2671. }
  2672. }
  2673. //----------------------------------------------------------------------------
  2674. std::string cmGlobalXCodeGenerator::LookupFlags(const char* varNamePrefix,
  2675. const char* varNameLang,
  2676. const char* varNameSuffix,
  2677. const char* default_flags)
  2678. {
  2679. if(varNameLang)
  2680. {
  2681. std::string varName = varNamePrefix;
  2682. varName += varNameLang;
  2683. varName += varNameSuffix;
  2684. if(const char* varValue =
  2685. this->CurrentMakefile->GetDefinition(varName.c_str()))
  2686. {
  2687. if(*varValue)
  2688. {
  2689. return varValue;
  2690. }
  2691. }
  2692. }
  2693. return default_flags;
  2694. }