cmGlobalXCodeGenerator.cxx 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845
  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(); ++cit)
  900. {
  901. buildPhases->AddObject(*cit);
  902. }
  903. if(sourceBuildPhase)
  904. {
  905. buildPhases->AddObject(sourceBuildPhase);
  906. }
  907. if(preLinkPhase)
  908. {
  909. buildPhases->AddObject(preLinkPhase);
  910. }
  911. if(frameworkBuildPhase)
  912. {
  913. buildPhases->AddObject(frameworkBuildPhase);
  914. }
  915. if(postBuildPhase)
  916. {
  917. buildPhases->AddObject(postBuildPhase);
  918. }
  919. }
  920. //----------------------------------------------------------------------------
  921. std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
  922. std::string& flags)
  923. {
  924. std::string retFlag;
  925. std::string::size_type pos = flags.find(flag);
  926. if(pos != flags.npos)
  927. {
  928. while(pos < flags.size() && flags[pos] != ' ')
  929. {
  930. retFlag += flags[pos];
  931. flags[pos] = ' ';
  932. pos++;
  933. }
  934. }
  935. return retFlag;
  936. }
  937. //----------------------------------------------------------------------------
  938. void
  939. cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  940. cmTarget& target,
  941. std::vector<cmCustomCommand>
  942. const & commands,
  943. const char* name)
  944. {
  945. if(strcmp(name, "cmakeReRunPhase") == 0)
  946. {
  947. std::string cdir = this->CurrentMakefile->GetHomeOutputDirectory();
  948. cdir = this->ConvertToRelativeForMake(cdir.c_str());
  949. std::string makecmd = "make -C ";
  950. makecmd += cdir;
  951. makecmd += " -f ";
  952. makecmd +=
  953. this->ConvertToRelativeForMake(this->CurrentReRunCMakeMakefile.c_str());
  954. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  955. buildphase->AddAttribute("shellScript",
  956. this->CreateString(makecmd.c_str()));
  957. return;
  958. }
  959. // collect multiple outputs of custom commands into a set
  960. // which will be used for every configuration
  961. std::map<cmStdString, cmStdString> multipleOutputPairs;
  962. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  963. i != commands.end(); ++i)
  964. {
  965. cmCustomCommand const& cc = *i;
  966. if(!cc.GetCommandLines().empty())
  967. {
  968. const std::vector<std::string>& outputs = cc.GetOutputs();
  969. if(!outputs.empty())
  970. {
  971. // If there are more than one outputs treat the
  972. // first as the primary output and make the rest depend on it.
  973. std::vector<std::string>::const_iterator o = outputs.begin();
  974. std::string primaryOutput = this->ConvertToRelativeForMake(o->c_str());
  975. for(++o; o != outputs.end(); ++o)
  976. {
  977. std::string currentOutput=this->ConvertToRelativeForMake(o->c_str());
  978. multipleOutputPairs[currentOutput] = primaryOutput;
  979. }
  980. }
  981. }
  982. }
  983. std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory();
  984. dir += "/CMakeScripts";
  985. cmSystemTools::MakeDirectory(dir.c_str());
  986. std::string makefile = dir;
  987. makefile += "/";
  988. makefile += target.GetName();
  989. makefile += "_";
  990. makefile += name;
  991. makefile += ".make";
  992. for (std::vector<std::string>::const_iterator currentConfig=
  993. this->CurrentConfigurationTypes.begin();
  994. currentConfig!=this->CurrentConfigurationTypes.end();
  995. currentConfig++ )
  996. {
  997. this->CreateCustomRulesMakefile(makefile.c_str(),
  998. target,
  999. commands,
  1000. currentConfig->c_str(),
  1001. multipleOutputPairs);
  1002. }
  1003. std::string cdir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1004. cdir = this->ConvertToRelativeForXCode(cdir.c_str());
  1005. std::string makecmd = "make -C ";
  1006. makecmd += cdir;
  1007. makecmd += " -f ";
  1008. makecmd += this->ConvertToRelativeForMake(
  1009. (makefile+"$CONFIGURATION").c_str());
  1010. if(!multipleOutputPairs.empty())
  1011. {
  1012. makecmd += " cmake_check_multiple_outputs";
  1013. }
  1014. makecmd += " all";
  1015. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  1016. buildphase->AddAttribute("shellScript",
  1017. this->CreateString(makecmd.c_str()));
  1018. }
  1019. //----------------------------------------------------------------------------
  1020. void cmGlobalXCodeGenerator
  1021. ::CreateCustomRulesMakefile(const char* makefileBasename,
  1022. cmTarget& target,
  1023. std::vector<cmCustomCommand>
  1024. const & commands,
  1025. const char* configName,
  1026. const std::map<cmStdString,
  1027. cmStdString>& multipleOutputPairs
  1028. )
  1029. {
  1030. std::string makefileName=makefileBasename;
  1031. makefileName+=configName;
  1032. cmGeneratedFileStream makefileStream(makefileName.c_str());
  1033. if(!makefileStream)
  1034. {
  1035. return;
  1036. }
  1037. makefileStream.SetCopyIfDifferent(true);
  1038. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  1039. makefileStream << "# Custom rules for " << target.GetName() << "\n";
  1040. // have all depend on all outputs
  1041. makefileStream << "all: ";
  1042. std::map<const cmCustomCommand*, cmStdString> tname;
  1043. int count = 0;
  1044. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1045. i != commands.end(); ++i)
  1046. {
  1047. cmCustomCommand const& cc = *i;
  1048. if(!cc.GetCommandLines().empty())
  1049. {
  1050. const std::vector<std::string>& outputs = cc.GetOutputs();
  1051. if(!outputs.empty())
  1052. {
  1053. for(std::vector<std::string>::const_iterator o = outputs.begin();
  1054. o != outputs.end(); ++o)
  1055. {
  1056. makefileStream
  1057. << "\\\n\t" << this->ConvertToRelativeForMake(o->c_str());
  1058. }
  1059. }
  1060. else
  1061. {
  1062. cmOStringStream str;
  1063. str << "_buildpart_" << count++ ;
  1064. tname[&cc] = std::string(target.GetName()) + str.str();
  1065. makefileStream << "\\\n\t" << tname[&cc];
  1066. }
  1067. }
  1068. }
  1069. makefileStream << "\n\n";
  1070. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1071. i != commands.end(); ++i)
  1072. {
  1073. cmCustomCommand const& cc = *i;
  1074. if(!cc.GetCommandLines().empty())
  1075. {
  1076. bool escapeOldStyle = cc.GetEscapeOldStyle();
  1077. bool escapeAllowMakeVars = cc.GetEscapeAllowMakeVars();
  1078. makefileStream << "\n#" << "Custom command rule: ";
  1079. if(cc.GetComment())
  1080. {
  1081. makefileStream << cc.GetComment();
  1082. }
  1083. makefileStream << "\n";
  1084. const std::vector<std::string>& outputs = cc.GetOutputs();
  1085. if(!outputs.empty())
  1086. {
  1087. // There is at least one output, start the rule for it
  1088. std::string primary_output =
  1089. this->ConvertToRelativeForMake(outputs.begin()->c_str());
  1090. makefileStream << primary_output << ": ";
  1091. }
  1092. else
  1093. {
  1094. // There are no outputs. Use the generated force rule name.
  1095. makefileStream << tname[&cc] << ": ";
  1096. }
  1097. for(std::vector<std::string>::const_iterator d =
  1098. cc.GetDepends().begin();
  1099. d != cc.GetDepends().end(); ++d)
  1100. {
  1101. std::string dep =
  1102. this->CurrentLocalGenerator->GetRealDependency(d->c_str(),
  1103. configName);
  1104. makefileStream << "\\\n" << this
  1105. ->ConvertToRelativeForMake(dep.c_str());
  1106. }
  1107. makefileStream << "\n";
  1108. // Add each command line to the set of commands.
  1109. for(cmCustomCommandLines::const_iterator cl =
  1110. cc.GetCommandLines().begin();
  1111. cl != cc.GetCommandLines().end(); ++cl)
  1112. {
  1113. // Build the command line in a single string.
  1114. const cmCustomCommandLine& commandLine = *cl;
  1115. std::string cmd2 = this->CurrentLocalGenerator
  1116. ->GetRealLocation(commandLine[0].c_str(), configName);
  1117. cmSystemTools::ReplaceString(cmd2, "/./", "/");
  1118. cmd2 = this->ConvertToRelativeForMake(cmd2.c_str());
  1119. std::string cmd;
  1120. if(cc.GetWorkingDirectory())
  1121. {
  1122. cmd += "cd ";
  1123. cmd += this->ConvertToRelativeForMake(cc.GetWorkingDirectory());
  1124. cmd += " && ";
  1125. }
  1126. cmd += cmd2;
  1127. for(unsigned int j=1; j < commandLine.size(); ++j)
  1128. {
  1129. cmd += " ";
  1130. if(escapeOldStyle)
  1131. {
  1132. cmd += (this->CurrentLocalGenerator
  1133. ->EscapeForShellOldStyle(commandLine[j].c_str()));
  1134. }
  1135. else
  1136. {
  1137. cmd += (this->CurrentLocalGenerator->
  1138. EscapeForShell(commandLine[j].c_str(),
  1139. escapeAllowMakeVars));
  1140. }
  1141. }
  1142. makefileStream << "\t" << cmd.c_str() << "\n";
  1143. }
  1144. }
  1145. }
  1146. // Add rules to deal with multiple outputs of custom commands.
  1147. if(!multipleOutputPairs.empty())
  1148. {
  1149. makefileStream <<
  1150. "\n# Dependencies of multiple outputs to their primary outputs \n";
  1151. for(std::map<cmStdString, cmStdString>::const_iterator o =
  1152. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1153. {
  1154. makefileStream << o->first << ": " << o->second << "\n";
  1155. }
  1156. makefileStream <<
  1157. "\n"
  1158. "cmake_check_multiple_outputs:\n";
  1159. for(std::map<cmStdString, cmStdString>::const_iterator o =
  1160. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1161. {
  1162. makefileStream << "\t@if [ ! -f "
  1163. << o->first << " ]; then rm -f "
  1164. << o->second << "; fi\n";
  1165. }
  1166. }
  1167. }
  1168. //----------------------------------------------------------------------------
  1169. void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
  1170. cmXCodeObject* buildSettings,
  1171. std::string& fileType,
  1172. std::string& productType,
  1173. std::string& productName,
  1174. const char* configName)
  1175. {
  1176. std::string flags;
  1177. std::string defFlags;
  1178. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  1179. (target.GetType() == cmTarget::MODULE_LIBRARY));
  1180. // Add the export symbol definition for shared library objects.
  1181. if(const char* exportMacro = target.GetExportMacro())
  1182. {
  1183. defFlags += "-D";
  1184. defFlags += exportMacro;
  1185. }
  1186. const char* lang = target.GetLinkerLanguage(this);
  1187. std::string cflags;
  1188. if(lang)
  1189. {
  1190. // for c++ projects get the c flags as well
  1191. if(strcmp(lang, "CXX") == 0)
  1192. {
  1193. this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName);
  1194. this->CurrentLocalGenerator->AddSharedFlags(cflags, lang, shared);
  1195. }
  1196. // Add language-specific flags.
  1197. this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName);
  1198. // Add shared-library flags if needed.
  1199. this->CurrentLocalGenerator->AddSharedFlags(flags, lang, shared);
  1200. }
  1201. // Add define flags
  1202. this->CurrentLocalGenerator->
  1203. AppendFlags(defFlags,
  1204. this->CurrentMakefile->GetDefineFlags());
  1205. cmSystemTools::ReplaceString(defFlags, "\"", "\\\"");
  1206. cmSystemTools::ReplaceString(flags, "\"", "\\\"");
  1207. cmSystemTools::ReplaceString(cflags, "\"", "\\\"");
  1208. if(this->XcodeVersion > 15)
  1209. {
  1210. buildSettings->AddAttribute
  1211. ("GCC_PREPROCESSOR_DEFINITIONS",
  1212. this->CreateString("CMAKE_INTDIR=\\\\\"$(CONFIGURATION)\\\\\""));
  1213. }
  1214. std::string extraLinkOptions;
  1215. if(target.GetType() == cmTarget::EXECUTABLE)
  1216. {
  1217. extraLinkOptions =
  1218. this->CurrentMakefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
  1219. }
  1220. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  1221. {
  1222. extraLinkOptions = this->CurrentMakefile->
  1223. GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
  1224. }
  1225. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  1226. {
  1227. extraLinkOptions = this->CurrentMakefile->
  1228. GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
  1229. }
  1230. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1231. if(targetLinkFlags)
  1232. {
  1233. extraLinkOptions += " ";
  1234. extraLinkOptions += targetLinkFlags;
  1235. }
  1236. // The product name is the full name of the target for this configuration.
  1237. productName = target.GetFullName(configName);
  1238. // Get the product name components.
  1239. std::string pnprefix;
  1240. std::string pnbase;
  1241. std::string pnsuffix;
  1242. target.GetFullName(pnprefix, pnbase, pnsuffix, configName);
  1243. // Store the product name for all target types.
  1244. buildSettings->AddAttribute("PRODUCT_NAME",
  1245. this->CreateString(pnbase.c_str()));
  1246. // Set attributes to specify the proper name for the target.
  1247. if(target.GetType() == cmTarget::STATIC_LIBRARY ||
  1248. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1249. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1250. target.GetType() == cmTarget::EXECUTABLE)
  1251. {
  1252. std::string pndir = target.GetDirectory();
  1253. if (target.GetType() == cmTarget::SHARED_LIBRARY &&
  1254. target.GetPropertyAsBool("FRAMEWORK"))
  1255. {
  1256. pndir += "/..";
  1257. pndir = cmSystemTools::CollapseFullPath(pndir.c_str());
  1258. }
  1259. buildSettings->AddAttribute("SYMROOT",
  1260. this->CreateString(pndir.c_str()));
  1261. buildSettings->AddAttribute("EXECUTABLE_PREFIX",
  1262. this->CreateString(pnprefix.c_str()));
  1263. buildSettings->AddAttribute("EXECUTABLE_SUFFIX",
  1264. this->CreateString(pnsuffix.c_str()));
  1265. }
  1266. // Handle settings for each target type.
  1267. switch(target.GetType())
  1268. {
  1269. case cmTarget::STATIC_LIBRARY:
  1270. {
  1271. fileType = "archive.ar";
  1272. productType = "com.apple.product-type.library.static";
  1273. buildSettings->AddAttribute("LIBRARY_STYLE",
  1274. this->CreateString("STATIC"));
  1275. break;
  1276. }
  1277. case cmTarget::MODULE_LIBRARY:
  1278. {
  1279. buildSettings->AddAttribute("LIBRARY_STYLE",
  1280. this->CreateString("BUNDLE"));
  1281. if(this->XcodeVersion >= 22)
  1282. {
  1283. fileType = "compiled.mach-o.executable";
  1284. productType = "com.apple.product-type.tool";
  1285. buildSettings->AddAttribute("MACH_O_TYPE",
  1286. this->CreateString("mh_bundle"));
  1287. buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
  1288. this->CreateString("NO"));
  1289. // Add the flags to create an executable.
  1290. std::string createFlags =
  1291. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1292. if(!createFlags.empty())
  1293. {
  1294. extraLinkOptions += " ";
  1295. extraLinkOptions += createFlags;
  1296. }
  1297. }
  1298. else
  1299. {
  1300. fileType = "compiled.mach-o.dylib";
  1301. productType = "com.apple.product-type.library.dynamic";
  1302. // Add the flags to create a module.
  1303. std::string createFlags =
  1304. this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
  1305. "-bundle");
  1306. if(!createFlags.empty())
  1307. {
  1308. extraLinkOptions += " ";
  1309. extraLinkOptions += createFlags;
  1310. }
  1311. }
  1312. break;
  1313. }
  1314. case cmTarget::SHARED_LIBRARY:
  1315. {
  1316. if(target.GetPropertyAsBool("FRAMEWORK"))
  1317. {
  1318. fileType = "wrapper.framework";
  1319. productType = "com.apple.product-type.framework";
  1320. const char* version = target.GetProperty("FRAMEWORK_VERSION");
  1321. buildSettings->AddAttribute("FRAMEWORK_VERSION",
  1322. this->CreateString(version));
  1323. }
  1324. else
  1325. {
  1326. fileType = "compiled.mach-o.dylib";
  1327. productType = "com.apple.product-type.library.dynamic";
  1328. // Add the flags to create a shared library.
  1329. std::string createFlags =
  1330. this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", lang, "_FLAGS",
  1331. "-dynamiclib");
  1332. if(!createFlags.empty())
  1333. {
  1334. extraLinkOptions += " ";
  1335. extraLinkOptions += createFlags;
  1336. }
  1337. }
  1338. buildSettings->AddAttribute("LIBRARY_STYLE",
  1339. this->CreateString("DYNAMIC"));
  1340. buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
  1341. this->CreateString("1"));
  1342. buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
  1343. this->CreateString("1"));
  1344. break;
  1345. }
  1346. case cmTarget::EXECUTABLE:
  1347. {
  1348. fileType = "compiled.mach-o.executable";
  1349. // Add the flags to create an executable.
  1350. std::string createFlags =
  1351. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1352. if(!createFlags.empty())
  1353. {
  1354. extraLinkOptions += " ";
  1355. extraLinkOptions += createFlags;
  1356. }
  1357. // Handle bundles and normal executables separately.
  1358. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  1359. {
  1360. productType = "com.apple.product-type.application";
  1361. std::string f1 =
  1362. this->CurrentMakefile->GetModulesFile("MacOSXBundleInfo.plist.in");
  1363. if ( f1.size() == 0 )
  1364. {
  1365. cmSystemTools::Error("could not find Mac OSX bundle template file.");
  1366. }
  1367. std::string f2 = this->CurrentMakefile->GetCurrentOutputDirectory();
  1368. f2 += "/Info.plist";
  1369. this->CurrentMakefile->ConfigureFile(f1.c_str(), f2.c_str(),
  1370. false, false, false);
  1371. std::string path =
  1372. this->ConvertToRelativeForXCode(f2.c_str());
  1373. buildSettings->AddAttribute("INFOPLIST_FILE",
  1374. this->CreateString(path.c_str()));
  1375. }
  1376. else
  1377. {
  1378. productType = "com.apple.product-type.tool";
  1379. }
  1380. }
  1381. break;
  1382. default:
  1383. break;
  1384. }
  1385. if(this->XcodeVersion >= 22)
  1386. {
  1387. buildSettings->AddAttribute("PREBINDING",
  1388. this->CreateString("NO"));
  1389. }
  1390. std::string dirs;
  1391. std::vector<std::string> includes;
  1392. this->CurrentLocalGenerator->GetIncludeDirectories(includes);
  1393. std::vector<std::string>::iterator i = includes.begin();
  1394. std::string fdirs;
  1395. std::set<cmStdString> emitted;
  1396. emitted.insert("/System/Library/Frameworks");
  1397. for(;i != includes.end(); ++i)
  1398. {
  1399. if(cmSystemTools::IsPathToFramework(i->c_str()))
  1400. {
  1401. std::string frameworkDir = *i;
  1402. frameworkDir += "/../";
  1403. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1404. if(emitted.insert(frameworkDir).second)
  1405. {
  1406. fdirs += this->XCodeEscapePath(frameworkDir.c_str());
  1407. fdirs += " ";
  1408. }
  1409. }
  1410. else
  1411. {
  1412. std::string incpath =
  1413. this->XCodeEscapePath(i->c_str());
  1414. dirs += incpath + " ";
  1415. }
  1416. }
  1417. std::vector<std::string>& frameworks = target.GetFrameworks();
  1418. if(frameworks.size())
  1419. {
  1420. for(std::vector<std::string>::iterator fmIt = frameworks.begin();
  1421. fmIt != frameworks.end(); ++fmIt)
  1422. {
  1423. if(emitted.insert(*fmIt).second)
  1424. {
  1425. fdirs += this->XCodeEscapePath(fmIt->c_str());
  1426. fdirs += " ";
  1427. }
  1428. }
  1429. }
  1430. if(fdirs.size())
  1431. {
  1432. buildSettings->AddAttribute("FRAMEWORK_SEARCH_PATHS",
  1433. this->CreateString(fdirs.c_str()));
  1434. }
  1435. if(dirs.size())
  1436. {
  1437. buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
  1438. this->CreateString(dirs.c_str()));
  1439. }
  1440. std::string oflagc = this->ExtractFlag("-O", cflags);
  1441. char optLevel[2];
  1442. optLevel[0] = '0';
  1443. optLevel[1] = 0;
  1444. if(oflagc.size() == 3)
  1445. {
  1446. optLevel[0] = oflagc[2];
  1447. }
  1448. if(oflagc.size() == 2)
  1449. {
  1450. optLevel[0] = '1';
  1451. }
  1452. std::string oflag = this->ExtractFlag("-O", flags);
  1453. if(oflag.size() == 3)
  1454. {
  1455. optLevel[0] = oflag[2];
  1456. }
  1457. if(oflag.size() == 2)
  1458. {
  1459. optLevel[0] = '1';
  1460. }
  1461. std::string gflagc = this->ExtractFlag("-g", cflags);
  1462. // put back gdwarf-2 if used since there is no way
  1463. // to represent it in the gui, but we still want debug yes
  1464. if(gflagc == "-gdwarf-2")
  1465. {
  1466. cflags += " ";
  1467. cflags += gflagc;
  1468. }
  1469. std::string gflag = this->ExtractFlag("-g", flags);
  1470. if(gflag == "-gdwarf-2")
  1471. {
  1472. flags += " ";
  1473. flags += gflag;
  1474. }
  1475. const char* debugStr = "YES";
  1476. if(gflagc.size() ==0 && gflag.size() == 0)
  1477. {
  1478. debugStr = "NO";
  1479. }
  1480. buildSettings->AddAttribute("GCC_GENERATE_DEBUGGING_SYMBOLS",
  1481. this->CreateString(debugStr));
  1482. buildSettings->AddAttribute("GCC_OPTIMIZATION_LEVEL",
  1483. this->CreateString(optLevel));
  1484. buildSettings->AddAttribute("OPTIMIZATION_CFLAGS",
  1485. this->CreateString(oflagc.c_str()));
  1486. buildSettings->AddAttribute("GCC_SYMBOLS_PRIVATE_EXTERN",
  1487. this->CreateString("NO"));
  1488. buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
  1489. this->CreateString("NO"));
  1490. if(lang && strcmp(lang, "CXX") == 0)
  1491. {
  1492. flags += " ";
  1493. flags += defFlags;
  1494. buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
  1495. this->CreateString(flags.c_str()));
  1496. cflags += " ";
  1497. cflags += defFlags;
  1498. buildSettings->AddAttribute("OTHER_CFLAGS",
  1499. this->CreateString(cflags.c_str()));
  1500. }
  1501. else
  1502. {
  1503. flags += " ";
  1504. flags += defFlags;
  1505. buildSettings->AddAttribute("OTHER_CFLAGS",
  1506. this->CreateString(flags.c_str()));
  1507. }
  1508. // Create the INSTALL_PATH attribute.
  1509. std::string install_name_dir;
  1510. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  1511. {
  1512. // Get the install_name directory for the build tree.
  1513. install_name_dir = target.GetInstallNameDirForBuildTree(configName);
  1514. if(target.GetPropertyAsBool("FRAMEWORK"))
  1515. {
  1516. if(install_name_dir.find(".framework") != install_name_dir.npos)
  1517. {
  1518. install_name_dir = install_name_dir + "/..";
  1519. install_name_dir =
  1520. cmSystemTools::CollapseFullPath(install_name_dir.c_str());
  1521. //std::cerr << "new install name " << install_name_dir << "\n";
  1522. }
  1523. }
  1524. if(install_name_dir.empty())
  1525. {
  1526. // Xcode will not pass the -install_name option at all if INSTALL_PATH
  1527. // is not given or is empty. We must explicitly put the flag in the
  1528. // link flags to create an install_name with just the library soname.
  1529. extraLinkOptions += " -install_name ";
  1530. extraLinkOptions += productName;
  1531. }
  1532. else
  1533. {
  1534. // Convert to a path for the native build tool.
  1535. cmSystemTools::ConvertToUnixSlashes(install_name_dir);
  1536. // do not escape spaces on this since it is only a single path
  1537. }
  1538. }
  1539. buildSettings->AddAttribute("INSTALL_PATH",
  1540. this->CreateString(install_name_dir.c_str()));
  1541. buildSettings->AddAttribute("OTHER_LDFLAGS",
  1542. this->CreateString(extraLinkOptions.c_str()));
  1543. buildSettings->AddAttribute("OTHER_REZFLAGS",
  1544. this->CreateString(""));
  1545. buildSettings->AddAttribute("SECTORDER_FLAGS",
  1546. this->CreateString(""));
  1547. buildSettings->AddAttribute("USE_HEADERMAP",
  1548. this->CreateString("NO"));
  1549. buildSettings->AddAttribute("WARNING_CFLAGS",
  1550. this->CreateString(
  1551. "-Wmost -Wno-four-char-constants"
  1552. " -Wno-unknown-pragmas"));
  1553. }
  1554. //----------------------------------------------------------------------------
  1555. cmXCodeObject*
  1556. cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
  1557. {
  1558. cmXCodeObject* shellBuildPhase =
  1559. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  1560. shellBuildPhase->AddAttribute("buildActionMask",
  1561. this->CreateString("2147483647"));
  1562. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1563. shellBuildPhase->AddAttribute("files", buildFiles);
  1564. cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1565. shellBuildPhase->AddAttribute("inputPaths", inputPaths);
  1566. cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1567. shellBuildPhase->AddAttribute("outputPaths", outputPaths);
  1568. shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1569. this->CreateString("0"));
  1570. shellBuildPhase->AddAttribute("shellPath",
  1571. this->CreateString("/bin/sh"));
  1572. shellBuildPhase->AddAttribute("shellScript",
  1573. this->CreateString(
  1574. "# shell script goes here\nexit 0"));
  1575. cmXCodeObject* target =
  1576. this->CreateObject(cmXCodeObject::PBXAggregateTarget);
  1577. target->SetComment(cmtarget.GetName());
  1578. cmXCodeObject* buildPhases =
  1579. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1580. std::vector<cmXCodeObject*> emptyContentVector;
  1581. this->CreateCustomCommands(buildPhases, 0, 0, 0, emptyContentVector, 0, cmtarget);
  1582. target->AddAttribute("buildPhases", buildPhases);
  1583. cmXCodeObject* buildSettings =
  1584. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1585. std::string fileTypeString;
  1586. std::string productTypeString;
  1587. std::string productName;
  1588. const char* globalConfig = 0;
  1589. if(this->XcodeVersion > 20)
  1590. {
  1591. this->AddConfigurations(target, cmtarget);
  1592. }
  1593. else
  1594. {
  1595. globalConfig = this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
  1596. }
  1597. this->CreateBuildSettings(cmtarget,
  1598. buildSettings, fileTypeString,
  1599. productTypeString, productName, globalConfig);
  1600. target->AddAttribute("buildSettings", buildSettings);
  1601. cmXCodeObject* dependencies =
  1602. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1603. target->AddAttribute("dependencies", dependencies);
  1604. target->AddAttribute("name", this->CreateString(productName.c_str()));
  1605. target->AddAttribute("productName",this->CreateString(productName.c_str()));
  1606. target->SetTarget(&cmtarget);
  1607. return target;
  1608. }
  1609. //----------------------------------------------------------------------------
  1610. void cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
  1611. cmTarget& cmtarget)
  1612. {
  1613. std::string configTypes =
  1614. this->CurrentMakefile->GetRequiredDefinition("CMAKE_CONFIGURATION_TYPES");
  1615. std::vector<std::string> configVectorIn;
  1616. std::vector<std::string> configVector;
  1617. configVectorIn.push_back(configTypes);
  1618. cmSystemTools::ExpandList(configVectorIn, configVector);
  1619. cmXCodeObject* configlist =
  1620. this->CreateObject(cmXCodeObject::XCConfigurationList);
  1621. cmXCodeObject* buildConfigurations =
  1622. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1623. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  1624. std::string comment = "Build configuration list for ";
  1625. comment += cmXCodeObject::PBXTypeNames[target->GetIsA()];
  1626. comment += " \"";
  1627. comment += cmtarget.GetName();
  1628. comment += "\"";
  1629. configlist->SetComment(comment.c_str());
  1630. target->AddAttribute("buildConfigurationList",
  1631. this->CreateObjectReference(configlist));
  1632. for(unsigned int i = 0; i < configVector.size(); ++i)
  1633. {
  1634. cmXCodeObject* config =
  1635. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  1636. buildConfigurations->AddObject(config);
  1637. cmXCodeObject* buildSettings =
  1638. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1639. std::string fileTypeString;
  1640. std::string productTypeString;
  1641. std::string productName;
  1642. this->CreateBuildSettings(cmtarget,
  1643. buildSettings, fileTypeString,
  1644. productTypeString, productName,
  1645. configVector[i].c_str());
  1646. config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
  1647. config->SetComment(configVector[i].c_str());
  1648. config->AddAttribute("buildSettings", buildSettings);
  1649. }
  1650. if(configVector.size())
  1651. {
  1652. configlist->AddAttribute("defaultConfigurationName",
  1653. this->CreateString(configVector[0].c_str()));
  1654. configlist->AddAttribute("defaultConfigurationIsVisible",
  1655. this->CreateString("0"));
  1656. }
  1657. }
  1658. //----------------------------------------------------------------------------
  1659. cmXCodeObject*
  1660. cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
  1661. cmXCodeObject* buildPhases)
  1662. {
  1663. cmXCodeObject* target =
  1664. this->CreateObject(cmXCodeObject::PBXNativeTarget);
  1665. target->AddAttribute("buildPhases", buildPhases);
  1666. cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1667. target->AddAttribute("buildRules", buildRules);
  1668. cmXCodeObject* buildSettings =
  1669. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1670. std::string fileTypeString;
  1671. std::string productTypeString;
  1672. std::string productName;
  1673. const char* globalConfig = 0;
  1674. if(this->XcodeVersion > 20)
  1675. {
  1676. this->AddConfigurations(target, cmtarget);
  1677. }
  1678. else
  1679. {
  1680. globalConfig = this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
  1681. }
  1682. this->CreateBuildSettings(cmtarget,
  1683. buildSettings, fileTypeString,
  1684. productTypeString, productName, globalConfig);
  1685. target->AddAttribute("buildSettings", buildSettings);
  1686. cmXCodeObject* dependencies =
  1687. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1688. target->AddAttribute("dependencies", dependencies);
  1689. target->AddAttribute("name", this->CreateString(productName.c_str()));
  1690. target->AddAttribute("productName",this->CreateString(productName.c_str()));
  1691. cmXCodeObject* fileRef =
  1692. this->CreateObject(cmXCodeObject::PBXFileReference);
  1693. fileRef->AddAttribute("explicitFileType",
  1694. this->CreateString(fileTypeString.c_str()));
  1695. fileRef->AddAttribute("path", this->CreateString(productName.c_str()));
  1696. fileRef->AddAttribute("refType", this->CreateString("0"));
  1697. fileRef->AddAttribute("sourceTree",
  1698. this->CreateString("BUILT_PRODUCTS_DIR"));
  1699. fileRef->SetComment(cmtarget.GetName());
  1700. target->AddAttribute("productReference",
  1701. this->CreateObjectReference(fileRef));
  1702. target->AddAttribute("productType",
  1703. this->CreateString(productTypeString.c_str()));
  1704. target->SetTarget(&cmtarget);
  1705. return target;
  1706. }
  1707. //----------------------------------------------------------------------------
  1708. cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
  1709. {
  1710. if(!t)
  1711. {
  1712. return 0;
  1713. }
  1714. for(std::vector<cmXCodeObject*>::iterator i = this->XCodeObjects.begin();
  1715. i != this->XCodeObjects.end(); ++i)
  1716. {
  1717. cmXCodeObject* o = *i;
  1718. if(o->GetTarget() == t)
  1719. {
  1720. return o;
  1721. }
  1722. }
  1723. return 0;
  1724. }
  1725. //----------------------------------------------------------------------------
  1726. void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
  1727. cmXCodeObject* dependTarget)
  1728. {
  1729. // make sure a target does not depend on itself
  1730. if(target == dependTarget)
  1731. {
  1732. return;
  1733. }
  1734. // now avoid circular references if dependTarget already
  1735. // depends on target then skip it. Circular references crashes
  1736. // xcode
  1737. cmXCodeObject* dependTargetDepends =
  1738. dependTarget->GetObject("dependencies");
  1739. if(dependTargetDepends)
  1740. {
  1741. if(dependTargetDepends->HasObject(target->GetPBXTargetDependency()))
  1742. {
  1743. return;
  1744. }
  1745. }
  1746. cmXCodeObject* targetdep = dependTarget->GetPBXTargetDependency();
  1747. if(!targetdep)
  1748. {
  1749. cmXCodeObject* container =
  1750. this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
  1751. container->SetComment("PBXContainerItemProxy");
  1752. container->AddAttribute("containerPortal",
  1753. this->CreateObjectReference(this->RootObject));
  1754. container->AddAttribute("proxyType", this->CreateString("1"));
  1755. container->AddAttribute("remoteGlobalIDString",
  1756. this->CreateObjectReference(dependTarget));
  1757. container->AddAttribute("remoteInfo",
  1758. this->CreateString(
  1759. dependTarget->GetTarget()->GetName()));
  1760. targetdep =
  1761. this->CreateObject(cmXCodeObject::PBXTargetDependency);
  1762. targetdep->SetComment("PBXTargetDependency");
  1763. targetdep->AddAttribute("target",
  1764. this->CreateObjectReference(dependTarget));
  1765. targetdep->AddAttribute("targetProxy",
  1766. this->CreateObjectReference(container));
  1767. dependTarget->SetPBXTargetDependency(targetdep);
  1768. }
  1769. cmXCodeObject* depends = target->GetObject("dependencies");
  1770. if(!depends)
  1771. {
  1772. cmSystemTools::
  1773. Error("target does not have dependencies attribute error..");
  1774. }
  1775. else
  1776. {
  1777. depends->AddUniqueObject(targetdep);
  1778. }
  1779. }
  1780. //----------------------------------------------------------------------------
  1781. void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings,
  1782. const char* attribute,
  1783. const char* value)
  1784. {
  1785. if(settings)
  1786. {
  1787. cmXCodeObject* attr = settings->GetObject(attribute);
  1788. if(!attr)
  1789. {
  1790. settings->AddAttribute(attribute, this->CreateString(value));
  1791. }
  1792. else
  1793. {
  1794. std::string oldValue = attr->GetString();
  1795. cmSystemTools::ReplaceString(oldValue, "\"", "");
  1796. oldValue += " ";
  1797. oldValue += value;
  1798. attr->SetString(oldValue.c_str());
  1799. }
  1800. }
  1801. }
  1802. //----------------------------------------------------------------------------
  1803. void cmGlobalXCodeGenerator
  1804. ::AppendBuildSettingAttribute(cmXCodeObject* target,
  1805. const char* attribute,
  1806. const char* value,
  1807. const char* configName)
  1808. {
  1809. if(this->XcodeVersion < 21)
  1810. {
  1811. // There is only one configuration. Add the setting to the buildSettings
  1812. // of the target.
  1813. this->AppendOrAddBuildSetting(target->GetObject("buildSettings"),
  1814. attribute, value);
  1815. }
  1816. else
  1817. {
  1818. // There are multiple configurations. Add the setting to the
  1819. // buildSettings of the configuration name given.
  1820. cmXCodeObject* configurationList =
  1821. target->GetObject("buildConfigurationList")->GetObject();
  1822. cmXCodeObject* buildConfigs =
  1823. configurationList->GetObject("buildConfigurations");
  1824. std::vector<cmXCodeObject*> list = buildConfigs->GetObjectList();
  1825. // each configuration and the target itself has a buildSettings in it
  1826. //list.push_back(target);
  1827. for(std::vector<cmXCodeObject*>::iterator i = list.begin();
  1828. i != list.end(); ++i)
  1829. {
  1830. if(configName)
  1831. {
  1832. if(strcmp((*i)->GetObject("name")->GetString(), configName) == 0)
  1833. {
  1834. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  1835. this->AppendOrAddBuildSetting(settings, attribute, value);
  1836. }
  1837. }
  1838. else
  1839. {
  1840. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  1841. this->AppendOrAddBuildSetting(settings, attribute, value);
  1842. }
  1843. }
  1844. }
  1845. }
  1846. //----------------------------------------------------------------------------
  1847. void cmGlobalXCodeGenerator
  1848. ::AddDependAndLinkInformation(cmXCodeObject* target)
  1849. {
  1850. cmTarget* cmtarget = target->GetTarget();
  1851. if(!cmtarget)
  1852. {
  1853. cmSystemTools::Error("Error no target on xobject\n");
  1854. return;
  1855. }
  1856. // Add dependencies on other CMake targets.
  1857. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  1858. {
  1859. // Keep track of dependencies already listed.
  1860. std::set<cmStdString> emitted;
  1861. // A target should not depend on itself.
  1862. emitted.insert(cmtarget->GetName());
  1863. // Loop over all library dependencies.
  1864. const cmTarget::LinkLibraryVectorType& tlibs =
  1865. cmtarget->GetLinkLibraries();
  1866. for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
  1867. lib != tlibs.end(); ++lib)
  1868. {
  1869. // Don't emit the same library twice for this target.
  1870. if(emitted.insert(lib->first).second)
  1871. {
  1872. // Add this dependency.
  1873. cmTarget* t = this->FindTarget(this->CurrentProject.c_str(),
  1874. lib->first.c_str(), false);
  1875. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  1876. if(dptarget)
  1877. {
  1878. this->AddDependTarget(target, dptarget);
  1879. }
  1880. }
  1881. }
  1882. }
  1883. // write utility dependencies.
  1884. for(std::set<cmStdString>::const_iterator i
  1885. = cmtarget->GetUtilities().begin();
  1886. i != cmtarget->GetUtilities().end(); ++i)
  1887. {
  1888. cmTarget* t = this->FindTarget(this->CurrentProject.c_str(),
  1889. i->c_str(), false);
  1890. // if the target is in this project then make target depend
  1891. // on it. It may not be in this project if this is a sub
  1892. // project from the top.
  1893. if(t)
  1894. {
  1895. cmXCodeObject* dptarget = this->FindXCodeTarget(t);
  1896. if(dptarget)
  1897. {
  1898. this->AddDependTarget(target, dptarget);
  1899. }
  1900. else
  1901. {
  1902. std::string m = "Error Utility: ";
  1903. m += i->c_str();
  1904. m += "\n";
  1905. m += "cmtarget ";
  1906. if(t)
  1907. {
  1908. m += t->GetName();
  1909. }
  1910. m += "\n";
  1911. m += "Is on the target ";
  1912. m += cmtarget->GetName();
  1913. m += "\n";
  1914. m += "But it has no xcode target created yet??\n";
  1915. m += "Current project is ";
  1916. m += this->CurrentProject.c_str();
  1917. cmSystemTools::Error(m.c_str());
  1918. }
  1919. }
  1920. }
  1921. // Loop over configuration types and set per-configuration info.
  1922. for(std::vector<std::string>::iterator i =
  1923. this->CurrentConfigurationTypes.begin();
  1924. i != this->CurrentConfigurationTypes.end(); ++i)
  1925. {
  1926. // Get the current configuration name.
  1927. const char* configName = i->c_str();
  1928. if(!*configName)
  1929. {
  1930. configName = 0;
  1931. }
  1932. // Compute the link library and directory information.
  1933. std::vector<cmStdString> libNames;
  1934. std::vector<cmStdString> libDirs;
  1935. std::vector<cmStdString> fullPathLibs;
  1936. this->CurrentLocalGenerator->ComputeLinkInformation(*cmtarget, configName,
  1937. libNames, libDirs,
  1938. &fullPathLibs);
  1939. // Add dependencies directly on library files.
  1940. for(std::vector<cmStdString>::iterator j = fullPathLibs.begin();
  1941. j != fullPathLibs.end(); ++j)
  1942. {
  1943. target->AddDependLibrary(configName, j->c_str());
  1944. }
  1945. std::string linkDirs;
  1946. // add the library search paths
  1947. for(std::vector<cmStdString>::const_iterator libDir = libDirs.begin();
  1948. libDir != libDirs.end(); ++libDir)
  1949. {
  1950. if(libDir->size() && *libDir != "/usr/lib")
  1951. {
  1952. if(this->XcodeVersion > 15)
  1953. {
  1954. // now add the same one but append $(CONFIGURATION) to it:
  1955. linkDirs += " ";
  1956. linkDirs += this->XCodeEscapePath(libDir->c_str());
  1957. linkDirs += "/$(CONFIGURATION)";
  1958. }
  1959. linkDirs += " ";
  1960. linkDirs += this->XCodeEscapePath(libDir->c_str());
  1961. }
  1962. }
  1963. this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS",
  1964. linkDirs.c_str(), configName);
  1965. // now add the link libraries
  1966. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  1967. {
  1968. std::string fdirs;
  1969. std::set<cmStdString> emitted;
  1970. emitted.insert("/System/Library/Frameworks");
  1971. for(std::vector<cmStdString>::iterator lib = libNames.begin();
  1972. lib != libNames.end(); ++lib)
  1973. {
  1974. std::string& libString = *lib;
  1975. // check to see if this is a -F framework path and extract it if it is
  1976. // -F framework stuff should be in the FRAMEWORK_SEARCH_PATHS and not
  1977. // OTHER_LDFLAGS
  1978. if(libString.size() > 2 && libString[0] == '-'
  1979. && libString[1] == 'F')
  1980. {
  1981. std::string path = libString.substr(2);
  1982. // remove escaped spaces from the path
  1983. cmSystemTools::ReplaceString(path, "\\ ", " ");
  1984. if(emitted.insert(path).second)
  1985. {
  1986. if(fdirs.size())
  1987. {
  1988. fdirs += " ";
  1989. }
  1990. fdirs += this->XCodeEscapePath(path.c_str());
  1991. }
  1992. }
  1993. else
  1994. {
  1995. this->AppendBuildSettingAttribute(target, "OTHER_LDFLAGS",
  1996. lib->c_str(), configName);
  1997. }
  1998. }
  1999. if(fdirs.size())
  2000. {
  2001. this->AppendBuildSettingAttribute(target, "FRAMEWORK_SEARCH_PATHS",
  2002. fdirs.c_str(), configName);
  2003. }
  2004. }
  2005. }
  2006. }
  2007. //----------------------------------------------------------------------------
  2008. void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
  2009. std::vector<cmLocalGenerator*>&
  2010. generators)
  2011. {
  2012. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  2013. i != generators.end(); ++i)
  2014. {
  2015. if(this->IsExcluded(root, *i))
  2016. {
  2017. continue;
  2018. }
  2019. cmMakefile* mf = (*i)->GetMakefile();
  2020. std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
  2021. cmTargets &tgts = mf->GetTargets();
  2022. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  2023. {
  2024. cmTarget& cmtarget = l->second;
  2025. // Same skipping logic here as in CreateXCodeTargets so that we do not
  2026. // end up with (empty anyhow) ALL_BUILD and XCODE_DEPEND_HELPER source
  2027. // groups:
  2028. //
  2029. if(cmtarget.GetType() == cmTarget::UTILITY ||
  2030. cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
  2031. {
  2032. continue;
  2033. }
  2034. // add the soon to be generated Info.plist file as a source for a
  2035. // MACOSX_BUNDLE file
  2036. if(cmtarget.GetPropertyAsBool("MACOSX_BUNDLE"))
  2037. {
  2038. std::string plistFile =
  2039. this->CurrentMakefile->GetCurrentOutputDirectory();
  2040. plistFile += "/Info.plist";
  2041. cmSourceFile* sf =
  2042. this->CurrentMakefile->GetOrCreateSource(plistFile.c_str(), true);
  2043. cmtarget.AddSourceFile(sf);
  2044. }
  2045. std::vector<cmSourceFile*> classes = cmtarget.GetSourceFiles();
  2046. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  2047. s != classes.end(); s++)
  2048. {
  2049. cmSourceFile* sf = *s;
  2050. // Add the file to the list of sources.
  2051. std::string const& source = sf->GetFullPath();
  2052. cmSourceGroup& sourceGroup =
  2053. mf->FindSourceGroup(source.c_str(), sourceGroups);
  2054. cmXCodeObject* pbxgroup =
  2055. this->CreateOrGetPBXGroup(cmtarget, &sourceGroup);
  2056. cmStdString key = GetGroupMapKey(cmtarget, sf);
  2057. this->GroupMap[key] = pbxgroup;
  2058. }
  2059. }
  2060. }
  2061. }
  2062. //----------------------------------------------------------------------------
  2063. cmXCodeObject* cmGlobalXCodeGenerator
  2064. ::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg)
  2065. {
  2066. cmStdString s = cmtarget.GetName();
  2067. s += "/";
  2068. s += sg->GetName();
  2069. std::map<cmStdString, cmXCodeObject* >::iterator i =
  2070. this->GroupNameMap.find(s);
  2071. if(i != this->GroupNameMap.end())
  2072. {
  2073. return i->second;
  2074. }
  2075. i = this->TargetGroup.find(cmtarget.GetName());
  2076. cmXCodeObject* tgroup = 0;
  2077. if(i != this->TargetGroup.end())
  2078. {
  2079. tgroup = i->second;
  2080. }
  2081. else
  2082. {
  2083. tgroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2084. this->TargetGroup[cmtarget.GetName()] = tgroup;
  2085. cmXCodeObject* tgroupChildren =
  2086. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2087. tgroup->AddAttribute("name", this->CreateString(cmtarget.GetName()));
  2088. tgroup->AddAttribute("children", tgroupChildren);
  2089. if(this->XcodeVersion == 15)
  2090. {
  2091. tgroup->AddAttribute("refType", this->CreateString("4"));
  2092. }
  2093. tgroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2094. this->SourcesGroupChildren->AddObject(tgroup);
  2095. }
  2096. // If it's the default source group (empty name) then put the source file
  2097. // directly in the tgroup...
  2098. //
  2099. if (cmStdString(sg->GetName()) == "")
  2100. {
  2101. this->GroupNameMap[s] = tgroup;
  2102. return tgroup;
  2103. }
  2104. cmXCodeObject* tgroupChildren = tgroup->GetObject("children");
  2105. cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
  2106. cmXCodeObject* groupChildren =
  2107. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2108. group->AddAttribute("name", this->CreateString(sg->GetName()));
  2109. group->AddAttribute("children", groupChildren);
  2110. if(this->XcodeVersion == 15)
  2111. {
  2112. group->AddAttribute("refType", this->CreateString("4"));
  2113. }
  2114. group->AddAttribute("sourceTree", this->CreateString("<group>"));
  2115. tgroupChildren->AddObject(group);
  2116. this->GroupNameMap[s] = group;
  2117. return group;
  2118. }
  2119. //----------------------------------------------------------------------------
  2120. void cmGlobalXCodeGenerator
  2121. ::CreateXCodeObjects(cmLocalGenerator* root,
  2122. std::vector<cmLocalGenerator*>&
  2123. generators)
  2124. {
  2125. this->ClearXCodeObjects();
  2126. this->RootObject = 0;
  2127. this->SourcesGroupChildren = 0;
  2128. this->ResourcesGroupChildren = 0;
  2129. this->MainGroupChildren = 0;
  2130. cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2131. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  2132. cmXCodeObject* developBuildStyle =
  2133. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2134. cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2135. if(this->XcodeVersion == 15)
  2136. {
  2137. developBuildStyle->AddAttribute("name",
  2138. this->CreateString("Development"));
  2139. developBuildStyle->AddAttribute("buildSettings", group);
  2140. listObjs->AddObject(developBuildStyle);
  2141. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2142. group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("YES"));
  2143. cmXCodeObject* deployBuildStyle =
  2144. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2145. deployBuildStyle->AddAttribute("name", this->CreateString("Deployment"));
  2146. deployBuildStyle->AddAttribute("buildSettings", group);
  2147. listObjs->AddObject(deployBuildStyle);
  2148. }
  2149. else
  2150. {
  2151. for(unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i)
  2152. {
  2153. cmXCodeObject* buildStyle =
  2154. this->CreateObject(cmXCodeObject::PBXBuildStyle);
  2155. const char* name = this->CurrentConfigurationTypes[i].c_str();
  2156. buildStyle->AddAttribute("name", this->CreateString(name));
  2157. buildStyle->SetComment(name);
  2158. cmXCodeObject* sgroup =
  2159. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2160. sgroup->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
  2161. buildStyle->AddAttribute("buildSettings", sgroup);
  2162. listObjs->AddObject(buildStyle);
  2163. }
  2164. }
  2165. cmXCodeObject* mainGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2166. this->MainGroupChildren =
  2167. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2168. mainGroup->AddAttribute("children", this->MainGroupChildren);
  2169. if(this->XcodeVersion == 15)
  2170. {
  2171. mainGroup->AddAttribute("refType", this->CreateString("4"));
  2172. }
  2173. mainGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2174. cmXCodeObject* sourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2175. this->SourcesGroupChildren =
  2176. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2177. sourcesGroup->AddAttribute("name", this->CreateString("Sources"));
  2178. sourcesGroup->AddAttribute("children", this->SourcesGroupChildren);
  2179. if(this->XcodeVersion == 15)
  2180. {
  2181. sourcesGroup->AddAttribute("refType", this->CreateString("4"));
  2182. }
  2183. sourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2184. this->MainGroupChildren->AddObject(sourcesGroup);
  2185. cmXCodeObject* resourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2186. this->ResourcesGroupChildren =
  2187. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2188. resourcesGroup->AddAttribute("name", this->CreateString("Resources"));
  2189. resourcesGroup->AddAttribute("children", this->ResourcesGroupChildren);
  2190. if(this->XcodeVersion == 15)
  2191. {
  2192. resourcesGroup->AddAttribute("refType", this->CreateString("4"));
  2193. }
  2194. resourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2195. this->MainGroupChildren->AddObject(resourcesGroup);
  2196. // now create the cmake groups
  2197. this->CreateGroups(root, generators);
  2198. cmXCodeObject* productGroup = this->CreateObject(cmXCodeObject::PBXGroup);
  2199. productGroup->AddAttribute("name", this->CreateString("Products"));
  2200. if(this->XcodeVersion == 15)
  2201. {
  2202. productGroup->AddAttribute("refType", this->CreateString("4"));
  2203. }
  2204. productGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
  2205. cmXCodeObject* productGroupChildren =
  2206. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2207. productGroup->AddAttribute("children", productGroupChildren);
  2208. this->MainGroupChildren->AddObject(productGroup);
  2209. this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
  2210. this->RootObject->SetComment("Project object");
  2211. group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2212. this->RootObject->AddAttribute("mainGroup",
  2213. this->CreateObjectReference(mainGroup));
  2214. this->RootObject->AddAttribute("buildSettings", group);
  2215. this->RootObject->AddAttribute("buildStyles", listObjs);
  2216. this->RootObject->AddAttribute("hasScannedForEncodings",
  2217. this->CreateString("0"));
  2218. cmXCodeObject* configlist =
  2219. this->CreateObject(cmXCodeObject::XCConfigurationList);
  2220. cmXCodeObject* buildConfigurations =
  2221. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2222. std::vector<cmXCodeObject*> configs;
  2223. if(this->XcodeVersion == 15)
  2224. {
  2225. cmXCodeObject* configDebug =
  2226. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  2227. configDebug->AddAttribute("name", this->CreateString("Debug"));
  2228. configs.push_back(configDebug);
  2229. cmXCodeObject* configRelease =
  2230. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  2231. configRelease->AddAttribute("name", this->CreateString("Release"));
  2232. configs.push_back(configRelease);
  2233. }
  2234. else
  2235. {
  2236. for(unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i)
  2237. {
  2238. const char* name = this->CurrentConfigurationTypes[i].c_str();
  2239. cmXCodeObject* config =
  2240. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  2241. config->AddAttribute("name", this->CreateString(name));
  2242. configs.push_back(config);
  2243. }
  2244. }
  2245. for(std::vector<cmXCodeObject*>::iterator c = configs.begin();
  2246. c != configs.end(); ++c)
  2247. {
  2248. buildConfigurations->AddObject(*c);
  2249. }
  2250. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  2251. std::string comment = "Build configuration list for PBXProject ";
  2252. comment += " \"";
  2253. comment += this->CurrentProject;
  2254. comment += "\"";
  2255. configlist->SetComment(comment.c_str());
  2256. configlist->AddAttribute("defaultConfigurationIsVisible",
  2257. this->CreateString("0"));
  2258. configlist->AddAttribute("defaultConfigurationName",
  2259. this->CreateString("Debug"));
  2260. cmXCodeObject* buildSettings =
  2261. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  2262. const char* osxArch =
  2263. this->CurrentMakefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
  2264. const char* sysroot =
  2265. this->CurrentMakefile->GetDefinition("CMAKE_OSX_SYSROOT");
  2266. if(osxArch && sysroot)
  2267. {
  2268. // recompute this as it may have been changed since enable language
  2269. this->Architectures.clear();
  2270. cmSystemTools::ExpandListArgument(std::string(osxArch),
  2271. this->Architectures);
  2272. if(this->Architectures.size() > 1)
  2273. {
  2274. buildSettings->AddAttribute("SDKROOT",
  2275. this->CreateString(sysroot));
  2276. std::string archString;
  2277. for( std::vector<std::string>::iterator i =
  2278. this->Architectures.begin();
  2279. i != this->Architectures.end(); ++i)
  2280. {
  2281. archString += *i;
  2282. archString += " ";
  2283. }
  2284. buildSettings->AddAttribute("ARCHS",
  2285. this->CreateString(archString.c_str()));
  2286. }
  2287. }
  2288. for( std::vector<cmXCodeObject*>::iterator i = configs.begin();
  2289. i != configs.end(); ++i)
  2290. {
  2291. (*i)->AddAttribute("buildSettings", buildSettings);
  2292. }
  2293. this->RootObject->AddAttribute("buildConfigurationList",
  2294. this->CreateObjectReference(configlist));
  2295. std::vector<cmXCodeObject*> targets;
  2296. for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
  2297. i != generators.end(); ++i)
  2298. {
  2299. if(!this->IsExcluded(root, *i))
  2300. {
  2301. this->CreateXCodeTargets(*i, targets);
  2302. }
  2303. }
  2304. // loop over all targets and add link and depend info
  2305. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  2306. i != targets.end(); ++i)
  2307. {
  2308. cmXCodeObject* t = *i;
  2309. this->AddDependAndLinkInformation(t);
  2310. }
  2311. // now create xcode depend hack makefile
  2312. this->CreateXCodeDependHackTarget(targets);
  2313. // now add all targets to the root object
  2314. cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  2315. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  2316. i != targets.end(); ++i)
  2317. {
  2318. cmXCodeObject* t = *i;
  2319. allTargets->AddObject(t);
  2320. cmXCodeObject* productRef = t->GetObject("productReference");
  2321. if(productRef)
  2322. {
  2323. productGroupChildren->AddObject(productRef->GetObject());
  2324. }
  2325. }
  2326. this->RootObject->AddAttribute("targets", allTargets);
  2327. }
  2328. //----------------------------------------------------------------------------
  2329. void
  2330. cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
  2331. std::vector<cmXCodeObject*>& targets)
  2332. {
  2333. cmGeneratedFileStream
  2334. makefileStream(this->CurrentXCodeHackMakefile.c_str());
  2335. if(!makefileStream)
  2336. {
  2337. cmSystemTools::Error("Could not create",
  2338. this->CurrentXCodeHackMakefile.c_str());
  2339. return;
  2340. }
  2341. makefileStream.SetCopyIfDifferent(true);
  2342. // one more pass for external depend information not handled
  2343. // correctly by xcode
  2344. makefileStream << "# DO NOT EDIT\n";
  2345. makefileStream << "# This makefile makes sure all linkable targets are \n";
  2346. makefileStream << "# up-to-date with anything they link to,avoiding a "
  2347. "bug in XCode 1.5\n";
  2348. for(std::vector<std::string>::const_iterator
  2349. ct = this->CurrentConfigurationTypes.begin();
  2350. ct != this->CurrentConfigurationTypes.end(); ++ct)
  2351. {
  2352. if(this->XcodeVersion < 21 || ct->empty())
  2353. {
  2354. makefileStream << "all: ";
  2355. }
  2356. else
  2357. {
  2358. makefileStream << "all." << *ct << ": ";
  2359. }
  2360. const char* configName = 0;
  2361. if(!ct->empty())
  2362. {
  2363. configName = ct->c_str();
  2364. }
  2365. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  2366. i != targets.end(); ++i)
  2367. {
  2368. cmXCodeObject* target = *i;
  2369. cmTarget* t =target->GetTarget();
  2370. if(t->GetType() == cmTarget::EXECUTABLE ||
  2371. t->GetType() == cmTarget::SHARED_LIBRARY ||
  2372. t->GetType() == cmTarget::MODULE_LIBRARY)
  2373. {
  2374. makefileStream << "\\\n\t" <<
  2375. this->ConvertToRelativeForMake(
  2376. t->GetFullPath(configName).c_str());
  2377. }
  2378. }
  2379. makefileStream << "\n\n";
  2380. }
  2381. makefileStream
  2382. << "# For each target create a dummy rule "
  2383. "so the target does not have to exist\n";
  2384. std::set<cmStdString> emitted;
  2385. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  2386. i != targets.end(); ++i)
  2387. {
  2388. cmXCodeObject* target = *i;
  2389. std::map<cmStdString, cmXCodeObject::StringVec> const& deplibs =
  2390. target->GetDependLibraries();
  2391. for(std::map<cmStdString, cmXCodeObject::StringVec>::const_iterator ci
  2392. = deplibs.begin(); ci != deplibs.end(); ++ci)
  2393. {
  2394. for(cmXCodeObject::StringVec::const_iterator d = ci->second.begin();
  2395. d != ci->second.end(); ++d)
  2396. {
  2397. if(emitted.insert(*d).second)
  2398. {
  2399. makefileStream <<
  2400. this->ConvertToRelativeForMake(d->c_str()) << ":\n";
  2401. }
  2402. }
  2403. }
  2404. }
  2405. makefileStream << "\n\n";
  2406. // Write rules to help Xcode relink things at the right time.
  2407. makefileStream <<
  2408. "# Rules to remove targets that are older than anything to which they\n"
  2409. "# link. This forces Xcode to relink the targets from scratch. It\n"
  2410. "# does not seem to check these dependencies itself.\n";
  2411. for(std::vector<std::string>::const_iterator
  2412. ct = this->CurrentConfigurationTypes.begin();
  2413. ct != this->CurrentConfigurationTypes.end(); ++ct)
  2414. {
  2415. const char* configName = 0;
  2416. if(!ct->empty())
  2417. {
  2418. configName = ct->c_str();
  2419. }
  2420. for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
  2421. i != targets.end(); ++i)
  2422. {
  2423. cmXCodeObject* target = *i;
  2424. cmTarget* t =target->GetTarget();
  2425. if(t->GetType() == cmTarget::EXECUTABLE ||
  2426. t->GetType() == cmTarget::SHARED_LIBRARY ||
  2427. t->GetType() == cmTarget::MODULE_LIBRARY)
  2428. {
  2429. // Create a rule for this target.
  2430. std::string tfull = t->GetFullPath(configName);
  2431. makefileStream << this->ConvertToRelativeForMake(tfull.c_str())
  2432. << ":";
  2433. // List dependencies if any exist.
  2434. std::map<cmStdString, cmXCodeObject::StringVec>::const_iterator
  2435. x = target->GetDependLibraries().find(*ct);
  2436. if(x != target->GetDependLibraries().end())
  2437. {
  2438. std::vector<cmStdString> const& deplibs = x->second;
  2439. for(std::vector<cmStdString>::const_iterator d = deplibs.begin();
  2440. d != deplibs.end(); ++d)
  2441. {
  2442. makefileStream << "\\\n\t" <<
  2443. this->ConvertToRelativeForMake(d->c_str());
  2444. }
  2445. }
  2446. // Write the action to remove the target if it is out of date.
  2447. makefileStream << "\n";
  2448. makefileStream << "\t/bin/rm -f "
  2449. << this->ConvertToRelativeForMake(tfull.c_str())
  2450. << "\n";
  2451. // if building for more than one architecture
  2452. // then remove those exectuables as well
  2453. if(this->Architectures.size() > 1)
  2454. {
  2455. std::string universal = t->GetDirectory();
  2456. universal += "/";
  2457. universal += this->CurrentMakefile->GetProjectName();
  2458. universal += ".build/";
  2459. universal += configName;
  2460. universal += "/";
  2461. universal += t->GetName();
  2462. universal += ".build/Objects-normal/";
  2463. for( std::vector<std::string>::iterator arch =
  2464. this->Architectures.begin();
  2465. arch != this->Architectures.end(); ++arch)
  2466. {
  2467. std::string universalFile = universal;
  2468. universalFile += *arch;
  2469. universalFile += "/";
  2470. universalFile += t->GetName();
  2471. makefileStream << "\t/bin/rm -f "
  2472. <<
  2473. this->ConvertToRelativeForMake(universalFile.c_str())
  2474. << "\n";
  2475. }
  2476. }
  2477. makefileStream << "\n\n";
  2478. }
  2479. }
  2480. }
  2481. }
  2482. //----------------------------------------------------------------------------
  2483. void
  2484. cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
  2485. std::vector<cmLocalGenerator*>&
  2486. generators)
  2487. {
  2488. if(generators.size() == 0)
  2489. {
  2490. return;
  2491. }
  2492. // Skip local generators that are excluded from this project.
  2493. for(std::vector<cmLocalGenerator*>::iterator g = generators.begin();
  2494. g != generators.end(); ++g)
  2495. {
  2496. if(this->IsExcluded(root, *g))
  2497. {
  2498. continue;
  2499. }
  2500. }
  2501. this->CreateXCodeObjects(root,
  2502. generators);
  2503. std::string xcodeDir = root->GetMakefile()->GetStartOutputDirectory();
  2504. xcodeDir += "/";
  2505. xcodeDir += root->GetMakefile()->GetProjectName();
  2506. xcodeDir += ".xcode";
  2507. if(this->XcodeVersion > 20)
  2508. {
  2509. xcodeDir += "proj";
  2510. }
  2511. cmSystemTools::MakeDirectory(xcodeDir.c_str());
  2512. std::string xcodeProjFile = xcodeDir + "/project.pbxproj";
  2513. cmGeneratedFileStream fout(xcodeProjFile.c_str());
  2514. fout.SetCopyIfDifferent(true);
  2515. if(!fout)
  2516. {
  2517. return;
  2518. }
  2519. this->WriteXCodePBXProj(fout, root, generators);
  2520. this->ClearXCodeObjects();
  2521. }
  2522. //----------------------------------------------------------------------------
  2523. void
  2524. cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
  2525. cmLocalGenerator* ,
  2526. std::vector<cmLocalGenerator*>& )
  2527. {
  2528. fout << "// !$*UTF8*$!\n";
  2529. fout << "{\n";
  2530. cmXCodeObject::Indent(1, fout);
  2531. fout << "archiveVersion = 1;\n";
  2532. cmXCodeObject::Indent(1, fout);
  2533. fout << "classes = {\n";
  2534. cmXCodeObject::Indent(1, fout);
  2535. fout << "};\n";
  2536. cmXCodeObject::Indent(1, fout);
  2537. fout << "objectVersion = 39;\n";
  2538. cmXCodeObject::PrintList(this->XCodeObjects, fout);
  2539. cmXCodeObject::Indent(1, fout);
  2540. fout << "rootObject = " << this->RootObject->GetId() << ";\n";
  2541. fout << "}\n";
  2542. }
  2543. //----------------------------------------------------------------------------
  2544. void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry)
  2545. const
  2546. {
  2547. entry.name = this->GetName();
  2548. entry.brief = "Generate XCode project files.";
  2549. entry.full = "";
  2550. }
  2551. //----------------------------------------------------------------------------
  2552. std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(const char* p)
  2553. {
  2554. if ( !this->CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  2555. {
  2556. return cmSystemTools::ConvertToOutputPath(p);
  2557. }
  2558. else
  2559. {
  2560. std::string ret =
  2561. this->CurrentLocalGenerator->
  2562. ConvertToRelativePath(this->CurrentOutputDirectoryComponents, p);
  2563. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  2564. }
  2565. }
  2566. //----------------------------------------------------------------------------
  2567. std::string cmGlobalXCodeGenerator::ConvertToRelativeForXCode(const char* p)
  2568. {
  2569. if ( !this->CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
  2570. {
  2571. return cmSystemTools::ConvertToOutputPath(p);
  2572. }
  2573. else
  2574. {
  2575. std::string ret =
  2576. this->CurrentLocalGenerator->
  2577. ConvertToRelativePath(this->ProjectOutputDirectoryComponents, p);
  2578. return cmSystemTools::ConvertToOutputPath(ret.c_str());
  2579. }
  2580. }
  2581. //----------------------------------------------------------------------------
  2582. std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p)
  2583. {
  2584. std::string ret = p;
  2585. if(ret.find(' ') != ret.npos)
  2586. {
  2587. std::string t = ret;
  2588. ret = "\"";
  2589. ret += t;
  2590. ret += "\"";
  2591. }
  2592. return ret;
  2593. }
  2594. //----------------------------------------------------------------------------
  2595. void cmGlobalXCodeGenerator::
  2596. GetTargetObjectFileDirectories(cmTarget* target,
  2597. std::vector<std::string>&
  2598. dirs)
  2599. {
  2600. std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory();
  2601. dir += "/";
  2602. dir += this->CurrentMakefile->GetProjectName();
  2603. dir += ".build/";
  2604. dir += this->GetCMakeCFGInitDirectory();
  2605. dir += "/";
  2606. if(target->GetType() != cmTarget::EXECUTABLE)
  2607. {
  2608. dir += "lib";
  2609. }
  2610. dir += target->GetName();
  2611. if(target->GetType() == cmTarget::STATIC_LIBRARY)
  2612. {
  2613. dir += ".a";
  2614. }
  2615. if(target->GetType() == cmTarget::SHARED_LIBRARY)
  2616. {
  2617. dir += ".dylib";
  2618. }
  2619. if(target->GetType() == cmTarget::MODULE_LIBRARY)
  2620. {
  2621. dir += ".so";
  2622. }
  2623. dir += ".build/Objects-normal/";
  2624. std::string dirsave = dir;
  2625. if(this->Architectures.size())
  2626. {
  2627. for(std::vector<std::string>::iterator i = this->Architectures.begin();
  2628. i != this->Architectures.end(); ++i)
  2629. {
  2630. dir += *i;
  2631. dirs.push_back(dir);
  2632. dir = dirsave;
  2633. }
  2634. }
  2635. else
  2636. {
  2637. dirs.push_back(dir);
  2638. }
  2639. }
  2640. //----------------------------------------------------------------------------
  2641. void
  2642. cmGlobalXCodeGenerator
  2643. ::AppendDirectoryForConfig(const char* prefix,
  2644. const char* config,
  2645. const char* suffix,
  2646. std::string& dir)
  2647. {
  2648. if(this->XcodeVersion > 20)
  2649. {
  2650. if(config)
  2651. {
  2652. if(dir.find(".framework") != dir.npos)
  2653. {
  2654. std::string::size_type pos = dir.rfind("/");
  2655. std::string framework = dir.substr(pos);
  2656. std::string newDir;
  2657. newDir = dir.substr(0, pos);
  2658. newDir += "/";
  2659. newDir += config;
  2660. dir = newDir;
  2661. }
  2662. else
  2663. {
  2664. dir += prefix;
  2665. dir += config;
  2666. dir += suffix;
  2667. }
  2668. }
  2669. }
  2670. }
  2671. //----------------------------------------------------------------------------
  2672. std::string cmGlobalXCodeGenerator::LookupFlags(const char* varNamePrefix,
  2673. const char* varNameLang,
  2674. const char* varNameSuffix,
  2675. const char* default_flags)
  2676. {
  2677. if(varNameLang)
  2678. {
  2679. std::string varName = varNamePrefix;
  2680. varName += varNameLang;
  2681. varName += varNameSuffix;
  2682. if(const char* varValue =
  2683. this->CurrentMakefile->GetDefinition(varName.c_str()))
  2684. {
  2685. if(*varValue)
  2686. {
  2687. return varValue;
  2688. }
  2689. }
  2690. }
  2691. return default_flags;
  2692. }