cmMakefile.cxx 169 KB

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