cmGlobalXCodeGenerator.cxx 97 KB

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