cmLocalGenerator.cxx 114 KB

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