cmLocalGenerator.cxx 96 KB

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