cmLocalGenerator.cxx 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797
  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", CM_NULLPTR };
  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 CM_NULLPTR;
  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. CM_NULLPTR
  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. }
  575. return "0";
  576. }
  577. if (variable == "TARGET_VERSION_MINOR") {
  578. if (replaceValues.TargetVersionMinor) {
  579. return replaceValues.TargetVersionMinor;
  580. }
  581. return "0";
  582. }
  583. if (replaceValues.Target) {
  584. if (variable == "TARGET_BASE") {
  585. // Strip the last extension off the target name.
  586. std::string targetBase = replaceValues.Target;
  587. std::string::size_type pos = targetBase.rfind('.');
  588. if (pos != targetBase.npos) {
  589. return targetBase.substr(0, pos);
  590. }
  591. return targetBase;
  592. }
  593. }
  594. }
  595. if (variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
  596. variable == "TARGET_INSTALLNAME_DIR") {
  597. // All these variables depend on TargetSOName
  598. if (replaceValues.TargetSOName) {
  599. if (variable == "TARGET_SONAME") {
  600. return replaceValues.TargetSOName;
  601. }
  602. if (variable == "SONAME_FLAG" && replaceValues.SONameFlag) {
  603. return replaceValues.SONameFlag;
  604. }
  605. if (replaceValues.TargetInstallNameDir &&
  606. variable == "TARGET_INSTALLNAME_DIR") {
  607. return replaceValues.TargetInstallNameDir;
  608. }
  609. }
  610. return "";
  611. }
  612. if (replaceValues.LinkLibraries) {
  613. if (variable == "LINK_LIBRARIES") {
  614. return replaceValues.LinkLibraries;
  615. }
  616. }
  617. if (replaceValues.Language) {
  618. if (variable == "LANGUAGE") {
  619. return replaceValues.Language;
  620. }
  621. }
  622. if (replaceValues.CMTarget) {
  623. if (variable == "TARGET_NAME") {
  624. return replaceValues.CMTarget->GetName();
  625. }
  626. if (variable == "TARGET_TYPE") {
  627. return cmState::GetTargetTypeName(replaceValues.CMTarget->GetType());
  628. }
  629. }
  630. if (replaceValues.Output) {
  631. if (variable == "OUTPUT") {
  632. return replaceValues.Output;
  633. }
  634. }
  635. if (variable == "CMAKE_COMMAND") {
  636. return this->Convert(cmSystemTools::GetCMakeCommand(), FULL, SHELL);
  637. }
  638. std::vector<std::string> enabledLanguages =
  639. this->GetState()->GetEnabledLanguages();
  640. // loop over language specific replace variables
  641. int pos = 0;
  642. while (ruleReplaceVars[pos]) {
  643. for (std::vector<std::string>::iterator i = enabledLanguages.begin();
  644. i != enabledLanguages.end(); ++i) {
  645. const char* lang = i->c_str();
  646. std::string actualReplace = ruleReplaceVars[pos];
  647. // If this is the compiler then look for the extra variable
  648. // _COMPILER_ARG1 which must be the first argument to the compiler
  649. const char* compilerArg1 = CM_NULLPTR;
  650. const char* compilerTarget = CM_NULLPTR;
  651. const char* compilerOptionTarget = CM_NULLPTR;
  652. const char* compilerExternalToolchain = CM_NULLPTR;
  653. const char* compilerOptionExternalToolchain = CM_NULLPTR;
  654. const char* compilerSysroot = CM_NULLPTR;
  655. const char* compilerOptionSysroot = CM_NULLPTR;
  656. if (actualReplace == "CMAKE_${LANG}_COMPILER") {
  657. std::string arg1 = actualReplace + "_ARG1";
  658. cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
  659. compilerArg1 = this->Makefile->GetDefinition(arg1);
  660. compilerTarget = this->Makefile->GetDefinition(
  661. std::string("CMAKE_") + lang + "_COMPILER_TARGET");
  662. compilerOptionTarget = this->Makefile->GetDefinition(
  663. std::string("CMAKE_") + lang + "_COMPILE_OPTIONS_TARGET");
  664. compilerExternalToolchain = this->Makefile->GetDefinition(
  665. std::string("CMAKE_") + lang + "_COMPILER_EXTERNAL_TOOLCHAIN");
  666. compilerOptionExternalToolchain =
  667. this->Makefile->GetDefinition(std::string("CMAKE_") + lang +
  668. "_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN");
  669. compilerSysroot = this->Makefile->GetDefinition("CMAKE_SYSROOT");
  670. compilerOptionSysroot = this->Makefile->GetDefinition(
  671. std::string("CMAKE_") + lang + "_COMPILE_OPTIONS_SYSROOT");
  672. }
  673. if (actualReplace.find("${LANG}") != actualReplace.npos) {
  674. cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
  675. }
  676. if (actualReplace == variable) {
  677. std::string replace = this->Makefile->GetSafeDefinition(variable);
  678. // if the variable is not a FLAG then treat it like a path
  679. if (variable.find("_FLAG") == variable.npos) {
  680. std::string ret = this->ConvertToOutputForExisting(replace);
  681. // if there is a required first argument to the compiler add it
  682. // to the compiler string
  683. if (compilerArg1) {
  684. ret += " ";
  685. ret += compilerArg1;
  686. }
  687. if (compilerTarget && compilerOptionTarget) {
  688. ret += " ";
  689. ret += compilerOptionTarget;
  690. ret += compilerTarget;
  691. }
  692. if (compilerExternalToolchain && compilerOptionExternalToolchain) {
  693. ret += " ";
  694. ret += compilerOptionExternalToolchain;
  695. ret += this->EscapeForShell(compilerExternalToolchain, true);
  696. }
  697. if (compilerSysroot && compilerOptionSysroot) {
  698. ret += " ";
  699. ret += compilerOptionSysroot;
  700. ret += this->EscapeForShell(compilerSysroot, true);
  701. }
  702. return ret;
  703. }
  704. return replace;
  705. }
  706. }
  707. pos++;
  708. }
  709. return variable;
  710. }
  711. void cmLocalGenerator::ExpandRuleVariables(std::string& s,
  712. const RuleVariables& replaceValues)
  713. {
  714. if (replaceValues.RuleLauncher) {
  715. this->InsertRuleLauncher(s, replaceValues.CMTarget,
  716. replaceValues.RuleLauncher);
  717. }
  718. std::string::size_type start = s.find('<');
  719. // no variables to expand
  720. if (start == s.npos) {
  721. return;
  722. }
  723. std::string::size_type pos = 0;
  724. std::string expandedInput;
  725. while (start != s.npos && start < s.size() - 2) {
  726. std::string::size_type end = s.find('>', start);
  727. // if we find a < with no > we are done
  728. if (end == s.npos) {
  729. return;
  730. }
  731. char c = s[start + 1];
  732. // if the next char after the < is not A-Za-z then
  733. // skip it and try to find the next < in the string
  734. if (!isalpha(c)) {
  735. start = s.find('<', start + 1);
  736. } else {
  737. // extract the var
  738. std::string var = s.substr(start + 1, end - start - 1);
  739. std::string replace = this->ExpandRuleVariable(var, replaceValues);
  740. expandedInput += s.substr(pos, start - pos);
  741. expandedInput += replace;
  742. // move to next one
  743. start = s.find('<', start + var.size() + 2);
  744. pos = end + 1;
  745. }
  746. }
  747. // add the rest of the input
  748. expandedInput += s.substr(pos, s.size() - pos);
  749. s = expandedInput;
  750. }
  751. const char* cmLocalGenerator::GetRuleLauncher(cmGeneratorTarget* target,
  752. const std::string& prop)
  753. {
  754. if (target) {
  755. return target->GetProperty(prop);
  756. }
  757. return this->Makefile->GetProperty(prop);
  758. }
  759. void cmLocalGenerator::InsertRuleLauncher(std::string& s,
  760. cmGeneratorTarget* target,
  761. const std::string& prop)
  762. {
  763. if (const char* val = this->GetRuleLauncher(target, prop)) {
  764. std::ostringstream wrapped;
  765. wrapped << val << " " << s;
  766. s = wrapped.str();
  767. }
  768. }
  769. std::string cmLocalGenerator::ConvertToIncludeReference(
  770. std::string const& path, OutputFormat format, bool forceFullPaths)
  771. {
  772. static_cast<void>(forceFullPaths);
  773. return this->ConvertToOutputForExisting(path, format);
  774. }
  775. std::string cmLocalGenerator::GetIncludeFlags(
  776. const std::vector<std::string>& includes, cmGeneratorTarget* target,
  777. const std::string& lang, bool forceFullPaths, bool forResponseFile,
  778. const std::string& config)
  779. {
  780. if (lang.empty()) {
  781. return "";
  782. }
  783. OutputFormat shellFormat = forResponseFile ? RESPONSE : SHELL;
  784. std::ostringstream includeFlags;
  785. std::string flagVar = "CMAKE_INCLUDE_FLAG_";
  786. flagVar += lang;
  787. const char* includeFlag = this->Makefile->GetSafeDefinition(flagVar);
  788. flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
  789. flagVar += lang;
  790. const char* sep = this->Makefile->GetDefinition(flagVar);
  791. bool quotePaths = false;
  792. if (this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS")) {
  793. quotePaths = true;
  794. }
  795. bool repeatFlag = true;
  796. // should the include flag be repeated like ie. -IA -IB
  797. if (!sep) {
  798. sep = " ";
  799. } else {
  800. // if there is a separator then the flag is not repeated but is only
  801. // given once i.e. -classpath a:b:c
  802. repeatFlag = false;
  803. }
  804. // Support special system include flag if it is available and the
  805. // normal flag is repeated for each directory.
  806. std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
  807. sysFlagVar += lang;
  808. const char* sysIncludeFlag = CM_NULLPTR;
  809. if (repeatFlag) {
  810. sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar);
  811. }
  812. std::string fwSearchFlagVar = "CMAKE_";
  813. fwSearchFlagVar += lang;
  814. fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
  815. const char* fwSearchFlag = this->Makefile->GetDefinition(fwSearchFlagVar);
  816. std::string sysFwSearchFlagVar = "CMAKE_";
  817. sysFwSearchFlagVar += lang;
  818. sysFwSearchFlagVar += "_SYSTEM_FRAMEWORK_SEARCH_FLAG";
  819. const char* sysFwSearchFlag =
  820. this->Makefile->GetDefinition(sysFwSearchFlagVar);
  821. bool flagUsed = false;
  822. std::set<std::string> emitted;
  823. #ifdef __APPLE__
  824. emitted.insert("/System/Library/Frameworks");
  825. #endif
  826. std::vector<std::string>::const_iterator i;
  827. for (i = includes.begin(); i != includes.end(); ++i) {
  828. if (fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE") &&
  829. cmSystemTools::IsPathToFramework(i->c_str())) {
  830. std::string frameworkDir = *i;
  831. frameworkDir += "/../";
  832. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
  833. if (emitted.insert(frameworkDir).second) {
  834. if (sysFwSearchFlag && target &&
  835. target->IsSystemIncludeDirectory(*i, config)) {
  836. includeFlags << sysFwSearchFlag;
  837. } else {
  838. includeFlags << fwSearchFlag;
  839. }
  840. includeFlags << this->ConvertToOutputFormat(frameworkDir, shellFormat)
  841. << " ";
  842. }
  843. continue;
  844. }
  845. if (!flagUsed || repeatFlag) {
  846. if (sysIncludeFlag && target &&
  847. target->IsSystemIncludeDirectory(*i, config)) {
  848. includeFlags << sysIncludeFlag;
  849. } else {
  850. includeFlags << includeFlag;
  851. }
  852. flagUsed = true;
  853. }
  854. std::string includePath =
  855. this->ConvertToIncludeReference(*i, shellFormat, forceFullPaths);
  856. if (quotePaths && !includePath.empty() && includePath[0] != '\"') {
  857. includeFlags << "\"";
  858. }
  859. includeFlags << includePath;
  860. if (quotePaths && !includePath.empty() && includePath[0] != '\"') {
  861. includeFlags << "\"";
  862. }
  863. includeFlags << sep;
  864. }
  865. std::string flags = includeFlags.str();
  866. // remove trailing separators
  867. if ((sep[0] != ' ') && !flags.empty() && flags[flags.size() - 1] == sep[0]) {
  868. flags[flags.size() - 1] = ' ';
  869. }
  870. return flags;
  871. }
  872. void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
  873. cmGeneratorTarget const* target,
  874. const std::string& config,
  875. const std::string& lang) const
  876. {
  877. std::vector<std::string> targetDefines;
  878. target->GetCompileDefinitions(targetDefines, config, lang);
  879. this->AppendDefines(defines, targetDefines);
  880. }
  881. void cmLocalGenerator::AddCompileOptions(std::string& flags,
  882. cmGeneratorTarget* target,
  883. const std::string& lang,
  884. const std::string& config)
  885. {
  886. std::string langFlagRegexVar = std::string("CMAKE_") + lang + "_FLAG_REGEX";
  887. if (const char* langFlagRegexStr =
  888. this->Makefile->GetDefinition(langFlagRegexVar)) {
  889. // Filter flags acceptable to this language.
  890. cmsys::RegularExpression r(langFlagRegexStr);
  891. std::vector<std::string> opts;
  892. if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) {
  893. cmSystemTools::ParseWindowsCommandLine(targetFlags, opts);
  894. }
  895. target->GetCompileOptions(opts, config, lang);
  896. for (std::vector<std::string>::const_iterator i = opts.begin();
  897. i != opts.end(); ++i) {
  898. if (r.find(i->c_str())) {
  899. // (Re-)Escape this flag. COMPILE_FLAGS were already parsed
  900. // as a command line above, and COMPILE_OPTIONS are escaped.
  901. this->AppendFlagEscape(flags, *i);
  902. }
  903. }
  904. } else {
  905. // Use all flags.
  906. if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) {
  907. // COMPILE_FLAGS are not escaped for historical reasons.
  908. this->AppendFlags(flags, targetFlags);
  909. }
  910. std::vector<std::string> opts;
  911. target->GetCompileOptions(opts, config, lang);
  912. for (std::vector<std::string>::const_iterator i = opts.begin();
  913. i != opts.end(); ++i) {
  914. // COMPILE_OPTIONS are escaped.
  915. this->AppendFlagEscape(flags, *i);
  916. }
  917. }
  918. std::vector<std::string> features;
  919. target->GetCompileFeatures(features, config);
  920. for (std::vector<std::string>::const_iterator it = features.begin();
  921. it != features.end(); ++it) {
  922. if (!this->Makefile->AddRequiredTargetFeature(target->Target, *it)) {
  923. return;
  924. }
  925. }
  926. for (std::map<std::string, std::string>::const_iterator it =
  927. target->GetMaxLanguageStandards().begin();
  928. it != target->GetMaxLanguageStandards().end(); ++it) {
  929. const char* standard = target->GetProperty(it->first + "_STANDARD");
  930. if (!standard) {
  931. continue;
  932. }
  933. if (this->Makefile->IsLaterStandard(it->first, standard, it->second)) {
  934. std::ostringstream e;
  935. e << "The COMPILE_FEATURES property of target \"" << target->GetName()
  936. << "\" was evaluated when computing the link "
  937. "implementation, and the \""
  938. << it->first << "_STANDARD\" was \"" << it->second
  939. << "\" for that computation. Computing the "
  940. "COMPILE_FEATURES based on the link implementation resulted in a "
  941. "higher \""
  942. << it->first << "_STANDARD\" \"" << standard
  943. << "\". "
  944. "This is not permitted. The COMPILE_FEATURES may not both depend "
  945. "on "
  946. "and be depended on by the link implementation."
  947. << std::endl;
  948. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  949. return;
  950. }
  951. }
  952. this->AddCompilerRequirementFlag(flags, target, lang);
  953. }
  954. void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
  955. cmGeneratorTarget const* target,
  956. const std::string& lang,
  957. const std::string& config,
  958. bool stripImplicitInclDirs) const
  959. {
  960. // Need to decide whether to automatically include the source and
  961. // binary directories at the beginning of the include path.
  962. bool includeSourceDir = false;
  963. bool includeBinaryDir = false;
  964. // When automatic include directories are requested for a build then
  965. // include the source and binary directories at the beginning of the
  966. // include path to approximate include file behavior for an
  967. // in-source build. This does not account for the case of a source
  968. // file in a subdirectory of the current source directory but we
  969. // cannot fix this because not all native build tools support
  970. // per-source-file include paths.
  971. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR")) {
  972. includeSourceDir = true;
  973. includeBinaryDir = true;
  974. }
  975. // Do not repeat an include path.
  976. std::set<std::string> emitted;
  977. // Store the automatic include paths.
  978. if (includeBinaryDir) {
  979. std::string binDir = this->StateSnapshot.GetDirectory().GetCurrentBinary();
  980. if (emitted.find(binDir) == emitted.end()) {
  981. dirs.push_back(binDir);
  982. emitted.insert(binDir);
  983. }
  984. }
  985. if (includeSourceDir) {
  986. std::string srcDir = this->StateSnapshot.GetDirectory().GetCurrentSource();
  987. if (emitted.find(srcDir) == emitted.end()) {
  988. dirs.push_back(srcDir);
  989. emitted.insert(srcDir);
  990. }
  991. }
  992. if (!target) {
  993. return;
  994. }
  995. std::string rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
  996. std::vector<std::string> implicitDirs;
  997. // Load implicit include directories for this language.
  998. std::string impDirVar = "CMAKE_";
  999. impDirVar += lang;
  1000. impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
  1001. if (const char* value = this->Makefile->GetDefinition(impDirVar)) {
  1002. std::vector<std::string> impDirVec;
  1003. cmSystemTools::ExpandListArgument(value, impDirVec);
  1004. for (std::vector<std::string>::const_iterator i = impDirVec.begin();
  1005. i != impDirVec.end(); ++i) {
  1006. std::string d = rootPath + *i;
  1007. cmSystemTools::ConvertToUnixSlashes(d);
  1008. emitted.insert(d);
  1009. if (!stripImplicitInclDirs) {
  1010. implicitDirs.push_back(*i);
  1011. }
  1012. }
  1013. }
  1014. // Get the target-specific include directories.
  1015. std::vector<std::string> includes;
  1016. includes = target->GetIncludeDirectories(config, lang);
  1017. // Support putting all the in-project include directories first if
  1018. // it is requested by the project.
  1019. if (this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE")) {
  1020. const char* topSourceDir = this->GetState()->GetSourceDirectory();
  1021. const char* topBinaryDir = this->GetState()->GetBinaryDirectory();
  1022. for (std::vector<std::string>::const_iterator i = includes.begin();
  1023. i != includes.end(); ++i) {
  1024. // Emit this directory only if it is a subdirectory of the
  1025. // top-level source or binary tree.
  1026. if (cmSystemTools::ComparePath(*i, topSourceDir) ||
  1027. cmSystemTools::ComparePath(*i, topBinaryDir) ||
  1028. cmSystemTools::IsSubDirectory(*i, topSourceDir) ||
  1029. cmSystemTools::IsSubDirectory(*i, topBinaryDir)) {
  1030. if (emitted.insert(*i).second) {
  1031. dirs.push_back(*i);
  1032. }
  1033. }
  1034. }
  1035. }
  1036. // Construct the final ordered include directory list.
  1037. for (std::vector<std::string>::const_iterator i = includes.begin();
  1038. i != includes.end(); ++i) {
  1039. if (emitted.insert(*i).second) {
  1040. dirs.push_back(*i);
  1041. }
  1042. }
  1043. for (std::vector<std::string>::const_iterator i = implicitDirs.begin();
  1044. i != implicitDirs.end(); ++i) {
  1045. if (std::find(includes.begin(), includes.end(), *i) != includes.end()) {
  1046. dirs.push_back(*i);
  1047. }
  1048. }
  1049. }
  1050. void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
  1051. std::string const& config,
  1052. cmGeneratorTarget* target)
  1053. {
  1054. this->AppendFlags(
  1055. flags, this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS"));
  1056. if (!config.empty()) {
  1057. std::string name = "CMAKE_STATIC_LINKER_FLAGS_" + config;
  1058. this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name));
  1059. }
  1060. this->AppendFlags(flags, target->GetProperty("STATIC_LIBRARY_FLAGS"));
  1061. if (!config.empty()) {
  1062. std::string name = "STATIC_LIBRARY_FLAGS_" + config;
  1063. this->AppendFlags(flags, target->GetProperty(name));
  1064. }
  1065. }
  1066. void cmLocalGenerator::GetTargetFlags(
  1067. const std::string& config, std::string& linkLibs, std::string& flags,
  1068. std::string& linkFlags, std::string& frameworkPath, std::string& linkPath,
  1069. cmGeneratorTarget* target, bool useWatcomQuote)
  1070. {
  1071. const std::string buildType = cmSystemTools::UpperCase(config);
  1072. const char* libraryLinkVariable =
  1073. "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
  1074. switch (target->GetType()) {
  1075. case cmState::STATIC_LIBRARY:
  1076. this->GetStaticLibraryFlags(linkFlags, buildType, target);
  1077. break;
  1078. case cmState::MODULE_LIBRARY:
  1079. libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
  1080. case cmState::SHARED_LIBRARY: {
  1081. linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
  1082. linkFlags += " ";
  1083. if (!buildType.empty()) {
  1084. std::string build = libraryLinkVariable;
  1085. build += "_";
  1086. build += buildType;
  1087. linkFlags += this->Makefile->GetSafeDefinition(build);
  1088. linkFlags += " ";
  1089. }
  1090. if (this->Makefile->IsOn("WIN32") &&
  1091. !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW"))) {
  1092. std::vector<cmSourceFile*> sources;
  1093. target->GetSourceFiles(sources, buildType);
  1094. for (std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1095. i != sources.end(); ++i) {
  1096. cmSourceFile* sf = *i;
  1097. if (sf->GetExtension() == "def") {
  1098. linkFlags +=
  1099. this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1100. linkFlags += this->Convert(sf->GetFullPath(), FULL, SHELL);
  1101. linkFlags += " ";
  1102. }
  1103. }
  1104. }
  1105. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  1106. if (targetLinkFlags) {
  1107. linkFlags += targetLinkFlags;
  1108. linkFlags += " ";
  1109. }
  1110. if (!buildType.empty()) {
  1111. std::string configLinkFlags = "LINK_FLAGS_";
  1112. configLinkFlags += buildType;
  1113. targetLinkFlags = target->GetProperty(configLinkFlags);
  1114. if (targetLinkFlags) {
  1115. linkFlags += targetLinkFlags;
  1116. linkFlags += " ";
  1117. }
  1118. }
  1119. this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath, *target,
  1120. false, false, useWatcomQuote);
  1121. } break;
  1122. case cmState::EXECUTABLE: {
  1123. linkFlags += this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1124. linkFlags += " ";
  1125. if (!buildType.empty()) {
  1126. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1127. build += buildType;
  1128. linkFlags += this->Makefile->GetSafeDefinition(build);
  1129. linkFlags += " ";
  1130. }
  1131. std::string linkLanguage = target->GetLinkerLanguage(buildType);
  1132. if (linkLanguage.empty()) {
  1133. cmSystemTools::Error(
  1134. "CMake can not determine linker language for target: ",
  1135. target->GetName().c_str());
  1136. return;
  1137. }
  1138. this->AddLanguageFlags(flags, linkLanguage, buildType);
  1139. this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath, *target,
  1140. false, false, useWatcomQuote);
  1141. if (cmSystemTools::IsOn(
  1142. this->Makefile->GetDefinition("BUILD_SHARED_LIBS"))) {
  1143. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") +
  1144. linkLanguage + std::string("_FLAGS");
  1145. linkFlags += this->Makefile->GetSafeDefinition(sFlagVar);
  1146. linkFlags += " ";
  1147. }
  1148. if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) {
  1149. linkFlags +=
  1150. this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1151. linkFlags += " ";
  1152. } else {
  1153. linkFlags +=
  1154. this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1155. linkFlags += " ";
  1156. }
  1157. if (target->IsExecutableWithExports()) {
  1158. std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
  1159. exportFlagVar += linkLanguage;
  1160. exportFlagVar += "_FLAG";
  1161. linkFlags += this->Makefile->GetSafeDefinition(exportFlagVar);
  1162. linkFlags += " ";
  1163. }
  1164. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  1165. if (targetLinkFlags) {
  1166. linkFlags += targetLinkFlags;
  1167. linkFlags += " ";
  1168. }
  1169. if (!buildType.empty()) {
  1170. std::string configLinkFlags = "LINK_FLAGS_";
  1171. configLinkFlags += buildType;
  1172. targetLinkFlags = target->GetProperty(configLinkFlags);
  1173. if (targetLinkFlags) {
  1174. linkFlags += targetLinkFlags;
  1175. linkFlags += " ";
  1176. }
  1177. }
  1178. } break;
  1179. default:
  1180. break;
  1181. }
  1182. }
  1183. void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target,
  1184. std::string const& config,
  1185. std::string const& lang,
  1186. std::string& flags)
  1187. {
  1188. cmMakefile* mf = this->GetMakefile();
  1189. // Add language-specific flags.
  1190. this->AddLanguageFlags(flags, lang, config);
  1191. if (target->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION", config)) {
  1192. this->AppendFeatureOptions(flags, lang, "IPO");
  1193. }
  1194. this->AddArchitectureFlags(flags, target, lang, config);
  1195. if (lang == "Fortran") {
  1196. this->AppendFlags(flags, this->GetTargetFortranFlags(target, config));
  1197. }
  1198. this->AddCMP0018Flags(flags, target, lang, config);
  1199. this->AddVisibilityPresetFlags(flags, target, lang);
  1200. this->AppendFlags(flags, mf->GetDefineFlags());
  1201. this->AppendFlags(flags, this->GetFrameworkFlags(lang, config, target));
  1202. this->AddCompileOptions(flags, target, lang, config);
  1203. }
  1204. static std::string GetFrameworkFlags(const std::string& lang,
  1205. const std::string& config,
  1206. cmGeneratorTarget* target)
  1207. {
  1208. cmLocalGenerator* lg = target->GetLocalGenerator();
  1209. cmMakefile* mf = lg->GetMakefile();
  1210. if (!mf->IsOn("APPLE")) {
  1211. return std::string();
  1212. }
  1213. std::string fwSearchFlagVar = "CMAKE_" + lang + "_FRAMEWORK_SEARCH_FLAG";
  1214. const char* fwSearchFlag = mf->GetDefinition(fwSearchFlagVar);
  1215. if (!(fwSearchFlag && *fwSearchFlag)) {
  1216. return std::string();
  1217. }
  1218. std::set<std::string> emitted;
  1219. #ifdef __APPLE__ /* don't insert this when crosscompiling e.g. to iphone */
  1220. emitted.insert("/System/Library/Frameworks");
  1221. #endif
  1222. std::vector<std::string> includes;
  1223. lg->GetIncludeDirectories(includes, target, "C", config);
  1224. // check all include directories for frameworks as this
  1225. // will already have added a -F for the framework
  1226. for (std::vector<std::string>::iterator i = includes.begin();
  1227. i != includes.end(); ++i) {
  1228. if (lg->GetGlobalGenerator()->NameResolvesToFramework(*i)) {
  1229. std::string frameworkDir = *i;
  1230. frameworkDir += "/../";
  1231. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
  1232. emitted.insert(frameworkDir);
  1233. }
  1234. }
  1235. std::string flags;
  1236. if (cmComputeLinkInformation* cli = target->GetLinkInformation(config)) {
  1237. std::vector<std::string> const& frameworks = cli->GetFrameworkPaths();
  1238. for (std::vector<std::string>::const_iterator i = frameworks.begin();
  1239. i != frameworks.end(); ++i) {
  1240. if (emitted.insert(*i).second) {
  1241. flags += fwSearchFlag;
  1242. flags += lg->ConvertToOutputFormat(*i, cmOutputConverter::SHELL);
  1243. flags += " ";
  1244. }
  1245. }
  1246. }
  1247. return flags;
  1248. }
  1249. std::string cmLocalGenerator::GetFrameworkFlags(std::string const& l,
  1250. std::string const& config,
  1251. cmGeneratorTarget* target)
  1252. {
  1253. return ::GetFrameworkFlags(l, config, target);
  1254. }
  1255. void cmLocalGenerator::GetTargetDefines(cmGeneratorTarget const* target,
  1256. std::string const& config,
  1257. std::string const& lang,
  1258. std::set<std::string>& defines) const
  1259. {
  1260. // Add the export symbol definition for shared library objects.
  1261. if (const char* exportMacro = target->GetExportMacro()) {
  1262. this->AppendDefines(defines, exportMacro);
  1263. }
  1264. // Add preprocessor definitions for this target and configuration.
  1265. this->AddCompileDefinitions(defines, target, config, lang.c_str());
  1266. }
  1267. std::string cmLocalGenerator::GetTargetFortranFlags(
  1268. cmGeneratorTarget const* /*unused*/, std::string const& /*unused*/)
  1269. {
  1270. // Implemented by specific generators that override this.
  1271. return std::string();
  1272. }
  1273. std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib,
  1274. OutputFormat format)
  1275. {
  1276. #if defined(_WIN32) && !defined(__CYGWIN__)
  1277. // Work-ardound command line parsing limitations in MSVC 6.0
  1278. if (this->Makefile->IsOn("MSVC60")) {
  1279. // Search for the last space.
  1280. std::string::size_type pos = lib.rfind(' ');
  1281. if (pos != lib.npos) {
  1282. // Find the slash after the last space, if any.
  1283. pos = lib.find('/', pos);
  1284. // Convert the portion of the path with a space to a short path.
  1285. std::string sp;
  1286. if (cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp)) {
  1287. // Append the rest of the path with no space.
  1288. sp += lib.substr(pos);
  1289. // Convert to an output path.
  1290. return this->Convert(sp.c_str(), NONE, format);
  1291. }
  1292. }
  1293. }
  1294. #endif
  1295. // Normal behavior.
  1296. return this->Convert(lib, START_OUTPUT, format);
  1297. }
  1298. /**
  1299. * Output the linking rules on a command line. For executables,
  1300. * targetLibrary should be a NULL pointer. For libraries, it should point
  1301. * to the name of the library. This will not link a library against itself.
  1302. */
  1303. void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
  1304. std::string& frameworkPath,
  1305. std::string& linkPath,
  1306. cmGeneratorTarget& tgt, bool relink,
  1307. bool forResponseFile,
  1308. bool useWatcomQuote)
  1309. {
  1310. OutputFormat shellFormat =
  1311. (forResponseFile) ? RESPONSE : ((useWatcomQuote) ? WATCOMQUOTE : SHELL);
  1312. bool escapeAllowMakeVars = !forResponseFile;
  1313. std::ostringstream fout;
  1314. std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1315. cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config);
  1316. if (!pcli) {
  1317. return;
  1318. }
  1319. cmComputeLinkInformation& cli = *pcli;
  1320. // Collect library linking flags command line options.
  1321. std::string linkLibs;
  1322. std::string linkLanguage = cli.GetLinkLanguage();
  1323. std::string libPathFlag =
  1324. this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
  1325. std::string libPathTerminator =
  1326. this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
  1327. // Flags to link an executable to shared libraries.
  1328. if (tgt.GetType() == cmState::EXECUTABLE &&
  1329. this->StateSnapshot.GetState()->GetGlobalPropertyAsBool(
  1330. "TARGET_SUPPORTS_SHARED_LIBS")) {
  1331. bool add_shlib_flags = false;
  1332. switch (tgt.GetPolicyStatusCMP0065()) {
  1333. case cmPolicies::WARN:
  1334. if (!tgt.GetPropertyAsBool("ENABLE_EXPORTS") &&
  1335. this->Makefile->PolicyOptionalWarningEnabled(
  1336. "CMAKE_POLICY_WARNING_CMP0065")) {
  1337. std::ostringstream w;
  1338. /* clang-format off */
  1339. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0065) << "\n"
  1340. "For compatibility with older versions of CMake, "
  1341. "additional flags may be added to export symbols on all "
  1342. "executables regardless of their ENABLE_EXPORTS property.";
  1343. /* clang-format on */
  1344. this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  1345. }
  1346. case cmPolicies::OLD:
  1347. // OLD behavior is to always add the flags
  1348. add_shlib_flags = true;
  1349. break;
  1350. case cmPolicies::REQUIRED_IF_USED:
  1351. case cmPolicies::REQUIRED_ALWAYS:
  1352. this->IssueMessage(
  1353. cmake::FATAL_ERROR,
  1354. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065));
  1355. case cmPolicies::NEW:
  1356. // NEW behavior is to only add the flags if ENABLE_EXPORTS is on
  1357. add_shlib_flags = tgt.GetPropertyAsBool("ENABLE_EXPORTS");
  1358. break;
  1359. }
  1360. if (add_shlib_flags) {
  1361. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
  1362. linkFlagsVar += linkLanguage;
  1363. linkFlagsVar += "_FLAGS";
  1364. linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar);
  1365. linkLibs += " ";
  1366. }
  1367. }
  1368. // Append the framework search path flags.
  1369. std::string fwSearchFlagVar = "CMAKE_";
  1370. fwSearchFlagVar += linkLanguage;
  1371. fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
  1372. const char* fwSearchFlag = this->Makefile->GetDefinition(fwSearchFlagVar);
  1373. if (fwSearchFlag && *fwSearchFlag) {
  1374. std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
  1375. for (std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1376. fdi != fwDirs.end(); ++fdi) {
  1377. frameworkPath += fwSearchFlag;
  1378. frameworkPath += this->Convert(*fdi, NONE, shellFormat);
  1379. frameworkPath += " ";
  1380. }
  1381. }
  1382. // Append the library search path flags.
  1383. std::vector<std::string> const& libDirs = cli.GetDirectories();
  1384. for (std::vector<std::string>::const_iterator libDir = libDirs.begin();
  1385. libDir != libDirs.end(); ++libDir) {
  1386. std::string libpath =
  1387. this->ConvertToOutputForExisting(*libDir, shellFormat);
  1388. linkPath += " " + libPathFlag;
  1389. linkPath += libpath;
  1390. linkPath += libPathTerminator;
  1391. linkPath += " ";
  1392. }
  1393. // Append the link items.
  1394. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1395. ItemVector const& items = cli.GetItems();
  1396. for (ItemVector::const_iterator li = items.begin(); li != items.end();
  1397. ++li) {
  1398. if (li->Target && li->Target->GetType() == cmState::INTERFACE_LIBRARY) {
  1399. continue;
  1400. }
  1401. if (li->IsPath) {
  1402. linkLibs += this->ConvertToLinkReference(li->Value, shellFormat);
  1403. } else {
  1404. linkLibs += li->Value;
  1405. }
  1406. linkLibs += " ";
  1407. }
  1408. // Write the library flags to the build rule.
  1409. fout << linkLibs;
  1410. // Check what kind of rpath flags to use.
  1411. if (cli.GetRuntimeSep().empty()) {
  1412. // Each rpath entry gets its own option ("-R a -R b -R c")
  1413. std::vector<std::string> runtimeDirs;
  1414. cli.GetRPath(runtimeDirs, relink);
  1415. std::string rpath;
  1416. for (std::vector<std::string>::iterator ri = runtimeDirs.begin();
  1417. ri != runtimeDirs.end(); ++ri) {
  1418. rpath += cli.GetRuntimeFlag();
  1419. rpath += this->Convert(*ri, NONE, shellFormat);
  1420. rpath += " ";
  1421. }
  1422. fout << rpath;
  1423. } else {
  1424. // All rpath entries are combined ("-Wl,-rpath,a:b:c").
  1425. std::string rpath = cli.GetRPathString(relink);
  1426. // Store the rpath option in the stream.
  1427. if (!rpath.empty()) {
  1428. fout << cli.GetRuntimeFlag();
  1429. fout << this->EscapeForShell(rpath, escapeAllowMakeVars);
  1430. fout << " ";
  1431. }
  1432. }
  1433. // Add the linker runtime search path if any.
  1434. std::string rpath_link = cli.GetRPathLinkString();
  1435. if (!cli.GetRPathLinkFlag().empty() && !rpath_link.empty()) {
  1436. fout << cli.GetRPathLinkFlag();
  1437. fout << this->EscapeForShell(rpath_link, escapeAllowMakeVars);
  1438. fout << " ";
  1439. }
  1440. // Add standard libraries for this language.
  1441. std::string standardLibsVar = "CMAKE_";
  1442. standardLibsVar += cli.GetLinkLanguage();
  1443. standardLibsVar += "_STANDARD_LIBRARIES";
  1444. if (const char* stdLibs = this->Makefile->GetDefinition(standardLibsVar)) {
  1445. fout << stdLibs << " ";
  1446. }
  1447. linkLibraries = fout.str();
  1448. }
  1449. void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
  1450. cmGeneratorTarget const* target,
  1451. const std::string& lang,
  1452. const std::string& config)
  1453. {
  1454. // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
  1455. if (this->Makefile->IsOn("APPLE") && this->EmitUniversalBinaryFlags) {
  1456. std::vector<std::string> archs;
  1457. target->GetAppleArchs(config, archs);
  1458. const char* sysroot = this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
  1459. if (sysroot && sysroot[0] == '/' && !sysroot[1]) {
  1460. sysroot = CM_NULLPTR;
  1461. }
  1462. std::string sysrootFlagVar =
  1463. std::string("CMAKE_") + lang + "_SYSROOT_FLAG";
  1464. const char* sysrootFlag = this->Makefile->GetDefinition(sysrootFlagVar);
  1465. const char* deploymentTarget =
  1466. this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
  1467. std::string deploymentTargetFlagVar =
  1468. std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
  1469. const char* deploymentTargetFlag =
  1470. this->Makefile->GetDefinition(deploymentTargetFlagVar);
  1471. if (!archs.empty() && !lang.empty() &&
  1472. (lang[0] == 'C' || lang[0] == 'F')) {
  1473. for (std::vector<std::string>::iterator i = archs.begin();
  1474. i != archs.end(); ++i) {
  1475. flags += " -arch ";
  1476. flags += *i;
  1477. }
  1478. }
  1479. if (sysrootFlag && *sysrootFlag && sysroot && *sysroot) {
  1480. flags += " ";
  1481. flags += sysrootFlag;
  1482. flags += " ";
  1483. flags += this->Convert(sysroot, NONE, SHELL);
  1484. }
  1485. if (deploymentTargetFlag && *deploymentTargetFlag && deploymentTarget &&
  1486. *deploymentTarget) {
  1487. flags += " ";
  1488. flags += deploymentTargetFlag;
  1489. flags += deploymentTarget;
  1490. }
  1491. }
  1492. }
  1493. void cmLocalGenerator::AddLanguageFlags(std::string& flags,
  1494. const std::string& lang,
  1495. const std::string& config)
  1496. {
  1497. // Add language-specific flags.
  1498. std::string flagsVar = "CMAKE_";
  1499. flagsVar += lang;
  1500. flagsVar += "_FLAGS";
  1501. this->AddConfigVariableFlags(flags, flagsVar, config);
  1502. }
  1503. cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse(
  1504. const std::string& name) const
  1505. {
  1506. std::vector<cmGeneratorTarget*>::const_iterator imported = std::find_if(
  1507. this->ImportedGeneratorTargets.begin(),
  1508. this->ImportedGeneratorTargets.end(), NamedGeneratorTargetFinder(name));
  1509. if (imported != this->ImportedGeneratorTargets.end()) {
  1510. return *imported;
  1511. }
  1512. if (cmGeneratorTarget* t = this->FindLocalNonAliasGeneratorTarget(name)) {
  1513. return t;
  1514. }
  1515. return this->GetGlobalGenerator()->FindGeneratorTarget(name);
  1516. }
  1517. bool cmLocalGenerator::GetRealDependency(const std::string& inName,
  1518. const std::string& config,
  1519. std::string& dep)
  1520. {
  1521. // Older CMake code may specify the dependency using the target
  1522. // output file rather than the target name. Such code would have
  1523. // been written before there was support for target properties that
  1524. // modify the name so stripping down to just the file name should
  1525. // produce the target name in this case.
  1526. std::string name = cmSystemTools::GetFilenameName(inName);
  1527. // If the input name is the empty string, there is no real
  1528. // dependency. Short-circuit the other checks:
  1529. if (name == "") {
  1530. return false;
  1531. }
  1532. if (cmSystemTools::GetFilenameLastExtension(name) == ".exe") {
  1533. name = cmSystemTools::GetFilenameWithoutLastExtension(name);
  1534. }
  1535. // Look for a CMake target with the given name.
  1536. if (cmGeneratorTarget* target = this->FindGeneratorTargetToUse(name)) {
  1537. // make sure it is not just a coincidence that the target name
  1538. // found is part of the inName
  1539. if (cmSystemTools::FileIsFullPath(inName.c_str())) {
  1540. std::string tLocation;
  1541. if (target->GetType() >= cmState::EXECUTABLE &&
  1542. target->GetType() <= cmState::MODULE_LIBRARY) {
  1543. tLocation = target->GetLocation(config);
  1544. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1545. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  1546. }
  1547. std::string depLocation =
  1548. cmSystemTools::GetFilenamePath(std::string(inName));
  1549. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  1550. if (depLocation != tLocation) {
  1551. // it is a full path to a depend that has the same name
  1552. // as a target but is in a different location so do not use
  1553. // the target as the depend
  1554. dep = inName;
  1555. return true;
  1556. }
  1557. }
  1558. switch (target->GetType()) {
  1559. case cmState::EXECUTABLE:
  1560. case cmState::STATIC_LIBRARY:
  1561. case cmState::SHARED_LIBRARY:
  1562. case cmState::MODULE_LIBRARY:
  1563. case cmState::UNKNOWN_LIBRARY:
  1564. dep = target->GetLocation(config);
  1565. return true;
  1566. case cmState::OBJECT_LIBRARY:
  1567. // An object library has no single file on which to depend.
  1568. // This was listed to get the target-level dependency.
  1569. return false;
  1570. case cmState::INTERFACE_LIBRARY:
  1571. // An interface library has no file on which to depend.
  1572. // This was listed to get the target-level dependency.
  1573. return false;
  1574. case cmState::UTILITY:
  1575. case cmState::GLOBAL_TARGET:
  1576. // A utility target has no file on which to depend. This was listed
  1577. // only to get the target-level dependency.
  1578. return false;
  1579. }
  1580. }
  1581. // The name was not that of a CMake target. It must name a file.
  1582. if (cmSystemTools::FileIsFullPath(inName.c_str())) {
  1583. // This is a full path. Return it as given.
  1584. dep = inName;
  1585. return true;
  1586. }
  1587. // Check for a source file in this directory that matches the
  1588. // dependency.
  1589. if (cmSourceFile* sf = this->Makefile->GetSource(inName)) {
  1590. dep = sf->GetFullPath();
  1591. return true;
  1592. }
  1593. // Treat the name as relative to the source directory in which it
  1594. // was given.
  1595. dep = this->StateSnapshot.GetDirectory().GetCurrentSource();
  1596. dep += "/";
  1597. dep += inName;
  1598. return true;
  1599. }
  1600. void cmLocalGenerator::AddSharedFlags(std::string& flags,
  1601. const std::string& lang, bool shared)
  1602. {
  1603. std::string flagsVar;
  1604. // Add flags for dealing with shared libraries for this language.
  1605. if (shared) {
  1606. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1607. flagsVar += lang;
  1608. flagsVar += "_FLAGS";
  1609. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  1610. }
  1611. }
  1612. void cmLocalGenerator::AddCompilerRequirementFlag(
  1613. std::string& flags, cmGeneratorTarget const* target, const std::string& lang)
  1614. {
  1615. if (lang.empty()) {
  1616. return;
  1617. }
  1618. const char* defaultStd =
  1619. this->Makefile->GetDefinition("CMAKE_" + lang + "_STANDARD_DEFAULT");
  1620. if (!defaultStd || !*defaultStd) {
  1621. // This compiler has no notion of language standard levels.
  1622. return;
  1623. }
  1624. std::string stdProp = lang + "_STANDARD";
  1625. const char* standardProp = target->GetProperty(stdProp);
  1626. if (!standardProp) {
  1627. return;
  1628. }
  1629. std::string extProp = lang + "_EXTENSIONS";
  1630. std::string type = "EXTENSION";
  1631. bool ext = true;
  1632. if (const char* extPropValue = target->GetProperty(extProp)) {
  1633. if (cmSystemTools::IsOff(extPropValue)) {
  1634. ext = false;
  1635. type = "STANDARD";
  1636. }
  1637. }
  1638. if (target->GetPropertyAsBool(lang + "_STANDARD_REQUIRED")) {
  1639. std::string option_flag =
  1640. "CMAKE_" + lang + standardProp + "_" + type + "_COMPILE_OPTION";
  1641. const char* opt =
  1642. target->Target->GetMakefile()->GetDefinition(option_flag);
  1643. if (!opt) {
  1644. std::ostringstream e;
  1645. e << "Target \"" << target->GetName() << "\" requires the language "
  1646. "dialect \""
  1647. << lang << standardProp << "\" "
  1648. << (ext ? "(with compiler extensions)" : "")
  1649. << ", but CMake "
  1650. "does not know the compile flags to use to enable it.";
  1651. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  1652. } else {
  1653. this->AppendFlagEscape(flags, opt);
  1654. }
  1655. return;
  1656. }
  1657. static std::map<std::string, std::vector<std::string> > langStdMap;
  1658. if (langStdMap.empty()) {
  1659. // Maintain sorted order, most recent first.
  1660. langStdMap["CXX"].push_back("14");
  1661. langStdMap["CXX"].push_back("11");
  1662. langStdMap["CXX"].push_back("98");
  1663. langStdMap["C"].push_back("11");
  1664. langStdMap["C"].push_back("99");
  1665. langStdMap["C"].push_back("90");
  1666. }
  1667. std::string standard(standardProp);
  1668. std::vector<std::string>& stds = langStdMap[lang];
  1669. std::vector<std::string>::const_iterator stdIt =
  1670. std::find(stds.begin(), stds.end(), standard);
  1671. if (stdIt == stds.end()) {
  1672. std::string e =
  1673. lang + "_STANDARD is set to invalid value '" + standard + "'";
  1674. this->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
  1675. cmake::FATAL_ERROR, e, target->GetBacktrace());
  1676. return;
  1677. }
  1678. std::vector<std::string>::const_iterator defaultStdIt =
  1679. std::find(stds.begin(), stds.end(), defaultStd);
  1680. if (defaultStdIt == stds.end()) {
  1681. std::string e = "CMAKE_" + lang +
  1682. "_STANDARD_DEFAULT is set to invalid value '" + std::string(defaultStd) +
  1683. "'";
  1684. this->IssueMessage(cmake::INTERNAL_ERROR, e);
  1685. return;
  1686. }
  1687. // Greater or equal because the standards are stored in
  1688. // backward chronological order.
  1689. if (stdIt >= defaultStdIt) {
  1690. std::string option_flag =
  1691. "CMAKE_" + lang + *stdIt + "_" + type + "_COMPILE_OPTION";
  1692. const char* opt =
  1693. target->Target->GetMakefile()->GetRequiredDefinition(option_flag);
  1694. this->AppendFlagEscape(flags, opt);
  1695. return;
  1696. }
  1697. for (; stdIt < defaultStdIt; ++stdIt) {
  1698. std::string option_flag =
  1699. "CMAKE_" + lang + *stdIt + "_" + type + "_COMPILE_OPTION";
  1700. if (const char* opt =
  1701. target->Target->GetMakefile()->GetDefinition(option_flag)) {
  1702. this->AppendFlagEscape(flags, opt);
  1703. return;
  1704. }
  1705. }
  1706. }
  1707. static void AddVisibilityCompileOption(std::string& flags,
  1708. cmGeneratorTarget const* target,
  1709. cmLocalGenerator* lg,
  1710. const std::string& lang,
  1711. std::string* warnCMP0063)
  1712. {
  1713. std::string compileOption = "CMAKE_" + lang + "_COMPILE_OPTIONS_VISIBILITY";
  1714. const char* opt = lg->GetMakefile()->GetDefinition(compileOption);
  1715. if (!opt) {
  1716. return;
  1717. }
  1718. std::string flagDefine = lang + "_VISIBILITY_PRESET";
  1719. const char* prop = target->GetProperty(flagDefine);
  1720. if (!prop) {
  1721. return;
  1722. }
  1723. if (warnCMP0063) {
  1724. *warnCMP0063 += " " + flagDefine + "\n";
  1725. return;
  1726. }
  1727. if (strcmp(prop, "hidden") != 0 && strcmp(prop, "default") != 0 &&
  1728. strcmp(prop, "protected") != 0 && strcmp(prop, "internal") != 0) {
  1729. std::ostringstream e;
  1730. e << "Target " << target->GetName() << " uses unsupported value \"" << prop
  1731. << "\" for " << flagDefine << ".";
  1732. cmSystemTools::Error(e.str().c_str());
  1733. return;
  1734. }
  1735. std::string option = std::string(opt) + prop;
  1736. lg->AppendFlags(flags, option);
  1737. }
  1738. static void AddInlineVisibilityCompileOption(std::string& flags,
  1739. cmGeneratorTarget const* target,
  1740. cmLocalGenerator* lg,
  1741. std::string* warnCMP0063)
  1742. {
  1743. std::string compileOption =
  1744. "CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN";
  1745. const char* opt = lg->GetMakefile()->GetDefinition(compileOption);
  1746. if (!opt) {
  1747. return;
  1748. }
  1749. bool prop = target->GetPropertyAsBool("VISIBILITY_INLINES_HIDDEN");
  1750. if (!prop) {
  1751. return;
  1752. }
  1753. if (warnCMP0063) {
  1754. *warnCMP0063 += " VISIBILITY_INLINES_HIDDEN\n";
  1755. return;
  1756. }
  1757. lg->AppendFlags(flags, opt);
  1758. }
  1759. void cmLocalGenerator::AddVisibilityPresetFlags(
  1760. std::string& flags, cmGeneratorTarget const* target, const std::string& lang)
  1761. {
  1762. if (lang.empty()) {
  1763. return;
  1764. }
  1765. std::string warnCMP0063;
  1766. std::string* pWarnCMP0063 = CM_NULLPTR;
  1767. if (target->GetType() != cmState::SHARED_LIBRARY &&
  1768. target->GetType() != cmState::MODULE_LIBRARY &&
  1769. !target->IsExecutableWithExports()) {
  1770. switch (target->GetPolicyStatusCMP0063()) {
  1771. case cmPolicies::OLD:
  1772. return;
  1773. case cmPolicies::WARN:
  1774. pWarnCMP0063 = &warnCMP0063;
  1775. break;
  1776. default:
  1777. break;
  1778. }
  1779. }
  1780. AddVisibilityCompileOption(flags, target, this, lang, pWarnCMP0063);
  1781. if (lang == "CXX") {
  1782. AddInlineVisibilityCompileOption(flags, target, this, pWarnCMP0063);
  1783. }
  1784. if (!warnCMP0063.empty() && this->WarnCMP0063.insert(target).second) {
  1785. std::ostringstream w;
  1786. /* clang-format off */
  1787. w <<
  1788. cmPolicies::GetPolicyWarning(cmPolicies::CMP0063) << "\n"
  1789. "Target \"" << target->GetName() << "\" of "
  1790. "type \"" << cmState::GetTargetTypeName(target->GetType()) << "\" "
  1791. "has the following visibility properties set for " << lang << ":\n" <<
  1792. warnCMP0063 <<
  1793. "For compatibility CMake is not honoring them for this target.";
  1794. /* clang-format on */
  1795. target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1796. cmake::AUTHOR_WARNING, w.str(), target->GetBacktrace());
  1797. }
  1798. }
  1799. void cmLocalGenerator::AddCMP0018Flags(std::string& flags,
  1800. cmGeneratorTarget const* target,
  1801. std::string const& lang,
  1802. const std::string& config)
  1803. {
  1804. int targetType = target->GetType();
  1805. bool shared = ((targetType == cmState::SHARED_LIBRARY) ||
  1806. (targetType == cmState::MODULE_LIBRARY));
  1807. if (this->GetShouldUseOldFlags(shared, lang)) {
  1808. this->AddSharedFlags(flags, lang, shared);
  1809. } else {
  1810. if (target->GetType() == cmState::OBJECT_LIBRARY) {
  1811. if (target->GetPropertyAsBool("POSITION_INDEPENDENT_CODE")) {
  1812. this->AddPositionIndependentFlags(flags, lang, targetType);
  1813. }
  1814. return;
  1815. }
  1816. if (target->GetLinkInterfaceDependentBoolProperty(
  1817. "POSITION_INDEPENDENT_CODE", config)) {
  1818. this->AddPositionIndependentFlags(flags, lang, targetType);
  1819. }
  1820. if (shared) {
  1821. this->AppendFeatureOptions(flags, lang, "DLL");
  1822. }
  1823. }
  1824. }
  1825. bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
  1826. const std::string& lang) const
  1827. {
  1828. std::string originalFlags =
  1829. this->GlobalGenerator->GetSharedLibFlagsForLanguage(lang);
  1830. if (shared) {
  1831. std::string flagsVar = "CMAKE_SHARED_LIBRARY_";
  1832. flagsVar += lang;
  1833. flagsVar += "_FLAGS";
  1834. const char* flags = this->Makefile->GetSafeDefinition(flagsVar);
  1835. if (flags && flags != originalFlags) {
  1836. switch (this->GetPolicyStatus(cmPolicies::CMP0018)) {
  1837. case cmPolicies::WARN: {
  1838. std::ostringstream e;
  1839. e << "Variable " << flagsVar
  1840. << " has been modified. CMake "
  1841. "will ignore the POSITION_INDEPENDENT_CODE target property for "
  1842. "shared libraries and will use the "
  1843. << flagsVar
  1844. << " variable "
  1845. "instead. This may cause errors if the original content of "
  1846. << flagsVar << " was removed.\n"
  1847. << cmPolicies::GetPolicyWarning(cmPolicies::CMP0018);
  1848. this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  1849. // fall through to OLD behaviour
  1850. }
  1851. case cmPolicies::OLD:
  1852. return true;
  1853. case cmPolicies::REQUIRED_IF_USED:
  1854. case cmPolicies::REQUIRED_ALWAYS:
  1855. case cmPolicies::NEW:
  1856. return false;
  1857. }
  1858. }
  1859. }
  1860. return false;
  1861. }
  1862. void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
  1863. std::string const& lang,
  1864. int targetType)
  1865. {
  1866. const char* picFlags = CM_NULLPTR;
  1867. if (targetType == cmState::EXECUTABLE) {
  1868. std::string flagsVar = "CMAKE_";
  1869. flagsVar += lang;
  1870. flagsVar += "_COMPILE_OPTIONS_PIE";
  1871. picFlags = this->Makefile->GetSafeDefinition(flagsVar);
  1872. }
  1873. if (!picFlags) {
  1874. std::string flagsVar = "CMAKE_";
  1875. flagsVar += lang;
  1876. flagsVar += "_COMPILE_OPTIONS_PIC";
  1877. picFlags = this->Makefile->GetSafeDefinition(flagsVar);
  1878. }
  1879. if (picFlags) {
  1880. std::vector<std::string> options;
  1881. cmSystemTools::ExpandListArgument(picFlags, options);
  1882. for (std::vector<std::string>::const_iterator oi = options.begin();
  1883. oi != options.end(); ++oi) {
  1884. this->AppendFlagEscape(flags, *oi);
  1885. }
  1886. }
  1887. }
  1888. void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
  1889. const std::string& var,
  1890. const std::string& config)
  1891. {
  1892. // Add the flags from the variable itself.
  1893. std::string flagsVar = var;
  1894. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  1895. // Add the flags from the build-type specific variable.
  1896. if (!config.empty()) {
  1897. flagsVar += "_";
  1898. flagsVar += cmSystemTools::UpperCase(config);
  1899. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  1900. }
  1901. }
  1902. void cmLocalGenerator::AppendFlags(std::string& flags,
  1903. const std::string& newFlags)
  1904. {
  1905. if (!newFlags.empty()) {
  1906. if (!flags.empty()) {
  1907. flags += " ";
  1908. }
  1909. flags += newFlags;
  1910. }
  1911. }
  1912. void cmLocalGenerator::AppendFlags(std::string& flags, const char* newFlags)
  1913. {
  1914. if (newFlags && *newFlags) {
  1915. this->AppendFlags(flags, std::string(newFlags));
  1916. }
  1917. }
  1918. void cmLocalGenerator::AppendFlagEscape(std::string& flags,
  1919. const std::string& rawFlag)
  1920. {
  1921. this->AppendFlags(flags, this->EscapeForShell(rawFlag));
  1922. }
  1923. void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
  1924. const char* defines_list) const
  1925. {
  1926. // Short-circuit if there are no definitions.
  1927. if (!defines_list) {
  1928. return;
  1929. }
  1930. // Expand the list of definitions.
  1931. std::vector<std::string> defines_vec;
  1932. cmSystemTools::ExpandListArgument(defines_list, defines_vec);
  1933. this->AppendDefines(defines, defines_vec);
  1934. }
  1935. void cmLocalGenerator::AppendDefines(
  1936. std::set<std::string>& defines,
  1937. const std::vector<std::string>& defines_vec) const
  1938. {
  1939. for (std::vector<std::string>::const_iterator di = defines_vec.begin();
  1940. di != defines_vec.end(); ++di) {
  1941. // Skip unsupported definitions.
  1942. if (!this->CheckDefinition(*di)) {
  1943. continue;
  1944. }
  1945. defines.insert(*di);
  1946. }
  1947. }
  1948. void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
  1949. std::string& definesString,
  1950. const std::string& lang)
  1951. {
  1952. // Lookup the define flag for the current language.
  1953. std::string dflag = "-D";
  1954. if (!lang.empty()) {
  1955. std::string defineFlagVar = "CMAKE_";
  1956. defineFlagVar += lang;
  1957. defineFlagVar += "_DEFINE_FLAG";
  1958. const char* df = this->Makefile->GetDefinition(defineFlagVar);
  1959. if (df && *df) {
  1960. dflag = df;
  1961. }
  1962. }
  1963. std::set<std::string>::const_iterator defineIt = defines.begin();
  1964. const std::set<std::string>::const_iterator defineEnd = defines.end();
  1965. const char* itemSeparator = definesString.empty() ? "" : " ";
  1966. for (; defineIt != defineEnd; ++defineIt) {
  1967. // Append the definition with proper escaping.
  1968. std::string def = dflag;
  1969. if (this->GetState()->UseWatcomWMake()) {
  1970. // The Watcom compiler does its own command line parsing instead
  1971. // of using the windows shell rules. Definitions are one of
  1972. // -DNAME
  1973. // -DNAME=<cpp-token>
  1974. // -DNAME="c-string with spaces and other characters(?@#$)"
  1975. //
  1976. // Watcom will properly parse each of these cases from the
  1977. // command line without any escapes. However we still have to
  1978. // get the '$' and '#' characters through WMake as '$$' and
  1979. // '$#'.
  1980. for (const char* c = defineIt->c_str(); *c; ++c) {
  1981. if (*c == '$' || *c == '#') {
  1982. def += '$';
  1983. }
  1984. def += *c;
  1985. }
  1986. } else {
  1987. // Make the definition appear properly on the command line. Use
  1988. // -DNAME="value" instead of -D"NAME=value" for historical reasons.
  1989. std::string::size_type eq = defineIt->find("=");
  1990. def += defineIt->substr(0, eq);
  1991. if (eq != defineIt->npos) {
  1992. def += "=";
  1993. def += this->EscapeForShell(defineIt->c_str() + eq + 1, true);
  1994. }
  1995. }
  1996. definesString += itemSeparator;
  1997. itemSeparator = " ";
  1998. definesString += def;
  1999. }
  2000. }
  2001. void cmLocalGenerator::AppendFeatureOptions(std::string& flags,
  2002. const std::string& lang,
  2003. const char* feature)
  2004. {
  2005. std::string optVar = "CMAKE_";
  2006. optVar += lang;
  2007. optVar += "_COMPILE_OPTIONS_";
  2008. optVar += feature;
  2009. if (const char* optionList = this->Makefile->GetDefinition(optVar)) {
  2010. std::vector<std::string> options;
  2011. cmSystemTools::ExpandListArgument(optionList, options);
  2012. for (std::vector<std::string>::const_iterator oi = options.begin();
  2013. oi != options.end(); ++oi) {
  2014. this->AppendFlagEscape(flags, *oi);
  2015. }
  2016. }
  2017. }
  2018. const char* cmLocalGenerator::GetFeature(const std::string& feature,
  2019. const std::string& config)
  2020. {
  2021. std::string featureName = feature;
  2022. // TODO: Define accumulation policy for features (prepend, append, replace).
  2023. // Currently we always replace.
  2024. if (!config.empty()) {
  2025. featureName += "_";
  2026. featureName += cmSystemTools::UpperCase(config);
  2027. }
  2028. cmState::Snapshot snp = this->StateSnapshot;
  2029. while (snp.IsValid()) {
  2030. if (const char* value = snp.GetDirectory().GetProperty(featureName)) {
  2031. return value;
  2032. }
  2033. snp = snp.GetBuildsystemDirectoryParent();
  2034. }
  2035. return CM_NULLPTR;
  2036. }
  2037. std::string cmLocalGenerator::GetProjectName() const
  2038. {
  2039. return this->StateSnapshot.GetProjectName();
  2040. }
  2041. std::string cmLocalGenerator::ConstructComment(
  2042. cmCustomCommandGenerator const& ccg, const char* default_comment)
  2043. {
  2044. // Check for a comment provided with the command.
  2045. if (ccg.GetComment()) {
  2046. return ccg.GetComment();
  2047. }
  2048. // Construct a reasonable default comment if possible.
  2049. if (!ccg.GetOutputs().empty()) {
  2050. std::string comment;
  2051. comment = "Generating ";
  2052. const char* sep = "";
  2053. for (std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin();
  2054. o != ccg.GetOutputs().end(); ++o) {
  2055. comment += sep;
  2056. comment += this->Convert(*o, cmOutputConverter::START_OUTPUT);
  2057. sep = ", ";
  2058. }
  2059. return comment;
  2060. }
  2061. // Otherwise use the provided default.
  2062. return default_comment;
  2063. }
  2064. class cmInstallTargetGeneratorLocal : public cmInstallTargetGenerator
  2065. {
  2066. public:
  2067. cmInstallTargetGeneratorLocal(cmLocalGenerator* lg, std::string const& t,
  2068. const char* dest, bool implib)
  2069. : cmInstallTargetGenerator(
  2070. t, dest, implib, "", std::vector<std::string>(), "Unspecified",
  2071. cmInstallGenerator::SelectMessageLevel(lg->GetMakefile()), false,
  2072. false)
  2073. {
  2074. this->Compute(lg);
  2075. }
  2076. };
  2077. void cmLocalGenerator::GenerateTargetInstallRules(
  2078. std::ostream& os, const std::string& config,
  2079. std::vector<std::string> const& configurationTypes)
  2080. {
  2081. // Convert the old-style install specification from each target to
  2082. // an install generator and run it.
  2083. std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
  2084. for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
  2085. l != tgts.end(); ++l) {
  2086. if ((*l)->GetType() == cmState::INTERFACE_LIBRARY) {
  2087. continue;
  2088. }
  2089. // Include the user-specified pre-install script for this target.
  2090. if (const char* preinstall = (*l)->GetProperty("PRE_INSTALL_SCRIPT")) {
  2091. cmInstallScriptGenerator g(preinstall, false, CM_NULLPTR, false);
  2092. g.Generate(os, config, configurationTypes);
  2093. }
  2094. // Install this target if a destination is given.
  2095. if ((*l)->Target->GetInstallPath() != "") {
  2096. // Compute the full install destination. Note that converting
  2097. // to unix slashes also removes any trailing slash.
  2098. // We also skip over the leading slash given by the user.
  2099. std::string destination = (*l)->Target->GetInstallPath().substr(1);
  2100. cmSystemTools::ConvertToUnixSlashes(destination);
  2101. if (destination.empty()) {
  2102. destination = ".";
  2103. }
  2104. // Generate the proper install generator for this target type.
  2105. switch ((*l)->GetType()) {
  2106. case cmState::EXECUTABLE:
  2107. case cmState::STATIC_LIBRARY:
  2108. case cmState::MODULE_LIBRARY: {
  2109. // Use a target install generator.
  2110. cmInstallTargetGeneratorLocal g(this, (*l)->GetName(),
  2111. destination.c_str(), false);
  2112. g.Generate(os, config, configurationTypes);
  2113. } break;
  2114. case cmState::SHARED_LIBRARY: {
  2115. #if defined(_WIN32) || defined(__CYGWIN__)
  2116. // Special code to handle DLL. Install the import library
  2117. // to the normal destination and the DLL to the runtime
  2118. // destination.
  2119. cmInstallTargetGeneratorLocal g1(this, (*l)->GetName(),
  2120. destination.c_str(), true);
  2121. g1.Generate(os, config, configurationTypes);
  2122. // We also skip over the leading slash given by the user.
  2123. destination = (*l)->Target->GetRuntimeInstallPath().substr(1);
  2124. cmSystemTools::ConvertToUnixSlashes(destination);
  2125. cmInstallTargetGeneratorLocal g2(this, (*l)->GetName(),
  2126. destination.c_str(), false);
  2127. g2.Generate(os, config, configurationTypes);
  2128. #else
  2129. // Use a target install generator.
  2130. cmInstallTargetGeneratorLocal g(this, (*l)->GetName(),
  2131. destination.c_str(), false);
  2132. g.Generate(os, config, configurationTypes);
  2133. #endif
  2134. } break;
  2135. default:
  2136. break;
  2137. }
  2138. }
  2139. // Include the user-specified post-install script for this target.
  2140. if (const char* postinstall = (*l)->GetProperty("POST_INSTALL_SCRIPT")) {
  2141. cmInstallScriptGenerator g(postinstall, false, CM_NULLPTR, false);
  2142. g.Generate(os, config, configurationTypes);
  2143. }
  2144. }
  2145. }
  2146. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2147. static std::string cmLocalGeneratorMD5(const char* input)
  2148. {
  2149. char md5out[32];
  2150. cmsysMD5* md5 = cmsysMD5_New();
  2151. cmsysMD5_Initialize(md5);
  2152. cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
  2153. cmsysMD5_FinalizeHex(md5, md5out);
  2154. cmsysMD5_Delete(md5);
  2155. return std::string(md5out, 32);
  2156. }
  2157. static bool cmLocalGeneratorShortenObjectName(std::string& objName,
  2158. std::string::size_type max_len)
  2159. {
  2160. // Replace the beginning of the path portion of the object name with
  2161. // its own md5 sum.
  2162. std::string::size_type pos =
  2163. objName.find('/', objName.size() - max_len + 32);
  2164. if (pos != objName.npos) {
  2165. std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
  2166. md5name += objName.substr(pos);
  2167. objName = md5name;
  2168. // The object name is now short enough.
  2169. return true;
  2170. }
  2171. // The object name could not be shortened enough.
  2172. return false;
  2173. }
  2174. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  2175. std::string::size_type dir_len,
  2176. std::string::size_type max_total_len)
  2177. {
  2178. // Enforce the maximum file name length if possible.
  2179. std::string::size_type max_obj_len = max_total_len;
  2180. if (dir_len < max_total_len) {
  2181. max_obj_len = max_total_len - dir_len;
  2182. if (objName.size() > max_obj_len) {
  2183. // The current object file name is too long. Try to shorten it.
  2184. return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
  2185. }
  2186. // The object file name is short enough.
  2187. return true;
  2188. }
  2189. // The build directory in which the object will be stored is
  2190. // already too deep.
  2191. return false;
  2192. }
  2193. #endif
  2194. std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName(
  2195. const std::string& sin, std::string const& dir_max)
  2196. {
  2197. // Look for an existing mapped name for this object file.
  2198. std::map<std::string, std::string>::iterator it =
  2199. this->UniqueObjectNamesMap.find(sin);
  2200. // If no entry exists create one.
  2201. if (it == this->UniqueObjectNamesMap.end()) {
  2202. // Start with the original name.
  2203. std::string ssin = sin;
  2204. // Avoid full paths by removing leading slashes.
  2205. ssin.erase(0, ssin.find_first_not_of('/'));
  2206. // Avoid full paths by removing colons.
  2207. std::replace(ssin.begin(), ssin.end(), ':', '_');
  2208. // Avoid relative paths that go up the tree.
  2209. cmSystemTools::ReplaceString(ssin, "../", "__/");
  2210. // Avoid spaces.
  2211. std::replace(ssin.begin(), ssin.end(), ' ', '_');
  2212. // Mangle the name if necessary.
  2213. if (this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES")) {
  2214. bool done;
  2215. int cc = 0;
  2216. char rpstr[100];
  2217. sprintf(rpstr, "_p_");
  2218. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2219. std::string sssin = sin;
  2220. do {
  2221. done = true;
  2222. for (it = this->UniqueObjectNamesMap.begin();
  2223. it != this->UniqueObjectNamesMap.end(); ++it) {
  2224. if (it->second == ssin) {
  2225. done = false;
  2226. }
  2227. }
  2228. if (done) {
  2229. break;
  2230. }
  2231. sssin = ssin;
  2232. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2233. sprintf(rpstr, "_p%d_", cc++);
  2234. } while (!done);
  2235. }
  2236. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2237. if (!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
  2238. this->ObjectPathMax)) {
  2239. // Warn if this is the first time the path has been seen.
  2240. if (this->ObjectMaxPathViolations.insert(dir_max).second) {
  2241. std::ostringstream m;
  2242. /* clang-format off */
  2243. m << "The object file directory\n"
  2244. << " " << dir_max << "\n"
  2245. << "has " << dir_max.size() << " characters. "
  2246. << "The maximum full path to an object file is "
  2247. << this->ObjectPathMax << " characters "
  2248. << "(see CMAKE_OBJECT_PATH_MAX). "
  2249. << "Object file\n"
  2250. << " " << ssin << "\n"
  2251. << "cannot be safely placed under this directory. "
  2252. << "The build may not work correctly.";
  2253. /* clang-format on */
  2254. this->IssueMessage(cmake::WARNING, m.str());
  2255. }
  2256. }
  2257. #else
  2258. (void)dir_max;
  2259. #endif
  2260. // Insert the newly mapped object file name.
  2261. std::map<std::string, std::string>::value_type e(sin, ssin);
  2262. it = this->UniqueObjectNamesMap.insert(e).first;
  2263. }
  2264. // Return the map entry.
  2265. return it->second;
  2266. }
  2267. void cmLocalGenerator::ComputeObjectFilenames(
  2268. std::map<cmSourceFile const*, std::string>& /*unused*/,
  2269. cmGeneratorTarget const* /*unused*/)
  2270. {
  2271. }
  2272. bool cmLocalGenerator::IsWindowsShell() const
  2273. {
  2274. return this->GetState()->UseWindowsShell();
  2275. }
  2276. bool cmLocalGenerator::IsWatcomWMake() const
  2277. {
  2278. return this->GetState()->UseWatcomWMake();
  2279. }
  2280. bool cmLocalGenerator::IsMinGWMake() const
  2281. {
  2282. return this->GetState()->UseMinGWMake();
  2283. }
  2284. bool cmLocalGenerator::IsNMake() const
  2285. {
  2286. return this->GetState()->UseNMake();
  2287. }
  2288. std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
  2289. const cmSourceFile& source, std::string const& dir_max,
  2290. bool* hasSourceExtension)
  2291. {
  2292. // Construct the object file name using the full path to the source
  2293. // file which is its only unique identification.
  2294. const char* fullPath = source.GetFullPath().c_str();
  2295. // Try referencing the source relative to the source tree.
  2296. std::string relFromSource = this->Convert(fullPath, START);
  2297. assert(!relFromSource.empty());
  2298. bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
  2299. bool subSource = relSource && relFromSource[0] != '.';
  2300. // Try referencing the source relative to the binary tree.
  2301. std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
  2302. assert(!relFromBinary.empty());
  2303. bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
  2304. bool subBinary = relBinary && relFromBinary[0] != '.';
  2305. // Select a nice-looking reference to the source file to construct
  2306. // the object file name.
  2307. std::string objectName;
  2308. if ((relSource && !relBinary) || (subSource && !subBinary)) {
  2309. objectName = relFromSource;
  2310. } else if ((relBinary && !relSource) || (subBinary && !subSource)) {
  2311. objectName = relFromBinary;
  2312. } else if (relFromBinary.length() < relFromSource.length()) {
  2313. objectName = relFromBinary;
  2314. } else {
  2315. objectName = relFromSource;
  2316. }
  2317. // if it is still a full path check for the try compile case
  2318. // try compile never have in source sources, and should not
  2319. // have conflicting source file names in the same target
  2320. if (cmSystemTools::FileIsFullPath(objectName.c_str())) {
  2321. if (this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile()) {
  2322. objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
  2323. }
  2324. }
  2325. // Replace the original source file extension with the object file
  2326. // extension.
  2327. bool keptSourceExtension = true;
  2328. if (!source.GetPropertyAsBool("KEEP_EXTENSION")) {
  2329. // Decide whether this language wants to replace the source
  2330. // extension with the object extension. For CMake 2.4
  2331. // compatibility do this by default.
  2332. bool replaceExt = this->NeedBackwardsCompatibility_2_4();
  2333. if (!replaceExt) {
  2334. std::string lang = source.GetLanguage();
  2335. if (!lang.empty()) {
  2336. std::string repVar = "CMAKE_";
  2337. repVar += lang;
  2338. repVar += "_OUTPUT_EXTENSION_REPLACE";
  2339. replaceExt = this->Makefile->IsOn(repVar);
  2340. }
  2341. }
  2342. // Remove the source extension if it is to be replaced.
  2343. if (replaceExt) {
  2344. keptSourceExtension = false;
  2345. std::string::size_type dot_pos = objectName.rfind('.');
  2346. if (dot_pos != std::string::npos) {
  2347. objectName = objectName.substr(0, dot_pos);
  2348. }
  2349. }
  2350. // Store the new extension.
  2351. objectName += this->GlobalGenerator->GetLanguageOutputExtension(source);
  2352. }
  2353. if (hasSourceExtension) {
  2354. *hasSourceExtension = keptSourceExtension;
  2355. }
  2356. // Convert to a safe name.
  2357. return this->CreateSafeUniqueObjectFileName(objectName, dir_max);
  2358. }
  2359. std::string cmLocalGenerator::GetSourceFileLanguage(const cmSourceFile& source)
  2360. {
  2361. return source.GetLanguage();
  2362. }
  2363. cmake* cmLocalGenerator::GetCMakeInstance() const
  2364. {
  2365. return this->GlobalGenerator->GetCMakeInstance();
  2366. }
  2367. const char* cmLocalGenerator::GetSourceDirectory() const
  2368. {
  2369. return this->GetCMakeInstance()->GetHomeDirectory();
  2370. }
  2371. const char* cmLocalGenerator::GetBinaryDirectory() const
  2372. {
  2373. return this->GetCMakeInstance()->GetHomeOutputDirectory();
  2374. }
  2375. const char* cmLocalGenerator::GetCurrentBinaryDirectory() const
  2376. {
  2377. return this->StateSnapshot.GetDirectory().GetCurrentBinary();
  2378. }
  2379. const char* cmLocalGenerator::GetCurrentSourceDirectory() const
  2380. {
  2381. return this->StateSnapshot.GetDirectory().GetCurrentSource();
  2382. }
  2383. std::string cmLocalGenerator::GetTargetDirectory(
  2384. const cmGeneratorTarget* /*unused*/) const
  2385. {
  2386. cmSystemTools::Error("GetTargetDirectory"
  2387. " called on cmLocalGenerator");
  2388. return "";
  2389. }
  2390. KWIML_INT_uint64_t cmLocalGenerator::GetBackwardsCompatibility()
  2391. {
  2392. // The computed version may change until the project is fully
  2393. // configured.
  2394. if (!this->BackwardsCompatibilityFinal) {
  2395. unsigned int major = 0;
  2396. unsigned int minor = 0;
  2397. unsigned int patch = 0;
  2398. if (const char* value =
  2399. this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY")) {
  2400. switch (sscanf(value, "%u.%u.%u", &major, &minor, &patch)) {
  2401. case 2:
  2402. patch = 0;
  2403. break;
  2404. case 1:
  2405. minor = 0;
  2406. patch = 0;
  2407. break;
  2408. default:
  2409. break;
  2410. }
  2411. }
  2412. this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
  2413. this->BackwardsCompatibilityFinal = true;
  2414. }
  2415. return this->BackwardsCompatibility;
  2416. }
  2417. bool cmLocalGenerator::NeedBackwardsCompatibility_2_4()
  2418. {
  2419. // Check the policy to decide whether to pay attention to this
  2420. // variable.
  2421. switch (this->GetPolicyStatus(cmPolicies::CMP0001)) {
  2422. case cmPolicies::WARN:
  2423. // WARN is just OLD without warning because user code does not
  2424. // always affect whether this check is done.
  2425. case cmPolicies::OLD:
  2426. // Old behavior is to check the variable.
  2427. break;
  2428. case cmPolicies::NEW:
  2429. // New behavior is to ignore the variable.
  2430. return false;
  2431. case cmPolicies::REQUIRED_IF_USED:
  2432. case cmPolicies::REQUIRED_ALWAYS:
  2433. // This will never be the case because the only way to require
  2434. // the setting is to require the user to specify version policy
  2435. // 2.6 or higher. Once we add that requirement then this whole
  2436. // method can be removed anyway.
  2437. return false;
  2438. }
  2439. // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
  2440. // equal to or lower than the given version.
  2441. KWIML_INT_uint64_t actual_compat = this->GetBackwardsCompatibility();
  2442. return (actual_compat && actual_compat <= CMake_VERSION_ENCODE(2, 4, 255));
  2443. }
  2444. cmPolicies::PolicyStatus cmLocalGenerator::GetPolicyStatus(
  2445. cmPolicies::PolicyID id) const
  2446. {
  2447. return this->Makefile->GetPolicyStatus(id);
  2448. }
  2449. bool cmLocalGenerator::CheckDefinition(std::string const& define) const
  2450. {
  2451. // Many compilers do not support -DNAME(arg)=sdf so we disable it.
  2452. std::string::size_type pos = define.find_first_of("(=");
  2453. if (pos != std::string::npos) {
  2454. if (define[pos] == '(') {
  2455. std::ostringstream e;
  2456. /* clang-format off */
  2457. e << "WARNING: Function-style preprocessor definitions may not be "
  2458. << "passed on the compiler command line because many compilers "
  2459. << "do not support it.\n"
  2460. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2461. << "Consider defining the macro in a (configured) header file.\n";
  2462. /* clang-format on */
  2463. cmSystemTools::Message(e.str().c_str());
  2464. return false;
  2465. }
  2466. }
  2467. // Many compilers do not support # in the value so we disable it.
  2468. if (define.find_first_of('#') != define.npos) {
  2469. std::ostringstream e;
  2470. /* clang-format off */
  2471. e << "WARNING: Preprocessor definitions containing '#' may not be "
  2472. << "passed on the compiler command line because many compilers "
  2473. << "do not support it.\n"
  2474. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2475. << "Consider defining the macro in a (configured) header file.\n";
  2476. /* clang-format on */
  2477. cmSystemTools::Message(e.str().c_str());
  2478. return false;
  2479. }
  2480. // Assume it is supported.
  2481. return true;
  2482. }
  2483. static void cmLGInfoProp(cmMakefile* mf, cmGeneratorTarget* target,
  2484. const std::string& prop)
  2485. {
  2486. if (const char* val = target->GetProperty(prop)) {
  2487. mf->AddDefinition(prop, val);
  2488. }
  2489. }
  2490. void cmLocalGenerator::GenerateAppleInfoPList(cmGeneratorTarget* target,
  2491. const std::string& targetName,
  2492. const char* fname)
  2493. {
  2494. // Find the Info.plist template.
  2495. const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
  2496. std::string inFile = (in && *in) ? in : "MacOSXBundleInfo.plist.in";
  2497. if (!cmSystemTools::FileIsFullPath(inFile.c_str())) {
  2498. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2499. if (!inMod.empty()) {
  2500. inFile = inMod;
  2501. }
  2502. }
  2503. if (!cmSystemTools::FileExists(inFile.c_str(), true)) {
  2504. std::ostringstream e;
  2505. e << "Target " << target->GetName() << " Info.plist template \"" << inFile
  2506. << "\" could not be found.";
  2507. cmSystemTools::Error(e.str().c_str());
  2508. return;
  2509. }
  2510. // Convert target properties to variables in an isolated makefile
  2511. // scope to configure the file. If properties are set they will
  2512. // override user make variables. If not the configuration will fall
  2513. // back to the directory-level values set by the user.
  2514. cmMakefile* mf = this->Makefile;
  2515. cmMakefile::ScopePushPop varScope(mf);
  2516. mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName.c_str());
  2517. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
  2518. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
  2519. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
  2520. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
  2521. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
  2522. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
  2523. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
  2524. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
  2525. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2526. }
  2527. void cmLocalGenerator::GenerateFrameworkInfoPList(
  2528. cmGeneratorTarget* target, const std::string& targetName, const char* fname)
  2529. {
  2530. // Find the Info.plist template.
  2531. const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
  2532. std::string inFile = (in && *in) ? in : "MacOSXFrameworkInfo.plist.in";
  2533. if (!cmSystemTools::FileIsFullPath(inFile.c_str())) {
  2534. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2535. if (!inMod.empty()) {
  2536. inFile = inMod;
  2537. }
  2538. }
  2539. if (!cmSystemTools::FileExists(inFile.c_str(), true)) {
  2540. std::ostringstream e;
  2541. e << "Target " << target->GetName() << " Info.plist template \"" << inFile
  2542. << "\" could not be found.";
  2543. cmSystemTools::Error(e.str().c_str());
  2544. return;
  2545. }
  2546. // Convert target properties to variables in an isolated makefile
  2547. // scope to configure the file. If properties are set they will
  2548. // override user make variables. If not the configuration will fall
  2549. // back to the directory-level values set by the user.
  2550. cmMakefile* mf = this->Makefile;
  2551. cmMakefile::ScopePushPop varScope(mf);
  2552. mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName.c_str());
  2553. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
  2554. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
  2555. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
  2556. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
  2557. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2558. }