cmLocalGenerator.cxx 95 KB

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