cmLocalGenerator.cxx 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769
  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 "cmAlgorithms.h"
  12. #include "cmComputeLinkInformation.h"
  13. #include "cmCustomCommandGenerator.h"
  14. #include "cmGeneratedFileStream.h"
  15. #include "cmGeneratorExpressionEvaluationFile.h"
  16. #include "cmGlobalGenerator.h"
  17. #include "cmInstallFilesGenerator.h"
  18. #include "cmInstallGenerator.h"
  19. #include "cmInstallScriptGenerator.h"
  20. #include "cmInstallTargetGenerator.h"
  21. #include "cmMakefile.h"
  22. #include "cmSourceFile.h"
  23. #include "cmTest.h"
  24. #include "cmTestGenerator.h"
  25. #include "cmVersion.h"
  26. #include "cmake.h"
  27. #if defined(CMAKE_BUILD_WITH_CMAKE)
  28. #define CM_LG_ENCODE_OBJECT_NAMES
  29. #include <cmsys/MD5.h>
  30. #endif
  31. #include <ctype.h> // for isalpha
  32. #include <assert.h>
  33. #if defined(__HAIKU__)
  34. #include <FindDirectory.h>
  35. #include <StorageDefs.h>
  36. #endif
  37. cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
  38. : cmOutputConverter(makefile->GetStateSnapshot())
  39. , StateSnapshot(makefile->GetStateSnapshot())
  40. , DirectoryBacktrace(makefile->GetBacktrace())
  41. {
  42. this->GlobalGenerator = gg;
  43. this->Makefile = makefile;
  44. this->AliasTargets = makefile->GetAliasTargets();
  45. this->EmitUniversalBinaryFlags = true;
  46. this->BackwardsCompatibility = 0;
  47. this->BackwardsCompatibilityFinal = false;
  48. this->ComputeObjectMaxPath();
  49. }
  50. cmLocalGenerator::~cmLocalGenerator()
  51. {
  52. cmDeleteAll(this->GeneratorTargets);
  53. cmDeleteAll(this->OwnedImportedGeneratorTargets);
  54. }
  55. void cmLocalGenerator::IssueMessage(cmake::MessageType t,
  56. std::string const& text) const
  57. {
  58. this->GetCMakeInstance()->IssueMessage(t, text, this->DirectoryBacktrace);
  59. }
  60. void cmLocalGenerator::ComputeObjectMaxPath()
  61. {
  62. // Choose a maximum object file name length.
  63. #if defined(_WIN32) || defined(__CYGWIN__)
  64. this->ObjectPathMax = 250;
  65. #else
  66. this->ObjectPathMax = 1000;
  67. #endif
  68. const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
  69. if (plen && *plen) {
  70. unsigned int pmax;
  71. if (sscanf(plen, "%u", &pmax) == 1) {
  72. if (pmax >= 128) {
  73. this->ObjectPathMax = pmax;
  74. } else {
  75. std::ostringstream w;
  76. w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
  77. << ", which is less than the minimum of 128. "
  78. << "The value will be ignored.";
  79. this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  80. }
  81. } else {
  82. std::ostringstream w;
  83. w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
  84. << "\", which fails to parse as a positive integer. "
  85. << "The value will be ignored.";
  86. this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  87. }
  88. }
  89. this->ObjectMaxPathViolations.clear();
  90. }
  91. void cmLocalGenerator::TraceDependencies()
  92. {
  93. std::vector<std::string> configs;
  94. this->Makefile->GetConfigurations(configs);
  95. if (configs.empty()) {
  96. configs.push_back("");
  97. }
  98. for (std::vector<std::string>::const_iterator ci = configs.begin();
  99. ci != configs.end(); ++ci) {
  100. this->GlobalGenerator->CreateEvaluationSourceFiles(*ci);
  101. }
  102. // Generate the rule files for each target.
  103. std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
  104. for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
  105. t != targets.end(); ++t) {
  106. if ((*t)->GetType() == cmState::INTERFACE_LIBRARY) {
  107. continue;
  108. }
  109. (*t)->TraceDependencies();
  110. }
  111. }
  112. void cmLocalGenerator::GenerateTestFiles()
  113. {
  114. if (!this->Makefile->IsOn("CMAKE_TESTING_ENABLED")) {
  115. return;
  116. }
  117. // Compute the set of configurations.
  118. std::vector<std::string> configurationTypes;
  119. const std::string& config =
  120. this->Makefile->GetConfigurations(configurationTypes, false);
  121. std::string file = this->StateSnapshot.GetDirectory().GetCurrentBinary();
  122. file += "/";
  123. file += "CTestTestfile.cmake";
  124. cmGeneratedFileStream fout(file.c_str());
  125. fout.SetCopyIfDifferent(true);
  126. fout << "# CMake generated Testfile for " << std::endl
  127. << "# Source directory: "
  128. << this->StateSnapshot.GetDirectory().GetCurrentSource() << std::endl
  129. << "# Build directory: "
  130. << this->StateSnapshot.GetDirectory().GetCurrentBinary() << std::endl
  131. << "# " << std::endl
  132. << "# This file includes the relevant testing commands "
  133. << "required for " << std::endl
  134. << "# testing this directory and lists subdirectories to "
  135. << "be tested as well." << std::endl;
  136. const char* testIncludeFile =
  137. this->Makefile->GetProperty("TEST_INCLUDE_FILE");
  138. if (testIncludeFile) {
  139. fout << "include(\"" << testIncludeFile << "\")" << std::endl;
  140. }
  141. // Ask each test generator to write its code.
  142. std::vector<cmTestGenerator*> const& testers =
  143. this->Makefile->GetTestGenerators();
  144. for (std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
  145. gi != testers.end(); ++gi) {
  146. (*gi)->Compute(this);
  147. (*gi)->Generate(fout, config, configurationTypes);
  148. }
  149. size_t i;
  150. std::vector<cmState::Snapshot> children =
  151. this->Makefile->GetStateSnapshot().GetChildren();
  152. for (i = 0; i < children.size(); ++i) {
  153. // TODO: Use add_subdirectory instead?
  154. fout << "subdirs(";
  155. std::string outP = children[i].GetDirectory().GetCurrentBinary();
  156. fout << this->Convert(outP, START_OUTPUT);
  157. fout << ")" << std::endl;
  158. }
  159. }
  160. void cmLocalGenerator::CreateEvaluationFileOutputs(std::string const& config)
  161. {
  162. std::vector<cmGeneratorExpressionEvaluationFile*> ef =
  163. this->Makefile->GetEvaluationFiles();
  164. for (std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator li =
  165. ef.begin();
  166. li != ef.end(); ++li) {
  167. (*li)->CreateOutputFile(this, config);
  168. }
  169. }
  170. void cmLocalGenerator::ProcessEvaluationFiles(
  171. std::vector<std::string>& generatedFiles)
  172. {
  173. std::vector<cmGeneratorExpressionEvaluationFile*> ef =
  174. this->Makefile->GetEvaluationFiles();
  175. for (std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator li =
  176. ef.begin();
  177. li != ef.end(); ++li) {
  178. (*li)->Generate(this);
  179. if (cmSystemTools::GetFatalErrorOccured()) {
  180. return;
  181. }
  182. std::vector<std::string> files = (*li)->GetFiles();
  183. std::sort(files.begin(), files.end());
  184. std::vector<std::string> intersection;
  185. std::set_intersection(files.begin(), files.end(), generatedFiles.begin(),
  186. generatedFiles.end(),
  187. std::back_inserter(intersection));
  188. if (!intersection.empty()) {
  189. cmSystemTools::Error("Files to be generated by multiple different "
  190. "commands: ",
  191. cmWrap('"', intersection, '"', " ").c_str());
  192. return;
  193. }
  194. generatedFiles.insert(generatedFiles.end(), files.begin(), files.end());
  195. std::vector<std::string>::iterator newIt =
  196. generatedFiles.end() - files.size();
  197. std::inplace_merge(generatedFiles.begin(), newIt, generatedFiles.end());
  198. }
  199. }
  200. void cmLocalGenerator::GenerateInstallRules()
  201. {
  202. // Compute the install prefix.
  203. const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
  204. #if defined(_WIN32) && !defined(__CYGWIN__)
  205. std::string prefix_win32;
  206. if (!prefix) {
  207. if (!cmSystemTools::GetEnv("SystemDrive", prefix_win32)) {
  208. prefix_win32 = "C:";
  209. }
  210. const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
  211. if (project_name && project_name[0]) {
  212. prefix_win32 += "/Program Files/";
  213. prefix_win32 += project_name;
  214. } else {
  215. prefix_win32 += "/InstalledCMakeProject";
  216. }
  217. prefix = prefix_win32.c_str();
  218. }
  219. #elif defined(__HAIKU__)
  220. char dir[B_PATH_NAME_LENGTH];
  221. if (!prefix) {
  222. if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir)) ==
  223. B_OK) {
  224. prefix = dir;
  225. } else {
  226. prefix = "/boot/system";
  227. }
  228. }
  229. #else
  230. if (!prefix) {
  231. prefix = "/usr/local";
  232. }
  233. #endif
  234. if (const char* stagingPrefix =
  235. this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX")) {
  236. prefix = stagingPrefix;
  237. }
  238. // Compute the set of configurations.
  239. std::vector<std::string> configurationTypes;
  240. const std::string& config =
  241. this->Makefile->GetConfigurations(configurationTypes, false);
  242. // Choose a default install configuration.
  243. std::string default_config = config;
  244. const char* default_order[] = { "RELEASE", "MINSIZEREL", "RELWITHDEBINFO",
  245. "DEBUG", 0 };
  246. for (const char** c = default_order; *c && default_config.empty(); ++c) {
  247. for (std::vector<std::string>::iterator i = configurationTypes.begin();
  248. i != configurationTypes.end(); ++i) {
  249. if (cmSystemTools::UpperCase(*i) == *c) {
  250. default_config = *i;
  251. }
  252. }
  253. }
  254. if (default_config.empty() && !configurationTypes.empty()) {
  255. default_config = configurationTypes[0];
  256. }
  257. // Create the install script file.
  258. std::string file = this->StateSnapshot.GetDirectory().GetCurrentBinary();
  259. std::string homedir = this->GetState()->GetBinaryDirectory();
  260. int toplevel_install = 0;
  261. if (file == homedir) {
  262. toplevel_install = 1;
  263. }
  264. file += "/cmake_install.cmake";
  265. cmGeneratedFileStream fout(file.c_str());
  266. fout.SetCopyIfDifferent(true);
  267. // Write the header.
  268. fout << "# Install script for directory: "
  269. << this->StateSnapshot.GetDirectory().GetCurrentSource() << std::endl
  270. << std::endl;
  271. fout << "# Set the install prefix" << std::endl
  272. << "if(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  273. << " set(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
  274. << "endif()" << std::endl
  275. << "string(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
  276. << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
  277. << std::endl;
  278. // Write support code for generating per-configuration install rules.
  279. /* clang-format off */
  280. fout <<
  281. "# Set the install configuration name.\n"
  282. "if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  283. " if(BUILD_TYPE)\n"
  284. " string(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
  285. " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
  286. " else()\n"
  287. " set(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
  288. " endif()\n"
  289. " message(STATUS \"Install configuration: "
  290. "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
  291. "endif()\n"
  292. "\n";
  293. /* clang-format on */
  294. // Write support code for dealing with component-specific installs.
  295. /* clang-format off */
  296. fout <<
  297. "# Set the component getting installed.\n"
  298. "if(NOT CMAKE_INSTALL_COMPONENT)\n"
  299. " if(COMPONENT)\n"
  300. " message(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
  301. " set(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
  302. " else()\n"
  303. " set(CMAKE_INSTALL_COMPONENT)\n"
  304. " endif()\n"
  305. "endif()\n"
  306. "\n";
  307. /* clang-format on */
  308. // Copy user-specified install options to the install code.
  309. if (const char* so_no_exe =
  310. this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE")) {
  311. /* clang-format off */
  312. fout <<
  313. "# Install shared libraries without execute permission?\n"
  314. "if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  315. " set(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
  316. "endif()\n"
  317. "\n";
  318. /* clang-format on */
  319. }
  320. // Ask each install generator to write its code.
  321. std::vector<cmInstallGenerator*> const& installers =
  322. this->Makefile->GetInstallGenerators();
  323. for (std::vector<cmInstallGenerator*>::const_iterator gi =
  324. installers.begin();
  325. gi != installers.end(); ++gi) {
  326. (*gi)->Generate(fout, config, configurationTypes);
  327. }
  328. // Write rules from old-style specification stored in targets.
  329. this->GenerateTargetInstallRules(fout, config, configurationTypes);
  330. // Include install scripts from subdirectories.
  331. std::vector<cmState::Snapshot> children =
  332. this->Makefile->GetStateSnapshot().GetChildren();
  333. if (!children.empty()) {
  334. fout << "if(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
  335. fout << " # Include the install script for each subdirectory.\n";
  336. for (std::vector<cmState::Snapshot>::const_iterator ci = children.begin();
  337. ci != children.end(); ++ci) {
  338. if (!ci->GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
  339. std::string odir = ci->GetDirectory().GetCurrentBinary();
  340. cmSystemTools::ConvertToUnixSlashes(odir);
  341. fout << " include(\"" << odir << "/cmake_install.cmake\")"
  342. << std::endl;
  343. }
  344. }
  345. fout << "\n";
  346. fout << "endif()\n\n";
  347. }
  348. // Record the install manifest.
  349. if (toplevel_install) {
  350. /* clang-format off */
  351. fout <<
  352. "if(CMAKE_INSTALL_COMPONENT)\n"
  353. " set(CMAKE_INSTALL_MANIFEST \"install_manifest_"
  354. "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
  355. "else()\n"
  356. " set(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
  357. "endif()\n"
  358. "\n"
  359. "string(REPLACE \";\" \"\\n\" CMAKE_INSTALL_MANIFEST_CONTENT\n"
  360. " \"${CMAKE_INSTALL_MANIFEST_FILES}\")\n"
  361. "file(WRITE \"" << homedir << "/${CMAKE_INSTALL_MANIFEST}\"\n"
  362. " \"${CMAKE_INSTALL_MANIFEST_CONTENT}\")\n";
  363. /* clang-format on */
  364. }
  365. }
  366. void cmLocalGenerator::AddGeneratorTarget(cmGeneratorTarget* gt)
  367. {
  368. this->GeneratorTargets.push_back(gt);
  369. this->GlobalGenerator->IndexGeneratorTarget(gt);
  370. }
  371. void cmLocalGenerator::AddImportedGeneratorTarget(cmGeneratorTarget* gt)
  372. {
  373. this->ImportedGeneratorTargets.push_back(gt);
  374. this->GlobalGenerator->IndexGeneratorTarget(gt);
  375. }
  376. void cmLocalGenerator::AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt)
  377. {
  378. this->OwnedImportedGeneratorTargets.push_back(gt);
  379. }
  380. struct NamedGeneratorTargetFinder
  381. {
  382. NamedGeneratorTargetFinder(std::string const& name)
  383. : Name(name)
  384. {
  385. }
  386. bool operator()(cmGeneratorTarget* tgt)
  387. {
  388. return tgt->GetName() == this->Name;
  389. }
  390. private:
  391. std::string Name;
  392. };
  393. cmGeneratorTarget* cmLocalGenerator::FindLocalNonAliasGeneratorTarget(
  394. const std::string& name) const
  395. {
  396. std::vector<cmGeneratorTarget*>::const_iterator ti =
  397. std::find_if(this->GeneratorTargets.begin(), this->GeneratorTargets.end(),
  398. NamedGeneratorTargetFinder(name));
  399. if (ti != this->GeneratorTargets.end()) {
  400. return *ti;
  401. }
  402. return 0;
  403. }
  404. void cmLocalGenerator::ComputeTargetManifest()
  405. {
  406. // Collect the set of configuration types.
  407. std::vector<std::string> configNames;
  408. this->Makefile->GetConfigurations(configNames);
  409. if (configNames.empty()) {
  410. configNames.push_back("");
  411. }
  412. // Add our targets to the manifest for each configuration.
  413. std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
  414. for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
  415. t != targets.end(); ++t) {
  416. cmGeneratorTarget* target = *t;
  417. if (target->GetType() == cmState::INTERFACE_LIBRARY) {
  418. continue;
  419. }
  420. for (std::vector<std::string>::iterator ci = configNames.begin();
  421. ci != configNames.end(); ++ci) {
  422. const char* config = ci->c_str();
  423. target->ComputeTargetManifest(config);
  424. }
  425. }
  426. }
  427. bool cmLocalGenerator::IsRootMakefile() const
  428. {
  429. return !this->StateSnapshot.GetBuildsystemDirectoryParent().IsValid();
  430. }
  431. cmState* cmLocalGenerator::GetState() const
  432. {
  433. return this->GlobalGenerator->GetCMakeInstance()->GetState();
  434. }
  435. cmState::Snapshot cmLocalGenerator::GetStateSnapshot() const
  436. {
  437. return this->Makefile->GetStateSnapshot();
  438. }
  439. // List of variables that are replaced when
  440. // rules are expanced. These variables are
  441. // replaced in the form <var> with GetSafeDefinition(var).
  442. // ${LANG} is replaced in the variable first with all enabled
  443. // languages.
  444. static const char* ruleReplaceVars[] = {
  445. "CMAKE_${LANG}_COMPILER",
  446. "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
  447. "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
  448. "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
  449. "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
  450. "CMAKE_${LANG}_LINK_FLAGS",
  451. "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
  452. "CMAKE_${LANG}_ARCHIVE",
  453. "CMAKE_AR",
  454. "CMAKE_CURRENT_SOURCE_DIR",
  455. "CMAKE_CURRENT_BINARY_DIR",
  456. "CMAKE_RANLIB",
  457. "CMAKE_LINKER",
  458. "CMAKE_CL_SHOWINCLUDES_PREFIX",
  459. 0
  460. };
  461. std::string cmLocalGenerator::ExpandRuleVariable(
  462. std::string const& variable, const RuleVariables& replaceValues)
  463. {
  464. if (replaceValues.LinkFlags) {
  465. if (variable == "LINK_FLAGS") {
  466. return replaceValues.LinkFlags;
  467. }
  468. }
  469. if (replaceValues.Manifests) {
  470. if (variable == "MANIFESTS") {
  471. return replaceValues.Manifests;
  472. }
  473. }
  474. if (replaceValues.Flags) {
  475. if (variable == "FLAGS") {
  476. return replaceValues.Flags;
  477. }
  478. }
  479. if (replaceValues.Source) {
  480. if (variable == "SOURCE") {
  481. return replaceValues.Source;
  482. }
  483. }
  484. if (replaceValues.PreprocessedSource) {
  485. if (variable == "PREPROCESSED_SOURCE") {
  486. return replaceValues.PreprocessedSource;
  487. }
  488. }
  489. if (replaceValues.AssemblySource) {
  490. if (variable == "ASSEMBLY_SOURCE") {
  491. return replaceValues.AssemblySource;
  492. }
  493. }
  494. if (replaceValues.Object) {
  495. if (variable == "OBJECT") {
  496. return replaceValues.Object;
  497. }
  498. }
  499. if (replaceValues.ObjectDir) {
  500. if (variable == "OBJECT_DIR") {
  501. return replaceValues.ObjectDir;
  502. }
  503. }
  504. if (replaceValues.ObjectFileDir) {
  505. if (variable == "OBJECT_FILE_DIR") {
  506. return replaceValues.ObjectFileDir;
  507. }
  508. }
  509. if (replaceValues.Objects) {
  510. if (variable == "OBJECTS") {
  511. return replaceValues.Objects;
  512. }
  513. }
  514. if (replaceValues.ObjectsQuoted) {
  515. if (variable == "OBJECTS_QUOTED") {
  516. return replaceValues.ObjectsQuoted;
  517. }
  518. }
  519. if (replaceValues.Defines && variable == "DEFINES") {
  520. return replaceValues.Defines;
  521. }
  522. if (replaceValues.Includes && variable == "INCLUDES") {
  523. return replaceValues.Includes;
  524. }
  525. if (replaceValues.TargetPDB) {
  526. if (variable == "TARGET_PDB") {
  527. return replaceValues.TargetPDB;
  528. }
  529. }
  530. if (replaceValues.TargetCompilePDB) {
  531. if (variable == "TARGET_COMPILE_PDB") {
  532. return replaceValues.TargetCompilePDB;
  533. }
  534. }
  535. if (replaceValues.DependencyFile) {
  536. if (variable == "DEP_FILE") {
  537. return replaceValues.DependencyFile;
  538. }
  539. }
  540. if (replaceValues.Target) {
  541. if (variable == "TARGET_QUOTED") {
  542. std::string targetQuoted = replaceValues.Target;
  543. if (!targetQuoted.empty() && targetQuoted[0] != '\"') {
  544. targetQuoted = '\"';
  545. targetQuoted += replaceValues.Target;
  546. targetQuoted += '\"';
  547. }
  548. return targetQuoted;
  549. }
  550. if (variable == "TARGET_UNQUOTED") {
  551. std::string unquoted = replaceValues.Target;
  552. std::string::size_type sz = unquoted.size();
  553. if (sz > 2 && unquoted[0] == '\"' && unquoted[sz - 1] == '\"') {
  554. unquoted = unquoted.substr(1, sz - 2);
  555. }
  556. return unquoted;
  557. }
  558. if (replaceValues.LanguageCompileFlags) {
  559. if (variable == "LANGUAGE_COMPILE_FLAGS") {
  560. return replaceValues.LanguageCompileFlags;
  561. }
  562. }
  563. if (replaceValues.Target) {
  564. if (variable == "TARGET") {
  565. return replaceValues.Target;
  566. }
  567. }
  568. if (variable == "TARGET_IMPLIB") {
  569. return this->TargetImplib;
  570. }
  571. if (variable == "TARGET_VERSION_MAJOR") {
  572. if (replaceValues.TargetVersionMajor) {
  573. return replaceValues.TargetVersionMajor;
  574. } else {
  575. return "0";
  576. }
  577. }
  578. if (variable == "TARGET_VERSION_MINOR") {
  579. if (replaceValues.TargetVersionMinor) {
  580. return replaceValues.TargetVersionMinor;
  581. } else {
  582. return "0";
  583. }
  584. }
  585. if (replaceValues.Target) {
  586. if (variable == "TARGET_BASE") {
  587. // Strip the last extension off the target name.
  588. std::string targetBase = replaceValues.Target;
  589. std::string::size_type pos = targetBase.rfind('.');
  590. if (pos != targetBase.npos) {
  591. return targetBase.substr(0, pos);
  592. } else {
  593. return targetBase;
  594. }
  595. }
  596. }
  597. }
  598. if (variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
  599. variable == "TARGET_INSTALLNAME_DIR") {
  600. // All these variables depend on TargetSOName
  601. if (replaceValues.TargetSOName) {
  602. if (variable == "TARGET_SONAME") {
  603. return replaceValues.TargetSOName;
  604. }
  605. if (variable == "SONAME_FLAG" && replaceValues.SONameFlag) {
  606. return replaceValues.SONameFlag;
  607. }
  608. if (replaceValues.TargetInstallNameDir &&
  609. variable == "TARGET_INSTALLNAME_DIR") {
  610. return replaceValues.TargetInstallNameDir;
  611. }
  612. }
  613. return "";
  614. }
  615. if (replaceValues.LinkLibraries) {
  616. if (variable == "LINK_LIBRARIES") {
  617. return replaceValues.LinkLibraries;
  618. }
  619. }
  620. if (replaceValues.Language) {
  621. if (variable == "LANGUAGE") {
  622. return replaceValues.Language;
  623. }
  624. }
  625. if (replaceValues.CMTarget) {
  626. if (variable == "TARGET_NAME") {
  627. return replaceValues.CMTarget->GetName();
  628. }
  629. if (variable == "TARGET_TYPE") {
  630. return cmState::GetTargetTypeName(replaceValues.CMTarget->GetType());
  631. }
  632. }
  633. if (replaceValues.Output) {
  634. if (variable == "OUTPUT") {
  635. return replaceValues.Output;
  636. }
  637. }
  638. if (variable == "CMAKE_COMMAND") {
  639. return this->Convert(cmSystemTools::GetCMakeCommand(), FULL, SHELL);
  640. }
  641. std::vector<std::string> enabledLanguages =
  642. this->GetState()->GetEnabledLanguages();
  643. // loop over language specific replace variables
  644. int pos = 0;
  645. while (ruleReplaceVars[pos]) {
  646. for (std::vector<std::string>::iterator i = enabledLanguages.begin();
  647. i != enabledLanguages.end(); ++i) {
  648. const char* lang = i->c_str();
  649. std::string actualReplace = ruleReplaceVars[pos];
  650. // If this is the compiler then look for the extra variable
  651. // _COMPILER_ARG1 which must be the first argument to the compiler
  652. const char* compilerArg1 = 0;
  653. const char* compilerTarget = 0;
  654. const char* compilerOptionTarget = 0;
  655. const char* compilerExternalToolchain = 0;
  656. const char* compilerOptionExternalToolchain = 0;
  657. const char* compilerSysroot = 0;
  658. const char* compilerOptionSysroot = 0;
  659. if (actualReplace == "CMAKE_${LANG}_COMPILER") {
  660. std::string arg1 = actualReplace + "_ARG1";
  661. cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
  662. compilerArg1 = this->Makefile->GetDefinition(arg1);
  663. compilerTarget = this->Makefile->GetDefinition(
  664. std::string("CMAKE_") + lang + "_COMPILER_TARGET");
  665. compilerOptionTarget = this->Makefile->GetDefinition(
  666. std::string("CMAKE_") + lang + "_COMPILE_OPTIONS_TARGET");
  667. compilerExternalToolchain = this->Makefile->GetDefinition(
  668. std::string("CMAKE_") + lang + "_COMPILER_EXTERNAL_TOOLCHAIN");
  669. compilerOptionExternalToolchain =
  670. this->Makefile->GetDefinition(std::string("CMAKE_") + lang +
  671. "_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN");
  672. compilerSysroot = this->Makefile->GetDefinition("CMAKE_SYSROOT");
  673. compilerOptionSysroot = this->Makefile->GetDefinition(
  674. std::string("CMAKE_") + lang + "_COMPILE_OPTIONS_SYSROOT");
  675. }
  676. if (actualReplace.find("${LANG}") != actualReplace.npos) {
  677. cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
  678. }
  679. if (actualReplace == variable) {
  680. std::string replace = this->Makefile->GetSafeDefinition(variable);
  681. // if the variable is not a FLAG then treat it like a path
  682. if (variable.find("_FLAG") == variable.npos) {
  683. std::string ret = this->ConvertToOutputForExisting(replace);
  684. // if there is a required first argument to the compiler add it
  685. // to the compiler string
  686. if (compilerArg1) {
  687. ret += " ";
  688. ret += compilerArg1;
  689. }
  690. if (compilerTarget && compilerOptionTarget) {
  691. ret += " ";
  692. ret += compilerOptionTarget;
  693. ret += compilerTarget;
  694. }
  695. if (compilerExternalToolchain && compilerOptionExternalToolchain) {
  696. ret += " ";
  697. ret += compilerOptionExternalToolchain;
  698. ret += this->EscapeForShell(compilerExternalToolchain, true);
  699. }
  700. if (compilerSysroot && compilerOptionSysroot) {
  701. ret += " ";
  702. ret += compilerOptionSysroot;
  703. ret += this->EscapeForShell(compilerSysroot, true);
  704. }
  705. return ret;
  706. }
  707. return replace;
  708. }
  709. }
  710. pos++;
  711. }
  712. return variable;
  713. }
  714. void cmLocalGenerator::ExpandRuleVariables(std::string& s,
  715. const RuleVariables& replaceValues)
  716. {
  717. if (replaceValues.RuleLauncher) {
  718. this->InsertRuleLauncher(s, replaceValues.CMTarget,
  719. replaceValues.RuleLauncher);
  720. }
  721. std::string::size_type start = s.find('<');
  722. // no variables to expand
  723. if (start == s.npos) {
  724. return;
  725. }
  726. std::string::size_type pos = 0;
  727. std::string expandedInput;
  728. while (start != s.npos && start < s.size() - 2) {
  729. std::string::size_type end = s.find('>', start);
  730. // if we find a < with no > we are done
  731. if (end == s.npos) {
  732. return;
  733. }
  734. char c = s[start + 1];
  735. // if the next char after the < is not A-Za-z then
  736. // skip it and try to find the next < in the string
  737. if (!isalpha(c)) {
  738. start = s.find('<', start + 1);
  739. } else {
  740. // extract the var
  741. std::string var = s.substr(start + 1, end - start - 1);
  742. std::string replace = this->ExpandRuleVariable(var, replaceValues);
  743. expandedInput += s.substr(pos, start - pos);
  744. expandedInput += replace;
  745. // move to next one
  746. start = s.find('<', start + var.size() + 2);
  747. pos = end + 1;
  748. }
  749. }
  750. // add the rest of the input
  751. expandedInput += s.substr(pos, s.size() - pos);
  752. s = expandedInput;
  753. }
  754. const char* cmLocalGenerator::GetRuleLauncher(cmGeneratorTarget* target,
  755. const std::string& prop)
  756. {
  757. if (target) {
  758. return target->GetProperty(prop);
  759. } else {
  760. return this->Makefile->GetProperty(prop);
  761. }
  762. }
  763. void cmLocalGenerator::InsertRuleLauncher(std::string& s,
  764. cmGeneratorTarget* target,
  765. const std::string& prop)
  766. {
  767. if (const char* val = this->GetRuleLauncher(target, prop)) {
  768. std::ostringstream wrapped;
  769. wrapped << val << " " << s;
  770. s = wrapped.str();
  771. }
  772. }
  773. std::string cmLocalGenerator::ConvertToIncludeReference(
  774. std::string const& path, OutputFormat format, bool forceFullPaths)
  775. {
  776. return this->ConvertToOutputForExisting(
  777. path, forceFullPaths ? FULL : START_OUTPUT, format);
  778. }
  779. std::string cmLocalGenerator::GetIncludeFlags(
  780. const std::vector<std::string>& includes, cmGeneratorTarget* target,
  781. const std::string& lang, bool forceFullPaths, bool forResponseFile,
  782. const std::string& config)
  783. {
  784. if (lang.empty()) {
  785. return "";
  786. }
  787. OutputFormat shellFormat = forResponseFile ? RESPONSE : SHELL;
  788. std::ostringstream includeFlags;
  789. std::string flagVar = "CMAKE_INCLUDE_FLAG_";
  790. flagVar += lang;
  791. const char* includeFlag = this->Makefile->GetSafeDefinition(flagVar);
  792. flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
  793. flagVar += lang;
  794. const char* sep = this->Makefile->GetDefinition(flagVar);
  795. bool quotePaths = false;
  796. if (this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS")) {
  797. quotePaths = true;
  798. }
  799. bool repeatFlag = true;
  800. // should the include flag be repeated like ie. -IA -IB
  801. if (!sep) {
  802. sep = " ";
  803. } else {
  804. // if there is a separator then the flag is not repeated but is only
  805. // given once i.e. -classpath a:b:c
  806. repeatFlag = false;
  807. }
  808. // Support special system include flag if it is available and the
  809. // normal flag is repeated for each directory.
  810. std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
  811. sysFlagVar += lang;
  812. const char* sysIncludeFlag = 0;
  813. if (repeatFlag) {
  814. sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar);
  815. }
  816. std::string fwSearchFlagVar = "CMAKE_";
  817. fwSearchFlagVar += lang;
  818. fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
  819. const char* fwSearchFlag = this->Makefile->GetDefinition(fwSearchFlagVar);
  820. std::string sysFwSearchFlagVar = "CMAKE_";
  821. sysFwSearchFlagVar += lang;
  822. sysFwSearchFlagVar += "_SYSTEM_FRAMEWORK_SEARCH_FLAG";
  823. const char* sysFwSearchFlag =
  824. this->Makefile->GetDefinition(sysFwSearchFlagVar);
  825. bool flagUsed = false;
  826. std::set<std::string> emitted;
  827. #ifdef __APPLE__
  828. emitted.insert("/System/Library/Frameworks");
  829. #endif
  830. std::vector<std::string>::const_iterator i;
  831. for (i = includes.begin(); i != includes.end(); ++i) {
  832. if (fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE") &&
  833. cmSystemTools::IsPathToFramework(i->c_str())) {
  834. std::string frameworkDir = *i;
  835. frameworkDir += "/../";
  836. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
  837. if (emitted.insert(frameworkDir).second) {
  838. if (sysFwSearchFlag && target &&
  839. target->IsSystemIncludeDirectory(*i, config)) {
  840. includeFlags << sysFwSearchFlag;
  841. } else {
  842. includeFlags << fwSearchFlag;
  843. }
  844. includeFlags << this->ConvertToOutputFormat(frameworkDir, shellFormat)
  845. << " ";
  846. }
  847. continue;
  848. }
  849. if (!flagUsed || repeatFlag) {
  850. if (sysIncludeFlag && target &&
  851. target->IsSystemIncludeDirectory(*i, config)) {
  852. includeFlags << sysIncludeFlag;
  853. } else {
  854. includeFlags << includeFlag;
  855. }
  856. flagUsed = true;
  857. }
  858. std::string includePath =
  859. this->ConvertToIncludeReference(*i, shellFormat, forceFullPaths);
  860. if (quotePaths && !includePath.empty() && includePath[0] != '\"') {
  861. includeFlags << "\"";
  862. }
  863. includeFlags << includePath;
  864. if (quotePaths && !includePath.empty() && includePath[0] != '\"') {
  865. includeFlags << "\"";
  866. }
  867. includeFlags << sep;
  868. }
  869. std::string flags = includeFlags.str();
  870. // remove trailing separators
  871. if ((sep[0] != ' ') && !flags.empty() && flags[flags.size() - 1] == sep[0]) {
  872. flags[flags.size() - 1] = ' ';
  873. }
  874. return flags;
  875. }
  876. void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
  877. cmGeneratorTarget const* target,
  878. const std::string& config,
  879. const std::string& lang) const
  880. {
  881. std::vector<std::string> targetDefines;
  882. target->GetCompileDefinitions(targetDefines, config, lang);
  883. this->AppendDefines(defines, targetDefines);
  884. }
  885. void cmLocalGenerator::AddCompileOptions(std::string& flags,
  886. cmGeneratorTarget* target,
  887. const std::string& lang,
  888. const std::string& config)
  889. {
  890. std::string langFlagRegexVar = std::string("CMAKE_") + lang + "_FLAG_REGEX";
  891. if (const char* langFlagRegexStr =
  892. this->Makefile->GetDefinition(langFlagRegexVar)) {
  893. // Filter flags acceptable to this language.
  894. cmsys::RegularExpression r(langFlagRegexStr);
  895. std::vector<std::string> opts;
  896. if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) {
  897. cmSystemTools::ParseWindowsCommandLine(targetFlags, opts);
  898. }
  899. target->GetCompileOptions(opts, config, lang);
  900. for (std::vector<std::string>::const_iterator i = opts.begin();
  901. i != opts.end(); ++i) {
  902. if (r.find(i->c_str())) {
  903. // (Re-)Escape this flag. COMPILE_FLAGS were already parsed
  904. // as a command line above, and COMPILE_OPTIONS are escaped.
  905. this->AppendFlagEscape(flags, *i);
  906. }
  907. }
  908. } else {
  909. // Use all flags.
  910. if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) {
  911. // COMPILE_FLAGS are not escaped for historical reasons.
  912. this->AppendFlags(flags, targetFlags);
  913. }
  914. std::vector<std::string> opts;
  915. target->GetCompileOptions(opts, config, lang);
  916. for (std::vector<std::string>::const_iterator i = opts.begin();
  917. i != opts.end(); ++i) {
  918. // COMPILE_OPTIONS are escaped.
  919. this->AppendFlagEscape(flags, *i);
  920. }
  921. }
  922. std::vector<std::string> features;
  923. target->GetCompileFeatures(features, config);
  924. for (std::vector<std::string>::const_iterator it = features.begin();
  925. it != features.end(); ++it) {
  926. if (!this->Makefile->AddRequiredTargetFeature(target->Target, *it)) {
  927. return;
  928. }
  929. }
  930. for (std::map<std::string, std::string>::const_iterator it =
  931. target->GetMaxLanguageStandards().begin();
  932. it != target->GetMaxLanguageStandards().end(); ++it) {
  933. const char* standard = target->GetProperty(it->first + "_STANDARD");
  934. if (!standard) {
  935. continue;
  936. }
  937. if (this->Makefile->IsLaterStandard(it->first, standard, it->second)) {
  938. std::ostringstream e;
  939. e << "The COMPILE_FEATURES property of target \"" << target->GetName()
  940. << "\" was evaluated when computing the link "
  941. "implementation, and the \""
  942. << it->first << "_STANDARD\" was \"" << it->second
  943. << "\" for that computation. Computing the "
  944. "COMPILE_FEATURES based on the link implementation resulted in a "
  945. "higher \""
  946. << it->first << "_STANDARD\" \"" << standard
  947. << "\". "
  948. "This is not permitted. The COMPILE_FEATURES may not both depend "
  949. "on "
  950. "and be depended on by the link implementation."
  951. << std::endl;
  952. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  953. return;
  954. }
  955. }
  956. this->AddCompilerRequirementFlag(flags, target, lang);
  957. }
  958. void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
  959. cmGeneratorTarget const* target,
  960. const std::string& lang,
  961. const std::string& config,
  962. bool stripImplicitInclDirs) const
  963. {
  964. // Need to decide whether to automatically include the source and
  965. // binary directories at the beginning of the include path.
  966. bool includeSourceDir = false;
  967. bool includeBinaryDir = false;
  968. // When automatic include directories are requested for a build then
  969. // include the source and binary directories at the beginning of the
  970. // include path to approximate include file behavior for an
  971. // in-source build. This does not account for the case of a source
  972. // file in a subdirectory of the current source directory but we
  973. // cannot fix this because not all native build tools support
  974. // per-source-file include paths.
  975. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR")) {
  976. includeSourceDir = true;
  977. includeBinaryDir = true;
  978. }
  979. // Do not repeat an include path.
  980. std::set<std::string> emitted;
  981. // Store the automatic include paths.
  982. if (includeBinaryDir) {
  983. std::string binDir = this->StateSnapshot.GetDirectory().GetCurrentBinary();
  984. if (emitted.find(binDir) == emitted.end()) {
  985. dirs.push_back(binDir);
  986. emitted.insert(binDir);
  987. }
  988. }
  989. if (includeSourceDir) {
  990. std::string srcDir = this->StateSnapshot.GetDirectory().GetCurrentSource();
  991. if (emitted.find(srcDir) == emitted.end()) {
  992. dirs.push_back(srcDir);
  993. emitted.insert(srcDir);
  994. }
  995. }
  996. if (!target) {
  997. return;
  998. }
  999. std::string rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
  1000. std::vector<std::string> implicitDirs;
  1001. // Load implicit include directories for this language.
  1002. std::string impDirVar = "CMAKE_";
  1003. impDirVar += lang;
  1004. impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
  1005. if (const char* value = this->Makefile->GetDefinition(impDirVar)) {
  1006. std::vector<std::string> impDirVec;
  1007. cmSystemTools::ExpandListArgument(value, impDirVec);
  1008. for (std::vector<std::string>::const_iterator i = impDirVec.begin();
  1009. i != impDirVec.end(); ++i) {
  1010. std::string d = rootPath + *i;
  1011. cmSystemTools::ConvertToUnixSlashes(d);
  1012. emitted.insert(d);
  1013. if (!stripImplicitInclDirs) {
  1014. implicitDirs.push_back(*i);
  1015. }
  1016. }
  1017. }
  1018. // Get the target-specific include directories.
  1019. std::vector<std::string> includes;
  1020. includes = target->GetIncludeDirectories(config, lang);
  1021. // Support putting all the in-project include directories first if
  1022. // it is requested by the project.
  1023. if (this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE")) {
  1024. const char* topSourceDir = this->GetState()->GetSourceDirectory();
  1025. const char* topBinaryDir = this->GetState()->GetBinaryDirectory();
  1026. for (std::vector<std::string>::const_iterator i = includes.begin();
  1027. i != includes.end(); ++i) {
  1028. // Emit this directory only if it is a subdirectory of the
  1029. // top-level source or binary tree.
  1030. if (cmSystemTools::ComparePath(*i, topSourceDir) ||
  1031. cmSystemTools::ComparePath(*i, topBinaryDir) ||
  1032. cmSystemTools::IsSubDirectory(*i, topSourceDir) ||
  1033. cmSystemTools::IsSubDirectory(*i, topBinaryDir)) {
  1034. if (emitted.insert(*i).second) {
  1035. dirs.push_back(*i);
  1036. }
  1037. }
  1038. }
  1039. }
  1040. // Construct the final ordered include directory list.
  1041. for (std::vector<std::string>::const_iterator i = includes.begin();
  1042. i != includes.end(); ++i) {
  1043. if (emitted.insert(*i).second) {
  1044. dirs.push_back(*i);
  1045. }
  1046. }
  1047. for (std::vector<std::string>::const_iterator i = implicitDirs.begin();
  1048. i != implicitDirs.end(); ++i) {
  1049. if (std::find(includes.begin(), includes.end(), *i) != includes.end()) {
  1050. dirs.push_back(*i);
  1051. }
  1052. }
  1053. }
  1054. void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
  1055. std::string const& config,
  1056. cmGeneratorTarget* target)
  1057. {
  1058. this->AppendFlags(
  1059. flags, this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS"));
  1060. if (!config.empty()) {
  1061. std::string name = "CMAKE_STATIC_LINKER_FLAGS_" + config;
  1062. this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name));
  1063. }
  1064. this->AppendFlags(flags, target->GetProperty("STATIC_LIBRARY_FLAGS"));
  1065. if (!config.empty()) {
  1066. std::string name = "STATIC_LIBRARY_FLAGS_" + config;
  1067. this->AppendFlags(flags, target->GetProperty(name));
  1068. }
  1069. }
  1070. void cmLocalGenerator::GetTargetFlags(
  1071. const std::string& config, std::string& linkLibs, std::string& flags,
  1072. std::string& linkFlags, std::string& frameworkPath, std::string& linkPath,
  1073. cmGeneratorTarget* target, bool useWatcomQuote)
  1074. {
  1075. const std::string buildType = cmSystemTools::UpperCase(config);
  1076. const char* libraryLinkVariable =
  1077. "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
  1078. switch (target->GetType()) {
  1079. case cmState::STATIC_LIBRARY:
  1080. this->GetStaticLibraryFlags(linkFlags, buildType, target);
  1081. break;
  1082. case cmState::MODULE_LIBRARY:
  1083. libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
  1084. case cmState::SHARED_LIBRARY: {
  1085. linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
  1086. linkFlags += " ";
  1087. if (!buildType.empty()) {
  1088. std::string build = libraryLinkVariable;
  1089. build += "_";
  1090. build += buildType;
  1091. linkFlags += this->Makefile->GetSafeDefinition(build);
  1092. linkFlags += " ";
  1093. }
  1094. if (this->Makefile->IsOn("WIN32") &&
  1095. !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW"))) {
  1096. std::vector<cmSourceFile*> sources;
  1097. target->GetSourceFiles(sources, buildType);
  1098. for (std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1099. i != sources.end(); ++i) {
  1100. cmSourceFile* sf = *i;
  1101. if (sf->GetExtension() == "def") {
  1102. linkFlags +=
  1103. this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1104. linkFlags += this->Convert(sf->GetFullPath(), FULL, SHELL);
  1105. linkFlags += " ";
  1106. }
  1107. }
  1108. }
  1109. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  1110. if (targetLinkFlags) {
  1111. linkFlags += targetLinkFlags;
  1112. linkFlags += " ";
  1113. }
  1114. if (!buildType.empty()) {
  1115. std::string configLinkFlags = "LINK_FLAGS_";
  1116. configLinkFlags += buildType;
  1117. targetLinkFlags = target->GetProperty(configLinkFlags);
  1118. if (targetLinkFlags) {
  1119. linkFlags += targetLinkFlags;
  1120. linkFlags += " ";
  1121. }
  1122. }
  1123. this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath, *target,
  1124. false, false, useWatcomQuote);
  1125. } break;
  1126. case cmState::EXECUTABLE: {
  1127. linkFlags += this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1128. linkFlags += " ";
  1129. if (!buildType.empty()) {
  1130. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1131. build += buildType;
  1132. linkFlags += this->Makefile->GetSafeDefinition(build);
  1133. linkFlags += " ";
  1134. }
  1135. std::string linkLanguage = target->GetLinkerLanguage(buildType);
  1136. if (linkLanguage.empty()) {
  1137. cmSystemTools::Error(
  1138. "CMake can not determine linker language for target: ",
  1139. target->GetName().c_str());
  1140. return;
  1141. }
  1142. this->AddLanguageFlags(flags, linkLanguage, buildType);
  1143. this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath, *target,
  1144. false, false, useWatcomQuote);
  1145. if (cmSystemTools::IsOn(
  1146. this->Makefile->GetDefinition("BUILD_SHARED_LIBS"))) {
  1147. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") +
  1148. linkLanguage + std::string("_FLAGS");
  1149. linkFlags += this->Makefile->GetSafeDefinition(sFlagVar);
  1150. linkFlags += " ";
  1151. }
  1152. if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) {
  1153. linkFlags +=
  1154. this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1155. linkFlags += " ";
  1156. } else {
  1157. linkFlags +=
  1158. this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1159. linkFlags += " ";
  1160. }
  1161. if (target->IsExecutableWithExports()) {
  1162. std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
  1163. exportFlagVar += linkLanguage;
  1164. exportFlagVar += "_FLAG";
  1165. linkFlags += this->Makefile->GetSafeDefinition(exportFlagVar);
  1166. linkFlags += " ";
  1167. }
  1168. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  1169. if (targetLinkFlags) {
  1170. linkFlags += targetLinkFlags;
  1171. linkFlags += " ";
  1172. }
  1173. if (!buildType.empty()) {
  1174. std::string configLinkFlags = "LINK_FLAGS_";
  1175. configLinkFlags += buildType;
  1176. targetLinkFlags = target->GetProperty(configLinkFlags);
  1177. if (targetLinkFlags) {
  1178. linkFlags += targetLinkFlags;
  1179. linkFlags += " ";
  1180. }
  1181. }
  1182. } break;
  1183. default:
  1184. break;
  1185. }
  1186. }
  1187. static std::string GetFrameworkFlags(const std::string& lang,
  1188. const std::string& config,
  1189. cmGeneratorTarget* target)
  1190. {
  1191. cmLocalGenerator* lg = target->GetLocalGenerator();
  1192. cmMakefile* mf = lg->GetMakefile();
  1193. if (!mf->IsOn("APPLE")) {
  1194. return std::string();
  1195. }
  1196. std::string fwSearchFlagVar = "CMAKE_" + lang + "_FRAMEWORK_SEARCH_FLAG";
  1197. const char* fwSearchFlag = mf->GetDefinition(fwSearchFlagVar);
  1198. if (!(fwSearchFlag && *fwSearchFlag)) {
  1199. return std::string();
  1200. }
  1201. std::set<std::string> emitted;
  1202. #ifdef __APPLE__ /* don't insert this when crosscompiling e.g. to iphone */
  1203. emitted.insert("/System/Library/Frameworks");
  1204. #endif
  1205. std::vector<std::string> includes;
  1206. lg->GetIncludeDirectories(includes, target, "C", config);
  1207. // check all include directories for frameworks as this
  1208. // will already have added a -F for the framework
  1209. for (std::vector<std::string>::iterator i = includes.begin();
  1210. i != includes.end(); ++i) {
  1211. if (lg->GetGlobalGenerator()->NameResolvesToFramework(*i)) {
  1212. std::string frameworkDir = *i;
  1213. frameworkDir += "/../";
  1214. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
  1215. emitted.insert(frameworkDir);
  1216. }
  1217. }
  1218. std::string flags;
  1219. if (cmComputeLinkInformation* cli = target->GetLinkInformation(config)) {
  1220. std::vector<std::string> const& frameworks = cli->GetFrameworkPaths();
  1221. for (std::vector<std::string>::const_iterator i = frameworks.begin();
  1222. i != frameworks.end(); ++i) {
  1223. if (emitted.insert(*i).second) {
  1224. flags += fwSearchFlag;
  1225. flags += lg->ConvertToOutputFormat(*i, cmOutputConverter::SHELL);
  1226. flags += " ";
  1227. }
  1228. }
  1229. }
  1230. return flags;
  1231. }
  1232. std::string cmLocalGenerator::GetFrameworkFlags(std::string const& l,
  1233. std::string const& config,
  1234. cmGeneratorTarget* target)
  1235. {
  1236. return ::GetFrameworkFlags(l, config, target);
  1237. }
  1238. void cmLocalGenerator::GetTargetDefines(cmGeneratorTarget const* target,
  1239. std::string const& config,
  1240. std::string const& lang,
  1241. std::set<std::string>& defines) const
  1242. {
  1243. // Add the export symbol definition for shared library objects.
  1244. if (const char* exportMacro = target->GetExportMacro()) {
  1245. this->AppendDefines(defines, exportMacro);
  1246. }
  1247. // Add preprocessor definitions for this target and configuration.
  1248. this->AddCompileDefinitions(defines, target, config, lang.c_str());
  1249. }
  1250. std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib,
  1251. OutputFormat format)
  1252. {
  1253. #if defined(_WIN32) && !defined(__CYGWIN__)
  1254. // Work-ardound command line parsing limitations in MSVC 6.0
  1255. if (this->Makefile->IsOn("MSVC60")) {
  1256. // Search for the last space.
  1257. std::string::size_type pos = lib.rfind(' ');
  1258. if (pos != lib.npos) {
  1259. // Find the slash after the last space, if any.
  1260. pos = lib.find('/', pos);
  1261. // Convert the portion of the path with a space to a short path.
  1262. std::string sp;
  1263. if (cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp)) {
  1264. // Append the rest of the path with no space.
  1265. sp += lib.substr(pos);
  1266. // Convert to an output path.
  1267. return this->Convert(sp.c_str(), NONE, format);
  1268. }
  1269. }
  1270. }
  1271. #endif
  1272. // Normal behavior.
  1273. return this->Convert(lib, START_OUTPUT, format);
  1274. }
  1275. /**
  1276. * Output the linking rules on a command line. For executables,
  1277. * targetLibrary should be a NULL pointer. For libraries, it should point
  1278. * to the name of the library. This will not link a library against itself.
  1279. */
  1280. void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
  1281. std::string& frameworkPath,
  1282. std::string& linkPath,
  1283. cmGeneratorTarget& tgt, bool relink,
  1284. bool forResponseFile,
  1285. bool useWatcomQuote)
  1286. {
  1287. OutputFormat shellFormat =
  1288. (forResponseFile) ? RESPONSE : ((useWatcomQuote) ? WATCOMQUOTE : SHELL);
  1289. bool escapeAllowMakeVars = !forResponseFile;
  1290. std::ostringstream fout;
  1291. std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1292. cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config);
  1293. if (!pcli) {
  1294. return;
  1295. }
  1296. cmComputeLinkInformation& cli = *pcli;
  1297. // Collect library linking flags command line options.
  1298. std::string linkLibs;
  1299. std::string linkLanguage = cli.GetLinkLanguage();
  1300. std::string libPathFlag =
  1301. this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
  1302. std::string libPathTerminator =
  1303. this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
  1304. // Flags to link an executable to shared libraries.
  1305. if (tgt.GetType() == cmState::EXECUTABLE &&
  1306. this->StateSnapshot.GetState()->GetGlobalPropertyAsBool(
  1307. "TARGET_SUPPORTS_SHARED_LIBS")) {
  1308. bool add_shlib_flags = false;
  1309. switch (tgt.GetPolicyStatusCMP0065()) {
  1310. case cmPolicies::WARN:
  1311. if (!tgt.GetPropertyAsBool("ENABLE_EXPORTS") &&
  1312. this->Makefile->PolicyOptionalWarningEnabled(
  1313. "CMAKE_POLICY_WARNING_CMP0065")) {
  1314. std::ostringstream w;
  1315. /* clang-format off */
  1316. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0065) << "\n"
  1317. "For compatibility with older versions of CMake, "
  1318. "additional flags may be added to export symbols on all "
  1319. "executables regardless of thier ENABLE_EXPORTS property.";
  1320. /* clang-format on */
  1321. this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  1322. }
  1323. case cmPolicies::OLD:
  1324. // OLD behavior is to always add the flags
  1325. add_shlib_flags = true;
  1326. break;
  1327. case cmPolicies::REQUIRED_IF_USED:
  1328. case cmPolicies::REQUIRED_ALWAYS:
  1329. this->IssueMessage(
  1330. cmake::FATAL_ERROR,
  1331. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065));
  1332. case cmPolicies::NEW:
  1333. // NEW behavior is to only add the flags if ENABLE_EXPORTS is on
  1334. add_shlib_flags = tgt.GetPropertyAsBool("ENABLE_EXPORTS");
  1335. break;
  1336. }
  1337. if (add_shlib_flags) {
  1338. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
  1339. linkFlagsVar += linkLanguage;
  1340. linkFlagsVar += "_FLAGS";
  1341. linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar);
  1342. linkLibs += " ";
  1343. }
  1344. }
  1345. // Append the framework search path flags.
  1346. std::string fwSearchFlagVar = "CMAKE_";
  1347. fwSearchFlagVar += linkLanguage;
  1348. fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
  1349. const char* fwSearchFlag = this->Makefile->GetDefinition(fwSearchFlagVar);
  1350. if (fwSearchFlag && *fwSearchFlag) {
  1351. std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
  1352. for (std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1353. fdi != fwDirs.end(); ++fdi) {
  1354. frameworkPath += fwSearchFlag;
  1355. frameworkPath += this->Convert(*fdi, NONE, shellFormat);
  1356. frameworkPath += " ";
  1357. }
  1358. }
  1359. // Append the library search path flags.
  1360. std::vector<std::string> const& libDirs = cli.GetDirectories();
  1361. for (std::vector<std::string>::const_iterator libDir = libDirs.begin();
  1362. libDir != libDirs.end(); ++libDir) {
  1363. std::string libpath =
  1364. this->ConvertToOutputForExisting(*libDir, START_OUTPUT, shellFormat);
  1365. linkPath += " " + libPathFlag;
  1366. linkPath += libpath;
  1367. linkPath += libPathTerminator;
  1368. linkPath += " ";
  1369. }
  1370. // Append the link items.
  1371. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1372. ItemVector const& items = cli.GetItems();
  1373. for (ItemVector::const_iterator li = items.begin(); li != items.end();
  1374. ++li) {
  1375. if (li->Target && li->Target->GetType() == cmState::INTERFACE_LIBRARY) {
  1376. continue;
  1377. }
  1378. if (li->IsPath) {
  1379. linkLibs += this->ConvertToLinkReference(li->Value, shellFormat);
  1380. } else {
  1381. linkLibs += li->Value;
  1382. }
  1383. linkLibs += " ";
  1384. }
  1385. // Write the library flags to the build rule.
  1386. fout << linkLibs;
  1387. // Check what kind of rpath flags to use.
  1388. if (cli.GetRuntimeSep().empty()) {
  1389. // Each rpath entry gets its own option ("-R a -R b -R c")
  1390. std::vector<std::string> runtimeDirs;
  1391. cli.GetRPath(runtimeDirs, relink);
  1392. std::string rpath;
  1393. for (std::vector<std::string>::iterator ri = runtimeDirs.begin();
  1394. ri != runtimeDirs.end(); ++ri) {
  1395. rpath += cli.GetRuntimeFlag();
  1396. rpath += this->Convert(*ri, NONE, shellFormat);
  1397. rpath += " ";
  1398. }
  1399. fout << rpath;
  1400. } else {
  1401. // All rpath entries are combined ("-Wl,-rpath,a:b:c").
  1402. std::string rpath = cli.GetRPathString(relink);
  1403. // Store the rpath option in the stream.
  1404. if (!rpath.empty()) {
  1405. fout << cli.GetRuntimeFlag();
  1406. fout << this->EscapeForShell(rpath, escapeAllowMakeVars);
  1407. fout << " ";
  1408. }
  1409. }
  1410. // Add the linker runtime search path if any.
  1411. std::string rpath_link = cli.GetRPathLinkString();
  1412. if (!cli.GetRPathLinkFlag().empty() && !rpath_link.empty()) {
  1413. fout << cli.GetRPathLinkFlag();
  1414. fout << this->EscapeForShell(rpath_link, escapeAllowMakeVars);
  1415. fout << " ";
  1416. }
  1417. // Add standard libraries for this language.
  1418. std::string standardLibsVar = "CMAKE_";
  1419. standardLibsVar += cli.GetLinkLanguage();
  1420. standardLibsVar += "_STANDARD_LIBRARIES";
  1421. if (const char* stdLibs = this->Makefile->GetDefinition(standardLibsVar)) {
  1422. fout << stdLibs << " ";
  1423. }
  1424. linkLibraries = fout.str();
  1425. }
  1426. void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
  1427. cmGeneratorTarget const* target,
  1428. const std::string& lang,
  1429. const std::string& config)
  1430. {
  1431. // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
  1432. if (this->Makefile->IsOn("APPLE") && this->EmitUniversalBinaryFlags) {
  1433. std::vector<std::string> archs;
  1434. target->GetAppleArchs(config, archs);
  1435. const char* sysroot = this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
  1436. if (sysroot && sysroot[0] == '/' && !sysroot[1]) {
  1437. sysroot = 0;
  1438. }
  1439. std::string sysrootFlagVar =
  1440. std::string("CMAKE_") + lang + "_SYSROOT_FLAG";
  1441. const char* sysrootFlag = this->Makefile->GetDefinition(sysrootFlagVar);
  1442. const char* deploymentTarget =
  1443. this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
  1444. std::string deploymentTargetFlagVar =
  1445. std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
  1446. const char* deploymentTargetFlag =
  1447. this->Makefile->GetDefinition(deploymentTargetFlagVar);
  1448. if (!archs.empty() && !lang.empty() &&
  1449. (lang[0] == 'C' || lang[0] == 'F')) {
  1450. for (std::vector<std::string>::iterator i = archs.begin();
  1451. i != archs.end(); ++i) {
  1452. flags += " -arch ";
  1453. flags += *i;
  1454. }
  1455. }
  1456. if (sysrootFlag && *sysrootFlag && sysroot && *sysroot) {
  1457. flags += " ";
  1458. flags += sysrootFlag;
  1459. flags += " ";
  1460. flags += this->Convert(sysroot, NONE, SHELL);
  1461. }
  1462. if (deploymentTargetFlag && *deploymentTargetFlag && deploymentTarget &&
  1463. *deploymentTarget) {
  1464. flags += " ";
  1465. flags += deploymentTargetFlag;
  1466. flags += deploymentTarget;
  1467. }
  1468. }
  1469. }
  1470. void cmLocalGenerator::AddLanguageFlags(std::string& flags,
  1471. const std::string& lang,
  1472. const std::string& config)
  1473. {
  1474. // Add language-specific flags.
  1475. std::string flagsVar = "CMAKE_";
  1476. flagsVar += lang;
  1477. flagsVar += "_FLAGS";
  1478. this->AddConfigVariableFlags(flags, flagsVar, config);
  1479. }
  1480. cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse(
  1481. const std::string& name) const
  1482. {
  1483. std::vector<cmGeneratorTarget*>::const_iterator imported = std::find_if(
  1484. this->ImportedGeneratorTargets.begin(),
  1485. this->ImportedGeneratorTargets.end(), NamedGeneratorTargetFinder(name));
  1486. if (imported != this->ImportedGeneratorTargets.end()) {
  1487. return *imported;
  1488. }
  1489. if (cmGeneratorTarget* t = this->FindLocalNonAliasGeneratorTarget(name)) {
  1490. return t;
  1491. }
  1492. return this->GetGlobalGenerator()->FindGeneratorTarget(name);
  1493. }
  1494. bool cmLocalGenerator::GetRealDependency(const std::string& inName,
  1495. const std::string& config,
  1496. std::string& dep)
  1497. {
  1498. // Older CMake code may specify the dependency using the target
  1499. // output file rather than the target name. Such code would have
  1500. // been written before there was support for target properties that
  1501. // modify the name so stripping down to just the file name should
  1502. // produce the target name in this case.
  1503. std::string name = cmSystemTools::GetFilenameName(inName);
  1504. // If the input name is the empty string, there is no real
  1505. // dependency. Short-circuit the other checks:
  1506. if (name == "") {
  1507. return false;
  1508. }
  1509. if (cmSystemTools::GetFilenameLastExtension(name) == ".exe") {
  1510. name = cmSystemTools::GetFilenameWithoutLastExtension(name);
  1511. }
  1512. // Look for a CMake target with the given name.
  1513. if (cmGeneratorTarget* target = this->FindGeneratorTargetToUse(name)) {
  1514. // make sure it is not just a coincidence that the target name
  1515. // found is part of the inName
  1516. if (cmSystemTools::FileIsFullPath(inName.c_str())) {
  1517. std::string tLocation;
  1518. if (target->GetType() >= cmState::EXECUTABLE &&
  1519. target->GetType() <= cmState::MODULE_LIBRARY) {
  1520. tLocation = target->GetLocation(config);
  1521. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1522. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  1523. }
  1524. std::string depLocation =
  1525. cmSystemTools::GetFilenamePath(std::string(inName));
  1526. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  1527. if (depLocation != tLocation) {
  1528. // it is a full path to a depend that has the same name
  1529. // as a target but is in a different location so do not use
  1530. // the target as the depend
  1531. dep = inName;
  1532. return true;
  1533. }
  1534. }
  1535. switch (target->GetType()) {
  1536. case cmState::EXECUTABLE:
  1537. case cmState::STATIC_LIBRARY:
  1538. case cmState::SHARED_LIBRARY:
  1539. case cmState::MODULE_LIBRARY:
  1540. case cmState::UNKNOWN_LIBRARY:
  1541. dep = target->GetLocation(config);
  1542. return true;
  1543. case cmState::OBJECT_LIBRARY:
  1544. // An object library has no single file on which to depend.
  1545. // This was listed to get the target-level dependency.
  1546. return false;
  1547. case cmState::INTERFACE_LIBRARY:
  1548. // An interface library has no file on which to depend.
  1549. // This was listed to get the target-level dependency.
  1550. return false;
  1551. case cmState::UTILITY:
  1552. case cmState::GLOBAL_TARGET:
  1553. // A utility target has no file on which to depend. This was listed
  1554. // only to get the target-level dependency.
  1555. return false;
  1556. }
  1557. }
  1558. // The name was not that of a CMake target. It must name a file.
  1559. if (cmSystemTools::FileIsFullPath(inName.c_str())) {
  1560. // This is a full path. Return it as given.
  1561. dep = inName;
  1562. return true;
  1563. }
  1564. // Check for a source file in this directory that matches the
  1565. // dependency.
  1566. if (cmSourceFile* sf = this->Makefile->GetSource(inName)) {
  1567. dep = sf->GetFullPath();
  1568. return true;
  1569. }
  1570. // Treat the name as relative to the source directory in which it
  1571. // was given.
  1572. dep = this->StateSnapshot.GetDirectory().GetCurrentSource();
  1573. dep += "/";
  1574. dep += inName;
  1575. return true;
  1576. }
  1577. void cmLocalGenerator::AddSharedFlags(std::string& flags,
  1578. const std::string& lang, bool shared)
  1579. {
  1580. std::string flagsVar;
  1581. // Add flags for dealing with shared libraries for this language.
  1582. if (shared) {
  1583. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1584. flagsVar += lang;
  1585. flagsVar += "_FLAGS";
  1586. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  1587. }
  1588. }
  1589. void cmLocalGenerator::AddCompilerRequirementFlag(
  1590. std::string& flags, cmGeneratorTarget const* target, const std::string& lang)
  1591. {
  1592. if (lang.empty()) {
  1593. return;
  1594. }
  1595. const char* defaultStd =
  1596. this->Makefile->GetDefinition("CMAKE_" + lang + "_STANDARD_DEFAULT");
  1597. if (!defaultStd || !*defaultStd) {
  1598. // This compiler has no notion of language standard levels.
  1599. return;
  1600. }
  1601. std::string stdProp = lang + "_STANDARD";
  1602. const char* standardProp = target->GetProperty(stdProp);
  1603. if (!standardProp) {
  1604. return;
  1605. }
  1606. std::string extProp = lang + "_EXTENSIONS";
  1607. std::string type = "EXTENSION";
  1608. bool ext = true;
  1609. if (const char* extPropValue = target->GetProperty(extProp)) {
  1610. if (cmSystemTools::IsOff(extPropValue)) {
  1611. ext = false;
  1612. type = "STANDARD";
  1613. }
  1614. }
  1615. if (target->GetPropertyAsBool(lang + "_STANDARD_REQUIRED")) {
  1616. std::string option_flag =
  1617. "CMAKE_" + lang + standardProp + "_" + type + "_COMPILE_OPTION";
  1618. const char* opt =
  1619. target->Target->GetMakefile()->GetDefinition(option_flag);
  1620. if (!opt) {
  1621. std::ostringstream e;
  1622. e << "Target \"" << target->GetName() << "\" requires the language "
  1623. "dialect \""
  1624. << lang << standardProp << "\" "
  1625. << (ext ? "(with compiler extensions)" : "")
  1626. << ", but CMake "
  1627. "does not know the compile flags to use to enable it.";
  1628. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  1629. } else {
  1630. this->AppendFlagEscape(flags, opt);
  1631. }
  1632. return;
  1633. }
  1634. static std::map<std::string, std::vector<std::string> > langStdMap;
  1635. if (langStdMap.empty()) {
  1636. // Maintain sorted order, most recent first.
  1637. langStdMap["CXX"].push_back("14");
  1638. langStdMap["CXX"].push_back("11");
  1639. langStdMap["CXX"].push_back("98");
  1640. langStdMap["C"].push_back("11");
  1641. langStdMap["C"].push_back("99");
  1642. langStdMap["C"].push_back("90");
  1643. }
  1644. std::string standard(standardProp);
  1645. std::vector<std::string>& stds = langStdMap[lang];
  1646. std::vector<std::string>::const_iterator stdIt =
  1647. std::find(stds.begin(), stds.end(), standard);
  1648. if (stdIt == stds.end()) {
  1649. std::string e =
  1650. lang + "_STANDARD is set to invalid value '" + standard + "'";
  1651. this->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
  1652. cmake::FATAL_ERROR, e, target->GetBacktrace());
  1653. return;
  1654. }
  1655. std::vector<std::string>::const_iterator defaultStdIt =
  1656. std::find(stds.begin(), stds.end(), defaultStd);
  1657. if (defaultStdIt == stds.end()) {
  1658. std::string e = "CMAKE_" + lang +
  1659. "_STANDARD_DEFAULT is set to invalid value '" + std::string(defaultStd) +
  1660. "'";
  1661. this->IssueMessage(cmake::INTERNAL_ERROR, e);
  1662. return;
  1663. }
  1664. // Greater or equal because the standards are stored in
  1665. // backward chronological order.
  1666. if (stdIt >= defaultStdIt) {
  1667. std::string option_flag =
  1668. "CMAKE_" + lang + *stdIt + "_" + type + "_COMPILE_OPTION";
  1669. const char* opt =
  1670. target->Target->GetMakefile()->GetRequiredDefinition(option_flag);
  1671. this->AppendFlagEscape(flags, opt);
  1672. return;
  1673. }
  1674. for (; stdIt < defaultStdIt; ++stdIt) {
  1675. std::string option_flag =
  1676. "CMAKE_" + lang + *stdIt + "_" + type + "_COMPILE_OPTION";
  1677. if (const char* opt =
  1678. target->Target->GetMakefile()->GetDefinition(option_flag)) {
  1679. this->AppendFlagEscape(flags, opt);
  1680. return;
  1681. }
  1682. }
  1683. }
  1684. static void AddVisibilityCompileOption(std::string& flags,
  1685. cmGeneratorTarget const* target,
  1686. cmLocalGenerator* lg,
  1687. const std::string& lang,
  1688. std::string* warnCMP0063)
  1689. {
  1690. std::string compileOption = "CMAKE_" + lang + "_COMPILE_OPTIONS_VISIBILITY";
  1691. const char* opt = lg->GetMakefile()->GetDefinition(compileOption);
  1692. if (!opt) {
  1693. return;
  1694. }
  1695. std::string flagDefine = lang + "_VISIBILITY_PRESET";
  1696. const char* prop = target->GetProperty(flagDefine);
  1697. if (!prop) {
  1698. return;
  1699. }
  1700. if (warnCMP0063) {
  1701. *warnCMP0063 += " " + flagDefine + "\n";
  1702. return;
  1703. }
  1704. if (strcmp(prop, "hidden") != 0 && strcmp(prop, "default") != 0 &&
  1705. strcmp(prop, "protected") != 0 && strcmp(prop, "internal") != 0) {
  1706. std::ostringstream e;
  1707. e << "Target " << target->GetName() << " uses unsupported value \"" << prop
  1708. << "\" for " << flagDefine << ".";
  1709. cmSystemTools::Error(e.str().c_str());
  1710. return;
  1711. }
  1712. std::string option = std::string(opt) + prop;
  1713. lg->AppendFlags(flags, option);
  1714. }
  1715. static void AddInlineVisibilityCompileOption(std::string& flags,
  1716. cmGeneratorTarget const* target,
  1717. cmLocalGenerator* lg,
  1718. std::string* warnCMP0063)
  1719. {
  1720. std::string compileOption =
  1721. "CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN";
  1722. const char* opt = lg->GetMakefile()->GetDefinition(compileOption);
  1723. if (!opt) {
  1724. return;
  1725. }
  1726. bool prop = target->GetPropertyAsBool("VISIBILITY_INLINES_HIDDEN");
  1727. if (!prop) {
  1728. return;
  1729. }
  1730. if (warnCMP0063) {
  1731. *warnCMP0063 += " VISIBILITY_INLINES_HIDDEN\n";
  1732. return;
  1733. }
  1734. lg->AppendFlags(flags, opt);
  1735. }
  1736. void cmLocalGenerator::AddVisibilityPresetFlags(
  1737. std::string& flags, cmGeneratorTarget const* target, const std::string& lang)
  1738. {
  1739. if (lang.empty()) {
  1740. return;
  1741. }
  1742. std::string warnCMP0063;
  1743. std::string* pWarnCMP0063 = 0;
  1744. if (target->GetType() != cmState::SHARED_LIBRARY &&
  1745. target->GetType() != cmState::MODULE_LIBRARY &&
  1746. !target->IsExecutableWithExports()) {
  1747. switch (target->GetPolicyStatusCMP0063()) {
  1748. case cmPolicies::OLD:
  1749. return;
  1750. case cmPolicies::WARN:
  1751. pWarnCMP0063 = &warnCMP0063;
  1752. break;
  1753. default:
  1754. break;
  1755. }
  1756. }
  1757. AddVisibilityCompileOption(flags, target, this, lang, pWarnCMP0063);
  1758. if (lang == "CXX") {
  1759. AddInlineVisibilityCompileOption(flags, target, this, pWarnCMP0063);
  1760. }
  1761. if (!warnCMP0063.empty() && this->WarnCMP0063.insert(target).second) {
  1762. std::ostringstream w;
  1763. /* clang-format off */
  1764. w <<
  1765. cmPolicies::GetPolicyWarning(cmPolicies::CMP0063) << "\n"
  1766. "Target \"" << target->GetName() << "\" of "
  1767. "type \"" << cmState::GetTargetTypeName(target->GetType()) << "\" "
  1768. "has the following visibility properties set for " << lang << ":\n" <<
  1769. warnCMP0063 <<
  1770. "For compatibility CMake is not honoring them for this target.";
  1771. /* clang-format on */
  1772. target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1773. cmake::AUTHOR_WARNING, w.str(), target->GetBacktrace());
  1774. }
  1775. }
  1776. void cmLocalGenerator::AddCMP0018Flags(std::string& flags,
  1777. cmGeneratorTarget const* target,
  1778. std::string const& lang,
  1779. const std::string& config)
  1780. {
  1781. int targetType = target->GetType();
  1782. bool shared = ((targetType == cmState::SHARED_LIBRARY) ||
  1783. (targetType == cmState::MODULE_LIBRARY));
  1784. if (this->GetShouldUseOldFlags(shared, lang)) {
  1785. this->AddSharedFlags(flags, lang, shared);
  1786. } else {
  1787. if (target->GetType() == cmState::OBJECT_LIBRARY) {
  1788. if (target->GetPropertyAsBool("POSITION_INDEPENDENT_CODE")) {
  1789. this->AddPositionIndependentFlags(flags, lang, targetType);
  1790. }
  1791. return;
  1792. }
  1793. if (target->GetLinkInterfaceDependentBoolProperty(
  1794. "POSITION_INDEPENDENT_CODE", config)) {
  1795. this->AddPositionIndependentFlags(flags, lang, targetType);
  1796. }
  1797. if (shared) {
  1798. this->AppendFeatureOptions(flags, lang, "DLL");
  1799. }
  1800. }
  1801. }
  1802. bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
  1803. const std::string& lang) const
  1804. {
  1805. std::string originalFlags =
  1806. this->GlobalGenerator->GetSharedLibFlagsForLanguage(lang);
  1807. if (shared) {
  1808. std::string flagsVar = "CMAKE_SHARED_LIBRARY_";
  1809. flagsVar += lang;
  1810. flagsVar += "_FLAGS";
  1811. const char* flags = this->Makefile->GetSafeDefinition(flagsVar);
  1812. if (flags && flags != originalFlags) {
  1813. switch (this->GetPolicyStatus(cmPolicies::CMP0018)) {
  1814. case cmPolicies::WARN: {
  1815. std::ostringstream e;
  1816. e << "Variable " << flagsVar
  1817. << " has been modified. CMake "
  1818. "will ignore the POSITION_INDEPENDENT_CODE target property for "
  1819. "shared libraries and will use the "
  1820. << flagsVar
  1821. << " variable "
  1822. "instead. This may cause errors if the original content of "
  1823. << flagsVar << " was removed.\n"
  1824. << cmPolicies::GetPolicyWarning(cmPolicies::CMP0018);
  1825. this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  1826. // fall through to OLD behaviour
  1827. }
  1828. case cmPolicies::OLD:
  1829. return true;
  1830. case cmPolicies::REQUIRED_IF_USED:
  1831. case cmPolicies::REQUIRED_ALWAYS:
  1832. case cmPolicies::NEW:
  1833. return false;
  1834. }
  1835. }
  1836. }
  1837. return false;
  1838. }
  1839. void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
  1840. std::string const& lang,
  1841. int targetType)
  1842. {
  1843. const char* picFlags = 0;
  1844. if (targetType == cmState::EXECUTABLE) {
  1845. std::string flagsVar = "CMAKE_";
  1846. flagsVar += lang;
  1847. flagsVar += "_COMPILE_OPTIONS_PIE";
  1848. picFlags = this->Makefile->GetSafeDefinition(flagsVar);
  1849. }
  1850. if (!picFlags) {
  1851. std::string flagsVar = "CMAKE_";
  1852. flagsVar += lang;
  1853. flagsVar += "_COMPILE_OPTIONS_PIC";
  1854. picFlags = this->Makefile->GetSafeDefinition(flagsVar);
  1855. }
  1856. if (picFlags) {
  1857. std::vector<std::string> options;
  1858. cmSystemTools::ExpandListArgument(picFlags, options);
  1859. for (std::vector<std::string>::const_iterator oi = options.begin();
  1860. oi != options.end(); ++oi) {
  1861. this->AppendFlagEscape(flags, *oi);
  1862. }
  1863. }
  1864. }
  1865. void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
  1866. const std::string& var,
  1867. const std::string& config)
  1868. {
  1869. // Add the flags from the variable itself.
  1870. std::string flagsVar = var;
  1871. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  1872. // Add the flags from the build-type specific variable.
  1873. if (!config.empty()) {
  1874. flagsVar += "_";
  1875. flagsVar += cmSystemTools::UpperCase(config);
  1876. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  1877. }
  1878. }
  1879. void cmLocalGenerator::AppendFlags(std::string& flags,
  1880. const std::string& newFlags)
  1881. {
  1882. if (!newFlags.empty()) {
  1883. if (!flags.empty()) {
  1884. flags += " ";
  1885. }
  1886. flags += newFlags;
  1887. }
  1888. }
  1889. void cmLocalGenerator::AppendFlags(std::string& flags, const char* newFlags)
  1890. {
  1891. if (newFlags && *newFlags) {
  1892. this->AppendFlags(flags, std::string(newFlags));
  1893. }
  1894. }
  1895. void cmLocalGenerator::AppendFlagEscape(std::string& flags,
  1896. const std::string& rawFlag)
  1897. {
  1898. this->AppendFlags(flags, this->EscapeForShell(rawFlag));
  1899. }
  1900. void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
  1901. const char* defines_list) const
  1902. {
  1903. // Short-circuit if there are no definitions.
  1904. if (!defines_list) {
  1905. return;
  1906. }
  1907. // Expand the list of definitions.
  1908. std::vector<std::string> defines_vec;
  1909. cmSystemTools::ExpandListArgument(defines_list, defines_vec);
  1910. this->AppendDefines(defines, defines_vec);
  1911. }
  1912. void cmLocalGenerator::AppendDefines(
  1913. std::set<std::string>& defines,
  1914. const std::vector<std::string>& defines_vec) const
  1915. {
  1916. for (std::vector<std::string>::const_iterator di = defines_vec.begin();
  1917. di != defines_vec.end(); ++di) {
  1918. // Skip unsupported definitions.
  1919. if (!this->CheckDefinition(*di)) {
  1920. continue;
  1921. }
  1922. defines.insert(*di);
  1923. }
  1924. }
  1925. void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
  1926. std::string& definesString,
  1927. const std::string& lang)
  1928. {
  1929. // Lookup the define flag for the current language.
  1930. std::string dflag = "-D";
  1931. if (!lang.empty()) {
  1932. std::string defineFlagVar = "CMAKE_";
  1933. defineFlagVar += lang;
  1934. defineFlagVar += "_DEFINE_FLAG";
  1935. const char* df = this->Makefile->GetDefinition(defineFlagVar);
  1936. if (df && *df) {
  1937. dflag = df;
  1938. }
  1939. }
  1940. std::set<std::string>::const_iterator defineIt = defines.begin();
  1941. const std::set<std::string>::const_iterator defineEnd = defines.end();
  1942. const char* itemSeparator = definesString.empty() ? "" : " ";
  1943. for (; defineIt != defineEnd; ++defineIt) {
  1944. // Append the definition with proper escaping.
  1945. std::string def = dflag;
  1946. if (this->GetState()->UseWatcomWMake()) {
  1947. // The Watcom compiler does its own command line parsing instead
  1948. // of using the windows shell rules. Definitions are one of
  1949. // -DNAME
  1950. // -DNAME=<cpp-token>
  1951. // -DNAME="c-string with spaces and other characters(?@#$)"
  1952. //
  1953. // Watcom will properly parse each of these cases from the
  1954. // command line without any escapes. However we still have to
  1955. // get the '$' and '#' characters through WMake as '$$' and
  1956. // '$#'.
  1957. for (const char* c = defineIt->c_str(); *c; ++c) {
  1958. if (*c == '$' || *c == '#') {
  1959. def += '$';
  1960. }
  1961. def += *c;
  1962. }
  1963. } else {
  1964. // Make the definition appear properly on the command line. Use
  1965. // -DNAME="value" instead of -D"NAME=value" for historical reasons.
  1966. std::string::size_type eq = defineIt->find("=");
  1967. def += defineIt->substr(0, eq);
  1968. if (eq != defineIt->npos) {
  1969. def += "=";
  1970. def += this->EscapeForShell(defineIt->c_str() + eq + 1, true);
  1971. }
  1972. }
  1973. definesString += itemSeparator;
  1974. itemSeparator = " ";
  1975. definesString += def;
  1976. }
  1977. }
  1978. void cmLocalGenerator::AppendFeatureOptions(std::string& flags,
  1979. const std::string& lang,
  1980. const char* feature)
  1981. {
  1982. std::string optVar = "CMAKE_";
  1983. optVar += lang;
  1984. optVar += "_COMPILE_OPTIONS_";
  1985. optVar += feature;
  1986. if (const char* optionList = this->Makefile->GetDefinition(optVar)) {
  1987. std::vector<std::string> options;
  1988. cmSystemTools::ExpandListArgument(optionList, options);
  1989. for (std::vector<std::string>::const_iterator oi = options.begin();
  1990. oi != options.end(); ++oi) {
  1991. this->AppendFlagEscape(flags, *oi);
  1992. }
  1993. }
  1994. }
  1995. const char* cmLocalGenerator::GetFeature(const std::string& feature,
  1996. const std::string& config)
  1997. {
  1998. std::string featureName = feature;
  1999. // TODO: Define accumulation policy for features (prepend, append, replace).
  2000. // Currently we always replace.
  2001. if (!config.empty()) {
  2002. featureName += "_";
  2003. featureName += cmSystemTools::UpperCase(config);
  2004. }
  2005. cmState::Snapshot snp = this->StateSnapshot;
  2006. while (snp.IsValid()) {
  2007. if (const char* value = snp.GetDirectory().GetProperty(featureName)) {
  2008. return value;
  2009. }
  2010. snp = snp.GetBuildsystemDirectoryParent();
  2011. }
  2012. return 0;
  2013. }
  2014. std::string cmLocalGenerator::GetProjectName() const
  2015. {
  2016. return this->StateSnapshot.GetProjectName();
  2017. }
  2018. std::string cmLocalGenerator::ConstructComment(
  2019. cmCustomCommandGenerator const& ccg, const char* default_comment)
  2020. {
  2021. // Check for a comment provided with the command.
  2022. if (ccg.GetComment()) {
  2023. return ccg.GetComment();
  2024. }
  2025. // Construct a reasonable default comment if possible.
  2026. if (!ccg.GetOutputs().empty()) {
  2027. std::string comment;
  2028. comment = "Generating ";
  2029. const char* sep = "";
  2030. for (std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin();
  2031. o != ccg.GetOutputs().end(); ++o) {
  2032. comment += sep;
  2033. comment += this->Convert(*o, cmOutputConverter::START_OUTPUT);
  2034. sep = ", ";
  2035. }
  2036. return comment;
  2037. }
  2038. // Otherwise use the provided default.
  2039. return default_comment;
  2040. }
  2041. class cmInstallTargetGeneratorLocal : public cmInstallTargetGenerator
  2042. {
  2043. public:
  2044. cmInstallTargetGeneratorLocal(cmLocalGenerator* lg, std::string const& t,
  2045. const char* dest, bool implib)
  2046. : cmInstallTargetGenerator(
  2047. t, dest, implib, "", std::vector<std::string>(), "Unspecified",
  2048. cmInstallGenerator::SelectMessageLevel(lg->GetMakefile()), false,
  2049. false)
  2050. {
  2051. this->Compute(lg);
  2052. }
  2053. };
  2054. void cmLocalGenerator::GenerateTargetInstallRules(
  2055. std::ostream& os, const std::string& config,
  2056. std::vector<std::string> const& configurationTypes)
  2057. {
  2058. // Convert the old-style install specification from each target to
  2059. // an install generator and run it.
  2060. std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
  2061. for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
  2062. l != tgts.end(); ++l) {
  2063. if ((*l)->GetType() == cmState::INTERFACE_LIBRARY) {
  2064. continue;
  2065. }
  2066. // Include the user-specified pre-install script for this target.
  2067. if (const char* preinstall = (*l)->GetProperty("PRE_INSTALL_SCRIPT")) {
  2068. cmInstallScriptGenerator g(preinstall, false, 0, false);
  2069. g.Generate(os, config, configurationTypes);
  2070. }
  2071. // Install this target if a destination is given.
  2072. if ((*l)->Target->GetInstallPath() != "") {
  2073. // Compute the full install destination. Note that converting
  2074. // to unix slashes also removes any trailing slash.
  2075. // We also skip over the leading slash given by the user.
  2076. std::string destination = (*l)->Target->GetInstallPath().substr(1);
  2077. cmSystemTools::ConvertToUnixSlashes(destination);
  2078. if (destination.empty()) {
  2079. destination = ".";
  2080. }
  2081. // Generate the proper install generator for this target type.
  2082. switch ((*l)->GetType()) {
  2083. case cmState::EXECUTABLE:
  2084. case cmState::STATIC_LIBRARY:
  2085. case cmState::MODULE_LIBRARY: {
  2086. // Use a target install generator.
  2087. cmInstallTargetGeneratorLocal g(this, (*l)->GetName(),
  2088. destination.c_str(), false);
  2089. g.Generate(os, config, configurationTypes);
  2090. } break;
  2091. case cmState::SHARED_LIBRARY: {
  2092. #if defined(_WIN32) || defined(__CYGWIN__)
  2093. // Special code to handle DLL. Install the import library
  2094. // to the normal destination and the DLL to the runtime
  2095. // destination.
  2096. cmInstallTargetGeneratorLocal g1(this, (*l)->GetName(),
  2097. destination.c_str(), true);
  2098. g1.Generate(os, config, configurationTypes);
  2099. // We also skip over the leading slash given by the user.
  2100. destination = (*l)->Target->GetRuntimeInstallPath().substr(1);
  2101. cmSystemTools::ConvertToUnixSlashes(destination);
  2102. cmInstallTargetGeneratorLocal g2(this, (*l)->GetName(),
  2103. destination.c_str(), false);
  2104. g2.Generate(os, config, configurationTypes);
  2105. #else
  2106. // Use a target install generator.
  2107. cmInstallTargetGeneratorLocal g(this, (*l)->GetName(),
  2108. destination.c_str(), false);
  2109. g.Generate(os, config, configurationTypes);
  2110. #endif
  2111. } break;
  2112. default:
  2113. break;
  2114. }
  2115. }
  2116. // Include the user-specified post-install script for this target.
  2117. if (const char* postinstall = (*l)->GetProperty("POST_INSTALL_SCRIPT")) {
  2118. cmInstallScriptGenerator g(postinstall, false, 0, false);
  2119. g.Generate(os, config, configurationTypes);
  2120. }
  2121. }
  2122. }
  2123. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2124. static std::string cmLocalGeneratorMD5(const char* input)
  2125. {
  2126. char md5out[32];
  2127. cmsysMD5* md5 = cmsysMD5_New();
  2128. cmsysMD5_Initialize(md5);
  2129. cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
  2130. cmsysMD5_FinalizeHex(md5, md5out);
  2131. cmsysMD5_Delete(md5);
  2132. return std::string(md5out, 32);
  2133. }
  2134. static bool cmLocalGeneratorShortenObjectName(std::string& objName,
  2135. std::string::size_type max_len)
  2136. {
  2137. // Replace the beginning of the path portion of the object name with
  2138. // its own md5 sum.
  2139. std::string::size_type pos =
  2140. objName.find('/', objName.size() - max_len + 32);
  2141. if (pos != objName.npos) {
  2142. std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
  2143. md5name += objName.substr(pos);
  2144. objName = md5name;
  2145. // The object name is now short enough.
  2146. return true;
  2147. } else {
  2148. // The object name could not be shortened enough.
  2149. return false;
  2150. }
  2151. }
  2152. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  2153. std::string::size_type dir_len,
  2154. std::string::size_type max_total_len)
  2155. {
  2156. // Enforce the maximum file name length if possible.
  2157. std::string::size_type max_obj_len = max_total_len;
  2158. if (dir_len < max_total_len) {
  2159. max_obj_len = max_total_len - dir_len;
  2160. if (objName.size() > max_obj_len) {
  2161. // The current object file name is too long. Try to shorten it.
  2162. return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
  2163. } else {
  2164. // The object file name is short enough.
  2165. return true;
  2166. }
  2167. } else {
  2168. // The build directory in which the object will be stored is
  2169. // already too deep.
  2170. return false;
  2171. }
  2172. }
  2173. #endif
  2174. std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName(
  2175. const std::string& sin, std::string const& dir_max)
  2176. {
  2177. // Look for an existing mapped name for this object file.
  2178. std::map<std::string, std::string>::iterator it =
  2179. this->UniqueObjectNamesMap.find(sin);
  2180. // If no entry exists create one.
  2181. if (it == this->UniqueObjectNamesMap.end()) {
  2182. // Start with the original name.
  2183. std::string ssin = sin;
  2184. // Avoid full paths by removing leading slashes.
  2185. ssin.erase(0, ssin.find_first_not_of('/'));
  2186. // Avoid full paths by removing colons.
  2187. std::replace(ssin.begin(), ssin.end(), ':', '_');
  2188. // Avoid relative paths that go up the tree.
  2189. cmSystemTools::ReplaceString(ssin, "../", "__/");
  2190. // Avoid spaces.
  2191. std::replace(ssin.begin(), ssin.end(), ' ', '_');
  2192. // Mangle the name if necessary.
  2193. if (this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES")) {
  2194. bool done;
  2195. int cc = 0;
  2196. char rpstr[100];
  2197. sprintf(rpstr, "_p_");
  2198. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2199. std::string sssin = sin;
  2200. do {
  2201. done = true;
  2202. for (it = this->UniqueObjectNamesMap.begin();
  2203. it != this->UniqueObjectNamesMap.end(); ++it) {
  2204. if (it->second == ssin) {
  2205. done = false;
  2206. }
  2207. }
  2208. if (done) {
  2209. break;
  2210. }
  2211. sssin = ssin;
  2212. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2213. sprintf(rpstr, "_p%d_", cc++);
  2214. } while (!done);
  2215. }
  2216. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2217. if (!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
  2218. this->ObjectPathMax)) {
  2219. // Warn if this is the first time the path has been seen.
  2220. if (this->ObjectMaxPathViolations.insert(dir_max).second) {
  2221. std::ostringstream m;
  2222. /* clang-format off */
  2223. m << "The object file directory\n"
  2224. << " " << dir_max << "\n"
  2225. << "has " << dir_max.size() << " characters. "
  2226. << "The maximum full path to an object file is "
  2227. << this->ObjectPathMax << " characters "
  2228. << "(see CMAKE_OBJECT_PATH_MAX). "
  2229. << "Object file\n"
  2230. << " " << ssin << "\n"
  2231. << "cannot be safely placed under this directory. "
  2232. << "The build may not work correctly.";
  2233. /* clang-format on */
  2234. this->IssueMessage(cmake::WARNING, m.str());
  2235. }
  2236. }
  2237. #else
  2238. (void)dir_max;
  2239. #endif
  2240. // Insert the newly mapped object file name.
  2241. std::map<std::string, std::string>::value_type e(sin, ssin);
  2242. it = this->UniqueObjectNamesMap.insert(e).first;
  2243. }
  2244. // Return the map entry.
  2245. return it->second;
  2246. }
  2247. void cmLocalGenerator::ComputeObjectFilenames(
  2248. std::map<cmSourceFile const*, std::string>&, cmGeneratorTarget const*)
  2249. {
  2250. }
  2251. bool cmLocalGenerator::IsWindowsShell() const
  2252. {
  2253. return this->GetState()->UseWindowsShell();
  2254. }
  2255. bool cmLocalGenerator::IsWatcomWMake() const
  2256. {
  2257. return this->GetState()->UseWatcomWMake();
  2258. }
  2259. bool cmLocalGenerator::IsMinGWMake() const
  2260. {
  2261. return this->GetState()->UseMinGWMake();
  2262. }
  2263. bool cmLocalGenerator::IsNMake() const
  2264. {
  2265. return this->GetState()->UseNMake();
  2266. }
  2267. std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
  2268. const cmSourceFile& source, std::string const& dir_max,
  2269. bool* hasSourceExtension)
  2270. {
  2271. // Construct the object file name using the full path to the source
  2272. // file which is its only unique identification.
  2273. const char* fullPath = source.GetFullPath().c_str();
  2274. // Try referencing the source relative to the source tree.
  2275. std::string relFromSource = this->Convert(fullPath, START);
  2276. assert(!relFromSource.empty());
  2277. bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
  2278. bool subSource = relSource && relFromSource[0] != '.';
  2279. // Try referencing the source relative to the binary tree.
  2280. std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
  2281. assert(!relFromBinary.empty());
  2282. bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
  2283. bool subBinary = relBinary && relFromBinary[0] != '.';
  2284. // Select a nice-looking reference to the source file to construct
  2285. // the object file name.
  2286. std::string objectName;
  2287. if ((relSource && !relBinary) || (subSource && !subBinary)) {
  2288. objectName = relFromSource;
  2289. } else if ((relBinary && !relSource) || (subBinary && !subSource)) {
  2290. objectName = relFromBinary;
  2291. } else if (relFromBinary.length() < relFromSource.length()) {
  2292. objectName = relFromBinary;
  2293. } else {
  2294. objectName = relFromSource;
  2295. }
  2296. // if it is still a full path check for the try compile case
  2297. // try compile never have in source sources, and should not
  2298. // have conflicting source file names in the same target
  2299. if (cmSystemTools::FileIsFullPath(objectName.c_str())) {
  2300. if (this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile()) {
  2301. objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
  2302. }
  2303. }
  2304. // Replace the original source file extension with the object file
  2305. // extension.
  2306. bool keptSourceExtension = true;
  2307. if (!source.GetPropertyAsBool("KEEP_EXTENSION")) {
  2308. // Decide whether this language wants to replace the source
  2309. // extension with the object extension. For CMake 2.4
  2310. // compatibility do this by default.
  2311. bool replaceExt = this->NeedBackwardsCompatibility_2_4();
  2312. if (!replaceExt) {
  2313. std::string lang = source.GetLanguage();
  2314. if (!lang.empty()) {
  2315. std::string repVar = "CMAKE_";
  2316. repVar += lang;
  2317. repVar += "_OUTPUT_EXTENSION_REPLACE";
  2318. replaceExt = this->Makefile->IsOn(repVar);
  2319. }
  2320. }
  2321. // Remove the source extension if it is to be replaced.
  2322. if (replaceExt) {
  2323. keptSourceExtension = false;
  2324. std::string::size_type dot_pos = objectName.rfind('.');
  2325. if (dot_pos != std::string::npos) {
  2326. objectName = objectName.substr(0, dot_pos);
  2327. }
  2328. }
  2329. // Store the new extension.
  2330. objectName += this->GlobalGenerator->GetLanguageOutputExtension(source);
  2331. }
  2332. if (hasSourceExtension) {
  2333. *hasSourceExtension = keptSourceExtension;
  2334. }
  2335. // Convert to a safe name.
  2336. return this->CreateSafeUniqueObjectFileName(objectName, dir_max);
  2337. }
  2338. std::string cmLocalGenerator::GetSourceFileLanguage(const cmSourceFile& source)
  2339. {
  2340. return source.GetLanguage();
  2341. }
  2342. cmake* cmLocalGenerator::GetCMakeInstance() const
  2343. {
  2344. return this->GlobalGenerator->GetCMakeInstance();
  2345. }
  2346. const char* cmLocalGenerator::GetSourceDirectory() const
  2347. {
  2348. return this->GetCMakeInstance()->GetHomeDirectory();
  2349. }
  2350. const char* cmLocalGenerator::GetBinaryDirectory() const
  2351. {
  2352. return this->GetCMakeInstance()->GetHomeOutputDirectory();
  2353. }
  2354. const char* cmLocalGenerator::GetCurrentBinaryDirectory() const
  2355. {
  2356. return this->StateSnapshot.GetDirectory().GetCurrentBinary();
  2357. }
  2358. const char* cmLocalGenerator::GetCurrentSourceDirectory() const
  2359. {
  2360. return this->StateSnapshot.GetDirectory().GetCurrentSource();
  2361. }
  2362. std::string cmLocalGenerator::GetTargetDirectory(
  2363. const cmGeneratorTarget*) const
  2364. {
  2365. cmSystemTools::Error("GetTargetDirectory"
  2366. " called on cmLocalGenerator");
  2367. return "";
  2368. }
  2369. KWIML_INT_uint64_t cmLocalGenerator::GetBackwardsCompatibility()
  2370. {
  2371. // The computed version may change until the project is fully
  2372. // configured.
  2373. if (!this->BackwardsCompatibilityFinal) {
  2374. unsigned int major = 0;
  2375. unsigned int minor = 0;
  2376. unsigned int patch = 0;
  2377. if (const char* value =
  2378. this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY")) {
  2379. switch (sscanf(value, "%u.%u.%u", &major, &minor, &patch)) {
  2380. case 2:
  2381. patch = 0;
  2382. break;
  2383. case 1:
  2384. minor = 0;
  2385. patch = 0;
  2386. break;
  2387. default:
  2388. break;
  2389. }
  2390. }
  2391. this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
  2392. this->BackwardsCompatibilityFinal = true;
  2393. }
  2394. return this->BackwardsCompatibility;
  2395. }
  2396. bool cmLocalGenerator::NeedBackwardsCompatibility_2_4()
  2397. {
  2398. // Check the policy to decide whether to pay attention to this
  2399. // variable.
  2400. switch (this->GetPolicyStatus(cmPolicies::CMP0001)) {
  2401. case cmPolicies::WARN:
  2402. // WARN is just OLD without warning because user code does not
  2403. // always affect whether this check is done.
  2404. case cmPolicies::OLD:
  2405. // Old behavior is to check the variable.
  2406. break;
  2407. case cmPolicies::NEW:
  2408. // New behavior is to ignore the variable.
  2409. return false;
  2410. case cmPolicies::REQUIRED_IF_USED:
  2411. case cmPolicies::REQUIRED_ALWAYS:
  2412. // This will never be the case because the only way to require
  2413. // the setting is to require the user to specify version policy
  2414. // 2.6 or higher. Once we add that requirement then this whole
  2415. // method can be removed anyway.
  2416. return false;
  2417. }
  2418. // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
  2419. // equal to or lower than the given version.
  2420. KWIML_INT_uint64_t actual_compat = this->GetBackwardsCompatibility();
  2421. return (actual_compat && actual_compat <= CMake_VERSION_ENCODE(2, 4, 255));
  2422. }
  2423. cmPolicies::PolicyStatus cmLocalGenerator::GetPolicyStatus(
  2424. cmPolicies::PolicyID id) const
  2425. {
  2426. return this->Makefile->GetPolicyStatus(id);
  2427. }
  2428. bool cmLocalGenerator::CheckDefinition(std::string const& define) const
  2429. {
  2430. // Many compilers do not support -DNAME(arg)=sdf so we disable it.
  2431. std::string::size_type pos = define.find_first_of("(=");
  2432. if (pos != std::string::npos) {
  2433. if (define[pos] == '(') {
  2434. std::ostringstream e;
  2435. /* clang-format off */
  2436. e << "WARNING: Function-style preprocessor definitions may not be "
  2437. << "passed on the compiler command line because many compilers "
  2438. << "do not support it.\n"
  2439. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2440. << "Consider defining the macro in a (configured) header file.\n";
  2441. /* clang-format on */
  2442. cmSystemTools::Message(e.str().c_str());
  2443. return false;
  2444. }
  2445. }
  2446. // Many compilers do not support # in the value so we disable it.
  2447. if (define.find_first_of('#') != define.npos) {
  2448. std::ostringstream e;
  2449. /* clang-format off */
  2450. e << "WARNING: Preprocessor definitions containing '#' may not be "
  2451. << "passed on the compiler command line because many compilers "
  2452. << "do not support it.\n"
  2453. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2454. << "Consider defining the macro in a (configured) header file.\n";
  2455. /* clang-format on */
  2456. cmSystemTools::Message(e.str().c_str());
  2457. return false;
  2458. }
  2459. // Assume it is supported.
  2460. return true;
  2461. }
  2462. static void cmLGInfoProp(cmMakefile* mf, cmGeneratorTarget* target,
  2463. const std::string& prop)
  2464. {
  2465. if (const char* val = target->GetProperty(prop)) {
  2466. mf->AddDefinition(prop, val);
  2467. }
  2468. }
  2469. void cmLocalGenerator::GenerateAppleInfoPList(cmGeneratorTarget* target,
  2470. const std::string& targetName,
  2471. const char* fname)
  2472. {
  2473. // Find the Info.plist template.
  2474. const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
  2475. std::string inFile = (in && *in) ? in : "MacOSXBundleInfo.plist.in";
  2476. if (!cmSystemTools::FileIsFullPath(inFile.c_str())) {
  2477. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2478. if (!inMod.empty()) {
  2479. inFile = inMod;
  2480. }
  2481. }
  2482. if (!cmSystemTools::FileExists(inFile.c_str(), true)) {
  2483. std::ostringstream e;
  2484. e << "Target " << target->GetName() << " Info.plist template \"" << inFile
  2485. << "\" could not be found.";
  2486. cmSystemTools::Error(e.str().c_str());
  2487. return;
  2488. }
  2489. // Convert target properties to variables in an isolated makefile
  2490. // scope to configure the file. If properties are set they will
  2491. // override user make variables. If not the configuration will fall
  2492. // back to the directory-level values set by the user.
  2493. cmMakefile* mf = this->Makefile;
  2494. cmMakefile::ScopePushPop varScope(mf);
  2495. mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName.c_str());
  2496. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
  2497. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
  2498. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
  2499. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
  2500. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
  2501. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
  2502. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
  2503. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
  2504. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2505. }
  2506. void cmLocalGenerator::GenerateFrameworkInfoPList(
  2507. cmGeneratorTarget* target, const std::string& targetName, const char* fname)
  2508. {
  2509. // Find the Info.plist template.
  2510. const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
  2511. std::string inFile = (in && *in) ? in : "MacOSXFrameworkInfo.plist.in";
  2512. if (!cmSystemTools::FileIsFullPath(inFile.c_str())) {
  2513. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2514. if (!inMod.empty()) {
  2515. inFile = inMod;
  2516. }
  2517. }
  2518. if (!cmSystemTools::FileExists(inFile.c_str(), true)) {
  2519. std::ostringstream e;
  2520. e << "Target " << target->GetName() << " Info.plist template \"" << inFile
  2521. << "\" could not be found.";
  2522. cmSystemTools::Error(e.str().c_str());
  2523. return;
  2524. }
  2525. // Convert target properties to variables in an isolated makefile
  2526. // scope to configure the file. If properties are set they will
  2527. // override user make variables. If not the configuration will fall
  2528. // back to the directory-level values set by the user.
  2529. cmMakefile* mf = this->Makefile;
  2530. cmMakefile::ScopePushPop varScope(mf);
  2531. mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName.c_str());
  2532. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
  2533. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
  2534. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
  2535. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
  2536. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2537. }