cmLocalGenerator.cxx 94 KB

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