cmLocalGenerator.cxx 97 KB

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