cmLocalGenerator.cxx 116 KB

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