cmLocalGenerator.cxx 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102
  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 "cmLocalGenerator.h"
  14. #include "cmComputeLinkInformation.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmGlobalGenerator.h"
  17. #include "cmInstallGenerator.h"
  18. #include "cmInstallFilesGenerator.h"
  19. #include "cmInstallScriptGenerator.h"
  20. #include "cmInstallTargetGenerator.h"
  21. #include "cmMakefile.h"
  22. #include "cmSourceFile.h"
  23. #include "cmTest.h"
  24. #include "cmTestGenerator.h"
  25. #include "cmVersion.h"
  26. #include "cmake.h"
  27. #if defined(CMAKE_BUILD_WITH_CMAKE)
  28. # define CM_LG_ENCODE_OBJECT_NAMES
  29. # include <cmsys/MD5.h>
  30. #endif
  31. #include <cmsys/System.h>
  32. #include <ctype.h> // for isalpha
  33. #include <assert.h>
  34. cmLocalGenerator::cmLocalGenerator()
  35. {
  36. this->Makefile = 0; // moved to after set on global
  37. this->Parent = 0;
  38. this->WindowsShell = false;
  39. this->WindowsVSIDE = false;
  40. this->WatcomWMake = false;
  41. this->MinGWMake = false;
  42. this->NMake = false;
  43. this->MSYSShell = false;
  44. this->LinkScriptShell = false;
  45. this->IgnoreLibPrefix = false;
  46. this->UseRelativePaths = false;
  47. this->Configured = false;
  48. this->EmitUniversalBinaryFlags = true;
  49. this->IsMakefileGenerator = false;
  50. this->RelativePathsConfigured = false;
  51. this->PathConversionsSetup = false;
  52. this->BackwardsCompatibility = 0;
  53. this->BackwardsCompatibilityFinal = false;
  54. }
  55. cmLocalGenerator::~cmLocalGenerator()
  56. {
  57. delete this->Makefile;
  58. }
  59. //----------------------------------------------------------------------------
  60. class cmLocalGeneratorCurrent
  61. {
  62. cmGlobalGenerator* GG;
  63. cmLocalGenerator* LG;
  64. public:
  65. cmLocalGeneratorCurrent(cmLocalGenerator* lg)
  66. {
  67. this->GG = lg->GetGlobalGenerator();
  68. this->LG = this->GG->GetCurrentLocalGenerator();
  69. this->GG->SetCurrentLocalGenerator(lg);
  70. }
  71. ~cmLocalGeneratorCurrent()
  72. {
  73. this->GG->SetCurrentLocalGenerator(this->LG);
  74. }
  75. };
  76. //----------------------------------------------------------------------------
  77. void cmLocalGenerator::Configure()
  78. {
  79. // Manage the global generator's current local generator.
  80. cmLocalGeneratorCurrent clg(this);
  81. static_cast<void>(clg);
  82. // make sure the CMakeFiles dir is there
  83. std::string filesDir = this->Makefile->GetStartOutputDirectory();
  84. filesDir += cmake::GetCMakeFilesDirectory();
  85. cmSystemTools::MakeDirectory(filesDir.c_str());
  86. // find & read the list file
  87. this->ReadInputFile();
  88. // at the end of the ReadListFile handle any old style subdirs
  89. // first get all the subdirectories
  90. std::vector<cmLocalGenerator *> subdirs = this->GetChildren();
  91. // for each subdir recurse
  92. std::vector<cmLocalGenerator *>::iterator sdi = subdirs.begin();
  93. for (; sdi != subdirs.end(); ++sdi)
  94. {
  95. if (!(*sdi)->Configured)
  96. {
  97. this->Makefile->ConfigureSubDirectory(*sdi);
  98. }
  99. }
  100. // Check whether relative paths should be used for optionally
  101. // relative paths.
  102. this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
  103. this->ComputeObjectMaxPath();
  104. this->Configured = true;
  105. }
  106. //----------------------------------------------------------------------------
  107. void cmLocalGenerator::ComputeObjectMaxPath()
  108. {
  109. // Choose a maximum object file name length.
  110. #if defined(_WIN32) || defined(__CYGWIN__)
  111. this->ObjectPathMax = 250;
  112. #else
  113. this->ObjectPathMax = 1000;
  114. #endif
  115. const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
  116. if(plen && *plen)
  117. {
  118. unsigned int pmax;
  119. if(sscanf(plen, "%u", &pmax) == 1)
  120. {
  121. if(pmax >= 128)
  122. {
  123. this->ObjectPathMax = pmax;
  124. }
  125. else
  126. {
  127. cmOStringStream w;
  128. w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
  129. << ", which is less than the minimum of 128. "
  130. << "The value will be ignored.";
  131. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  132. }
  133. }
  134. else
  135. {
  136. cmOStringStream w;
  137. w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
  138. << "\", which fails to parse as a positive integer. "
  139. << "The value will be ignored.";
  140. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  141. }
  142. }
  143. this->ObjectMaxPathViolations.clear();
  144. }
  145. //----------------------------------------------------------------------------
  146. void cmLocalGenerator::ReadInputFile()
  147. {
  148. // Look for the CMakeLists.txt file.
  149. std::string currentStart = this->Makefile->GetStartDirectory();
  150. currentStart += "/CMakeLists.txt";
  151. if(cmSystemTools::FileExists(currentStart.c_str(), true))
  152. {
  153. this->Makefile->ReadListFile(currentStart.c_str());
  154. return;
  155. }
  156. if(!this->Parent)
  157. {
  158. return;
  159. }
  160. // The file is missing. Check policy CMP0014.
  161. cmMakefile* mf = this->Parent->GetMakefile();
  162. cmOStringStream e;
  163. e << "The source directory\n"
  164. << " " << this->Makefile->GetStartDirectory() << "\n"
  165. << "does not contain a CMakeLists.txt file.";
  166. switch (mf->GetPolicyStatus(cmPolicies::CMP0014))
  167. {
  168. case cmPolicies::WARN:
  169. // Print the warning.
  170. e << "\n"
  171. << "CMake does not support this case but it used "
  172. << "to work accidentally and is being allowed for "
  173. << "compatibility."
  174. << "\n"
  175. << mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0014);
  176. mf->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  177. case cmPolicies::OLD:
  178. // OLD behavior does not warn.
  179. return;
  180. case cmPolicies::REQUIRED_IF_USED:
  181. case cmPolicies::REQUIRED_ALWAYS:
  182. e << "\n"
  183. << mf->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0014);
  184. case cmPolicies::NEW:
  185. // NEW behavior prints the error.
  186. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  187. break;
  188. }
  189. }
  190. void cmLocalGenerator::SetupPathConversions()
  191. {
  192. // Setup the current output directory components for use by
  193. // Convert
  194. std::string outdir;
  195. outdir =
  196. cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
  197. cmSystemTools::SplitPath(outdir.c_str(), this->HomeDirectoryComponents);
  198. outdir =
  199. cmSystemTools::CollapseFullPath(this->Makefile->GetStartDirectory());
  200. cmSystemTools::SplitPath(outdir.c_str(), this->StartDirectoryComponents);
  201. outdir = cmSystemTools::CollapseFullPath
  202. (this->Makefile->GetHomeOutputDirectory());
  203. cmSystemTools::SplitPath(outdir.c_str(),
  204. this->HomeOutputDirectoryComponents);
  205. outdir = cmSystemTools::CollapseFullPath
  206. (this->Makefile->GetStartOutputDirectory());
  207. cmSystemTools::SplitPath(outdir.c_str(),
  208. this->StartOutputDirectoryComponents);
  209. }
  210. void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
  211. {
  212. this->GlobalGenerator = gg;
  213. this->Makefile = new cmMakefile;
  214. this->Makefile->SetLocalGenerator(this);
  215. // setup the home directories
  216. this->Makefile->GetProperties().SetCMakeInstance(gg->GetCMakeInstance());
  217. this->Makefile->SetHomeDirectory(
  218. gg->GetCMakeInstance()->GetHomeDirectory());
  219. this->Makefile->SetHomeOutputDirectory(
  220. gg->GetCMakeInstance()->GetHomeOutputDirectory());
  221. }
  222. void cmLocalGenerator::ConfigureFinalPass()
  223. {
  224. this->Makefile->ConfigureFinalPass();
  225. }
  226. void cmLocalGenerator::TraceDependencies()
  227. {
  228. // Generate the rule files for each target.
  229. cmTargets& targets = this->Makefile->GetTargets();
  230. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  231. {
  232. const char* projectFilename = 0;
  233. if (this->IsMakefileGenerator == false) // only use of this variable
  234. {
  235. projectFilename = t->second.GetName();
  236. }
  237. t->second.TraceDependencies(projectFilename);
  238. }
  239. }
  240. void cmLocalGenerator::GenerateTestFiles()
  241. {
  242. if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
  243. {
  244. return;
  245. }
  246. // Compute the set of configurations.
  247. std::vector<std::string> configurationTypes;
  248. if(const char* types =
  249. this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  250. {
  251. cmSystemTools::ExpandListArgument(types, configurationTypes);
  252. }
  253. const char* config = 0;
  254. if(configurationTypes.empty())
  255. {
  256. config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  257. }
  258. std::string file = this->Makefile->GetStartOutputDirectory();
  259. file += "/";
  260. file += "CTestTestfile.cmake";
  261. cmGeneratedFileStream fout(file.c_str());
  262. fout.SetCopyIfDifferent(true);
  263. fout << "# CMake generated Testfile for " << std::endl
  264. << "# Source directory: "
  265. << this->Makefile->GetStartDirectory() << std::endl
  266. << "# Build directory: "
  267. << this->Makefile->GetStartOutputDirectory() << std::endl
  268. << "# " << std::endl
  269. << "# This file includes the relevent testing commands "
  270. << "required for " << std::endl
  271. << "# testing this directory and lists subdirectories to "
  272. << "be tested as well." << std::endl;
  273. const char* testIncludeFile =
  274. this->Makefile->GetProperty("TEST_INCLUDE_FILE");
  275. if ( testIncludeFile )
  276. {
  277. fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
  278. }
  279. // Ask each test generator to write its code.
  280. std::vector<cmTestGenerator*> const&
  281. testers = this->Makefile->GetTestGenerators();
  282. for(std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
  283. gi != testers.end(); ++gi)
  284. {
  285. (*gi)->Generate(fout, config, configurationTypes);
  286. }
  287. if ( this->Children.size())
  288. {
  289. size_t i;
  290. for(i = 0; i < this->Children.size(); ++i)
  291. {
  292. fout << "SUBDIRS(";
  293. std::string outP =
  294. this->Children[i]->GetMakefile()->GetStartOutputDirectory();
  295. fout << this->Convert(outP.c_str(),START_OUTPUT);
  296. fout << ")" << std::endl;
  297. }
  298. }
  299. }
  300. //----------------------------------------------------------------------------
  301. void cmLocalGenerator::GenerateInstallRules()
  302. {
  303. // Compute the install prefix.
  304. const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
  305. #if defined(_WIN32) && !defined(__CYGWIN__)
  306. std::string prefix_win32;
  307. if(!prefix)
  308. {
  309. if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
  310. {
  311. prefix_win32 = "C:";
  312. }
  313. const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
  314. if(project_name && project_name[0])
  315. {
  316. prefix_win32 += "/Program Files/";
  317. prefix_win32 += project_name;
  318. }
  319. else
  320. {
  321. prefix_win32 += "/InstalledCMakeProject";
  322. }
  323. prefix = prefix_win32.c_str();
  324. }
  325. #else
  326. if (!prefix)
  327. {
  328. prefix = "/usr/local";
  329. }
  330. #endif
  331. // Compute the set of configurations.
  332. std::vector<std::string> configurationTypes;
  333. if(const char* types =
  334. this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  335. {
  336. cmSystemTools::ExpandListArgument(types, configurationTypes);
  337. }
  338. const char* config = 0;
  339. if(configurationTypes.empty())
  340. {
  341. config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  342. }
  343. // Choose a default install configuration.
  344. const char* default_config = config;
  345. const char* default_order[] = {"RELEASE", "MINSIZEREL",
  346. "RELWITHDEBINFO", "DEBUG", 0};
  347. for(const char** c = default_order; *c && !default_config; ++c)
  348. {
  349. for(std::vector<std::string>::iterator i = configurationTypes.begin();
  350. i != configurationTypes.end(); ++i)
  351. {
  352. if(cmSystemTools::UpperCase(*i) == *c)
  353. {
  354. default_config = i->c_str();
  355. }
  356. }
  357. }
  358. if(!default_config && !configurationTypes.empty())
  359. {
  360. default_config = configurationTypes[0].c_str();
  361. }
  362. if(!default_config)
  363. {
  364. default_config = "Release";
  365. }
  366. // Create the install script file.
  367. std::string file = this->Makefile->GetStartOutputDirectory();
  368. std::string homedir = this->Makefile->GetHomeOutputDirectory();
  369. std::string currdir = this->Makefile->GetCurrentOutputDirectory();
  370. cmSystemTools::ConvertToUnixSlashes(file);
  371. cmSystemTools::ConvertToUnixSlashes(homedir);
  372. cmSystemTools::ConvertToUnixSlashes(currdir);
  373. int toplevel_install = 0;
  374. if ( currdir == homedir )
  375. {
  376. toplevel_install = 1;
  377. }
  378. file += "/cmake_install.cmake";
  379. cmGeneratedFileStream fout(file.c_str());
  380. fout.SetCopyIfDifferent(true);
  381. // Write the header.
  382. fout << "# Install script for directory: "
  383. << this->Makefile->GetCurrentDirectory() << std::endl << std::endl;
  384. fout << "# Set the install prefix" << std::endl
  385. << "IF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  386. << " SET(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
  387. << "ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  388. << "STRING(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
  389. << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
  390. << std::endl;
  391. // Write support code for generating per-configuration install rules.
  392. fout <<
  393. "# Set the install configuration name.\n"
  394. "IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  395. " IF(BUILD_TYPE)\n"
  396. " STRING(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
  397. " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
  398. " ELSE(BUILD_TYPE)\n"
  399. " SET(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
  400. " ENDIF(BUILD_TYPE)\n"
  401. " MESSAGE(STATUS \"Install configuration: "
  402. "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
  403. "ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  404. "\n";
  405. // Write support code for dealing with component-specific installs.
  406. fout <<
  407. "# Set the component getting installed.\n"
  408. "IF(NOT CMAKE_INSTALL_COMPONENT)\n"
  409. " IF(COMPONENT)\n"
  410. " MESSAGE(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
  411. " SET(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
  412. " ELSE(COMPONENT)\n"
  413. " SET(CMAKE_INSTALL_COMPONENT)\n"
  414. " ENDIF(COMPONENT)\n"
  415. "ENDIF(NOT CMAKE_INSTALL_COMPONENT)\n"
  416. "\n";
  417. // Copy user-specified install options to the install code.
  418. if(const char* so_no_exe =
  419. this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
  420. {
  421. fout <<
  422. "# Install shared libraries without execute permission?\n"
  423. "IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  424. " SET(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
  425. "ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  426. "\n";
  427. }
  428. // Ask each install generator to write its code.
  429. std::vector<cmInstallGenerator*> const& installers =
  430. this->Makefile->GetInstallGenerators();
  431. for(std::vector<cmInstallGenerator*>::const_iterator
  432. gi = installers.begin();
  433. gi != installers.end(); ++gi)
  434. {
  435. (*gi)->Generate(fout, config, configurationTypes);
  436. }
  437. // Write rules from old-style specification stored in targets.
  438. this->GenerateTargetInstallRules(fout, config, configurationTypes);
  439. // Include install scripts from subdirectories.
  440. if(!this->Children.empty())
  441. {
  442. fout << "IF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
  443. fout << " # Include the install script for each subdirectory.\n";
  444. for(std::vector<cmLocalGenerator*>::const_iterator
  445. ci = this->Children.begin(); ci != this->Children.end(); ++ci)
  446. {
  447. if(!(*ci)->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  448. {
  449. std::string odir = (*ci)->GetMakefile()->GetStartOutputDirectory();
  450. cmSystemTools::ConvertToUnixSlashes(odir);
  451. fout << " INCLUDE(\"" << odir.c_str()
  452. << "/cmake_install.cmake\")" << std::endl;
  453. }
  454. }
  455. fout << "\n";
  456. fout << "ENDIF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n\n";
  457. }
  458. // Record the install manifest.
  459. if ( toplevel_install )
  460. {
  461. fout <<
  462. "IF(CMAKE_INSTALL_COMPONENT)\n"
  463. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest_"
  464. "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
  465. "ELSE(CMAKE_INSTALL_COMPONENT)\n"
  466. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
  467. "ENDIF(CMAKE_INSTALL_COMPONENT)\n\n";
  468. fout
  469. << "FILE(WRITE \""
  470. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  471. << "\"\")" << std::endl;
  472. fout
  473. << "FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
  474. << " FILE(APPEND \""
  475. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  476. << "\"${file}\\n\")" << std::endl
  477. << "ENDFOREACH(file)" << std::endl;
  478. }
  479. }
  480. //----------------------------------------------------------------------------
  481. void cmLocalGenerator::GenerateTargetManifest()
  482. {
  483. // Collect the set of configuration types.
  484. std::vector<std::string> configNames;
  485. if(const char* configurationTypes =
  486. this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  487. {
  488. cmSystemTools::ExpandListArgument(configurationTypes, configNames);
  489. }
  490. else if(const char* buildType =
  491. this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
  492. {
  493. if(*buildType)
  494. {
  495. configNames.push_back(buildType);
  496. }
  497. }
  498. // Add our targets to the manifest for each configuration.
  499. cmTargets& targets = this->Makefile->GetTargets();
  500. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  501. {
  502. cmTarget& target = t->second;
  503. if(configNames.empty())
  504. {
  505. target.GenerateTargetManifest(0);
  506. }
  507. else
  508. {
  509. for(std::vector<std::string>::iterator ci = configNames.begin();
  510. ci != configNames.end(); ++ci)
  511. {
  512. const char* config = ci->c_str();
  513. target.GenerateTargetManifest(config);
  514. }
  515. }
  516. }
  517. }
  518. void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
  519. const char* lang,
  520. cmSourceFile& source,
  521. cmTarget& )
  522. {
  523. std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
  524. objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL);
  525. std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
  526. std::string sourceFile =
  527. this->Convert(source.GetFullPath().c_str(),START_OUTPUT,SHELL,true);
  528. std::string varString = "CMAKE_";
  529. varString += lang;
  530. varString += "_COMPILE_OBJECT";
  531. std::vector<std::string> rules;
  532. rules.push_back(this->Makefile->GetRequiredDefinition(varString.c_str()));
  533. varString = "CMAKE_";
  534. varString += lang;
  535. varString += "_FLAGS";
  536. std::string flags;
  537. flags += this->Makefile->GetSafeDefinition(varString.c_str());
  538. flags += " ";
  539. flags += this->GetIncludeFlags(lang);
  540. // Construct the command lines.
  541. cmCustomCommandLines commandLines;
  542. std::vector<std::string> commands;
  543. cmSystemTools::ExpandList(rules, commands);
  544. cmLocalGenerator::RuleVariables vars;
  545. vars.Language = lang;
  546. vars.Source = sourceFile.c_str();
  547. vars.Object = objectFile.c_str();
  548. vars.ObjectDir = objectDir.c_str();
  549. vars.Flags = flags.c_str();
  550. for(std::vector<std::string>::iterator i = commands.begin();
  551. i != commands.end(); ++i)
  552. {
  553. // Expand the full command line string.
  554. this->ExpandRuleVariables(*i, vars);
  555. // Parse the string to get the custom command line.
  556. cmCustomCommandLine commandLine;
  557. std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
  558. for(std::vector<cmStdString>::iterator a = cmd.begin();
  559. a != cmd.end(); ++a)
  560. {
  561. commandLine.push_back(*a);
  562. }
  563. // Store this command line.
  564. commandLines.push_back(commandLine);
  565. }
  566. // Check for extra object-file dependencies.
  567. std::vector<std::string> depends;
  568. const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
  569. if(additionalDeps)
  570. {
  571. cmSystemTools::ExpandListArgument(additionalDeps, depends);
  572. }
  573. // Generate a meaningful comment for the command.
  574. std::string comment = "Building ";
  575. comment += lang;
  576. comment += " object ";
  577. comment += this->Convert(ofname, START_OUTPUT);
  578. // Add the custom command to build the object file.
  579. this->Makefile->AddCustomCommandToOutput(
  580. ofname,
  581. depends,
  582. source.GetFullPath().c_str(),
  583. commandLines,
  584. comment.c_str(),
  585. this->Makefile->GetStartOutputDirectory()
  586. );
  587. }
  588. void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
  589. {
  590. cmStdString objs;
  591. std::vector<std::string> objVector;
  592. // Add all the sources outputs to the depends of the target
  593. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  594. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  595. i != classes.end(); ++i)
  596. {
  597. cmSourceFile* sf = *i;
  598. if(!sf->GetCustomCommand() &&
  599. !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  600. !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  601. {
  602. std::string dir_max;
  603. dir_max += this->Makefile->GetCurrentOutputDirectory();
  604. dir_max += "/";
  605. std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
  606. if(!obj.empty())
  607. {
  608. std::string ofname = this->Makefile->GetCurrentOutputDirectory();
  609. ofname += "/";
  610. ofname += obj;
  611. objVector.push_back(ofname);
  612. this->AddCustomCommandToCreateObject(ofname.c_str(),
  613. llang, *(*i), target);
  614. objs += this->Convert(ofname.c_str(),START_OUTPUT,MAKEFILE);
  615. objs += " ";
  616. }
  617. }
  618. }
  619. std::string createRule = "CMAKE_";
  620. createRule += llang;
  621. createRule += target.GetCreateRuleVariable();
  622. std::string targetName = target.GetFullName();
  623. // Executable :
  624. // Shared Library:
  625. // Static Library:
  626. // Shared Module:
  627. std::string linkLibs; // should be set
  628. std::string flags; // should be set
  629. std::string linkFlags; // should be set
  630. this->GetTargetFlags(linkLibs, flags, linkFlags, target);
  631. cmLocalGenerator::RuleVariables vars;
  632. vars.Language = llang;
  633. vars.Objects = objs.c_str();
  634. vars.ObjectDir = ".";
  635. vars.Target = targetName.c_str();
  636. vars.LinkLibraries = linkLibs.c_str();
  637. vars.Flags = flags.c_str();
  638. vars.LinkFlags = linkFlags.c_str();
  639. std::string langFlags;
  640. this->AddLanguageFlags(langFlags, llang, 0);
  641. vars.LanguageCompileFlags = langFlags.c_str();
  642. cmCustomCommandLines commandLines;
  643. std::vector<std::string> rules;
  644. rules.push_back(this->Makefile->GetRequiredDefinition(createRule.c_str()));
  645. std::vector<std::string> commands;
  646. cmSystemTools::ExpandList(rules, commands);
  647. for(std::vector<std::string>::iterator i = commands.begin();
  648. i != commands.end(); ++i)
  649. {
  650. // Expand the full command line string.
  651. this->ExpandRuleVariables(*i, vars);
  652. // Parse the string to get the custom command line.
  653. cmCustomCommandLine commandLine;
  654. std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
  655. for(std::vector<cmStdString>::iterator a = cmd.begin();
  656. a != cmd.end(); ++a)
  657. {
  658. commandLine.push_back(*a);
  659. }
  660. // Store this command line.
  661. commandLines.push_back(commandLine);
  662. }
  663. std::string targetFullPath = target.GetFullPath();
  664. // Generate a meaningful comment for the command.
  665. std::string comment = "Linking ";
  666. comment += llang;
  667. comment += " target ";
  668. comment += this->Convert(targetFullPath.c_str(), START_OUTPUT);
  669. this->Makefile->AddCustomCommandToOutput(
  670. targetFullPath.c_str(),
  671. objVector,
  672. 0,
  673. commandLines,
  674. comment.c_str(),
  675. this->Makefile->GetStartOutputDirectory()
  676. );
  677. target.AddSourceFile
  678. (this->Makefile->GetSource(targetFullPath.c_str()));
  679. }
  680. void cmLocalGenerator
  681. ::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang)
  682. {
  683. cmTargets &tgts = this->Makefile->GetTargets();
  684. for(cmTargets::iterator l = tgts.begin();
  685. l != tgts.end(); l++)
  686. {
  687. cmTarget& target = l->second;
  688. switch(target.GetType())
  689. {
  690. case cmTarget::STATIC_LIBRARY:
  691. case cmTarget::SHARED_LIBRARY:
  692. case cmTarget::MODULE_LIBRARY:
  693. case cmTarget::EXECUTABLE:
  694. {
  695. const char* llang = target.GetLinkerLanguage();
  696. if(!llang)
  697. {
  698. cmSystemTools::Error
  699. ("CMake can not determine linker language for target:",
  700. target.GetName());
  701. return;
  702. }
  703. // if the language is not in the set lang then create custom
  704. // commands to build the target
  705. if(lang.count(llang) == 0)
  706. {
  707. this->AddBuildTargetRule(llang, target);
  708. }
  709. }
  710. break;
  711. default:
  712. break;
  713. }
  714. }
  715. }
  716. // List of variables that are replaced when
  717. // rules are expanced. These variables are
  718. // replaced in the form <var> with GetSafeDefinition(var).
  719. // ${LANG} is replaced in the variable first with all enabled
  720. // languages.
  721. static const char* ruleReplaceVars[] =
  722. {
  723. "CMAKE_${LANG}_COMPILER",
  724. "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
  725. "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
  726. "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
  727. "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
  728. "CMAKE_${LANG}_LINK_FLAGS",
  729. "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
  730. "CMAKE_${LANG}_ARCHIVE",
  731. "CMAKE_AR",
  732. "CMAKE_CURRENT_SOURCE_DIR",
  733. "CMAKE_CURRENT_BINARY_DIR",
  734. "CMAKE_RANLIB",
  735. "CMAKE_LINKER",
  736. 0
  737. };
  738. std::string
  739. cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
  740. const RuleVariables& replaceValues)
  741. {
  742. if(replaceValues.LinkFlags)
  743. {
  744. if(variable == "LINK_FLAGS")
  745. {
  746. return replaceValues.LinkFlags;
  747. }
  748. }
  749. if(replaceValues.Flags)
  750. {
  751. if(variable == "FLAGS")
  752. {
  753. return replaceValues.Flags;
  754. }
  755. }
  756. if(replaceValues.Source)
  757. {
  758. if(variable == "SOURCE")
  759. {
  760. return replaceValues.Source;
  761. }
  762. }
  763. if(replaceValues.PreprocessedSource)
  764. {
  765. if(variable == "PREPROCESSED_SOURCE")
  766. {
  767. return replaceValues.PreprocessedSource;
  768. }
  769. }
  770. if(replaceValues.AssemblySource)
  771. {
  772. if(variable == "ASSEMBLY_SOURCE")
  773. {
  774. return replaceValues.AssemblySource;
  775. }
  776. }
  777. if(replaceValues.Object)
  778. {
  779. if(variable == "OBJECT")
  780. {
  781. return replaceValues.Object;
  782. }
  783. }
  784. if(replaceValues.ObjectDir)
  785. {
  786. if(variable == "OBJECT_DIR")
  787. {
  788. return replaceValues.ObjectDir;
  789. }
  790. }
  791. if(replaceValues.Objects)
  792. {
  793. if(variable == "OBJECTS")
  794. {
  795. return replaceValues.Objects;
  796. }
  797. }
  798. if(replaceValues.ObjectsQuoted)
  799. {
  800. if(variable == "OBJECTS_QUOTED")
  801. {
  802. return replaceValues.ObjectsQuoted;
  803. }
  804. }
  805. if(replaceValues.Defines && variable == "DEFINES")
  806. {
  807. return replaceValues.Defines;
  808. }
  809. if(replaceValues.TargetPDB )
  810. {
  811. if(variable == "TARGET_PDB")
  812. {
  813. return replaceValues.TargetPDB;
  814. }
  815. }
  816. if(replaceValues.Target)
  817. {
  818. if(variable == "TARGET_QUOTED")
  819. {
  820. std::string targetQuoted = replaceValues.Target;
  821. if(targetQuoted.size() && targetQuoted[0] != '\"')
  822. {
  823. targetQuoted = '\"';
  824. targetQuoted += replaceValues.Target;
  825. targetQuoted += '\"';
  826. }
  827. return targetQuoted;
  828. }
  829. if(replaceValues.LanguageCompileFlags)
  830. {
  831. if(variable == "LANGUAGE_COMPILE_FLAGS")
  832. {
  833. return replaceValues.LanguageCompileFlags;
  834. }
  835. }
  836. if(replaceValues.Target)
  837. {
  838. if(variable == "TARGET")
  839. {
  840. return replaceValues.Target;
  841. }
  842. }
  843. if(variable == "TARGET_IMPLIB")
  844. {
  845. return this->TargetImplib;
  846. }
  847. if(variable == "TARGET_VERSION_MAJOR")
  848. {
  849. if(replaceValues.TargetVersionMajor)
  850. {
  851. return replaceValues.TargetVersionMajor;
  852. }
  853. else
  854. {
  855. return "0";
  856. }
  857. }
  858. if(variable == "TARGET_VERSION_MINOR")
  859. {
  860. if(replaceValues.TargetVersionMinor)
  861. {
  862. return replaceValues.TargetVersionMinor;
  863. }
  864. else
  865. {
  866. return "0";
  867. }
  868. }
  869. if(replaceValues.Target)
  870. {
  871. if(variable == "TARGET_BASE")
  872. {
  873. // Strip the last extension off the target name.
  874. std::string targetBase = replaceValues.Target;
  875. std::string::size_type pos = targetBase.rfind(".");
  876. if(pos != targetBase.npos)
  877. {
  878. return targetBase.substr(0, pos);
  879. }
  880. else
  881. {
  882. return targetBase;
  883. }
  884. }
  885. }
  886. }
  887. if(replaceValues.TargetSOName)
  888. {
  889. if(variable == "TARGET_SONAME")
  890. {
  891. if(replaceValues.Language)
  892. {
  893. std::string name = "CMAKE_SHARED_LIBRARY_SONAME_";
  894. name += replaceValues.Language;
  895. name += "_FLAG";
  896. if(this->Makefile->GetDefinition(name.c_str()))
  897. {
  898. return replaceValues.TargetSOName;
  899. }
  900. }
  901. return "";
  902. }
  903. }
  904. if(replaceValues.TargetInstallNameDir)
  905. {
  906. if(variable == "TARGET_INSTALLNAME_DIR")
  907. {
  908. return replaceValues.TargetInstallNameDir;
  909. }
  910. }
  911. if(replaceValues.LinkLibraries)
  912. {
  913. if(variable == "LINK_LIBRARIES")
  914. {
  915. return replaceValues.LinkLibraries;
  916. }
  917. }
  918. if(replaceValues.Language)
  919. {
  920. if(variable == "LANGUAGE")
  921. {
  922. return replaceValues.Language;
  923. }
  924. }
  925. if(replaceValues.CMTarget)
  926. {
  927. if(variable == "TARGET_NAME")
  928. {
  929. return replaceValues.CMTarget->GetName();
  930. }
  931. if(variable == "TARGET_TYPE")
  932. {
  933. return cmTarget::TargetTypeNames[replaceValues.CMTarget->GetType()];
  934. }
  935. }
  936. if(replaceValues.Output)
  937. {
  938. if(variable == "OUTPUT")
  939. {
  940. return replaceValues.Output;
  941. }
  942. }
  943. if(variable == "CMAKE_COMMAND")
  944. {
  945. const char* cmcommand =
  946. this->GetMakefile()->GetDefinition("CMAKE_COMMAND");
  947. return this->Convert(cmcommand, FULL, SHELL);
  948. }
  949. std::vector<std::string> enabledLanguages;
  950. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  951. // loop over language specific replace variables
  952. int pos = 0;
  953. while(ruleReplaceVars[pos])
  954. {
  955. for(std::vector<std::string>::iterator i = enabledLanguages.begin();
  956. i != enabledLanguages.end(); ++i)
  957. {
  958. const char* lang = i->c_str();
  959. std::string actualReplace = ruleReplaceVars[pos];
  960. // If this is the compiler then look for the extra variable
  961. // _COMPILER_ARG1 which must be the first argument to the compiler
  962. const char* compilerArg1 = 0;
  963. if(actualReplace == "CMAKE_${LANG}_COMPILER")
  964. {
  965. std::string arg1 = actualReplace + "_ARG1";
  966. cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
  967. compilerArg1 = this->Makefile->GetDefinition(arg1.c_str());
  968. }
  969. if(actualReplace.find("${LANG}") != actualReplace.npos)
  970. {
  971. cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
  972. }
  973. if(actualReplace == variable)
  974. {
  975. std::string replace =
  976. this->Makefile->GetSafeDefinition(variable.c_str());
  977. // if the variable is not a FLAG then treat it like a path
  978. if(variable.find("_FLAG") == variable.npos)
  979. {
  980. std::string ret = this->ConvertToOutputForExisting(replace.c_str());
  981. // if there is a required first argument to the compiler add it
  982. // to the compiler string
  983. if(compilerArg1)
  984. {
  985. ret += " ";
  986. ret += compilerArg1;
  987. }
  988. return ret;
  989. }
  990. return replace;
  991. }
  992. }
  993. pos++;
  994. }
  995. return variable;
  996. }
  997. void
  998. cmLocalGenerator::ExpandRuleVariables(std::string& s,
  999. const RuleVariables& replaceValues)
  1000. {
  1001. std::vector<std::string> enabledLanguages;
  1002. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  1003. this->InsertRuleLauncher(s, replaceValues.CMTarget,
  1004. replaceValues.RuleLauncher);
  1005. std::string::size_type start = s.find('<');
  1006. // no variables to expand
  1007. if(start == s.npos)
  1008. {
  1009. return;
  1010. }
  1011. std::string::size_type pos = 0;
  1012. std::string expandedInput;
  1013. while(start != s.npos && start < s.size()-2)
  1014. {
  1015. std::string::size_type end = s.find('>', start);
  1016. // if we find a < with no > we are done
  1017. if(end == s.npos)
  1018. {
  1019. return;
  1020. }
  1021. char c = s[start+1];
  1022. // if the next char after the < is not A-Za-z then
  1023. // skip it and try to find the next < in the string
  1024. if(!isalpha(c))
  1025. {
  1026. start = s.find('<', start+1);
  1027. }
  1028. else
  1029. {
  1030. // extract the var
  1031. std::string var = s.substr(start+1, end - start-1);
  1032. std::string replace = this->ExpandRuleVariable(var,
  1033. replaceValues);
  1034. expandedInput += s.substr(pos, start-pos);
  1035. expandedInput += replace;
  1036. // move to next one
  1037. start = s.find('<', start+var.size()+2);
  1038. pos = end+1;
  1039. }
  1040. }
  1041. // add the rest of the input
  1042. expandedInput += s.substr(pos, s.size()-pos);
  1043. s = expandedInput;
  1044. }
  1045. //----------------------------------------------------------------------------
  1046. const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
  1047. const char* prop)
  1048. {
  1049. if(target)
  1050. {
  1051. return target->GetProperty(prop);
  1052. }
  1053. else
  1054. {
  1055. return this->Makefile->GetProperty(prop);
  1056. }
  1057. }
  1058. //----------------------------------------------------------------------------
  1059. void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
  1060. const char* prop)
  1061. {
  1062. if(const char* val = this->GetRuleLauncher(target, prop))
  1063. {
  1064. cmOStringStream wrapped;
  1065. wrapped << val << " " << s;
  1066. s = wrapped.str();
  1067. }
  1068. }
  1069. //----------------------------------------------------------------------------
  1070. std::string
  1071. cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote,
  1072. std::string const& result)
  1073. {
  1074. // If this is a windows shell, the result has a space, and the path
  1075. // already exists, we can use a short-path to reference it without a
  1076. // space.
  1077. if(this->WindowsShell && result.find(' ') != result.npos &&
  1078. cmSystemTools::FileExists(remote))
  1079. {
  1080. std::string tmp;
  1081. if(cmSystemTools::GetShortPath(remote, tmp))
  1082. {
  1083. return this->Convert(tmp.c_str(), NONE, SHELL, true);
  1084. }
  1085. }
  1086. // Otherwise, leave it unchanged.
  1087. return result;
  1088. }
  1089. //----------------------------------------------------------------------------
  1090. std::string
  1091. cmLocalGenerator::ConvertToOutputForExisting(const char* remote,
  1092. RelativeRoot local)
  1093. {
  1094. // Perform standard conversion.
  1095. std::string result = this->Convert(remote, local, SHELL, true);
  1096. // Consider short-path.
  1097. return this->ConvertToOutputForExistingCommon(remote, result);
  1098. }
  1099. //----------------------------------------------------------------------------
  1100. std::string
  1101. cmLocalGenerator::ConvertToOutputForExisting(RelativeRoot remote,
  1102. const char* local)
  1103. {
  1104. // Perform standard conversion.
  1105. std::string result = this->Convert(remote, local, SHELL, true);
  1106. // Consider short-path.
  1107. const char* remotePath = this->GetRelativeRootPath(remote);
  1108. return this->ConvertToOutputForExistingCommon(remotePath, result);
  1109. }
  1110. //----------------------------------------------------------------------------
  1111. const char* cmLocalGenerator::GetIncludeFlags(const char* lang)
  1112. {
  1113. if(!lang)
  1114. {
  1115. return "";
  1116. }
  1117. if(this->LanguageToIncludeFlags.count(lang))
  1118. {
  1119. return this->LanguageToIncludeFlags[lang].c_str();
  1120. }
  1121. cmOStringStream includeFlags;
  1122. std::vector<std::string> includes;
  1123. this->GetIncludeDirectories(includes, lang);
  1124. std::vector<std::string>::iterator i;
  1125. std::string flagVar = "CMAKE_INCLUDE_FLAG_";
  1126. flagVar += lang;
  1127. const char* includeFlag =
  1128. this->Makefile->GetSafeDefinition(flagVar.c_str());
  1129. flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
  1130. flagVar += lang;
  1131. const char* sep = this->Makefile->GetDefinition(flagVar.c_str());
  1132. bool quotePaths = false;
  1133. if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
  1134. {
  1135. quotePaths = true;
  1136. }
  1137. bool repeatFlag = true;
  1138. // should the include flag be repeated like ie. -IA -IB
  1139. if(!sep)
  1140. {
  1141. sep = " ";
  1142. }
  1143. else
  1144. {
  1145. // if there is a separator then the flag is not repeated but is only
  1146. // given once i.e. -classpath a:b:c
  1147. repeatFlag = false;
  1148. }
  1149. // Support special system include flag if it is available and the
  1150. // normal flag is repeated for each directory.
  1151. std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
  1152. sysFlagVar += lang;
  1153. const char* sysIncludeFlag = 0;
  1154. if(repeatFlag)
  1155. {
  1156. sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar.c_str());
  1157. }
  1158. bool flagUsed = false;
  1159. std::set<cmStdString> emitted;
  1160. #ifdef __APPLE__
  1161. emitted.insert("/System/Library/Frameworks");
  1162. #endif
  1163. for(i = includes.begin(); i != includes.end(); ++i)
  1164. {
  1165. #ifdef __APPLE__
  1166. if(cmSystemTools::IsPathToFramework(i->c_str()))
  1167. {
  1168. std::string frameworkDir = *i;
  1169. frameworkDir += "/../";
  1170. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1171. if(emitted.insert(frameworkDir).second)
  1172. {
  1173. includeFlags
  1174. << "-F" << this->Convert(frameworkDir.c_str(),
  1175. cmLocalGenerator::START_OUTPUT,
  1176. cmLocalGenerator::SHELL, true)
  1177. << " ";
  1178. }
  1179. continue;
  1180. }
  1181. #endif
  1182. std::string include = *i;
  1183. if(!flagUsed || repeatFlag)
  1184. {
  1185. if(sysIncludeFlag &&
  1186. this->Makefile->IsSystemIncludeDirectory(i->c_str()))
  1187. {
  1188. includeFlags << sysIncludeFlag;
  1189. }
  1190. else
  1191. {
  1192. includeFlags << includeFlag;
  1193. }
  1194. flagUsed = true;
  1195. }
  1196. std::string includePath = this->ConvertToOutputForExisting(i->c_str());
  1197. if(quotePaths && includePath.size() && includePath[0] != '\"')
  1198. {
  1199. includeFlags << "\"";
  1200. }
  1201. includeFlags << includePath;
  1202. if(quotePaths && includePath.size() && includePath[0] != '\"')
  1203. {
  1204. includeFlags << "\"";
  1205. }
  1206. includeFlags << sep;
  1207. }
  1208. std::string flags = includeFlags.str();
  1209. // remove trailing separators
  1210. if((sep[0] != ' ') && flags.size()>0 && flags[flags.size()-1] == sep[0])
  1211. {
  1212. flags[flags.size()-1] = ' ';
  1213. }
  1214. std::string defineFlags = this->Makefile->GetDefineFlags();
  1215. flags += defineFlags;
  1216. this->LanguageToIncludeFlags[lang] = flags;
  1217. // Use this temorary variable for the return value to work-around a
  1218. // bogus GCC 2.95 warning.
  1219. const char* ret = this->LanguageToIncludeFlags[lang].c_str();
  1220. return ret;
  1221. }
  1222. //----------------------------------------------------------------------------
  1223. void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
  1224. const char* lang)
  1225. {
  1226. // Need to decide whether to automatically include the source and
  1227. // binary directories at the beginning of the include path.
  1228. bool includeSourceDir = false;
  1229. bool includeBinaryDir = false;
  1230. // When automatic include directories are requested for a build then
  1231. // include the source and binary directories at the beginning of the
  1232. // include path to approximate include file behavior for an
  1233. // in-source build. This does not account for the case of a source
  1234. // file in a subdirectory of the current source directory but we
  1235. // cannot fix this because not all native build tools support
  1236. // per-source-file include paths.
  1237. if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
  1238. {
  1239. includeSourceDir = true;
  1240. includeBinaryDir = true;
  1241. }
  1242. // CMake versions below 2.0 would add the source tree to the -I path
  1243. // automatically. Preserve compatibility.
  1244. if(this->NeedBackwardsCompatibility(1,9))
  1245. {
  1246. includeSourceDir = true;
  1247. }
  1248. // Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
  1249. // not set the backwards compatibility level automatically.
  1250. const char* vtkSourceDir =
  1251. this->Makefile->GetDefinition("VTK_SOURCE_DIR");
  1252. if(vtkSourceDir)
  1253. {
  1254. const char* vtk_major =
  1255. this->Makefile->GetDefinition("VTK_MAJOR_VERSION");
  1256. const char* vtk_minor =
  1257. this->Makefile->GetDefinition("VTK_MINOR_VERSION");
  1258. vtk_major = vtk_major? vtk_major : "4";
  1259. vtk_minor = vtk_minor? vtk_minor : "4";
  1260. int vmajor = 0;
  1261. int vminor = 0;
  1262. if(sscanf(vtk_major, "%d", &vmajor) &&
  1263. sscanf(vtk_minor, "%d", &vminor) && vmajor == 4 && vminor <= 4)
  1264. {
  1265. includeSourceDir = true;
  1266. }
  1267. }
  1268. // Do not repeat an include path.
  1269. std::set<cmStdString> emitted;
  1270. // Store the automatic include paths.
  1271. if(includeBinaryDir)
  1272. {
  1273. dirs.push_back(this->Makefile->GetStartOutputDirectory());
  1274. emitted.insert(this->Makefile->GetStartOutputDirectory());
  1275. }
  1276. if(includeSourceDir)
  1277. {
  1278. if(emitted.find(this->Makefile->GetStartDirectory()) == emitted.end())
  1279. {
  1280. dirs.push_back(this->Makefile->GetStartDirectory());
  1281. emitted.insert(this->Makefile->GetStartDirectory());
  1282. }
  1283. }
  1284. // Load implicit include directories for this language.
  1285. std::string impDirVar = "CMAKE_";
  1286. impDirVar += lang;
  1287. impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
  1288. if(const char* value = this->Makefile->GetDefinition(impDirVar.c_str()))
  1289. {
  1290. std::vector<std::string> impDirVec;
  1291. cmSystemTools::ExpandListArgument(value, impDirVec);
  1292. for(std::vector<std::string>::const_iterator i = impDirVec.begin();
  1293. i != impDirVec.end(); ++i)
  1294. {
  1295. emitted.insert(*i);
  1296. }
  1297. }
  1298. // Get the project-specified include directories.
  1299. std::vector<std::string>& includes =
  1300. this->Makefile->GetIncludeDirectories();
  1301. // Support putting all the in-project include directories first if
  1302. // it is requested by the project.
  1303. if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
  1304. {
  1305. const char* topSourceDir = this->Makefile->GetHomeDirectory();
  1306. const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
  1307. for(std::vector<std::string>::iterator i = includes.begin();
  1308. i != includes.end(); ++i)
  1309. {
  1310. // Emit this directory only if it is a subdirectory of the
  1311. // top-level source or binary tree.
  1312. if(cmSystemTools::ComparePath(i->c_str(), topSourceDir) ||
  1313. cmSystemTools::ComparePath(i->c_str(), topBinaryDir) ||
  1314. cmSystemTools::IsSubDirectory(i->c_str(), topSourceDir) ||
  1315. cmSystemTools::IsSubDirectory(i->c_str(), topBinaryDir))
  1316. {
  1317. if(emitted.insert(*i).second)
  1318. {
  1319. dirs.push_back(*i);
  1320. }
  1321. }
  1322. }
  1323. }
  1324. // Construct the final ordered include directory list.
  1325. for(std::vector<std::string>::iterator i = includes.begin();
  1326. i != includes.end(); ++i)
  1327. {
  1328. if(emitted.insert(*i).second)
  1329. {
  1330. dirs.push_back(*i);
  1331. }
  1332. }
  1333. }
  1334. void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
  1335. std::string& flags,
  1336. std::string& linkFlags,
  1337. cmTarget& target)
  1338. {
  1339. std::string buildType =
  1340. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1341. buildType = cmSystemTools::UpperCase(buildType);
  1342. const char* libraryLinkVariable =
  1343. "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
  1344. switch(target.GetType())
  1345. {
  1346. case cmTarget::STATIC_LIBRARY:
  1347. {
  1348. const char* targetLinkFlags =
  1349. target.GetProperty("STATIC_LIBRARY_FLAGS");
  1350. if(targetLinkFlags)
  1351. {
  1352. linkFlags += targetLinkFlags;
  1353. linkFlags += " ";
  1354. }
  1355. }
  1356. break;
  1357. case cmTarget::MODULE_LIBRARY:
  1358. libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
  1359. case cmTarget::SHARED_LIBRARY:
  1360. {
  1361. linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
  1362. linkFlags += " ";
  1363. if(buildType.size())
  1364. {
  1365. std::string build = libraryLinkVariable;
  1366. build += "_";
  1367. build += buildType;
  1368. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1369. linkFlags += " ";
  1370. }
  1371. if(this->Makefile->IsOn("WIN32") &&
  1372. !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
  1373. {
  1374. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  1375. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1376. i != sources.end(); ++i)
  1377. {
  1378. cmSourceFile* sf = *i;
  1379. if(sf->GetExtension() == "def")
  1380. {
  1381. linkFlags +=
  1382. this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1383. linkFlags += this->Convert(sf->GetFullPath().c_str(),
  1384. START_OUTPUT, SHELL);
  1385. linkFlags += " ";
  1386. }
  1387. }
  1388. }
  1389. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1390. if(targetLinkFlags)
  1391. {
  1392. linkFlags += targetLinkFlags;
  1393. linkFlags += " ";
  1394. std::string configLinkFlags = targetLinkFlags;
  1395. configLinkFlags += buildType;
  1396. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1397. if(targetLinkFlags)
  1398. {
  1399. linkFlags += targetLinkFlags;
  1400. linkFlags += " ";
  1401. }
  1402. }
  1403. cmOStringStream linklibsStr;
  1404. this->OutputLinkLibraries(linklibsStr, target, false);
  1405. linkLibs = linklibsStr.str();
  1406. }
  1407. break;
  1408. case cmTarget::EXECUTABLE:
  1409. {
  1410. linkFlags +=
  1411. this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1412. linkFlags += " ";
  1413. if(buildType.size())
  1414. {
  1415. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1416. build += buildType;
  1417. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1418. linkFlags += " ";
  1419. }
  1420. const char* linkLanguage = target.GetLinkerLanguage();
  1421. if(!linkLanguage)
  1422. {
  1423. cmSystemTools::Error
  1424. ("CMake can not determine linker language for target:",
  1425. target.GetName());
  1426. return;
  1427. }
  1428. std::string langVar = "CMAKE_";
  1429. langVar += linkLanguage;
  1430. std::string flagsVar = langVar + "_FLAGS";
  1431. std::string sharedFlagsVar = "CMAKE_SHARED_LIBRARY_";
  1432. sharedFlagsVar += linkLanguage;
  1433. sharedFlagsVar += "_FLAGS";
  1434. flags += this->Makefile->GetSafeDefinition(flagsVar.c_str());
  1435. flags += " ";
  1436. flags += this->Makefile->GetSafeDefinition(sharedFlagsVar.c_str());
  1437. flags += " ";
  1438. cmOStringStream linklibs;
  1439. this->OutputLinkLibraries(linklibs, target, false);
  1440. linkLibs = linklibs.str();
  1441. if(cmSystemTools::IsOn
  1442. (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1443. {
  1444. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
  1445. + linkLanguage + std::string("_FLAGS");
  1446. linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str());
  1447. linkFlags += " ";
  1448. }
  1449. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  1450. {
  1451. linkFlags +=
  1452. this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1453. linkFlags += " ";
  1454. }
  1455. else
  1456. {
  1457. linkFlags +=
  1458. this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1459. linkFlags += " ";
  1460. }
  1461. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1462. if(targetLinkFlags)
  1463. {
  1464. linkFlags += targetLinkFlags;
  1465. linkFlags += " ";
  1466. std::string configLinkFlags = targetLinkFlags;
  1467. configLinkFlags += buildType;
  1468. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1469. if(targetLinkFlags)
  1470. {
  1471. linkFlags += targetLinkFlags;
  1472. linkFlags += " ";
  1473. }
  1474. }
  1475. }
  1476. break;
  1477. default:
  1478. break;
  1479. }
  1480. }
  1481. std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib)
  1482. {
  1483. #if defined(_WIN32) && !defined(__CYGWIN__)
  1484. // Work-ardound command line parsing limitations in MSVC 6.0 and
  1485. // Watcom.
  1486. if(this->Makefile->IsOn("MSVC60") || this->Makefile->IsOn("WATCOM"))
  1487. {
  1488. // Search for the last space.
  1489. std::string::size_type pos = lib.rfind(' ');
  1490. if(pos != lib.npos)
  1491. {
  1492. // Find the slash after the last space, if any.
  1493. pos = lib.find('/', pos);
  1494. // Convert the portion of the path with a space to a short path.
  1495. std::string sp;
  1496. if(cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp))
  1497. {
  1498. // Append the rest of the path with no space.
  1499. sp += lib.substr(pos);
  1500. // Convert to an output path.
  1501. return this->Convert(sp.c_str(), NONE, SHELL);
  1502. }
  1503. }
  1504. }
  1505. #endif
  1506. // Normal behavior.
  1507. return this->Convert(lib.c_str(), START_OUTPUT, SHELL);
  1508. }
  1509. /**
  1510. * Output the linking rules on a command line. For executables,
  1511. * targetLibrary should be a NULL pointer. For libraries, it should point
  1512. * to the name of the library. This will not link a library against itself.
  1513. */
  1514. void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout,
  1515. cmTarget& tgt,
  1516. bool relink)
  1517. {
  1518. const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  1519. cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config);
  1520. if(!pcli)
  1521. {
  1522. return;
  1523. }
  1524. cmComputeLinkInformation& cli = *pcli;
  1525. // Collect library linking flags command line options.
  1526. std::string linkLibs;
  1527. const char* linkLanguage = cli.GetLinkLanguage();
  1528. std::string libPathFlag =
  1529. this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
  1530. std::string libPathTerminator =
  1531. this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
  1532. // Flags to link an executable to shared libraries.
  1533. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
  1534. linkFlagsVar += linkLanguage;
  1535. linkFlagsVar += "_FLAGS";
  1536. if( tgt.GetType() == cmTarget::EXECUTABLE )
  1537. {
  1538. linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str());
  1539. linkLibs += " ";
  1540. }
  1541. // Append the framework search path flags.
  1542. std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
  1543. for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1544. fdi != fwDirs.end(); ++fdi)
  1545. {
  1546. linkLibs += "-F";
  1547. linkLibs += this->Convert(fdi->c_str(), NONE, SHELL, false);
  1548. linkLibs += " ";
  1549. }
  1550. // Append the library search path flags.
  1551. std::vector<std::string> const& libDirs = cli.GetDirectories();
  1552. for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
  1553. libDir != libDirs.end(); ++libDir)
  1554. {
  1555. std::string libpath = this->ConvertToOutputForExisting(libDir->c_str());
  1556. linkLibs += libPathFlag;
  1557. linkLibs += libpath;
  1558. linkLibs += libPathTerminator;
  1559. linkLibs += " ";
  1560. }
  1561. // Append the link items.
  1562. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1563. ItemVector const& items = cli.GetItems();
  1564. for(ItemVector::const_iterator li = items.begin(); li != items.end(); ++li)
  1565. {
  1566. if(li->IsPath)
  1567. {
  1568. linkLibs += this->ConvertToLinkReference(li->Value);
  1569. }
  1570. else
  1571. {
  1572. linkLibs += li->Value;
  1573. }
  1574. linkLibs += " ";
  1575. }
  1576. // Write the library flags to the build rule.
  1577. fout << linkLibs;
  1578. // Get the RPATH entries.
  1579. std::vector<std::string> runtimeDirs;
  1580. cli.GetRPath(runtimeDirs, relink);
  1581. // Check what kind of rpath flags to use.
  1582. if(cli.GetRuntimeSep().empty())
  1583. {
  1584. // Each rpath entry gets its own option ("-R a -R b -R c")
  1585. std::string rpath;
  1586. for(std::vector<std::string>::iterator ri = runtimeDirs.begin();
  1587. ri != runtimeDirs.end(); ++ri)
  1588. {
  1589. rpath += cli.GetRuntimeFlag();
  1590. rpath += this->Convert(ri->c_str(), NONE, SHELL, false);
  1591. rpath += " ";
  1592. }
  1593. fout << rpath;
  1594. }
  1595. else
  1596. {
  1597. // All rpath entries are combined ("-Wl,-rpath,a:b:c").
  1598. std::string rpath = cli.GetRPathString(relink);
  1599. // Store the rpath option in the stream.
  1600. if(!rpath.empty())
  1601. {
  1602. fout << cli.GetRuntimeFlag();
  1603. fout << this->EscapeForShell(rpath.c_str(), true);
  1604. fout << " ";
  1605. }
  1606. }
  1607. // Add the linker runtime search path if any.
  1608. std::string rpath_link = cli.GetRPathLinkString();
  1609. if(!cli.GetRPathLinkFlag().empty() && !rpath_link.empty())
  1610. {
  1611. fout << cli.GetRPathLinkFlag();
  1612. fout << this->EscapeForShell(rpath_link.c_str(), true);
  1613. fout << " ";
  1614. }
  1615. // Add standard libraries for this language.
  1616. std::string standardLibsVar = "CMAKE_";
  1617. standardLibsVar += cli.GetLinkLanguage();
  1618. standardLibsVar += "_STANDARD_LIBRARIES";
  1619. if(const char* stdLibs =
  1620. this->Makefile->GetDefinition(standardLibsVar.c_str()))
  1621. {
  1622. fout << stdLibs << " ";
  1623. }
  1624. }
  1625. //----------------------------------------------------------------------------
  1626. void cmLocalGenerator::AddLanguageFlags(std::string& flags,
  1627. const char* lang,
  1628. const char* config)
  1629. {
  1630. // Add language-specific flags.
  1631. std::string flagsVar = "CMAKE_";
  1632. flagsVar += lang;
  1633. flagsVar += "_FLAGS";
  1634. // Add special OSX flags
  1635. #ifdef __APPLE__
  1636. if(this->EmitUniversalBinaryFlags)
  1637. {
  1638. const char* osxArch =
  1639. this->Makefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
  1640. const char* sysroot =
  1641. this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
  1642. const char* sysrootDefault =
  1643. this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT_DEFAULT");
  1644. const char* deploymentTarget =
  1645. this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
  1646. std::string isysrootVar = std::string("CMAKE_") + lang + "_HAS_ISYSROOT";
  1647. bool hasIsysroot = this->Makefile->IsOn(isysrootVar.c_str());
  1648. bool flagsUsed = false;
  1649. if(osxArch && sysroot && lang && (lang[0] =='C' || lang[0] == 'F'))
  1650. {
  1651. std::vector<std::string> archs;
  1652. cmSystemTools::ExpandListArgument(std::string(osxArch),
  1653. archs);
  1654. bool addArchFlag = false;
  1655. if(archs.size() >= 1)
  1656. {
  1657. if(archs[0] != "")
  1658. {
  1659. addArchFlag = true;
  1660. }
  1661. }
  1662. // if there is more than one arch add the -arch and
  1663. // -isysroot flags, or if there is one arch flag, but
  1664. // it is not the default -arch flag for the system, then
  1665. // add it. Otherwize do not add -arch and -isysroot
  1666. if(addArchFlag)
  1667. {
  1668. for( std::vector<std::string>::iterator i = archs.begin();
  1669. i != archs.end(); ++i)
  1670. {
  1671. flags += " -arch ";
  1672. flags += *i;
  1673. }
  1674. if(hasIsysroot)
  1675. {
  1676. flags += " -isysroot ";
  1677. flags += sysroot;
  1678. }
  1679. flagsUsed = true;
  1680. }
  1681. }
  1682. if(!flagsUsed && sysroot && sysrootDefault &&
  1683. strcmp(sysroot, sysrootDefault) != 0 && hasIsysroot)
  1684. {
  1685. flags += " -isysroot ";
  1686. flags += sysroot;
  1687. }
  1688. if (deploymentTarget && *deploymentTarget &&
  1689. lang && (lang[0] =='C' || lang[0] == 'F'))
  1690. {
  1691. flags += " -mmacosx-version-min=";
  1692. flags += deploymentTarget;
  1693. }
  1694. }
  1695. #endif
  1696. this->AddConfigVariableFlags(flags, flagsVar.c_str(), config);
  1697. }
  1698. //----------------------------------------------------------------------------
  1699. std::string cmLocalGenerator::GetRealDependency(const char* inName,
  1700. const char* config)
  1701. {
  1702. // Older CMake code may specify the dependency using the target
  1703. // output file rather than the target name. Such code would have
  1704. // been written before there was support for target properties that
  1705. // modify the name so stripping down to just the file name should
  1706. // produce the target name in this case.
  1707. std::string name = cmSystemTools::GetFilenameName(inName);
  1708. if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
  1709. {
  1710. name = cmSystemTools::GetFilenameWithoutLastExtension(name);
  1711. }
  1712. // Look for a CMake target with the given name.
  1713. if(cmTarget* target = this->Makefile->FindTargetToUse(name.c_str()))
  1714. {
  1715. // make sure it is not just a coincidence that the target name
  1716. // found is part of the inName
  1717. if(cmSystemTools::FileIsFullPath(inName))
  1718. {
  1719. std::string tLocation = target->GetLocation(config);
  1720. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1721. std::string depLocation = cmSystemTools::GetFilenamePath(
  1722. std::string(inName));
  1723. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  1724. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  1725. if(depLocation != tLocation)
  1726. {
  1727. // it is a full path to a depend that has the same name
  1728. // as a target but is in a different location so do not use
  1729. // the target as the depend
  1730. return inName;
  1731. }
  1732. }
  1733. switch (target->GetType())
  1734. {
  1735. case cmTarget::EXECUTABLE:
  1736. case cmTarget::STATIC_LIBRARY:
  1737. case cmTarget::SHARED_LIBRARY:
  1738. case cmTarget::MODULE_LIBRARY:
  1739. case cmTarget::UNKNOWN_LIBRARY:
  1740. {
  1741. // Get the location of the target's output file and depend on it.
  1742. if(const char* location = target->GetLocation(config))
  1743. {
  1744. return location;
  1745. }
  1746. }
  1747. break;
  1748. case cmTarget::UTILITY:
  1749. case cmTarget::GLOBAL_TARGET:
  1750. // Depending on a utility target may not work but just trust
  1751. // the user to have given a valid name.
  1752. return inName;
  1753. case cmTarget::INSTALL_FILES:
  1754. case cmTarget::INSTALL_PROGRAMS:
  1755. case cmTarget::INSTALL_DIRECTORY:
  1756. break;
  1757. }
  1758. }
  1759. // The name was not that of a CMake target. It must name a file.
  1760. if(cmSystemTools::FileIsFullPath(inName))
  1761. {
  1762. // This is a full path. Return it as given.
  1763. return inName;
  1764. }
  1765. // Check for a source file in this directory that matches the
  1766. // dependency.
  1767. if(cmSourceFile* sf = this->Makefile->GetSource(inName))
  1768. {
  1769. name = sf->GetFullPath();
  1770. return name;
  1771. }
  1772. // Treat the name as relative to the source directory in which it
  1773. // was given.
  1774. name = this->Makefile->GetCurrentDirectory();
  1775. name += "/";
  1776. name += inName;
  1777. return name;
  1778. }
  1779. //----------------------------------------------------------------------------
  1780. std::string cmLocalGenerator::GetRealLocation(const char* inName,
  1781. const char* config)
  1782. {
  1783. std::string outName=inName;
  1784. // Look for a CMake target with the given name, which is an executable
  1785. // and which can be run
  1786. cmTarget* target = this->Makefile->FindTargetToUse(inName);
  1787. if ((target != 0)
  1788. && (target->GetType() == cmTarget::EXECUTABLE)
  1789. && ((this->Makefile->IsOn("CMAKE_CROSSCOMPILING") == false)
  1790. || (target->IsImported() == true)))
  1791. {
  1792. outName = target->GetLocation( config );
  1793. }
  1794. return outName;
  1795. }
  1796. //----------------------------------------------------------------------------
  1797. void cmLocalGenerator::AddSharedFlags(std::string& flags,
  1798. const char* lang,
  1799. bool shared)
  1800. {
  1801. std::string flagsVar;
  1802. // Add flags for dealing with shared libraries for this language.
  1803. if(shared)
  1804. {
  1805. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1806. flagsVar += lang;
  1807. flagsVar += "_FLAGS";
  1808. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1809. }
  1810. // Add flags specific to shared builds.
  1811. if(cmSystemTools::IsOn(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1812. {
  1813. flagsVar = "CMAKE_SHARED_BUILD_";
  1814. flagsVar += lang;
  1815. flagsVar += "_FLAGS";
  1816. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1817. }
  1818. }
  1819. //----------------------------------------------------------------------------
  1820. void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
  1821. const char* var,
  1822. const char* config)
  1823. {
  1824. // Add the flags from the variable itself.
  1825. std::string flagsVar = var;
  1826. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1827. // Add the flags from the build-type specific variable.
  1828. if(config && *config)
  1829. {
  1830. flagsVar += "_";
  1831. flagsVar += cmSystemTools::UpperCase(config);
  1832. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1833. }
  1834. }
  1835. //----------------------------------------------------------------------------
  1836. void cmLocalGenerator::AppendFlags(std::string& flags,
  1837. const char* newFlags)
  1838. {
  1839. if(newFlags && *newFlags)
  1840. {
  1841. std::string newf = newFlags;
  1842. if(flags.size())
  1843. {
  1844. flags += " ";
  1845. }
  1846. flags += newFlags;
  1847. }
  1848. }
  1849. //----------------------------------------------------------------------------
  1850. void cmLocalGenerator::AppendDefines(std::string& defines,
  1851. const char* defines_list,
  1852. const char* lang)
  1853. {
  1854. // Short-circuit if there are no definitions.
  1855. if(!defines_list)
  1856. {
  1857. return;
  1858. }
  1859. // Expand the list of definitions.
  1860. std::vector<std::string> defines_vec;
  1861. cmSystemTools::ExpandListArgument(defines_list, defines_vec);
  1862. // Short-circuit if there are no definitions.
  1863. if(defines_vec.empty())
  1864. {
  1865. return;
  1866. }
  1867. // Lookup the define flag for the current language.
  1868. std::string dflag = "-D";
  1869. if(lang)
  1870. {
  1871. std::string defineFlagVar = "CMAKE_";
  1872. defineFlagVar += lang;
  1873. defineFlagVar += "_DEFINE_FLAG";
  1874. const char* df = this->Makefile->GetDefinition(defineFlagVar.c_str());
  1875. if(df && *df)
  1876. {
  1877. dflag = df;
  1878. }
  1879. }
  1880. // Add each definition to the command line with appropriate escapes.
  1881. const char* dsep = defines.empty()? "" : " ";
  1882. for(std::vector<std::string>::const_iterator di = defines_vec.begin();
  1883. di != defines_vec.end(); ++di)
  1884. {
  1885. // Skip unsupported definitions.
  1886. if(!this->CheckDefinition(*di))
  1887. {
  1888. continue;
  1889. }
  1890. // Separate from previous definitions.
  1891. defines += dsep;
  1892. dsep = " ";
  1893. // Append the definition with proper escaping.
  1894. defines += dflag;
  1895. if(this->WatcomWMake)
  1896. {
  1897. // The Watcom compiler does its own command line parsing instead
  1898. // of using the windows shell rules. Definitions are one of
  1899. // -DNAME
  1900. // -DNAME=<cpp-token>
  1901. // -DNAME="c-string with spaces and other characters(?@#$)"
  1902. //
  1903. // Watcom will properly parse each of these cases from the
  1904. // command line without any escapes. However we still have to
  1905. // get the '$' and '#' characters through WMake as '$$' and
  1906. // '$#'.
  1907. for(const char* c = di->c_str(); *c; ++c)
  1908. {
  1909. if(*c == '$' || *c == '#')
  1910. {
  1911. defines += '$';
  1912. }
  1913. defines += *c;
  1914. }
  1915. }
  1916. else
  1917. {
  1918. // Make the definition appear properly on the command line. Use
  1919. // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.
  1920. std::string::size_type eq = di->find("=");
  1921. defines += di->substr(0, eq);
  1922. if(eq != di->npos)
  1923. {
  1924. defines += "=";
  1925. defines += this->EscapeForShell(di->c_str() + eq + 1, true);
  1926. }
  1927. }
  1928. }
  1929. }
  1930. //----------------------------------------------------------------------------
  1931. std::string
  1932. cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
  1933. const char* default_comment)
  1934. {
  1935. // Check for a comment provided with the command.
  1936. if(cc.GetComment())
  1937. {
  1938. return cc.GetComment();
  1939. }
  1940. // Construct a reasonable default comment if possible.
  1941. if(!cc.GetOutputs().empty())
  1942. {
  1943. std::string comment;
  1944. comment = "Generating ";
  1945. const char* sep = "";
  1946. for(std::vector<std::string>::const_iterator o = cc.GetOutputs().begin();
  1947. o != cc.GetOutputs().end(); ++o)
  1948. {
  1949. comment += sep;
  1950. comment += this->Convert(o->c_str(), cmLocalGenerator::START_OUTPUT);
  1951. sep = ", ";
  1952. }
  1953. return comment;
  1954. }
  1955. // Otherwise use the provided default.
  1956. return default_comment;
  1957. }
  1958. //----------------------------------------------------------------------------
  1959. std::string
  1960. cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote)
  1961. {
  1962. return this->Convert(remote, START_OUTPUT, SHELL, true);
  1963. }
  1964. //----------------------------------------------------------------------------
  1965. const char* cmLocalGenerator::GetRelativeRootPath(RelativeRoot relroot)
  1966. {
  1967. switch (relroot)
  1968. {
  1969. case HOME: return this->Makefile->GetHomeDirectory();
  1970. case START: return this->Makefile->GetStartDirectory();
  1971. case HOME_OUTPUT: return this->Makefile->GetHomeOutputDirectory();
  1972. case START_OUTPUT: return this->Makefile->GetStartOutputDirectory();
  1973. default: break;
  1974. }
  1975. return 0;
  1976. }
  1977. //----------------------------------------------------------------------------
  1978. std::string cmLocalGenerator::Convert(const char* source,
  1979. RelativeRoot relative,
  1980. OutputFormat output,
  1981. bool optional)
  1982. {
  1983. // Make sure the relative path conversion components are set.
  1984. if(!this->PathConversionsSetup)
  1985. {
  1986. this->SetupPathConversions();
  1987. this->PathConversionsSetup = true;
  1988. }
  1989. // Convert the path to a relative path.
  1990. std::string result = source;
  1991. if (!optional || this->UseRelativePaths)
  1992. {
  1993. switch (relative)
  1994. {
  1995. case HOME:
  1996. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1997. result = this->ConvertToRelativePath(this->HomeDirectoryComponents,
  1998. result.c_str());
  1999. break;
  2000. case START:
  2001. //result = cmSystemTools::CollapseFullPath(result.c_str());
  2002. result = this->ConvertToRelativePath(this->StartDirectoryComponents,
  2003. result.c_str());
  2004. break;
  2005. case HOME_OUTPUT:
  2006. //result = cmSystemTools::CollapseFullPath(result.c_str());
  2007. result =
  2008. this->ConvertToRelativePath(this->HomeOutputDirectoryComponents,
  2009. result.c_str());
  2010. break;
  2011. case START_OUTPUT:
  2012. //result = cmSystemTools::CollapseFullPath(result.c_str());
  2013. result =
  2014. this->ConvertToRelativePath(this->StartOutputDirectoryComponents,
  2015. result.c_str());
  2016. break;
  2017. case FULL:
  2018. result = cmSystemTools::CollapseFullPath(result.c_str());
  2019. break;
  2020. case NONE:
  2021. break;
  2022. }
  2023. }
  2024. return this->ConvertToOutputFormat(result.c_str(), output);
  2025. }
  2026. //----------------------------------------------------------------------------
  2027. std::string cmLocalGenerator::ConvertToOutputFormat(const char* source,
  2028. OutputFormat output)
  2029. {
  2030. std::string result = source;
  2031. // Convert it to an output path.
  2032. if (output == MAKEFILE)
  2033. {
  2034. result = cmSystemTools::ConvertToOutputPath(result.c_str());
  2035. }
  2036. else if( output == SHELL)
  2037. {
  2038. // For the MSYS shell convert drive letters to posix paths, so
  2039. // that c:/some/path becomes /c/some/path. This is needed to
  2040. // avoid problems with the shell path translation.
  2041. if(this->MSYSShell && !this->LinkScriptShell)
  2042. {
  2043. if(result.size() > 2 && result[1] == ':')
  2044. {
  2045. result[1] = result[0];
  2046. result[0] = '/';
  2047. }
  2048. }
  2049. if(this->WindowsShell)
  2050. {
  2051. std::string::size_type pos = 0;
  2052. while((pos = result.find('/', pos)) != std::string::npos)
  2053. {
  2054. result[pos] = '\\';
  2055. pos++;
  2056. }
  2057. }
  2058. result = this->EscapeForShell(result.c_str(), true, false);
  2059. }
  2060. return result;
  2061. }
  2062. //----------------------------------------------------------------------------
  2063. std::string cmLocalGenerator::Convert(RelativeRoot remote,
  2064. const char* local,
  2065. OutputFormat output,
  2066. bool optional)
  2067. {
  2068. const char* remotePath = this->GetRelativeRootPath(remote);
  2069. // The relative root must have a path (i.e. not FULL or NONE)
  2070. assert(remotePath != 0);
  2071. if(local && (!optional || this->UseRelativePaths))
  2072. {
  2073. std::vector<std::string> components;
  2074. cmSystemTools::SplitPath(local, components);
  2075. std::string result = this->ConvertToRelativePath(components, remotePath);
  2076. return this->ConvertToOutputFormat(result.c_str(), output);
  2077. }
  2078. else
  2079. {
  2080. return this->ConvertToOutputFormat(remotePath, output);
  2081. }
  2082. }
  2083. //----------------------------------------------------------------------------
  2084. std::string cmLocalGenerator::FindRelativePathTopSource()
  2085. {
  2086. // Relative path conversion within a single tree managed by CMake is
  2087. // safe. We can use our parent relative path top if and only if
  2088. // this is a subdirectory of that top.
  2089. if(cmLocalGenerator* parent = this->GetParent())
  2090. {
  2091. std::string parentTop = parent->FindRelativePathTopSource();
  2092. if(cmSystemTools::IsSubDirectory(
  2093. this->Makefile->GetStartDirectory(), parentTop.c_str()))
  2094. {
  2095. return parentTop;
  2096. }
  2097. }
  2098. // Otherwise this directory itself is the new top.
  2099. return this->Makefile->GetStartDirectory();
  2100. }
  2101. //----------------------------------------------------------------------------
  2102. std::string cmLocalGenerator::FindRelativePathTopBinary()
  2103. {
  2104. // Relative path conversion within a single tree managed by CMake is
  2105. // safe. We can use our parent relative path top if and only if
  2106. // this is a subdirectory of that top.
  2107. if(cmLocalGenerator* parent = this->GetParent())
  2108. {
  2109. std::string parentTop = parent->FindRelativePathTopBinary();
  2110. if(cmSystemTools::IsSubDirectory(
  2111. this->Makefile->GetStartOutputDirectory(), parentTop.c_str()))
  2112. {
  2113. return parentTop;
  2114. }
  2115. }
  2116. // Otherwise this directory itself is the new top.
  2117. return this->Makefile->GetStartOutputDirectory();
  2118. }
  2119. //----------------------------------------------------------------------------
  2120. void cmLocalGenerator::ConfigureRelativePaths()
  2121. {
  2122. // Relative path conversion inside the source tree is not used to
  2123. // construct relative paths passed to build tools so it is safe to
  2124. // even when the source is a network path.
  2125. std::string source = this->FindRelativePathTopSource();
  2126. this->RelativePathTopSource = source;
  2127. // The current working directory on Windows cannot be a network
  2128. // path. Therefore relative paths cannot work when the binary tree
  2129. // is a network path.
  2130. std::string binary = this->FindRelativePathTopBinary();
  2131. if(binary.size() < 2 || binary.substr(0, 2) != "//")
  2132. {
  2133. this->RelativePathTopBinary = binary;
  2134. }
  2135. else
  2136. {
  2137. this->RelativePathTopBinary = "";
  2138. }
  2139. }
  2140. //----------------------------------------------------------------------------
  2141. static bool cmLocalGeneratorNotAbove(const char* a, const char* b)
  2142. {
  2143. return (cmSystemTools::ComparePath(a, b) ||
  2144. cmSystemTools::IsSubDirectory(a, b));
  2145. }
  2146. //----------------------------------------------------------------------------
  2147. std::string
  2148. cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
  2149. const char* in_remote, bool force)
  2150. {
  2151. // The path should never be quoted.
  2152. assert(in_remote[0] != '\"');
  2153. // The local path should never have a trailing slash.
  2154. assert(local.size() > 0 && !(local[local.size()-1] == ""));
  2155. // If the path is already relative then just return the path.
  2156. if(!cmSystemTools::FileIsFullPath(in_remote))
  2157. {
  2158. return in_remote;
  2159. }
  2160. // Make sure relative path conversion is configured.
  2161. if(!this->RelativePathsConfigured)
  2162. {
  2163. this->ConfigureRelativePaths();
  2164. this->RelativePathsConfigured = true;
  2165. }
  2166. if(!force)
  2167. {
  2168. // Skip conversion if the path and local are not both in the source
  2169. // or both in the binary tree.
  2170. std::string local_path = cmSystemTools::JoinPath(local);
  2171. if(!((cmLocalGeneratorNotAbove(local_path.c_str(),
  2172. this->RelativePathTopBinary.c_str()) &&
  2173. cmLocalGeneratorNotAbove(in_remote,
  2174. this->RelativePathTopBinary.c_str())) ||
  2175. (cmLocalGeneratorNotAbove(local_path.c_str(),
  2176. this->RelativePathTopSource.c_str()) &&
  2177. cmLocalGeneratorNotAbove(in_remote,
  2178. this->RelativePathTopSource.c_str()))))
  2179. {
  2180. return in_remote;
  2181. }
  2182. }
  2183. // Identify the longest shared path component between the remote
  2184. // path and the local path.
  2185. std::vector<std::string> remote;
  2186. cmSystemTools::SplitPath(in_remote, remote);
  2187. unsigned int common=0;
  2188. while(common < remote.size() &&
  2189. common < local.size() &&
  2190. cmSystemTools::ComparePath(remote[common].c_str(),
  2191. local[common].c_str()))
  2192. {
  2193. ++common;
  2194. }
  2195. // If no part of the path is in common then return the full path.
  2196. if(common == 0)
  2197. {
  2198. return in_remote;
  2199. }
  2200. // If the entire path is in common then just return a ".".
  2201. if(common == remote.size() &&
  2202. common == local.size())
  2203. {
  2204. return ".";
  2205. }
  2206. // If the entire path is in common except for a trailing slash then
  2207. // just return a "./".
  2208. if(common+1 == remote.size() &&
  2209. remote[common].size() == 0 &&
  2210. common == local.size())
  2211. {
  2212. return "./";
  2213. }
  2214. // Construct the relative path.
  2215. std::string relative;
  2216. // First add enough ../ to get up to the level of the shared portion
  2217. // of the path. Leave off the trailing slash. Note that the last
  2218. // component of local will never be empty because local should never
  2219. // have a trailing slash.
  2220. for(unsigned int i=common; i < local.size(); ++i)
  2221. {
  2222. relative += "..";
  2223. if(i < local.size()-1)
  2224. {
  2225. relative += "/";
  2226. }
  2227. }
  2228. // Now add the portion of the destination path that is not included
  2229. // in the shared portion of the path. Add a slash the first time
  2230. // only if there was already something in the path. If there was a
  2231. // trailing slash in the input then the last iteration of the loop
  2232. // will add a slash followed by an empty string which will preserve
  2233. // the trailing slash in the output.
  2234. for(unsigned int i=common; i < remote.size(); ++i)
  2235. {
  2236. if(relative.size() > 0)
  2237. {
  2238. relative += "/";
  2239. }
  2240. relative += remote[i];
  2241. }
  2242. // Finally return the path.
  2243. return relative;
  2244. }
  2245. //----------------------------------------------------------------------------
  2246. void
  2247. cmLocalGenerator
  2248. ::GenerateTargetInstallRules(
  2249. std::ostream& os, const char* config,
  2250. std::vector<std::string> const& configurationTypes)
  2251. {
  2252. // Convert the old-style install specification from each target to
  2253. // an install generator and run it.
  2254. cmTargets& tgts = this->Makefile->GetTargets();
  2255. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  2256. {
  2257. // Include the user-specified pre-install script for this target.
  2258. if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
  2259. {
  2260. cmInstallScriptGenerator g(preinstall, false, 0);
  2261. g.Generate(os, config, configurationTypes);
  2262. }
  2263. // Install this target if a destination is given.
  2264. if(l->second.GetInstallPath() != "")
  2265. {
  2266. // Compute the full install destination. Note that converting
  2267. // to unix slashes also removes any trailing slash.
  2268. // We also skip over the leading slash given by the user.
  2269. std::string destination = l->second.GetInstallPath().substr(1);
  2270. cmSystemTools::ConvertToUnixSlashes(destination);
  2271. if(destination.empty())
  2272. {
  2273. destination = ".";
  2274. }
  2275. // Generate the proper install generator for this target type.
  2276. switch(l->second.GetType())
  2277. {
  2278. case cmTarget::EXECUTABLE:
  2279. case cmTarget::STATIC_LIBRARY:
  2280. case cmTarget::MODULE_LIBRARY:
  2281. {
  2282. // Use a target install generator.
  2283. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  2284. g.Generate(os, config, configurationTypes);
  2285. }
  2286. break;
  2287. case cmTarget::SHARED_LIBRARY:
  2288. {
  2289. #if defined(_WIN32) || defined(__CYGWIN__)
  2290. // Special code to handle DLL. Install the import library
  2291. // to the normal destination and the DLL to the runtime
  2292. // destination.
  2293. cmInstallTargetGenerator g1(l->second, destination.c_str(), true);
  2294. g1.Generate(os, config, configurationTypes);
  2295. // We also skip over the leading slash given by the user.
  2296. destination = l->second.GetRuntimeInstallPath().substr(1);
  2297. cmSystemTools::ConvertToUnixSlashes(destination);
  2298. cmInstallTargetGenerator g2(l->second, destination.c_str(), false);
  2299. g2.Generate(os, config, configurationTypes);
  2300. #else
  2301. // Use a target install generator.
  2302. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  2303. g.Generate(os, config, configurationTypes);
  2304. #endif
  2305. }
  2306. break;
  2307. default:
  2308. break;
  2309. }
  2310. }
  2311. // Include the user-specified post-install script for this target.
  2312. if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
  2313. {
  2314. cmInstallScriptGenerator g(postinstall, false, 0);
  2315. g.Generate(os, config, configurationTypes);
  2316. }
  2317. }
  2318. }
  2319. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2320. static std::string cmLocalGeneratorMD5(const char* input)
  2321. {
  2322. char md5out[32];
  2323. cmsysMD5* md5 = cmsysMD5_New();
  2324. cmsysMD5_Initialize(md5);
  2325. cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
  2326. cmsysMD5_FinalizeHex(md5, md5out);
  2327. cmsysMD5_Delete(md5);
  2328. return std::string(md5out, 32);
  2329. }
  2330. static bool
  2331. cmLocalGeneratorShortenObjectName(std::string& objName,
  2332. std::string::size_type max_len)
  2333. {
  2334. // Replace the beginning of the path portion of the object name with
  2335. // its own md5 sum.
  2336. std::string::size_type pos = objName.find('/', objName.size()-max_len+32);
  2337. if(pos != objName.npos)
  2338. {
  2339. std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
  2340. md5name += objName.substr(pos);
  2341. objName = md5name;
  2342. // The object name is now short enough.
  2343. return true;
  2344. }
  2345. else
  2346. {
  2347. // The object name could not be shortened enough.
  2348. return false;
  2349. }
  2350. }
  2351. static
  2352. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  2353. std::string::size_type dir_len,
  2354. std::string::size_type max_total_len)
  2355. {
  2356. // Enforce the maximum file name length if possible.
  2357. std::string::size_type max_obj_len = max_total_len;
  2358. if(dir_len < max_total_len)
  2359. {
  2360. max_obj_len = max_total_len - dir_len;
  2361. if(objName.size() > max_obj_len)
  2362. {
  2363. // The current object file name is too long. Try to shorten it.
  2364. return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
  2365. }
  2366. else
  2367. {
  2368. // The object file name is short enough.
  2369. return true;
  2370. }
  2371. }
  2372. else
  2373. {
  2374. // The build directory in which the object will be stored is
  2375. // already too deep.
  2376. return false;
  2377. }
  2378. }
  2379. #endif
  2380. //----------------------------------------------------------------------------
  2381. std::string&
  2382. cmLocalGenerator
  2383. ::CreateSafeUniqueObjectFileName(const char* sin,
  2384. std::string const& dir_max)
  2385. {
  2386. // Look for an existing mapped name for this object file.
  2387. std::map<cmStdString,cmStdString>::iterator it =
  2388. this->UniqueObjectNamesMap.find(sin);
  2389. // If no entry exists create one.
  2390. if(it == this->UniqueObjectNamesMap.end())
  2391. {
  2392. // Start with the original name.
  2393. std::string ssin = sin;
  2394. // Avoid full paths by removing leading slashes.
  2395. std::string::size_type pos = 0;
  2396. for(;pos < ssin.size() && ssin[pos] == '/'; ++pos)
  2397. {
  2398. }
  2399. ssin = ssin.substr(pos);
  2400. // Avoid full paths by removing colons.
  2401. cmSystemTools::ReplaceString(ssin, ":", "_");
  2402. // Avoid relative paths that go up the tree.
  2403. cmSystemTools::ReplaceString(ssin, "../", "__/");
  2404. // Avoid spaces.
  2405. cmSystemTools::ReplaceString(ssin, " ", "_");
  2406. // Mangle the name if necessary.
  2407. if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
  2408. {
  2409. bool done;
  2410. int cc = 0;
  2411. char rpstr[100];
  2412. sprintf(rpstr, "_p_");
  2413. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2414. std::string sssin = sin;
  2415. do
  2416. {
  2417. done = true;
  2418. for ( it = this->UniqueObjectNamesMap.begin();
  2419. it != this->UniqueObjectNamesMap.end();
  2420. ++ it )
  2421. {
  2422. if ( it->second == ssin )
  2423. {
  2424. done = false;
  2425. }
  2426. }
  2427. if ( done )
  2428. {
  2429. break;
  2430. }
  2431. sssin = ssin;
  2432. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2433. sprintf(rpstr, "_p%d_", cc++);
  2434. }
  2435. while ( !done );
  2436. }
  2437. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2438. if(!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
  2439. this->ObjectPathMax))
  2440. {
  2441. // Warn if this is the first time the path has been seen.
  2442. if(this->ObjectMaxPathViolations.insert(dir_max).second)
  2443. {
  2444. cmOStringStream m;
  2445. m << "The object file directory\n"
  2446. << " " << dir_max << "\n"
  2447. << "has " << dir_max.size() << " characters. "
  2448. << "The maximum full path to an object file is "
  2449. << this->ObjectPathMax << " characters "
  2450. << "(see CMAKE_OBJECT_PATH_MAX). "
  2451. << "Object file\n"
  2452. << " " << ssin << "\n"
  2453. << "cannot be safely placed under this directory. "
  2454. << "The build may not work correctly.";
  2455. this->Makefile->IssueMessage(cmake::WARNING, m.str());
  2456. }
  2457. }
  2458. #else
  2459. (void)dir_max;
  2460. #endif
  2461. // Insert the newly mapped object file name.
  2462. std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
  2463. it = this->UniqueObjectNamesMap.insert(e).first;
  2464. }
  2465. // Return the map entry.
  2466. return it->second;
  2467. }
  2468. //----------------------------------------------------------------------------
  2469. std::string
  2470. cmLocalGenerator
  2471. ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
  2472. std::string const& dir_max,
  2473. bool* hasSourceExtension)
  2474. {
  2475. // Construct the object file name using the full path to the source
  2476. // file which is its only unique identification.
  2477. const char* fullPath = source.GetFullPath().c_str();
  2478. // Try referencing the source relative to the source tree.
  2479. std::string relFromSource = this->Convert(fullPath, START);
  2480. assert(!relFromSource.empty());
  2481. bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
  2482. bool subSource = relSource && relFromSource[0] != '.';
  2483. // Try referencing the source relative to the binary tree.
  2484. std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
  2485. assert(!relFromBinary.empty());
  2486. bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
  2487. bool subBinary = relBinary && relFromBinary[0] != '.';
  2488. // Select a nice-looking reference to the source file to construct
  2489. // the object file name.
  2490. std::string objectName;
  2491. if((relSource && !relBinary) || (subSource && !subBinary))
  2492. {
  2493. objectName = relFromSource;
  2494. }
  2495. else if((relBinary && !relSource) || (subBinary && !subSource))
  2496. {
  2497. objectName = relFromBinary;
  2498. }
  2499. else if(relFromBinary.length() < relFromSource.length())
  2500. {
  2501. objectName = relFromBinary;
  2502. }
  2503. else
  2504. {
  2505. objectName = relFromSource;
  2506. }
  2507. // if it is still a full path check for the try compile case
  2508. // try compile never have in source sources, and should not
  2509. // have conflicting source file names in the same target
  2510. if(cmSystemTools::FileIsFullPath(objectName.c_str()))
  2511. {
  2512. if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
  2513. {
  2514. objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
  2515. }
  2516. }
  2517. // Replace the original source file extension with the object file
  2518. // extension.
  2519. bool keptSourceExtension = true;
  2520. if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
  2521. {
  2522. // Decide whether this language wants to replace the source
  2523. // extension with the object extension. For CMake 2.4
  2524. // compatibility do this by default.
  2525. bool replaceExt = this->NeedBackwardsCompatibility(2, 4);
  2526. if(!replaceExt)
  2527. {
  2528. std::string repVar = "CMAKE_";
  2529. repVar += source.GetLanguage();
  2530. repVar += "_OUTPUT_EXTENSION_REPLACE";
  2531. replaceExt = this->Makefile->IsOn(repVar.c_str());
  2532. }
  2533. // Remove the source extension if it is to be replaced.
  2534. if(replaceExt)
  2535. {
  2536. keptSourceExtension = false;
  2537. std::string::size_type dot_pos = objectName.rfind(".");
  2538. if(dot_pos != std::string::npos)
  2539. {
  2540. objectName = objectName.substr(0, dot_pos);
  2541. }
  2542. }
  2543. // Store the new extension.
  2544. objectName +=
  2545. this->GlobalGenerator->GetLanguageOutputExtension(source);
  2546. }
  2547. if(hasSourceExtension)
  2548. {
  2549. *hasSourceExtension = keptSourceExtension;
  2550. }
  2551. // Convert to a safe name.
  2552. return this->CreateSafeUniqueObjectFileName(objectName.c_str(), dir_max);
  2553. }
  2554. //----------------------------------------------------------------------------
  2555. const char*
  2556. cmLocalGenerator
  2557. ::GetSourceFileLanguage(const cmSourceFile& source)
  2558. {
  2559. return source.GetLanguage();
  2560. }
  2561. //----------------------------------------------------------------------------
  2562. std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
  2563. {
  2564. std::string result;
  2565. bool forceOn = cmSystemTools::GetForceUnixPaths();
  2566. if(forceOn && this->WindowsShell)
  2567. {
  2568. cmSystemTools::SetForceUnixPaths(false);
  2569. }
  2570. result = cmSystemTools::EscapeSpaces(str);
  2571. if(forceOn && this->WindowsShell)
  2572. {
  2573. cmSystemTools::SetForceUnixPaths(true);
  2574. }
  2575. return result;
  2576. }
  2577. //----------------------------------------------------------------------------
  2578. static bool cmLocalGeneratorIsShellOperator(const char* str)
  2579. {
  2580. if(strcmp(str, "<") == 0 ||
  2581. strcmp(str, ">") == 0 ||
  2582. strcmp(str, "<<") == 0 ||
  2583. strcmp(str, ">>") == 0 ||
  2584. strcmp(str, "|") == 0 ||
  2585. strcmp(str, "||") == 0 ||
  2586. strcmp(str, "&&") == 0 ||
  2587. strcmp(str, "&>") == 0 ||
  2588. strcmp(str, "1>") == 0 ||
  2589. strcmp(str, "2>") == 0 ||
  2590. strcmp(str, "2>&1") == 0 ||
  2591. strcmp(str, "1>&2") == 0)
  2592. {
  2593. return true;
  2594. }
  2595. return false;
  2596. }
  2597. //----------------------------------------------------------------------------
  2598. std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
  2599. bool forEcho)
  2600. {
  2601. // Do not escape shell operators.
  2602. if(cmLocalGeneratorIsShellOperator(str))
  2603. {
  2604. return str;
  2605. }
  2606. // Compute the flags for the target shell environment.
  2607. int flags = 0;
  2608. if(this->WindowsVSIDE)
  2609. {
  2610. flags |= cmsysSystem_Shell_Flag_VSIDE;
  2611. }
  2612. else if(!this->LinkScriptShell)
  2613. {
  2614. flags |= cmsysSystem_Shell_Flag_Make;
  2615. }
  2616. if(makeVars)
  2617. {
  2618. flags |= cmsysSystem_Shell_Flag_AllowMakeVariables;
  2619. }
  2620. if(forEcho)
  2621. {
  2622. flags |= cmsysSystem_Shell_Flag_EchoWindows;
  2623. }
  2624. if(this->WatcomWMake)
  2625. {
  2626. flags |= cmsysSystem_Shell_Flag_WatcomWMake;
  2627. }
  2628. if(this->MinGWMake)
  2629. {
  2630. flags |= cmsysSystem_Shell_Flag_MinGWMake;
  2631. }
  2632. if(this->NMake)
  2633. {
  2634. flags |= cmsysSystem_Shell_Flag_NMake;
  2635. }
  2636. // Compute the buffer size needed.
  2637. int size = (this->WindowsShell ?
  2638. cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) :
  2639. cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags));
  2640. // Compute the shell argument itself.
  2641. std::vector<char> arg(size);
  2642. if(this->WindowsShell)
  2643. {
  2644. cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags);
  2645. }
  2646. else
  2647. {
  2648. cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags);
  2649. }
  2650. return std::string(&arg[0]);
  2651. }
  2652. //----------------------------------------------------------------------------
  2653. std::string cmLocalGenerator::EscapeForCMake(const char* str)
  2654. {
  2655. // Always double-quote the argument to take care of most escapes.
  2656. std::string result = "\"";
  2657. for(const char* c = str; *c; ++c)
  2658. {
  2659. if(*c == '"')
  2660. {
  2661. // Escape the double quote to avoid ending the argument.
  2662. result += "\\\"";
  2663. }
  2664. else if(*c == '$')
  2665. {
  2666. // Escape the dollar to avoid expanding variables.
  2667. result += "\\$";
  2668. }
  2669. else if(*c == '\\')
  2670. {
  2671. // Escape the backslash to avoid other escapes.
  2672. result += "\\\\";
  2673. }
  2674. else
  2675. {
  2676. // Other characters will be parsed correctly.
  2677. result += *c;
  2678. }
  2679. }
  2680. result += "\"";
  2681. return result;
  2682. }
  2683. //----------------------------------------------------------------------------
  2684. std::string
  2685. cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
  2686. {
  2687. cmSystemTools::Error("GetTargetDirectory"
  2688. " called on cmLocalGenerator");
  2689. return "";
  2690. }
  2691. //----------------------------------------------------------------------------
  2692. void
  2693. cmLocalGenerator::GetTargetObjectFileDirectories(cmTarget* ,
  2694. std::vector<std::string>&
  2695. )
  2696. {
  2697. cmSystemTools::Error("GetTargetObjectFileDirectories"
  2698. " called on cmLocalGenerator");
  2699. }
  2700. //----------------------------------------------------------------------------
  2701. unsigned int cmLocalGenerator::GetBackwardsCompatibility()
  2702. {
  2703. // The computed version may change until the project is fully
  2704. // configured.
  2705. if(!this->BackwardsCompatibilityFinal)
  2706. {
  2707. unsigned int major = 0;
  2708. unsigned int minor = 0;
  2709. unsigned int patch = 0;
  2710. if(const char* value
  2711. = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
  2712. {
  2713. switch(sscanf(value, "%u.%u.%u", &major, &minor, &patch))
  2714. {
  2715. case 2: patch = 0; break;
  2716. case 1: minor = 0; patch = 0; break;
  2717. default: break;
  2718. }
  2719. }
  2720. this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
  2721. this->BackwardsCompatibilityFinal = this->Configured;
  2722. }
  2723. return this->BackwardsCompatibility;
  2724. }
  2725. //----------------------------------------------------------------------------
  2726. bool cmLocalGenerator::NeedBackwardsCompatibility(unsigned int major,
  2727. unsigned int minor,
  2728. unsigned int patch)
  2729. {
  2730. // Check the policy to decide whether to pay attention to this
  2731. // variable.
  2732. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0001))
  2733. {
  2734. case cmPolicies::WARN:
  2735. // WARN is just OLD without warning because user code does not
  2736. // always affect whether this check is done.
  2737. case cmPolicies::OLD:
  2738. // Old behavior is to check the variable.
  2739. break;
  2740. case cmPolicies::NEW:
  2741. // New behavior is to ignore the variable.
  2742. return false;
  2743. case cmPolicies::REQUIRED_IF_USED:
  2744. case cmPolicies::REQUIRED_ALWAYS:
  2745. // This will never be the case because the only way to require
  2746. // the setting is to require the user to specify version policy
  2747. // 2.6 or higher. Once we add that requirement then this whole
  2748. // method can be removed anyway.
  2749. return false;
  2750. }
  2751. // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
  2752. // equal to or lower than the given version.
  2753. unsigned int actual_compat = this->GetBackwardsCompatibility();
  2754. return (actual_compat &&
  2755. actual_compat <= CMake_VERSION_ENCODE(major, minor, patch));
  2756. }
  2757. //----------------------------------------------------------------------------
  2758. bool cmLocalGenerator::CheckDefinition(std::string const& define) const
  2759. {
  2760. // Many compilers do not support -DNAME(arg)=sdf so we disable it.
  2761. bool function_style = false;
  2762. for(const char* c = define.c_str(); *c && *c != '='; ++c)
  2763. {
  2764. if(*c == '(')
  2765. {
  2766. function_style = true;
  2767. break;
  2768. }
  2769. }
  2770. if(function_style)
  2771. {
  2772. cmOStringStream e;
  2773. e << "WARNING: Function-style preprocessor definitions may not be "
  2774. << "passed on the compiler command line because many compilers "
  2775. << "do not support it.\n"
  2776. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2777. << "Consider defining the macro in a (configured) header file.\n";
  2778. cmSystemTools::Message(e.str().c_str());
  2779. return false;
  2780. }
  2781. // Many compilers do not support # in the value so we disable it.
  2782. if(define.find_first_of("#") != define.npos)
  2783. {
  2784. cmOStringStream e;
  2785. e << "WARNING: Peprocessor definitions containing '#' may not be "
  2786. << "passed on the compiler command line because many compilers "
  2787. << "do not support it.\n"
  2788. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2789. << "Consider defining the macro in a (configured) header file.\n";
  2790. cmSystemTools::Message(e.str().c_str());
  2791. return false;
  2792. }
  2793. // Assume it is supported.
  2794. return true;
  2795. }
  2796. //----------------------------------------------------------------------------
  2797. static void cmLGInfoProp(cmMakefile* mf, cmTarget* target, const char* prop)
  2798. {
  2799. if(const char* val = target->GetProperty(prop))
  2800. {
  2801. mf->AddDefinition(prop, val);
  2802. }
  2803. }
  2804. //----------------------------------------------------------------------------
  2805. void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
  2806. const char* targetName,
  2807. const char* fname)
  2808. {
  2809. // Find the Info.plist template.
  2810. const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
  2811. std::string inFile = (in && *in)? in : "MacOSXBundleInfo.plist.in";
  2812. if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
  2813. {
  2814. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2815. if(!inMod.empty())
  2816. {
  2817. inFile = inMod;
  2818. }
  2819. }
  2820. if(!cmSystemTools::FileExists(inFile.c_str(), true))
  2821. {
  2822. cmOStringStream e;
  2823. e << "Target " << target->GetName() << " Info.plist template \""
  2824. << inFile << "\" could not be found.";
  2825. cmSystemTools::Error(e.str().c_str());
  2826. return;
  2827. }
  2828. // Convert target properties to variables in an isolated makefile
  2829. // scope to configure the file. If properties are set they will
  2830. // override user make variables. If not the configuration will fall
  2831. // back to the directory-level values set by the user.
  2832. cmMakefile* mf = this->Makefile;
  2833. mf->PushScope();
  2834. mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName);
  2835. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
  2836. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
  2837. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
  2838. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
  2839. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
  2840. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
  2841. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
  2842. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
  2843. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2844. mf->PopScope();
  2845. }
  2846. //----------------------------------------------------------------------------
  2847. void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target,
  2848. const char* targetName,
  2849. const char* fname)
  2850. {
  2851. // Find the Info.plist template.
  2852. const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
  2853. std::string inFile = (in && *in)? in : "MacOSXFrameworkInfo.plist.in";
  2854. if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
  2855. {
  2856. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2857. if(!inMod.empty())
  2858. {
  2859. inFile = inMod;
  2860. }
  2861. }
  2862. if(!cmSystemTools::FileExists(inFile.c_str(), true))
  2863. {
  2864. cmOStringStream e;
  2865. e << "Target " << target->GetName() << " Info.plist template \""
  2866. << inFile << "\" could not be found.";
  2867. cmSystemTools::Error(e.str().c_str());
  2868. return;
  2869. }
  2870. // Convert target properties to variables in an isolated makefile
  2871. // scope to configure the file. If properties are set they will
  2872. // override user make variables. If not the configuration will fall
  2873. // back to the directory-level values set by the user.
  2874. cmMakefile* mf = this->Makefile;
  2875. mf->PushScope();
  2876. mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName);
  2877. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
  2878. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
  2879. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
  2880. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
  2881. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2882. mf->PopScope();
  2883. }