cmLocalGenerator.cxx 117 KB

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