cmLocalGenerator.cxx 95 KB

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