cmLocalGenerator.cxx 95 KB

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