cmGlobalXCodeGenerator.cxx 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883
  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. std::cerr << "**** build command " << makeCommand.c_str() << "\n";
  204. return makeCommand;
  205. }
  206. //----------------------------------------------------------------------------
  207. ///! Create a local generator appropriate to this Global Generator
  208. cmLocalGenerator *cmGlobalXCodeGenerator::CreateLocalGenerator()
  209. {
  210. cmLocalGenerator *lg = new cmLocalXCodeGenerator;
  211. lg->SetGlobalGenerator(this);
  212. return lg;
  213. }
  214. //----------------------------------------------------------------------------
  215. void cmGlobalXCodeGenerator::Generate()
  216. {
  217. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  218. // make sure extra targets are added before calling
  219. // the parent generate which will call trace depends
  220. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  221. {
  222. cmLocalGenerator* root = it->second[0];
  223. this->SetGenerationRoot(root);
  224. // add ALL_BUILD, INSTALL, etc
  225. this->AddExtraTargets(root, it->second);
  226. }
  227. this->cmGlobalGenerator::Generate();
  228. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  229. {
  230. cmLocalGenerator* root = it->second[0];
  231. this->SetGenerationRoot(root);
  232. // now create the project
  233. this->OutputXCodeProject(root, it->second);
  234. }
  235. }
  236. //----------------------------------------------------------------------------
  237. void cmGlobalXCodeGenerator::SetGenerationRoot(cmLocalGenerator* root)
  238. {
  239. this->CurrentProject = root->GetMakefile()->GetProjectName();
  240. this->SetCurrentLocalGenerator(root);
  241. std::string outDir = this->CurrentMakefile->GetHomeOutputDirectory();
  242. outDir =cmSystemTools::CollapseFullPath(outDir.c_str());
  243. cmSystemTools::SplitPath(outDir.c_str(),
  244. this->ProjectOutputDirectoryComponents);
  245. this->CurrentXCodeHackMakefile =
  246. root->GetMakefile()->GetCurrentOutputDirectory();
  247. this->CurrentXCodeHackMakefile += "/CMakeScripts";
  248. cmSystemTools::MakeDirectory(this->CurrentXCodeHackMakefile.c_str());
  249. this->CurrentXCodeHackMakefile += "/XCODE_DEPEND_HELPER.make";
  250. }
  251. //----------------------------------------------------------------------------
  252. void
  253. cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
  254. std::vector<cmLocalGenerator*>& gens)
  255. {
  256. cmMakefile* mf = root->GetMakefile();
  257. // Add ALL_BUILD
  258. const char* no_working_directory = 0;
  259. std::vector<std::string> no_depends;
  260. mf->AddUtilityCommand("ALL_BUILD", true, no_depends,
  261. no_working_directory,
  262. "echo", "Build all projects");
  263. cmTarget* allbuild = mf->FindTarget("ALL_BUILD", false);
  264. // Add XCODE depend helper
  265. std::string dir = mf->GetCurrentOutputDirectory();
  266. cmCustomCommandLine makecommand;
  267. makecommand.push_back("make");
  268. makecommand.push_back("-C");
  269. makecommand.push_back(dir.c_str());
  270. makecommand.push_back("-f");
  271. makecommand.push_back(this->CurrentXCodeHackMakefile.c_str());
  272. if(this->XcodeVersion > 20)
  273. {
  274. makecommand.push_back("all.$(CONFIGURATION)");
  275. }
  276. cmCustomCommandLines commandLines;
  277. commandLines.push_back(makecommand);
  278. mf->AddUtilityCommand("XCODE_DEPEND_HELPER", true,
  279. no_working_directory,
  280. no_depends,
  281. commandLines);
  282. // Add Re-Run CMake rules
  283. this->CreateReRunCMakeFile(root);
  284. // now make the allbuild depend on all the non-utility targets
  285. // in the project
  286. for(std::vector<cmLocalGenerator*>::iterator i = gens.begin();
  287. i != gens.end(); ++i)
  288. {
  289. cmLocalGenerator* lg = *i;
  290. if(this->IsExcluded(root, *i))
  291. {
  292. continue;
  293. }
  294. cmTargets& tgts = lg->GetMakefile()->GetTargets();
  295. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  296. {
  297. cmTarget& target = l->second;
  298. // make all exe, shared libs and modules depend
  299. // on the XCODE_DEPEND_HELPER target
  300. if((target.GetType() == cmTarget::EXECUTABLE ||
  301. target.GetType() == cmTarget::SHARED_LIBRARY ||
  302. target.GetType() == cmTarget::MODULE_LIBRARY))
  303. {
  304. target.AddUtility("XCODE_DEPEND_HELPER");
  305. }
  306. if(!target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  307. {
  308. allbuild->AddUtility(target.GetName());
  309. }
  310. }
  311. }
  312. }
  313. //----------------------------------------------------------------------------
  314. void cmGlobalXCodeGenerator::CreateReRunCMakeFile(cmLocalGenerator* root)
  315. {
  316. cmMakefile* mf = root->GetMakefile();
  317. std::vector<std::string> lfiles = mf->GetListFiles();
  318. // sort the array
  319. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
  320. std::vector<std::string>::iterator new_end =
  321. std::unique(lfiles.begin(), lfiles.end());
  322. lfiles.erase(new_end, lfiles.end());
  323. std::string dir = mf->GetHomeOutputDirectory();
  324. this->CurrentReRunCMakeMakefile = dir;
  325. this->CurrentReRunCMakeMakefile += "/CMakeScripts";
  326. cmSystemTools::MakeDirectory(this->CurrentReRunCMakeMakefile.c_str());
  327. this->CurrentReRunCMakeMakefile += "/ReRunCMake.make";
  328. cmGeneratedFileStream makefileStream
  329. (this->CurrentReRunCMakeMakefile.c_str());
  330. makefileStream.SetCopyIfDifferent(true);
  331. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  332. makefileStream << cmake::GetCMakeFilesDirectoryPostSlash();
  333. makefileStream << "cmake.check_cache: ";
  334. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  335. i != lfiles.end(); ++i)
  336. {
  337. makefileStream << "\\\n" << this->ConvertToRelativeForMake(i->c_str());
  338. }
  339. std::string cmake = mf->GetRequiredDefinition("CMAKE_COMMAND");
  340. makefileStream << "\n\t" << this->ConvertToRelativeForMake(cmake.c_str())
  341. << " -H" << this->ConvertToRelativeForMake(
  342. mf->GetHomeDirectory())
  343. << " -B" << this->ConvertToRelativeForMake(
  344. mf->GetHomeOutputDirectory()) << "\n";
  345. }
  346. //----------------------------------------------------------------------------
  347. void cmGlobalXCodeGenerator::ClearXCodeObjects()
  348. {
  349. this->TargetDoneSet.clear();
  350. for(unsigned int i = 0; i < this->XCodeObjects.size(); ++i)
  351. {
  352. delete this->XCodeObjects[i];
  353. }
  354. this->XCodeObjects.clear();
  355. this->GroupMap.clear();
  356. this->GroupNameMap.clear();
  357. this->TargetGroup.clear();
  358. this->FileRefs.clear();
  359. }
  360. //----------------------------------------------------------------------------
  361. cmXCodeObject*
  362. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
  363. {
  364. cmXCodeObject* obj;
  365. if(this->XcodeVersion == 15)
  366. {
  367. obj = new cmXCodeObject(ptype, cmXCodeObject::OBJECT);
  368. }
  369. else
  370. {
  371. obj = new cmXCode21Object(ptype, cmXCodeObject::OBJECT);
  372. }
  373. this->XCodeObjects.push_back(obj);
  374. return obj;
  375. }
  376. //----------------------------------------------------------------------------
  377. cmXCodeObject*
  378. cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
  379. {
  380. cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, type);
  381. this->XCodeObjects.push_back(obj);
  382. return obj;
  383. }
  384. //----------------------------------------------------------------------------
  385. cmXCodeObject*
  386. cmGlobalXCodeGenerator::CreateString(const char* s)
  387. {
  388. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::STRING);
  389. obj->SetString(s);
  390. return obj;
  391. }
  392. //----------------------------------------------------------------------------
  393. cmXCodeObject* cmGlobalXCodeGenerator
  394. ::CreateObjectReference(cmXCodeObject* ref)
  395. {
  396. cmXCodeObject* obj = this->CreateObject(cmXCodeObject::OBJECT_REF);
  397. obj->SetObject(ref);
  398. return obj;
  399. }
  400. //----------------------------------------------------------------------------
  401. cmStdString GetGroupMapKey(cmTarget& cmtarget, cmSourceFile* sf)
  402. {
  403. cmStdString key(cmtarget.GetName());
  404. key += "-";
  405. key += sf->GetFullPath();
  406. return key;
  407. }
  408. //----------------------------------------------------------------------------
  409. cmXCodeObject*
  410. cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
  411. cmSourceFile* sf,
  412. cmTarget& cmtarget)
  413. {
  414. // Add flags from target and source file properties.
  415. std::string flags;
  416. if(cmtarget.GetProperty("COMPILE_FLAGS"))
  417. {
  418. lg->AppendFlags(flags, cmtarget.GetProperty("COMPILE_FLAGS"));
  419. }
  420. lg->AppendFlags(flags, sf->GetProperty("COMPILE_FLAGS"));
  421. cmSystemTools::ReplaceString(flags, "\"", "\\\"");
  422. // Using a map and the full path guarantees that we will always get the same
  423. // fileRef object for any given full path.
  424. //
  425. std::string fname = sf->GetFullPath();
  426. cmXCodeObject* fileRef = this->FileRefs[fname];
  427. if(!fileRef)
  428. {
  429. fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
  430. std::string comment = fname;
  431. comment += " in ";
  432. //std::string gname = group->GetObject("name")->GetString();
  433. //comment += gname.substr(1, gname.size()-2);
  434. fileRef->SetComment(fname.c_str());
  435. this->FileRefs[fname] = fileRef;
  436. }
  437. cmStdString key = GetGroupMapKey(cmtarget, sf);
  438. cmXCodeObject* group = this->GroupMap[key];
  439. cmXCodeObject* children = group->GetObject("children");
  440. if (!children->HasObject(fileRef))
  441. {
  442. children->AddObject(fileRef);
  443. }
  444. cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
  445. buildFile->SetComment(fileRef->GetComment());
  446. buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef));
  447. cmXCodeObject* settings =
  448. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  449. settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags.c_str()));
  450. // Is this a resource file in this target? Add it to the resources group...
  451. //
  452. cmTarget::SourceFileFlags tsFlags = cmtarget.GetTargetSourceFileFlags(sf);
  453. bool isResource = tsFlags.Resource;
  454. // Is this a "private" or "public" framework header file?
  455. // Set the ATTRIBUTES attribute appropriately...
  456. //
  457. if(cmtarget.GetType() == cmTarget::SHARED_LIBRARY &&
  458. cmtarget.GetPropertyAsBool("FRAMEWORK"))
  459. {
  460. if(tsFlags.PrivateHeader)
  461. {
  462. cmXCodeObject* attrs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  463. attrs->AddObject(this->CreateString("Private"));
  464. settings->AddAttribute("ATTRIBUTES", attrs);
  465. isResource = true;
  466. }
  467. else if(tsFlags.PublicHeader)
  468. {
  469. cmXCodeObject* attrs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  470. attrs->AddObject(this->CreateString("Public"));
  471. settings->AddAttribute("ATTRIBUTES", attrs);
  472. isResource = true;
  473. }
  474. }
  475. // Add the fileRef to the top level Resources group/folder if it is not
  476. // already there.
  477. //
  478. if(isResource && this->ResourcesGroupChildren &&
  479. !this->ResourcesGroupChildren->HasObject(fileRef))
  480. {
  481. this->ResourcesGroupChildren->AddObject(fileRef);
  482. }
  483. buildFile->AddAttribute("settings", settings);
  484. fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
  485. const char* lang =
  486. this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
  487. std::string sourcecode = "sourcecode";
  488. std::string ext = sf->GetExtension();
  489. ext = cmSystemTools::LowerCase(ext);
  490. if(ext == "o")
  491. {
  492. sourcecode = "compiled.mach-o.objfile";
  493. }
  494. else if(ext == "mm")
  495. {
  496. sourcecode += ".cpp.objcpp";
  497. }
  498. else if(ext == "m")
  499. {
  500. sourcecode += ".cpp.objc";
  501. }
  502. else if(ext == "plist")
  503. {
  504. sourcecode += ".text.plist";
  505. }
  506. else if(!lang)
  507. {
  508. sourcecode += ext;
  509. sourcecode += ".";
  510. sourcecode += ext;
  511. }
  512. else if(strcmp(lang, "C") == 0)
  513. {
  514. sourcecode += ".c.c";
  515. }
  516. else if(strcmp(lang, "CXX") == 0)
  517. {
  518. sourcecode += ".cpp.cpp";
  519. }
  520. else
  521. {
  522. sourcecode += ext;
  523. sourcecode += ".";
  524. sourcecode += ext;
  525. }
  526. fileRef->AddAttribute("lastKnownFileType",
  527. this->CreateString(sourcecode.c_str()));
  528. std::string path =
  529. this->ConvertToRelativeForXCode(sf->GetFullPath().c_str());
  530. std::string dir;
  531. std::string file;
  532. cmSystemTools::SplitProgramPath(sf->GetFullPath().c_str(),
  533. dir, file);
  534. fileRef->AddAttribute("name", this->CreateString(file.c_str()));
  535. fileRef->AddAttribute("path", this->CreateString(path.c_str()));
  536. if(this->XcodeVersion == 15)
  537. {
  538. fileRef->AddAttribute("refType", this->CreateString("4"));
  539. }
  540. if(path.size() > 1 && path[0] == '.' && path[1] == '.')
  541. {
  542. fileRef->AddAttribute("sourceTree", this->CreateString("<group>"));
  543. }
  544. else
  545. {
  546. fileRef->AddAttribute("sourceTree", this->CreateString("<absolute>"));
  547. }
  548. return buildFile;
  549. }
  550. //----------------------------------------------------------------------------
  551. bool cmGlobalXCodeGenerator::SpecialTargetEmitted(std::string const& tname)
  552. {
  553. if(tname == "ALL_BUILD" || tname == "XCODE_DEPEND_HELPER" ||
  554. tname == "install" || tname == "package" || tname == "RUN_TESTS" )
  555. {
  556. if(this->TargetDoneSet.find(tname) != this->TargetDoneSet.end())
  557. {
  558. return true;
  559. }
  560. this->TargetDoneSet.insert(tname);
  561. return false;
  562. }
  563. return false;
  564. }
  565. //----------------------------------------------------------------------------
  566. void cmGlobalXCodeGenerator::SetCurrentLocalGenerator(cmLocalGenerator* gen)
  567. {
  568. this->CurrentLocalGenerator = gen;
  569. this->CurrentMakefile = gen->GetMakefile();
  570. std::string outdir =
  571. cmSystemTools::CollapseFullPath(this->CurrentMakefile->
  572. GetCurrentOutputDirectory());
  573. cmSystemTools::SplitPath(outdir.c_str(),
  574. this->CurrentOutputDirectoryComponents);
  575. // Select the current set of configuration types.
  576. this->CurrentConfigurationTypes.clear();
  577. if(this->XcodeVersion > 20)
  578. {
  579. if(const char* types =
  580. this->CurrentMakefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  581. {
  582. cmSystemTools::ExpandListArgument(types,
  583. this->CurrentConfigurationTypes);
  584. }
  585. }
  586. if(this->CurrentConfigurationTypes.empty())
  587. {
  588. if(const char* buildType =
  589. this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE"))
  590. {
  591. this->CurrentConfigurationTypes.push_back(buildType);
  592. }
  593. else
  594. {
  595. this->CurrentConfigurationTypes.push_back("");
  596. }
  597. }
  598. }
  599. //----------------------------------------------------------------------------
  600. void
  601. cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
  602. std::vector<cmXCodeObject*>&
  603. targets)
  604. {
  605. this->SetCurrentLocalGenerator(gen);
  606. cmTargets &tgts = this->CurrentMakefile->GetTargets();
  607. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  608. {
  609. cmTarget& cmtarget = l->second;
  610. // make sure ALL_BUILD, INSTALL, etc are only done once
  611. if(this->SpecialTargetEmitted(l->first.c_str()))
  612. {
  613. continue;
  614. }
  615. if(cmtarget.GetType() == cmTarget::UTILITY ||
  616. cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
  617. {
  618. targets.push_back(this->CreateUtilityTarget(cmtarget));
  619. continue;
  620. }
  621. // organize the sources
  622. std::vector<cmSourceFile*> const &classes = cmtarget.GetSourceFiles();
  623. std::vector<cmXCodeObject*> externalObjFiles;
  624. std::vector<cmXCodeObject*> headerFiles;
  625. std::vector<cmXCodeObject*> resourceFiles;
  626. std::vector<cmXCodeObject*> sourceFiles;
  627. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  628. i != classes.end(); ++i)
  629. {
  630. cmXCodeObject* xsf =
  631. this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
  632. *i, cmtarget);
  633. cmXCodeObject* fr = xsf->GetObject("fileRef");
  634. cmXCodeObject* filetype =
  635. fr->GetObject()->GetObject("lastKnownFileType");
  636. cmTarget::SourceFileFlags tsFlags =
  637. cmtarget.GetTargetSourceFileFlags(*i);
  638. if(strcmp(filetype->GetString(), "\"compiled.mach-o.objfile\"") == 0)
  639. {
  640. externalObjFiles.push_back(xsf);
  641. }
  642. else if((*i)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  643. {
  644. headerFiles.push_back(xsf);
  645. }
  646. else if(tsFlags.Resource)
  647. {
  648. resourceFiles.push_back(xsf);
  649. }
  650. else
  651. {
  652. sourceFiles.push_back(xsf);
  653. }
  654. }
  655. // some build phases only apply to bundles and/or frameworks
  656. bool isFrameworkTarget = cmtarget.GetType() == cmTarget::SHARED_LIBRARY &&
  657. cmtarget.GetPropertyAsBool("FRAMEWORK");
  658. bool isBundleTarget = cmtarget.GetPropertyAsBool("MACOSX_BUNDLE");
  659. cmXCodeObject* buildFiles = 0;
  660. // create source build phase
  661. cmXCodeObject* sourceBuildPhase = 0;
  662. if (!sourceFiles.empty())
  663. {
  664. sourceBuildPhase =
  665. this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
  666. sourceBuildPhase->SetComment("Sources");
  667. sourceBuildPhase->AddAttribute("buildActionMask",
  668. this->CreateString("2147483647"));
  669. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  670. for(std::vector<cmXCodeObject*>::iterator i = sourceFiles.begin();
  671. i != sourceFiles.end(); ++i)
  672. {
  673. buildFiles->AddObject(*i);
  674. }
  675. sourceBuildPhase->AddAttribute("files", buildFiles);
  676. sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  677. this->CreateString("0"));
  678. }
  679. // create header build phase - only for framework targets
  680. cmXCodeObject* headerBuildPhase = 0;
  681. if (!headerFiles.empty() && isFrameworkTarget)
  682. {
  683. headerBuildPhase =
  684. this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase);
  685. headerBuildPhase->SetComment("Headers");
  686. headerBuildPhase->AddAttribute("buildActionMask",
  687. this->CreateString("2147483647"));
  688. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  689. for(std::vector<cmXCodeObject*>::iterator i = headerFiles.begin();
  690. i != headerFiles.end(); ++i)
  691. {
  692. buildFiles->AddObject(*i);
  693. }
  694. headerBuildPhase->AddAttribute("files", buildFiles);
  695. headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  696. this->CreateString("0"));
  697. }
  698. // create resource build phase - only for framework or bundle targets
  699. cmXCodeObject* resourceBuildPhase = 0;
  700. if (!resourceFiles.empty() && (isFrameworkTarget || isBundleTarget))
  701. {
  702. resourceBuildPhase =
  703. this->CreateObject(cmXCodeObject::PBXResourcesBuildPhase);
  704. resourceBuildPhase->SetComment("Resources");
  705. resourceBuildPhase->AddAttribute("buildActionMask",
  706. this->CreateString("2147483647"));
  707. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  708. for(std::vector<cmXCodeObject*>::iterator i = resourceFiles.begin();
  709. i != resourceFiles.end(); ++i)
  710. {
  711. buildFiles->AddObject(*i);
  712. }
  713. resourceBuildPhase->AddAttribute("files", buildFiles);
  714. resourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  715. this->CreateString("0"));
  716. }
  717. // create vector of "non-resource content file" build phases - only for
  718. // framework or bundle targets
  719. std::vector<cmXCodeObject*> contentBuildPhases;
  720. if (isFrameworkTarget || isBundleTarget)
  721. {
  722. typedef std::map<cmStdString, std::vector<cmSourceFile*> >
  723. mapOfVectorOfSourceFiles;
  724. mapOfVectorOfSourceFiles bundleFiles;
  725. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  726. i != classes.end(); ++i)
  727. {
  728. const char* contentLoc = (*i)->GetProperty("MACOSX_PACKAGE_LOCATION");
  729. if ( !contentLoc || cmStdString(contentLoc) == "Resources" )
  730. {
  731. continue;
  732. }
  733. bundleFiles[contentLoc].push_back(*i);
  734. }
  735. mapOfVectorOfSourceFiles::iterator mit;
  736. for ( mit = bundleFiles.begin(); mit != bundleFiles.end(); ++ mit )
  737. {
  738. cmXCodeObject* copyFilesBuildPhase =
  739. this->CreateObject(cmXCodeObject::PBXCopyFilesBuildPhase);
  740. copyFilesBuildPhase->SetComment("Copy files");
  741. copyFilesBuildPhase->AddAttribute("buildActionMask",
  742. this->CreateString("2147483647"));
  743. copyFilesBuildPhase->AddAttribute("dstSubfolderSpec",
  744. this->CreateString("6"));
  745. cmOStringStream ostr;
  746. if ( mit->first != "MacOS" )
  747. {
  748. ostr << "../" << mit->first.c_str();
  749. }
  750. copyFilesBuildPhase->AddAttribute("dstPath",
  751. this->CreateString(ostr.str().c_str()));
  752. copyFilesBuildPhase->AddAttribute(
  753. "runOnlyForDeploymentPostprocessing", this->CreateString("0"));
  754. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  755. copyFilesBuildPhase->AddAttribute("files", buildFiles);
  756. std::vector<cmSourceFile*>::iterator sfIt;
  757. for ( sfIt = mit->second.begin(); sfIt != mit->second.end(); ++ sfIt )
  758. {
  759. cmXCodeObject* xsf =
  760. this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
  761. *sfIt, cmtarget);
  762. buildFiles->AddObject(xsf);
  763. }
  764. contentBuildPhases.push_back(copyFilesBuildPhase);
  765. }
  766. }
  767. // create framework build phase
  768. cmXCodeObject* frameworkBuildPhase = 0;
  769. if (!externalObjFiles.empty())
  770. {
  771. frameworkBuildPhase =
  772. this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
  773. frameworkBuildPhase->SetComment("Frameworks");
  774. frameworkBuildPhase->AddAttribute("buildActionMask",
  775. this->CreateString("2147483647"));
  776. buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  777. frameworkBuildPhase->AddAttribute("files", buildFiles);
  778. for(std::vector<cmXCodeObject*>::iterator i = externalObjFiles.begin();
  779. i != externalObjFiles.end(); ++i)
  780. {
  781. buildFiles->AddObject(*i);
  782. }
  783. frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  784. this->CreateString("0"));
  785. }
  786. // create list of build phases and create the XCode target
  787. cmXCodeObject* buildPhases =
  788. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  789. this->CreateCustomCommands(buildPhases, sourceBuildPhase,
  790. headerBuildPhase, resourceBuildPhase,
  791. contentBuildPhases,
  792. frameworkBuildPhase, cmtarget);
  793. targets.push_back(this->CreateXCodeTarget(cmtarget, buildPhases));
  794. }
  795. }
  796. //----------------------------------------------------------------------------
  797. cmXCodeObject*
  798. cmGlobalXCodeGenerator::CreateBuildPhase(const char* name,
  799. const char* name2,
  800. cmTarget& cmtarget,
  801. const std::vector<cmCustomCommand>&
  802. commands)
  803. {
  804. if(commands.size() == 0 && strcmp(name, "CMake ReRun") != 0)
  805. {
  806. return 0;
  807. }
  808. cmXCodeObject* buildPhase =
  809. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  810. buildPhase->AddAttribute("buildActionMask",
  811. this->CreateString("2147483647"));
  812. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  813. buildPhase->AddAttribute("files", buildFiles);
  814. buildPhase->AddAttribute("name",
  815. this->CreateString(name));
  816. buildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  817. this->CreateString("0"));
  818. buildPhase->AddAttribute("shellPath",
  819. this->CreateString("/bin/sh"));
  820. this->AddCommandsToBuildPhase(buildPhase, cmtarget, commands,
  821. name2);
  822. return buildPhase;
  823. }
  824. //----------------------------------------------------------------------------
  825. void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
  826. cmXCodeObject*
  827. sourceBuildPhase,
  828. cmXCodeObject*
  829. headerBuildPhase,
  830. cmXCodeObject*
  831. resourceBuildPhase,
  832. std::vector<cmXCodeObject*>
  833. contentBuildPhases,
  834. cmXCodeObject*
  835. frameworkBuildPhase,
  836. cmTarget& cmtarget)
  837. {
  838. std::vector<cmCustomCommand> const & prebuild
  839. = cmtarget.GetPreBuildCommands();
  840. std::vector<cmCustomCommand> const & prelink
  841. = cmtarget.GetPreLinkCommands();
  842. std::vector<cmCustomCommand> const & postbuild
  843. = cmtarget.GetPostBuildCommands();
  844. std::vector<cmSourceFile*>const &classes = cmtarget.GetSourceFiles();
  845. // add all the sources
  846. std::vector<cmCustomCommand> commands;
  847. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  848. i != classes.end(); ++i)
  849. {
  850. if((*i)->GetCustomCommand())
  851. {
  852. commands.push_back(*(*i)->GetCustomCommand());
  853. }
  854. }
  855. std::vector<cmCustomCommand> reruncom;
  856. cmXCodeObject* cmakeReRunPhase =
  857. this->CreateBuildPhase("CMake ReRun", "cmakeReRunPhase",
  858. cmtarget, reruncom);
  859. buildPhases->AddObject(cmakeReRunPhase);
  860. // create prebuild phase
  861. cmXCodeObject* cmakeRulesBuildPhase =
  862. this->CreateBuildPhase("CMake Rules",
  863. "cmakeRulesBuildPhase",
  864. cmtarget, commands);
  865. // create prebuild phase
  866. cmXCodeObject* preBuildPhase =
  867. this->CreateBuildPhase("CMake PreBuild Rules", "preBuildCommands",
  868. cmtarget, prebuild);
  869. // create prelink phase
  870. cmXCodeObject* preLinkPhase =
  871. this->CreateBuildPhase("CMake PreLink Rules", "preLinkCommands",
  872. cmtarget, prelink);
  873. // create postbuild phase
  874. cmXCodeObject* postBuildPhase =
  875. this->CreateBuildPhase("CMake PostBuild Rules", "postBuildPhase",
  876. cmtarget, postbuild);
  877. // The order here is the order they will be built in.
  878. // The order "headers, resources, sources" mimics a native project generated
  879. // from an xcode template...
  880. //
  881. if(preBuildPhase)
  882. {
  883. buildPhases->AddObject(preBuildPhase);
  884. }
  885. if(cmakeRulesBuildPhase)
  886. {
  887. buildPhases->AddObject(cmakeRulesBuildPhase);
  888. }
  889. if(headerBuildPhase)
  890. {
  891. buildPhases->AddObject(headerBuildPhase);
  892. }
  893. if(resourceBuildPhase)
  894. {
  895. buildPhases->AddObject(resourceBuildPhase);
  896. }
  897. std::vector<cmXCodeObject*>::iterator cit;
  898. for (cit = contentBuildPhases.begin(); cit != contentBuildPhases.end();
  899. ++cit)
  900. {
  901. buildPhases->AddObject(*cit);
  902. }
  903. if(sourceBuildPhase)
  904. {
  905. buildPhases->AddObject(sourceBuildPhase);
  906. }
  907. if(preLinkPhase)
  908. {
  909. buildPhases->AddObject(preLinkPhase);
  910. }
  911. if(frameworkBuildPhase)
  912. {
  913. buildPhases->AddObject(frameworkBuildPhase);
  914. }
  915. if(postBuildPhase)
  916. {
  917. buildPhases->AddObject(postBuildPhase);
  918. }
  919. }
  920. //----------------------------------------------------------------------------
  921. std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
  922. std::string& flags)
  923. {
  924. std::string retFlag;
  925. std::string::size_type pos = flags.find(flag);
  926. if(pos != flags.npos)
  927. {
  928. while(pos < flags.size() && flags[pos] != ' ')
  929. {
  930. retFlag += flags[pos];
  931. flags[pos] = ' ';
  932. pos++;
  933. }
  934. }
  935. return retFlag;
  936. }
  937. //----------------------------------------------------------------------------
  938. void
  939. cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  940. cmTarget& target,
  941. std::vector<cmCustomCommand>
  942. const & commands,
  943. const char* name)
  944. {
  945. if(strcmp(name, "cmakeReRunPhase") == 0)
  946. {
  947. std::string cdir = this->CurrentMakefile->GetHomeOutputDirectory();
  948. cdir = this->ConvertToRelativeForMake(cdir.c_str());
  949. std::string makecmd = "make -C ";
  950. makecmd += cdir;
  951. makecmd += " -f ";
  952. makecmd +=
  953. this->ConvertToRelativeForMake(this->CurrentReRunCMakeMakefile.c_str());
  954. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  955. buildphase->AddAttribute("shellScript",
  956. this->CreateString(makecmd.c_str()));
  957. return;
  958. }
  959. // collect multiple outputs of custom commands into a set
  960. // which will be used for every configuration
  961. std::map<cmStdString, cmStdString> multipleOutputPairs;
  962. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  963. i != commands.end(); ++i)
  964. {
  965. cmCustomCommand const& cc = *i;
  966. if(!cc.GetCommandLines().empty())
  967. {
  968. const std::vector<std::string>& outputs = cc.GetOutputs();
  969. if(!outputs.empty())
  970. {
  971. // If there are more than one outputs treat the
  972. // first as the primary output and make the rest depend on it.
  973. std::vector<std::string>::const_iterator o = outputs.begin();
  974. std::string primaryOutput = this->ConvertToRelativeForMake(o->c_str());
  975. for(++o; o != outputs.end(); ++o)
  976. {
  977. std::string currentOutput=this->ConvertToRelativeForMake(o->c_str());
  978. multipleOutputPairs[currentOutput] = primaryOutput;
  979. }
  980. }
  981. }
  982. }
  983. std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory();
  984. dir += "/CMakeScripts";
  985. cmSystemTools::MakeDirectory(dir.c_str());
  986. std::string makefile = dir;
  987. makefile += "/";
  988. makefile += target.GetName();
  989. makefile += "_";
  990. makefile += name;
  991. makefile += ".make";
  992. for (std::vector<std::string>::const_iterator currentConfig=
  993. this->CurrentConfigurationTypes.begin();
  994. currentConfig!=this->CurrentConfigurationTypes.end();
  995. currentConfig++ )
  996. {
  997. this->CreateCustomRulesMakefile(makefile.c_str(),
  998. target,
  999. commands,
  1000. currentConfig->c_str(),
  1001. multipleOutputPairs);
  1002. }
  1003. std::string cdir = this->CurrentMakefile->GetCurrentOutputDirectory();
  1004. cdir = this->ConvertToRelativeForXCode(cdir.c_str());
  1005. std::string makecmd = "make -C ";
  1006. makecmd += cdir;
  1007. makecmd += " -f ";
  1008. makecmd += this->ConvertToRelativeForMake(
  1009. (makefile+"$CONFIGURATION").c_str());
  1010. if(!multipleOutputPairs.empty())
  1011. {
  1012. makecmd += " cmake_check_multiple_outputs";
  1013. }
  1014. makecmd += " all";
  1015. cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
  1016. buildphase->AddAttribute("shellScript",
  1017. this->CreateString(makecmd.c_str()));
  1018. }
  1019. //----------------------------------------------------------------------------
  1020. void cmGlobalXCodeGenerator
  1021. ::CreateCustomRulesMakefile(const char* makefileBasename,
  1022. cmTarget& target,
  1023. std::vector<cmCustomCommand>
  1024. const & commands,
  1025. const char* configName,
  1026. const std::map<cmStdString,
  1027. cmStdString>& multipleOutputPairs
  1028. )
  1029. {
  1030. std::string makefileName=makefileBasename;
  1031. makefileName+=configName;
  1032. cmGeneratedFileStream makefileStream(makefileName.c_str());
  1033. if(!makefileStream)
  1034. {
  1035. return;
  1036. }
  1037. makefileStream.SetCopyIfDifferent(true);
  1038. makefileStream << "# Generated by CMake, DO NOT EDIT\n";
  1039. makefileStream << "# Custom rules for " << target.GetName() << "\n";
  1040. // have all depend on all outputs
  1041. makefileStream << "all: ";
  1042. std::map<const cmCustomCommand*, cmStdString> tname;
  1043. int count = 0;
  1044. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1045. i != commands.end(); ++i)
  1046. {
  1047. cmCustomCommand const& cc = *i;
  1048. if(!cc.GetCommandLines().empty())
  1049. {
  1050. const std::vector<std::string>& outputs = cc.GetOutputs();
  1051. if(!outputs.empty())
  1052. {
  1053. for(std::vector<std::string>::const_iterator o = outputs.begin();
  1054. o != outputs.end(); ++o)
  1055. {
  1056. makefileStream
  1057. << "\\\n\t" << this->ConvertToRelativeForMake(o->c_str());
  1058. }
  1059. }
  1060. else
  1061. {
  1062. cmOStringStream str;
  1063. str << "_buildpart_" << count++ ;
  1064. tname[&cc] = std::string(target.GetName()) + str.str();
  1065. makefileStream << "\\\n\t" << tname[&cc];
  1066. }
  1067. }
  1068. }
  1069. makefileStream << "\n\n";
  1070. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1071. i != commands.end(); ++i)
  1072. {
  1073. cmCustomCommand const& cc = *i;
  1074. if(!cc.GetCommandLines().empty())
  1075. {
  1076. bool escapeOldStyle = cc.GetEscapeOldStyle();
  1077. bool escapeAllowMakeVars = cc.GetEscapeAllowMakeVars();
  1078. makefileStream << "\n#" << "Custom command rule: ";
  1079. if(cc.GetComment())
  1080. {
  1081. makefileStream << cc.GetComment();
  1082. }
  1083. makefileStream << "\n";
  1084. const std::vector<std::string>& outputs = cc.GetOutputs();
  1085. if(!outputs.empty())
  1086. {
  1087. // There is at least one output, start the rule for it
  1088. std::string primary_output =
  1089. this->ConvertToRelativeForMake(outputs.begin()->c_str());
  1090. makefileStream << primary_output << ": ";
  1091. }
  1092. else
  1093. {
  1094. // There are no outputs. Use the generated force rule name.
  1095. makefileStream << tname[&cc] << ": ";
  1096. }
  1097. for(std::vector<std::string>::const_iterator d =
  1098. cc.GetDepends().begin();
  1099. d != cc.GetDepends().end(); ++d)
  1100. {
  1101. std::string dep =
  1102. this->CurrentLocalGenerator->GetRealDependency(d->c_str(),
  1103. configName);
  1104. makefileStream << "\\\n" << this
  1105. ->ConvertToRelativeForMake(dep.c_str());
  1106. }
  1107. makefileStream << "\n";
  1108. // Add each command line to the set of commands.
  1109. for(cmCustomCommandLines::const_iterator cl =
  1110. cc.GetCommandLines().begin();
  1111. cl != cc.GetCommandLines().end(); ++cl)
  1112. {
  1113. // Build the command line in a single string.
  1114. const cmCustomCommandLine& commandLine = *cl;
  1115. std::string cmd2 = this->CurrentLocalGenerator
  1116. ->GetRealLocation(commandLine[0].c_str(), configName);
  1117. cmSystemTools::ReplaceString(cmd2, "/./", "/");
  1118. cmd2 = this->ConvertToRelativeForMake(cmd2.c_str());
  1119. std::string cmd;
  1120. if(cc.GetWorkingDirectory())
  1121. {
  1122. cmd += "cd ";
  1123. cmd += this->ConvertToRelativeForMake(cc.GetWorkingDirectory());
  1124. cmd += " && ";
  1125. }
  1126. cmd += cmd2;
  1127. for(unsigned int j=1; j < commandLine.size(); ++j)
  1128. {
  1129. cmd += " ";
  1130. if(escapeOldStyle)
  1131. {
  1132. cmd += (this->CurrentLocalGenerator
  1133. ->EscapeForShellOldStyle(commandLine[j].c_str()));
  1134. }
  1135. else
  1136. {
  1137. cmd += (this->CurrentLocalGenerator->
  1138. EscapeForShell(commandLine[j].c_str(),
  1139. escapeAllowMakeVars));
  1140. }
  1141. }
  1142. makefileStream << "\t" << cmd.c_str() << "\n";
  1143. }
  1144. }
  1145. }
  1146. // Add rules to deal with multiple outputs of custom commands.
  1147. if(!multipleOutputPairs.empty())
  1148. {
  1149. makefileStream <<
  1150. "\n# Dependencies of multiple outputs to their primary outputs \n";
  1151. for(std::map<cmStdString, cmStdString>::const_iterator o =
  1152. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1153. {
  1154. makefileStream << o->first << ": " << o->second << "\n";
  1155. }
  1156. makefileStream <<
  1157. "\n"
  1158. "cmake_check_multiple_outputs:\n";
  1159. for(std::map<cmStdString, cmStdString>::const_iterator o =
  1160. multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
  1161. {
  1162. makefileStream << "\t@if [ ! -f "
  1163. << o->first << " ]; then rm -f "
  1164. << o->second << "; fi\n";
  1165. }
  1166. }
  1167. }
  1168. //----------------------------------------------------------------------------
  1169. void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
  1170. cmXCodeObject* buildSettings,
  1171. std::string& fileType,
  1172. std::string& productType,
  1173. std::string& productName,
  1174. const char* configName)
  1175. {
  1176. std::string flags;
  1177. std::string defFlags;
  1178. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  1179. (target.GetType() == cmTarget::MODULE_LIBRARY));
  1180. // Add the export symbol definition for shared library objects.
  1181. if(const char* exportMacro = target.GetExportMacro())
  1182. {
  1183. defFlags += "-D";
  1184. defFlags += exportMacro;
  1185. }
  1186. const char* lang = target.GetLinkerLanguage(this);
  1187. std::string cflags;
  1188. if(lang)
  1189. {
  1190. // for c++ projects get the c flags as well
  1191. if(strcmp(lang, "CXX") == 0)
  1192. {
  1193. this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName);
  1194. this->CurrentLocalGenerator->AddSharedFlags(cflags, lang, shared);
  1195. }
  1196. // Add language-specific flags.
  1197. this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName);
  1198. // Add shared-library flags if needed.
  1199. this->CurrentLocalGenerator->AddSharedFlags(flags, lang, shared);
  1200. }
  1201. // Add define flags
  1202. this->CurrentLocalGenerator->
  1203. AppendFlags(defFlags,
  1204. this->CurrentMakefile->GetDefineFlags());
  1205. cmSystemTools::ReplaceString(defFlags, "\"", "\\\"");
  1206. cmSystemTools::ReplaceString(flags, "\"", "\\\"");
  1207. cmSystemTools::ReplaceString(cflags, "\"", "\\\"");
  1208. if(this->XcodeVersion > 15)
  1209. {
  1210. buildSettings->AddAttribute
  1211. ("GCC_PREPROCESSOR_DEFINITIONS",
  1212. this->CreateString("CMAKE_INTDIR=\\\\\"$(CONFIGURATION)\\\\\""));
  1213. }
  1214. std::string extraLinkOptions;
  1215. if(target.GetType() == cmTarget::EXECUTABLE)
  1216. {
  1217. extraLinkOptions =
  1218. this->CurrentMakefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
  1219. }
  1220. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  1221. {
  1222. extraLinkOptions = this->CurrentMakefile->
  1223. GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
  1224. }
  1225. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  1226. {
  1227. extraLinkOptions = this->CurrentMakefile->
  1228. GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
  1229. }
  1230. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1231. if(targetLinkFlags)
  1232. {
  1233. extraLinkOptions += " ";
  1234. extraLinkOptions += targetLinkFlags;
  1235. }
  1236. // The product name is the full name of the target for this configuration.
  1237. productName = target.GetFullName(configName);
  1238. // Get the product name components.
  1239. std::string pnprefix;
  1240. std::string pnbase;
  1241. std::string pnsuffix;
  1242. target.GetFullName(pnprefix, pnbase, pnsuffix, configName);
  1243. // Store the product name for all target types.
  1244. buildSettings->AddAttribute("PRODUCT_NAME",
  1245. this->CreateString(pnbase.c_str()));
  1246. // Set attributes to specify the proper name for the target.
  1247. if(target.GetType() == cmTarget::STATIC_LIBRARY ||
  1248. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1249. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1250. target.GetType() == cmTarget::EXECUTABLE)
  1251. {
  1252. std::string pndir = target.GetDirectory();
  1253. if (target.GetType() == cmTarget::SHARED_LIBRARY &&
  1254. target.GetPropertyAsBool("FRAMEWORK"))
  1255. {
  1256. pndir += "/..";
  1257. pndir = cmSystemTools::CollapseFullPath(pndir.c_str());
  1258. }
  1259. buildSettings->AddAttribute("SYMROOT",
  1260. this->CreateString(pndir.c_str()));
  1261. buildSettings->AddAttribute("EXECUTABLE_PREFIX",
  1262. this->CreateString(pnprefix.c_str()));
  1263. buildSettings->AddAttribute("EXECUTABLE_SUFFIX",
  1264. this->CreateString(pnsuffix.c_str()));
  1265. }
  1266. // Handle settings for each target type.
  1267. switch(target.GetType())
  1268. {
  1269. case cmTarget::STATIC_LIBRARY:
  1270. {
  1271. fileType = "archive.ar";
  1272. productType = "com.apple.product-type.library.static";
  1273. buildSettings->AddAttribute("LIBRARY_STYLE",
  1274. this->CreateString("STATIC"));
  1275. break;
  1276. }
  1277. case cmTarget::MODULE_LIBRARY:
  1278. {
  1279. buildSettings->AddAttribute("LIBRARY_STYLE",
  1280. this->CreateString("BUNDLE"));
  1281. if(this->XcodeVersion >= 22)
  1282. {
  1283. fileType = "compiled.mach-o.executable";
  1284. productType = "com.apple.product-type.tool";
  1285. buildSettings->AddAttribute("MACH_O_TYPE",
  1286. this->CreateString("mh_bundle"));
  1287. buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
  1288. this->CreateString("NO"));
  1289. // Add the flags to create an executable.
  1290. std::string createFlags =
  1291. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1292. if(!createFlags.empty())
  1293. {
  1294. extraLinkOptions += " ";
  1295. extraLinkOptions += createFlags;
  1296. }
  1297. }
  1298. else
  1299. {
  1300. fileType = "compiled.mach-o.dylib";
  1301. productType = "com.apple.product-type.library.dynamic";
  1302. // Add the flags to create a module.
  1303. std::string createFlags =
  1304. this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
  1305. "-bundle");
  1306. if(!createFlags.empty())
  1307. {
  1308. extraLinkOptions += " ";
  1309. extraLinkOptions += createFlags;
  1310. }
  1311. }
  1312. break;
  1313. }
  1314. case cmTarget::SHARED_LIBRARY:
  1315. {
  1316. if(target.GetPropertyAsBool("FRAMEWORK"))
  1317. {
  1318. fileType = "wrapper.framework";
  1319. productType = "com.apple.product-type.framework";
  1320. const char* version = target.GetProperty("FRAMEWORK_VERSION");
  1321. if(!version)
  1322. {
  1323. version = target.GetProperty("VERSION");
  1324. }
  1325. if(!version)
  1326. {
  1327. version = "A";
  1328. }
  1329. buildSettings->AddAttribute("FRAMEWORK_VERSION",
  1330. this->CreateString(version));
  1331. }
  1332. else
  1333. {
  1334. fileType = "compiled.mach-o.dylib";
  1335. productType = "com.apple.product-type.library.dynamic";
  1336. // Add the flags to create a shared library.
  1337. std::string createFlags =
  1338. this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", lang, "_FLAGS",
  1339. "-dynamiclib");
  1340. if(!createFlags.empty())
  1341. {
  1342. extraLinkOptions += " ";
  1343. extraLinkOptions += createFlags;
  1344. }
  1345. }
  1346. buildSettings->AddAttribute("LIBRARY_STYLE",
  1347. this->CreateString("DYNAMIC"));
  1348. buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
  1349. this->CreateString("1"));
  1350. buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
  1351. this->CreateString("1"));
  1352. break;
  1353. }
  1354. case cmTarget::EXECUTABLE:
  1355. {
  1356. fileType = "compiled.mach-o.executable";
  1357. // Add the flags to create an executable.
  1358. std::string createFlags =
  1359. this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
  1360. if(!createFlags.empty())
  1361. {
  1362. extraLinkOptions += " ";
  1363. extraLinkOptions += createFlags;
  1364. }
  1365. // Handle bundles and normal executables separately.
  1366. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  1367. {
  1368. productType = "com.apple.product-type.application";
  1369. std::string f1 =
  1370. this->CurrentMakefile->GetModulesFile("MacOSXBundleInfo.plist.in");
  1371. if ( f1.size() == 0 )
  1372. {
  1373. cmSystemTools::Error("could not find Mac OSX bundle template file.");
  1374. }
  1375. std::string f2 = this->CurrentMakefile->GetCurrentOutputDirectory();
  1376. f2 += "/Info.plist";
  1377. this->CurrentMakefile->ConfigureFile(f1.c_str(), f2.c_str(),
  1378. false, false, false);
  1379. std::string path =
  1380. this->ConvertToRelativeForXCode(f2.c_str());
  1381. buildSettings->AddAttribute("INFOPLIST_FILE",
  1382. this->CreateString(path.c_str()));
  1383. }
  1384. else
  1385. {
  1386. productType = "com.apple.product-type.tool";
  1387. }
  1388. }
  1389. break;
  1390. default:
  1391. break;
  1392. }
  1393. if(this->XcodeVersion >= 22)
  1394. {
  1395. buildSettings->AddAttribute("PREBINDING",
  1396. this->CreateString("NO"));
  1397. }
  1398. std::string dirs;
  1399. std::vector<std::string> includes;
  1400. this->CurrentLocalGenerator->GetIncludeDirectories(includes);
  1401. std::string fdirs;
  1402. std::set<cmStdString> emitted;
  1403. emitted.insert("/System/Library/Frameworks");
  1404. for(std::vector<std::string>::iterator i = includes.begin();
  1405. i != includes.end(); ++i)
  1406. {
  1407. if(this->NameResolvesToFramework(i->c_str()))
  1408. {
  1409. std::string frameworkDir = *i;
  1410. frameworkDir += "/../";
  1411. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1412. if(emitted.insert(frameworkDir).second)
  1413. {
  1414. fdirs += this->XCodeEscapePath(frameworkDir.c_str());
  1415. fdirs += " ";
  1416. }
  1417. }
  1418. else
  1419. {
  1420. std::string incpath =
  1421. this->XCodeEscapePath(i->c_str());
  1422. dirs += incpath + " ";
  1423. }
  1424. }
  1425. std::vector<std::string>& frameworks = target.GetFrameworks();
  1426. if(frameworks.size())
  1427. {
  1428. for(std::vector<std::string>::iterator fmIt = frameworks.begin();
  1429. fmIt != frameworks.end(); ++fmIt)
  1430. {
  1431. if(emitted.insert(*fmIt).second)
  1432. {
  1433. fdirs += this->XCodeEscapePath(fmIt->c_str());
  1434. fdirs += " ";
  1435. }
  1436. }
  1437. }
  1438. if(fdirs.size())
  1439. {
  1440. buildSettings->AddAttribute("FRAMEWORK_SEARCH_PATHS",
  1441. this->CreateString(fdirs.c_str()));
  1442. }
  1443. if(dirs.size())
  1444. {
  1445. buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
  1446. this->CreateString(dirs.c_str()));
  1447. }
  1448. std::string oflagc = this->ExtractFlag("-O", cflags);
  1449. char optLevel[2];
  1450. optLevel[0] = '0';
  1451. optLevel[1] = 0;
  1452. if(oflagc.size() == 3)
  1453. {
  1454. optLevel[0] = oflagc[2];
  1455. }
  1456. if(oflagc.size() == 2)
  1457. {
  1458. optLevel[0] = '1';
  1459. }
  1460. std::string oflag = this->ExtractFlag("-O", flags);
  1461. if(oflag.size() == 3)
  1462. {
  1463. optLevel[0] = oflag[2];
  1464. }
  1465. if(oflag.size() == 2)
  1466. {
  1467. optLevel[0] = '1';
  1468. }
  1469. std::string gflagc = this->ExtractFlag("-g", cflags);
  1470. // put back gdwarf-2 if used since there is no way
  1471. // to represent it in the gui, but we still want debug yes
  1472. if(gflagc == "-gdwarf-2")
  1473. {
  1474. cflags += " ";
  1475. cflags += gflagc;
  1476. }
  1477. std::string gflag = this->ExtractFlag("-g", flags);
  1478. if(gflag == "-gdwarf-2")
  1479. {
  1480. flags += " ";
  1481. flags += gflag;
  1482. }
  1483. const char* debugStr = "YES";
  1484. if(gflagc.size() ==0 && gflag.size() == 0)
  1485. {
  1486. debugStr = "NO";
  1487. }
  1488. // Convert "XCODE_ATTRIBUTE_*" properties directly.
  1489. {
  1490. cmPropertyMap const& props = target.GetProperties();
  1491. for(cmPropertyMap::const_iterator i = props.begin();
  1492. i != props.end(); ++i)
  1493. {
  1494. if(i->first.find("XCODE_ATTRIBUTE_") == 0)
  1495. {
  1496. buildSettings->AddAttribute(i->first.substr(16).c_str(),
  1497. this->CreateString(i->second.GetValue()));
  1498. }
  1499. }
  1500. }
  1501. buildSettings->AddAttribute("GCC_GENERATE_DEBUGGING_SYMBOLS",
  1502. this->CreateString(debugStr));
  1503. buildSettings->AddAttribute("GCC_OPTIMIZATION_LEVEL",
  1504. this->CreateString(optLevel));
  1505. buildSettings->AddAttribute("OPTIMIZATION_CFLAGS",
  1506. this->CreateString(oflagc.c_str()));
  1507. buildSettings->AddAttribute("GCC_SYMBOLS_PRIVATE_EXTERN",
  1508. this->CreateString("NO"));
  1509. buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
  1510. this->CreateString("NO"));
  1511. if(lang && strcmp(lang, "CXX") == 0)
  1512. {
  1513. flags += " ";
  1514. flags += defFlags;
  1515. buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
  1516. this->CreateString(flags.c_str()));
  1517. cflags += " ";
  1518. cflags += defFlags;
  1519. buildSettings->AddAttribute("OTHER_CFLAGS",
  1520. this->CreateString(cflags.c_str()));
  1521. }
  1522. else
  1523. {
  1524. flags += " ";
  1525. flags += defFlags;
  1526. buildSettings->AddAttribute("OTHER_CFLAGS",
  1527. this->CreateString(flags.c_str()));
  1528. }
  1529. // Create the INSTALL_PATH attribute.
  1530. std::string install_name_dir;
  1531. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  1532. {
  1533. // Get the install_name directory for the build tree.
  1534. install_name_dir = target.GetInstallNameDirForBuildTree(configName);
  1535. if(target.GetPropertyAsBool("FRAMEWORK"))
  1536. {
  1537. if(install_name_dir.find(".framework") != install_name_dir.npos)
  1538. {
  1539. install_name_dir = install_name_dir + "/..";
  1540. install_name_dir =
  1541. cmSystemTools::CollapseFullPath(install_name_dir.c_str());
  1542. //std::cerr << "new install name " << install_name_dir << "\n";
  1543. }
  1544. }
  1545. if(install_name_dir.empty())
  1546. {
  1547. // Xcode will not pass the -install_name option at all if INSTALL_PATH
  1548. // is not given or is empty. We must explicitly put the flag in the
  1549. // link flags to create an install_name with just the library soname.
  1550. extraLinkOptions += " -install_name ";
  1551. extraLinkOptions += productName;
  1552. }
  1553. else
  1554. {
  1555. // Convert to a path for the native build tool.
  1556. cmSystemTools::ConvertToUnixSlashes(install_name_dir);
  1557. // do not escape spaces on this since it is only a single path
  1558. }
  1559. }
  1560. buildSettings->AddAttribute("INSTALL_PATH",
  1561. this->CreateString(install_name_dir.c_str()));
  1562. buildSettings->AddAttribute("OTHER_LDFLAGS",
  1563. this->CreateString(extraLinkOptions.c_str()));
  1564. buildSettings->AddAttribute("OTHER_REZFLAGS",
  1565. this->CreateString(""));
  1566. buildSettings->AddAttribute("SECTORDER_FLAGS",
  1567. this->CreateString(""));
  1568. buildSettings->AddAttribute("USE_HEADERMAP",
  1569. this->CreateString("NO"));
  1570. buildSettings->AddAttribute("WARNING_CFLAGS",
  1571. this->CreateString(
  1572. "-Wmost -Wno-four-char-constants"
  1573. " -Wno-unknown-pragmas"));
  1574. }
  1575. //----------------------------------------------------------------------------
  1576. cmXCodeObject*
  1577. cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
  1578. {
  1579. cmXCodeObject* shellBuildPhase =
  1580. this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
  1581. shellBuildPhase->AddAttribute("buildActionMask",
  1582. this->CreateString("2147483647"));
  1583. cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1584. shellBuildPhase->AddAttribute("files", buildFiles);
  1585. cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1586. shellBuildPhase->AddAttribute("inputPaths", inputPaths);
  1587. cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1588. shellBuildPhase->AddAttribute("outputPaths", outputPaths);
  1589. shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
  1590. this->CreateString("0"));
  1591. shellBuildPhase->AddAttribute("shellPath",
  1592. this->CreateString("/bin/sh"));
  1593. shellBuildPhase->AddAttribute("shellScript",
  1594. this->CreateString(
  1595. "# shell script goes here\nexit 0"));
  1596. cmXCodeObject* target =
  1597. this->CreateObject(cmXCodeObject::PBXAggregateTarget);
  1598. target->SetComment(cmtarget.GetName());
  1599. cmXCodeObject* buildPhases =
  1600. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1601. std::vector<cmXCodeObject*> emptyContentVector;
  1602. this->CreateCustomCommands(buildPhases, 0, 0, 0, emptyContentVector, 0,
  1603. cmtarget);
  1604. target->AddAttribute("buildPhases", buildPhases);
  1605. cmXCodeObject* buildSettings =
  1606. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1607. std::string fileTypeString;
  1608. std::string productTypeString;
  1609. std::string productName;
  1610. const char* globalConfig = 0;
  1611. if(this->XcodeVersion > 20)
  1612. {
  1613. this->AddConfigurations(target, cmtarget);
  1614. }
  1615. else
  1616. {
  1617. globalConfig = this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
  1618. }
  1619. this->CreateBuildSettings(cmtarget,
  1620. buildSettings, fileTypeString,
  1621. productTypeString, productName, globalConfig);
  1622. target->AddAttribute("buildSettings", buildSettings);
  1623. cmXCodeObject* dependencies =
  1624. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1625. target->AddAttribute("dependencies", dependencies);
  1626. target->AddAttribute("name", this->CreateString(productName.c_str()));
  1627. target->AddAttribute("productName",this->CreateString(productName.c_str()));
  1628. target->SetTarget(&cmtarget);
  1629. return target;
  1630. }
  1631. //----------------------------------------------------------------------------
  1632. void cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
  1633. cmTarget& cmtarget)
  1634. {
  1635. std::string configTypes =
  1636. this->CurrentMakefile->GetRequiredDefinition("CMAKE_CONFIGURATION_TYPES");
  1637. std::vector<std::string> configVectorIn;
  1638. std::vector<std::string> configVector;
  1639. configVectorIn.push_back(configTypes);
  1640. cmSystemTools::ExpandList(configVectorIn, configVector);
  1641. cmXCodeObject* configlist =
  1642. this->CreateObject(cmXCodeObject::XCConfigurationList);
  1643. cmXCodeObject* buildConfigurations =
  1644. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1645. configlist->AddAttribute("buildConfigurations", buildConfigurations);
  1646. std::string comment = "Build configuration list for ";
  1647. comment += cmXCodeObject::PBXTypeNames[target->GetIsA()];
  1648. comment += " \"";
  1649. comment += cmtarget.GetName();
  1650. comment += "\"";
  1651. configlist->SetComment(comment.c_str());
  1652. target->AddAttribute("buildConfigurationList",
  1653. this->CreateObjectReference(configlist));
  1654. for(unsigned int i = 0; i < configVector.size(); ++i)
  1655. {
  1656. cmXCodeObject* config =
  1657. this->CreateObject(cmXCodeObject::XCBuildConfiguration);
  1658. buildConfigurations->AddObject(config);
  1659. cmXCodeObject* buildSettings =
  1660. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1661. std::string fileTypeString;
  1662. std::string productTypeString;
  1663. std::string productName;
  1664. this->CreateBuildSettings(cmtarget,
  1665. buildSettings, fileTypeString,
  1666. productTypeString, productName,
  1667. configVector[i].c_str());
  1668. config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
  1669. config->SetComment(configVector[i].c_str());
  1670. config->AddAttribute("buildSettings", buildSettings);
  1671. }
  1672. if(configVector.size())
  1673. {
  1674. configlist->AddAttribute("defaultConfigurationName",
  1675. this->CreateString(configVector[0].c_str()));
  1676. configlist->AddAttribute("defaultConfigurationIsVisible",
  1677. this->CreateString("0"));
  1678. }
  1679. }
  1680. //----------------------------------------------------------------------------
  1681. cmXCodeObject*
  1682. cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
  1683. cmXCodeObject* buildPhases)
  1684. {
  1685. cmXCodeObject* target =
  1686. this->CreateObject(cmXCodeObject::PBXNativeTarget);
  1687. target->AddAttribute("buildPhases", buildPhases);
  1688. cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1689. target->AddAttribute("buildRules", buildRules);
  1690. cmXCodeObject* buildSettings =
  1691. this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
  1692. std::string fileTypeString;
  1693. std::string productTypeString;
  1694. std::string productName;
  1695. const char* globalConfig = 0;
  1696. if(this->XcodeVersion > 20)
  1697. {
  1698. this->AddConfigurations(target, cmtarget);
  1699. }
  1700. else
  1701. {
  1702. globalConfig = this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
  1703. }
  1704. this->CreateBuildSettings(cmtarget,
  1705. buildSettings, fileTypeString,
  1706. productTypeString, productName, globalConfig);
  1707. target->AddAttribute("buildSettings", buildSettings);
  1708. cmXCodeObject* dependencies =
  1709. this->CreateObject(cmXCodeObject::OBJECT_LIST);
  1710. target->AddAttribute("dependencies", dependencies);
  1711. target->AddAttribute("name", this->CreateString(productName.c_str()));
  1712. target->AddAttribute("productName",this->CreateString(productName.c_str()));
  1713. cmXCodeObject* fileRef =
  1714. this->CreateObject(cmXCodeObject::PBXFileReference);
  1715. fileRef->AddAttribute("explicitFileType",
  1716. this->CreateString(fileTypeString.c_str()));
  1717. fileRef->AddAttribute("path", this->CreateString(productName.c_str()));
  1718. fileRef->AddAttribute("refType", this->CreateString("0"));
  1719. fileRef->AddAttribute("sourceTree",
  1720. this->CreateString("BUILT_PRODUCTS_DIR"));
  1721. fileRef->SetComment(cmtarget.GetName());
  1722. target->AddAttribute("productReference",
  1723. this->CreateObjectReference(fileRef));
  1724. target->AddAttribute("productType",
  1725. this->CreateString(productTypeString.c_str()));
  1726. target->SetTarget(&cmtarget);
  1727. return target;
  1728. }
  1729. //----------------------------------------------------------------------------
  1730. cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
  1731. {
  1732. if(!t)
  1733. {
  1734. return 0;
  1735. }
  1736. for(std::vector<cmXCodeObject*>::iterator i = this->XCodeObjects.begin();
  1737. i != this->XCodeObjects.end(); ++i)
  1738. {
  1739. cmXCodeObject* o = *i;
  1740. if(o->GetTarget() == t)
  1741. {
  1742. return o;
  1743. }
  1744. }
  1745. return 0;
  1746. }
  1747. //----------------------------------------------------------------------------
  1748. void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
  1749. cmXCodeObject* dependTarget)
  1750. {
  1751. // make sure a target does not depend on itself
  1752. if(target == dependTarget)
  1753. {
  1754. return;
  1755. }
  1756. // now avoid circular references if dependTarget already
  1757. // depends on target then skip it. Circular references crashes
  1758. // xcode
  1759. cmXCodeObject* dependTargetDepends =
  1760. dependTarget->GetObject("dependencies");
  1761. if(dependTargetDepends)
  1762. {
  1763. if(dependTargetDepends->HasObject(target->GetPBXTargetDependency()))
  1764. {
  1765. return;
  1766. }
  1767. }
  1768. cmXCodeObject* targetdep = dependTarget->GetPBXTargetDependency();
  1769. if(!targetdep)
  1770. {
  1771. cmXCodeObject* container =
  1772. this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
  1773. container->SetComment("PBXContainerItemProxy");
  1774. container->AddAttribute("containerPortal",
  1775. this->CreateObjectReference(this->RootObject));
  1776. container->AddAttribute("proxyType", this->CreateString("1"));
  1777. container->AddAttribute("remoteGlobalIDString",
  1778. this->CreateObjectReference(dependTarget));
  1779. container->AddAttribute("remoteInfo",
  1780. this->CreateString(
  1781. dependTarget->GetTarget()->GetName()));
  1782. targetdep =
  1783. this->CreateObject(cmXCodeObject::PBXTargetDependency);
  1784. targetdep->SetComment("PBXTargetDependency");
  1785. targetdep->AddAttribute("target",
  1786. this->CreateObjectReference(dependTarget));
  1787. targetdep->AddAttribute("targetProxy",
  1788. this->CreateObjectReference(container));
  1789. dependTarget->SetPBXTargetDependency(targetdep);
  1790. }
  1791. cmXCodeObject* depends = target->GetObject("dependencies");
  1792. if(!depends)
  1793. {
  1794. cmSystemTools::
  1795. Error("target does not have dependencies attribute error..");
  1796. }
  1797. else
  1798. {
  1799. depends->AddUniqueObject(targetdep);
  1800. }
  1801. }
  1802. //----------------------------------------------------------------------------
  1803. void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings,
  1804. const char* attribute,
  1805. const char* value)
  1806. {
  1807. if(settings)
  1808. {
  1809. cmXCodeObject* attr = settings->GetObject(attribute);
  1810. if(!attr)
  1811. {
  1812. settings->AddAttribute(attribute, this->CreateString(value));
  1813. }
  1814. else
  1815. {
  1816. std::string oldValue = attr->GetString();
  1817. // unescape escaped quotes internal to the string:
  1818. cmSystemTools::ReplaceString(oldValue, "\\\"", "\"");
  1819. // remove surrounding quotes, if any:
  1820. std::string::size_type len = oldValue.length();
  1821. if(oldValue[0] == '\"' && oldValue[len-1] == '\"')
  1822. {
  1823. oldValue = oldValue.substr(1, len-2);
  1824. }
  1825. oldValue += " ";
  1826. oldValue += value;
  1827. // SetString automatically escapes internal quotes and then surrounds
  1828. // the result with quotes if necessary...
  1829. attr->SetString(oldValue.c_str());
  1830. }
  1831. }
  1832. }
  1833. //----------------------------------------------------------------------------
  1834. void cmGlobalXCodeGenerator
  1835. ::AppendBuildSettingAttribute(cmXCodeObject* target,
  1836. const char* attribute,
  1837. const char* value,
  1838. const char* configName)
  1839. {
  1840. if(this->XcodeVersion < 21)
  1841. {
  1842. // There is only one configuration. Add the setting to the buildSettings
  1843. // of the target.
  1844. this->AppendOrAddBuildSetting(target->GetObject("buildSettings"),
  1845. attribute, value);
  1846. }
  1847. else
  1848. {
  1849. // There are multiple configurations. Add the setting to the
  1850. // buildSettings of the configuration name given.
  1851. cmXCodeObject* configurationList =
  1852. target->GetObject("buildConfigurationList")->GetObject();
  1853. cmXCodeObject* buildConfigs =
  1854. configurationList->GetObject("buildConfigurations");
  1855. std::vector<cmXCodeObject*> list = buildConfigs->GetObjectList();
  1856. // each configuration and the target itself has a buildSettings in it
  1857. //list.push_back(target);
  1858. for(std::vector<cmXCodeObject*>::iterator i = list.begin();
  1859. i != list.end(); ++i)
  1860. {
  1861. if(configName)
  1862. {
  1863. if(strcmp((*i)->GetObject("name")->GetString(), configName) == 0)
  1864. {
  1865. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  1866. this->AppendOrAddBuildSetting(settings, attribute, value);
  1867. }
  1868. }
  1869. else
  1870. {
  1871. cmXCodeObject* settings = (*i)->GetObject("buildSettings");
  1872. this->AppendOrAddBuildSetting(settings, attribute, value);
  1873. }
  1874. }
  1875. }
  1876. }
  1877. //----------------------------------------------------------------------------
  1878. void cmGlobalXCodeGenerator
  1879. ::AddDependAndLinkInformation(cmXCodeObject* target)
  1880. {
  1881. cmTarget* cmtarget = target->GetTarget();
  1882. if(!cmtarget)
  1883. {
  1884. cmSystemTools::Error("Error no target on xobject\n");
  1885. return;
  1886. }
  1887. // Add dependencies on other CMake targets.
  1888. if(cmtarget->GetType() != cmTarget::STATIC_LIBRARY)
  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. }