cmLocalGenerator.cxx 97 KB

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