cmMakefile.cxx 168 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509
  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 "cmMakefile.h"
  11. #include "cmVersion.h"
  12. #include "cmCommand.h"
  13. #include "cmSourceFile.h"
  14. #include "cmSourceFileLocation.h"
  15. #include "cmSystemTools.h"
  16. #include "cmGlobalGenerator.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmCommands.h"
  19. #include "cmState.h"
  20. #include "cmOutputConverter.h"
  21. #include "cmFunctionBlocker.h"
  22. #include "cmGeneratorExpressionEvaluationFile.h"
  23. #include "cmListFileCache.h"
  24. #include "cmCommandArgumentParserHelper.h"
  25. #include "cmGeneratorExpression.h"
  26. #include "cmTest.h"
  27. #ifdef CMAKE_BUILD_WITH_CMAKE
  28. # include "cmVariableWatch.h"
  29. #endif
  30. #include "cmInstallGenerator.h"
  31. #include "cmTestGenerator.h"
  32. #include "cmDefinitions.h"
  33. #include "cmAlgorithms.h"
  34. #include "cmake.h"
  35. #include <stdlib.h> // required for atoi
  36. #include <cmsys/RegularExpression.hxx>
  37. #include <cmsys/FStream.hxx>
  38. #include <cmsys/auto_ptr.hxx>
  39. #include <list>
  40. #include <ctype.h> // for isspace
  41. #include <assert.h>
  42. class cmMakefile::Internals
  43. {
  44. public:
  45. enum ScopeType
  46. {
  47. BaseScope,
  48. MacroScope,
  49. FunctionScope,
  50. VariableScope
  51. };
  52. struct VarScope
  53. {
  54. ScopeType Type;
  55. cmLinkedTree<cmDefinitions>::iterator Vars;
  56. cmLinkedTree<cmDefinitions>::iterator ParentScope;
  57. };
  58. cmLinkedTree<cmDefinitions> VarTree;
  59. cmLinkedTree<VarScope> VarScopes;
  60. cmLinkedTree<VarScope>::iterator VarScopeIter;
  61. bool IsSourceFileTryCompile;
  62. void PushDefinitions(ScopeType scope)
  63. {
  64. assert(this->VarScopeIter.IsValid());
  65. assert(this->VarScopeIter->Vars.IsValid());
  66. cmLinkedTree<cmDefinitions>::iterator origin =
  67. this->VarScopeIter->Vars;
  68. cmLinkedTree<cmDefinitions>::iterator parentScope =
  69. // this->VarTree.Extend(origin);
  70. origin;
  71. this->VarScopeIter->Vars = parentScope;
  72. this->VarScopeIter = this->VarScopes.Extend(this->VarScopeIter);
  73. this->VarScopeIter->ParentScope = parentScope;
  74. this->VarScopeIter->Vars = this->VarTree.Extend(origin);
  75. this->VarScopeIter->Type = scope;
  76. }
  77. void InitializeVarScope()
  78. {
  79. assert(!this->VarScopeIter.IsValid());
  80. this->VarScopeIter = this->VarScopes.Extend(this->VarScopes.Root());
  81. this->VarScopeIter->Vars = this->VarTree.Extend(this->VarTree.Root());
  82. this->VarScopeIter->ParentScope = this->VarTree.Root();
  83. this->VarScopeIter->Type = BaseScope;
  84. }
  85. void InitializeDefinitions(cmMakefile* parent)
  86. {
  87. assert(this->VarScopeIter.IsValid());
  88. assert(this->VarScopeIter->Vars.IsValid());
  89. *this->VarScopeIter->Vars =
  90. cmDefinitions::MakeClosure(parent->Internal->VarScopeIter->Vars,
  91. parent->Internal->VarTree.Root());
  92. }
  93. const char* GetDefinition(std::string const& name)
  94. {
  95. assert(this->VarScopeIter.IsValid());
  96. assert(this->VarScopeIter->Vars.IsValid());
  97. return cmDefinitions::Get(name,
  98. this->VarScopeIter->Vars, this->VarTree.Root());
  99. }
  100. bool IsInitialized(std::string const& name)
  101. {
  102. return cmDefinitions::HasKey(name,
  103. this->VarScopeIter->Vars, this->VarTree.Root());
  104. }
  105. void SetDefinition(std::string const& name, std::string const& value)
  106. {
  107. this->VarScopeIter->Vars->Set(name, value.c_str());
  108. }
  109. void RemoveDefinition(std::string const& name)
  110. {
  111. this->VarScopeIter->Vars->Set(name, 0);
  112. }
  113. std::vector<std::string> UnusedKeys() const
  114. {
  115. return this->VarScopeIter->Vars->UnusedKeys();
  116. }
  117. std::vector<std::string> ClosureKeys() const
  118. {
  119. return cmDefinitions::ClosureKeys(this->VarScopeIter->Vars,
  120. this->VarTree.Root());
  121. }
  122. void PopDefinitions()
  123. {
  124. ++this->VarScopeIter;
  125. }
  126. bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
  127. {
  128. assert(this->VarScopeIter->Vars != this->VarTree.Root());
  129. if(this->VarScopeIter->ParentScope == this->VarTree.Root())
  130. {
  131. cmLocalGenerator* plg = mf->LocalGenerator->GetParent();
  132. if(!plg)
  133. {
  134. return false;
  135. }
  136. // Update the definition in the parent directory top scope. This
  137. // directory's scope was initialized by the closure of the parent
  138. // scope, so we do not need to localize the definition first.
  139. cmMakefile* parent = plg->GetMakefile();
  140. if (varDef)
  141. {
  142. parent->AddDefinition(var, varDef);
  143. }
  144. else
  145. {
  146. parent->RemoveDefinition(var);
  147. }
  148. return true;
  149. }
  150. // First localize the definition in the current scope.
  151. cmDefinitions::Raise(var, this->VarScopeIter->Vars, this->VarTree.Root());
  152. // Now update the definition in the parent scope.
  153. this->VarScopeIter->ParentScope->Set(var, varDef);
  154. return true;
  155. }
  156. };
  157. // default is not to be building executables
  158. cmMakefile::cmMakefile(cmLocalGenerator* localGenerator)
  159. : Internal(new Internals),
  160. LocalGenerator(localGenerator),
  161. StateSnapshot(localGenerator->GetStateSnapshot())
  162. {
  163. this->Internal->InitializeVarScope();
  164. this->Internal->IsSourceFileTryCompile = false;
  165. // Initialize these first since AddDefaultDefinitions calls AddDefinition
  166. this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused();
  167. this->CheckSystemVars = this->GetCMakeInstance()->GetCheckSystemVars();
  168. this->Configured = false;
  169. this->SuppressWatches = false;
  170. // Setup the default include file regular expression (match everything).
  171. this->SetProperty("INCLUDE_REGULAR_EXPRESSION", "^.*$");
  172. // Setup the default include complaint regular expression (match nothing).
  173. this->ComplainFileRegularExpression = "^$";
  174. // Source and header file extensions that we can handle
  175. // Set up a list of source and header extensions
  176. // these are used to find files when the extension
  177. // is not given
  178. // The "c" extension MUST precede the "C" extension.
  179. this->SourceFileExtensions.push_back( "c" );
  180. this->SourceFileExtensions.push_back( "C" );
  181. this->SourceFileExtensions.push_back( "c++" );
  182. this->SourceFileExtensions.push_back( "cc" );
  183. this->SourceFileExtensions.push_back( "cpp" );
  184. this->SourceFileExtensions.push_back( "cxx" );
  185. this->SourceFileExtensions.push_back( "m" );
  186. this->SourceFileExtensions.push_back( "M" );
  187. this->SourceFileExtensions.push_back( "mm" );
  188. this->HeaderFileExtensions.push_back( "h" );
  189. this->HeaderFileExtensions.push_back( "hh" );
  190. this->HeaderFileExtensions.push_back( "h++" );
  191. this->HeaderFileExtensions.push_back( "hm" );
  192. this->HeaderFileExtensions.push_back( "hpp" );
  193. this->HeaderFileExtensions.push_back( "hxx" );
  194. this->HeaderFileExtensions.push_back( "in" );
  195. this->HeaderFileExtensions.push_back( "txx" );
  196. this->DefineFlags = " ";
  197. this->AddDefaultDefinitions();
  198. this->cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)");
  199. this->cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)");
  200. this->cmAtVarRegex.compile("(@[A-Za-z_0-9/.+-]+@)");
  201. this->cmNamedCurly.compile("^[A-Za-z0-9/_.+-]+{");
  202. this->StateSnapshot = this->StateSnapshot.GetState()
  203. ->CreatePolicyScopeSnapshot(this->StateSnapshot);
  204. // Enter a policy level for this directory.
  205. this->PushPolicy();
  206. // push empty loop block
  207. this->PushLoopBlockBarrier();
  208. // By default the check is not done. It is enabled by
  209. // cmListFileCache in the top level if necessary.
  210. this->CheckCMP0000 = false;
  211. #if defined(CMAKE_BUILD_WITH_CMAKE)
  212. this->AddSourceGroup("", "^.*$");
  213. this->AddSourceGroup
  214. ("Source Files",
  215. "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|f|f90|for|fpp"
  216. "|ftn|m|mm|rc|def|r|odl|idl|hpj|bat)$");
  217. this->AddSourceGroup("Header Files", CM_HEADER_REGEX);
  218. this->AddSourceGroup("CMake Rules", "\\.rule$");
  219. this->AddSourceGroup("Resources", "\\.plist$");
  220. this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$");
  221. #endif
  222. {
  223. const char* dir = this->GetCMakeInstance()->GetHomeDirectory();
  224. this->AddDefinition("CMAKE_SOURCE_DIR", dir);
  225. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", dir);
  226. }
  227. {
  228. const char* dir = this->GetCMakeInstance()->GetHomeOutputDirectory();
  229. this->AddDefinition("CMAKE_BINARY_DIR", dir);
  230. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", dir);
  231. }
  232. }
  233. cmMakefile::~cmMakefile()
  234. {
  235. cmDeleteAll(this->InstallGenerators);
  236. cmDeleteAll(this->TestGenerators);
  237. cmDeleteAll(this->SourceFiles);
  238. cmDeleteAll(this->Tests);
  239. cmDeleteAll(this->ImportedTargetsOwned);
  240. cmDeleteAll(this->FinalPassCommands);
  241. cmDeleteAll(this->FunctionBlockers);
  242. cmDeleteAll(this->EvaluationFiles);
  243. this->EvaluationFiles.clear();
  244. this->FunctionBlockers.clear();
  245. }
  246. //----------------------------------------------------------------------------
  247. void cmMakefile::IssueMessage(cmake::MessageType t,
  248. std::string const& text) const
  249. {
  250. // Collect context information.
  251. if(!this->ExecutionStatusStack.empty())
  252. {
  253. if((t == cmake::FATAL_ERROR) || (t == cmake::INTERNAL_ERROR))
  254. {
  255. this->ExecutionStatusStack.back()->SetNestedError(true);
  256. }
  257. this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace());
  258. }
  259. else
  260. {
  261. cmListFileContext lfc;
  262. // We are not currently executing a command. Add whatever context
  263. // information we have.
  264. lfc.FilePath = this->GetExecutionFilePath();
  265. if(!this->GetCMakeInstance()->GetIsInTryCompile())
  266. {
  267. cmOutputConverter converter(this->StateSnapshot);
  268. lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
  269. }
  270. lfc.Line = 0;
  271. this->GetCMakeInstance()->IssueMessage(t, text, lfc);
  272. }
  273. }
  274. cmStringRange cmMakefile::GetIncludeDirectoriesEntries() const
  275. {
  276. return this->StateSnapshot.GetDirectory().GetIncludeDirectoriesEntries();
  277. }
  278. cmBacktraceRange cmMakefile::GetIncludeDirectoriesBacktraces() const
  279. {
  280. return this->StateSnapshot.GetDirectory()
  281. .GetIncludeDirectoriesEntryBacktraces();
  282. }
  283. cmStringRange cmMakefile::GetCompileOptionsEntries() const
  284. {
  285. return this->StateSnapshot.GetDirectory().GetCompileOptionsEntries();
  286. }
  287. cmBacktraceRange cmMakefile::GetCompileOptionsBacktraces() const
  288. {
  289. return this->StateSnapshot.GetDirectory().GetCompileOptionsEntryBacktraces();
  290. }
  291. cmStringRange cmMakefile::GetCompileDefinitionsEntries() const
  292. {
  293. return this->StateSnapshot.GetDirectory().GetCompileDefinitionsEntries();
  294. }
  295. cmBacktraceRange cmMakefile::GetCompileDefinitionsBacktraces() const
  296. {
  297. return this->StateSnapshot.GetDirectory()
  298. .GetCompileDefinitionsEntryBacktraces();
  299. }
  300. //----------------------------------------------------------------------------
  301. cmListFileBacktrace cmMakefile::GetBacktrace() const
  302. {
  303. cmListFileBacktrace backtrace;
  304. if (!this->ContextStack.empty())
  305. {
  306. backtrace = cmListFileBacktrace(this->StateSnapshot,
  307. *this->ContextStack.back());
  308. }
  309. return backtrace;
  310. }
  311. //----------------------------------------------------------------------------
  312. cmListFileBacktrace
  313. cmMakefile::GetBacktrace(cmCommandContext const& cc) const
  314. {
  315. cmState::Snapshot snp = this->StateSnapshot;
  316. return cmListFileBacktrace(snp, cc);
  317. }
  318. //----------------------------------------------------------------------------
  319. cmListFileContext cmMakefile::GetExecutionContext() const
  320. {
  321. return cmListFileContext::FromCommandContext(
  322. *this->ContextStack.back(),
  323. this->StateSnapshot.GetExecutionListFile());
  324. }
  325. //----------------------------------------------------------------------------
  326. void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const
  327. {
  328. std::ostringstream msg;
  329. msg << this->GetExecutionFilePath() << "(" << lff.Line << "): ";
  330. msg << lff.Name << "(";
  331. bool expand = this->GetCMakeInstance()->GetTraceExpand();
  332. std::string temp;
  333. for(std::vector<cmListFileArgument>::const_iterator i =
  334. lff.Arguments.begin(); i != lff.Arguments.end(); ++i)
  335. {
  336. if (expand)
  337. {
  338. temp = i->Value;
  339. this->ExpandVariablesInString(temp);
  340. msg << temp;
  341. }
  342. else
  343. {
  344. msg << i->Value;
  345. }
  346. msg << " ";
  347. }
  348. msg << ")";
  349. cmSystemTools::Message(msg.str().c_str());
  350. }
  351. //----------------------------------------------------------------------------
  352. bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
  353. cmExecutionStatus &status)
  354. {
  355. bool result = true;
  356. // quick return if blocked
  357. if(this->IsFunctionBlocked(lff,status))
  358. {
  359. // No error.
  360. return result;
  361. }
  362. std::string name = lff.Name;
  363. // Place this call on the call stack.
  364. cmMakefileCall stack_manager(this, lff, status);
  365. static_cast<void>(stack_manager);
  366. // Lookup the command prototype.
  367. if(cmCommand* proto = this->GetState()->GetCommand(name))
  368. {
  369. // Clone the prototype.
  370. cmsys::auto_ptr<cmCommand> pcmd(proto->Clone());
  371. pcmd->SetMakefile(this);
  372. // Decide whether to invoke the command.
  373. if(pcmd->GetEnabled() && !cmSystemTools::GetFatalErrorOccured() &&
  374. (this->GetCMakeInstance()->GetWorkingMode() != cmake::SCRIPT_MODE
  375. || pcmd->IsScriptable()))
  376. {
  377. // if trace is enabled, print out invoke information
  378. if(this->GetCMakeInstance()->GetTrace())
  379. {
  380. this->PrintCommandTrace(lff);
  381. }
  382. // Try invoking the command.
  383. if(!pcmd->InvokeInitialPass(lff.Arguments,status) ||
  384. status.GetNestedError())
  385. {
  386. if(!status.GetNestedError())
  387. {
  388. // The command invocation requested that we report an error.
  389. this->IssueMessage(cmake::FATAL_ERROR, pcmd->GetError());
  390. }
  391. result = false;
  392. if ( this->GetCMakeInstance()->GetWorkingMode() != cmake::NORMAL_MODE)
  393. {
  394. cmSystemTools::SetFatalErrorOccured();
  395. }
  396. }
  397. else if(pcmd->HasFinalPass())
  398. {
  399. // use the command
  400. this->FinalPassCommands.push_back(pcmd.release());
  401. }
  402. }
  403. else if ( this->GetCMakeInstance()->GetWorkingMode() == cmake::SCRIPT_MODE
  404. && !pcmd->IsScriptable() )
  405. {
  406. std::string error = "Command ";
  407. error += pcmd->GetName();
  408. error += "() is not scriptable";
  409. this->IssueMessage(cmake::FATAL_ERROR, error);
  410. result = false;
  411. cmSystemTools::SetFatalErrorOccured();
  412. }
  413. }
  414. else
  415. {
  416. if(!cmSystemTools::GetFatalErrorOccured())
  417. {
  418. std::string error = "Unknown CMake command \"";
  419. error += lff.Name;
  420. error += "\".";
  421. this->IssueMessage(cmake::FATAL_ERROR, error);
  422. result = false;
  423. cmSystemTools::SetFatalErrorOccured();
  424. }
  425. }
  426. return result;
  427. }
  428. //----------------------------------------------------------------------------
  429. class cmMakefile::IncludeScope
  430. {
  431. public:
  432. IncludeScope(cmMakefile* mf, std::string const& filenametoread,
  433. bool noPolicyScope);
  434. ~IncludeScope();
  435. void Quiet() { this->ReportError = false; }
  436. private:
  437. cmMakefile* Makefile;
  438. bool NoPolicyScope;
  439. bool CheckCMP0011;
  440. bool ReportError;
  441. void EnforceCMP0011();
  442. };
  443. //----------------------------------------------------------------------------
  444. cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf,
  445. std::string const& filenametoread,
  446. bool noPolicyScope):
  447. Makefile(mf), NoPolicyScope(noPolicyScope),
  448. CheckCMP0011(false), ReportError(true)
  449. {
  450. this->Makefile->PushFunctionBlockerBarrier();
  451. this->Makefile->StateSnapshot =
  452. this->Makefile->GetState()->CreateCallStackSnapshot(
  453. this->Makefile->StateSnapshot,
  454. this->Makefile->ContextStack.back()->Name,
  455. this->Makefile->ContextStack.back()->Line,
  456. filenametoread);
  457. if(!this->NoPolicyScope)
  458. {
  459. // Check CMP0011 to determine the policy scope type.
  460. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0011))
  461. {
  462. case cmPolicies::WARN:
  463. // We need to push a scope to detect whether the script sets
  464. // any policies that would affect the includer and therefore
  465. // requires a warning. We use a weak scope to simulate OLD
  466. // behavior by allowing policy changes to affect the includer.
  467. this->Makefile->PushPolicy(true);
  468. this->CheckCMP0011 = true;
  469. break;
  470. case cmPolicies::OLD:
  471. // OLD behavior is to not push a scope at all.
  472. this->NoPolicyScope = true;
  473. break;
  474. case cmPolicies::REQUIRED_IF_USED:
  475. case cmPolicies::REQUIRED_ALWAYS:
  476. // We should never make this policy required, but we handle it
  477. // here just in case.
  478. this->CheckCMP0011 = true;
  479. case cmPolicies::NEW:
  480. // NEW behavior is to push a (strong) scope.
  481. this->Makefile->PushPolicy();
  482. break;
  483. }
  484. }
  485. }
  486. //----------------------------------------------------------------------------
  487. cmMakefile::IncludeScope::~IncludeScope()
  488. {
  489. if(!this->NoPolicyScope)
  490. {
  491. // If we need to enforce policy CMP0011 then the top entry is the
  492. // one we pushed above. If the entry is empty, then the included
  493. // script did not set any policies that might affect the includer so
  494. // we do not need to enforce the policy.
  495. if(this->CheckCMP0011
  496. && !this->Makefile->StateSnapshot.HasDefinedPolicyCMP0011())
  497. {
  498. this->CheckCMP0011 = false;
  499. }
  500. // Pop the scope we pushed for the script.
  501. this->Makefile->PopPolicy();
  502. // We enforce the policy after the script's policy stack entry has
  503. // been removed.
  504. if(this->CheckCMP0011)
  505. {
  506. this->EnforceCMP0011();
  507. }
  508. }
  509. this->Makefile->PopPolicyBarrier(this->ReportError);
  510. this->Makefile->PopFunctionBlockerBarrier(this->ReportError);
  511. }
  512. //----------------------------------------------------------------------------
  513. void cmMakefile::IncludeScope::EnforceCMP0011()
  514. {
  515. // We check the setting of this policy again because the included
  516. // script might actually set this policy for its includer.
  517. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0011))
  518. {
  519. case cmPolicies::WARN:
  520. // Warn because the user did not set this policy.
  521. {
  522. std::ostringstream w;
  523. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0011) << "\n"
  524. << "The included script\n "
  525. << this->Makefile->GetExecutionFilePath() << "\n"
  526. << "affects policy settings. "
  527. << "CMake is implying the NO_POLICY_SCOPE option for compatibility, "
  528. << "so the effects are applied to the including context.";
  529. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  530. }
  531. break;
  532. case cmPolicies::REQUIRED_IF_USED:
  533. case cmPolicies::REQUIRED_ALWAYS:
  534. {
  535. std::ostringstream e;
  536. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0011) << "\n"
  537. << "The included script\n "
  538. << this->Makefile->GetExecutionFilePath() << "\n"
  539. << "affects policy settings, so it requires this policy to be set.";
  540. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  541. }
  542. break;
  543. case cmPolicies::OLD:
  544. case cmPolicies::NEW:
  545. // The script set this policy. We assume the purpose of the
  546. // script is to initialize policies for its includer, and since
  547. // the policy is now set for later scripts, we do not warn.
  548. break;
  549. }
  550. }
  551. class cmParseFileScope
  552. {
  553. public:
  554. cmParseFileScope(cmMakefile* mf)
  555. : Makefile(mf)
  556. {
  557. this->Makefile->ContextStack.push_back(&this->Context);
  558. }
  559. ~cmParseFileScope()
  560. {
  561. this->Makefile->ContextStack.pop_back();
  562. }
  563. private:
  564. cmMakefile* Makefile;
  565. cmCommandContext Context;
  566. };
  567. bool cmMakefile::ReadDependentFile(const char* filename, bool noPolicyScope)
  568. {
  569. this->AddDefinition("CMAKE_PARENT_LIST_FILE",
  570. this->GetDefinition("CMAKE_CURRENT_LIST_FILE"));
  571. std::string filenametoread =
  572. cmSystemTools::CollapseFullPath(filename,
  573. this->GetCurrentSourceDirectory());
  574. IncludeScope incScope(this, filenametoread, noPolicyScope);
  575. cmListFile listFile;
  576. {
  577. cmParseFileScope pfs(this);
  578. if (!listFile.ParseFile(filenametoread.c_str(), false, this))
  579. {
  580. return false;
  581. }
  582. }
  583. this->ReadListFile(listFile, filenametoread);
  584. if(cmSystemTools::GetFatalErrorOccured())
  585. {
  586. incScope.Quiet();
  587. }
  588. return true;
  589. }
  590. class cmMakefile::ListFileScope
  591. {
  592. public:
  593. ListFileScope(cmMakefile* mf, std::string const& filenametoread)
  594. : Makefile(mf), ReportError(true)
  595. {
  596. long line = 0;
  597. std::string name;
  598. if (!this->Makefile->ContextStack.empty())
  599. {
  600. line = this->Makefile->ContextStack.back()->Line;
  601. name = this->Makefile->ContextStack.back()->Name;
  602. }
  603. this->Makefile->StateSnapshot =
  604. this->Makefile->GetState()->CreateInlineListFileSnapshot(
  605. this->Makefile->StateSnapshot, name, line, filenametoread);
  606. assert(this->Makefile->StateSnapshot.IsValid());
  607. this->Makefile->PushFunctionBlockerBarrier();
  608. }
  609. ~ListFileScope()
  610. {
  611. this->Makefile->PopPolicyBarrier(this->ReportError);
  612. this->Makefile->PopFunctionBlockerBarrier(this->ReportError);
  613. }
  614. void Quiet() { this->ReportError = false; }
  615. private:
  616. cmMakefile* Makefile;
  617. bool ReportError;
  618. };
  619. bool cmMakefile::ReadListFile(const char* filename)
  620. {
  621. std::string filenametoread =
  622. cmSystemTools::CollapseFullPath(filename,
  623. this->GetCurrentSourceDirectory());
  624. ListFileScope scope(this, filenametoread);
  625. cmListFile listFile;
  626. {
  627. cmParseFileScope pfs(this);
  628. if (!listFile.ParseFile(filenametoread.c_str(), false, this))
  629. {
  630. return false;
  631. }
  632. }
  633. this->ReadListFile(listFile, filenametoread);
  634. if(cmSystemTools::GetFatalErrorOccured())
  635. {
  636. scope.Quiet();
  637. }
  638. return true;
  639. }
  640. void cmMakefile::ReadListFile(cmListFile const& listFile,
  641. std::string const& filenametoread)
  642. {
  643. // add this list file to the list of dependencies
  644. this->ListFiles.push_back(filenametoread);
  645. std::string currentParentFile
  646. = this->GetSafeDefinition("CMAKE_PARENT_LIST_FILE");
  647. std::string currentFile
  648. = this->GetSafeDefinition("CMAKE_CURRENT_LIST_FILE");
  649. this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread.c_str());
  650. this->AddDefinition("CMAKE_CURRENT_LIST_DIR",
  651. cmSystemTools::GetFilenamePath(filenametoread).c_str());
  652. this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE");
  653. this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE");
  654. this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR");
  655. // Run the parsed commands.
  656. const size_t numberFunctions = listFile.Functions.size();
  657. for(size_t i =0; i < numberFunctions; ++i)
  658. {
  659. cmExecutionStatus status;
  660. this->ExecuteCommand(listFile.Functions[i],status);
  661. if(cmSystemTools::GetFatalErrorOccured())
  662. {
  663. break;
  664. }
  665. if(status.GetReturnInvoked())
  666. {
  667. // Exit early due to return command.
  668. break;
  669. }
  670. }
  671. this->CheckForUnusedVariables();
  672. this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str());
  673. this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
  674. this->AddDefinition("CMAKE_CURRENT_LIST_DIR",
  675. cmSystemTools::GetFilenamePath(currentFile).c_str());
  676. this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE");
  677. this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE");
  678. this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR");
  679. }
  680. //----------------------------------------------------------------------------
  681. void cmMakefile::EnforceDirectoryLevelRules() const
  682. {
  683. // Diagnose a violation of CMP0000 if necessary.
  684. if(this->CheckCMP0000)
  685. {
  686. std::ostringstream msg;
  687. msg << "No cmake_minimum_required command is present. "
  688. << "A line of code such as\n"
  689. << " cmake_minimum_required(VERSION "
  690. << cmVersion::GetMajorVersion() << "."
  691. << cmVersion::GetMinorVersion()
  692. << ")\n"
  693. << "should be added at the top of the file. "
  694. << "The version specified may be lower if you wish to "
  695. << "support older CMake versions for this project. "
  696. << "For more information run "
  697. << "\"cmake --help-policy CMP0000\".";
  698. switch (this->GetPolicyStatus(cmPolicies::CMP0000))
  699. {
  700. case cmPolicies::WARN:
  701. // Warn because the user did not provide a mimimum required
  702. // version.
  703. this->IssueMessage(cmake::AUTHOR_WARNING, msg.str());
  704. case cmPolicies::OLD:
  705. // OLD behavior is to use policy version 2.4 set in
  706. // cmListFileCache.
  707. break;
  708. case cmPolicies::REQUIRED_IF_USED:
  709. case cmPolicies::REQUIRED_ALWAYS:
  710. case cmPolicies::NEW:
  711. // NEW behavior is to issue an error.
  712. this->IssueMessage(cmake::FATAL_ERROR, msg.str());
  713. cmSystemTools::SetFatalErrorOccured();
  714. return;
  715. }
  716. }
  717. }
  718. void cmMakefile::AddEvaluationFile(const std::string& inputFile,
  719. cmsys::auto_ptr<cmCompiledGeneratorExpression> outputName,
  720. cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
  721. bool inputIsContent)
  722. {
  723. this->EvaluationFiles.push_back(
  724. new cmGeneratorExpressionEvaluationFile(inputFile, outputName,
  725. condition,
  726. inputIsContent));
  727. }
  728. std::vector<cmGeneratorExpressionEvaluationFile*>
  729. cmMakefile::GetEvaluationFiles() const
  730. {
  731. return this->EvaluationFiles;
  732. }
  733. namespace
  734. {
  735. struct file_not_persistent
  736. {
  737. bool operator()(const std::string& path) const
  738. {
  739. return !(path.find("CMakeTmp") == path.npos &&
  740. cmSystemTools::FileExists(path.c_str()));
  741. }
  742. };
  743. }
  744. void cmMakefile::FinalPass()
  745. {
  746. // do all the variable expansions here
  747. this->ExpandVariablesCMP0019();
  748. // give all the commands a chance to do something
  749. // after the file has been parsed before generation
  750. for(std::vector<cmCommand*>::iterator i = this->FinalPassCommands.begin();
  751. i != this->FinalPassCommands.end(); ++i)
  752. {
  753. (*i)->FinalPass();
  754. }
  755. //go through all configured files and see which ones still exist.
  756. //we don't want cmake to re-run if a configured file is created and deleted
  757. //during processing as that would make it a transient file that can't
  758. //influence the build process
  759. //remove_if will move all items that don't have a valid file name to the
  760. //back of the vector
  761. std::vector<std::string>::iterator new_output_files_end = std::remove_if(
  762. this->OutputFiles.begin(),
  763. this->OutputFiles.end(),
  764. file_not_persistent() );
  765. //we just have to erase all items at the back
  766. this->OutputFiles.erase(new_output_files_end, this->OutputFiles.end() );
  767. //if a configured file is used as input for another configured file,
  768. //and then deleted it will show up in the input list files so we
  769. //need to scan those too
  770. std::vector<std::string>::iterator new_list_files_end = std::remove_if(
  771. this->ListFiles.begin(),
  772. this->ListFiles.end(),
  773. file_not_persistent() );
  774. this->ListFiles.erase(new_list_files_end, this->ListFiles.end() );
  775. }
  776. // Generate the output file
  777. void cmMakefile::ConfigureFinalPass()
  778. {
  779. this->FinalPass();
  780. const char* oldValue
  781. = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  782. if (oldValue && cmSystemTools::VersionCompare(
  783. cmSystemTools::OP_LESS, oldValue, "2.4"))
  784. {
  785. this->IssueMessage(
  786. cmake::FATAL_ERROR,
  787. "You have set CMAKE_BACKWARDS_COMPATIBILITY to a CMake version less "
  788. "than 2.4. This version of CMake only supports backwards compatibility "
  789. "with CMake 2.4 or later. For compatibility with older versions please "
  790. "use any CMake 2.8.x release or lower.");
  791. }
  792. for (cmTargets::iterator l = this->Targets.begin();
  793. l != this->Targets.end(); l++)
  794. {
  795. if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  796. {
  797. continue;
  798. }
  799. l->second.FinishConfigure();
  800. }
  801. }
  802. //----------------------------------------------------------------------------
  803. void
  804. cmMakefile::AddCustomCommandToTarget(const std::string& target,
  805. const std::vector<std::string>& byproducts,
  806. const std::vector<std::string>& depends,
  807. const cmCustomCommandLines& commandLines,
  808. cmTarget::CustomCommandType type,
  809. const char* comment,
  810. const char* workingDir,
  811. bool escapeOldStyle,
  812. bool uses_terminal)
  813. {
  814. // Find the target to which to add the custom command.
  815. cmTargets::iterator ti = this->Targets.find(target);
  816. if(ti == this->Targets.end())
  817. {
  818. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  819. bool issueMessage = false;
  820. std::ostringstream e;
  821. switch(this->GetPolicyStatus(cmPolicies::CMP0040))
  822. {
  823. case cmPolicies::WARN:
  824. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0040) << "\n";
  825. issueMessage = true;
  826. case cmPolicies::OLD:
  827. break;
  828. case cmPolicies::NEW:
  829. case cmPolicies::REQUIRED_IF_USED:
  830. case cmPolicies::REQUIRED_ALWAYS:
  831. issueMessage = true;
  832. messageType = cmake::FATAL_ERROR;
  833. }
  834. if(issueMessage)
  835. {
  836. e << "The target name \"" << target << "\" is unknown in this context.";
  837. IssueMessage(messageType, e.str());
  838. }
  839. return;
  840. }
  841. if(ti->second.GetType() == cmTarget::OBJECT_LIBRARY)
  842. {
  843. std::ostringstream e;
  844. e << "Target \"" << target << "\" is an OBJECT library "
  845. "that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands.";
  846. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  847. return;
  848. }
  849. if(ti->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  850. {
  851. std::ostringstream e;
  852. e << "Target \"" << target << "\" is an INTERFACE library "
  853. "that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands.";
  854. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  855. return;
  856. }
  857. // Always create the byproduct sources and mark them generated.
  858. for(std::vector<std::string>::const_iterator o = byproducts.begin();
  859. o != byproducts.end(); ++o)
  860. {
  861. if(cmSourceFile* out = this->GetOrCreateSource(*o, true))
  862. {
  863. out->SetProperty("GENERATED", "1");
  864. }
  865. }
  866. // Add the command to the appropriate build step for the target.
  867. std::vector<std::string> no_output;
  868. cmCustomCommand cc(this, no_output, byproducts, depends,
  869. commandLines, comment, workingDir);
  870. cc.SetEscapeOldStyle(escapeOldStyle);
  871. cc.SetEscapeAllowMakeVars(true);
  872. cc.SetUsesTerminal(uses_terminal);
  873. switch(type)
  874. {
  875. case cmTarget::PRE_BUILD:
  876. ti->second.AddPreBuildCommand(cc);
  877. break;
  878. case cmTarget::PRE_LINK:
  879. ti->second.AddPreLinkCommand(cc);
  880. break;
  881. case cmTarget::POST_BUILD:
  882. ti->second.AddPostBuildCommand(cc);
  883. break;
  884. }
  885. }
  886. //----------------------------------------------------------------------------
  887. cmSourceFile*
  888. cmMakefile::AddCustomCommandToOutput(const std::vector<std::string>& outputs,
  889. const std::vector<std::string>& byproducts,
  890. const std::vector<std::string>& depends,
  891. const std::string& main_dependency,
  892. const cmCustomCommandLines& commandLines,
  893. const char* comment,
  894. const char* workingDir,
  895. bool replace,
  896. bool escapeOldStyle,
  897. bool uses_terminal)
  898. {
  899. // Make sure there is at least one output.
  900. if(outputs.empty())
  901. {
  902. cmSystemTools::Error("Attempt to add a custom rule with no output!");
  903. return 0;
  904. }
  905. // Validate custom commands. TODO: More strict?
  906. for(cmCustomCommandLines::const_iterator i=commandLines.begin();
  907. i != commandLines.end(); ++i)
  908. {
  909. cmCustomCommandLine const& cl = *i;
  910. if(!cl.empty() && !cl[0].empty() && cl[0][0] == '"')
  911. {
  912. std::ostringstream e;
  913. e << "COMMAND may not contain literal quotes:\n " << cl[0] << "\n";
  914. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  915. return 0;
  916. }
  917. }
  918. // Choose a source file on which to store the custom command.
  919. cmSourceFile* file = 0;
  920. if(!commandLines.empty() && !main_dependency.empty())
  921. {
  922. // The main dependency was specified. Use it unless a different
  923. // custom command already used it.
  924. file = this->GetSource(main_dependency);
  925. if(file && file->GetCustomCommand() && !replace)
  926. {
  927. // The main dependency already has a custom command.
  928. if(commandLines == file->GetCustomCommand()->GetCommandLines())
  929. {
  930. // The existing custom command is identical. Silently ignore
  931. // the duplicate.
  932. return file;
  933. }
  934. else
  935. {
  936. // The existing custom command is different. We need to
  937. // generate a rule file for this new command.
  938. file = 0;
  939. }
  940. }
  941. else if (!file)
  942. {
  943. file = this->CreateSource(main_dependency);
  944. }
  945. }
  946. // Generate a rule file if the main dependency is not available.
  947. if(!file)
  948. {
  949. cmGlobalGenerator* gg = this->GetGlobalGenerator();
  950. // Construct a rule file associated with the first output produced.
  951. std::string outName = gg->GenerateRuleFile(outputs[0]);
  952. // Check if the rule file already exists.
  953. file = this->GetSource(outName);
  954. if(file && file->GetCustomCommand() && !replace)
  955. {
  956. // The rule file already exists.
  957. if(commandLines != file->GetCustomCommand()->GetCommandLines())
  958. {
  959. cmSystemTools::Error("Attempt to add a custom rule to output \"",
  960. outName.c_str(),
  961. "\" which already has a custom rule.");
  962. }
  963. return file;
  964. }
  965. // Create a cmSourceFile for the rule file.
  966. if (!file)
  967. {
  968. file = this->CreateSource(outName, true);
  969. }
  970. file->SetProperty("__CMAKE_RULE", "1");
  971. }
  972. // Always create the output sources and mark them generated.
  973. for(std::vector<std::string>::const_iterator o = outputs.begin();
  974. o != outputs.end(); ++o)
  975. {
  976. if(cmSourceFile* out = this->GetOrCreateSource(*o, true))
  977. {
  978. out->SetProperty("GENERATED", "1");
  979. }
  980. }
  981. for(std::vector<std::string>::const_iterator o = byproducts.begin();
  982. o != byproducts.end(); ++o)
  983. {
  984. if(cmSourceFile* out = this->GetOrCreateSource(*o, true))
  985. {
  986. out->SetProperty("GENERATED", "1");
  987. }
  988. }
  989. // Attach the custom command to the file.
  990. if(file)
  991. {
  992. // Construct a complete list of dependencies.
  993. std::vector<std::string> depends2(depends);
  994. if(!main_dependency.empty())
  995. {
  996. depends2.push_back(main_dependency);
  997. }
  998. cmCustomCommand* cc =
  999. new cmCustomCommand(this, outputs, byproducts, depends2,
  1000. commandLines, comment, workingDir);
  1001. cc->SetEscapeOldStyle(escapeOldStyle);
  1002. cc->SetEscapeAllowMakeVars(true);
  1003. cc->SetUsesTerminal(uses_terminal);
  1004. file->SetCustomCommand(cc);
  1005. this->UpdateOutputToSourceMap(outputs, file);
  1006. }
  1007. return file;
  1008. }
  1009. //----------------------------------------------------------------------------
  1010. void
  1011. cmMakefile::UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
  1012. cmSourceFile* source)
  1013. {
  1014. for(std::vector<std::string>::const_iterator o = outputs.begin();
  1015. o != outputs.end(); ++o)
  1016. {
  1017. this->UpdateOutputToSourceMap(*o, source);
  1018. }
  1019. }
  1020. //----------------------------------------------------------------------------
  1021. void
  1022. cmMakefile::UpdateOutputToSourceMap(std::string const& output,
  1023. cmSourceFile* source)
  1024. {
  1025. OutputToSourceMap::iterator i = this->OutputToSource.find(output);
  1026. if(i != this->OutputToSource.end())
  1027. {
  1028. // Multiple custom commands produce the same output but may
  1029. // be attached to a different source file (MAIN_DEPENDENCY).
  1030. // LinearGetSourceFileWithOutput would return the first one,
  1031. // so keep the mapping for the first one.
  1032. //
  1033. // TODO: Warn the user about this case. However, the VS 8 generator
  1034. // triggers it for separate generate.stamp rules in ZERO_CHECK and
  1035. // individual targets.
  1036. return;
  1037. }
  1038. this->OutputToSource[output] = source;
  1039. }
  1040. //----------------------------------------------------------------------------
  1041. cmSourceFile*
  1042. cmMakefile::AddCustomCommandToOutput(const std::string& output,
  1043. const std::vector<std::string>& depends,
  1044. const std::string& main_dependency,
  1045. const cmCustomCommandLines& commandLines,
  1046. const char* comment,
  1047. const char* workingDir,
  1048. bool replace,
  1049. bool escapeOldStyle,
  1050. bool uses_terminal)
  1051. {
  1052. std::vector<std::string> outputs;
  1053. outputs.push_back(output);
  1054. std::vector<std::string> no_byproducts;
  1055. return this->AddCustomCommandToOutput(outputs, no_byproducts,
  1056. depends, main_dependency,
  1057. commandLines, comment, workingDir,
  1058. replace, escapeOldStyle,
  1059. uses_terminal);
  1060. }
  1061. //----------------------------------------------------------------------------
  1062. void
  1063. cmMakefile::AddCustomCommandOldStyle(const std::string& target,
  1064. const std::vector<std::string>& outputs,
  1065. const std::vector<std::string>& depends,
  1066. const std::string& source,
  1067. const cmCustomCommandLines& commandLines,
  1068. const char* comment)
  1069. {
  1070. // Translate the old-style signature to one of the new-style
  1071. // signatures.
  1072. if(source == target)
  1073. {
  1074. // In the old-style signature if the source and target were the
  1075. // same then it added a post-build rule to the target. Preserve
  1076. // this behavior.
  1077. std::vector<std::string> no_byproducts;
  1078. this->AddCustomCommandToTarget(target, no_byproducts,
  1079. depends, commandLines,
  1080. cmTarget::POST_BUILD, comment, 0);
  1081. return;
  1082. }
  1083. // Each output must get its own copy of this rule.
  1084. cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|"
  1085. "rc|def|r|odl|idl|hpj|bat|h|h\\+\\+|"
  1086. "hm|hpp|hxx|in|txx|inl)$");
  1087. for(std::vector<std::string>::const_iterator oi = outputs.begin();
  1088. oi != outputs.end(); ++oi)
  1089. {
  1090. // Get the name of this output.
  1091. const char* output = oi->c_str();
  1092. cmSourceFile* sf;
  1093. // Choose whether to use a main dependency.
  1094. if(sourceFiles.find(source))
  1095. {
  1096. // The source looks like a real file. Use it as the main dependency.
  1097. sf = this->AddCustomCommandToOutput(output, depends, source,
  1098. commandLines, comment, 0);
  1099. }
  1100. else
  1101. {
  1102. // The source may not be a real file. Do not use a main dependency.
  1103. std::string no_main_dependency = "";
  1104. std::vector<std::string> depends2 = depends;
  1105. depends2.push_back(source);
  1106. sf = this->AddCustomCommandToOutput(output, depends2, no_main_dependency,
  1107. commandLines, comment, 0);
  1108. }
  1109. // If the rule was added to the source (and not a .rule file),
  1110. // then add the source to the target to make sure the rule is
  1111. // included.
  1112. if(sf && !sf->GetPropertyAsBool("__CMAKE_RULE"))
  1113. {
  1114. if (this->Targets.find(target) != this->Targets.end())
  1115. {
  1116. this->Targets[target].AddSource(sf->GetFullPath());
  1117. }
  1118. else
  1119. {
  1120. cmSystemTools::Error("Attempt to add a custom rule to a target "
  1121. "that does not exist yet for target ",
  1122. target.c_str());
  1123. return;
  1124. }
  1125. }
  1126. }
  1127. }
  1128. //----------------------------------------------------------------------------
  1129. cmTarget*
  1130. cmMakefile::AddUtilityCommand(const std::string& utilityName,
  1131. bool excludeFromAll,
  1132. const std::vector<std::string>& depends,
  1133. const char* workingDirectory,
  1134. const char* command,
  1135. const char* arg1,
  1136. const char* arg2,
  1137. const char* arg3,
  1138. const char* arg4)
  1139. {
  1140. // Construct the command line for the custom command.
  1141. cmCustomCommandLine commandLine;
  1142. commandLine.push_back(command);
  1143. if(arg1)
  1144. {
  1145. commandLine.push_back(arg1);
  1146. }
  1147. if(arg2)
  1148. {
  1149. commandLine.push_back(arg2);
  1150. }
  1151. if(arg3)
  1152. {
  1153. commandLine.push_back(arg3);
  1154. }
  1155. if(arg4)
  1156. {
  1157. commandLine.push_back(arg4);
  1158. }
  1159. cmCustomCommandLines commandLines;
  1160. commandLines.push_back(commandLine);
  1161. // Call the real signature of this method.
  1162. return this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory,
  1163. depends, commandLines);
  1164. }
  1165. //----------------------------------------------------------------------------
  1166. cmTarget*
  1167. cmMakefile::AddUtilityCommand(const std::string& utilityName,
  1168. bool excludeFromAll,
  1169. const char* workingDirectory,
  1170. const std::vector<std::string>& depends,
  1171. const cmCustomCommandLines& commandLines,
  1172. bool escapeOldStyle, const char* comment,
  1173. bool uses_terminal)
  1174. {
  1175. std::vector<std::string> no_byproducts;
  1176. return this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory,
  1177. no_byproducts, depends, commandLines,
  1178. escapeOldStyle, comment, uses_terminal);
  1179. }
  1180. //----------------------------------------------------------------------------
  1181. cmTarget*
  1182. cmMakefile::AddUtilityCommand(const std::string& utilityName,
  1183. bool excludeFromAll,
  1184. const char* workingDirectory,
  1185. const std::vector<std::string>& byproducts,
  1186. const std::vector<std::string>& depends,
  1187. const cmCustomCommandLines& commandLines,
  1188. bool escapeOldStyle, const char* comment,
  1189. bool uses_terminal)
  1190. {
  1191. // Create a target instance for this utility.
  1192. cmTarget* target = this->AddNewTarget(cmTarget::UTILITY, utilityName);
  1193. if (excludeFromAll)
  1194. {
  1195. target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
  1196. }
  1197. if(!comment)
  1198. {
  1199. // Use an empty comment to avoid generation of default comment.
  1200. comment = "";
  1201. }
  1202. // Store the custom command in the target.
  1203. if (!commandLines.empty() || !depends.empty())
  1204. {
  1205. std::string force = this->GetCurrentBinaryDirectory();
  1206. force += cmake::GetCMakeFilesDirectory();
  1207. force += "/";
  1208. force += utilityName;
  1209. std::vector<std::string> forced;
  1210. forced.push_back(force);
  1211. std::string no_main_dependency = "";
  1212. bool no_replace = false;
  1213. this->AddCustomCommandToOutput(forced, byproducts,
  1214. depends, no_main_dependency,
  1215. commandLines, comment,
  1216. workingDirectory, no_replace,
  1217. escapeOldStyle, uses_terminal);
  1218. cmSourceFile* sf = target->AddSourceCMP0049(force);
  1219. // The output is not actually created so mark it symbolic.
  1220. if(sf)
  1221. {
  1222. sf->SetProperty("SYMBOLIC", "1");
  1223. }
  1224. else
  1225. {
  1226. cmSystemTools::Error("Could not get source file entry for ",
  1227. force.c_str());
  1228. }
  1229. // Always create the byproduct sources and mark them generated.
  1230. for(std::vector<std::string>::const_iterator o = byproducts.begin();
  1231. o != byproducts.end(); ++o)
  1232. {
  1233. if(cmSourceFile* out = this->GetOrCreateSource(*o, true))
  1234. {
  1235. out->SetProperty("GENERATED", "1");
  1236. }
  1237. }
  1238. }
  1239. return target;
  1240. }
  1241. void cmMakefile::AddDefineFlag(const char* flag)
  1242. {
  1243. if (!flag)
  1244. {
  1245. return;
  1246. }
  1247. // Update the string used for the old DEFINITIONS property.
  1248. this->AddDefineFlag(flag, this->DefineFlagsOrig);
  1249. // If this is really a definition, update COMPILE_DEFINITIONS.
  1250. if(this->ParseDefineFlag(flag, false))
  1251. {
  1252. return;
  1253. }
  1254. // Add this flag that does not look like a definition.
  1255. this->AddDefineFlag(flag, this->DefineFlags);
  1256. }
  1257. void cmMakefile::AddDefineFlag(const char* flag, std::string& dflags)
  1258. {
  1259. // remove any \n\r
  1260. std::string::size_type initSize = dflags.size();
  1261. dflags += std::string(" ") + flag;
  1262. std::string::iterator flagStart = dflags.begin() + initSize + 1;
  1263. std::replace(flagStart, dflags.end(), '\n', ' ');
  1264. std::replace(flagStart, dflags.end(), '\r', ' ');
  1265. }
  1266. void cmMakefile::RemoveDefineFlag(const char* flag)
  1267. {
  1268. // Check the length of the flag to remove.
  1269. std::string::size_type len = strlen(flag);
  1270. if(len < 1)
  1271. {
  1272. return;
  1273. }
  1274. // Update the string used for the old DEFINITIONS property.
  1275. this->RemoveDefineFlag(flag, len, this->DefineFlagsOrig);
  1276. // If this is really a definition, update COMPILE_DEFINITIONS.
  1277. if(this->ParseDefineFlag(flag, true))
  1278. {
  1279. return;
  1280. }
  1281. // Remove this flag that does not look like a definition.
  1282. this->RemoveDefineFlag(flag, len, this->DefineFlags);
  1283. }
  1284. void cmMakefile::RemoveDefineFlag(const char* flag,
  1285. std::string::size_type len,
  1286. std::string& dflags)
  1287. {
  1288. // Remove all instances of the flag that are surrounded by
  1289. // whitespace or the beginning/end of the string.
  1290. for(std::string::size_type lpos = dflags.find(flag, 0);
  1291. lpos != std::string::npos; lpos = dflags.find(flag, lpos))
  1292. {
  1293. std::string::size_type rpos = lpos + len;
  1294. if((lpos <= 0 || isspace(dflags[lpos-1])) &&
  1295. (rpos >= dflags.size() || isspace(dflags[rpos])))
  1296. {
  1297. dflags.erase(lpos, len);
  1298. }
  1299. else
  1300. {
  1301. ++lpos;
  1302. }
  1303. }
  1304. }
  1305. void cmMakefile::AddCompileOption(const char* option)
  1306. {
  1307. this->AppendProperty("COMPILE_OPTIONS", option);
  1308. }
  1309. bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
  1310. {
  1311. // Create a regular expression to match valid definitions.
  1312. static cmsys::RegularExpression
  1313. valid("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=.*)?$");
  1314. // Make sure the definition matches.
  1315. if(!valid.find(def.c_str()))
  1316. {
  1317. return false;
  1318. }
  1319. // VS6 IDE does not support definition values with spaces in
  1320. // combination with '"', '$', or ';'.
  1321. if((this->GetGlobalGenerator()->GetName() == "Visual Studio 6") &&
  1322. (def.find(" ") != def.npos && def.find_first_of("\"$;") != def.npos))
  1323. {
  1324. return false;
  1325. }
  1326. // Definitions with non-trivial values require a policy check.
  1327. static cmsys::RegularExpression
  1328. trivial("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=[A-Za-z0-9_.]+)?$");
  1329. if(!trivial.find(def.c_str()))
  1330. {
  1331. // This definition has a non-trivial value.
  1332. switch(this->GetPolicyStatus(cmPolicies::CMP0005))
  1333. {
  1334. case cmPolicies::WARN:
  1335. this->IssueMessage(
  1336. cmake::AUTHOR_WARNING,
  1337. cmPolicies::GetPolicyWarning(cmPolicies::CMP0005)
  1338. );
  1339. case cmPolicies::OLD:
  1340. // OLD behavior is to not escape the value. We should not
  1341. // convert the definition to use the property.
  1342. return false;
  1343. case cmPolicies::REQUIRED_IF_USED:
  1344. case cmPolicies::REQUIRED_ALWAYS:
  1345. this->IssueMessage(
  1346. cmake::FATAL_ERROR,
  1347. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0005)
  1348. );
  1349. return false;
  1350. case cmPolicies::NEW:
  1351. // NEW behavior is to escape the value. Proceed to convert it
  1352. // to an entry in the property.
  1353. break;
  1354. }
  1355. }
  1356. // Get the definition part after the flag.
  1357. const char* define = def.c_str() + 2;
  1358. if(remove)
  1359. {
  1360. if(const char* cdefs = this->GetProperty("COMPILE_DEFINITIONS"))
  1361. {
  1362. // Expand the list.
  1363. std::vector<std::string> defs;
  1364. cmSystemTools::ExpandListArgument(cdefs, defs);
  1365. // Recompose the list without the definition.
  1366. std::vector<std::string>::const_iterator defEnd =
  1367. std::remove(defs.begin(), defs.end(), define);
  1368. std::vector<std::string>::const_iterator defBegin =
  1369. defs.begin();
  1370. std::string ndefs = cmJoin(cmMakeRange(defBegin, defEnd), ";");
  1371. // Store the new list.
  1372. this->SetProperty("COMPILE_DEFINITIONS", ndefs.c_str());
  1373. }
  1374. }
  1375. else
  1376. {
  1377. // Append the definition to the directory property.
  1378. this->AppendProperty("COMPILE_DEFINITIONS", define);
  1379. }
  1380. return true;
  1381. }
  1382. void cmMakefile::AddLinkLibrary(const std::string& lib,
  1383. cmTarget::LinkLibraryType llt)
  1384. {
  1385. cmTarget::LibraryID tmp;
  1386. tmp.first = lib;
  1387. tmp.second = llt;
  1388. this->LinkLibraries.push_back(tmp);
  1389. }
  1390. void cmMakefile::AddLinkLibraryForTarget(const std::string& target,
  1391. const std::string& lib,
  1392. cmTarget::LinkLibraryType llt)
  1393. {
  1394. cmTargets::iterator i = this->Targets.find(target);
  1395. if ( i != this->Targets.end())
  1396. {
  1397. cmTarget* tgt = this->GetGlobalGenerator()->FindTarget(lib);
  1398. if(tgt)
  1399. {
  1400. // if it is not a static or shared library then you can not link to it
  1401. if(!((tgt->GetType() == cmTarget::STATIC_LIBRARY) ||
  1402. (tgt->GetType() == cmTarget::SHARED_LIBRARY) ||
  1403. (tgt->GetType() == cmTarget::INTERFACE_LIBRARY) ||
  1404. tgt->IsExecutableWithExports()))
  1405. {
  1406. std::ostringstream e;
  1407. e << "Target \"" << lib << "\" of type "
  1408. << cmTarget::GetTargetTypeName(tgt->GetType())
  1409. << " may not be linked into another target. "
  1410. << "One may link only to STATIC or SHARED libraries, or "
  1411. << "to executables with the ENABLE_EXPORTS property set.";
  1412. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  1413. }
  1414. }
  1415. i->second.AddLinkLibrary( *this, target, lib, llt );
  1416. }
  1417. else
  1418. {
  1419. std::ostringstream e;
  1420. e << "Attempt to add link library \""
  1421. << lib << "\" to target \""
  1422. << target << "\" which is not built in this directory.";
  1423. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  1424. }
  1425. }
  1426. void cmMakefile::AddLinkDirectoryForTarget(const std::string& target,
  1427. const std::string& d)
  1428. {
  1429. cmTargets::iterator i = this->Targets.find(target);
  1430. if ( i != this->Targets.end())
  1431. {
  1432. if(this->IsAlias(target))
  1433. {
  1434. std::ostringstream e;
  1435. e << "ALIAS target \"" << target << "\" "
  1436. << "may not be linked into another target.";
  1437. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  1438. return;
  1439. }
  1440. i->second.AddLinkDirectory( d );
  1441. }
  1442. else
  1443. {
  1444. cmSystemTools::Error
  1445. ("Attempt to add link directories to non-existent target: ",
  1446. target.c_str(), " for directory ", d.c_str());
  1447. }
  1448. }
  1449. void cmMakefile::AddLinkLibrary(const std::string& lib)
  1450. {
  1451. this->AddLinkLibrary(lib,cmTarget::GENERAL);
  1452. }
  1453. void cmMakefile::InitializeFromParent(cmMakefile* parent)
  1454. {
  1455. // Initialize definitions with the closure of the parent scope.
  1456. this->Internal->InitializeDefinitions(parent);
  1457. this->StateSnapshot.InitializeFromParent();
  1458. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  1459. this->GetCurrentSourceDirectory());
  1460. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  1461. this->GetCurrentBinaryDirectory());
  1462. this->SystemIncludeDirectories = parent->SystemIncludeDirectories;
  1463. // define flags
  1464. this->DefineFlags = parent->DefineFlags;
  1465. this->DefineFlagsOrig = parent->DefineFlagsOrig;
  1466. // Include transform property. There is no per-config version.
  1467. {
  1468. const char* prop = "IMPLICIT_DEPENDS_INCLUDE_TRANSFORM";
  1469. this->SetProperty(prop, parent->GetProperty(prop));
  1470. }
  1471. // compile definitions property and per-config versions
  1472. cmPolicies::PolicyStatus polSt = this->GetPolicyStatus(cmPolicies::CMP0043);
  1473. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
  1474. {
  1475. this->SetProperty("COMPILE_DEFINITIONS",
  1476. parent->GetProperty("COMPILE_DEFINITIONS"));
  1477. std::vector<std::string> configs;
  1478. this->GetConfigurations(configs);
  1479. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1480. ci != configs.end(); ++ci)
  1481. {
  1482. std::string defPropName = "COMPILE_DEFINITIONS_";
  1483. defPropName += cmSystemTools::UpperCase(*ci);
  1484. const char* prop = parent->GetProperty(defPropName);
  1485. this->SetProperty(defPropName, prop);
  1486. }
  1487. }
  1488. // link libraries
  1489. this->LinkLibraries = parent->LinkLibraries;
  1490. // link directories
  1491. this->SetProperty("LINK_DIRECTORIES",
  1492. parent->GetProperty("LINK_DIRECTORIES"));
  1493. // the initial project name
  1494. this->ProjectName = parent->ProjectName;
  1495. // Copy include regular expressions.
  1496. this->ComplainFileRegularExpression = parent->ComplainFileRegularExpression;
  1497. // Imported targets.
  1498. this->ImportedTargets = parent->ImportedTargets;
  1499. }
  1500. void cmMakefile::PushFunctionScope(std::string const& fileName,
  1501. const cmPolicies::PolicyMap& pm)
  1502. {
  1503. this->StateSnapshot =
  1504. this->GetState()->CreateFunctionCallSnapshot(
  1505. this->StateSnapshot,
  1506. this->ContextStack.back()->Name, this->ContextStack.back()->Line,
  1507. fileName);
  1508. assert(this->StateSnapshot.IsValid());
  1509. this->Internal->PushDefinitions(Internals::FunctionScope);
  1510. this->PushLoopBlockBarrier();
  1511. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1512. this->GetGlobalGenerator()->GetFileLockPool().PushFunctionScope();
  1513. #endif
  1514. this->PushFunctionBlockerBarrier();
  1515. this->PushPolicy(true, pm);
  1516. }
  1517. void cmMakefile::PopFunctionScope(bool reportError)
  1518. {
  1519. this->PopPolicy();
  1520. this->PopPolicyBarrier(reportError);
  1521. this->PopFunctionBlockerBarrier(reportError);
  1522. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1523. this->GetGlobalGenerator()->GetFileLockPool().PopFunctionScope();
  1524. #endif
  1525. this->PopLoopBlockBarrier();
  1526. this->CheckForUnusedVariables();
  1527. this->Internal->PopDefinitions();
  1528. }
  1529. void cmMakefile::PushMacroScope(std::string const& fileName,
  1530. const cmPolicies::PolicyMap& pm)
  1531. {
  1532. this->StateSnapshot =
  1533. this->GetState()->CreateMacroCallSnapshot(
  1534. this->StateSnapshot,
  1535. this->ContextStack.back()->Name, this->ContextStack.back()->Line,
  1536. fileName);
  1537. assert(this->StateSnapshot.IsValid());
  1538. this->PushFunctionBlockerBarrier();
  1539. this->PushPolicy(true, pm);
  1540. }
  1541. void cmMakefile::PopMacroScope(bool reportError)
  1542. {
  1543. this->PopPolicy();
  1544. this->PopPolicyBarrier(reportError);
  1545. this->PopFunctionBlockerBarrier(reportError);
  1546. }
  1547. bool cmMakefile::IsRootMakefile() const
  1548. {
  1549. return !this->StateSnapshot.GetBuildsystemDirectoryParent().IsValid();
  1550. }
  1551. class cmMakefile::BuildsystemFileScope
  1552. {
  1553. public:
  1554. BuildsystemFileScope(cmMakefile* mf)
  1555. : Makefile(mf), ReportError(true)
  1556. {
  1557. std::string currentStart =
  1558. this->Makefile->StateSnapshot.GetDirectory().GetCurrentSource();
  1559. currentStart += "/CMakeLists.txt";
  1560. this->Makefile->StateSnapshot.SetListFile(currentStart);
  1561. this->Makefile->StateSnapshot = this->Makefile->StateSnapshot.GetState()
  1562. ->CreatePolicyScopeSnapshot(this->Makefile->StateSnapshot);
  1563. this->Makefile->PushFunctionBlockerBarrier();
  1564. this->GG = mf->GetGlobalGenerator();
  1565. this->CurrentMakefile = this->GG->GetCurrentMakefile();
  1566. this->Snapshot = this->GG->GetCMakeInstance()->GetCurrentSnapshot();
  1567. this->GG->GetCMakeInstance()->SetCurrentSnapshot(this->Snapshot);
  1568. this->GG->SetCurrentMakefile(mf);
  1569. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1570. this->GG->GetFileLockPool().PushFileScope();
  1571. #endif
  1572. }
  1573. ~BuildsystemFileScope()
  1574. {
  1575. this->Makefile->PopFunctionBlockerBarrier(this->ReportError);
  1576. this->Makefile->PopPolicyBarrier(this->ReportError);
  1577. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1578. this->GG->GetFileLockPool().PopFileScope();
  1579. #endif
  1580. this->GG->SetCurrentMakefile(this->CurrentMakefile);
  1581. this->GG->GetCMakeInstance()->SetCurrentSnapshot(this->Snapshot);
  1582. }
  1583. void Quiet() { this->ReportError = false; }
  1584. private:
  1585. cmMakefile* Makefile;
  1586. cmGlobalGenerator* GG;
  1587. cmMakefile* CurrentMakefile;
  1588. cmState::Snapshot Snapshot;
  1589. bool ReportError;
  1590. };
  1591. //----------------------------------------------------------------------------
  1592. void cmMakefile::Configure()
  1593. {
  1594. BuildsystemFileScope scope(this);
  1595. // make sure the CMakeFiles dir is there
  1596. std::string filesDir = this->StateSnapshot.GetDirectory().GetCurrentBinary();
  1597. filesDir += cmake::GetCMakeFilesDirectory();
  1598. cmSystemTools::MakeDirectory(filesDir.c_str());
  1599. std::string currentStart =
  1600. this->StateSnapshot.GetDirectory().GetCurrentSource();
  1601. currentStart += "/CMakeLists.txt";
  1602. assert(cmSystemTools::FileExists(currentStart.c_str(), true));
  1603. this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart.c_str());
  1604. cmListFile listFile;
  1605. {
  1606. cmParseFileScope pfs(this);
  1607. if (!listFile.ParseFile(currentStart.c_str(), this->IsRootMakefile(), this))
  1608. {
  1609. this->SetConfigured();
  1610. return;
  1611. }
  1612. }
  1613. this->ReadListFile(listFile, currentStart);
  1614. if(cmSystemTools::GetFatalErrorOccured())
  1615. {
  1616. scope.Quiet();
  1617. }
  1618. // at the end handle any old style subdirs
  1619. std::vector<cmMakefile*> subdirs = this->UnConfiguredDirectories;
  1620. // for each subdir recurse
  1621. std::vector<cmMakefile*>::iterator sdi = subdirs.begin();
  1622. for (; sdi != subdirs.end(); ++sdi)
  1623. {
  1624. this->ConfigureSubDirectory(*sdi);
  1625. }
  1626. this->AddCMakeDependFilesFromUser();
  1627. this->SetConfigured();
  1628. }
  1629. void cmMakefile::ConfigureSubDirectory(cmMakefile *mf)
  1630. {
  1631. mf->InitializeFromParent(this);
  1632. std::string currentStart = mf->GetCurrentSourceDirectory();
  1633. if (this->GetCMakeInstance()->GetDebugOutput())
  1634. {
  1635. std::string msg=" Entering ";
  1636. msg += currentStart;
  1637. cmSystemTools::Message(msg.c_str());
  1638. }
  1639. std::string const currentStartFile = currentStart + "/CMakeLists.txt";
  1640. if (!cmSystemTools::FileExists(currentStartFile, true))
  1641. {
  1642. // The file is missing. Check policy CMP0014.
  1643. std::ostringstream e;
  1644. e << "The source directory\n"
  1645. << " " << currentStart << "\n"
  1646. << "does not contain a CMakeLists.txt file.";
  1647. switch (this->GetPolicyStatus(cmPolicies::CMP0014))
  1648. {
  1649. case cmPolicies::WARN:
  1650. // Print the warning.
  1651. e << "\n"
  1652. << "CMake does not support this case but it used "
  1653. << "to work accidentally and is being allowed for "
  1654. << "compatibility."
  1655. << "\n"
  1656. << cmPolicies::GetPolicyWarning(cmPolicies::CMP0014);
  1657. this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  1658. case cmPolicies::OLD:
  1659. // OLD behavior does not warn.
  1660. break;
  1661. case cmPolicies::REQUIRED_IF_USED:
  1662. case cmPolicies::REQUIRED_ALWAYS:
  1663. e << "\n"
  1664. << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0014);
  1665. case cmPolicies::NEW:
  1666. // NEW behavior prints the error.
  1667. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  1668. }
  1669. mf->SetConfigured();
  1670. return;
  1671. }
  1672. // finally configure the subdir
  1673. mf->Configure();
  1674. if (this->GetCMakeInstance()->GetDebugOutput())
  1675. {
  1676. std::string msg=" Returning to ";
  1677. msg += this->GetCurrentSourceDirectory();
  1678. cmSystemTools::Message(msg.c_str());
  1679. }
  1680. }
  1681. void cmMakefile::AddSubDirectory(const std::string& srcPath,
  1682. const std::string& binPath,
  1683. bool excludeFromAll,
  1684. bool immediate)
  1685. {
  1686. // Make sure the binary directory is unique.
  1687. if(!this->EnforceUniqueDir(srcPath, binPath))
  1688. {
  1689. return;
  1690. }
  1691. cmState::Snapshot newSnapshot = this->GetState()
  1692. ->CreateBuildsystemDirectorySnapshot(this->StateSnapshot,
  1693. this->ContextStack.back()->Name,
  1694. this->ContextStack.back()->Line);
  1695. // create a new local generator and set its parent
  1696. cmLocalGenerator *lg2 = this->GetGlobalGenerator()
  1697. ->MakeLocalGenerator(newSnapshot, this->LocalGenerator);
  1698. this->GetGlobalGenerator()->AddMakefile(lg2->GetMakefile());
  1699. this->GetGlobalGenerator()->AddLocalGenerator(lg2);
  1700. cmMakefile* subMf = lg2->GetMakefile();
  1701. // set the subdirs start dirs
  1702. subMf->SetCurrentSourceDirectory(srcPath);
  1703. subMf->SetCurrentBinaryDirectory(binPath);
  1704. if(excludeFromAll)
  1705. {
  1706. subMf->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
  1707. }
  1708. if (immediate)
  1709. {
  1710. this->ConfigureSubDirectory(subMf);
  1711. }
  1712. else
  1713. {
  1714. this->UnConfiguredDirectories.push_back(subMf);
  1715. }
  1716. }
  1717. void cmMakefile::SetCurrentSourceDirectory(const std::string& dir)
  1718. {
  1719. this->StateSnapshot.GetDirectory().SetCurrentSource(dir);
  1720. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  1721. this->StateSnapshot.GetDirectory().GetCurrentSource());
  1722. }
  1723. const char* cmMakefile::GetCurrentSourceDirectory() const
  1724. {
  1725. return this->StateSnapshot.GetDirectory().GetCurrentSource();
  1726. }
  1727. void cmMakefile::SetCurrentBinaryDirectory(const std::string& dir)
  1728. {
  1729. this->StateSnapshot.GetDirectory().SetCurrentBinary(dir);
  1730. const char* binDir = this->StateSnapshot.GetDirectory().GetCurrentBinary();
  1731. cmSystemTools::MakeDirectory(binDir);
  1732. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", binDir);
  1733. }
  1734. const char* cmMakefile::GetCurrentBinaryDirectory() const
  1735. {
  1736. return this->StateSnapshot.GetDirectory().GetCurrentBinary();
  1737. }
  1738. void cmMakefile::AddGeneratorTarget(cmTarget* t, cmGeneratorTarget* gt)
  1739. {
  1740. this->GeneratorTargets[t] = gt;
  1741. this->GetGlobalGenerator()->AddGeneratorTarget(t, gt);
  1742. }
  1743. //----------------------------------------------------------------------------
  1744. void cmMakefile::AddIncludeDirectories(const std::vector<std::string> &incs,
  1745. bool before)
  1746. {
  1747. if (incs.empty())
  1748. {
  1749. return;
  1750. }
  1751. cmListFileBacktrace lfbt = this->GetBacktrace();
  1752. std::string entryString = cmJoin(incs, ";");
  1753. if (before)
  1754. {
  1755. this->StateSnapshot.GetDirectory()
  1756. .PrependIncludeDirectoriesEntry(entryString, lfbt);
  1757. }
  1758. else
  1759. {
  1760. this->StateSnapshot.GetDirectory()
  1761. .AppendIncludeDirectoriesEntry(entryString, lfbt);
  1762. }
  1763. // Property on each target:
  1764. for (cmTargets::iterator l = this->Targets.begin();
  1765. l != this->Targets.end(); ++l)
  1766. {
  1767. cmTarget &t = l->second;
  1768. t.InsertInclude(entryString, lfbt, before);
  1769. }
  1770. }
  1771. //----------------------------------------------------------------------------
  1772. void
  1773. cmMakefile::AddSystemIncludeDirectories(const std::set<std::string> &incs)
  1774. {
  1775. this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  1776. for (cmTargets::iterator l = this->Targets.begin();
  1777. l != this->Targets.end(); ++l)
  1778. {
  1779. cmTarget &t = l->second;
  1780. t.AddSystemIncludeDirectories(incs);
  1781. }
  1782. }
  1783. void cmMakefile::AddDefinition(const std::string& name, const char* value)
  1784. {
  1785. if (!value )
  1786. {
  1787. return;
  1788. }
  1789. if (this->VariableInitialized(name))
  1790. {
  1791. this->LogUnused("changing definition", name);
  1792. }
  1793. this->Internal->SetDefinition(name, value);
  1794. #ifdef CMAKE_BUILD_WITH_CMAKE
  1795. cmVariableWatch* vv = this->GetVariableWatch();
  1796. if ( vv )
  1797. {
  1798. vv->VariableAccessed(name,
  1799. cmVariableWatch::VARIABLE_MODIFIED_ACCESS,
  1800. value,
  1801. this);
  1802. }
  1803. #endif
  1804. }
  1805. void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
  1806. const char* doc,
  1807. cmState::CacheEntryType type,
  1808. bool force)
  1809. {
  1810. bool haveVal = value ? true : false;
  1811. std::string val = haveVal ? value : "";
  1812. const char* existingValue =
  1813. this->GetState()->GetInitializedCacheValue(name);
  1814. if(existingValue
  1815. && (this->GetState()->GetCacheEntryType(name)
  1816. == cmState::UNINITIALIZED))
  1817. {
  1818. // if this is not a force, then use the value from the cache
  1819. // if it is a force, then use the value being passed in
  1820. if(!force)
  1821. {
  1822. val = existingValue;
  1823. haveVal = true;
  1824. }
  1825. if ( type == cmState::PATH || type == cmState::FILEPATH )
  1826. {
  1827. std::vector<std::string>::size_type cc;
  1828. std::vector<std::string> files;
  1829. std::string nvalue = "";
  1830. cmSystemTools::ExpandListArgument(val, files);
  1831. for ( cc = 0; cc < files.size(); cc ++ )
  1832. {
  1833. if(!cmSystemTools::IsOff(files[cc].c_str()))
  1834. {
  1835. files[cc] = cmSystemTools::CollapseFullPath(files[cc]);
  1836. }
  1837. if ( cc > 0 )
  1838. {
  1839. nvalue += ";";
  1840. }
  1841. nvalue += files[cc];
  1842. }
  1843. this->GetState()->AddCacheEntry(name, nvalue.c_str(), doc, type);
  1844. val = this->GetState()->GetInitializedCacheValue(name);
  1845. haveVal = true;
  1846. }
  1847. }
  1848. this->GetState()->AddCacheEntry(name, haveVal ? val.c_str() : 0,
  1849. doc, type);
  1850. // if there was a definition then remove it
  1851. this->Internal->RemoveDefinition(name);
  1852. }
  1853. void cmMakefile::AddDefinition(const std::string& name, bool value)
  1854. {
  1855. if (this->VariableInitialized(name))
  1856. {
  1857. this->LogUnused("changing definition", name);
  1858. }
  1859. this->Internal->SetDefinition(name, value ? "ON" : "OFF");
  1860. #ifdef CMAKE_BUILD_WITH_CMAKE
  1861. cmVariableWatch* vv = this->GetVariableWatch();
  1862. if ( vv )
  1863. {
  1864. vv->VariableAccessed(name, cmVariableWatch::VARIABLE_MODIFIED_ACCESS,
  1865. value?"ON":"OFF", this);
  1866. }
  1867. #endif
  1868. }
  1869. void cmMakefile::CheckForUnusedVariables() const
  1870. {
  1871. if (!this->WarnUnused)
  1872. {
  1873. return;
  1874. }
  1875. const std::vector<std::string>& unused = this->Internal->UnusedKeys();
  1876. std::vector<std::string>::const_iterator it = unused.begin();
  1877. for (; it != unused.end(); ++it)
  1878. {
  1879. this->LogUnused("out of scope", *it);
  1880. }
  1881. }
  1882. void cmMakefile::MarkVariableAsUsed(const std::string& var)
  1883. {
  1884. this->Internal->GetDefinition(var);
  1885. }
  1886. bool cmMakefile::VariableInitialized(const std::string& var) const
  1887. {
  1888. return this->Internal->IsInitialized(var);
  1889. }
  1890. void cmMakefile::LogUnused(const char* reason,
  1891. const std::string& name) const
  1892. {
  1893. if (this->WarnUnused)
  1894. {
  1895. std::string path;
  1896. cmListFileContext lfc;
  1897. if (!this->ExecutionStatusStack.empty())
  1898. {
  1899. lfc = this->GetExecutionContext();
  1900. path = lfc.FilePath;
  1901. }
  1902. else
  1903. {
  1904. path = this->GetCurrentSourceDirectory();
  1905. path += "/CMakeLists.txt";
  1906. lfc.FilePath = path;
  1907. lfc.Line = 0;
  1908. }
  1909. cmOutputConverter converter(this->StateSnapshot);
  1910. lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
  1911. if (this->CheckSystemVars ||
  1912. cmSystemTools::IsSubDirectory(path,
  1913. this->GetHomeDirectory()) ||
  1914. (cmSystemTools::IsSubDirectory(path,
  1915. this->GetHomeOutputDirectory()) &&
  1916. !cmSystemTools::IsSubDirectory(path,
  1917. cmake::GetCMakeFilesDirectory())))
  1918. {
  1919. std::ostringstream msg;
  1920. msg << "unused variable (" << reason << ") \'" << name << "\'";
  1921. this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
  1922. msg.str(),
  1923. lfc);
  1924. }
  1925. }
  1926. }
  1927. void cmMakefile::RemoveDefinition(const std::string& name)
  1928. {
  1929. if (this->VariableInitialized(name))
  1930. {
  1931. this->LogUnused("unsetting", name);
  1932. }
  1933. this->Internal->RemoveDefinition(name);
  1934. #ifdef CMAKE_BUILD_WITH_CMAKE
  1935. cmVariableWatch* vv = this->GetVariableWatch();
  1936. if ( vv )
  1937. {
  1938. vv->VariableAccessed(name, cmVariableWatch::VARIABLE_REMOVED_ACCESS,
  1939. 0, this);
  1940. }
  1941. #endif
  1942. }
  1943. void cmMakefile::RemoveCacheDefinition(const std::string& name)
  1944. {
  1945. this->GetState()->RemoveCacheEntry(name);
  1946. }
  1947. void cmMakefile::SetProjectName(const char* p)
  1948. {
  1949. this->ProjectName = p;
  1950. }
  1951. void cmMakefile::AddGlobalLinkInformation(const std::string& name,
  1952. cmTarget& target)
  1953. {
  1954. // for these targets do not add anything
  1955. switch(target.GetType())
  1956. {
  1957. case cmTarget::UTILITY:
  1958. case cmTarget::GLOBAL_TARGET:
  1959. case cmTarget::INTERFACE_LIBRARY:
  1960. return;
  1961. default:;
  1962. }
  1963. if (const char* linkDirsProp = this->GetProperty("LINK_DIRECTORIES"))
  1964. {
  1965. std::vector<std::string> linkDirs;
  1966. cmSystemTools::ExpandListArgument(linkDirsProp, linkDirs);
  1967. for(std::vector<std::string>::iterator j = linkDirs.begin();
  1968. j != linkDirs.end(); ++j)
  1969. {
  1970. std::string newdir = *j;
  1971. // remove trailing slashes
  1972. if(*j->rbegin() == '/')
  1973. {
  1974. newdir = j->substr(0, j->size()-1);
  1975. }
  1976. if(std::find(this->LinkDirectories.begin(),
  1977. this->LinkDirectories.end(), newdir)
  1978. == this->LinkDirectories.end())
  1979. {target.AddLinkDirectory(*j);
  1980. }
  1981. }
  1982. }
  1983. target.MergeLinkLibraries( *this, name, this->LinkLibraries );
  1984. }
  1985. void cmMakefile::AddAlias(const std::string& lname, cmTarget *tgt)
  1986. {
  1987. this->AliasTargets[lname] = tgt;
  1988. this->GetGlobalGenerator()->AddAlias(lname, tgt);
  1989. }
  1990. cmTarget* cmMakefile::AddLibrary(const std::string& lname,
  1991. cmTarget::TargetType type,
  1992. const std::vector<std::string> &srcs,
  1993. bool excludeFromAll)
  1994. {
  1995. // wrong type ? default to STATIC
  1996. if ( (type != cmTarget::STATIC_LIBRARY)
  1997. && (type != cmTarget::SHARED_LIBRARY)
  1998. && (type != cmTarget::MODULE_LIBRARY)
  1999. && (type != cmTarget::OBJECT_LIBRARY)
  2000. && (type != cmTarget::INTERFACE_LIBRARY))
  2001. {
  2002. this->IssueMessage(cmake::INTERNAL_ERROR,
  2003. "cmMakefile::AddLibrary given invalid target type.");
  2004. type = cmTarget::STATIC_LIBRARY;
  2005. }
  2006. cmTarget* target = this->AddNewTarget(type, lname);
  2007. // Clear its dependencies. Otherwise, dependencies might persist
  2008. // over changes in CMakeLists.txt, making the information stale and
  2009. // hence useless.
  2010. target->ClearDependencyInformation( *this, lname );
  2011. if(excludeFromAll)
  2012. {
  2013. target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
  2014. }
  2015. target->AddSources(srcs);
  2016. this->AddGlobalLinkInformation(lname, *target);
  2017. return target;
  2018. }
  2019. cmTarget* cmMakefile::AddExecutable(const char *exeName,
  2020. const std::vector<std::string> &srcs,
  2021. bool excludeFromAll)
  2022. {
  2023. cmTarget* target = this->AddNewTarget(cmTarget::EXECUTABLE, exeName);
  2024. if(excludeFromAll)
  2025. {
  2026. target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
  2027. }
  2028. target->AddSources(srcs);
  2029. this->AddGlobalLinkInformation(exeName, *target);
  2030. return target;
  2031. }
  2032. //----------------------------------------------------------------------------
  2033. cmTarget*
  2034. cmMakefile::AddNewTarget(cmTarget::TargetType type, const std::string& name)
  2035. {
  2036. cmTargets::iterator it =
  2037. this->Targets.insert(cmTargets::value_type(name, cmTarget())).first;
  2038. cmTarget& target = it->second;
  2039. target.SetType(type, name);
  2040. target.SetMakefile(this);
  2041. this->GetGlobalGenerator()->AddTarget(&it->second);
  2042. return &it->second;
  2043. }
  2044. cmSourceFile*
  2045. cmMakefile::LinearGetSourceFileWithOutput(const std::string& name) const
  2046. {
  2047. std::string out;
  2048. // look through all the source files that have custom commands
  2049. // and see if the custom command has the passed source file as an output
  2050. for(std::vector<cmSourceFile*>::const_iterator i =
  2051. this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  2052. {
  2053. // does this source file have a custom command?
  2054. if ((*i)->GetCustomCommand())
  2055. {
  2056. // Does the output of the custom command match the source file name?
  2057. const std::vector<std::string>& outputs =
  2058. (*i)->GetCustomCommand()->GetOutputs();
  2059. for(std::vector<std::string>::const_iterator o = outputs.begin();
  2060. o != outputs.end(); ++o)
  2061. {
  2062. out = *o;
  2063. std::string::size_type pos = out.rfind(name);
  2064. // If the output matches exactly
  2065. if (pos != out.npos &&
  2066. pos == out.size() - name.size() &&
  2067. (pos ==0 || out[pos-1] == '/'))
  2068. {
  2069. return *i;
  2070. }
  2071. }
  2072. }
  2073. }
  2074. // otherwise return NULL
  2075. return 0;
  2076. }
  2077. cmSourceFile *cmMakefile::GetSourceFileWithOutput(
  2078. const std::string& name) const
  2079. {
  2080. // If the queried path is not absolute we use the backward compatible
  2081. // linear-time search for an output with a matching suffix.
  2082. if(!cmSystemTools::FileIsFullPath(name.c_str()))
  2083. {
  2084. return this->LinearGetSourceFileWithOutput(name);
  2085. }
  2086. // Otherwise we use an efficient lookup map.
  2087. OutputToSourceMap::const_iterator o = this->OutputToSource.find(name);
  2088. if (o != this->OutputToSource.end())
  2089. {
  2090. return (*o).second;
  2091. }
  2092. return 0;
  2093. }
  2094. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2095. cmSourceGroup*
  2096. cmMakefile::GetSourceGroup(const std::vector<std::string>&name) const
  2097. {
  2098. cmSourceGroup* sg = 0;
  2099. // first look for source group starting with the same as the one we wants
  2100. for (std::vector<cmSourceGroup>::const_iterator
  2101. sgIt = this->SourceGroups.begin();
  2102. sgIt != this->SourceGroups.end(); ++sgIt)
  2103. {
  2104. std::string sgName = sgIt->GetName();
  2105. if(sgName == name[0])
  2106. {
  2107. sg = const_cast<cmSourceGroup*>(&(*sgIt));
  2108. break;
  2109. }
  2110. }
  2111. if(sg != 0)
  2112. {
  2113. // iterate through its children to find match source group
  2114. for(unsigned int i=1; i<name.size(); ++i)
  2115. {
  2116. sg = sg->LookupChild(name[i].c_str());
  2117. if(sg == 0)
  2118. {
  2119. break;
  2120. }
  2121. }
  2122. }
  2123. return sg;
  2124. }
  2125. void cmMakefile::AddSourceGroup(const std::string& name,
  2126. const char* regex)
  2127. {
  2128. std::vector<std::string> nameVector;
  2129. nameVector.push_back(name);
  2130. AddSourceGroup(nameVector, regex);
  2131. }
  2132. void cmMakefile::AddSourceGroup(const std::vector<std::string>& name,
  2133. const char* regex)
  2134. {
  2135. cmSourceGroup* sg = 0;
  2136. std::vector<std::string> currentName;
  2137. int i = 0;
  2138. const int lastElement = static_cast<int>(name.size()-1);
  2139. for(i=lastElement; i>=0; --i)
  2140. {
  2141. currentName.assign(name.begin(), name.begin()+i+1);
  2142. sg = this->GetSourceGroup(currentName);
  2143. if(sg != 0)
  2144. {
  2145. break;
  2146. }
  2147. }
  2148. // i now contains the index of the last found component
  2149. if(i==lastElement)
  2150. {
  2151. // group already exists, replace its regular expression
  2152. if ( regex && sg)
  2153. {
  2154. // We only want to set the regular expression. If there are already
  2155. // source files in the group, we don't want to remove them.
  2156. sg->SetGroupRegex(regex);
  2157. }
  2158. return;
  2159. }
  2160. else if(i==-1)
  2161. {
  2162. // group does not exist nor belong to any existing group
  2163. // add its first component
  2164. this->SourceGroups.push_back(cmSourceGroup(name[0].c_str(), regex));
  2165. sg = this->GetSourceGroup(currentName);
  2166. i = 0; // last component found
  2167. }
  2168. if(!sg)
  2169. {
  2170. cmSystemTools::Error("Could not create source group ");
  2171. return;
  2172. }
  2173. // build the whole source group path
  2174. for(++i; i<=lastElement; ++i)
  2175. {
  2176. sg->AddChild(cmSourceGroup(name[i].c_str(), 0, sg->GetFullName()));
  2177. sg = sg->LookupChild(name[i].c_str());
  2178. }
  2179. sg->SetGroupRegex(regex);
  2180. }
  2181. #endif
  2182. static bool mightExpandVariablesCMP0019(const char* s)
  2183. {
  2184. return s && *s && strstr(s,"${") && strchr(s,'}');
  2185. }
  2186. void cmMakefile::ExpandVariablesCMP0019()
  2187. {
  2188. // Drop this ancient compatibility behavior with a policy.
  2189. cmPolicies::PolicyStatus pol = this->GetPolicyStatus(cmPolicies::CMP0019);
  2190. if(pol != cmPolicies::OLD && pol != cmPolicies::WARN)
  2191. {
  2192. return;
  2193. }
  2194. std::ostringstream w;
  2195. const char *includeDirs = this->GetProperty("INCLUDE_DIRECTORIES");
  2196. if(mightExpandVariablesCMP0019(includeDirs))
  2197. {
  2198. std::string dirs = includeDirs;
  2199. this->ExpandVariablesInString(dirs, true, true);
  2200. if(pol == cmPolicies::WARN && dirs != includeDirs)
  2201. {
  2202. w << "Evaluated directory INCLUDE_DIRECTORIES\n"
  2203. << " " << includeDirs << "\n"
  2204. << "as\n"
  2205. << " " << dirs << "\n";
  2206. }
  2207. this->SetProperty("INCLUDE_DIRECTORIES", dirs.c_str());
  2208. }
  2209. // Also for each target's INCLUDE_DIRECTORIES property:
  2210. for (cmTargets::iterator l = this->Targets.begin();
  2211. l != this->Targets.end(); ++l)
  2212. {
  2213. cmTarget &t = l->second;
  2214. if (t.GetType() == cmTarget::INTERFACE_LIBRARY)
  2215. {
  2216. continue;
  2217. }
  2218. includeDirs = t.GetProperty("INCLUDE_DIRECTORIES");
  2219. if(mightExpandVariablesCMP0019(includeDirs))
  2220. {
  2221. std::string dirs = includeDirs;
  2222. this->ExpandVariablesInString(dirs, true, true);
  2223. if(pol == cmPolicies::WARN && dirs != includeDirs)
  2224. {
  2225. w << "Evaluated target " << t.GetName() << " INCLUDE_DIRECTORIES\n"
  2226. << " " << includeDirs << "\n"
  2227. << "as\n"
  2228. << " " << dirs << "\n";
  2229. }
  2230. t.SetProperty("INCLUDE_DIRECTORIES", dirs.c_str());
  2231. }
  2232. }
  2233. if (const char* linkDirsProp = this->GetProperty("LINK_DIRECTORIES"))
  2234. {
  2235. if(mightExpandVariablesCMP0019(linkDirsProp))
  2236. {
  2237. std::string d = linkDirsProp;
  2238. std::string orig = linkDirsProp;
  2239. this->ExpandVariablesInString(d, true, true);
  2240. if(pol == cmPolicies::WARN && d != orig)
  2241. {
  2242. w << "Evaluated link directories\n"
  2243. << " " << orig << "\n"
  2244. << "as\n"
  2245. << " " << d << "\n";
  2246. }
  2247. }
  2248. }
  2249. for(cmTarget::LinkLibraryVectorType::iterator l =
  2250. this->LinkLibraries.begin();
  2251. l != this->LinkLibraries.end(); ++l)
  2252. {
  2253. if(mightExpandVariablesCMP0019(l->first.c_str()))
  2254. {
  2255. std::string orig = l->first;
  2256. this->ExpandVariablesInString(l->first, true, true);
  2257. if(pol == cmPolicies::WARN && l->first != orig)
  2258. {
  2259. w << "Evaluated link library\n"
  2260. << " " << orig << "\n"
  2261. << "as\n"
  2262. << " " << l->first << "\n";
  2263. }
  2264. }
  2265. }
  2266. if(!w.str().empty())
  2267. {
  2268. std::ostringstream m;
  2269. m << cmPolicies::GetPolicyWarning(cmPolicies::CMP0019)
  2270. << "\n"
  2271. << "The following variable evaluations were encountered:\n"
  2272. << w.str();
  2273. this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
  2274. }
  2275. }
  2276. bool cmMakefile::IsOn(const std::string& name) const
  2277. {
  2278. const char* value = this->GetDefinition(name);
  2279. return cmSystemTools::IsOn(value);
  2280. }
  2281. bool cmMakefile::IsSet(const std::string& name) const
  2282. {
  2283. const char* value = this->GetDefinition(name);
  2284. if ( !value )
  2285. {
  2286. return false;
  2287. }
  2288. if ( ! *value )
  2289. {
  2290. return false;
  2291. }
  2292. if ( cmSystemTools::IsNOTFOUND(value) )
  2293. {
  2294. return false;
  2295. }
  2296. return true;
  2297. }
  2298. bool cmMakefile::PlatformIs64Bit() const
  2299. {
  2300. if(const char* sizeof_dptr = this->GetDefinition("CMAKE_SIZEOF_VOID_P"))
  2301. {
  2302. return atoi(sizeof_dptr) == 8;
  2303. }
  2304. return false;
  2305. }
  2306. const char* cmMakefile::GetSONameFlag(const std::string& language) const
  2307. {
  2308. std::string name = "CMAKE_SHARED_LIBRARY_SONAME";
  2309. if(!language.empty())
  2310. {
  2311. name += "_";
  2312. name += language;
  2313. }
  2314. name += "_FLAG";
  2315. return GetDefinition(name);
  2316. }
  2317. bool cmMakefile::CanIWriteThisFile(const char* fileName) const
  2318. {
  2319. if ( !this->IsOn("CMAKE_DISABLE_SOURCE_CHANGES") )
  2320. {
  2321. return true;
  2322. }
  2323. // If we are doing an in-source build, then the test will always fail
  2324. if ( cmSystemTools::SameFile(this->GetHomeDirectory(),
  2325. this->GetHomeOutputDirectory()) )
  2326. {
  2327. if ( this->IsOn("CMAKE_DISABLE_IN_SOURCE_BUILD") )
  2328. {
  2329. return false;
  2330. }
  2331. return true;
  2332. }
  2333. // Check if this is a subdirectory of the source tree but not a
  2334. // subdirectory of the build tree
  2335. if ( cmSystemTools::IsSubDirectory(fileName,
  2336. this->GetHomeDirectory()) &&
  2337. !cmSystemTools::IsSubDirectory(fileName,
  2338. this->GetHomeOutputDirectory()) )
  2339. {
  2340. return false;
  2341. }
  2342. return true;
  2343. }
  2344. const char* cmMakefile::GetRequiredDefinition(const std::string& name) const
  2345. {
  2346. const char* ret = this->GetDefinition(name);
  2347. if(!ret)
  2348. {
  2349. cmSystemTools::Error("Error required internal CMake variable not "
  2350. "set, cmake may be not be built correctly.\n",
  2351. "Missing variable is:\n",
  2352. name.c_str());
  2353. return "";
  2354. }
  2355. return ret;
  2356. }
  2357. bool cmMakefile::IsDefinitionSet(const std::string& name) const
  2358. {
  2359. const char* def = this->Internal->GetDefinition(name);
  2360. if(!def)
  2361. {
  2362. def = this->GetState()->GetInitializedCacheValue(name);
  2363. }
  2364. #ifdef CMAKE_BUILD_WITH_CMAKE
  2365. if(cmVariableWatch* vv = this->GetVariableWatch())
  2366. {
  2367. if(!def)
  2368. {
  2369. vv->VariableAccessed
  2370. (name, cmVariableWatch::UNKNOWN_VARIABLE_DEFINED_ACCESS,
  2371. def, this);
  2372. }
  2373. }
  2374. #endif
  2375. return def?true:false;
  2376. }
  2377. const char* cmMakefile::GetDefinition(const std::string& name) const
  2378. {
  2379. const char* def = this->Internal->GetDefinition(name);
  2380. if(!def)
  2381. {
  2382. def = this->GetState()->GetInitializedCacheValue(name);
  2383. }
  2384. #ifdef CMAKE_BUILD_WITH_CMAKE
  2385. cmVariableWatch* vv = this->GetVariableWatch();
  2386. if ( vv && !this->SuppressWatches )
  2387. {
  2388. if ( def )
  2389. {
  2390. vv->VariableAccessed(name, cmVariableWatch::VARIABLE_READ_ACCESS,
  2391. def, this);
  2392. }
  2393. else
  2394. {
  2395. vv->VariableAccessed(name,
  2396. cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS, def, this);
  2397. }
  2398. }
  2399. #endif
  2400. return def;
  2401. }
  2402. const char* cmMakefile::GetSafeDefinition(const std::string& def) const
  2403. {
  2404. const char* ret = this->GetDefinition(def);
  2405. if(!ret)
  2406. {
  2407. return "";
  2408. }
  2409. return ret;
  2410. }
  2411. std::vector<std::string> cmMakefile::GetDefinitions() const
  2412. {
  2413. std::vector<std::string> res = this->Internal->ClosureKeys();
  2414. std::vector<std::string> cacheKeys = this->GetState()->GetCacheEntryKeys();
  2415. res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
  2416. std::sort(res.begin(), res.end());
  2417. return res;
  2418. }
  2419. const char *cmMakefile::ExpandVariablesInString(std::string& source) const
  2420. {
  2421. return this->ExpandVariablesInString(source, false, false);
  2422. }
  2423. const char *cmMakefile::ExpandVariablesInString(std::string& source,
  2424. bool escapeQuotes,
  2425. bool noEscapes,
  2426. bool atOnly,
  2427. const char* filename,
  2428. long line,
  2429. bool removeEmpty,
  2430. bool replaceAt) const
  2431. {
  2432. bool compareResults = false;
  2433. cmake::MessageType mtype = cmake::LOG;
  2434. std::string errorstr;
  2435. std::string original;
  2436. // Sanity check the @ONLY mode.
  2437. if(atOnly && (!noEscapes || !removeEmpty))
  2438. {
  2439. // This case should never be called. At-only is for
  2440. // configure-file/string which always does no escapes.
  2441. this->IssueMessage(cmake::INTERNAL_ERROR,
  2442. "ExpandVariablesInString @ONLY called "
  2443. "on something with escapes.");
  2444. return source.c_str();
  2445. }
  2446. // Variables used in the WARN case.
  2447. std::string newResult;
  2448. std::string newErrorstr;
  2449. cmake::MessageType newError = cmake::LOG;
  2450. switch(this->GetPolicyStatus(cmPolicies::CMP0053))
  2451. {
  2452. case cmPolicies::WARN:
  2453. {
  2454. // Save the original string for the warning.
  2455. original = source;
  2456. newResult = source;
  2457. compareResults = true;
  2458. // Suppress variable watches to avoid calling hooks twice. Suppress new
  2459. // dereferences since the OLD behavior is still what is actually used.
  2460. this->SuppressWatches = true;
  2461. newError =
  2462. ExpandVariablesInStringNew(newErrorstr, newResult, escapeQuotes,
  2463. noEscapes, atOnly, filename, line,
  2464. removeEmpty, replaceAt);
  2465. this->SuppressWatches = false;
  2466. }
  2467. case cmPolicies::OLD:
  2468. mtype = ExpandVariablesInStringOld(errorstr, source, escapeQuotes,
  2469. noEscapes, atOnly, filename,
  2470. line, removeEmpty, true);
  2471. break;
  2472. case cmPolicies::REQUIRED_IF_USED:
  2473. case cmPolicies::REQUIRED_ALWAYS:
  2474. // Messaging here would be *very* verbose.
  2475. case cmPolicies::NEW:
  2476. mtype = ExpandVariablesInStringNew(errorstr, source, escapeQuotes,
  2477. noEscapes, atOnly, filename,
  2478. line, removeEmpty, replaceAt);
  2479. break;
  2480. }
  2481. // If it's an error in either case, just report the error...
  2482. if(mtype != cmake::LOG)
  2483. {
  2484. if(mtype == cmake::FATAL_ERROR)
  2485. {
  2486. cmSystemTools::SetFatalErrorOccured();
  2487. }
  2488. this->IssueMessage(mtype, errorstr);
  2489. }
  2490. // ...otherwise, see if there's a difference that needs to be warned about.
  2491. else if(compareResults && (newResult != source || newError != mtype))
  2492. {
  2493. std::string msg =
  2494. cmPolicies::GetPolicyWarning(cmPolicies::CMP0053);
  2495. msg += "\n";
  2496. std::string msg_input = original;
  2497. cmSystemTools::ReplaceString(msg_input, "\n", "\n ");
  2498. msg += "For input:\n '";
  2499. msg += msg_input;
  2500. msg += "'\n";
  2501. std::string msg_old = source;
  2502. cmSystemTools::ReplaceString(msg_old, "\n", "\n ");
  2503. msg += "the old evaluation rules produce:\n '";
  2504. msg += msg_old;
  2505. msg += "'\n";
  2506. if(newError == mtype)
  2507. {
  2508. std::string msg_new = newResult;
  2509. cmSystemTools::ReplaceString(msg_new, "\n", "\n ");
  2510. msg += "but the new evaluation rules produce:\n '";
  2511. msg += msg_new;
  2512. msg += "'\n";
  2513. }
  2514. else
  2515. {
  2516. std::string msg_err = newErrorstr;
  2517. cmSystemTools::ReplaceString(msg_err, "\n", "\n ");
  2518. msg += "but the new evaluation rules produce an error:\n ";
  2519. msg += msg_err;
  2520. msg += "\n";
  2521. }
  2522. msg +=
  2523. "Using the old result for compatibility since the policy is not set.";
  2524. this->IssueMessage(cmake::AUTHOR_WARNING, msg);
  2525. }
  2526. return source.c_str();
  2527. }
  2528. cmake::MessageType cmMakefile::ExpandVariablesInStringOld(
  2529. std::string& errorstr,
  2530. std::string& source,
  2531. bool escapeQuotes,
  2532. bool noEscapes,
  2533. bool atOnly,
  2534. const char* filename,
  2535. long line,
  2536. bool removeEmpty,
  2537. bool replaceAt) const
  2538. {
  2539. // Fast path strings without any special characters.
  2540. if ( source.find_first_of("$@\\") == source.npos)
  2541. {
  2542. return cmake::LOG;
  2543. }
  2544. // Special-case the @ONLY mode.
  2545. if(atOnly)
  2546. {
  2547. // Store an original copy of the input.
  2548. std::string input = source;
  2549. // Start with empty output.
  2550. source = "";
  2551. // Look for one @VAR@ at a time.
  2552. const char* in = input.c_str();
  2553. while(this->cmAtVarRegex.find(in))
  2554. {
  2555. // Get the range of the string to replace.
  2556. const char* first = in + this->cmAtVarRegex.start();
  2557. const char* last = in + this->cmAtVarRegex.end();
  2558. // Store the unchanged part of the string now.
  2559. source.append(in, first-in);
  2560. // Lookup the definition of VAR.
  2561. std::string var(first+1, last-first-2);
  2562. if(const char* val = this->GetDefinition(var))
  2563. {
  2564. // Store the value in the output escaping as requested.
  2565. if(escapeQuotes)
  2566. {
  2567. source.append(cmSystemTools::EscapeQuotes(val));
  2568. }
  2569. else
  2570. {
  2571. source.append(val);
  2572. }
  2573. }
  2574. // Continue looking for @VAR@ further along the string.
  2575. in = last;
  2576. }
  2577. // Append the rest of the unchanged part of the string.
  2578. source.append(in);
  2579. return cmake::LOG;
  2580. }
  2581. // This method replaces ${VAR} and @VAR@ where VAR is looked up
  2582. // with GetDefinition(), if not found in the map, nothing is expanded.
  2583. // It also supports the $ENV{VAR} syntax where VAR is looked up in
  2584. // the current environment variables.
  2585. cmCommandArgumentParserHelper parser;
  2586. parser.SetMakefile(this);
  2587. parser.SetLineFile(line, filename);
  2588. parser.SetEscapeQuotes(escapeQuotes);
  2589. parser.SetNoEscapeMode(noEscapes);
  2590. parser.SetReplaceAtSyntax(replaceAt);
  2591. parser.SetRemoveEmpty(removeEmpty);
  2592. int res = parser.ParseString(source.c_str(), 0);
  2593. const char* emsg = parser.GetError();
  2594. cmake::MessageType mtype = cmake::LOG;
  2595. if ( res && !emsg[0] )
  2596. {
  2597. source = parser.GetResult();
  2598. }
  2599. else
  2600. {
  2601. // Construct the main error message.
  2602. std::ostringstream error;
  2603. error << "Syntax error in cmake code ";
  2604. if(filename && line > 0)
  2605. {
  2606. // This filename and line number may be more specific than the
  2607. // command context because one command invocation can have
  2608. // arguments on multiple lines.
  2609. error << "at\n"
  2610. << " " << filename << ":" << line << "\n";
  2611. }
  2612. error << "when parsing string\n"
  2613. << " " << source << "\n";
  2614. error << emsg;
  2615. // If the parser failed ("res" is false) then this is a real
  2616. // argument parsing error, so the policy applies. Otherwise the
  2617. // parser reported an error message without failing because the
  2618. // helper implementation is unhappy, which has always reported an
  2619. // error.
  2620. mtype = cmake::FATAL_ERROR;
  2621. if(!res)
  2622. {
  2623. // This is a real argument parsing error. Use policy CMP0010 to
  2624. // decide whether it is an error.
  2625. switch(this->GetPolicyStatus(cmPolicies::CMP0010))
  2626. {
  2627. case cmPolicies::WARN:
  2628. error << "\n" << cmPolicies::GetPolicyWarning(cmPolicies::CMP0010);
  2629. case cmPolicies::OLD:
  2630. // OLD behavior is to just warn and continue.
  2631. mtype = cmake::AUTHOR_WARNING;
  2632. break;
  2633. case cmPolicies::REQUIRED_IF_USED:
  2634. case cmPolicies::REQUIRED_ALWAYS:
  2635. error << "\n"
  2636. << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0010);
  2637. case cmPolicies::NEW:
  2638. // NEW behavior is to report the error.
  2639. break;
  2640. }
  2641. }
  2642. errorstr = error.str();
  2643. }
  2644. return mtype;
  2645. }
  2646. typedef enum
  2647. {
  2648. NORMAL,
  2649. ENVIRONMENT,
  2650. CACHE
  2651. } t_domain;
  2652. struct t_lookup
  2653. {
  2654. t_lookup(): domain(NORMAL), loc(0) {}
  2655. t_domain domain;
  2656. size_t loc;
  2657. };
  2658. cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
  2659. std::string& errorstr,
  2660. std::string& source,
  2661. bool escapeQuotes,
  2662. bool noEscapes,
  2663. bool atOnly,
  2664. const char* filename,
  2665. long line,
  2666. bool removeEmpty,
  2667. bool replaceAt) const
  2668. {
  2669. // This method replaces ${VAR} and @VAR@ where VAR is looked up
  2670. // with GetDefinition(), if not found in the map, nothing is expanded.
  2671. // It also supports the $ENV{VAR} syntax where VAR is looked up in
  2672. // the current environment variables.
  2673. const char* in = source.c_str();
  2674. const char* last = in;
  2675. std::string result;
  2676. result.reserve(source.size());
  2677. std::stack<t_lookup> openstack;
  2678. bool error = false;
  2679. bool done = false;
  2680. openstack.push(t_lookup());
  2681. cmake::MessageType mtype = cmake::LOG;
  2682. cmState* state = this->GetCMakeInstance()->GetState();
  2683. do
  2684. {
  2685. char inc = *in;
  2686. switch(inc)
  2687. {
  2688. case '}':
  2689. if(openstack.size() > 1)
  2690. {
  2691. t_lookup var = openstack.top();
  2692. openstack.pop();
  2693. result.append(last, in - last);
  2694. std::string const& lookup = result.substr(var.loc);
  2695. const char* value = NULL;
  2696. std::string varresult;
  2697. static const std::string lineVar = "CMAKE_CURRENT_LIST_LINE";
  2698. switch(var.domain)
  2699. {
  2700. case NORMAL:
  2701. if(filename && lookup == lineVar)
  2702. {
  2703. std::ostringstream ostr;
  2704. ostr << line;
  2705. varresult = ostr.str();
  2706. }
  2707. else
  2708. {
  2709. value = this->GetDefinition(lookup);
  2710. }
  2711. break;
  2712. case ENVIRONMENT:
  2713. value = cmSystemTools::GetEnv(lookup.c_str());
  2714. break;
  2715. case CACHE:
  2716. value = state->GetCacheEntryValue(lookup);
  2717. break;
  2718. }
  2719. // Get the string we're meant to append to.
  2720. if(value)
  2721. {
  2722. if(escapeQuotes)
  2723. {
  2724. varresult = cmSystemTools::EscapeQuotes(value);
  2725. }
  2726. else
  2727. {
  2728. varresult = value;
  2729. }
  2730. }
  2731. else if(!removeEmpty)
  2732. {
  2733. // check to see if we need to print a warning
  2734. // if strict mode is on and the variable has
  2735. // not been "cleared"/initialized with a set(foo ) call
  2736. if(this->GetCMakeInstance()->GetWarnUninitialized() &&
  2737. !this->VariableInitialized(lookup))
  2738. {
  2739. if (this->CheckSystemVars ||
  2740. cmSystemTools::IsSubDirectory(filename,
  2741. this->GetHomeDirectory()) ||
  2742. cmSystemTools::IsSubDirectory(filename,
  2743. this->GetHomeOutputDirectory()))
  2744. {
  2745. std::ostringstream msg;
  2746. cmListFileContext lfc;
  2747. cmOutputConverter converter(this->StateSnapshot);
  2748. lfc.FilePath =
  2749. converter.Convert(filename, cmOutputConverter::HOME);
  2750. lfc.Line = line;
  2751. msg << "uninitialized variable \'" << lookup << "\'";
  2752. this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
  2753. msg.str(), lfc);
  2754. }
  2755. }
  2756. }
  2757. result.replace(var.loc, result.size() - var.loc, varresult);
  2758. // Start looking from here on out.
  2759. last = in + 1;
  2760. }
  2761. break;
  2762. case '$':
  2763. if(!atOnly)
  2764. {
  2765. t_lookup lookup;
  2766. const char* next = in + 1;
  2767. const char* start = NULL;
  2768. char nextc = *next;
  2769. if(nextc == '{')
  2770. {
  2771. // Looking for a variable.
  2772. start = in + 2;
  2773. lookup.domain = NORMAL;
  2774. }
  2775. else if(nextc == '<')
  2776. {
  2777. }
  2778. else if(!nextc)
  2779. {
  2780. result.append(last, next - last);
  2781. last = next;
  2782. }
  2783. else if(cmHasLiteralPrefix(next, "ENV{"))
  2784. {
  2785. // Looking for an environment variable.
  2786. start = in + 5;
  2787. lookup.domain = ENVIRONMENT;
  2788. }
  2789. else if(cmHasLiteralPrefix(next, "CACHE{"))
  2790. {
  2791. // Looking for a cache variable.
  2792. start = in + 7;
  2793. lookup.domain = CACHE;
  2794. }
  2795. else
  2796. {
  2797. if(this->cmNamedCurly.find(next))
  2798. {
  2799. errorstr = "Syntax $"
  2800. + std::string(next, this->cmNamedCurly.end())
  2801. + "{} is not supported. Only ${}, $ENV{}, "
  2802. "and $CACHE{} are allowed.";
  2803. mtype = cmake::FATAL_ERROR;
  2804. error = true;
  2805. }
  2806. }
  2807. if(start)
  2808. {
  2809. result.append(last, in - last);
  2810. last = start;
  2811. in = start - 1;
  2812. lookup.loc = result.size();
  2813. openstack.push(lookup);
  2814. }
  2815. break;
  2816. }
  2817. case '\\':
  2818. if(!noEscapes)
  2819. {
  2820. const char* next = in + 1;
  2821. char nextc = *next;
  2822. if(nextc == 't')
  2823. {
  2824. result.append(last, in - last);
  2825. result.append("\t");
  2826. last = next + 1;
  2827. }
  2828. else if(nextc == 'n')
  2829. {
  2830. result.append(last, in - last);
  2831. result.append("\n");
  2832. last = next + 1;
  2833. }
  2834. else if(nextc == 'r')
  2835. {
  2836. result.append(last, in - last);
  2837. result.append("\r");
  2838. last = next + 1;
  2839. }
  2840. else if(nextc == ';' && openstack.size() == 1)
  2841. {
  2842. // Handled in ExpandListArgument; pass the backslash literally.
  2843. }
  2844. else if (isalnum(nextc) || nextc == '\0')
  2845. {
  2846. errorstr += "Invalid character escape '\\";
  2847. if (nextc)
  2848. {
  2849. errorstr += nextc;
  2850. errorstr += "'.";
  2851. }
  2852. else
  2853. {
  2854. errorstr += "' (at end of input).";
  2855. }
  2856. error = true;
  2857. }
  2858. else
  2859. {
  2860. // Take what we've found so far, skipping the escape character.
  2861. result.append(last, in - last);
  2862. // Start tracking from the next character.
  2863. last = in + 1;
  2864. }
  2865. // Skip the next character since it was escaped, but don't read past
  2866. // the end of the string.
  2867. if(*last)
  2868. {
  2869. ++in;
  2870. }
  2871. }
  2872. break;
  2873. case '\n':
  2874. // Onto the next line.
  2875. ++line;
  2876. break;
  2877. case '\0':
  2878. done = true;
  2879. break;
  2880. case '@':
  2881. if(replaceAt)
  2882. {
  2883. const char* nextAt = strchr(in + 1, '@');
  2884. if(nextAt && nextAt != in + 1 &&
  2885. nextAt == in + 1 + strspn(in + 1,
  2886. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  2887. "abcdefghijklmnopqrstuvwxyz"
  2888. "0123456789/_.+-"))
  2889. {
  2890. std::string variable(in + 1, nextAt - in - 1);
  2891. std::string varresult = this->GetSafeDefinition(variable);
  2892. if(escapeQuotes)
  2893. {
  2894. varresult = cmSystemTools::EscapeQuotes(varresult);
  2895. }
  2896. // Skip over the variable.
  2897. result.append(last, in - last);
  2898. result.append(varresult);
  2899. in = nextAt;
  2900. last = in + 1;
  2901. break;
  2902. }
  2903. }
  2904. // Failed to find a valid @ expansion; treat it as literal.
  2905. /* FALLTHROUGH */
  2906. default:
  2907. {
  2908. if(openstack.size() > 1 &&
  2909. !(isalnum(inc) || inc == '_' ||
  2910. inc == '/' || inc == '.' ||
  2911. inc == '+' || inc == '-'))
  2912. {
  2913. errorstr += "Invalid character (\'";
  2914. errorstr += inc;
  2915. result.append(last, in - last);
  2916. errorstr += "\') in a variable name: "
  2917. "'" + result.substr(openstack.top().loc) + "'";
  2918. mtype = cmake::FATAL_ERROR;
  2919. error = true;
  2920. }
  2921. break;
  2922. }
  2923. }
  2924. // Look at the next character.
  2925. } while(!error && !done && *++in);
  2926. // Check for open variable references yet.
  2927. if(!error && openstack.size() != 1)
  2928. {
  2929. // There's an open variable reference waiting. Policy CMP0010 flags
  2930. // whether this is an error or not. The new parser now enforces
  2931. // CMP0010 as well.
  2932. errorstr += "There is an unterminated variable reference.";
  2933. error = true;
  2934. }
  2935. if(error)
  2936. {
  2937. std::ostringstream emsg;
  2938. emsg << "Syntax error in cmake code ";
  2939. if(filename)
  2940. {
  2941. // This filename and line number may be more specific than the
  2942. // command context because one command invocation can have
  2943. // arguments on multiple lines.
  2944. emsg << "at\n"
  2945. << " " << filename << ":" << line << "\n";
  2946. }
  2947. emsg << "when parsing string\n"
  2948. << " " << source << "\n";
  2949. emsg << errorstr;
  2950. mtype = cmake::FATAL_ERROR;
  2951. errorstr = emsg.str();
  2952. }
  2953. else
  2954. {
  2955. // Append the rest of the unchanged part of the string.
  2956. result.append(last);
  2957. source = result;
  2958. }
  2959. return mtype;
  2960. }
  2961. void cmMakefile::RemoveVariablesInString(std::string& source,
  2962. bool atOnly) const
  2963. {
  2964. if(!atOnly)
  2965. {
  2966. cmsys::RegularExpression var("(\\${[A-Za-z_0-9]*})");
  2967. while (var.find(source))
  2968. {
  2969. source.erase(var.start(),var.end() - var.start());
  2970. }
  2971. }
  2972. if(!atOnly)
  2973. {
  2974. cmsys::RegularExpression varb("(\\$ENV{[A-Za-z_0-9]*})");
  2975. while (varb.find(source))
  2976. {
  2977. source.erase(varb.start(),varb.end() - varb.start());
  2978. }
  2979. }
  2980. cmsys::RegularExpression var2("(@[A-Za-z_0-9]*@)");
  2981. while (var2.find(source))
  2982. {
  2983. source.erase(var2.start(),var2.end() - var2.start());
  2984. }
  2985. }
  2986. /**
  2987. * Add the default definitions to the makefile. These values must not
  2988. * be dependent on anything that isn't known when this cmMakefile instance
  2989. * is constructed.
  2990. */
  2991. void cmMakefile::AddDefaultDefinitions()
  2992. {
  2993. /* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
  2994. With CMake must separate between target and host platform. In most cases
  2995. the tests for WIN32, UNIX and APPLE will be for the target system, so an
  2996. additional set of variables for the host system is required ->
  2997. CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
  2998. WIN32, UNIX and APPLE are now set in the platform files in
  2999. Modules/Platforms/.
  3000. To keep cmake scripts (-P) and custom language and compiler modules
  3001. working, these variables are still also set here in this place, but they
  3002. will be reset in CMakeSystemSpecificInformation.cmake before the platform
  3003. files are executed. */
  3004. #if defined(_WIN32)
  3005. this->AddDefinition("WIN32", "1");
  3006. this->AddDefinition("CMAKE_HOST_WIN32", "1");
  3007. #else
  3008. this->AddDefinition("UNIX", "1");
  3009. this->AddDefinition("CMAKE_HOST_UNIX", "1");
  3010. #endif
  3011. #if defined(__CYGWIN__)
  3012. if(cmSystemTools::IsOn(cmSystemTools::GetEnv("CMAKE_LEGACY_CYGWIN_WIN32")))
  3013. {
  3014. this->AddDefinition("WIN32", "1");
  3015. this->AddDefinition("CMAKE_HOST_WIN32", "1");
  3016. }
  3017. #endif
  3018. #if defined(__APPLE__)
  3019. this->AddDefinition("APPLE", "1");
  3020. this->AddDefinition("CMAKE_HOST_APPLE", "1");
  3021. #endif
  3022. char temp[1024];
  3023. sprintf(temp, "%d", cmVersion::GetMinorVersion());
  3024. this->AddDefinition("CMAKE_MINOR_VERSION", temp);
  3025. sprintf(temp, "%d", cmVersion::GetMajorVersion());
  3026. this->AddDefinition("CMAKE_MAJOR_VERSION", temp);
  3027. sprintf(temp, "%d", cmVersion::GetPatchVersion());
  3028. this->AddDefinition("CMAKE_PATCH_VERSION", temp);
  3029. sprintf(temp, "%d", cmVersion::GetTweakVersion());
  3030. this->AddDefinition("CMAKE_TWEAK_VERSION", temp);
  3031. this->AddDefinition("CMAKE_VERSION", cmVersion::GetCMakeVersion());
  3032. this->AddDefinition("CMAKE_FILES_DIRECTORY",
  3033. cmake::GetCMakeFilesDirectory());
  3034. }
  3035. //----------------------------------------------------------------------------
  3036. std::string
  3037. cmMakefile::GetConfigurations(std::vector<std::string>& configs,
  3038. bool single) const
  3039. {
  3040. if(this->GetGlobalGenerator()->IsMultiConfig())
  3041. {
  3042. if(const char* configTypes =
  3043. this->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  3044. {
  3045. cmSystemTools::ExpandListArgument(configTypes, configs);
  3046. }
  3047. return "";
  3048. }
  3049. else
  3050. {
  3051. const std::string& buildType = this->GetSafeDefinition("CMAKE_BUILD_TYPE");
  3052. if(single && !buildType.empty())
  3053. {
  3054. configs.push_back(buildType);
  3055. }
  3056. return buildType;
  3057. }
  3058. }
  3059. #if defined(CMAKE_BUILD_WITH_CMAKE)
  3060. /**
  3061. * Find a source group whose regular expression matches the filename
  3062. * part of the given source name. Search backward through the list of
  3063. * source groups, and take the first matching group found. This way
  3064. * non-inherited SOURCE_GROUP commands will have precedence over
  3065. * inherited ones.
  3066. */
  3067. cmSourceGroup*
  3068. cmMakefile::FindSourceGroup(const char* source,
  3069. std::vector<cmSourceGroup> &groups) const
  3070. {
  3071. // First search for a group that lists the file explicitly.
  3072. for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
  3073. sg != groups.rend(); ++sg)
  3074. {
  3075. cmSourceGroup *result = sg->MatchChildrenFiles(source);
  3076. if(result)
  3077. {
  3078. return result;
  3079. }
  3080. }
  3081. // Now search for a group whose regex matches the file.
  3082. for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
  3083. sg != groups.rend(); ++sg)
  3084. {
  3085. cmSourceGroup *result = sg->MatchChildrenRegex(source);
  3086. if(result)
  3087. {
  3088. return result;
  3089. }
  3090. }
  3091. // Shouldn't get here, but just in case, return the default group.
  3092. return &groups.front();
  3093. }
  3094. #endif
  3095. bool cmMakefile::IsFunctionBlocked(const cmListFileFunction& lff,
  3096. cmExecutionStatus &status)
  3097. {
  3098. // if there are no blockers get out of here
  3099. if (this->FunctionBlockers.begin() == this->FunctionBlockers.end())
  3100. {
  3101. return false;
  3102. }
  3103. // loop over all function blockers to see if any block this command
  3104. // evaluate in reverse, this is critical for balanced IF statements etc
  3105. std::vector<cmFunctionBlocker*>::reverse_iterator pos;
  3106. for (pos = this->FunctionBlockers.rbegin();
  3107. pos != this->FunctionBlockers.rend(); ++pos)
  3108. {
  3109. if((*pos)->IsFunctionBlocked(lff, *this, status))
  3110. {
  3111. return true;
  3112. }
  3113. }
  3114. return false;
  3115. }
  3116. //----------------------------------------------------------------------------
  3117. void cmMakefile::PushFunctionBlockerBarrier()
  3118. {
  3119. this->FunctionBlockerBarriers.push_back(this->FunctionBlockers.size());
  3120. }
  3121. //----------------------------------------------------------------------------
  3122. void cmMakefile::PopFunctionBlockerBarrier(bool reportError)
  3123. {
  3124. // Remove any extra entries pushed on the barrier.
  3125. FunctionBlockersType::size_type barrier =
  3126. this->FunctionBlockerBarriers.back();
  3127. while(this->FunctionBlockers.size() > barrier)
  3128. {
  3129. cmsys::auto_ptr<cmFunctionBlocker> fb(this->FunctionBlockers.back());
  3130. this->FunctionBlockers.pop_back();
  3131. if(reportError)
  3132. {
  3133. // Report the context in which the unclosed block was opened.
  3134. cmListFileContext const& lfc = fb->GetStartingContext();
  3135. std::ostringstream e;
  3136. e << "A logical block opening on the line\n"
  3137. << " " << lfc << "\n"
  3138. << "is not closed.";
  3139. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  3140. reportError = false;
  3141. }
  3142. }
  3143. // Remove the barrier.
  3144. this->FunctionBlockerBarriers.pop_back();
  3145. }
  3146. //----------------------------------------------------------------------------
  3147. void cmMakefile::PushLoopBlock()
  3148. {
  3149. assert(!this->LoopBlockCounter.empty());
  3150. this->LoopBlockCounter.top()++;
  3151. }
  3152. void cmMakefile::PopLoopBlock()
  3153. {
  3154. assert(!this->LoopBlockCounter.empty());
  3155. assert(this->LoopBlockCounter.top() > 0);
  3156. this->LoopBlockCounter.top()--;
  3157. }
  3158. void cmMakefile::PushLoopBlockBarrier()
  3159. {
  3160. this->LoopBlockCounter.push(0);
  3161. }
  3162. void cmMakefile::PopLoopBlockBarrier()
  3163. {
  3164. assert(!this->LoopBlockCounter.empty());
  3165. assert(this->LoopBlockCounter.top() == 0);
  3166. this->LoopBlockCounter.pop();
  3167. }
  3168. bool cmMakefile::IsLoopBlock() const
  3169. {
  3170. assert(!this->LoopBlockCounter.empty());
  3171. return !this->LoopBlockCounter.empty() && this->LoopBlockCounter.top() > 0;
  3172. }
  3173. std::string cmMakefile::GetExecutionFilePath() const
  3174. {
  3175. assert(this->StateSnapshot.IsValid());
  3176. return this->StateSnapshot.GetExecutionListFile();
  3177. }
  3178. //----------------------------------------------------------------------------
  3179. bool cmMakefile::ExpandArguments(
  3180. std::vector<cmListFileArgument> const& inArgs,
  3181. std::vector<std::string>& outArgs, const char* filename) const
  3182. {
  3183. std::string efp = this->GetExecutionFilePath();
  3184. if (!filename)
  3185. {
  3186. filename = efp.c_str();
  3187. }
  3188. std::vector<cmListFileArgument>::const_iterator i;
  3189. std::string value;
  3190. outArgs.reserve(inArgs.size());
  3191. for(i = inArgs.begin(); i != inArgs.end(); ++i)
  3192. {
  3193. // No expansion in a bracket argument.
  3194. if(i->Delim == cmListFileArgument::Bracket)
  3195. {
  3196. outArgs.push_back(i->Value);
  3197. continue;
  3198. }
  3199. // Expand the variables in the argument.
  3200. value = i->Value;
  3201. this->ExpandVariablesInString(value, false, false, false,
  3202. filename, i->Line, false, false);
  3203. // If the argument is quoted, it should be one argument.
  3204. // Otherwise, it may be a list of arguments.
  3205. if(i->Delim == cmListFileArgument::Quoted)
  3206. {
  3207. outArgs.push_back(value);
  3208. }
  3209. else
  3210. {
  3211. cmSystemTools::ExpandListArgument(value, outArgs);
  3212. }
  3213. }
  3214. return !cmSystemTools::GetFatalErrorOccured();
  3215. }
  3216. //----------------------------------------------------------------------------
  3217. bool cmMakefile::ExpandArguments(
  3218. std::vector<cmListFileArgument> const& inArgs,
  3219. std::vector<cmExpandedCommandArgument>& outArgs, const char* filename) const
  3220. {
  3221. std::string efp = this->GetExecutionFilePath();
  3222. if (!filename)
  3223. {
  3224. filename = efp.c_str();
  3225. }
  3226. std::vector<cmListFileArgument>::const_iterator i;
  3227. std::string value;
  3228. outArgs.reserve(inArgs.size());
  3229. for(i = inArgs.begin(); i != inArgs.end(); ++i)
  3230. {
  3231. // No expansion in a bracket argument.
  3232. if(i->Delim == cmListFileArgument::Bracket)
  3233. {
  3234. outArgs.push_back(cmExpandedCommandArgument(i->Value, true));
  3235. continue;
  3236. }
  3237. // Expand the variables in the argument.
  3238. value = i->Value;
  3239. this->ExpandVariablesInString(value, false, false, false,
  3240. filename, i->Line, false, false);
  3241. // If the argument is quoted, it should be one argument.
  3242. // Otherwise, it may be a list of arguments.
  3243. if(i->Delim == cmListFileArgument::Quoted)
  3244. {
  3245. outArgs.push_back(cmExpandedCommandArgument(value, true));
  3246. }
  3247. else
  3248. {
  3249. std::vector<std::string> stringArgs;
  3250. cmSystemTools::ExpandListArgument(value, stringArgs);
  3251. for(size_t j = 0; j < stringArgs.size(); ++j)
  3252. {
  3253. outArgs.push_back(cmExpandedCommandArgument(stringArgs[j], false));
  3254. }
  3255. }
  3256. }
  3257. return !cmSystemTools::GetFatalErrorOccured();
  3258. }
  3259. //----------------------------------------------------------------------------
  3260. void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb)
  3261. {
  3262. if(!this->ExecutionStatusStack.empty())
  3263. {
  3264. // Record the context in which the blocker is created.
  3265. fb->SetStartingContext(this->GetExecutionContext());
  3266. }
  3267. this->FunctionBlockers.push_back(fb);
  3268. }
  3269. cmsys::auto_ptr<cmFunctionBlocker>
  3270. cmMakefile::RemoveFunctionBlocker(cmFunctionBlocker* fb,
  3271. const cmListFileFunction& lff)
  3272. {
  3273. // Find the function blocker stack barrier for the current scope.
  3274. // We only remove a blocker whose index is not less than the barrier.
  3275. FunctionBlockersType::size_type barrier = 0;
  3276. if(!this->FunctionBlockerBarriers.empty())
  3277. {
  3278. barrier = this->FunctionBlockerBarriers.back();
  3279. }
  3280. // Search for the function blocker whose scope this command ends.
  3281. for(FunctionBlockersType::size_type
  3282. i = this->FunctionBlockers.size(); i > barrier; --i)
  3283. {
  3284. std::vector<cmFunctionBlocker*>::iterator pos =
  3285. this->FunctionBlockers.begin() + (i - 1);
  3286. if (*pos == fb)
  3287. {
  3288. // Warn if the arguments do not match, but always remove.
  3289. if(!(*pos)->ShouldRemove(lff, *this))
  3290. {
  3291. cmListFileContext const& lfc = fb->GetStartingContext();
  3292. cmListFileContext closingContext =
  3293. cmListFileContext::FromCommandContext(lff, lfc.FilePath);
  3294. std::ostringstream e;
  3295. e << "A logical block opening on the line\n"
  3296. << " " << lfc << "\n"
  3297. << "closes on the line\n"
  3298. << " " << closingContext << "\n"
  3299. << "with mis-matching arguments.";
  3300. this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  3301. }
  3302. cmFunctionBlocker* b = *pos;
  3303. this->FunctionBlockers.erase(pos);
  3304. return cmsys::auto_ptr<cmFunctionBlocker>(b);
  3305. }
  3306. }
  3307. return cmsys::auto_ptr<cmFunctionBlocker>();
  3308. }
  3309. const char* cmMakefile::GetHomeDirectory() const
  3310. {
  3311. return this->GetCMakeInstance()->GetHomeDirectory();
  3312. }
  3313. const char* cmMakefile::GetHomeOutputDirectory() const
  3314. {
  3315. return this->GetCMakeInstance()->GetHomeOutputDirectory();
  3316. }
  3317. void cmMakefile::SetScriptModeFile(const char* scriptfile)
  3318. {
  3319. this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile);
  3320. }
  3321. void cmMakefile::SetArgcArgv(const std::vector<std::string>& args)
  3322. {
  3323. std::ostringstream strStream;
  3324. strStream << args.size();
  3325. this->AddDefinition("CMAKE_ARGC", strStream.str().c_str());
  3326. //this->MarkVariableAsUsed("CMAKE_ARGC");
  3327. for (unsigned int t = 0; t < args.size(); ++t)
  3328. {
  3329. std::ostringstream tmpStream;
  3330. tmpStream << "CMAKE_ARGV" << t;
  3331. this->AddDefinition(tmpStream.str(), args[t].c_str());
  3332. //this->MarkVariableAsUsed(tmpStream.str().c_str());
  3333. }
  3334. }
  3335. //----------------------------------------------------------------------------
  3336. cmSourceFile* cmMakefile::GetSource(const std::string& sourceName) const
  3337. {
  3338. cmSourceFileLocation sfl(this, sourceName);
  3339. for(std::vector<cmSourceFile*>::const_iterator
  3340. sfi = this->SourceFiles.begin();
  3341. sfi != this->SourceFiles.end(); ++sfi)
  3342. {
  3343. cmSourceFile* sf = *sfi;
  3344. if(sf->Matches(sfl))
  3345. {
  3346. return sf;
  3347. }
  3348. }
  3349. return 0;
  3350. }
  3351. //----------------------------------------------------------------------------
  3352. cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName,
  3353. bool generated)
  3354. {
  3355. cmSourceFile* sf = new cmSourceFile(this, sourceName);
  3356. if(generated)
  3357. {
  3358. sf->SetProperty("GENERATED", "1");
  3359. }
  3360. this->SourceFiles.push_back(sf);
  3361. return sf;
  3362. }
  3363. //----------------------------------------------------------------------------
  3364. cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName,
  3365. bool generated)
  3366. {
  3367. if(cmSourceFile* esf = this->GetSource(sourceName))
  3368. {
  3369. return esf;
  3370. }
  3371. else
  3372. {
  3373. return this->CreateSource(sourceName, generated);
  3374. }
  3375. }
  3376. void cmMakefile::EnableLanguage(std::vector<std::string> const & lang,
  3377. bool optional)
  3378. {
  3379. this->AddDefinition("CMAKE_CFG_INTDIR",
  3380. this->GetGlobalGenerator()->GetCMakeCFGIntDir());
  3381. this->GetGlobalGenerator()->EnableLanguage(lang, this, optional);
  3382. }
  3383. int cmMakefile::TryCompile(const std::string& srcdir,
  3384. const std::string& bindir,
  3385. const std::string& projectName,
  3386. const std::string& targetName,
  3387. bool fast,
  3388. const std::vector<std::string> *cmakeArgs,
  3389. std::string& output)
  3390. {
  3391. this->Internal->IsSourceFileTryCompile = fast;
  3392. // does the binary directory exist ? If not create it...
  3393. if (!cmSystemTools::FileIsDirectory(bindir))
  3394. {
  3395. cmSystemTools::MakeDirectory(bindir.c_str());
  3396. }
  3397. // change to the tests directory and run cmake
  3398. // use the cmake object instead of calling cmake
  3399. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  3400. cmSystemTools::ChangeDirectory(bindir);
  3401. // make sure the same generator is used
  3402. // use this program as the cmake to be run, it should not
  3403. // be run that way but the cmake object requires a vailid path
  3404. cmake cm;
  3405. cm.SetIsInTryCompile(true);
  3406. cmGlobalGenerator *gg = cm.CreateGlobalGenerator
  3407. (this->GetGlobalGenerator()->GetName());
  3408. if (!gg)
  3409. {
  3410. cmSystemTools::Error(
  3411. "Internal CMake error, TryCompile bad GlobalGenerator");
  3412. // return to the original directory
  3413. cmSystemTools::ChangeDirectory(cwd);
  3414. this->Internal->IsSourceFileTryCompile = false;
  3415. return 1;
  3416. }
  3417. cm.SetGlobalGenerator(gg);
  3418. // do a configure
  3419. cm.SetHomeDirectory(srcdir);
  3420. cm.SetHomeOutputDirectory(bindir);
  3421. cm.SetGeneratorPlatform(this->GetCMakeInstance()->GetGeneratorPlatform());
  3422. cm.SetGeneratorToolset(this->GetCMakeInstance()->GetGeneratorToolset());
  3423. cm.LoadCache();
  3424. if(!gg->IsMultiConfig())
  3425. {
  3426. if(const char* config =
  3427. this->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION"))
  3428. {
  3429. // Tell the single-configuration generator which one to use.
  3430. // Add this before the user-provided CMake arguments in case
  3431. // one of the arguments is -DCMAKE_BUILD_TYPE=...
  3432. cm.AddCacheEntry("CMAKE_BUILD_TYPE", config,
  3433. "Build configuration", cmState::STRING);
  3434. }
  3435. }
  3436. // if cmake args were provided then pass them in
  3437. if (cmakeArgs)
  3438. {
  3439. // FIXME: Workaround to ignore unused CLI variables in try-compile.
  3440. //
  3441. // Ideally we should use SetArgs to honor options like --warn-unused-vars.
  3442. // However, there is a subtle problem when certain arguments are passed to
  3443. // a macro wrapping around try_compile or try_run that does not escape
  3444. // semicolons in its parameters but just passes ${ARGV} or ${ARGN}. In
  3445. // this case a list argument like "-DVAR=a;b" gets split into multiple
  3446. // cmake arguments "-DVAR=a" and "b". Currently SetCacheArgs ignores
  3447. // argument "b" and uses just "-DVAR=a", leading to a subtle bug in that
  3448. // the try_compile or try_run does not get the proper value of VAR. If we
  3449. // call SetArgs here then it would treat "b" as the source directory and
  3450. // cause an error such as "The source directory .../CMakeFiles/CMakeTmp/b
  3451. // does not exist", thus breaking the try_compile or try_run completely.
  3452. //
  3453. // Strictly speaking the bug is in the wrapper macro because the CMake
  3454. // language has always flattened nested lists and the macro should escape
  3455. // the semicolons in its arguments before forwarding them. However, this
  3456. // bug is so subtle that projects typically work anyway, usually because
  3457. // the value VAR=a is sufficient for the try_compile or try_run to get the
  3458. // correct result. Calling SetArgs here would break such projects that
  3459. // previously built. Instead we work around the issue by never reporting
  3460. // unused arguments and ignoring options such as --warn-unused-vars.
  3461. cm.SetWarnUnusedCli(false);
  3462. //cm.SetArgs(*cmakeArgs, true);
  3463. cm.SetCacheArgs(*cmakeArgs);
  3464. }
  3465. // to save time we pass the EnableLanguage info directly
  3466. gg->EnableLanguagesFromGenerator(this->GetGlobalGenerator(), this);
  3467. if(this->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"))
  3468. {
  3469. cm.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS",
  3470. "TRUE", "", cmState::INTERNAL);
  3471. }
  3472. else
  3473. {
  3474. cm.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS",
  3475. "FALSE", "", cmState::INTERNAL);
  3476. }
  3477. if (cm.Configure() != 0)
  3478. {
  3479. cmSystemTools::Error(
  3480. "Internal CMake error, TryCompile configure of cmake failed");
  3481. // return to the original directory
  3482. cmSystemTools::ChangeDirectory(cwd);
  3483. this->Internal->IsSourceFileTryCompile = false;
  3484. return 1;
  3485. }
  3486. if (cm.Generate() != 0)
  3487. {
  3488. cmSystemTools::Error(
  3489. "Internal CMake error, TryCompile generation of cmake failed");
  3490. // return to the original directory
  3491. cmSystemTools::ChangeDirectory(cwd);
  3492. this->Internal->IsSourceFileTryCompile = false;
  3493. return 1;
  3494. }
  3495. // finally call the generator to actually build the resulting project
  3496. int ret = this->GetGlobalGenerator()->TryCompile(srcdir,bindir,
  3497. projectName,
  3498. targetName,
  3499. fast,
  3500. output,
  3501. this);
  3502. cmSystemTools::ChangeDirectory(cwd);
  3503. this->Internal->IsSourceFileTryCompile = false;
  3504. return ret;
  3505. }
  3506. bool cmMakefile::GetIsSourceFileTryCompile() const
  3507. {
  3508. return this->Internal->IsSourceFileTryCompile;
  3509. }
  3510. cmake *cmMakefile::GetCMakeInstance() const
  3511. {
  3512. return this->GetGlobalGenerator()->GetCMakeInstance();
  3513. }
  3514. cmGlobalGenerator* cmMakefile::GetGlobalGenerator() const
  3515. {
  3516. return this->LocalGenerator->GetGlobalGenerator();
  3517. }
  3518. #ifdef CMAKE_BUILD_WITH_CMAKE
  3519. cmVariableWatch *cmMakefile::GetVariableWatch() const
  3520. {
  3521. if ( this->GetCMakeInstance() &&
  3522. this->GetCMakeInstance()->GetVariableWatch() )
  3523. {
  3524. return this->GetCMakeInstance()->GetVariableWatch();
  3525. }
  3526. return 0;
  3527. }
  3528. #endif
  3529. cmState *cmMakefile::GetState() const
  3530. {
  3531. return this->GetCMakeInstance()->GetState();
  3532. }
  3533. void cmMakefile::DisplayStatus(const char* message, float s) const
  3534. {
  3535. cmake* cm = this->GetCMakeInstance();
  3536. if (cm->GetWorkingMode() == cmake::FIND_PACKAGE_MODE)
  3537. {
  3538. // don't output any STATUS message in FIND_PACKAGE_MODE, since they will
  3539. // directly be fed to the compiler, which will be confused.
  3540. return;
  3541. }
  3542. cm->UpdateProgress(message, s);
  3543. }
  3544. std::string cmMakefile::GetModulesFile(const char* filename) const
  3545. {
  3546. std::string result;
  3547. // We search the module always in CMAKE_ROOT and in CMAKE_MODULE_PATH,
  3548. // and then decide based on the policy setting which one to return.
  3549. // See CMP0017 for more details.
  3550. // The specific problem was that KDE 4.5.0 installs a
  3551. // FindPackageHandleStandardArgs.cmake which doesn't have the new features
  3552. // of FPHSA.cmake introduced in CMake 2.8.3 yet, and by setting
  3553. // CMAKE_MODULE_PATH also e.g. FindZLIB.cmake from cmake included
  3554. // FPHSA.cmake from kdelibs and not from CMake, and tried to use the
  3555. // new features, which were not there in the version from kdelibs, and so
  3556. // failed ("
  3557. std::string moduleInCMakeRoot;
  3558. std::string moduleInCMakeModulePath;
  3559. // Always search in CMAKE_MODULE_PATH:
  3560. const char* cmakeModulePath = this->GetDefinition("CMAKE_MODULE_PATH");
  3561. if(cmakeModulePath)
  3562. {
  3563. std::vector<std::string> modulePath;
  3564. cmSystemTools::ExpandListArgument(cmakeModulePath, modulePath);
  3565. //Look through the possible module directories.
  3566. for(std::vector<std::string>::iterator i = modulePath.begin();
  3567. i != modulePath.end(); ++i)
  3568. {
  3569. std::string itempl = *i;
  3570. cmSystemTools::ConvertToUnixSlashes(itempl);
  3571. itempl += "/";
  3572. itempl += filename;
  3573. if(cmSystemTools::FileExists(itempl.c_str()))
  3574. {
  3575. moduleInCMakeModulePath = itempl;
  3576. break;
  3577. }
  3578. }
  3579. }
  3580. // Always search in the standard modules location.
  3581. const char* cmakeRoot = this->GetDefinition("CMAKE_ROOT");
  3582. if(cmakeRoot)
  3583. {
  3584. moduleInCMakeRoot = cmakeRoot;
  3585. moduleInCMakeRoot += "/Modules/";
  3586. moduleInCMakeRoot += filename;
  3587. cmSystemTools::ConvertToUnixSlashes(moduleInCMakeRoot);
  3588. if(!cmSystemTools::FileExists(moduleInCMakeRoot.c_str()))
  3589. {
  3590. moduleInCMakeRoot = "";
  3591. }
  3592. }
  3593. // Normally, prefer the files found in CMAKE_MODULE_PATH. Only when the file
  3594. // from which we are being called is located itself in CMAKE_ROOT, then
  3595. // prefer results from CMAKE_ROOT depending on the policy setting.
  3596. result = moduleInCMakeModulePath;
  3597. if (result.empty())
  3598. {
  3599. result = moduleInCMakeRoot;
  3600. }
  3601. if (!moduleInCMakeModulePath.empty() && !moduleInCMakeRoot.empty())
  3602. {
  3603. const char* currentFile = this->GetDefinition("CMAKE_CURRENT_LIST_FILE");
  3604. std::string mods = cmakeRoot + std::string("/Modules/");
  3605. if (currentFile && strncmp(currentFile, mods.c_str(), mods.size()) == 0)
  3606. {
  3607. switch (this->GetPolicyStatus(cmPolicies::CMP0017))
  3608. {
  3609. case cmPolicies::WARN:
  3610. {
  3611. std::ostringstream e;
  3612. e << "File " << currentFile << " includes "
  3613. << moduleInCMakeModulePath
  3614. << " (found via CMAKE_MODULE_PATH) which shadows "
  3615. << moduleInCMakeRoot << ". This may cause errors later on .\n"
  3616. << cmPolicies::GetPolicyWarning(cmPolicies::CMP0017);
  3617. this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  3618. // break; // fall through to OLD behaviour
  3619. }
  3620. case cmPolicies::OLD:
  3621. result = moduleInCMakeModulePath;
  3622. break;
  3623. case cmPolicies::REQUIRED_IF_USED:
  3624. case cmPolicies::REQUIRED_ALWAYS:
  3625. case cmPolicies::NEW:
  3626. result = moduleInCMakeRoot;
  3627. break;
  3628. }
  3629. }
  3630. }
  3631. return result;
  3632. }
  3633. void cmMakefile::ConfigureString(const std::string& input,
  3634. std::string& output, bool atOnly,
  3635. bool escapeQuotes) const
  3636. {
  3637. // Split input to handle one line at a time.
  3638. std::string::const_iterator lineStart = input.begin();
  3639. while(lineStart != input.end())
  3640. {
  3641. // Find the end of this line.
  3642. std::string::const_iterator lineEnd = lineStart;
  3643. while(lineEnd != input.end() && *lineEnd != '\n')
  3644. {
  3645. ++lineEnd;
  3646. }
  3647. // Copy the line.
  3648. std::string line(lineStart, lineEnd);
  3649. // Skip the newline character.
  3650. bool haveNewline = (lineEnd != input.end());
  3651. if(haveNewline)
  3652. {
  3653. ++lineEnd;
  3654. }
  3655. // Replace #cmakedefine instances.
  3656. if(this->cmDefineRegex.find(line))
  3657. {
  3658. const char* def =
  3659. this->GetDefinition(this->cmDefineRegex.match(1));
  3660. if(!cmSystemTools::IsOff(def))
  3661. {
  3662. cmSystemTools::ReplaceString(line, "#cmakedefine", "#define");
  3663. output += line;
  3664. }
  3665. else
  3666. {
  3667. output += "/* #undef ";
  3668. output += this->cmDefineRegex.match(1);
  3669. output += " */";
  3670. }
  3671. }
  3672. else if(this->cmDefine01Regex.find(line))
  3673. {
  3674. const char* def =
  3675. this->GetDefinition(this->cmDefine01Regex.match(1));
  3676. cmSystemTools::ReplaceString(line, "#cmakedefine01", "#define");
  3677. output += line;
  3678. if(!cmSystemTools::IsOff(def))
  3679. {
  3680. output += " 1";
  3681. }
  3682. else
  3683. {
  3684. output += " 0";
  3685. }
  3686. }
  3687. else
  3688. {
  3689. output += line;
  3690. }
  3691. if(haveNewline)
  3692. {
  3693. output += "\n";
  3694. }
  3695. // Move to the next line.
  3696. lineStart = lineEnd;
  3697. }
  3698. // Perform variable replacements.
  3699. this->ExpandVariablesInString(output, escapeQuotes, true,
  3700. atOnly, 0, -1, true, true);
  3701. }
  3702. int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
  3703. bool copyonly, bool atOnly, bool escapeQuotes,
  3704. const cmNewLineStyle& newLine)
  3705. {
  3706. int res = 1;
  3707. if ( !this->CanIWriteThisFile(outfile) )
  3708. {
  3709. cmSystemTools::Error("Attempt to write file: ",
  3710. outfile, " into a source directory.");
  3711. return 0;
  3712. }
  3713. if ( !cmSystemTools::FileExists(infile) )
  3714. {
  3715. cmSystemTools::Error("File ", infile, " does not exist.");
  3716. return 0;
  3717. }
  3718. std::string soutfile = outfile;
  3719. std::string sinfile = infile;
  3720. this->AddCMakeDependFile(sinfile);
  3721. cmSystemTools::ConvertToUnixSlashes(soutfile);
  3722. // Re-generate if non-temporary outputs are missing.
  3723. //when we finalize the configuration we will remove all
  3724. //output files that now don't exist.
  3725. this->AddCMakeOutputFile(soutfile);
  3726. mode_t perm = 0;
  3727. cmSystemTools::GetPermissions(sinfile.c_str(), perm);
  3728. std::string::size_type pos = soutfile.rfind('/');
  3729. if(pos != std::string::npos)
  3730. {
  3731. std::string path = soutfile.substr(0, pos);
  3732. cmSystemTools::MakeDirectory(path.c_str());
  3733. }
  3734. if(copyonly)
  3735. {
  3736. if ( !cmSystemTools::CopyFileIfDifferent(sinfile.c_str(),
  3737. soutfile.c_str()))
  3738. {
  3739. return 0;
  3740. }
  3741. }
  3742. else
  3743. {
  3744. std::string newLineCharacters;
  3745. std::ios_base::openmode omode = std::ios_base::out | std::ios_base::trunc;
  3746. if (newLine.IsValid())
  3747. {
  3748. newLineCharacters = newLine.GetCharacters();
  3749. omode |= std::ios::binary;
  3750. }
  3751. else
  3752. {
  3753. newLineCharacters = "\n";
  3754. }
  3755. std::string tempOutputFile = soutfile;
  3756. tempOutputFile += ".tmp";
  3757. cmsys::ofstream fout(tempOutputFile.c_str(), omode);
  3758. if(!fout)
  3759. {
  3760. cmSystemTools::Error(
  3761. "Could not open file for write in copy operation ",
  3762. tempOutputFile.c_str());
  3763. cmSystemTools::ReportLastSystemError("");
  3764. return 0;
  3765. }
  3766. cmsys::ifstream fin(sinfile.c_str());
  3767. if(!fin)
  3768. {
  3769. cmSystemTools::Error("Could not open file for read in copy operation ",
  3770. sinfile.c_str());
  3771. return 0;
  3772. }
  3773. cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin);
  3774. if(bom != cmsys::FStream::BOM_None &&
  3775. bom != cmsys::FStream::BOM_UTF8)
  3776. {
  3777. std::ostringstream e;
  3778. e << "File starts with a Byte-Order-Mark that is not UTF-8:\n "
  3779. << sinfile;
  3780. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  3781. return 0;
  3782. }
  3783. // rewind to copy BOM to output file
  3784. fin.seekg(0);
  3785. // now copy input to output and expand variables in the
  3786. // input file at the same time
  3787. std::string inLine;
  3788. std::string outLine;
  3789. while( cmSystemTools::GetLineFromStream(fin, inLine) )
  3790. {
  3791. outLine = "";
  3792. this->ConfigureString(inLine, outLine, atOnly, escapeQuotes);
  3793. fout << outLine.c_str() << newLineCharacters;
  3794. }
  3795. // close the files before attempting to copy
  3796. fin.close();
  3797. fout.close();
  3798. if ( !cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(),
  3799. soutfile.c_str()) )
  3800. {
  3801. res = 0;
  3802. }
  3803. else
  3804. {
  3805. cmSystemTools::SetPermissions(soutfile.c_str(), perm);
  3806. }
  3807. cmSystemTools::RemoveFile(tempOutputFile);
  3808. }
  3809. return res;
  3810. }
  3811. void cmMakefile::SetProperty(const std::string& prop, const char* value)
  3812. {
  3813. if (prop == "INCLUDE_DIRECTORIES")
  3814. {
  3815. if (!value)
  3816. {
  3817. this->StateSnapshot.GetDirectory().ClearIncludeDirectories();
  3818. return;
  3819. }
  3820. cmListFileBacktrace lfbt = this->GetBacktrace();
  3821. this->StateSnapshot.GetDirectory().SetIncludeDirectories(value, lfbt);
  3822. return;
  3823. }
  3824. if (prop == "COMPILE_OPTIONS")
  3825. {
  3826. if (!value)
  3827. {
  3828. this->StateSnapshot.GetDirectory().ClearCompileOptions();
  3829. return;
  3830. }
  3831. cmListFileBacktrace lfbt = this->GetBacktrace();
  3832. this->StateSnapshot.GetDirectory().SetCompileOptions(value, lfbt);
  3833. return;
  3834. }
  3835. if (prop == "COMPILE_DEFINITIONS")
  3836. {
  3837. if (!value)
  3838. {
  3839. this->StateSnapshot.GetDirectory().ClearCompileDefinitions();
  3840. return;
  3841. }
  3842. cmListFileBacktrace lfbt = this->GetBacktrace();
  3843. this->StateSnapshot.GetDirectory().SetCompileDefinitions(value, lfbt);
  3844. return;
  3845. }
  3846. this->Properties.SetProperty(prop, value);
  3847. }
  3848. void cmMakefile::AppendProperty(const std::string& prop,
  3849. const char* value,
  3850. bool asString)
  3851. {
  3852. if (prop == "INCLUDE_DIRECTORIES")
  3853. {
  3854. cmListFileBacktrace lfbt = this->GetBacktrace();
  3855. this->StateSnapshot.GetDirectory().AppendIncludeDirectoriesEntry(value,
  3856. lfbt);
  3857. return;
  3858. }
  3859. if (prop == "COMPILE_OPTIONS")
  3860. {
  3861. cmListFileBacktrace lfbt = this->GetBacktrace();
  3862. this->StateSnapshot.GetDirectory().AppendCompileOptionsEntry(value, lfbt);
  3863. return;
  3864. }
  3865. if (prop == "COMPILE_DEFINITIONS")
  3866. {
  3867. cmListFileBacktrace lfbt = this->GetBacktrace();
  3868. this->StateSnapshot.GetDirectory().AppendCompileDefinitionsEntry(value,
  3869. lfbt);
  3870. return;
  3871. }
  3872. this->Properties.AppendProperty(prop, value, asString);
  3873. }
  3874. const char *cmMakefile::GetProperty(const std::string& prop) const
  3875. {
  3876. const bool chain = this->GetState()->
  3877. IsPropertyChained(prop, cmProperty::DIRECTORY);
  3878. return this->GetProperty(prop, chain);
  3879. }
  3880. const char *cmMakefile::GetProperty(const std::string& prop,
  3881. bool chain) const
  3882. {
  3883. // watch for specific properties
  3884. static std::string output;
  3885. output = "";
  3886. if (prop == "PARENT_DIRECTORY")
  3887. {
  3888. cmState::Snapshot parent =
  3889. this->StateSnapshot.GetBuildsystemDirectoryParent();
  3890. if(parent.IsValid())
  3891. {
  3892. return parent.GetDirectory().GetCurrentSource();
  3893. }
  3894. return "";
  3895. }
  3896. else if (prop == "LISTFILE_STACK")
  3897. {
  3898. std::vector<std::string> listFiles;
  3899. cmState::Snapshot snp = this->StateSnapshot;
  3900. while (snp.IsValid())
  3901. {
  3902. listFiles.push_back(snp.GetExecutionListFile());
  3903. snp = snp.GetCallStackParent();
  3904. }
  3905. std::reverse(listFiles.begin(), listFiles.end());
  3906. output = cmJoin(listFiles, ";");
  3907. return output.c_str();
  3908. }
  3909. else if ( prop == "CACHE_VARIABLES" )
  3910. {
  3911. output = cmJoin(this->GetState()->GetCacheEntryKeys(), ";");
  3912. return output.c_str();
  3913. }
  3914. else if (prop == "VARIABLES")
  3915. {
  3916. output = cmJoin(this->GetDefinitions(), ";");
  3917. return output.c_str();
  3918. }
  3919. else if (prop == "INCLUDE_DIRECTORIES")
  3920. {
  3921. output = cmJoin(this->StateSnapshot.GetDirectory()
  3922. .GetIncludeDirectoriesEntries(), ";");
  3923. return output.c_str();
  3924. }
  3925. else if (prop == "COMPILE_OPTIONS")
  3926. {
  3927. output = cmJoin(this->StateSnapshot.GetDirectory()
  3928. .GetCompileOptionsEntries(), ";");
  3929. return output.c_str();
  3930. }
  3931. else if (prop == "COMPILE_DEFINITIONS")
  3932. {
  3933. output = cmJoin(this->StateSnapshot.GetDirectory()
  3934. .GetCompileDefinitionsEntries(), ";");
  3935. return output.c_str();
  3936. }
  3937. const char *retVal = this->Properties.GetPropertyValue(prop);
  3938. if (!retVal && chain)
  3939. {
  3940. if(this->LocalGenerator->GetParent())
  3941. {
  3942. return this->LocalGenerator->GetParent()->GetMakefile()->
  3943. GetProperty(prop, chain);
  3944. }
  3945. return this->GetState()->GetGlobalProperty(prop);
  3946. }
  3947. return retVal;
  3948. }
  3949. bool cmMakefile::GetPropertyAsBool(const std::string& prop) const
  3950. {
  3951. return cmSystemTools::IsOn(this->GetProperty(prop));
  3952. }
  3953. std::vector<std::string> cmMakefile::GetPropertyKeys() const
  3954. {
  3955. std::vector<std::string> keys;
  3956. keys.reserve(this->Properties.size());
  3957. for(cmPropertyMap::const_iterator it = this->Properties.begin();
  3958. it != this->Properties.end(); ++it)
  3959. {
  3960. keys.push_back(it->first);
  3961. }
  3962. return keys;
  3963. }
  3964. cmTarget* cmMakefile::FindTarget(const std::string& name,
  3965. bool excludeAliases) const
  3966. {
  3967. if (!excludeAliases)
  3968. {
  3969. TargetMap::const_iterator i = this->AliasTargets.find(name);
  3970. if (i != this->AliasTargets.end())
  3971. {
  3972. return i->second;
  3973. }
  3974. }
  3975. cmTargets::iterator i = this->Targets.find( name );
  3976. if ( i != this->Targets.end() )
  3977. {
  3978. return &i->second;
  3979. }
  3980. return 0;
  3981. }
  3982. //----------------------------------------------------------------------------
  3983. cmTest* cmMakefile::CreateTest(const std::string& testName)
  3984. {
  3985. cmTest* test = this->GetTest(testName);
  3986. if ( test )
  3987. {
  3988. return test;
  3989. }
  3990. test = new cmTest(this);
  3991. test->SetName(testName);
  3992. this->Tests[testName] = test;
  3993. return test;
  3994. }
  3995. //----------------------------------------------------------------------------
  3996. cmTest* cmMakefile::GetTest(const std::string& testName) const
  3997. {
  3998. std::map<std::string, cmTest*>::const_iterator
  3999. mi = this->Tests.find(testName);
  4000. if(mi != this->Tests.end())
  4001. {
  4002. return mi->second;
  4003. }
  4004. return 0;
  4005. }
  4006. void cmMakefile::AddCMakeDependFilesFromUser()
  4007. {
  4008. std::vector<std::string> deps;
  4009. if(const char* deps_str = this->GetProperty("CMAKE_CONFIGURE_DEPENDS"))
  4010. {
  4011. cmSystemTools::ExpandListArgument(deps_str, deps);
  4012. }
  4013. for(std::vector<std::string>::iterator i = deps.begin();
  4014. i != deps.end(); ++i)
  4015. {
  4016. if(cmSystemTools::FileIsFullPath(i->c_str()))
  4017. {
  4018. this->AddCMakeDependFile(*i);
  4019. }
  4020. else
  4021. {
  4022. std::string f = this->GetCurrentSourceDirectory();
  4023. f += "/";
  4024. f += *i;
  4025. this->AddCMakeDependFile(f);
  4026. }
  4027. }
  4028. }
  4029. std::string cmMakefile::FormatListFileStack() const
  4030. {
  4031. std::vector<std::string> listFiles;
  4032. cmState::Snapshot snp = this->StateSnapshot;
  4033. while (snp.IsValid())
  4034. {
  4035. listFiles.push_back(snp.GetExecutionListFile());
  4036. snp = snp.GetCallStackParent();
  4037. }
  4038. std::reverse(listFiles.begin(), listFiles.end());
  4039. std::ostringstream tmp;
  4040. size_t depth = listFiles.size();
  4041. if (depth > 0)
  4042. {
  4043. std::vector<std::string>::const_iterator it = listFiles.end();
  4044. do
  4045. {
  4046. if (depth != listFiles.size())
  4047. {
  4048. tmp << "\n ";
  4049. }
  4050. --it;
  4051. tmp << "[";
  4052. tmp << depth;
  4053. tmp << "]\t";
  4054. tmp << *it;
  4055. depth--;
  4056. }
  4057. while (it != listFiles.begin());
  4058. }
  4059. return tmp.str();
  4060. }
  4061. void cmMakefile::PushScope()
  4062. {
  4063. this->Internal->PushDefinitions(Internals::VariableScope);
  4064. this->PushLoopBlockBarrier();
  4065. #if defined(CMAKE_BUILD_WITH_CMAKE)
  4066. this->GetGlobalGenerator()->GetFileLockPool().PushFunctionScope();
  4067. #endif
  4068. }
  4069. void cmMakefile::PopScope()
  4070. {
  4071. #if defined(CMAKE_BUILD_WITH_CMAKE)
  4072. this->GetGlobalGenerator()->GetFileLockPool().PopFunctionScope();
  4073. #endif
  4074. this->PopLoopBlockBarrier();
  4075. this->CheckForUnusedVariables();
  4076. this->Internal->PopDefinitions();
  4077. }
  4078. void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
  4079. {
  4080. if (var.empty())
  4081. {
  4082. return;
  4083. }
  4084. if (!this->Internal->RaiseScope(var, varDef, this))
  4085. {
  4086. std::ostringstream m;
  4087. m << "Cannot set \"" << var << "\": current scope has no parent.";
  4088. this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
  4089. }
  4090. }
  4091. //----------------------------------------------------------------------------
  4092. cmTarget*
  4093. cmMakefile::AddImportedTarget(const std::string& name,
  4094. cmTarget::TargetType type,
  4095. bool global)
  4096. {
  4097. // Create the target.
  4098. cmsys::auto_ptr<cmTarget> target(new cmTarget);
  4099. target->SetType(type, name);
  4100. target->MarkAsImported();
  4101. target->SetMakefile(this);
  4102. // Add to the set of available imported targets.
  4103. this->ImportedTargets[name] = target.get();
  4104. if(global)
  4105. {
  4106. this->GetGlobalGenerator()->AddTarget(target.get());
  4107. }
  4108. // Transfer ownership to this cmMakefile object.
  4109. this->ImportedTargetsOwned.push_back(target.get());
  4110. return target.release();
  4111. }
  4112. //----------------------------------------------------------------------------
  4113. cmTarget* cmMakefile::FindTargetToUse(const std::string& name,
  4114. bool excludeAliases) const
  4115. {
  4116. // Look for an imported target. These take priority because they
  4117. // are more local in scope and do not have to be globally unique.
  4118. TargetMap::const_iterator
  4119. imported = this->ImportedTargets.find(name);
  4120. if(imported != this->ImportedTargets.end())
  4121. {
  4122. return imported->second;
  4123. }
  4124. // Look for a target built in this directory.
  4125. if(cmTarget* t = this->FindTarget(name, excludeAliases))
  4126. {
  4127. return t;
  4128. }
  4129. // Look for a target built in this project.
  4130. return this->GetGlobalGenerator()->FindTarget(name, excludeAliases);
  4131. }
  4132. //----------------------------------------------------------------------------
  4133. bool cmMakefile::IsAlias(const std::string& name) const
  4134. {
  4135. if (this->AliasTargets.find(name) != this->AliasTargets.end())
  4136. return true;
  4137. return this->GetGlobalGenerator()->IsAlias(name);
  4138. }
  4139. //----------------------------------------------------------------------------
  4140. cmGeneratorTarget*
  4141. cmMakefile::FindGeneratorTargetToUse(const std::string& name) const
  4142. {
  4143. if (cmTarget *t = this->FindTargetToUse(name))
  4144. {
  4145. return this->GetGlobalGenerator()->GetGeneratorTarget(t);
  4146. }
  4147. return 0;
  4148. }
  4149. //----------------------------------------------------------------------------
  4150. bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
  4151. bool isCustom) const
  4152. {
  4153. if(this->IsAlias(name))
  4154. {
  4155. std::ostringstream e;
  4156. e << "cannot create target \"" << name
  4157. << "\" because an alias with the same name already exists.";
  4158. msg = e.str();
  4159. return false;
  4160. }
  4161. if(cmTarget* existing = this->FindTargetToUse(name))
  4162. {
  4163. // The name given conflicts with an existing target. Produce an
  4164. // error in a compatible way.
  4165. if(existing->IsImported())
  4166. {
  4167. // Imported targets were not supported in previous versions.
  4168. // This is new code, so we can make it an error.
  4169. std::ostringstream e;
  4170. e << "cannot create target \"" << name
  4171. << "\" because an imported target with the same name already exists.";
  4172. msg = e.str();
  4173. return false;
  4174. }
  4175. else
  4176. {
  4177. // target names must be globally unique
  4178. switch (this->GetPolicyStatus(cmPolicies::CMP0002))
  4179. {
  4180. case cmPolicies::WARN:
  4181. this->IssueMessage(cmake::AUTHOR_WARNING, cmPolicies::
  4182. GetPolicyWarning(cmPolicies::CMP0002));
  4183. case cmPolicies::OLD:
  4184. return true;
  4185. case cmPolicies::REQUIRED_IF_USED:
  4186. case cmPolicies::REQUIRED_ALWAYS:
  4187. this->IssueMessage(cmake::FATAL_ERROR,
  4188. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0002)
  4189. );
  4190. return true;
  4191. case cmPolicies::NEW:
  4192. break;
  4193. }
  4194. // The conflict is with a non-imported target.
  4195. // Allow this if the user has requested support.
  4196. cmake* cm = this->GetCMakeInstance();
  4197. if(isCustom && existing->GetType() == cmTarget::UTILITY &&
  4198. this != existing->GetMakefile() &&
  4199. cm->GetState()
  4200. ->GetGlobalPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
  4201. {
  4202. return true;
  4203. }
  4204. // Produce an error that tells the user how to work around the
  4205. // problem.
  4206. std::ostringstream e;
  4207. e << "cannot create target \"" << name
  4208. << "\" because another target with the same name already exists. "
  4209. << "The existing target is ";
  4210. switch(existing->GetType())
  4211. {
  4212. case cmTarget::EXECUTABLE:
  4213. e << "an executable ";
  4214. break;
  4215. case cmTarget::STATIC_LIBRARY:
  4216. e << "a static library ";
  4217. break;
  4218. case cmTarget::SHARED_LIBRARY:
  4219. e << "a shared library ";
  4220. break;
  4221. case cmTarget::MODULE_LIBRARY:
  4222. e << "a module library ";
  4223. break;
  4224. case cmTarget::UTILITY:
  4225. e << "a custom target ";
  4226. break;
  4227. case cmTarget::INTERFACE_LIBRARY:
  4228. e << "an interface library ";
  4229. break;
  4230. default: break;
  4231. }
  4232. e << "created in source directory \""
  4233. << existing->GetMakefile()->GetCurrentSourceDirectory() << "\". "
  4234. << "See documentation for policy CMP0002 for more details.";
  4235. msg = e.str();
  4236. return false;
  4237. }
  4238. }
  4239. return true;
  4240. }
  4241. //----------------------------------------------------------------------------
  4242. bool cmMakefile::EnforceUniqueDir(const std::string& srcPath,
  4243. const std::string& binPath) const
  4244. {
  4245. // Make sure the binary directory is unique.
  4246. cmGlobalGenerator* gg = this->GetGlobalGenerator();
  4247. if(gg->BinaryDirectoryIsNew(binPath))
  4248. {
  4249. return true;
  4250. }
  4251. std::ostringstream e;
  4252. switch (this->GetPolicyStatus(cmPolicies::CMP0013))
  4253. {
  4254. case cmPolicies::WARN:
  4255. // Print the warning.
  4256. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0013)
  4257. << "\n"
  4258. << "The binary directory\n"
  4259. << " " << binPath << "\n"
  4260. << "is already used to build a source directory. "
  4261. << "This command uses it to build source directory\n"
  4262. << " " << srcPath << "\n"
  4263. << "which can generate conflicting build files. "
  4264. << "CMake does not support this use case but it used "
  4265. << "to work accidentally and is being allowed for "
  4266. << "compatibility.";
  4267. this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  4268. case cmPolicies::OLD:
  4269. // OLD behavior does not warn.
  4270. return true;
  4271. case cmPolicies::REQUIRED_IF_USED:
  4272. case cmPolicies::REQUIRED_ALWAYS:
  4273. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0013)
  4274. << "\n";
  4275. case cmPolicies::NEW:
  4276. // NEW behavior prints the error.
  4277. e << "The binary directory\n"
  4278. << " " << binPath << "\n"
  4279. << "is already used to build a source directory. "
  4280. << "It cannot be used to build source directory\n"
  4281. << " " << srcPath << "\n"
  4282. << "Specify a unique binary directory name.";
  4283. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  4284. break;
  4285. }
  4286. return false;
  4287. }
  4288. //----------------------------------------------------------------------------
  4289. void cmMakefile::AddQtUiFileWithOptions(cmSourceFile *sf)
  4290. {
  4291. this->QtUiFilesWithOptions.push_back(sf);
  4292. }
  4293. //----------------------------------------------------------------------------
  4294. std::vector<cmSourceFile*> cmMakefile::GetQtUiFilesWithOptions() const
  4295. {
  4296. return this->QtUiFilesWithOptions;
  4297. }
  4298. static std::string const matchVariables[] = {
  4299. "CMAKE_MATCH_0",
  4300. "CMAKE_MATCH_1",
  4301. "CMAKE_MATCH_2",
  4302. "CMAKE_MATCH_3",
  4303. "CMAKE_MATCH_4",
  4304. "CMAKE_MATCH_5",
  4305. "CMAKE_MATCH_6",
  4306. "CMAKE_MATCH_7",
  4307. "CMAKE_MATCH_8",
  4308. "CMAKE_MATCH_9"
  4309. };
  4310. static std::string const nMatchesVariable = "CMAKE_MATCH_COUNT";
  4311. //----------------------------------------------------------------------------
  4312. void cmMakefile::ClearMatches()
  4313. {
  4314. const char* nMatchesStr = this->GetDefinition(nMatchesVariable);
  4315. if (!nMatchesStr)
  4316. {
  4317. return;
  4318. }
  4319. int nMatches = atoi(nMatchesStr);
  4320. for (int i=0; i<=nMatches; i++)
  4321. {
  4322. std::string const& var = matchVariables[i];
  4323. std::string const& s = this->GetSafeDefinition(var);
  4324. if(!s.empty())
  4325. {
  4326. this->AddDefinition(var, "");
  4327. this->MarkVariableAsUsed(var);
  4328. }
  4329. }
  4330. this->AddDefinition(nMatchesVariable, "0");
  4331. this->MarkVariableAsUsed(nMatchesVariable);
  4332. }
  4333. //----------------------------------------------------------------------------
  4334. void cmMakefile::StoreMatches(cmsys::RegularExpression& re)
  4335. {
  4336. char highest = 0;
  4337. for (int i=0; i<10; i++)
  4338. {
  4339. std::string const& m = re.match(i);
  4340. if(!m.empty())
  4341. {
  4342. std::string const& var = matchVariables[i];
  4343. this->AddDefinition(var, m.c_str());
  4344. this->MarkVariableAsUsed(var);
  4345. highest = static_cast<char>('0' + i);
  4346. }
  4347. }
  4348. char nMatches[] = {highest, '\0'};
  4349. this->AddDefinition(nMatchesVariable, nMatches);
  4350. this->MarkVariableAsUsed(nMatchesVariable);
  4351. }
  4352. cmState::Snapshot cmMakefile::GetStateSnapshot() const
  4353. {
  4354. return this->StateSnapshot;
  4355. }
  4356. const char* cmMakefile::GetDefineFlagsCMP0059() const
  4357. {
  4358. return this->DefineFlagsOrig.c_str();
  4359. }
  4360. //----------------------------------------------------------------------------
  4361. cmPolicies::PolicyStatus
  4362. cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id) const
  4363. {
  4364. return this->StateSnapshot.GetPolicy(id);
  4365. }
  4366. //----------------------------------------------------------------------------
  4367. bool cmMakefile::PolicyOptionalWarningEnabled(std::string const& var)
  4368. {
  4369. // Check for an explicit CMAKE_POLICY_WARNING_CMP<NNNN> setting.
  4370. if(!var.empty())
  4371. {
  4372. if(const char* val = this->GetDefinition(var))
  4373. {
  4374. return cmSystemTools::IsOn(val);
  4375. }
  4376. }
  4377. // Enable optional policy warnings with --debug-output, --trace,
  4378. // or --trace-expand.
  4379. cmake* cm = this->GetCMakeInstance();
  4380. return cm->GetDebugOutput() || cm->GetTrace();
  4381. }
  4382. bool cmMakefile::SetPolicy(const char *id,
  4383. cmPolicies::PolicyStatus status)
  4384. {
  4385. cmPolicies::PolicyID pid;
  4386. if (!cmPolicies::GetPolicyID(id, /* out */ pid))
  4387. {
  4388. std::ostringstream e;
  4389. e << "Policy \"" << id << "\" is not known to this version of CMake.";
  4390. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  4391. return false;
  4392. }
  4393. return this->SetPolicy(pid,status);
  4394. }
  4395. //----------------------------------------------------------------------------
  4396. bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
  4397. cmPolicies::PolicyStatus status)
  4398. {
  4399. // A REQUIRED_ALWAYS policy may be set only to NEW.
  4400. if(status != cmPolicies::NEW &&
  4401. cmPolicies::GetPolicyStatus(id) ==
  4402. cmPolicies::REQUIRED_ALWAYS)
  4403. {
  4404. std::string msg =
  4405. cmPolicies::GetRequiredAlwaysPolicyError(id);
  4406. this->IssueMessage(cmake::FATAL_ERROR, msg);
  4407. return false;
  4408. }
  4409. this->StateSnapshot.SetPolicy(id, status);
  4410. return true;
  4411. }
  4412. //----------------------------------------------------------------------------
  4413. cmMakefile::PolicyPushPop::PolicyPushPop(cmMakefile* m, bool weak,
  4414. cmPolicies::PolicyMap const& pm):
  4415. Makefile(m), ReportError(true)
  4416. {
  4417. this->Makefile->StateSnapshot = this->Makefile->StateSnapshot.GetState()
  4418. ->CreatePolicyScopeSnapshot(this->Makefile->StateSnapshot);
  4419. this->Makefile->PushPolicy(weak, pm);
  4420. }
  4421. //----------------------------------------------------------------------------
  4422. cmMakefile::PolicyPushPop::~PolicyPushPop()
  4423. {
  4424. this->Makefile->PopPolicy();
  4425. this->Makefile->PopPolicyBarrier(this->ReportError);
  4426. }
  4427. //----------------------------------------------------------------------------
  4428. void cmMakefile::PushPolicy(bool weak, cmPolicies::PolicyMap const& pm)
  4429. {
  4430. this->StateSnapshot.PushPolicy(pm, weak);
  4431. }
  4432. //----------------------------------------------------------------------------
  4433. void cmMakefile::PopPolicy()
  4434. {
  4435. if (!this->StateSnapshot.PopPolicy())
  4436. {
  4437. this->IssueMessage(cmake::FATAL_ERROR,
  4438. "cmake_policy POP without matching PUSH");
  4439. }
  4440. }
  4441. //----------------------------------------------------------------------------
  4442. void cmMakefile::PopPolicyBarrier(bool reportError)
  4443. {
  4444. while (!this->StateSnapshot.CanPopPolicyScope())
  4445. {
  4446. if(reportError)
  4447. {
  4448. this->IssueMessage(cmake::FATAL_ERROR,
  4449. "cmake_policy PUSH without matching POP");
  4450. reportError = false;
  4451. }
  4452. this->PopPolicy();
  4453. }
  4454. this->StateSnapshot = this->GetState()->Pop(this->StateSnapshot);
  4455. assert(this->StateSnapshot.IsValid());
  4456. }
  4457. //----------------------------------------------------------------------------
  4458. bool cmMakefile::SetPolicyVersion(const char *version)
  4459. {
  4460. return cmPolicies::ApplyPolicyVersion(this,version);
  4461. }
  4462. //----------------------------------------------------------------------------
  4463. bool cmMakefile::HasCMP0054AlreadyBeenReported() const
  4464. {
  4465. return !this->CMP0054ReportedIds.insert(this->GetExecutionContext()).second;
  4466. }
  4467. //----------------------------------------------------------------------------
  4468. void cmMakefile::RecordPolicies(cmPolicies::PolicyMap& pm)
  4469. {
  4470. /* Record the setting of every policy. */
  4471. typedef cmPolicies::PolicyID PolicyID;
  4472. for(PolicyID pid = cmPolicies::CMP0000;
  4473. pid != cmPolicies::CMPCOUNT; pid = PolicyID(pid+1))
  4474. {
  4475. pm.Set(pid, this->GetPolicyStatus(pid));
  4476. }
  4477. }
  4478. //----------------------------------------------------------------------------
  4479. bool cmMakefile::IgnoreErrorsCMP0061() const
  4480. {
  4481. bool ignoreErrors = true;
  4482. switch (this->GetPolicyStatus(cmPolicies::CMP0061))
  4483. {
  4484. case cmPolicies::WARN:
  4485. // No warning for this policy!
  4486. case cmPolicies::OLD:
  4487. break;
  4488. case cmPolicies::REQUIRED_IF_USED:
  4489. case cmPolicies::REQUIRED_ALWAYS:
  4490. case cmPolicies::NEW:
  4491. ignoreErrors = false;
  4492. break;
  4493. }
  4494. return ignoreErrors;
  4495. }
  4496. //----------------------------------------------------------------------------
  4497. #define FEATURE_STRING(F) , #F
  4498. static const char * const C_FEATURES[] = {
  4499. 0
  4500. FOR_EACH_C_FEATURE(FEATURE_STRING)
  4501. };
  4502. static const char * const CXX_FEATURES[] = {
  4503. 0
  4504. FOR_EACH_CXX_FEATURE(FEATURE_STRING)
  4505. };
  4506. #undef FEATURE_STRING
  4507. static const char * const C_STANDARDS[] = {
  4508. "90"
  4509. , "99"
  4510. , "11"
  4511. };
  4512. static const char * const CXX_STANDARDS[] = {
  4513. "98"
  4514. , "11"
  4515. , "14"
  4516. };
  4517. //----------------------------------------------------------------------------
  4518. bool cmMakefile::
  4519. AddRequiredTargetFeature(cmTarget *target, const std::string& feature,
  4520. std::string *error) const
  4521. {
  4522. if (cmGeneratorExpression::Find(feature) != std::string::npos)
  4523. {
  4524. target->AppendProperty("COMPILE_FEATURES", feature.c_str());
  4525. return true;
  4526. }
  4527. std::string lang;
  4528. if (!this->CompileFeatureKnown(target, feature, lang, error))
  4529. {
  4530. return false;
  4531. }
  4532. const char* features = this->CompileFeaturesAvailable(lang, error);
  4533. if (!features)
  4534. {
  4535. return false;
  4536. }
  4537. std::vector<std::string> availableFeatures;
  4538. cmSystemTools::ExpandListArgument(features, availableFeatures);
  4539. if (std::find(availableFeatures.begin(),
  4540. availableFeatures.end(),
  4541. feature) == availableFeatures.end())
  4542. {
  4543. std::ostringstream e;
  4544. e << "The compiler feature \"" << feature
  4545. << "\" is not known to " << lang << " compiler\n\""
  4546. << this->GetDefinition("CMAKE_" + lang + "_COMPILER_ID")
  4547. << "\"\nversion "
  4548. << this->GetDefinition("CMAKE_" + lang + "_COMPILER_VERSION") << ".";
  4549. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  4550. return false;
  4551. }
  4552. target->AppendProperty("COMPILE_FEATURES", feature.c_str());
  4553. return lang == "C"
  4554. ? this->AddRequiredTargetCFeature(target, feature)
  4555. : this->AddRequiredTargetCxxFeature(target, feature);
  4556. }
  4557. //----------------------------------------------------------------------------
  4558. bool cmMakefile::
  4559. CompileFeatureKnown(cmTarget const* target, const std::string& feature,
  4560. std::string& lang, std::string *error) const
  4561. {
  4562. assert(cmGeneratorExpression::Find(feature) == std::string::npos);
  4563. bool isCFeature = std::find_if(cmArrayBegin(C_FEATURES) + 1,
  4564. cmArrayEnd(C_FEATURES), cmStrCmp(feature))
  4565. != cmArrayEnd(C_FEATURES);
  4566. if (isCFeature)
  4567. {
  4568. lang = "C";
  4569. return true;
  4570. }
  4571. bool isCxxFeature = std::find_if(cmArrayBegin(CXX_FEATURES) + 1,
  4572. cmArrayEnd(CXX_FEATURES), cmStrCmp(feature))
  4573. != cmArrayEnd(CXX_FEATURES);
  4574. if (isCxxFeature)
  4575. {
  4576. lang = "CXX";
  4577. return true;
  4578. }
  4579. std::ostringstream e;
  4580. if (error)
  4581. {
  4582. e << "specified";
  4583. }
  4584. else
  4585. {
  4586. e << "Specified";
  4587. }
  4588. e << " unknown feature \"" << feature << "\" for "
  4589. "target \"" << target->GetName() << "\".";
  4590. if (error)
  4591. {
  4592. *error = e.str();
  4593. }
  4594. else
  4595. {
  4596. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  4597. }
  4598. return false;
  4599. }
  4600. //----------------------------------------------------------------------------
  4601. const char* cmMakefile::
  4602. CompileFeaturesAvailable(const std::string& lang, std::string *error) const
  4603. {
  4604. const char* featuresKnown =
  4605. this->GetDefinition("CMAKE_" + lang + "_COMPILE_FEATURES");
  4606. if (!featuresKnown || !*featuresKnown)
  4607. {
  4608. std::ostringstream e;
  4609. if (error)
  4610. {
  4611. e << "no";
  4612. }
  4613. else
  4614. {
  4615. e << "No";
  4616. }
  4617. e << " known features for " << lang << " compiler\n\""
  4618. << this->GetDefinition("CMAKE_" + lang + "_COMPILER_ID")
  4619. << "\"\nversion "
  4620. << this->GetDefinition("CMAKE_" + lang + "_COMPILER_VERSION") << ".";
  4621. if (error)
  4622. {
  4623. *error = e.str();
  4624. }
  4625. else
  4626. {
  4627. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  4628. }
  4629. return 0;
  4630. }
  4631. return featuresKnown;
  4632. }
  4633. //----------------------------------------------------------------------------
  4634. bool cmMakefile::HaveStandardAvailable(cmTarget const* target,
  4635. std::string const& lang,
  4636. const std::string& feature) const
  4637. {
  4638. return lang == "C"
  4639. ? this->HaveCStandardAvailable(target, feature)
  4640. : this->HaveCxxStandardAvailable(target, feature);
  4641. }
  4642. //----------------------------------------------------------------------------
  4643. bool cmMakefile::
  4644. HaveCStandardAvailable(cmTarget const* target,
  4645. const std::string& feature) const
  4646. {
  4647. const char* defaultCStandard =
  4648. this->GetDefinition("CMAKE_C_STANDARD_DEFAULT");
  4649. if (!defaultCStandard)
  4650. {
  4651. std::ostringstream e;
  4652. e << "CMAKE_C_STANDARD_DEFAULT is not set. COMPILE_FEATURES support "
  4653. "not fully configured for this compiler.";
  4654. this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
  4655. // Return true so the caller does not try to lookup the default standard.
  4656. return true;
  4657. }
  4658. if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
  4659. cmStrCmp(defaultCStandard)) == cmArrayEnd(C_STANDARDS))
  4660. {
  4661. std::ostringstream e;
  4662. e << "The CMAKE_C_STANDARD_DEFAULT variable contains an "
  4663. "invalid value: \"" << defaultCStandard << "\".";
  4664. this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
  4665. return false;
  4666. }
  4667. bool needC90 = false;
  4668. bool needC99 = false;
  4669. bool needC11 = false;
  4670. this->CheckNeededCLanguage(feature, needC90, needC99, needC11);
  4671. const char *existingCStandard = target->GetProperty("C_STANDARD");
  4672. if (!existingCStandard)
  4673. {
  4674. existingCStandard = defaultCStandard;
  4675. }
  4676. if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
  4677. cmStrCmp(existingCStandard)) == cmArrayEnd(C_STANDARDS))
  4678. {
  4679. std::ostringstream e;
  4680. e << "The C_STANDARD property on target \"" << target->GetName()
  4681. << "\" contained an invalid value: \"" << existingCStandard << "\".";
  4682. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  4683. return false;
  4684. }
  4685. const char * const *existingCIt = existingCStandard
  4686. ? std::find_if(cmArrayBegin(C_STANDARDS),
  4687. cmArrayEnd(C_STANDARDS),
  4688. cmStrCmp(existingCStandard))
  4689. : cmArrayEnd(C_STANDARDS);
  4690. if (needC11 && existingCStandard && existingCIt <
  4691. std::find_if(cmArrayBegin(C_STANDARDS),
  4692. cmArrayEnd(C_STANDARDS),
  4693. cmStrCmp("11")))
  4694. {
  4695. return false;
  4696. }
  4697. else if(needC99 && existingCStandard && existingCIt <
  4698. std::find_if(cmArrayBegin(C_STANDARDS),
  4699. cmArrayEnd(C_STANDARDS),
  4700. cmStrCmp("99")))
  4701. {
  4702. return false;
  4703. }
  4704. else if(needC90 && existingCStandard && existingCIt <
  4705. std::find_if(cmArrayBegin(C_STANDARDS),
  4706. cmArrayEnd(C_STANDARDS),
  4707. cmStrCmp("90")))
  4708. {
  4709. return false;
  4710. }
  4711. return true;
  4712. }
  4713. //----------------------------------------------------------------------------
  4714. bool cmMakefile::IsLaterStandard(std::string const& lang,
  4715. std::string const& lhs,
  4716. std::string const& rhs)
  4717. {
  4718. if (lang == "C")
  4719. {
  4720. const char * const *rhsIt = std::find_if(cmArrayBegin(C_STANDARDS),
  4721. cmArrayEnd(C_STANDARDS),
  4722. cmStrCmp(rhs));
  4723. return std::find_if(rhsIt, cmArrayEnd(C_STANDARDS),
  4724. cmStrCmp(lhs)) != cmArrayEnd(C_STANDARDS);
  4725. }
  4726. const char * const *rhsIt = std::find_if(cmArrayBegin(CXX_STANDARDS),
  4727. cmArrayEnd(CXX_STANDARDS),
  4728. cmStrCmp(rhs));
  4729. return std::find_if(rhsIt, cmArrayEnd(CXX_STANDARDS),
  4730. cmStrCmp(lhs)) != cmArrayEnd(CXX_STANDARDS);
  4731. }
  4732. //----------------------------------------------------------------------------
  4733. bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target,
  4734. const std::string& feature) const
  4735. {
  4736. const char* defaultCxxStandard =
  4737. this->GetDefinition("CMAKE_CXX_STANDARD_DEFAULT");
  4738. if (!defaultCxxStandard)
  4739. {
  4740. std::ostringstream e;
  4741. e << "CMAKE_CXX_STANDARD_DEFAULT is not set. COMPILE_FEATURES support "
  4742. "not fully configured for this compiler.";
  4743. this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
  4744. // Return true so the caller does not try to lookup the default standard.
  4745. return true;
  4746. }
  4747. if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
  4748. cmStrCmp(defaultCxxStandard)) == cmArrayEnd(CXX_STANDARDS))
  4749. {
  4750. std::ostringstream e;
  4751. e << "The CMAKE_CXX_STANDARD_DEFAULT variable contains an "
  4752. "invalid value: \"" << defaultCxxStandard << "\".";
  4753. this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
  4754. return false;
  4755. }
  4756. bool needCxx98 = false;
  4757. bool needCxx11 = false;
  4758. bool needCxx14 = false;
  4759. this->CheckNeededCxxLanguage(feature, needCxx98, needCxx11, needCxx14);
  4760. const char *existingCxxStandard = target->GetProperty("CXX_STANDARD");
  4761. if (!existingCxxStandard)
  4762. {
  4763. existingCxxStandard = defaultCxxStandard;
  4764. }
  4765. if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
  4766. cmStrCmp(existingCxxStandard)) == cmArrayEnd(CXX_STANDARDS))
  4767. {
  4768. std::ostringstream e;
  4769. e << "The CXX_STANDARD property on target \"" << target->GetName()
  4770. << "\" contained an invalid value: \"" << existingCxxStandard << "\".";
  4771. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  4772. return false;
  4773. }
  4774. const char * const *existingCxxIt = existingCxxStandard
  4775. ? std::find_if(cmArrayBegin(CXX_STANDARDS),
  4776. cmArrayEnd(CXX_STANDARDS),
  4777. cmStrCmp(existingCxxStandard))
  4778. : cmArrayEnd(CXX_STANDARDS);
  4779. if (needCxx11 && existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS),
  4780. cmArrayEnd(CXX_STANDARDS),
  4781. cmStrCmp("11")))
  4782. {
  4783. return false;
  4784. }
  4785. else if(needCxx98 && existingCxxIt <
  4786. std::find_if(cmArrayBegin(CXX_STANDARDS),
  4787. cmArrayEnd(CXX_STANDARDS),
  4788. cmStrCmp("98")))
  4789. {
  4790. return false;
  4791. }
  4792. return true;
  4793. }
  4794. //----------------------------------------------------------------------------
  4795. void cmMakefile::CheckNeededCxxLanguage(const std::string& feature,
  4796. bool& needCxx98,
  4797. bool& needCxx11,
  4798. bool& needCxx14) const
  4799. {
  4800. if (const char *propCxx98 =
  4801. this->GetDefinition("CMAKE_CXX98_COMPILE_FEATURES"))
  4802. {
  4803. std::vector<std::string> props;
  4804. cmSystemTools::ExpandListArgument(propCxx98, props);
  4805. needCxx98 = std::find(props.begin(), props.end(), feature) != props.end();
  4806. }
  4807. if (const char *propCxx11 =
  4808. this->GetDefinition("CMAKE_CXX11_COMPILE_FEATURES"))
  4809. {
  4810. std::vector<std::string> props;
  4811. cmSystemTools::ExpandListArgument(propCxx11, props);
  4812. needCxx11 = std::find(props.begin(), props.end(), feature) != props.end();
  4813. }
  4814. if (const char *propCxx14 =
  4815. this->GetDefinition("CMAKE_CXX14_COMPILE_FEATURES"))
  4816. {
  4817. std::vector<std::string> props;
  4818. cmSystemTools::ExpandListArgument(propCxx14, props);
  4819. needCxx14 = std::find(props.begin(), props.end(), feature) != props.end();
  4820. }
  4821. }
  4822. //----------------------------------------------------------------------------
  4823. bool cmMakefile::
  4824. AddRequiredTargetCxxFeature(cmTarget *target,
  4825. const std::string& feature) const
  4826. {
  4827. bool needCxx98 = false;
  4828. bool needCxx11 = false;
  4829. bool needCxx14 = false;
  4830. this->CheckNeededCxxLanguage(feature, needCxx98, needCxx11, needCxx14);
  4831. const char *existingCxxStandard = target->GetProperty("CXX_STANDARD");
  4832. if (existingCxxStandard)
  4833. {
  4834. if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
  4835. cmStrCmp(existingCxxStandard)) == cmArrayEnd(CXX_STANDARDS))
  4836. {
  4837. std::ostringstream e;
  4838. e << "The CXX_STANDARD property on target \"" << target->GetName()
  4839. << "\" contained an invalid value: \"" << existingCxxStandard << "\".";
  4840. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  4841. return false;
  4842. }
  4843. }
  4844. const char * const *existingCxxIt = existingCxxStandard
  4845. ? std::find_if(cmArrayBegin(CXX_STANDARDS),
  4846. cmArrayEnd(CXX_STANDARDS),
  4847. cmStrCmp(existingCxxStandard))
  4848. : cmArrayEnd(CXX_STANDARDS);
  4849. bool setCxx98 = needCxx98 && !existingCxxStandard;
  4850. bool setCxx11 = needCxx11 && !existingCxxStandard;
  4851. bool setCxx14 = needCxx14 && !existingCxxStandard;
  4852. if (needCxx14 && existingCxxStandard && existingCxxIt <
  4853. std::find_if(cmArrayBegin(CXX_STANDARDS),
  4854. cmArrayEnd(CXX_STANDARDS),
  4855. cmStrCmp("14")))
  4856. {
  4857. setCxx14 = true;
  4858. }
  4859. else if (needCxx11 && existingCxxStandard && existingCxxIt <
  4860. std::find_if(cmArrayBegin(CXX_STANDARDS),
  4861. cmArrayEnd(CXX_STANDARDS),
  4862. cmStrCmp("11")))
  4863. {
  4864. setCxx11 = true;
  4865. }
  4866. else if(needCxx98 && existingCxxStandard && existingCxxIt <
  4867. std::find_if(cmArrayBegin(CXX_STANDARDS),
  4868. cmArrayEnd(CXX_STANDARDS),
  4869. cmStrCmp("98")))
  4870. {
  4871. setCxx98 = true;
  4872. }
  4873. if (setCxx14)
  4874. {
  4875. target->SetProperty("CXX_STANDARD", "14");
  4876. }
  4877. else if (setCxx11)
  4878. {
  4879. target->SetProperty("CXX_STANDARD", "11");
  4880. }
  4881. else if (setCxx98)
  4882. {
  4883. target->SetProperty("CXX_STANDARD", "98");
  4884. }
  4885. return true;
  4886. }
  4887. //----------------------------------------------------------------------------
  4888. void cmMakefile::CheckNeededCLanguage(const std::string& feature,
  4889. bool& needC90,
  4890. bool& needC99,
  4891. bool& needC11) const
  4892. {
  4893. if (const char *propC90 =
  4894. this->GetDefinition("CMAKE_C90_COMPILE_FEATURES"))
  4895. {
  4896. std::vector<std::string> props;
  4897. cmSystemTools::ExpandListArgument(propC90, props);
  4898. needC90 = std::find(props.begin(), props.end(), feature) != props.end();
  4899. }
  4900. if (const char *propC99 =
  4901. this->GetDefinition("CMAKE_C99_COMPILE_FEATURES"))
  4902. {
  4903. std::vector<std::string> props;
  4904. cmSystemTools::ExpandListArgument(propC99, props);
  4905. needC99 = std::find(props.begin(), props.end(), feature) != props.end();
  4906. }
  4907. if (const char *propC11 =
  4908. this->GetDefinition("CMAKE_C11_COMPILE_FEATURES"))
  4909. {
  4910. std::vector<std::string> props;
  4911. cmSystemTools::ExpandListArgument(propC11, props);
  4912. needC11 = std::find(props.begin(), props.end(), feature) != props.end();
  4913. }
  4914. }
  4915. //----------------------------------------------------------------------------
  4916. bool cmMakefile::
  4917. AddRequiredTargetCFeature(cmTarget *target, const std::string& feature) const
  4918. {
  4919. bool needC90 = false;
  4920. bool needC99 = false;
  4921. bool needC11 = false;
  4922. this->CheckNeededCLanguage(feature, needC90, needC99, needC11);
  4923. const char *existingCStandard = target->GetProperty("C_STANDARD");
  4924. if (existingCStandard)
  4925. {
  4926. if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
  4927. cmStrCmp(existingCStandard)) == cmArrayEnd(C_STANDARDS))
  4928. {
  4929. std::ostringstream e;
  4930. e << "The C_STANDARD property on target \"" << target->GetName()
  4931. << "\" contained an invalid value: \"" << existingCStandard << "\".";
  4932. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  4933. return false;
  4934. }
  4935. }
  4936. const char * const *existingCIt = existingCStandard
  4937. ? std::find_if(cmArrayBegin(C_STANDARDS),
  4938. cmArrayEnd(C_STANDARDS),
  4939. cmStrCmp(existingCStandard))
  4940. : cmArrayEnd(C_STANDARDS);
  4941. bool setC90 = needC90 && !existingCStandard;
  4942. bool setC99 = needC99 && !existingCStandard;
  4943. bool setC11 = needC11 && !existingCStandard;
  4944. if (needC11 && existingCStandard && existingCIt <
  4945. std::find_if(cmArrayBegin(C_STANDARDS),
  4946. cmArrayEnd(C_STANDARDS),
  4947. cmStrCmp("11")))
  4948. {
  4949. setC11 = true;
  4950. }
  4951. else if(needC99 && existingCStandard && existingCIt <
  4952. std::find_if(cmArrayBegin(C_STANDARDS),
  4953. cmArrayEnd(C_STANDARDS),
  4954. cmStrCmp("99")))
  4955. {
  4956. setC99 = true;
  4957. }
  4958. else if(needC90 && existingCStandard && existingCIt <
  4959. std::find_if(cmArrayBegin(C_STANDARDS),
  4960. cmArrayEnd(C_STANDARDS),
  4961. cmStrCmp("90")))
  4962. {
  4963. setC90 = true;
  4964. }
  4965. if (setC11)
  4966. {
  4967. target->SetProperty("C_STANDARD", "11");
  4968. }
  4969. else if (setC99)
  4970. {
  4971. target->SetProperty("C_STANDARD", "99");
  4972. }
  4973. else if (setC90)
  4974. {
  4975. target->SetProperty("C_STANDARD", "90");
  4976. }
  4977. return true;
  4978. }
  4979. cmMakefile::FunctionPushPop::FunctionPushPop(cmMakefile* mf,
  4980. const std::string& fileName,
  4981. cmPolicies::PolicyMap const& pm)
  4982. : Makefile(mf), ReportError(true)
  4983. {
  4984. this->Makefile->PushFunctionScope(fileName, pm);
  4985. }
  4986. cmMakefile::FunctionPushPop::~FunctionPushPop()
  4987. {
  4988. this->Makefile->PopFunctionScope(this->ReportError);
  4989. }
  4990. cmMakefile::MacroPushPop::MacroPushPop(cmMakefile* mf,
  4991. const std::string& fileName,
  4992. const cmPolicies::PolicyMap& pm)
  4993. : Makefile(mf), ReportError(true)
  4994. {
  4995. this->Makefile->PushMacroScope(fileName, pm);
  4996. }
  4997. cmMakefile::MacroPushPop::~MacroPushPop()
  4998. {
  4999. this->Makefile->PopMacroScope(this->ReportError);
  5000. }
  5001. cmMakefileCall::cmMakefileCall(cmMakefile* mf, const cmCommandContext& lfc,
  5002. cmExecutionStatus& status): Makefile(mf)
  5003. {
  5004. this->Makefile->ContextStack.push_back(&lfc);
  5005. this->Makefile->ExecutionStatusStack.push_back(&status);
  5006. }
  5007. cmMakefileCall::~cmMakefileCall()
  5008. {
  5009. this->Makefile->ExecutionStatusStack.pop_back();
  5010. this->Makefile->ContextStack.pop_back();
  5011. }