cmGeneratorTarget.cxx 191 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2012 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 "cmGeneratorTarget.h"
  11. #include "cmTarget.h"
  12. #include "cmMakefile.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmSourceFile.h"
  16. #include "cmGeneratorExpression.h"
  17. #include "cmGeneratorExpressionDAGChecker.h"
  18. #include "cmComputeLinkInformation.h"
  19. #include "cmCustomCommandGenerator.h"
  20. #include "cmAlgorithms.h"
  21. #include <queue>
  22. #include <errno.h>
  23. #include "assert.h"
  24. #if defined(CMAKE_BUILD_WITH_CMAKE)
  25. #include <cmsys/hash_set.hxx>
  26. #define UNORDERED_SET cmsys::hash_set
  27. #else
  28. #define UNORDERED_SET std::set
  29. #endif
  30. class cmGeneratorTarget::TargetPropertyEntry {
  31. static cmLinkImplItem NoLinkImplItem;
  32. public:
  33. TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
  34. cmLinkImplItem const& item = NoLinkImplItem)
  35. : ge(cge), LinkImplItem(item)
  36. {}
  37. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  38. cmLinkImplItem const& LinkImplItem;
  39. };
  40. cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
  41. //----------------------------------------------------------------------------
  42. void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
  43. cmGeneratorTarget const* target, cmake *cm)
  44. {
  45. if(!badObjLib.empty())
  46. {
  47. std::ostringstream e;
  48. e << "OBJECT library \"" << target->GetName() << "\" contains:\n";
  49. for(std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
  50. i != badObjLib.end(); ++i)
  51. {
  52. e << " " << (*i)->GetLocation().GetName() << "\n";
  53. }
  54. e << "but may contain only sources that compile, header files, and "
  55. "other files that would not affect linking of a normal library.";
  56. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  57. target->GetBacktrace());
  58. }
  59. }
  60. struct ObjectSourcesTag {};
  61. struct CustomCommandsTag {};
  62. struct ExtraSourcesTag {};
  63. struct HeaderSourcesTag {};
  64. struct ExternalObjectsTag {};
  65. struct IDLSourcesTag {};
  66. struct ResxTag {};
  67. struct ModuleDefinitionFileTag {};
  68. struct AppManifestTag{};
  69. struct ManifestsTag{};
  70. struct CertificatesTag{};
  71. struct XamlTag{};
  72. template<typename Tag, typename OtherTag>
  73. struct IsSameTag
  74. {
  75. enum {
  76. Result = false
  77. };
  78. };
  79. template<typename Tag>
  80. struct IsSameTag<Tag, Tag>
  81. {
  82. enum {
  83. Result = true
  84. };
  85. };
  86. template<bool>
  87. struct DoAccept
  88. {
  89. template <typename T> static void Do(T&, cmSourceFile*) {}
  90. };
  91. template<>
  92. struct DoAccept<true>
  93. {
  94. static void Do(std::vector<cmSourceFile const*>& files, cmSourceFile* f)
  95. {
  96. files.push_back(f);
  97. }
  98. static void Do(cmGeneratorTarget::ResxData& data, cmSourceFile* f)
  99. {
  100. // Build and save the name of the corresponding .h file
  101. // This relationship will be used later when building the project files.
  102. // Both names would have been auto generated from Visual Studio
  103. // where the user supplied the file name and Visual Studio
  104. // appended the suffix.
  105. std::string resx = f->GetFullPath();
  106. std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
  107. data.ExpectedResxHeaders.insert(hFileName);
  108. data.ResxSources.push_back(f);
  109. }
  110. static void Do(cmGeneratorTarget::XamlData& data, cmSourceFile* f)
  111. {
  112. // Build and save the name of the corresponding .h and .cpp file
  113. // This relationship will be used later when building the project files.
  114. // Both names would have been auto generated from Visual Studio
  115. // where the user supplied the file name and Visual Studio
  116. // appended the suffix.
  117. std::string xaml = f->GetFullPath();
  118. std::string hFileName = xaml + ".h";
  119. std::string cppFileName = xaml + ".cpp";
  120. data.ExpectedXamlHeaders.insert(hFileName);
  121. data.ExpectedXamlSources.insert(cppFileName);
  122. data.XamlSources.push_back(f);
  123. }
  124. static void Do(std::string& data, cmSourceFile* f)
  125. {
  126. data = f->GetFullPath();
  127. }
  128. };
  129. //----------------------------------------------------------------------------
  130. template<typename Tag, typename DataType = std::vector<cmSourceFile const*> >
  131. struct TagVisitor
  132. {
  133. DataType& Data;
  134. std::vector<cmSourceFile*> BadObjLibFiles;
  135. cmGeneratorTarget const* Target;
  136. cmGlobalGenerator *GlobalGenerator;
  137. cmsys::RegularExpression Header;
  138. bool IsObjLib;
  139. TagVisitor(cmGeneratorTarget const* target, DataType& data)
  140. : Data(data), Target(target),
  141. GlobalGenerator(target->GetLocalGenerator()->GetGlobalGenerator()),
  142. Header(CM_HEADER_REGEX),
  143. IsObjLib(target->GetType() == cmState::OBJECT_LIBRARY)
  144. {
  145. }
  146. ~TagVisitor()
  147. {
  148. reportBadObjLib(this->BadObjLibFiles, this->Target,
  149. this->GlobalGenerator->GetCMakeInstance());
  150. }
  151. void Accept(cmSourceFile *sf)
  152. {
  153. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  154. if(sf->GetCustomCommand())
  155. {
  156. DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
  157. }
  158. else if(this->Target->GetType() == cmState::UTILITY)
  159. {
  160. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  161. }
  162. else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
  163. {
  164. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  165. }
  166. else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  167. {
  168. DoAccept<IsSameTag<Tag, ExternalObjectsTag>::Result>::Do(this->Data, sf);
  169. if(this->IsObjLib)
  170. {
  171. this->BadObjLibFiles.push_back(sf);
  172. }
  173. }
  174. else if(!sf->GetLanguage().empty())
  175. {
  176. DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
  177. }
  178. else if(ext == "def")
  179. {
  180. DoAccept<IsSameTag<Tag, ModuleDefinitionFileTag>::Result>::Do(this->Data,
  181. sf);
  182. if(this->IsObjLib)
  183. {
  184. this->BadObjLibFiles.push_back(sf);
  185. }
  186. }
  187. else if(ext == "idl")
  188. {
  189. DoAccept<IsSameTag<Tag, IDLSourcesTag>::Result>::Do(this->Data, sf);
  190. if(this->IsObjLib)
  191. {
  192. this->BadObjLibFiles.push_back(sf);
  193. }
  194. }
  195. else if(ext == "resx")
  196. {
  197. DoAccept<IsSameTag<Tag, ResxTag>::Result>::Do(this->Data, sf);
  198. }
  199. else if (ext == "appxmanifest")
  200. {
  201. DoAccept<IsSameTag<Tag, AppManifestTag>::Result>::Do(this->Data, sf);
  202. }
  203. else if (ext == "manifest")
  204. {
  205. DoAccept<IsSameTag<Tag, ManifestsTag>::Result>::Do(this->Data, sf);
  206. }
  207. else if (ext == "pfx")
  208. {
  209. DoAccept<IsSameTag<Tag, CertificatesTag>::Result>::Do(this->Data, sf);
  210. }
  211. else if (ext == "xaml")
  212. {
  213. DoAccept<IsSameTag<Tag, XamlTag>::Result>::Do(this->Data, sf);
  214. }
  215. else if(this->Header.find(sf->GetFullPath().c_str()))
  216. {
  217. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  218. }
  219. else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
  220. {
  221. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  222. }
  223. else
  224. {
  225. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  226. }
  227. }
  228. };
  229. void CreatePropertyGeneratorExpressions(
  230. cmStringRange const& entries,
  231. cmBacktraceRange const& backtraces,
  232. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items,
  233. bool evaluateForBuildsystem = false)
  234. {
  235. std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
  236. for (std::vector<std::string>::const_iterator it = entries.begin();
  237. it != entries.end(); ++it, ++btIt)
  238. {
  239. cmGeneratorExpression ge(*btIt);
  240. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
  241. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  242. items.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  243. }
  244. }
  245. //----------------------------------------------------------------------------
  246. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  247. : Target(t),
  248. SourceFileFlagsConstructed(false),
  249. PolicyWarnedCMP0022(false),
  250. DebugIncludesDone(false),
  251. DebugCompileOptionsDone(false),
  252. DebugCompileFeaturesDone(false),
  253. DebugCompileDefinitionsDone(false),
  254. DebugSourcesDone(false),
  255. LinkImplementationLanguageIsContextDependent(true),
  256. UtilityItemsDone(false)
  257. {
  258. this->Makefile = this->Target->GetMakefile();
  259. this->LocalGenerator = lg;
  260. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  261. this->GlobalGenerator->ComputeTargetObjectDirectory(this);
  262. CreatePropertyGeneratorExpressions(
  263. t->GetIncludeDirectoriesEntries(),
  264. t->GetIncludeDirectoriesBacktraces(),
  265. this->IncludeDirectoriesEntries);
  266. CreatePropertyGeneratorExpressions(
  267. t->GetCompileOptionsEntries(),
  268. t->GetCompileOptionsBacktraces(),
  269. this->CompileOptionsEntries);
  270. CreatePropertyGeneratorExpressions(
  271. t->GetCompileFeaturesEntries(),
  272. t->GetCompileFeaturesBacktraces(),
  273. this->CompileFeaturesEntries);
  274. CreatePropertyGeneratorExpressions(
  275. t->GetCompileDefinitionsEntries(),
  276. t->GetCompileDefinitionsBacktraces(),
  277. this->CompileDefinitionsEntries);
  278. CreatePropertyGeneratorExpressions(
  279. t->GetSourceEntries(),
  280. t->GetSourceBacktraces(),
  281. this->SourceEntries, true);
  282. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  283. this->Makefile->IsOn("CYGWIN") ||
  284. this->Makefile->IsOn("MINGW"));
  285. this->PolicyMap = t->PolicyMap;
  286. }
  287. cmGeneratorTarget::~cmGeneratorTarget()
  288. {
  289. cmDeleteAll(this->IncludeDirectoriesEntries);
  290. cmDeleteAll(this->CompileOptionsEntries);
  291. cmDeleteAll(this->CompileFeaturesEntries);
  292. cmDeleteAll(this->CompileDefinitionsEntries);
  293. cmDeleteAll(this->SourceEntries);
  294. cmDeleteAll(this->LinkInformation);
  295. this->LinkInformation.clear();
  296. }
  297. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  298. {
  299. return this->LocalGenerator;
  300. }
  301. //----------------------------------------------------------------------------
  302. cmState::TargetType cmGeneratorTarget::GetType() const
  303. {
  304. return this->Target->GetType();
  305. }
  306. //----------------------------------------------------------------------------
  307. std::string cmGeneratorTarget::GetName() const
  308. {
  309. return this->Target->GetName();
  310. }
  311. //----------------------------------------------------------------------------
  312. std::string cmGeneratorTarget::GetExportName() const
  313. {
  314. const char *exportName = this->GetProperty("EXPORT_NAME");
  315. if (exportName && *exportName)
  316. {
  317. if (!cmGeneratorExpression::IsValidTargetName(exportName))
  318. {
  319. std::ostringstream e;
  320. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  321. << this->GetName() << "\": is not valid.";
  322. cmSystemTools::Error(e.str().c_str());
  323. return "";
  324. }
  325. return exportName;
  326. }
  327. return this->GetName();
  328. }
  329. //----------------------------------------------------------------------------
  330. const char *cmGeneratorTarget::GetProperty(const std::string& prop) const
  331. {
  332. return this->Target->GetProperty(prop);
  333. }
  334. //----------------------------------------------------------------------------
  335. const char* cmGeneratorTarget::GetOutputTargetType(bool implib) const
  336. {
  337. switch(this->GetType())
  338. {
  339. case cmState::SHARED_LIBRARY:
  340. if(this->IsDLLPlatform())
  341. {
  342. if(implib)
  343. {
  344. // A DLL import library is treated as an archive target.
  345. return "ARCHIVE";
  346. }
  347. else
  348. {
  349. // A DLL shared library is treated as a runtime target.
  350. return "RUNTIME";
  351. }
  352. }
  353. else
  354. {
  355. // For non-DLL platforms shared libraries are treated as
  356. // library targets.
  357. return "LIBRARY";
  358. }
  359. case cmState::STATIC_LIBRARY:
  360. // Static libraries are always treated as archive targets.
  361. return "ARCHIVE";
  362. case cmState::MODULE_LIBRARY:
  363. if(implib)
  364. {
  365. // Module libraries are always treated as library targets.
  366. return "ARCHIVE";
  367. }
  368. else
  369. {
  370. // Module import libraries are treated as archive targets.
  371. return "LIBRARY";
  372. }
  373. case cmState::EXECUTABLE:
  374. if(implib)
  375. {
  376. // Executable import libraries are treated as archive targets.
  377. return "ARCHIVE";
  378. }
  379. else
  380. {
  381. // Executables are always treated as runtime targets.
  382. return "RUNTIME";
  383. }
  384. default:
  385. break;
  386. }
  387. return "";
  388. }
  389. //----------------------------------------------------------------------------
  390. std::string cmGeneratorTarget::GetOutputName(const std::string& config,
  391. bool implib) const
  392. {
  393. // Lookup/compute/cache the output name for this configuration.
  394. OutputNameKey key(config, implib);
  395. cmGeneratorTarget::OutputNameMapType::iterator i =
  396. this->OutputNameMap.find(key);
  397. if(i == this->OutputNameMap.end())
  398. {
  399. // Add empty name in map to detect potential recursion.
  400. OutputNameMapType::value_type entry(key, "");
  401. i = this->OutputNameMap.insert(entry).first;
  402. // Compute output name.
  403. std::vector<std::string> props;
  404. std::string type = this->GetOutputTargetType(implib);
  405. std::string configUpper = cmSystemTools::UpperCase(config);
  406. if(!type.empty() && !configUpper.empty())
  407. {
  408. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  409. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  410. }
  411. if(!type.empty())
  412. {
  413. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  414. props.push_back(type + "_OUTPUT_NAME");
  415. }
  416. if(!configUpper.empty())
  417. {
  418. // OUTPUT_NAME_<CONFIG>
  419. props.push_back("OUTPUT_NAME_" + configUpper);
  420. // <CONFIG>_OUTPUT_NAME
  421. props.push_back(configUpper + "_OUTPUT_NAME");
  422. }
  423. // OUTPUT_NAME
  424. props.push_back("OUTPUT_NAME");
  425. std::string outName;
  426. for(std::vector<std::string>::const_iterator it = props.begin();
  427. it != props.end(); ++it)
  428. {
  429. if (const char* outNameProp = this->GetProperty(*it))
  430. {
  431. outName = outNameProp;
  432. break;
  433. }
  434. }
  435. if(outName.empty())
  436. {
  437. outName = this->GetName();
  438. }
  439. // Now evaluate genex and update the previously-prepared map entry.
  440. cmGeneratorExpression ge;
  441. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  442. i->second = cge->Evaluate(this->LocalGenerator, config);
  443. }
  444. else if(i->second.empty())
  445. {
  446. // An empty map entry indicates we have been called recursively
  447. // from the above block.
  448. this->LocalGenerator->GetCMakeInstance()
  449. ->IssueMessage(
  450. cmake::FATAL_ERROR,
  451. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  452. this->GetBacktrace());
  453. }
  454. return i->second;
  455. }
  456. void cmGeneratorTarget::AddSource(const std::string& src)
  457. {
  458. this->Target->AddSource(src);
  459. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  460. cmGeneratorExpression ge(lfbt);
  461. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  462. cge->SetEvaluateForBuildsystem(true);
  463. this->SourceEntries.push_back(
  464. new TargetPropertyEntry(cge));
  465. this->SourceFilesMap.clear();
  466. this->LinkImplementationLanguageIsContextDependent = true;
  467. }
  468. void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
  469. {
  470. this->Target->AddTracedSources(srcs);
  471. if (!srcs.empty())
  472. {
  473. std::string srcFiles = cmJoin(srcs, ";");
  474. this->SourceFilesMap.clear();
  475. this->LinkImplementationLanguageIsContextDependent = true;
  476. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  477. cmGeneratorExpression ge(lfbt);
  478. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  479. cge->SetEvaluateForBuildsystem(true);
  480. this->SourceEntries.push_back(
  481. new cmGeneratorTarget::TargetPropertyEntry(cge));
  482. }
  483. }
  484. //----------------------------------------------------------------------------
  485. std::vector<cmSourceFile*> const*
  486. cmGeneratorTarget::GetSourceDepends(cmSourceFile const* sf) const
  487. {
  488. SourceEntriesType::const_iterator i = this->SourceDepends.find(sf);
  489. if(i != this->SourceDepends.end())
  490. {
  491. return &i->second.Depends;
  492. }
  493. return 0;
  494. }
  495. static void handleSystemIncludesDep(cmLocalGenerator *lg,
  496. cmGeneratorTarget const* depTgt,
  497. const std::string& config,
  498. cmGeneratorTarget const* headTarget,
  499. cmGeneratorExpressionDAGChecker *dagChecker,
  500. std::vector<std::string>& result,
  501. bool excludeImported)
  502. {
  503. if (const char* dirs =
  504. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES"))
  505. {
  506. cmGeneratorExpression ge;
  507. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  508. ->Evaluate(lg,
  509. config, false, headTarget,
  510. depTgt, dagChecker), result);
  511. }
  512. if (!depTgt->IsImported() || excludeImported)
  513. {
  514. return;
  515. }
  516. if (const char* dirs =
  517. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES"))
  518. {
  519. cmGeneratorExpression ge;
  520. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  521. ->Evaluate(lg,
  522. config, false, headTarget,
  523. depTgt, dagChecker), result);
  524. }
  525. }
  526. #define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
  527. { \
  528. std::vector<cmSourceFile*> sourceFiles; \
  529. this->GetSourceFiles(sourceFiles, config); \
  530. TagVisitor<DATA ## Tag DATATYPE> visitor(this, data); \
  531. for(std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
  532. si != sourceFiles.end(); ++si) \
  533. { \
  534. visitor.Accept(*si); \
  535. } \
  536. } \
  537. #define IMPLEMENT_VISIT(DATA) \
  538. IMPLEMENT_VISIT_IMPL(DATA, EMPTY) \
  539. #define EMPTY
  540. #define COMMA ,
  541. //----------------------------------------------------------------------------
  542. void
  543. cmGeneratorTarget
  544. ::GetObjectSources(std::vector<cmSourceFile const*> &data,
  545. const std::string& config) const
  546. {
  547. IMPLEMENT_VISIT(ObjectSources);
  548. if (!this->Objects.empty())
  549. {
  550. return;
  551. }
  552. for(std::vector<cmSourceFile const*>::const_iterator it = data.begin();
  553. it != data.end(); ++it)
  554. {
  555. this->Objects[*it];
  556. }
  557. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  558. }
  559. void cmGeneratorTarget::ComputeObjectMapping()
  560. {
  561. if(!this->Objects.empty())
  562. {
  563. return;
  564. }
  565. std::vector<std::string> configs;
  566. this->Makefile->GetConfigurations(configs);
  567. if (configs.empty())
  568. {
  569. configs.push_back("");
  570. }
  571. for(std::vector<std::string>::const_iterator ci = configs.begin();
  572. ci != configs.end(); ++ci)
  573. {
  574. std::vector<cmSourceFile const*> sourceFiles;
  575. this->GetObjectSources(sourceFiles, *ci);
  576. }
  577. }
  578. //----------------------------------------------------------------------------
  579. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  580. const std::string& config) const
  581. {
  582. if(!config.empty())
  583. {
  584. std::string featureConfig = feature;
  585. featureConfig += "_";
  586. featureConfig += cmSystemTools::UpperCase(config);
  587. if(const char* value = this->GetProperty(featureConfig))
  588. {
  589. return value;
  590. }
  591. }
  592. if(const char* value = this->GetProperty(feature))
  593. {
  594. return value;
  595. }
  596. return this->LocalGenerator->GetFeature(feature, config);
  597. }
  598. //----------------------------------------------------------------------------
  599. bool cmGeneratorTarget::GetFeatureAsBool(const std::string& feature,
  600. const std::string& config) const
  601. {
  602. return cmSystemTools::IsOn(this->GetFeature(feature, config));
  603. }
  604. //----------------------------------------------------------------------------
  605. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  606. {
  607. this->ComputeObjectMapping();
  608. return this->Objects[file];
  609. }
  610. //----------------------------------------------------------------------------
  611. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  612. {
  613. this->ExplicitObjectName.insert(sf);
  614. }
  615. //----------------------------------------------------------------------------
  616. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  617. {
  618. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  619. std::set<cmSourceFile const*>::const_iterator it
  620. = this->ExplicitObjectName.find(file);
  621. return it != this->ExplicitObjectName.end();
  622. }
  623. //----------------------------------------------------------------------------
  624. void cmGeneratorTarget
  625. ::GetIDLSources(std::vector<cmSourceFile const*>& data,
  626. const std::string& config) const
  627. {
  628. IMPLEMENT_VISIT(IDLSources);
  629. }
  630. //----------------------------------------------------------------------------
  631. void
  632. cmGeneratorTarget
  633. ::GetHeaderSources(std::vector<cmSourceFile const*>& data,
  634. const std::string& config) const
  635. {
  636. IMPLEMENT_VISIT(HeaderSources);
  637. }
  638. //----------------------------------------------------------------------------
  639. void cmGeneratorTarget
  640. ::GetExtraSources(std::vector<cmSourceFile const*>& data,
  641. const std::string& config) const
  642. {
  643. IMPLEMENT_VISIT(ExtraSources);
  644. }
  645. //----------------------------------------------------------------------------
  646. void
  647. cmGeneratorTarget
  648. ::GetCustomCommands(std::vector<cmSourceFile const*>& data,
  649. const std::string& config) const
  650. {
  651. IMPLEMENT_VISIT(CustomCommands);
  652. }
  653. //----------------------------------------------------------------------------
  654. void
  655. cmGeneratorTarget
  656. ::GetExternalObjects(std::vector<cmSourceFile const*>& data,
  657. const std::string& config) const
  658. {
  659. IMPLEMENT_VISIT(ExternalObjects);
  660. }
  661. //----------------------------------------------------------------------------
  662. void
  663. cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& srcs,
  664. const std::string& config) const
  665. {
  666. ResxData data;
  667. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  668. srcs = data.ExpectedResxHeaders;
  669. }
  670. //----------------------------------------------------------------------------
  671. void cmGeneratorTarget
  672. ::GetResxSources(std::vector<cmSourceFile const*>& srcs,
  673. const std::string& config) const
  674. {
  675. ResxData data;
  676. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  677. srcs = data.ResxSources;
  678. }
  679. //----------------------------------------------------------------------------
  680. void
  681. cmGeneratorTarget
  682. ::GetAppManifest(std::vector<cmSourceFile const*>& data,
  683. const std::string& config) const
  684. {
  685. IMPLEMENT_VISIT(AppManifest);
  686. }
  687. //----------------------------------------------------------------------------
  688. void
  689. cmGeneratorTarget
  690. ::GetManifests(std::vector<cmSourceFile const*>& data,
  691. const std::string& config) const
  692. {
  693. IMPLEMENT_VISIT(Manifests);
  694. }
  695. //----------------------------------------------------------------------------
  696. void
  697. cmGeneratorTarget
  698. ::GetCertificates(std::vector<cmSourceFile const*>& data,
  699. const std::string& config) const
  700. {
  701. IMPLEMENT_VISIT(Certificates);
  702. }
  703. //----------------------------------------------------------------------------
  704. void
  705. cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  706. const std::string& config) const
  707. {
  708. XamlData data;
  709. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  710. headers = data.ExpectedXamlHeaders;
  711. }
  712. //----------------------------------------------------------------------------
  713. void
  714. cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  715. const std::string& config) const
  716. {
  717. XamlData data;
  718. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  719. srcs = data.ExpectedXamlSources;
  720. }
  721. std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
  722. {
  723. if(!this->UtilityItemsDone)
  724. {
  725. this->UtilityItemsDone = true;
  726. std::set<std::string> const& utilities = this->Target->GetUtilities();
  727. for(std::set<std::string>::const_iterator i = utilities.begin();
  728. i != utilities.end(); ++i)
  729. {
  730. cmGeneratorTarget* gt =
  731. this->LocalGenerator->FindGeneratorTargetToUse(*i);
  732. this->UtilityItems.insert(cmLinkItem(*i, gt));
  733. }
  734. }
  735. return this->UtilityItems;
  736. }
  737. //----------------------------------------------------------------------------
  738. void cmGeneratorTarget
  739. ::GetXamlSources(std::vector<cmSourceFile const*>& srcs,
  740. const std::string& config) const
  741. {
  742. XamlData data;
  743. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  744. srcs = data.XamlSources;
  745. }
  746. //----------------------------------------------------------------------------
  747. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  748. {
  749. static std::string location;
  750. if (this->IsImported())
  751. {
  752. location = this->Target->ImportedGetFullPath(config, false);
  753. }
  754. else
  755. {
  756. location = this->GetFullPath(config, false);
  757. }
  758. return location.c_str();
  759. }
  760. std::vector<cmCustomCommand> const&
  761. cmGeneratorTarget::GetPreBuildCommands() const
  762. {
  763. return this->Target->GetPreBuildCommands();
  764. }
  765. std::vector<cmCustomCommand> const&
  766. cmGeneratorTarget::GetPreLinkCommands() const
  767. {
  768. return this->Target->GetPreLinkCommands();
  769. }
  770. std::vector<cmCustomCommand> const&
  771. cmGeneratorTarget::GetPostBuildCommands() const
  772. {
  773. return this->Target->GetPostBuildCommands();
  774. }
  775. bool cmGeneratorTarget::IsImported() const
  776. {
  777. return this->Target->IsImported();
  778. }
  779. //----------------------------------------------------------------------------
  780. const char* cmGeneratorTarget::GetLocationForBuild() const
  781. {
  782. static std::string location;
  783. if(this->IsImported())
  784. {
  785. location = this->Target->ImportedGetFullPath("", false);
  786. return location.c_str();
  787. }
  788. // Now handle the deprecated build-time configuration location.
  789. location = this->GetDirectory();
  790. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  791. if(cfgid && strcmp(cfgid, ".") != 0)
  792. {
  793. location += "/";
  794. location += cfgid;
  795. }
  796. if(this->IsAppBundleOnApple())
  797. {
  798. std::string macdir = this->BuildMacContentDirectory("", "",
  799. false);
  800. if(!macdir.empty())
  801. {
  802. location += "/";
  803. location += macdir;
  804. }
  805. }
  806. location += "/";
  807. location += this->GetFullName("", false);
  808. return location.c_str();
  809. }
  810. //----------------------------------------------------------------------------
  811. bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
  812. const std::string& config) const
  813. {
  814. assert(this->GetType() != cmState::INTERFACE_LIBRARY);
  815. std::string config_upper;
  816. if(!config.empty())
  817. {
  818. config_upper = cmSystemTools::UpperCase(config);
  819. }
  820. typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
  821. IncludeCacheType::const_iterator iter =
  822. this->SystemIncludesCache.find(config_upper);
  823. if (iter == this->SystemIncludesCache.end())
  824. {
  825. cmGeneratorExpressionDAGChecker dagChecker(
  826. this->GetName(),
  827. "SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
  828. bool excludeImported
  829. = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  830. std::vector<std::string> result;
  831. for (std::set<std::string>::const_iterator
  832. it = this->Target->GetSystemIncludeDirectories().begin();
  833. it != this->Target->GetSystemIncludeDirectories().end(); ++it)
  834. {
  835. cmGeneratorExpression ge;
  836. cmSystemTools::ExpandListArgument(ge.Parse(*it)
  837. ->Evaluate(this->LocalGenerator,
  838. config, false, this,
  839. &dagChecker), result);
  840. }
  841. std::vector<cmGeneratorTarget const*> const& deps =
  842. this->GetLinkImplementationClosure(config);
  843. for(std::vector<cmGeneratorTarget const*>::const_iterator
  844. li = deps.begin(), le = deps.end(); li != le; ++li)
  845. {
  846. handleSystemIncludesDep(this->LocalGenerator, *li, config, this,
  847. &dagChecker, result, excludeImported);
  848. }
  849. std::set<std::string> unique;
  850. for(std::vector<std::string>::iterator li = result.begin();
  851. li != result.end(); ++li)
  852. {
  853. cmSystemTools::ConvertToUnixSlashes(*li);
  854. unique.insert(*li);
  855. }
  856. result.clear();
  857. result.insert(result.end(), unique.begin(), unique.end());
  858. IncludeCacheType::value_type entry(config_upper, result);
  859. iter = this->SystemIncludesCache.insert(entry).first;
  860. }
  861. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  862. }
  863. //----------------------------------------------------------------------------
  864. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  865. {
  866. return this->Target->GetPropertyAsBool(prop);
  867. }
  868. //----------------------------------------------------------------------------
  869. static void AddInterfaceEntries(
  870. cmGeneratorTarget const* thisTarget, std::string const& config,
  871. std::string const& prop,
  872. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
  873. {
  874. if(cmLinkImplementationLibraries const* impl =
  875. thisTarget->GetLinkImplementationLibraries(config))
  876. {
  877. for (std::vector<cmLinkImplItem>::const_iterator
  878. it = impl->Libraries.begin(), end = impl->Libraries.end();
  879. it != end; ++it)
  880. {
  881. if(it->Target)
  882. {
  883. std::string genex =
  884. "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
  885. cmGeneratorExpression ge(it->Backtrace);
  886. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  887. cge->SetEvaluateForBuildsystem(true);
  888. entries.push_back(
  889. new cmGeneratorTarget::TargetPropertyEntry(cge, *it));
  890. }
  891. }
  892. }
  893. }
  894. //----------------------------------------------------------------------------
  895. static bool processSources(cmGeneratorTarget const* tgt,
  896. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  897. std::vector<std::string> &srcs,
  898. UNORDERED_SET<std::string> &uniqueSrcs,
  899. cmGeneratorExpressionDAGChecker *dagChecker,
  900. std::string const& config, bool debugSources)
  901. {
  902. cmMakefile *mf = tgt->Target->GetMakefile();
  903. bool contextDependent = false;
  904. for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
  905. it = entries.begin(), end = entries.end(); it != end; ++it)
  906. {
  907. cmLinkImplItem const& item = (*it)->LinkImplItem;
  908. std::string const& targetName = item;
  909. std::vector<std::string> entrySources;
  910. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(
  911. tgt->GetLocalGenerator(),
  912. config,
  913. false,
  914. tgt,
  915. tgt,
  916. dagChecker),
  917. entrySources);
  918. if ((*it)->ge->GetHadContextSensitiveCondition())
  919. {
  920. contextDependent = true;
  921. }
  922. for(std::vector<std::string>::iterator i = entrySources.begin();
  923. i != entrySources.end(); ++i)
  924. {
  925. std::string& src = *i;
  926. cmSourceFile* sf = mf->GetOrCreateSource(src);
  927. std::string e;
  928. std::string fullPath = sf->GetFullPath(&e);
  929. if(fullPath.empty())
  930. {
  931. if(!e.empty())
  932. {
  933. cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance();
  934. cm->IssueMessage(cmake::FATAL_ERROR, e,
  935. tgt->GetBacktrace());
  936. }
  937. return contextDependent;
  938. }
  939. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str()))
  940. {
  941. std::ostringstream err;
  942. if (!targetName.empty())
  943. {
  944. err << "Target \"" << targetName << "\" contains relative "
  945. "path in its INTERFACE_SOURCES:\n"
  946. " \"" << src << "\"";
  947. }
  948. else
  949. {
  950. err << "Found relative path while evaluating sources of "
  951. "\"" << tgt->GetName() << "\":\n \"" << src << "\"\n";
  952. }
  953. tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, err.str());
  954. return contextDependent;
  955. }
  956. src = fullPath;
  957. }
  958. std::string usedSources;
  959. for(std::vector<std::string>::iterator
  960. li = entrySources.begin(); li != entrySources.end(); ++li)
  961. {
  962. std::string src = *li;
  963. if(uniqueSrcs.insert(src).second)
  964. {
  965. srcs.push_back(src);
  966. if (debugSources)
  967. {
  968. usedSources += " * " + src + "\n";
  969. }
  970. }
  971. }
  972. if (!usedSources.empty())
  973. {
  974. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(cmake::LOG,
  975. std::string("Used sources for target ")
  976. + tgt->GetName() + ":\n"
  977. + usedSources, (*it)->ge->GetBacktrace());
  978. }
  979. }
  980. return contextDependent;
  981. }
  982. //----------------------------------------------------------------------------
  983. void cmGeneratorTarget::GetSourceFiles(std::vector<std::string> &files,
  984. const std::string& config) const
  985. {
  986. assert(this->GetType() != cmState::INTERFACE_LIBRARY);
  987. if (!this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026())
  988. {
  989. // At configure-time, this method can be called as part of getting the
  990. // LOCATION property or to export() a file to be include()d. However
  991. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  992. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  993. // behavior of CMP0024 and CMP0026 only.
  994. cmStringRange sourceEntries = this->Target->GetSourceEntries();
  995. for(cmStringRange::const_iterator
  996. i = sourceEntries.begin();
  997. i != sourceEntries.end(); ++i)
  998. {
  999. std::string const& entry = *i;
  1000. std::vector<std::string> items;
  1001. cmSystemTools::ExpandListArgument(entry, items);
  1002. for (std::vector<std::string>::const_iterator
  1003. li = items.begin(); li != items.end(); ++li)
  1004. {
  1005. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  1006. (*li)[li->size() - 1] == '>')
  1007. {
  1008. continue;
  1009. }
  1010. files.push_back(*li);
  1011. }
  1012. }
  1013. return;
  1014. }
  1015. std::vector<std::string> debugProperties;
  1016. const char *debugProp =
  1017. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  1018. if (debugProp)
  1019. {
  1020. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  1021. }
  1022. bool debugSources = !this->DebugSourcesDone
  1023. && std::find(debugProperties.begin(),
  1024. debugProperties.end(),
  1025. "SOURCES")
  1026. != debugProperties.end();
  1027. if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026())
  1028. {
  1029. this->DebugSourcesDone = true;
  1030. }
  1031. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  1032. "SOURCES", 0, 0);
  1033. UNORDERED_SET<std::string> uniqueSrcs;
  1034. bool contextDependentDirectSources = processSources(this,
  1035. this->SourceEntries,
  1036. files,
  1037. uniqueSrcs,
  1038. &dagChecker,
  1039. config,
  1040. debugSources);
  1041. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  1042. linkInterfaceSourcesEntries;
  1043. AddInterfaceEntries(
  1044. this, config, "INTERFACE_SOURCES",
  1045. linkInterfaceSourcesEntries);
  1046. std::vector<std::string>::size_type numFilesBefore = files.size();
  1047. bool contextDependentInterfaceSources = processSources(this,
  1048. linkInterfaceSourcesEntries,
  1049. files,
  1050. uniqueSrcs,
  1051. &dagChecker,
  1052. config,
  1053. debugSources);
  1054. if (!contextDependentDirectSources
  1055. && !(contextDependentInterfaceSources && numFilesBefore < files.size()))
  1056. {
  1057. this->LinkImplementationLanguageIsContextDependent = false;
  1058. }
  1059. cmDeleteAll(linkInterfaceSourcesEntries);
  1060. }
  1061. //----------------------------------------------------------------------------
  1062. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  1063. const std::string& config) const
  1064. {
  1065. // Lookup any existing link implementation for this configuration.
  1066. std::string key = cmSystemTools::UpperCase(config);
  1067. if(!this->LinkImplementationLanguageIsContextDependent)
  1068. {
  1069. files = this->SourceFilesMap.begin()->second;
  1070. return;
  1071. }
  1072. SourceFilesMapType::iterator
  1073. it = this->SourceFilesMap.find(key);
  1074. if(it != this->SourceFilesMap.end())
  1075. {
  1076. files = it->second;
  1077. }
  1078. else
  1079. {
  1080. std::vector<std::string> srcs;
  1081. this->GetSourceFiles(srcs, config);
  1082. std::set<cmSourceFile*> emitted;
  1083. for(std::vector<std::string>::const_iterator i = srcs.begin();
  1084. i != srcs.end(); ++i)
  1085. {
  1086. cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
  1087. if (emitted.insert(sf).second)
  1088. {
  1089. files.push_back(sf);
  1090. }
  1091. }
  1092. this->SourceFilesMap[key] = files;
  1093. }
  1094. }
  1095. //----------------------------------------------------------------------------
  1096. std::string
  1097. cmGeneratorTarget::GetCompilePDBName(const std::string& config) const
  1098. {
  1099. std::string prefix;
  1100. std::string base;
  1101. std::string suffix;
  1102. this->GetFullNameInternal(config, false, prefix, base, suffix);
  1103. // Check for a per-configuration output directory target property.
  1104. std::string configUpper = cmSystemTools::UpperCase(config);
  1105. std::string configProp = "COMPILE_PDB_NAME_";
  1106. configProp += configUpper;
  1107. const char* config_name = this->GetProperty(configProp);
  1108. if(config_name && *config_name)
  1109. {
  1110. return prefix + config_name + ".pdb";
  1111. }
  1112. const char* name = this->GetProperty("COMPILE_PDB_NAME");
  1113. if(name && *name)
  1114. {
  1115. return prefix + name + ".pdb";
  1116. }
  1117. return "";
  1118. }
  1119. //----------------------------------------------------------------------------
  1120. std::string
  1121. cmGeneratorTarget::GetCompilePDBPath(const std::string& config) const
  1122. {
  1123. std::string dir = this->GetCompilePDBDirectory(config);
  1124. std::string name = this->GetCompilePDBName(config);
  1125. if(dir.empty() && !name.empty())
  1126. {
  1127. dir = this->GetPDBDirectory(config);
  1128. }
  1129. if(!dir.empty())
  1130. {
  1131. dir += "/";
  1132. }
  1133. return dir + name;
  1134. }
  1135. //----------------------------------------------------------------------------
  1136. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  1137. {
  1138. // soname is supported only for shared libraries and modules,
  1139. // and then only when the platform supports an soname flag.
  1140. return ((this->GetType() == cmState::SHARED_LIBRARY) &&
  1141. !this->GetPropertyAsBool("NO_SONAME") &&
  1142. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  1143. }
  1144. //----------------------------------------------------------------------------
  1145. bool
  1146. cmGeneratorTarget::NeedRelinkBeforeInstall(const std::string& config) const
  1147. {
  1148. // Only executables and shared libraries can have an rpath and may
  1149. // need relinking.
  1150. if(this->GetType() != cmState::EXECUTABLE &&
  1151. this->GetType() != cmState::SHARED_LIBRARY &&
  1152. this->GetType() != cmState::MODULE_LIBRARY)
  1153. {
  1154. return false;
  1155. }
  1156. // If there is no install location this target will not be installed
  1157. // and therefore does not need relinking.
  1158. if(!this->Target->GetHaveInstallRule())
  1159. {
  1160. return false;
  1161. }
  1162. // If skipping all rpaths completely then no relinking is needed.
  1163. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  1164. {
  1165. return false;
  1166. }
  1167. // If building with the install-tree rpath no relinking is needed.
  1168. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  1169. {
  1170. return false;
  1171. }
  1172. // If chrpath is going to be used no relinking is needed.
  1173. if(this->IsChrpathUsed(config))
  1174. {
  1175. return false;
  1176. }
  1177. // Check for rpath support on this platform.
  1178. std::string ll = this->GetLinkerLanguage(config);
  1179. if(!ll.empty())
  1180. {
  1181. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1182. flagVar += ll;
  1183. flagVar += "_FLAG";
  1184. if(!this->Makefile->IsSet(flagVar))
  1185. {
  1186. // There is no rpath support on this platform so nothing needs
  1187. // relinking.
  1188. return false;
  1189. }
  1190. }
  1191. else
  1192. {
  1193. // No linker language is known. This error will be reported by
  1194. // other code.
  1195. return false;
  1196. }
  1197. // If either a build or install tree rpath is set then the rpath
  1198. // will likely change between the build tree and install tree and
  1199. // this target must be relinked.
  1200. return this->HaveBuildTreeRPATH(config)
  1201. || this->HaveInstallTreeRPATH();
  1202. }
  1203. //----------------------------------------------------------------------------
  1204. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  1205. {
  1206. // Only certain target types have an rpath.
  1207. if(!(this->GetType() == cmState::SHARED_LIBRARY ||
  1208. this->GetType() == cmState::MODULE_LIBRARY ||
  1209. this->GetType() == cmState::EXECUTABLE))
  1210. {
  1211. return false;
  1212. }
  1213. // If the target will not be installed we do not need to change its
  1214. // rpath.
  1215. if(!this->Target->GetHaveInstallRule())
  1216. {
  1217. return false;
  1218. }
  1219. // Skip chrpath if skipping rpath altogether.
  1220. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  1221. {
  1222. return false;
  1223. }
  1224. // Skip chrpath if it does not need to be changed at install time.
  1225. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  1226. {
  1227. return false;
  1228. }
  1229. // Allow the user to disable builtin chrpath explicitly.
  1230. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  1231. {
  1232. return false;
  1233. }
  1234. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  1235. {
  1236. return true;
  1237. }
  1238. #if defined(CMAKE_USE_ELF_PARSER)
  1239. // Enable if the rpath flag uses a separator and the target uses ELF
  1240. // binaries.
  1241. std::string ll = this->GetLinkerLanguage(config);
  1242. if(!ll.empty())
  1243. {
  1244. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1245. sepVar += ll;
  1246. sepVar += "_FLAG_SEP";
  1247. const char* sep = this->Makefile->GetDefinition(sepVar);
  1248. if(sep && *sep)
  1249. {
  1250. // TODO: Add ELF check to ABI detection and get rid of
  1251. // CMAKE_EXECUTABLE_FORMAT.
  1252. if(const char* fmt =
  1253. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  1254. {
  1255. return strcmp(fmt, "ELF") == 0;
  1256. }
  1257. }
  1258. }
  1259. #endif
  1260. static_cast<void>(config);
  1261. return false;
  1262. }
  1263. //----------------------------------------------------------------------------
  1264. bool cmGeneratorTarget::IsImportedSharedLibWithoutSOName(
  1265. const std::string& config) const
  1266. {
  1267. if(this->IsImported() && this->GetType() == cmState::SHARED_LIBRARY)
  1268. {
  1269. if(cmGeneratorTarget::ImportInfo const* info =
  1270. this->GetImportInfo(config))
  1271. {
  1272. return info->NoSOName;
  1273. }
  1274. }
  1275. return false;
  1276. }
  1277. //----------------------------------------------------------------------------
  1278. bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir(
  1279. const std::string& config) const
  1280. {
  1281. bool install_name_is_rpath = false;
  1282. bool macosx_rpath = false;
  1283. if(!this->IsImported())
  1284. {
  1285. if(this->GetType() != cmState::SHARED_LIBRARY)
  1286. {
  1287. return false;
  1288. }
  1289. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  1290. bool use_install_name =
  1291. this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  1292. if(install_name && use_install_name &&
  1293. std::string(install_name) == "@rpath")
  1294. {
  1295. install_name_is_rpath = true;
  1296. }
  1297. else if(install_name && use_install_name)
  1298. {
  1299. return false;
  1300. }
  1301. if(!install_name_is_rpath)
  1302. {
  1303. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  1304. }
  1305. }
  1306. else
  1307. {
  1308. // Lookup the imported soname.
  1309. if(cmGeneratorTarget::ImportInfo const* info =
  1310. this->GetImportInfo(config))
  1311. {
  1312. if(!info->NoSOName && !info->SOName.empty())
  1313. {
  1314. if(info->SOName.find("@rpath/") == 0)
  1315. {
  1316. install_name_is_rpath = true;
  1317. }
  1318. }
  1319. else
  1320. {
  1321. std::string install_name;
  1322. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  1323. if(install_name.find("@rpath") != std::string::npos)
  1324. {
  1325. install_name_is_rpath = true;
  1326. }
  1327. }
  1328. }
  1329. }
  1330. if(!install_name_is_rpath && !macosx_rpath)
  1331. {
  1332. return false;
  1333. }
  1334. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  1335. {
  1336. std::ostringstream w;
  1337. w << "Attempting to use";
  1338. if(macosx_rpath)
  1339. {
  1340. w << " MACOSX_RPATH";
  1341. }
  1342. else
  1343. {
  1344. w << " @rpath";
  1345. }
  1346. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  1347. w << " This could be because you are using a Mac OS X version";
  1348. w << " less than 10.5 or because CMake's platform configuration is";
  1349. w << " corrupt.";
  1350. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1351. cm->IssueMessage(cmake::FATAL_ERROR, w.str(),
  1352. this->GetBacktrace());
  1353. }
  1354. return true;
  1355. }
  1356. //----------------------------------------------------------------------------
  1357. bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const
  1358. {
  1359. // we can't do rpaths when unsupported
  1360. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  1361. {
  1362. return false;
  1363. }
  1364. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  1365. if(macosx_rpath_str)
  1366. {
  1367. return this->GetPropertyAsBool("MACOSX_RPATH");
  1368. }
  1369. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  1370. if(cmp0042 == cmPolicies::WARN)
  1371. {
  1372. this->LocalGenerator->GetGlobalGenerator()->
  1373. AddCMP0042WarnTarget(this->GetName());
  1374. }
  1375. if(cmp0042 == cmPolicies::NEW)
  1376. {
  1377. return true;
  1378. }
  1379. return false;
  1380. }
  1381. //----------------------------------------------------------------------------
  1382. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  1383. {
  1384. if(this->IsImported())
  1385. {
  1386. // Lookup the imported soname.
  1387. if(cmGeneratorTarget::ImportInfo const* info =
  1388. this->GetImportInfo(config))
  1389. {
  1390. if(info->NoSOName)
  1391. {
  1392. // The imported library has no builtin soname so the name
  1393. // searched at runtime will be just the filename.
  1394. return cmSystemTools::GetFilenameName(info->Location);
  1395. }
  1396. else
  1397. {
  1398. // Use the soname given if any.
  1399. if(info->SOName.find("@rpath/") == 0)
  1400. {
  1401. return info->SOName.substr(6);
  1402. }
  1403. return info->SOName;
  1404. }
  1405. }
  1406. else
  1407. {
  1408. return "";
  1409. }
  1410. }
  1411. else
  1412. {
  1413. // Compute the soname that will be built.
  1414. std::string name;
  1415. std::string soName;
  1416. std::string realName;
  1417. std::string impName;
  1418. std::string pdbName;
  1419. this->GetLibraryNames(name, soName, realName,
  1420. impName, pdbName, config);
  1421. return soName;
  1422. }
  1423. }
  1424. //----------------------------------------------------------------------------
  1425. std::string
  1426. cmGeneratorTarget::GetAppBundleDirectory(const std::string& config,
  1427. bool contentOnly) const
  1428. {
  1429. std::string fpath = this->GetFullName(config, false);
  1430. fpath += ".app";
  1431. if(!this->Makefile->PlatformIsAppleIos())
  1432. {
  1433. fpath += "/Contents";
  1434. if(!contentOnly)
  1435. fpath += "/MacOS";
  1436. }
  1437. return fpath;
  1438. }
  1439. //----------------------------------------------------------------------------
  1440. bool cmGeneratorTarget::IsBundleOnApple() const
  1441. {
  1442. return this->IsFrameworkOnApple()
  1443. || this->IsAppBundleOnApple()
  1444. || this->IsCFBundleOnApple();
  1445. }
  1446. //----------------------------------------------------------------------------
  1447. std::string cmGeneratorTarget::GetCFBundleDirectory(const std::string& config,
  1448. bool contentOnly) const
  1449. {
  1450. std::string fpath;
  1451. fpath += this->GetOutputName(config, false);
  1452. fpath += ".";
  1453. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  1454. if (!ext)
  1455. {
  1456. if (this->IsXCTestOnApple())
  1457. {
  1458. ext = "xctest";
  1459. }
  1460. else
  1461. {
  1462. ext = "bundle";
  1463. }
  1464. }
  1465. fpath += ext;
  1466. if(!this->Makefile->PlatformIsAppleIos())
  1467. {
  1468. fpath += "/Contents";
  1469. if(!contentOnly)
  1470. fpath += "/MacOS";
  1471. }
  1472. return fpath;
  1473. }
  1474. //----------------------------------------------------------------------------
  1475. std::string
  1476. cmGeneratorTarget::GetFrameworkDirectory(const std::string& config,
  1477. bool rootDir) const
  1478. {
  1479. std::string fpath;
  1480. fpath += this->GetOutputName(config, false);
  1481. fpath += ".framework";
  1482. if(!rootDir && !this->Makefile->PlatformIsAppleIos())
  1483. {
  1484. fpath += "/Versions/";
  1485. fpath += this->GetFrameworkVersion();
  1486. }
  1487. return fpath;
  1488. }
  1489. //----------------------------------------------------------------------------
  1490. std::string
  1491. cmGeneratorTarget::GetFullName(const std::string& config, bool implib) const
  1492. {
  1493. if(this->IsImported())
  1494. {
  1495. return this->GetFullNameImported(config, implib);
  1496. }
  1497. else
  1498. {
  1499. return this->GetFullNameInternal(config, implib);
  1500. }
  1501. }
  1502. //----------------------------------------------------------------------------
  1503. std::string
  1504. cmGeneratorTarget::GetInstallNameDirForBuildTree(
  1505. const std::string& config) const
  1506. {
  1507. // If building directly for installation then the build tree install_name
  1508. // is the same as the install tree.
  1509. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  1510. {
  1511. return this->GetInstallNameDirForInstallTree();
  1512. }
  1513. // Use the build tree directory for the target.
  1514. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  1515. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1516. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  1517. {
  1518. std::string dir;
  1519. if(this->MacOSXRpathInstallNameDirDefault())
  1520. {
  1521. dir = "@rpath";
  1522. }
  1523. else
  1524. {
  1525. dir = this->GetDirectory(config);
  1526. }
  1527. dir += "/";
  1528. return dir;
  1529. }
  1530. else
  1531. {
  1532. return "";
  1533. }
  1534. }
  1535. //----------------------------------------------------------------------------
  1536. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
  1537. {
  1538. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  1539. {
  1540. std::string dir;
  1541. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  1542. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1543. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  1544. {
  1545. if(install_name_dir && *install_name_dir)
  1546. {
  1547. dir = install_name_dir;
  1548. dir += "/";
  1549. }
  1550. }
  1551. if(!install_name_dir)
  1552. {
  1553. if(this->MacOSXRpathInstallNameDirDefault())
  1554. {
  1555. dir = "@rpath/";
  1556. }
  1557. }
  1558. return dir;
  1559. }
  1560. else
  1561. {
  1562. return "";
  1563. }
  1564. }
  1565. cmListFileBacktrace cmGeneratorTarget::GetBacktrace() const
  1566. {
  1567. return this->Target->GetBacktrace();
  1568. }
  1569. const std::vector<std::string>&cmGeneratorTarget::GetLinkDirectories() const
  1570. {
  1571. return this->Target->GetLinkDirectories();
  1572. }
  1573. //----------------------------------------------------------------------------
  1574. bool cmGeneratorTarget::HaveWellDefinedOutputFiles() const
  1575. {
  1576. return
  1577. this->GetType() == cmState::STATIC_LIBRARY ||
  1578. this->GetType() == cmState::SHARED_LIBRARY ||
  1579. this->GetType() == cmState::MODULE_LIBRARY ||
  1580. this->GetType() == cmState::EXECUTABLE;
  1581. }
  1582. //----------------------------------------------------------------------------
  1583. const char* cmGeneratorTarget::GetExportMacro() const
  1584. {
  1585. // Define the symbol for targets that export symbols.
  1586. if(this->GetType() == cmState::SHARED_LIBRARY ||
  1587. this->GetType() == cmState::MODULE_LIBRARY ||
  1588. this->IsExecutableWithExports())
  1589. {
  1590. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  1591. {
  1592. this->ExportMacro = custom_export_name;
  1593. }
  1594. else
  1595. {
  1596. std::string in = this->GetName();
  1597. in += "_EXPORTS";
  1598. this->ExportMacro = cmSystemTools::MakeCidentifier(in);
  1599. }
  1600. return this->ExportMacro.c_str();
  1601. }
  1602. else
  1603. {
  1604. return 0;
  1605. }
  1606. }
  1607. //----------------------------------------------------------------------------
  1608. class cmTargetCollectLinkLanguages
  1609. {
  1610. public:
  1611. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  1612. const std::string& config,
  1613. UNORDERED_SET<std::string>& languages,
  1614. cmGeneratorTarget const* head):
  1615. Config(config), Languages(languages), HeadTarget(head),
  1616. Makefile(target->Target->GetMakefile()), Target(target)
  1617. { this->Visited.insert(target); }
  1618. void Visit(cmLinkItem const& item)
  1619. {
  1620. if(!item.Target)
  1621. {
  1622. if(item.find("::") != std::string::npos)
  1623. {
  1624. bool noMessage = false;
  1625. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1626. std::stringstream e;
  1627. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
  1628. {
  1629. case cmPolicies::WARN:
  1630. {
  1631. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  1632. messageType = cmake::AUTHOR_WARNING;
  1633. }
  1634. break;
  1635. case cmPolicies::OLD:
  1636. noMessage = true;
  1637. case cmPolicies::REQUIRED_IF_USED:
  1638. case cmPolicies::REQUIRED_ALWAYS:
  1639. case cmPolicies::NEW:
  1640. // Issue the fatal message.
  1641. break;
  1642. }
  1643. if(!noMessage)
  1644. {
  1645. e << "Target \"" << this->Target->GetName()
  1646. << "\" links to target \"" << item
  1647. << "\" but the target was not found. Perhaps a find_package() "
  1648. "call is missing for an IMPORTED target, or an ALIAS target is "
  1649. "missing?";
  1650. this->Target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1651. messageType, e.str(), this->Target->GetBacktrace());
  1652. }
  1653. }
  1654. return;
  1655. }
  1656. if(!this->Visited.insert(item.Target).second)
  1657. {
  1658. return;
  1659. }
  1660. cmLinkInterface const* iface =
  1661. item.Target->GetLinkInterface(this->Config, this->HeadTarget);
  1662. if(!iface) { return; }
  1663. for(std::vector<std::string>::const_iterator
  1664. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  1665. {
  1666. this->Languages.insert(*li);
  1667. }
  1668. for(std::vector<cmLinkItem>::const_iterator
  1669. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  1670. {
  1671. this->Visit(*li);
  1672. }
  1673. }
  1674. private:
  1675. std::string Config;
  1676. UNORDERED_SET<std::string>& Languages;
  1677. cmGeneratorTarget const* HeadTarget;
  1678. cmMakefile* Makefile;
  1679. const cmGeneratorTarget* Target;
  1680. std::set<cmGeneratorTarget const*> Visited;
  1681. };
  1682. //----------------------------------------------------------------------------
  1683. cmGeneratorTarget::LinkClosure const*
  1684. cmGeneratorTarget::GetLinkClosure(const std::string& config) const
  1685. {
  1686. std::string key(cmSystemTools::UpperCase(config));
  1687. LinkClosureMapType::iterator
  1688. i = this->LinkClosureMap.find(key);
  1689. if(i == this->LinkClosureMap.end())
  1690. {
  1691. LinkClosure lc;
  1692. this->ComputeLinkClosure(config, lc);
  1693. LinkClosureMapType::value_type entry(key, lc);
  1694. i = this->LinkClosureMap.insert(entry).first;
  1695. }
  1696. return &i->second;
  1697. }
  1698. //----------------------------------------------------------------------------
  1699. class cmTargetSelectLinker
  1700. {
  1701. int Preference;
  1702. cmGeneratorTarget const* Target;
  1703. cmGlobalGenerator* GG;
  1704. std::set<std::string> Preferred;
  1705. public:
  1706. cmTargetSelectLinker(cmGeneratorTarget const* target)
  1707. : Preference(0), Target(target)
  1708. {
  1709. this->GG = this->Target->GetLocalGenerator()->GetGlobalGenerator();
  1710. }
  1711. void Consider(const char* lang)
  1712. {
  1713. int preference = this->GG->GetLinkerPreference(lang);
  1714. if(preference > this->Preference)
  1715. {
  1716. this->Preference = preference;
  1717. this->Preferred.clear();
  1718. }
  1719. if(preference == this->Preference)
  1720. {
  1721. this->Preferred.insert(lang);
  1722. }
  1723. }
  1724. std::string Choose()
  1725. {
  1726. if(this->Preferred.empty())
  1727. {
  1728. return "";
  1729. }
  1730. else if(this->Preferred.size() > 1)
  1731. {
  1732. std::stringstream e;
  1733. e << "Target " << this->Target->GetName()
  1734. << " contains multiple languages with the highest linker preference"
  1735. << " (" << this->Preference << "):\n";
  1736. for(std::set<std::string>::const_iterator
  1737. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  1738. {
  1739. e << " " << *li << "\n";
  1740. }
  1741. e << "Set the LINKER_LANGUAGE property for this target.";
  1742. cmake* cm = this->Target->GetLocalGenerator()->GetCMakeInstance();
  1743. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  1744. this->Target->GetBacktrace());
  1745. }
  1746. return *this->Preferred.begin();
  1747. }
  1748. };
  1749. //----------------------------------------------------------------------------
  1750. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  1751. LinkClosure& lc) const
  1752. {
  1753. // Get languages built in this target.
  1754. UNORDERED_SET<std::string> languages;
  1755. cmLinkImplementation const* impl =
  1756. this->GetLinkImplementation(config);
  1757. assert(impl);
  1758. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1759. li != impl->Languages.end(); ++li)
  1760. {
  1761. languages.insert(*li);
  1762. }
  1763. // Add interface languages from linked targets.
  1764. cmTargetCollectLinkLanguages cll(this, config, languages, this);
  1765. for(std::vector<cmLinkImplItem>::const_iterator li = impl->Libraries.begin();
  1766. li != impl->Libraries.end(); ++li)
  1767. {
  1768. cll.Visit(*li);
  1769. }
  1770. // Store the transitive closure of languages.
  1771. for(UNORDERED_SET<std::string>::const_iterator li = languages.begin();
  1772. li != languages.end(); ++li)
  1773. {
  1774. lc.Languages.push_back(*li);
  1775. }
  1776. // Choose the language whose linker should be used.
  1777. if(this->GetProperty("HAS_CXX"))
  1778. {
  1779. lc.LinkerLanguage = "CXX";
  1780. }
  1781. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  1782. {
  1783. lc.LinkerLanguage = linkerLang;
  1784. }
  1785. else
  1786. {
  1787. // Find the language with the highest preference value.
  1788. cmTargetSelectLinker tsl(this);
  1789. // First select from the languages compiled directly in this target.
  1790. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1791. li != impl->Languages.end(); ++li)
  1792. {
  1793. tsl.Consider(li->c_str());
  1794. }
  1795. // Now consider languages that propagate from linked targets.
  1796. for(UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
  1797. sit != languages.end(); ++sit)
  1798. {
  1799. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  1800. if(this->Makefile->IsOn(propagates))
  1801. {
  1802. tsl.Consider(sit->c_str());
  1803. }
  1804. }
  1805. lc.LinkerLanguage = tsl.Choose();
  1806. }
  1807. }
  1808. //----------------------------------------------------------------------------
  1809. void cmGeneratorTarget::GetFullNameComponents(std::string& prefix,
  1810. std::string& base,
  1811. std::string& suffix,
  1812. const std::string& config,
  1813. bool implib) const
  1814. {
  1815. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  1816. }
  1817. //----------------------------------------------------------------------------
  1818. std::string
  1819. cmGeneratorTarget::BuildMacContentDirectory(const std::string& base,
  1820. const std::string& config,
  1821. bool contentOnly) const
  1822. {
  1823. std::string fpath = base;
  1824. if(this->IsAppBundleOnApple())
  1825. {
  1826. fpath += this->GetAppBundleDirectory(config, contentOnly);
  1827. }
  1828. if(this->IsFrameworkOnApple())
  1829. {
  1830. fpath += this->GetFrameworkDirectory(config, contentOnly);
  1831. }
  1832. if(this->IsCFBundleOnApple())
  1833. {
  1834. fpath += this->GetCFBundleDirectory(config, contentOnly);
  1835. }
  1836. return fpath;
  1837. }
  1838. //----------------------------------------------------------------------------
  1839. std::string
  1840. cmGeneratorTarget::GetMacContentDirectory(const std::string& config,
  1841. bool implib) const
  1842. {
  1843. // Start with the output directory for the target.
  1844. std::string fpath = this->GetDirectory(config, implib);
  1845. fpath += "/";
  1846. bool contentOnly = true;
  1847. if(this->IsFrameworkOnApple())
  1848. {
  1849. // additional files with a framework go into the version specific
  1850. // directory
  1851. contentOnly = false;
  1852. }
  1853. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  1854. return fpath;
  1855. }
  1856. //----------------------------------------------------------------------------
  1857. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  1858. const std::string& config) const
  1859. {
  1860. // There is no compile information for imported targets.
  1861. if(this->IsImported())
  1862. {
  1863. return 0;
  1864. }
  1865. if(this->GetType() > cmState::OBJECT_LIBRARY)
  1866. {
  1867. std::string msg = "cmTarget::GetCompileInfo called for ";
  1868. msg += this->GetName();
  1869. msg += " which has type ";
  1870. msg += cmState::GetTargetTypeName(this->GetType());
  1871. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1872. return 0;
  1873. }
  1874. // Lookup/compute/cache the compile information for this configuration.
  1875. std::string config_upper;
  1876. if(!config.empty())
  1877. {
  1878. config_upper = cmSystemTools::UpperCase(config);
  1879. }
  1880. CompileInfoMapType::const_iterator i =
  1881. this->CompileInfoMap.find(config_upper);
  1882. if(i == this->CompileInfoMap.end())
  1883. {
  1884. CompileInfo info;
  1885. this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  1886. CompileInfoMapType::value_type entry(config_upper, info);
  1887. i = this->CompileInfoMap.insert(entry).first;
  1888. }
  1889. return &i->second;
  1890. }
  1891. //----------------------------------------------------------------------------
  1892. std::string
  1893. cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
  1894. {
  1895. std::string data;
  1896. IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
  1897. return data;
  1898. }
  1899. bool cmGeneratorTarget::IsDLLPlatform() const
  1900. {
  1901. return this->DLLPlatform;
  1902. }
  1903. //----------------------------------------------------------------------------
  1904. void
  1905. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
  1906. const std::string &config) const
  1907. {
  1908. std::vector<cmSourceFile const*> objectFiles;
  1909. this->GetExternalObjects(objectFiles, config);
  1910. std::vector<cmGeneratorTarget*> objectLibraries;
  1911. for(std::vector<cmSourceFile const*>::const_iterator
  1912. it = objectFiles.begin(); it != objectFiles.end(); ++it)
  1913. {
  1914. std::string objLib = (*it)->GetObjectLibrary();
  1915. if (cmGeneratorTarget* tgt =
  1916. this->LocalGenerator->FindGeneratorTargetToUse(objLib))
  1917. {
  1918. objectLibraries.push_back(tgt);
  1919. }
  1920. }
  1921. std::vector<cmGeneratorTarget*>::const_iterator end
  1922. = cmRemoveDuplicates(objectLibraries);
  1923. for(std::vector<cmGeneratorTarget*>::const_iterator
  1924. ti = objectLibraries.begin();
  1925. ti != end; ++ti)
  1926. {
  1927. cmGeneratorTarget* ogt = *ti;
  1928. std::vector<cmSourceFile const*> objectSources;
  1929. ogt->GetObjectSources(objectSources, config);
  1930. for(std::vector<cmSourceFile const*>::const_iterator
  1931. si = objectSources.begin();
  1932. si != objectSources.end(); ++si)
  1933. {
  1934. std::string obj = ogt->ObjectDirectory;
  1935. obj += ogt->Objects[*si];
  1936. objs.push_back(obj);
  1937. }
  1938. }
  1939. }
  1940. //----------------------------------------------------------------------------
  1941. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string> &result,
  1942. const std::string& config) const
  1943. {
  1944. const char *prop
  1945. = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  1946. config);
  1947. if (!prop)
  1948. {
  1949. return;
  1950. }
  1951. cmGeneratorExpression ge;
  1952. cmGeneratorExpressionDAGChecker dagChecker(
  1953. this->GetName(),
  1954. "AUTOUIC_OPTIONS", 0, 0);
  1955. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  1956. ->Evaluate(this->LocalGenerator,
  1957. config,
  1958. false,
  1959. this,
  1960. &dagChecker),
  1961. result);
  1962. }
  1963. //----------------------------------------------------------------------------
  1964. void processILibs(const std::string& config,
  1965. cmGeneratorTarget const* headTarget,
  1966. cmLinkItem const& item,
  1967. cmGlobalGenerator* gg,
  1968. std::vector<cmGeneratorTarget const*>& tgts,
  1969. std::set<cmGeneratorTarget const*>& emitted)
  1970. {
  1971. if (item.Target && emitted.insert(item.Target).second)
  1972. {
  1973. tgts.push_back(item.Target);
  1974. if(cmLinkInterfaceLibraries const* iface =
  1975. item.Target->GetLinkInterfaceLibraries(config, headTarget, true))
  1976. {
  1977. for(std::vector<cmLinkItem>::const_iterator
  1978. it = iface->Libraries.begin();
  1979. it != iface->Libraries.end(); ++it)
  1980. {
  1981. processILibs(config, headTarget, *it, gg, tgts, emitted);
  1982. }
  1983. }
  1984. }
  1985. }
  1986. //----------------------------------------------------------------------------
  1987. const std::vector<const cmGeneratorTarget*>&
  1988. cmGeneratorTarget::GetLinkImplementationClosure(
  1989. const std::string& config) const
  1990. {
  1991. LinkImplClosure& tgts =
  1992. this->LinkImplClosureMap[config];
  1993. if(!tgts.Done)
  1994. {
  1995. tgts.Done = true;
  1996. std::set<cmGeneratorTarget const*> emitted;
  1997. cmLinkImplementationLibraries const* impl
  1998. = this->GetLinkImplementationLibraries(config);
  1999. for(std::vector<cmLinkImplItem>::const_iterator
  2000. it = impl->Libraries.begin();
  2001. it != impl->Libraries.end(); ++it)
  2002. {
  2003. processILibs(config, this, *it,
  2004. this->LocalGenerator->GetGlobalGenerator(),
  2005. tgts , emitted);
  2006. }
  2007. }
  2008. return tgts;
  2009. }
  2010. //----------------------------------------------------------------------------
  2011. class cmTargetTraceDependencies
  2012. {
  2013. public:
  2014. cmTargetTraceDependencies(cmGeneratorTarget* target);
  2015. void Trace();
  2016. private:
  2017. cmGeneratorTarget* GeneratorTarget;
  2018. cmMakefile* Makefile;
  2019. cmLocalGenerator* LocalGenerator;
  2020. cmGlobalGenerator const* GlobalGenerator;
  2021. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  2022. SourceEntry* CurrentEntry;
  2023. std::queue<cmSourceFile*> SourceQueue;
  2024. std::set<cmSourceFile*> SourcesQueued;
  2025. typedef std::map<std::string, cmSourceFile*> NameMapType;
  2026. NameMapType NameMap;
  2027. std::vector<std::string> NewSources;
  2028. void QueueSource(cmSourceFile* sf);
  2029. void FollowName(std::string const& name);
  2030. void FollowNames(std::vector<std::string> const& names);
  2031. bool IsUtility(std::string const& dep);
  2032. void CheckCustomCommand(cmCustomCommand const& cc);
  2033. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  2034. void FollowCommandDepends(cmCustomCommand const& cc,
  2035. const std::string& config,
  2036. std::set<std::string>& emitted);
  2037. };
  2038. //----------------------------------------------------------------------------
  2039. cmTargetTraceDependencies
  2040. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  2041. GeneratorTarget(target)
  2042. {
  2043. // Convenience.
  2044. this->Makefile = target->Target->GetMakefile();
  2045. this->LocalGenerator = target->GetLocalGenerator();
  2046. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  2047. this->CurrentEntry = 0;
  2048. // Queue all the source files already specified for the target.
  2049. if (target->GetType() != cmState::INTERFACE_LIBRARY)
  2050. {
  2051. std::vector<std::string> configs;
  2052. this->Makefile->GetConfigurations(configs);
  2053. if (configs.empty())
  2054. {
  2055. configs.push_back("");
  2056. }
  2057. std::set<cmSourceFile*> emitted;
  2058. for(std::vector<std::string>::const_iterator ci = configs.begin();
  2059. ci != configs.end(); ++ci)
  2060. {
  2061. std::vector<cmSourceFile*> sources;
  2062. this->GeneratorTarget->GetSourceFiles(sources, *ci);
  2063. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  2064. si != sources.end(); ++si)
  2065. {
  2066. cmSourceFile* sf = *si;
  2067. const std::set<cmGeneratorTarget const*> tgts =
  2068. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  2069. if (tgts.find(this->GeneratorTarget) != tgts.end())
  2070. {
  2071. std::ostringstream e;
  2072. e << "Evaluation output file\n \"" << sf->GetFullPath()
  2073. << "\"\ndepends on the sources of a target it is used in. This "
  2074. "is a dependency loop and is not allowed.";
  2075. this->GeneratorTarget
  2076. ->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  2077. return;
  2078. }
  2079. if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)
  2080. {
  2081. this->SourceQueue.push(sf);
  2082. }
  2083. }
  2084. }
  2085. }
  2086. // Queue pre-build, pre-link, and post-build rule dependencies.
  2087. this->CheckCustomCommands(
  2088. this->GeneratorTarget->GetPreBuildCommands());
  2089. this->CheckCustomCommands(
  2090. this->GeneratorTarget->GetPreLinkCommands());
  2091. this->CheckCustomCommands(
  2092. this->GeneratorTarget->GetPostBuildCommands());
  2093. }
  2094. //----------------------------------------------------------------------------
  2095. void cmTargetTraceDependencies::Trace()
  2096. {
  2097. // Process one dependency at a time until the queue is empty.
  2098. while(!this->SourceQueue.empty())
  2099. {
  2100. // Get the next source from the queue.
  2101. cmSourceFile* sf = this->SourceQueue.front();
  2102. this->SourceQueue.pop();
  2103. this->CurrentEntry = &this->GeneratorTarget->SourceDepends[sf];
  2104. // Queue dependencies added explicitly by the user.
  2105. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  2106. {
  2107. std::vector<std::string> objDeps;
  2108. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  2109. for(std::vector<std::string>::iterator odi = objDeps.begin();
  2110. odi != objDeps.end(); ++odi)
  2111. {
  2112. if (cmSystemTools::FileIsFullPath(*odi))
  2113. {
  2114. *odi = cmSystemTools::CollapseFullPath(*odi);
  2115. }
  2116. }
  2117. this->FollowNames(objDeps);
  2118. }
  2119. // Queue the source needed to generate this file, if any.
  2120. this->FollowName(sf->GetFullPath());
  2121. // Queue dependencies added programatically by commands.
  2122. this->FollowNames(sf->GetDepends());
  2123. // Queue custom command dependencies.
  2124. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  2125. {
  2126. this->CheckCustomCommand(*cc);
  2127. }
  2128. }
  2129. this->CurrentEntry = 0;
  2130. this->GeneratorTarget->AddTracedSources(this->NewSources);
  2131. }
  2132. //----------------------------------------------------------------------------
  2133. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  2134. {
  2135. if(this->SourcesQueued.insert(sf).second)
  2136. {
  2137. this->SourceQueue.push(sf);
  2138. // Make sure this file is in the target at the end.
  2139. this->NewSources.push_back(sf->GetFullPath());
  2140. }
  2141. }
  2142. //----------------------------------------------------------------------------
  2143. void cmTargetTraceDependencies::FollowName(std::string const& name)
  2144. {
  2145. NameMapType::iterator i = this->NameMap.find(name);
  2146. if(i == this->NameMap.end())
  2147. {
  2148. // Check if we know how to generate this file.
  2149. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  2150. NameMapType::value_type entry(name, sf);
  2151. i = this->NameMap.insert(entry).first;
  2152. }
  2153. if(cmSourceFile* sf = i->second)
  2154. {
  2155. // Record the dependency we just followed.
  2156. if(this->CurrentEntry)
  2157. {
  2158. this->CurrentEntry->Depends.push_back(sf);
  2159. }
  2160. this->QueueSource(sf);
  2161. }
  2162. }
  2163. //----------------------------------------------------------------------------
  2164. void
  2165. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  2166. {
  2167. for(std::vector<std::string>::const_iterator i = names.begin();
  2168. i != names.end(); ++i)
  2169. {
  2170. this->FollowName(*i);
  2171. }
  2172. }
  2173. //----------------------------------------------------------------------------
  2174. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  2175. {
  2176. // Dependencies on targets (utilities) are supposed to be named by
  2177. // just the target name. However for compatibility we support
  2178. // naming the output file generated by the target (assuming there is
  2179. // no output-name property which old code would not have set). In
  2180. // that case the target name will be the file basename of the
  2181. // dependency.
  2182. std::string util = cmSystemTools::GetFilenameName(dep);
  2183. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  2184. {
  2185. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  2186. }
  2187. // Check for a target with this name.
  2188. if(cmGeneratorTarget* t
  2189. = this->GeneratorTarget->
  2190. GetLocalGenerator()->FindGeneratorTargetToUse(util))
  2191. {
  2192. // If we find the target and the dep was given as a full path,
  2193. // then make sure it was not a full path to something else, and
  2194. // the fact that the name matched a target was just a coincidence.
  2195. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  2196. {
  2197. if(t->GetType() >= cmState::EXECUTABLE &&
  2198. t->GetType() <= cmState::MODULE_LIBRARY)
  2199. {
  2200. // This is really only for compatibility so we do not need to
  2201. // worry about configuration names and output names.
  2202. std::string tLocation = t->GetLocationForBuild();
  2203. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  2204. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  2205. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  2206. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  2207. if(depLocation == tLocation)
  2208. {
  2209. this->GeneratorTarget->Target->AddUtility(util);
  2210. return true;
  2211. }
  2212. }
  2213. }
  2214. else
  2215. {
  2216. // The original name of the dependency was not a full path. It
  2217. // must name a target, so add the target-level dependency.
  2218. this->GeneratorTarget->Target->AddUtility(util);
  2219. return true;
  2220. }
  2221. }
  2222. // The dependency does not name a target built in this project.
  2223. return false;
  2224. }
  2225. //----------------------------------------------------------------------------
  2226. void
  2227. cmTargetTraceDependencies
  2228. ::CheckCustomCommand(cmCustomCommand const& cc)
  2229. {
  2230. // Transform command names that reference targets built in this
  2231. // project to corresponding target-level dependencies.
  2232. cmGeneratorExpression ge(cc.GetBacktrace());
  2233. // Add target-level dependencies referenced by generator expressions.
  2234. std::set<cmGeneratorTarget*> targets;
  2235. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  2236. cit != cc.GetCommandLines().end(); ++cit)
  2237. {
  2238. std::string const& command = *cit->begin();
  2239. // Check for a target with this name.
  2240. if(cmGeneratorTarget* t =
  2241. this->LocalGenerator->FindGeneratorTargetToUse(command))
  2242. {
  2243. if(t->GetType() == cmState::EXECUTABLE)
  2244. {
  2245. // The command refers to an executable target built in
  2246. // this project. Add the target-level dependency to make
  2247. // sure the executable is up to date before this custom
  2248. // command possibly runs.
  2249. this->GeneratorTarget->Target->AddUtility(command);
  2250. }
  2251. }
  2252. // Check for target references in generator expressions.
  2253. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  2254. cli != cit->end(); ++cli)
  2255. {
  2256. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  2257. = ge.Parse(*cli);
  2258. cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), "", true);
  2259. std::set<cmGeneratorTarget*> geTargets = cge->GetTargets();
  2260. targets.insert(geTargets.begin(), geTargets.end());
  2261. }
  2262. }
  2263. for(std::set<cmGeneratorTarget*>::iterator ti = targets.begin();
  2264. ti != targets.end(); ++ti)
  2265. {
  2266. this->GeneratorTarget->Target->AddUtility((*ti)->GetName());
  2267. }
  2268. // Queue the custom command dependencies.
  2269. std::vector<std::string> configs;
  2270. std::set<std::string> emitted;
  2271. this->Makefile->GetConfigurations(configs);
  2272. if (configs.empty())
  2273. {
  2274. configs.push_back("");
  2275. }
  2276. for(std::vector<std::string>::const_iterator ci = configs.begin();
  2277. ci != configs.end(); ++ci)
  2278. {
  2279. this->FollowCommandDepends(cc, *ci, emitted);
  2280. }
  2281. }
  2282. //----------------------------------------------------------------------------
  2283. void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
  2284. const std::string& config,
  2285. std::set<std::string>& emitted)
  2286. {
  2287. cmCustomCommandGenerator ccg(cc, config,
  2288. this->GeneratorTarget->LocalGenerator);
  2289. const std::vector<std::string>& depends = ccg.GetDepends();
  2290. for(std::vector<std::string>::const_iterator di = depends.begin();
  2291. di != depends.end(); ++di)
  2292. {
  2293. std::string const& dep = *di;
  2294. if(emitted.insert(dep).second)
  2295. {
  2296. if(!this->IsUtility(dep))
  2297. {
  2298. // The dependency does not name a target and may be a file we
  2299. // know how to generate. Queue it.
  2300. this->FollowName(dep);
  2301. }
  2302. }
  2303. }
  2304. }
  2305. //----------------------------------------------------------------------------
  2306. void
  2307. cmTargetTraceDependencies
  2308. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  2309. {
  2310. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  2311. cli != commands.end(); ++cli)
  2312. {
  2313. this->CheckCustomCommand(*cli);
  2314. }
  2315. }
  2316. //----------------------------------------------------------------------------
  2317. void cmGeneratorTarget::TraceDependencies()
  2318. {
  2319. // CMake-generated targets have no dependencies to trace. Normally tracing
  2320. // would find nothing anyway, but when building CMake itself the "install"
  2321. // target command ends up referencing the "cmake" target but we do not
  2322. // really want the dependency because "install" depend on "all" anyway.
  2323. if(this->GetType() == cmState::GLOBAL_TARGET)
  2324. {
  2325. return;
  2326. }
  2327. // Use a helper object to trace the dependencies.
  2328. cmTargetTraceDependencies tracer(this);
  2329. tracer.Trace();
  2330. }
  2331. std::string
  2332. cmGeneratorTarget::GetCompilePDBDirectory(const std::string& config) const
  2333. {
  2334. if(CompileInfo const* info = this->GetCompileInfo(config))
  2335. {
  2336. return info->CompilePdbDir;
  2337. }
  2338. return "";
  2339. }
  2340. //----------------------------------------------------------------------------
  2341. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  2342. std::vector<std::string>& archVec) const
  2343. {
  2344. const char* archs = 0;
  2345. if(!config.empty())
  2346. {
  2347. std::string defVarName = "OSX_ARCHITECTURES_";
  2348. defVarName += cmSystemTools::UpperCase(config);
  2349. archs = this->GetProperty(defVarName);
  2350. }
  2351. if(!archs)
  2352. {
  2353. archs = this->GetProperty("OSX_ARCHITECTURES");
  2354. }
  2355. if(archs)
  2356. {
  2357. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  2358. }
  2359. }
  2360. //----------------------------------------------------------------------------
  2361. std::string
  2362. cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
  2363. std::string const& config) const
  2364. {
  2365. switch(this->GetType())
  2366. {
  2367. case cmState::STATIC_LIBRARY:
  2368. {
  2369. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  2370. if(this->GetFeatureAsBool(
  2371. "INTERPROCEDURAL_OPTIMIZATION", config))
  2372. {
  2373. std::string varIPO = var + "_IPO";
  2374. if(this->Makefile->GetDefinition(varIPO))
  2375. {
  2376. return varIPO;
  2377. }
  2378. }
  2379. return var;
  2380. }
  2381. case cmState::SHARED_LIBRARY:
  2382. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  2383. case cmState::MODULE_LIBRARY:
  2384. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  2385. case cmState::EXECUTABLE:
  2386. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  2387. default:
  2388. break;
  2389. }
  2390. return "";
  2391. }
  2392. //----------------------------------------------------------------------------
  2393. static void processIncludeDirectories(cmGeneratorTarget const* tgt,
  2394. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2395. std::vector<std::string> &includes,
  2396. UNORDERED_SET<std::string> &uniqueIncludes,
  2397. cmGeneratorExpressionDAGChecker *dagChecker,
  2398. const std::string& config, bool debugIncludes,
  2399. const std::string& language)
  2400. {
  2401. for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
  2402. it = entries.begin(), end = entries.end(); it != end; ++it)
  2403. {
  2404. cmLinkImplItem const& item = (*it)->LinkImplItem;
  2405. std::string const& targetName = item;
  2406. bool const fromImported = item.Target && item.Target->IsImported();
  2407. bool const checkCMP0027 = item.FromGenex;
  2408. std::vector<std::string> entryIncludes;
  2409. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(
  2410. tgt->GetLocalGenerator(),
  2411. config,
  2412. false,
  2413. tgt,
  2414. dagChecker, language),
  2415. entryIncludes);
  2416. std::string usedIncludes;
  2417. for(std::vector<std::string>::iterator
  2418. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  2419. {
  2420. if (fromImported
  2421. && !cmSystemTools::FileExists(li->c_str()))
  2422. {
  2423. std::ostringstream e;
  2424. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2425. if (checkCMP0027)
  2426. {
  2427. switch(tgt->GetPolicyStatusCMP0027())
  2428. {
  2429. case cmPolicies::WARN:
  2430. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  2431. case cmPolicies::OLD:
  2432. messageType = cmake::AUTHOR_WARNING;
  2433. break;
  2434. case cmPolicies::REQUIRED_ALWAYS:
  2435. case cmPolicies::REQUIRED_IF_USED:
  2436. case cmPolicies::NEW:
  2437. break;
  2438. }
  2439. }
  2440. e << "Imported target \"" << targetName << "\" includes "
  2441. "non-existent path\n \"" << *li << "\"\nin its "
  2442. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  2443. "* The path was deleted, renamed, or moved to another "
  2444. "location.\n"
  2445. "* An install or uninstall procedure did not complete "
  2446. "successfully.\n"
  2447. "* The installation package was faulty and references files it "
  2448. "does not provide.\n";
  2449. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2450. return;
  2451. }
  2452. if (!cmSystemTools::FileIsFullPath(li->c_str()))
  2453. {
  2454. std::ostringstream e;
  2455. bool noMessage = false;
  2456. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2457. if (!targetName.empty())
  2458. {
  2459. e << "Target \"" << targetName << "\" contains relative "
  2460. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  2461. " \"" << *li << "\"";
  2462. }
  2463. else
  2464. {
  2465. switch(tgt->GetPolicyStatusCMP0021())
  2466. {
  2467. case cmPolicies::WARN:
  2468. {
  2469. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  2470. messageType = cmake::AUTHOR_WARNING;
  2471. }
  2472. break;
  2473. case cmPolicies::OLD:
  2474. noMessage = true;
  2475. case cmPolicies::REQUIRED_IF_USED:
  2476. case cmPolicies::REQUIRED_ALWAYS:
  2477. case cmPolicies::NEW:
  2478. // Issue the fatal message.
  2479. break;
  2480. }
  2481. e << "Found relative path while evaluating include directories of "
  2482. "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n";
  2483. }
  2484. if (!noMessage)
  2485. {
  2486. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2487. if (messageType == cmake::FATAL_ERROR)
  2488. {
  2489. return;
  2490. }
  2491. }
  2492. }
  2493. if (!cmSystemTools::IsOff(li->c_str()))
  2494. {
  2495. cmSystemTools::ConvertToUnixSlashes(*li);
  2496. }
  2497. std::string inc = *li;
  2498. if(uniqueIncludes.insert(inc).second)
  2499. {
  2500. includes.push_back(inc);
  2501. if (debugIncludes)
  2502. {
  2503. usedIncludes += " * " + inc + "\n";
  2504. }
  2505. }
  2506. }
  2507. if (!usedIncludes.empty())
  2508. {
  2509. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2510. std::string("Used includes for target ")
  2511. + tgt->GetName() + ":\n"
  2512. + usedIncludes, (*it)->ge->GetBacktrace());
  2513. }
  2514. }
  2515. }
  2516. //----------------------------------------------------------------------------
  2517. std::vector<std::string>
  2518. cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
  2519. const std::string& lang) const
  2520. {
  2521. std::vector<std::string> includes;
  2522. UNORDERED_SET<std::string> uniqueIncludes;
  2523. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2524. "INCLUDE_DIRECTORIES", 0, 0);
  2525. std::vector<std::string> debugProperties;
  2526. const char *debugProp =
  2527. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2528. if (debugProp)
  2529. {
  2530. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2531. }
  2532. bool debugIncludes = !this->DebugIncludesDone
  2533. && std::find(debugProperties.begin(),
  2534. debugProperties.end(),
  2535. "INCLUDE_DIRECTORIES")
  2536. != debugProperties.end();
  2537. if (this->GlobalGenerator->GetConfigureDoneCMP0026())
  2538. {
  2539. this->DebugIncludesDone = true;
  2540. }
  2541. processIncludeDirectories(this,
  2542. this->IncludeDirectoriesEntries,
  2543. includes,
  2544. uniqueIncludes,
  2545. &dagChecker,
  2546. config,
  2547. debugIncludes,
  2548. lang);
  2549. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2550. linkInterfaceIncludeDirectoriesEntries;
  2551. AddInterfaceEntries(
  2552. this, config, "INTERFACE_INCLUDE_DIRECTORIES",
  2553. linkInterfaceIncludeDirectoriesEntries);
  2554. if(this->Makefile->IsOn("APPLE"))
  2555. {
  2556. cmLinkImplementationLibraries const* impl =
  2557. this->GetLinkImplementationLibraries(config);
  2558. for(std::vector<cmLinkImplItem>::const_iterator
  2559. it = impl->Libraries.begin();
  2560. it != impl->Libraries.end(); ++it)
  2561. {
  2562. std::string libDir = cmSystemTools::CollapseFullPath(*it);
  2563. static cmsys::RegularExpression
  2564. frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  2565. if(!frameworkCheck.find(libDir))
  2566. {
  2567. continue;
  2568. }
  2569. libDir = frameworkCheck.match(1);
  2570. cmGeneratorExpression ge;
  2571. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2572. ge.Parse(libDir.c_str());
  2573. linkInterfaceIncludeDirectoriesEntries
  2574. .push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  2575. }
  2576. }
  2577. processIncludeDirectories(this,
  2578. linkInterfaceIncludeDirectoriesEntries,
  2579. includes,
  2580. uniqueIncludes,
  2581. &dagChecker,
  2582. config,
  2583. debugIncludes,
  2584. lang);
  2585. cmDeleteAll(linkInterfaceIncludeDirectoriesEntries);
  2586. return includes;
  2587. }
  2588. //----------------------------------------------------------------------------
  2589. static void processCompileOptionsInternal(cmGeneratorTarget const* tgt,
  2590. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2591. std::vector<std::string> &options,
  2592. UNORDERED_SET<std::string> &uniqueOptions,
  2593. cmGeneratorExpressionDAGChecker *dagChecker,
  2594. const std::string& config, bool debugOptions, const char *logName,
  2595. std::string const& language)
  2596. {
  2597. for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
  2598. it = entries.begin(), end = entries.end(); it != end; ++it)
  2599. {
  2600. std::vector<std::string> entryOptions;
  2601. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(
  2602. tgt->GetLocalGenerator(),
  2603. config,
  2604. false,
  2605. tgt,
  2606. dagChecker,
  2607. language),
  2608. entryOptions);
  2609. std::string usedOptions;
  2610. for(std::vector<std::string>::iterator
  2611. li = entryOptions.begin(); li != entryOptions.end(); ++li)
  2612. {
  2613. std::string const& opt = *li;
  2614. if(uniqueOptions.insert(opt).second)
  2615. {
  2616. options.push_back(opt);
  2617. if (debugOptions)
  2618. {
  2619. usedOptions += " * " + opt + "\n";
  2620. }
  2621. }
  2622. }
  2623. if (!usedOptions.empty())
  2624. {
  2625. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2626. std::string("Used compile ") + logName
  2627. + std::string(" for target ")
  2628. + tgt->GetName() + ":\n"
  2629. + usedOptions, (*it)->ge->GetBacktrace());
  2630. }
  2631. }
  2632. }
  2633. //----------------------------------------------------------------------------
  2634. static void processCompileOptions(cmGeneratorTarget const* tgt,
  2635. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2636. std::vector<std::string> &options,
  2637. UNORDERED_SET<std::string> &uniqueOptions,
  2638. cmGeneratorExpressionDAGChecker *dagChecker,
  2639. const std::string& config, bool debugOptions,
  2640. std::string const& language)
  2641. {
  2642. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2643. dagChecker, config, debugOptions, "options",
  2644. language);
  2645. }
  2646. //----------------------------------------------------------------------------
  2647. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string> &result,
  2648. const std::string& config,
  2649. const std::string& language) const
  2650. {
  2651. UNORDERED_SET<std::string> uniqueOptions;
  2652. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2653. "COMPILE_OPTIONS", 0, 0);
  2654. std::vector<std::string> debugProperties;
  2655. const char *debugProp =
  2656. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2657. if (debugProp)
  2658. {
  2659. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2660. }
  2661. bool debugOptions = !this->DebugCompileOptionsDone
  2662. && std::find(debugProperties.begin(),
  2663. debugProperties.end(),
  2664. "COMPILE_OPTIONS")
  2665. != debugProperties.end();
  2666. if (this->GlobalGenerator->GetConfigureDoneCMP0026())
  2667. {
  2668. this->DebugCompileOptionsDone = true;
  2669. }
  2670. processCompileOptions(this,
  2671. this->CompileOptionsEntries,
  2672. result,
  2673. uniqueOptions,
  2674. &dagChecker,
  2675. config,
  2676. debugOptions,
  2677. language);
  2678. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2679. linkInterfaceCompileOptionsEntries;
  2680. AddInterfaceEntries(
  2681. this, config, "INTERFACE_COMPILE_OPTIONS",
  2682. linkInterfaceCompileOptionsEntries);
  2683. processCompileOptions(this,
  2684. linkInterfaceCompileOptionsEntries,
  2685. result,
  2686. uniqueOptions,
  2687. &dagChecker,
  2688. config,
  2689. debugOptions,
  2690. language);
  2691. cmDeleteAll(linkInterfaceCompileOptionsEntries);
  2692. }
  2693. //----------------------------------------------------------------------------
  2694. static void processCompileFeatures(cmGeneratorTarget const* tgt,
  2695. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2696. std::vector<std::string> &options,
  2697. UNORDERED_SET<std::string> &uniqueOptions,
  2698. cmGeneratorExpressionDAGChecker *dagChecker,
  2699. const std::string& config, bool debugOptions)
  2700. {
  2701. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2702. dagChecker, config, debugOptions, "features",
  2703. std::string());
  2704. }
  2705. //----------------------------------------------------------------------------
  2706. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string> &result,
  2707. const std::string& config) const
  2708. {
  2709. UNORDERED_SET<std::string> uniqueFeatures;
  2710. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2711. "COMPILE_FEATURES",
  2712. 0, 0);
  2713. std::vector<std::string> debugProperties;
  2714. const char *debugProp =
  2715. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2716. if (debugProp)
  2717. {
  2718. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2719. }
  2720. bool debugFeatures = !this->DebugCompileFeaturesDone
  2721. && std::find(debugProperties.begin(),
  2722. debugProperties.end(),
  2723. "COMPILE_FEATURES")
  2724. != debugProperties.end();
  2725. if (this->GlobalGenerator->GetConfigureDoneCMP0026())
  2726. {
  2727. this->DebugCompileFeaturesDone = true;
  2728. }
  2729. processCompileFeatures(this,
  2730. this->CompileFeaturesEntries,
  2731. result,
  2732. uniqueFeatures,
  2733. &dagChecker,
  2734. config,
  2735. debugFeatures);
  2736. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2737. linkInterfaceCompileFeaturesEntries;
  2738. AddInterfaceEntries(
  2739. this, config, "INTERFACE_COMPILE_FEATURES",
  2740. linkInterfaceCompileFeaturesEntries);
  2741. processCompileFeatures(this,
  2742. linkInterfaceCompileFeaturesEntries,
  2743. result,
  2744. uniqueFeatures,
  2745. &dagChecker,
  2746. config,
  2747. debugFeatures);
  2748. cmDeleteAll(linkInterfaceCompileFeaturesEntries);
  2749. }
  2750. //----------------------------------------------------------------------------
  2751. static void processCompileDefinitions(cmGeneratorTarget const* tgt,
  2752. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2753. std::vector<std::string> &options,
  2754. UNORDERED_SET<std::string> &uniqueOptions,
  2755. cmGeneratorExpressionDAGChecker *dagChecker,
  2756. const std::string& config, bool debugOptions,
  2757. std::string const& language)
  2758. {
  2759. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2760. dagChecker, config, debugOptions,
  2761. "definitions", language);
  2762. }
  2763. //----------------------------------------------------------------------------
  2764. void cmGeneratorTarget::GetCompileDefinitions(std::vector<std::string> &list,
  2765. const std::string& config,
  2766. const std::string& language) const
  2767. {
  2768. UNORDERED_SET<std::string> uniqueOptions;
  2769. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2770. "COMPILE_DEFINITIONS", 0, 0);
  2771. std::vector<std::string> debugProperties;
  2772. const char *debugProp =
  2773. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2774. if (debugProp)
  2775. {
  2776. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2777. }
  2778. bool debugDefines = !this->DebugCompileDefinitionsDone
  2779. && std::find(debugProperties.begin(),
  2780. debugProperties.end(),
  2781. "COMPILE_DEFINITIONS")
  2782. != debugProperties.end();
  2783. if (this->GlobalGenerator->GetConfigureDoneCMP0026())
  2784. {
  2785. this->DebugCompileDefinitionsDone = true;
  2786. }
  2787. processCompileDefinitions(this,
  2788. this->CompileDefinitionsEntries,
  2789. list,
  2790. uniqueOptions,
  2791. &dagChecker,
  2792. config,
  2793. debugDefines,
  2794. language);
  2795. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2796. linkInterfaceCompileDefinitionsEntries;
  2797. AddInterfaceEntries(
  2798. this, config, "INTERFACE_COMPILE_DEFINITIONS",
  2799. linkInterfaceCompileDefinitionsEntries);
  2800. if (!config.empty())
  2801. {
  2802. std::string configPropName = "COMPILE_DEFINITIONS_"
  2803. + cmSystemTools::UpperCase(config);
  2804. const char *configProp = this->GetProperty(configPropName);
  2805. if (configProp)
  2806. {
  2807. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
  2808. {
  2809. case cmPolicies::WARN:
  2810. {
  2811. std::ostringstream e;
  2812. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
  2813. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING,
  2814. e.str());
  2815. }
  2816. case cmPolicies::OLD:
  2817. {
  2818. cmGeneratorExpression ge;
  2819. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2820. ge.Parse(configProp);
  2821. linkInterfaceCompileDefinitionsEntries
  2822. .push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  2823. }
  2824. break;
  2825. case cmPolicies::NEW:
  2826. case cmPolicies::REQUIRED_ALWAYS:
  2827. case cmPolicies::REQUIRED_IF_USED:
  2828. break;
  2829. }
  2830. }
  2831. }
  2832. processCompileDefinitions(this,
  2833. linkInterfaceCompileDefinitionsEntries,
  2834. list,
  2835. uniqueOptions,
  2836. &dagChecker,
  2837. config,
  2838. debugDefines,
  2839. language);
  2840. cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
  2841. }
  2842. //----------------------------------------------------------------------------
  2843. void cmGeneratorTarget::ComputeTargetManifest(
  2844. const std::string& config) const
  2845. {
  2846. if (this->IsImported())
  2847. {
  2848. return;
  2849. }
  2850. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  2851. // Get the names.
  2852. std::string name;
  2853. std::string soName;
  2854. std::string realName;
  2855. std::string impName;
  2856. std::string pdbName;
  2857. if(this->GetType() == cmState::EXECUTABLE)
  2858. {
  2859. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2860. }
  2861. else if(this->GetType() == cmState::STATIC_LIBRARY ||
  2862. this->GetType() == cmState::SHARED_LIBRARY ||
  2863. this->GetType() == cmState::MODULE_LIBRARY)
  2864. {
  2865. this->GetLibraryNames(name, soName, realName, impName, pdbName,
  2866. config);
  2867. }
  2868. else
  2869. {
  2870. return;
  2871. }
  2872. // Get the directory.
  2873. std::string dir = this->GetDirectory(config, false);
  2874. // Add each name.
  2875. std::string f;
  2876. if(!name.empty())
  2877. {
  2878. f = dir;
  2879. f += "/";
  2880. f += name;
  2881. gg->AddToManifest(f);
  2882. }
  2883. if(!soName.empty())
  2884. {
  2885. f = dir;
  2886. f += "/";
  2887. f += soName;
  2888. gg->AddToManifest(f);
  2889. }
  2890. if(!realName.empty())
  2891. {
  2892. f = dir;
  2893. f += "/";
  2894. f += realName;
  2895. gg->AddToManifest(f);
  2896. }
  2897. if(!pdbName.empty())
  2898. {
  2899. f = dir;
  2900. f += "/";
  2901. f += pdbName;
  2902. gg->AddToManifest(f);
  2903. }
  2904. if(!impName.empty())
  2905. {
  2906. f = this->GetDirectory(config, true);
  2907. f += "/";
  2908. f += impName;
  2909. gg->AddToManifest(f);
  2910. }
  2911. }
  2912. //----------------------------------------------------------------------------
  2913. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  2914. bool implib, bool realname) const
  2915. {
  2916. if(this->IsImported())
  2917. {
  2918. return this->Target->ImportedGetFullPath(config, implib);
  2919. }
  2920. else
  2921. {
  2922. return this->NormalGetFullPath(config, implib, realname);
  2923. }
  2924. }
  2925. std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
  2926. bool implib,
  2927. bool realname) const
  2928. {
  2929. std::string fpath = this->GetDirectory(config, implib);
  2930. fpath += "/";
  2931. if(this->IsAppBundleOnApple())
  2932. {
  2933. fpath = this->BuildMacContentDirectory(fpath, config, false);
  2934. fpath += "/";
  2935. }
  2936. // Add the full name of the target.
  2937. if(implib)
  2938. {
  2939. fpath += this->GetFullName(config, true);
  2940. }
  2941. else if(realname)
  2942. {
  2943. fpath += this->NormalGetRealName(config);
  2944. }
  2945. else
  2946. {
  2947. fpath += this->GetFullName(config, false);
  2948. }
  2949. return fpath;
  2950. }
  2951. //----------------------------------------------------------------------------
  2952. std::string
  2953. cmGeneratorTarget::NormalGetRealName(const std::string& config) const
  2954. {
  2955. // This should not be called for imported targets.
  2956. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2957. // enforcement of the limited imported target API.
  2958. if(this->IsImported())
  2959. {
  2960. std::string msg = "NormalGetRealName called on imported target: ";
  2961. msg += this->GetName();
  2962. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2963. }
  2964. if(this->GetType() == cmState::EXECUTABLE)
  2965. {
  2966. // Compute the real name that will be built.
  2967. std::string name;
  2968. std::string realName;
  2969. std::string impName;
  2970. std::string pdbName;
  2971. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2972. return realName;
  2973. }
  2974. else
  2975. {
  2976. // Compute the real name that will be built.
  2977. std::string name;
  2978. std::string soName;
  2979. std::string realName;
  2980. std::string impName;
  2981. std::string pdbName;
  2982. this->GetLibraryNames(name, soName, realName,
  2983. impName, pdbName, config);
  2984. return realName;
  2985. }
  2986. }
  2987. //----------------------------------------------------------------------------
  2988. void cmGeneratorTarget::GetLibraryNames(std::string& name,
  2989. std::string& soName,
  2990. std::string& realName,
  2991. std::string& impName,
  2992. std::string& pdbName,
  2993. const std::string& config) const
  2994. {
  2995. // This should not be called for imported targets.
  2996. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2997. // enforcement of the limited imported target API.
  2998. if(this->IsImported())
  2999. {
  3000. std::string msg = "GetLibraryNames called on imported target: ";
  3001. msg += this->GetName();
  3002. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR,
  3003. msg);
  3004. return;
  3005. }
  3006. // Check for library version properties.
  3007. const char* version = this->GetProperty("VERSION");
  3008. const char* soversion = this->GetProperty("SOVERSION");
  3009. if(!this->HasSOName(config) ||
  3010. this->IsFrameworkOnApple())
  3011. {
  3012. // Versioning is supported only for shared libraries and modules,
  3013. // and then only when the platform supports an soname flag.
  3014. version = 0;
  3015. soversion = 0;
  3016. }
  3017. if(version && !soversion)
  3018. {
  3019. // The soversion must be set if the library version is set. Use
  3020. // the library version as the soversion.
  3021. soversion = version;
  3022. }
  3023. if(!version && soversion)
  3024. {
  3025. // Use the soversion as the library version.
  3026. version = soversion;
  3027. }
  3028. // Get the components of the library name.
  3029. std::string prefix;
  3030. std::string base;
  3031. std::string suffix;
  3032. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3033. // The library name.
  3034. name = prefix+base+suffix;
  3035. if(this->IsFrameworkOnApple())
  3036. {
  3037. realName = prefix;
  3038. if(!this->Makefile->PlatformIsAppleIos())
  3039. {
  3040. realName += "Versions/";
  3041. realName += this->GetFrameworkVersion();
  3042. realName += "/";
  3043. }
  3044. realName += base;
  3045. soName = realName;
  3046. }
  3047. else
  3048. {
  3049. // The library's soname.
  3050. this->ComputeVersionedName(soName, prefix, base, suffix,
  3051. name, soversion);
  3052. // The library's real name on disk.
  3053. this->ComputeVersionedName(realName, prefix, base, suffix,
  3054. name, version);
  3055. }
  3056. // The import library name.
  3057. if(this->GetType() == cmState::SHARED_LIBRARY ||
  3058. this->GetType() == cmState::MODULE_LIBRARY)
  3059. {
  3060. impName = this->GetFullNameInternal(config, true);
  3061. }
  3062. else
  3063. {
  3064. impName = "";
  3065. }
  3066. // The program database file name.
  3067. pdbName = this->GetPDBName(config);
  3068. }
  3069. //----------------------------------------------------------------------------
  3070. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  3071. std::string& realName,
  3072. std::string& impName,
  3073. std::string& pdbName,
  3074. const std::string& config) const
  3075. {
  3076. // This should not be called for imported targets.
  3077. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3078. // enforcement of the limited imported target API.
  3079. if(this->IsImported())
  3080. {
  3081. std::string msg =
  3082. "GetExecutableNames called on imported target: ";
  3083. msg += this->GetName();
  3084. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  3085. }
  3086. // This versioning is supported only for executables and then only
  3087. // when the platform supports symbolic links.
  3088. #if defined(_WIN32) && !defined(__CYGWIN__)
  3089. const char* version = 0;
  3090. #else
  3091. // Check for executable version properties.
  3092. const char* version = this->GetProperty("VERSION");
  3093. if(this->GetType() != cmState::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  3094. {
  3095. version = 0;
  3096. }
  3097. #endif
  3098. // Get the components of the executable name.
  3099. std::string prefix;
  3100. std::string base;
  3101. std::string suffix;
  3102. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3103. // The executable name.
  3104. name = prefix+base+suffix;
  3105. // The executable's real name on disk.
  3106. #if defined(__CYGWIN__)
  3107. realName = prefix+base;
  3108. #else
  3109. realName = name;
  3110. #endif
  3111. if(version)
  3112. {
  3113. realName += "-";
  3114. realName += version;
  3115. }
  3116. #if defined(__CYGWIN__)
  3117. realName += suffix;
  3118. #endif
  3119. // The import library name.
  3120. impName = this->GetFullNameInternal(config, true);
  3121. // The program database file name.
  3122. pdbName = this->GetPDBName(config);
  3123. }
  3124. //----------------------------------------------------------------------------
  3125. std::string cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  3126. bool implib) const
  3127. {
  3128. std::string prefix;
  3129. std::string base;
  3130. std::string suffix;
  3131. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3132. return prefix+base+suffix;
  3133. }
  3134. //----------------------------------------------------------------------------
  3135. const char*
  3136. cmGeneratorTarget::ImportedGetLocation(const std::string& config) const
  3137. {
  3138. static std::string location;
  3139. assert(this->IsImported());
  3140. location = this->Target->ImportedGetFullPath(config, false);
  3141. return location.c_str();
  3142. }
  3143. //----------------------------------------------------------------------------
  3144. std::string cmGeneratorTarget::GetFullNameImported(const std::string& config,
  3145. bool implib) const
  3146. {
  3147. return cmSystemTools::GetFilenameName(
  3148. this->Target->ImportedGetFullPath(config, implib));
  3149. }
  3150. //----------------------------------------------------------------------------
  3151. void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  3152. bool implib,
  3153. std::string& outPrefix,
  3154. std::string& outBase,
  3155. std::string& outSuffix) const
  3156. {
  3157. // Use just the target name for non-main target types.
  3158. if(this->GetType() != cmState::STATIC_LIBRARY &&
  3159. this->GetType() != cmState::SHARED_LIBRARY &&
  3160. this->GetType() != cmState::MODULE_LIBRARY &&
  3161. this->GetType() != cmState::EXECUTABLE)
  3162. {
  3163. outPrefix = "";
  3164. outBase = this->GetName();
  3165. outSuffix = "";
  3166. return;
  3167. }
  3168. // Return an empty name for the import library if this platform
  3169. // does not support import libraries.
  3170. if(implib &&
  3171. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  3172. {
  3173. outPrefix = "";
  3174. outBase = "";
  3175. outSuffix = "";
  3176. return;
  3177. }
  3178. // The implib option is only allowed for shared libraries, module
  3179. // libraries, and executables.
  3180. if(this->GetType() != cmState::SHARED_LIBRARY &&
  3181. this->GetType() != cmState::MODULE_LIBRARY &&
  3182. this->GetType() != cmState::EXECUTABLE)
  3183. {
  3184. implib = false;
  3185. }
  3186. // Compute the full name for main target types.
  3187. const char* targetPrefix = (implib
  3188. ? this->GetProperty("IMPORT_PREFIX")
  3189. : this->GetProperty("PREFIX"));
  3190. const char* targetSuffix = (implib
  3191. ? this->GetProperty("IMPORT_SUFFIX")
  3192. : this->GetProperty("SUFFIX"));
  3193. const char* configPostfix = 0;
  3194. if(!config.empty())
  3195. {
  3196. std::string configProp = cmSystemTools::UpperCase(config);
  3197. configProp += "_POSTFIX";
  3198. configPostfix = this->GetProperty(configProp);
  3199. // Mac application bundles and frameworks have no postfix.
  3200. if(configPostfix &&
  3201. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  3202. {
  3203. configPostfix = 0;
  3204. }
  3205. }
  3206. const char* prefixVar = this->Target->GetPrefixVariableInternal(implib);
  3207. const char* suffixVar = this->Target->GetSuffixVariableInternal(implib);
  3208. // Check for language-specific default prefix and suffix.
  3209. std::string ll = this->GetLinkerLanguage(config);
  3210. if(!ll.empty())
  3211. {
  3212. if(!targetSuffix && suffixVar && *suffixVar)
  3213. {
  3214. std::string langSuff = suffixVar + std::string("_") + ll;
  3215. targetSuffix = this->Makefile->GetDefinition(langSuff);
  3216. }
  3217. if(!targetPrefix && prefixVar && *prefixVar)
  3218. {
  3219. std::string langPrefix = prefixVar + std::string("_") + ll;
  3220. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  3221. }
  3222. }
  3223. // if there is no prefix on the target use the cmake definition
  3224. if(!targetPrefix && prefixVar)
  3225. {
  3226. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  3227. }
  3228. // if there is no suffix on the target use the cmake definition
  3229. if(!targetSuffix && suffixVar)
  3230. {
  3231. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  3232. }
  3233. // frameworks have directory prefix but no suffix
  3234. std::string fw_prefix;
  3235. if(this->IsFrameworkOnApple())
  3236. {
  3237. fw_prefix = this->GetOutputName(config, false);
  3238. fw_prefix += ".framework/";
  3239. targetPrefix = fw_prefix.c_str();
  3240. targetSuffix = 0;
  3241. }
  3242. if(this->IsCFBundleOnApple())
  3243. {
  3244. fw_prefix = this->GetCFBundleDirectory(config, false);
  3245. fw_prefix += "/";
  3246. targetPrefix = fw_prefix.c_str();
  3247. targetSuffix = 0;
  3248. }
  3249. // Begin the final name with the prefix.
  3250. outPrefix = targetPrefix?targetPrefix:"";
  3251. // Append the target name or property-specified name.
  3252. outBase += this->GetOutputName(config, implib);
  3253. // Append the per-configuration postfix.
  3254. outBase += configPostfix?configPostfix:"";
  3255. // Name shared libraries with their version number on some platforms.
  3256. if(const char* soversion = this->GetProperty("SOVERSION"))
  3257. {
  3258. if(this->GetType() == cmState::SHARED_LIBRARY && !implib &&
  3259. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  3260. {
  3261. outBase += "-";
  3262. outBase += soversion;
  3263. }
  3264. }
  3265. // Append the suffix.
  3266. outSuffix = targetSuffix?targetSuffix:"";
  3267. }
  3268. //----------------------------------------------------------------------------
  3269. std::string
  3270. cmGeneratorTarget::GetLinkerLanguage(const std::string& config) const
  3271. {
  3272. return this->GetLinkClosure(config)->LinkerLanguage;
  3273. }
  3274. //----------------------------------------------------------------------------
  3275. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  3276. {
  3277. std::string prefix;
  3278. std::string base;
  3279. std::string suffix;
  3280. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3281. std::vector<std::string> props;
  3282. std::string configUpper =
  3283. cmSystemTools::UpperCase(config);
  3284. if(!configUpper.empty())
  3285. {
  3286. // PDB_NAME_<CONFIG>
  3287. props.push_back("PDB_NAME_" + configUpper);
  3288. }
  3289. // PDB_NAME
  3290. props.push_back("PDB_NAME");
  3291. for(std::vector<std::string>::const_iterator i = props.begin();
  3292. i != props.end(); ++i)
  3293. {
  3294. if(const char* outName = this->GetProperty(*i))
  3295. {
  3296. base = outName;
  3297. break;
  3298. }
  3299. }
  3300. return prefix+base+".pdb";
  3301. }
  3302. bool cmGeneratorTarget::StrictTargetComparison::operator()(
  3303. cmGeneratorTarget const* t1, cmGeneratorTarget const* t2) const
  3304. {
  3305. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  3306. if (nameResult == 0)
  3307. {
  3308. return strcmp(t1->GetLocalGenerator()->GetCurrentBinaryDirectory(),
  3309. t2->GetLocalGenerator()->GetCurrentBinaryDirectory()) < 0;
  3310. }
  3311. return nameResult < 0;
  3312. }
  3313. //----------------------------------------------------------------------------
  3314. struct cmGeneratorTarget::SourceFileFlags
  3315. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  3316. {
  3317. struct SourceFileFlags flags;
  3318. this->ConstructSourceFileFlags();
  3319. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  3320. this->SourceFlagsMap.find(sf);
  3321. if(si != this->SourceFlagsMap.end())
  3322. {
  3323. flags = si->second;
  3324. }
  3325. else
  3326. {
  3327. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  3328. // were not listed in one of the other lists.
  3329. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  3330. {
  3331. flags.MacFolder = location;
  3332. if(strcmp(location, "Resources") == 0)
  3333. {
  3334. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  3335. }
  3336. else
  3337. {
  3338. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  3339. }
  3340. }
  3341. }
  3342. return flags;
  3343. }
  3344. //----------------------------------------------------------------------------
  3345. void cmGeneratorTarget::ConstructSourceFileFlags() const
  3346. {
  3347. if(this->SourceFileFlagsConstructed)
  3348. {
  3349. return;
  3350. }
  3351. this->SourceFileFlagsConstructed = true;
  3352. // Process public headers to mark the source files.
  3353. if(const char* files = this->GetProperty("PUBLIC_HEADER"))
  3354. {
  3355. std::vector<std::string> relFiles;
  3356. cmSystemTools::ExpandListArgument(files, relFiles);
  3357. for(std::vector<std::string>::iterator it = relFiles.begin();
  3358. it != relFiles.end(); ++it)
  3359. {
  3360. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  3361. {
  3362. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3363. flags.MacFolder = "Headers";
  3364. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  3365. }
  3366. }
  3367. }
  3368. // Process private headers after public headers so that they take
  3369. // precedence if a file is listed in both.
  3370. if(const char* files = this->GetProperty("PRIVATE_HEADER"))
  3371. {
  3372. std::vector<std::string> relFiles;
  3373. cmSystemTools::ExpandListArgument(files, relFiles);
  3374. for(std::vector<std::string>::iterator it = relFiles.begin();
  3375. it != relFiles.end(); ++it)
  3376. {
  3377. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  3378. {
  3379. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3380. flags.MacFolder = "PrivateHeaders";
  3381. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  3382. }
  3383. }
  3384. }
  3385. // Mark sources listed as resources.
  3386. if(const char* files = this->GetProperty("RESOURCE"))
  3387. {
  3388. std::vector<std::string> relFiles;
  3389. cmSystemTools::ExpandListArgument(files, relFiles);
  3390. for(std::vector<std::string>::iterator it = relFiles.begin();
  3391. it != relFiles.end(); ++it)
  3392. {
  3393. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  3394. {
  3395. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3396. flags.MacFolder = "Resources";
  3397. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  3398. }
  3399. }
  3400. }
  3401. }
  3402. //----------------------------------------------------------------------------
  3403. const cmGeneratorTarget::CompatibleInterfacesBase&
  3404. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  3405. {
  3406. cmGeneratorTarget::CompatibleInterfaces& compat =
  3407. this->CompatibleInterfacesMap[config];
  3408. if(!compat.Done)
  3409. {
  3410. compat.Done = true;
  3411. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  3412. compat.PropsString.insert("AUTOUIC_OPTIONS");
  3413. std::vector<cmGeneratorTarget const*> const& deps =
  3414. this->GetLinkImplementationClosure(config);
  3415. for(std::vector<cmGeneratorTarget const*>::const_iterator li =
  3416. deps.begin(); li != deps.end(); ++li)
  3417. {
  3418. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  3419. if(const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) \
  3420. { \
  3421. std::vector<std::string> props; \
  3422. cmSystemTools::ExpandListArgument(prop, props); \
  3423. compat.Props##x.insert(props.begin(), props.end()); \
  3424. }
  3425. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  3426. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  3427. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  3428. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  3429. #undef CM_READ_COMPATIBLE_INTERFACE
  3430. }
  3431. }
  3432. return compat;
  3433. }
  3434. //----------------------------------------------------------------------------
  3435. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  3436. const std::string &p, const std::string& config) const
  3437. {
  3438. if (this->GetType() == cmState::OBJECT_LIBRARY
  3439. || this->GetType() == cmState::INTERFACE_LIBRARY)
  3440. {
  3441. return false;
  3442. }
  3443. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  3444. }
  3445. //----------------------------------------------------------------------------
  3446. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  3447. const std::string &p, const std::string& config) const
  3448. {
  3449. if (this->GetType() == cmState::OBJECT_LIBRARY
  3450. || this->GetType() == cmState::INTERFACE_LIBRARY)
  3451. {
  3452. return false;
  3453. }
  3454. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  3455. }
  3456. //----------------------------------------------------------------------------
  3457. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  3458. const std::string &p, const std::string& config) const
  3459. {
  3460. if (this->GetType() == cmState::OBJECT_LIBRARY
  3461. || this->GetType() == cmState::INTERFACE_LIBRARY)
  3462. {
  3463. return false;
  3464. }
  3465. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  3466. }
  3467. //----------------------------------------------------------------------------
  3468. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  3469. const std::string &p, const std::string& config) const
  3470. {
  3471. if (this->GetType() == cmState::OBJECT_LIBRARY
  3472. || this->GetType() == cmState::INTERFACE_LIBRARY)
  3473. {
  3474. return false;
  3475. }
  3476. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  3477. }
  3478. enum CompatibleType
  3479. {
  3480. BoolType,
  3481. StringType,
  3482. NumberMinType,
  3483. NumberMaxType
  3484. };
  3485. template<typename PropertyType>
  3486. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3487. const std::string& prop,
  3488. const std::string& config,
  3489. CompatibleType,
  3490. PropertyType *);
  3491. template<>
  3492. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3493. const std::string& prop,
  3494. const std::string& config,
  3495. CompatibleType, bool *)
  3496. {
  3497. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  3498. }
  3499. template<>
  3500. const char * getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3501. const std::string& prop,
  3502. const std::string& config,
  3503. CompatibleType t,
  3504. const char **)
  3505. {
  3506. switch(t)
  3507. {
  3508. case BoolType:
  3509. assert(0 && "String compatibility check function called for boolean");
  3510. return 0;
  3511. case StringType:
  3512. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  3513. case NumberMinType:
  3514. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  3515. case NumberMaxType:
  3516. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  3517. }
  3518. assert(0 && "Unreachable!");
  3519. return 0;
  3520. }
  3521. //----------------------------------------------------------------------------
  3522. template<typename PropertyType>
  3523. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  3524. cmGeneratorTarget const* dependee,
  3525. const std::string& propName,
  3526. std::set<std::string> &emitted,
  3527. const std::string& config,
  3528. CompatibleType t,
  3529. PropertyType *)
  3530. {
  3531. const char *prop = dependee->GetProperty(propName);
  3532. if (!prop)
  3533. {
  3534. return;
  3535. }
  3536. std::vector<std::string> props;
  3537. cmSystemTools::ExpandListArgument(prop, props);
  3538. std::string pdir =
  3539. dependee->Target->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  3540. pdir += "/Help/prop_tgt/";
  3541. for(std::vector<std::string>::iterator pi = props.begin();
  3542. pi != props.end(); ++pi)
  3543. {
  3544. std::string pname = cmSystemTools::HelpFileName(*pi);
  3545. std::string pfile = pdir + pname + ".rst";
  3546. if(cmSystemTools::FileExists(pfile.c_str(), true))
  3547. {
  3548. std::ostringstream e;
  3549. e << "Target \"" << dependee->GetName() << "\" has property \""
  3550. << *pi << "\" listed in its " << propName << " property. "
  3551. "This is not allowed. Only user-defined properties may appear "
  3552. "listed in the " << propName << " property.";
  3553. depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
  3554. return;
  3555. }
  3556. if(emitted.insert(*pi).second)
  3557. {
  3558. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  3559. t, 0);
  3560. if (cmSystemTools::GetErrorOccuredFlag())
  3561. {
  3562. return;
  3563. }
  3564. }
  3565. }
  3566. }
  3567. static std::string intersect(const std::set<std::string> &s1,
  3568. const std::set<std::string> &s2)
  3569. {
  3570. std::set<std::string> intersect;
  3571. std::set_intersection(s1.begin(),s1.end(),
  3572. s2.begin(),s2.end(),
  3573. std::inserter(intersect,intersect.begin()));
  3574. if (!intersect.empty())
  3575. {
  3576. return *intersect.begin();
  3577. }
  3578. return "";
  3579. }
  3580. static std::string intersect(const std::set<std::string> &s1,
  3581. const std::set<std::string> &s2,
  3582. const std::set<std::string> &s3)
  3583. {
  3584. std::string result;
  3585. result = intersect(s1, s2);
  3586. if (!result.empty())
  3587. return result;
  3588. result = intersect(s1, s3);
  3589. if (!result.empty())
  3590. return result;
  3591. return intersect(s2, s3);
  3592. }
  3593. static std::string intersect(const std::set<std::string> &s1,
  3594. const std::set<std::string> &s2,
  3595. const std::set<std::string> &s3,
  3596. const std::set<std::string> &s4)
  3597. {
  3598. std::string result;
  3599. result = intersect(s1, s2);
  3600. if (!result.empty())
  3601. return result;
  3602. result = intersect(s1, s3);
  3603. if (!result.empty())
  3604. return result;
  3605. result = intersect(s1, s4);
  3606. if (!result.empty())
  3607. return result;
  3608. return intersect(s2, s3, s4);
  3609. }
  3610. //----------------------------------------------------------------------------
  3611. void cmGeneratorTarget::CheckPropertyCompatibility(
  3612. cmComputeLinkInformation *info, const std::string& config) const
  3613. {
  3614. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  3615. std::set<std::string> emittedBools;
  3616. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  3617. std::set<std::string> emittedStrings;
  3618. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  3619. std::set<std::string> emittedMinNumbers;
  3620. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  3621. std::set<std::string> emittedMaxNumbers;
  3622. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  3623. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  3624. deps.begin(); li != deps.end(); ++li)
  3625. {
  3626. if (!li->Target)
  3627. {
  3628. continue;
  3629. }
  3630. checkPropertyConsistency<bool>(this, li->Target,
  3631. strBool,
  3632. emittedBools, config, BoolType, 0);
  3633. if (cmSystemTools::GetErrorOccuredFlag())
  3634. {
  3635. return;
  3636. }
  3637. checkPropertyConsistency<const char *>(this, li->Target,
  3638. strString,
  3639. emittedStrings, config,
  3640. StringType, 0);
  3641. if (cmSystemTools::GetErrorOccuredFlag())
  3642. {
  3643. return;
  3644. }
  3645. checkPropertyConsistency<const char *>(this, li->Target,
  3646. strNumMin,
  3647. emittedMinNumbers, config,
  3648. NumberMinType, 0);
  3649. if (cmSystemTools::GetErrorOccuredFlag())
  3650. {
  3651. return;
  3652. }
  3653. checkPropertyConsistency<const char *>(this, li->Target,
  3654. strNumMax,
  3655. emittedMaxNumbers, config,
  3656. NumberMaxType, 0);
  3657. if (cmSystemTools::GetErrorOccuredFlag())
  3658. {
  3659. return;
  3660. }
  3661. }
  3662. std::string prop = intersect(emittedBools,
  3663. emittedStrings,
  3664. emittedMinNumbers,
  3665. emittedMaxNumbers);
  3666. if (!prop.empty())
  3667. {
  3668. // Use a sorted std::vector to keep the error message sorted.
  3669. std::vector<std::string> props;
  3670. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  3671. if (i != emittedBools.end())
  3672. {
  3673. props.push_back(strBool);
  3674. }
  3675. i = emittedStrings.find(prop);
  3676. if (i != emittedStrings.end())
  3677. {
  3678. props.push_back(strString);
  3679. }
  3680. i = emittedMinNumbers.find(prop);
  3681. if (i != emittedMinNumbers.end())
  3682. {
  3683. props.push_back(strNumMin);
  3684. }
  3685. i = emittedMaxNumbers.find(prop);
  3686. if (i != emittedMaxNumbers.end())
  3687. {
  3688. props.push_back(strNumMax);
  3689. }
  3690. std::sort(props.begin(), props.end());
  3691. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  3692. propsString += " and the " + props.back();
  3693. std::ostringstream e;
  3694. e << "Property \"" << prop << "\" appears in both the "
  3695. << propsString <<
  3696. " property in the dependencies of target \"" << this->GetName() <<
  3697. "\". This is not allowed. A property may only require compatibility "
  3698. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  3699. "string interpretation, but not a mixture.";
  3700. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  3701. }
  3702. }
  3703. //----------------------------------------------------------------------------
  3704. std::string compatibilityType(CompatibleType t)
  3705. {
  3706. switch(t)
  3707. {
  3708. case BoolType:
  3709. return "Boolean compatibility";
  3710. case StringType:
  3711. return "String compatibility";
  3712. case NumberMaxType:
  3713. return "Numeric maximum compatibility";
  3714. case NumberMinType:
  3715. return "Numeric minimum compatibility";
  3716. }
  3717. assert(0 && "Unreachable!");
  3718. return "";
  3719. }
  3720. //----------------------------------------------------------------------------
  3721. std::string compatibilityAgree(CompatibleType t, bool dominant)
  3722. {
  3723. switch(t)
  3724. {
  3725. case BoolType:
  3726. case StringType:
  3727. return dominant ? "(Disagree)\n" : "(Agree)\n";
  3728. case NumberMaxType:
  3729. case NumberMinType:
  3730. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  3731. }
  3732. assert(0 && "Unreachable!");
  3733. return "";
  3734. }
  3735. //----------------------------------------------------------------------------
  3736. template<typename PropertyType>
  3737. PropertyType getTypedProperty(cmGeneratorTarget const* tgt,
  3738. const std::string& prop);
  3739. //----------------------------------------------------------------------------
  3740. template<>
  3741. bool getTypedProperty<bool>(cmGeneratorTarget const* tgt,
  3742. const std::string& prop)
  3743. {
  3744. return tgt->GetPropertyAsBool(prop);
  3745. }
  3746. //----------------------------------------------------------------------------
  3747. template<>
  3748. const char *getTypedProperty<const char *>(cmGeneratorTarget const* tgt,
  3749. const std::string& prop)
  3750. {
  3751. return tgt->GetProperty(prop);
  3752. }
  3753. template<typename PropertyType>
  3754. std::string valueAsString(PropertyType);
  3755. template<>
  3756. std::string valueAsString<bool>(bool value)
  3757. {
  3758. return value ? "TRUE" : "FALSE";
  3759. }
  3760. template<>
  3761. std::string valueAsString<const char*>(const char* value)
  3762. {
  3763. return value ? value : "(unset)";
  3764. }
  3765. template<typename PropertyType>
  3766. PropertyType impliedValue(PropertyType);
  3767. template<>
  3768. bool impliedValue<bool>(bool)
  3769. {
  3770. return false;
  3771. }
  3772. template<>
  3773. const char* impliedValue<const char*>(const char*)
  3774. {
  3775. return "";
  3776. }
  3777. //----------------------------------------------------------------------------
  3778. template<typename PropertyType>
  3779. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  3780. PropertyType rhs,
  3781. CompatibleType t);
  3782. //----------------------------------------------------------------------------
  3783. template<>
  3784. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  3785. CompatibleType)
  3786. {
  3787. return std::make_pair(lhs == rhs, lhs);
  3788. }
  3789. //----------------------------------------------------------------------------
  3790. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  3791. const char *rhs)
  3792. {
  3793. const bool b = strcmp(lhs, rhs) == 0;
  3794. return std::make_pair(b, b ? lhs : 0);
  3795. }
  3796. //----------------------------------------------------------------------------
  3797. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  3798. const char *rhs,
  3799. CompatibleType t)
  3800. {
  3801. char *pEnd;
  3802. const char* const null_ptr = 0;
  3803. long lnum = strtol(lhs, &pEnd, 0);
  3804. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  3805. {
  3806. return std::pair<bool, const char*>(false, null_ptr);
  3807. }
  3808. long rnum = strtol(rhs, &pEnd, 0);
  3809. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  3810. {
  3811. return std::pair<bool, const char*>(false, null_ptr);
  3812. }
  3813. if (t == NumberMaxType)
  3814. {
  3815. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  3816. }
  3817. else
  3818. {
  3819. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  3820. }
  3821. }
  3822. //----------------------------------------------------------------------------
  3823. template<>
  3824. std::pair<bool, const char*> consistentProperty(const char *lhs,
  3825. const char *rhs,
  3826. CompatibleType t)
  3827. {
  3828. if (!lhs && !rhs)
  3829. {
  3830. return std::make_pair(true, lhs);
  3831. }
  3832. if (!lhs)
  3833. {
  3834. return std::make_pair(true, rhs);
  3835. }
  3836. if (!rhs)
  3837. {
  3838. return std::make_pair(true, lhs);
  3839. }
  3840. const char* const null_ptr = 0;
  3841. switch(t)
  3842. {
  3843. case BoolType:
  3844. assert(0 && "consistentProperty for strings called with BoolType");
  3845. return std::pair<bool, const char*>(false, null_ptr);
  3846. case StringType:
  3847. return consistentStringProperty(lhs, rhs);
  3848. case NumberMinType:
  3849. case NumberMaxType:
  3850. return consistentNumberProperty(lhs, rhs, t);
  3851. }
  3852. assert(0 && "Unreachable!");
  3853. return std::pair<bool, const char*>(false, null_ptr);
  3854. }
  3855. //----------------------------------------------------------------------------
  3856. template<typename PropertyType>
  3857. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  3858. const std::string &p,
  3859. const std::string& config,
  3860. const char *defaultValue,
  3861. CompatibleType t,
  3862. PropertyType *)
  3863. {
  3864. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
  3865. const bool explicitlySet = tgt->Target->GetProperties()
  3866. .find(p)
  3867. != tgt->Target->GetProperties().end();
  3868. const bool impliedByUse =
  3869. tgt->IsNullImpliedByLinkLibraries(p);
  3870. assert((impliedByUse ^ explicitlySet)
  3871. || (!impliedByUse && !explicitlySet));
  3872. std::vector<cmGeneratorTarget const*> const& deps =
  3873. tgt->GetLinkImplementationClosure(config);
  3874. if(deps.empty())
  3875. {
  3876. return propContent;
  3877. }
  3878. bool propInitialized = explicitlySet;
  3879. std::string report = " * Target \"";
  3880. report += tgt->GetName();
  3881. if (explicitlySet)
  3882. {
  3883. report += "\" has property content \"";
  3884. report += valueAsString<PropertyType>(propContent);
  3885. report += "\"\n";
  3886. }
  3887. else if (impliedByUse)
  3888. {
  3889. report += "\" property is implied by use.\n";
  3890. }
  3891. else
  3892. {
  3893. report += "\" property not set.\n";
  3894. }
  3895. std::string interfaceProperty = "INTERFACE_" + p;
  3896. for(std::vector<cmGeneratorTarget const*>::const_iterator li =
  3897. deps.begin();
  3898. li != deps.end(); ++li)
  3899. {
  3900. // An error should be reported if one dependency
  3901. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  3902. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  3903. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  3904. // with a dependency.
  3905. cmGeneratorTarget const* theTarget = *li;
  3906. const bool ifaceIsSet = theTarget->Target->GetProperties()
  3907. .find(interfaceProperty)
  3908. != theTarget->Target->GetProperties().end();
  3909. PropertyType ifacePropContent =
  3910. getTypedProperty<PropertyType>(theTarget,
  3911. interfaceProperty);
  3912. std::string reportEntry;
  3913. if (ifaceIsSet)
  3914. {
  3915. reportEntry += " * Target \"";
  3916. reportEntry += theTarget->GetName();
  3917. reportEntry += "\" property value \"";
  3918. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  3919. reportEntry += "\" ";
  3920. }
  3921. if (explicitlySet)
  3922. {
  3923. if (ifaceIsSet)
  3924. {
  3925. std::pair<bool, PropertyType> consistent =
  3926. consistentProperty(propContent,
  3927. ifacePropContent, t);
  3928. report += reportEntry;
  3929. report += compatibilityAgree(t, propContent != consistent.second);
  3930. if (!consistent.first)
  3931. {
  3932. std::ostringstream e;
  3933. e << "Property " << p << " on target \""
  3934. << tgt->GetName() << "\" does\nnot match the "
  3935. "INTERFACE_" << p << " property requirement\nof "
  3936. "dependency \"" << theTarget->GetName() << "\".\n";
  3937. cmSystemTools::Error(e.str().c_str());
  3938. break;
  3939. }
  3940. else
  3941. {
  3942. propContent = consistent.second;
  3943. continue;
  3944. }
  3945. }
  3946. else
  3947. {
  3948. // Explicitly set on target and not set in iface. Can't disagree.
  3949. continue;
  3950. }
  3951. }
  3952. else if (impliedByUse)
  3953. {
  3954. propContent = impliedValue<PropertyType>(propContent);
  3955. if (ifaceIsSet)
  3956. {
  3957. std::pair<bool, PropertyType> consistent =
  3958. consistentProperty(propContent,
  3959. ifacePropContent, t);
  3960. report += reportEntry;
  3961. report += compatibilityAgree(t, propContent != consistent.second);
  3962. if (!consistent.first)
  3963. {
  3964. std::ostringstream e;
  3965. e << "Property " << p << " on target \""
  3966. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  3967. << " because it was used to determine the link libraries\n"
  3968. "already. The INTERFACE_" << p << " property on\ndependency \""
  3969. << theTarget->GetName() << "\" is in conflict.\n";
  3970. cmSystemTools::Error(e.str().c_str());
  3971. break;
  3972. }
  3973. else
  3974. {
  3975. propContent = consistent.second;
  3976. continue;
  3977. }
  3978. }
  3979. else
  3980. {
  3981. // Implicitly set on target and not set in iface. Can't disagree.
  3982. continue;
  3983. }
  3984. }
  3985. else
  3986. {
  3987. if (ifaceIsSet)
  3988. {
  3989. if (propInitialized)
  3990. {
  3991. std::pair<bool, PropertyType> consistent =
  3992. consistentProperty(propContent,
  3993. ifacePropContent, t);
  3994. report += reportEntry;
  3995. report += compatibilityAgree(t, propContent != consistent.second);
  3996. if (!consistent.first)
  3997. {
  3998. std::ostringstream e;
  3999. e << "The INTERFACE_" << p << " property of \""
  4000. << theTarget->GetName() << "\" does\nnot agree with the value "
  4001. "of " << p << " already determined\nfor \""
  4002. << tgt->GetName() << "\".\n";
  4003. cmSystemTools::Error(e.str().c_str());
  4004. break;
  4005. }
  4006. else
  4007. {
  4008. propContent = consistent.second;
  4009. continue;
  4010. }
  4011. }
  4012. else
  4013. {
  4014. report += reportEntry + "(Interface set)\n";
  4015. propContent = ifacePropContent;
  4016. propInitialized = true;
  4017. }
  4018. }
  4019. else
  4020. {
  4021. // Not set. Nothing to agree on.
  4022. continue;
  4023. }
  4024. }
  4025. }
  4026. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  4027. report, compatibilityType(t));
  4028. return propContent;
  4029. }
  4030. //----------------------------------------------------------------------------
  4031. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  4032. const std::string &p, const std::string& config) const
  4033. {
  4034. return checkInterfacePropertyCompatibility<bool>(this, p, config,
  4035. "FALSE",
  4036. BoolType, 0);
  4037. }
  4038. //----------------------------------------------------------------------------
  4039. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  4040. const std::string &p,
  4041. const std::string& config) const
  4042. {
  4043. return checkInterfacePropertyCompatibility<const char *>(this,
  4044. p,
  4045. config,
  4046. "empty",
  4047. StringType, 0);
  4048. }
  4049. //----------------------------------------------------------------------------
  4050. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  4051. const std::string &p,
  4052. const std::string& config) const
  4053. {
  4054. return checkInterfacePropertyCompatibility<const char *>(this,
  4055. p,
  4056. config,
  4057. "empty",
  4058. NumberMinType, 0);
  4059. }
  4060. //----------------------------------------------------------------------------
  4061. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  4062. const std::string &p,
  4063. const std::string& config) const
  4064. {
  4065. return checkInterfacePropertyCompatibility<const char *>(this,
  4066. p,
  4067. config,
  4068. "empty",
  4069. NumberMaxType, 0);
  4070. }
  4071. //----------------------------------------------------------------------------
  4072. cmComputeLinkInformation*
  4073. cmGeneratorTarget::GetLinkInformation(const std::string& config) const
  4074. {
  4075. // Lookup any existing information for this configuration.
  4076. std::string key(cmSystemTools::UpperCase(config));
  4077. cmTargetLinkInformationMap::iterator
  4078. i = this->LinkInformation.find(key);
  4079. if(i == this->LinkInformation.end())
  4080. {
  4081. // Compute information for this configuration.
  4082. cmComputeLinkInformation* info =
  4083. new cmComputeLinkInformation(this, config);
  4084. if(!info || !info->Compute())
  4085. {
  4086. delete info;
  4087. info = 0;
  4088. }
  4089. // Store the information for this configuration.
  4090. cmTargetLinkInformationMap::value_type entry(key, info);
  4091. i = this->LinkInformation.insert(entry).first;
  4092. if (info)
  4093. {
  4094. this->CheckPropertyCompatibility(info, config);
  4095. }
  4096. }
  4097. return i->second;
  4098. }
  4099. //----------------------------------------------------------------------------
  4100. void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
  4101. {
  4102. int patch;
  4103. this->GetTargetVersion(false, major, minor, patch);
  4104. }
  4105. //----------------------------------------------------------------------------
  4106. void cmGeneratorTarget::GetTargetVersion(bool soversion,
  4107. int& major, int& minor, int& patch) const
  4108. {
  4109. // Set the default values.
  4110. major = 0;
  4111. minor = 0;
  4112. patch = 0;
  4113. assert(this->GetType() != cmState::INTERFACE_LIBRARY);
  4114. // Look for a VERSION or SOVERSION property.
  4115. const char* prop = soversion? "SOVERSION" : "VERSION";
  4116. if(const char* version = this->GetProperty(prop))
  4117. {
  4118. // Try to parse the version number and store the results that were
  4119. // successfully parsed.
  4120. int parsed_major;
  4121. int parsed_minor;
  4122. int parsed_patch;
  4123. switch(sscanf(version, "%d.%d.%d",
  4124. &parsed_major, &parsed_minor, &parsed_patch))
  4125. {
  4126. case 3: patch = parsed_patch; // no break!
  4127. case 2: minor = parsed_minor; // no break!
  4128. case 1: major = parsed_major; // no break!
  4129. default: break;
  4130. }
  4131. }
  4132. }
  4133. //----------------------------------------------------------------------------
  4134. std::string cmGeneratorTarget::GetFrameworkVersion() const
  4135. {
  4136. assert(this->GetType() != cmState::INTERFACE_LIBRARY);
  4137. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  4138. {
  4139. return fversion;
  4140. }
  4141. else if(const char* tversion = this->GetProperty("VERSION"))
  4142. {
  4143. return tversion;
  4144. }
  4145. else
  4146. {
  4147. return "A";
  4148. }
  4149. }
  4150. //----------------------------------------------------------------------------
  4151. void cmGeneratorTarget::ComputeVersionedName(std::string& vName,
  4152. std::string const& prefix,
  4153. std::string const& base,
  4154. std::string const& suffix,
  4155. std::string const& name,
  4156. const char* version) const
  4157. {
  4158. vName = this->Makefile->IsOn("APPLE") ? (prefix+base) : name;
  4159. if(version)
  4160. {
  4161. vName += ".";
  4162. vName += version;
  4163. }
  4164. vName += this->Makefile->IsOn("APPLE") ? suffix : std::string();
  4165. }
  4166. //----------------------------------------------------------------------------
  4167. void
  4168. cmGeneratorTarget::ReportPropertyOrigin(const std::string &p,
  4169. const std::string &result,
  4170. const std::string &report,
  4171. const std::string &compatibilityType) const
  4172. {
  4173. std::vector<std::string> debugProperties;
  4174. const char *debugProp = this->Target->GetMakefile()
  4175. ->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  4176. if (debugProp)
  4177. {
  4178. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  4179. }
  4180. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  4181. && std::find(debugProperties.begin(),
  4182. debugProperties.end(),
  4183. p)
  4184. != debugProperties.end();
  4185. if (this->GlobalGenerator->GetConfigureDoneCMP0026())
  4186. {
  4187. this->DebugCompatiblePropertiesDone[p] = true;
  4188. }
  4189. if (!debugOrigin)
  4190. {
  4191. return;
  4192. }
  4193. std::string areport = compatibilityType;
  4194. areport += std::string(" of property \"") + p + "\" for target \"";
  4195. areport += std::string(this->GetName());
  4196. areport += "\" (result: \"";
  4197. areport += result;
  4198. areport += "\"):\n" + report;
  4199. this->LocalGenerator->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  4200. }
  4201. //----------------------------------------------------------------------------
  4202. void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
  4203. std::vector<cmLinkItem>& items) const
  4204. {
  4205. for(std::vector<std::string>::const_iterator i = names.begin();
  4206. i != names.end(); ++i)
  4207. {
  4208. std::string name = this->CheckCMP0004(*i);
  4209. if(name == this->GetName() || name.empty())
  4210. {
  4211. continue;
  4212. }
  4213. items.push_back(cmLinkItem(name, this->FindTargetToLink(name)));
  4214. }
  4215. }
  4216. //----------------------------------------------------------------------------
  4217. void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
  4218. std::string const& value,
  4219. std::string const& config,
  4220. cmGeneratorTarget const* headTarget,
  4221. bool usage_requirements_only,
  4222. std::vector<cmLinkItem>& items,
  4223. bool& hadHeadSensitiveCondition) const
  4224. {
  4225. cmGeneratorExpression ge;
  4226. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0);
  4227. // The $<LINK_ONLY> expression may be in a link interface to specify private
  4228. // link dependencies that are otherwise excluded from usage requirements.
  4229. if(usage_requirements_only)
  4230. {
  4231. dagChecker.SetTransitivePropertiesOnly();
  4232. }
  4233. std::vector<std::string> libs;
  4234. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  4235. cmSystemTools::ExpandListArgument(cge->Evaluate(
  4236. this->LocalGenerator,
  4237. config,
  4238. false,
  4239. headTarget,
  4240. this, &dagChecker), libs);
  4241. this->LookupLinkItems(libs, items);
  4242. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  4243. }
  4244. //----------------------------------------------------------------------------
  4245. cmLinkInterface const*
  4246. cmGeneratorTarget::GetLinkInterface(const std::string& config,
  4247. cmGeneratorTarget const* head) const
  4248. {
  4249. // Imported targets have their own link interface.
  4250. if(this->IsImported())
  4251. {
  4252. return this->GetImportLinkInterface(config, head, false);
  4253. }
  4254. // Link interfaces are not supported for executables that do not
  4255. // export symbols.
  4256. if(this->GetType() == cmState::EXECUTABLE &&
  4257. !this->IsExecutableWithExports())
  4258. {
  4259. return 0;
  4260. }
  4261. // Lookup any existing link interface for this configuration.
  4262. cmHeadToLinkInterfaceMap& hm =
  4263. this->GetHeadToLinkInterfaceMap(config);
  4264. // If the link interface does not depend on the head target
  4265. // then return the one we computed first.
  4266. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  4267. {
  4268. return &hm.begin()->second;
  4269. }
  4270. cmOptionalLinkInterface& iface = hm[head];
  4271. if(!iface.LibrariesDone)
  4272. {
  4273. iface.LibrariesDone = true;
  4274. this->ComputeLinkInterfaceLibraries(
  4275. config, iface, head, false);
  4276. }
  4277. if(!iface.AllDone)
  4278. {
  4279. iface.AllDone = true;
  4280. if(iface.Exists)
  4281. {
  4282. this->ComputeLinkInterface(config, iface, head);
  4283. }
  4284. }
  4285. return iface.Exists? &iface : 0;
  4286. }
  4287. //----------------------------------------------------------------------------
  4288. void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
  4289. cmOptionalLinkInterface &iface,
  4290. cmGeneratorTarget const* headTarget) const
  4291. {
  4292. if(iface.ExplicitLibraries)
  4293. {
  4294. if(this->GetType() == cmState::SHARED_LIBRARY
  4295. || this->GetType() == cmState::STATIC_LIBRARY
  4296. || this->GetType() == cmState::INTERFACE_LIBRARY)
  4297. {
  4298. // Shared libraries may have runtime implementation dependencies
  4299. // on other shared libraries that are not in the interface.
  4300. UNORDERED_SET<std::string> emitted;
  4301. for(std::vector<cmLinkItem>::const_iterator
  4302. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  4303. {
  4304. emitted.insert(*li);
  4305. }
  4306. if (this->GetType() != cmState::INTERFACE_LIBRARY)
  4307. {
  4308. cmLinkImplementation const* impl =
  4309. this->GetLinkImplementation(config);
  4310. for(std::vector<cmLinkImplItem>::const_iterator
  4311. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  4312. {
  4313. if(emitted.insert(*li).second)
  4314. {
  4315. if(li->Target)
  4316. {
  4317. // This is a runtime dependency on another shared library.
  4318. if(li->Target->GetType() == cmState::SHARED_LIBRARY)
  4319. {
  4320. iface.SharedDeps.push_back(*li);
  4321. }
  4322. }
  4323. else
  4324. {
  4325. // TODO: Recognize shared library file names. Perhaps this
  4326. // should be moved to cmComputeLinkInformation, but that creates
  4327. // a chicken-and-egg problem since this list is needed for its
  4328. // construction.
  4329. }
  4330. }
  4331. }
  4332. }
  4333. }
  4334. }
  4335. else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN
  4336. || this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  4337. {
  4338. // The link implementation is the default link interface.
  4339. cmLinkImplementationLibraries const*
  4340. impl = this->GetLinkImplementationLibrariesInternal(config,
  4341. headTarget);
  4342. iface.ImplementationIsInterface = true;
  4343. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  4344. }
  4345. if(this->Target->LinkLanguagePropagatesToDependents())
  4346. {
  4347. // Targets using this archive need its language runtime libraries.
  4348. if(cmLinkImplementation const* impl =
  4349. this->GetLinkImplementation(config))
  4350. {
  4351. iface.Languages = impl->Languages;
  4352. }
  4353. }
  4354. if(this->GetType() == cmState::STATIC_LIBRARY)
  4355. {
  4356. // Construct the property name suffix for this configuration.
  4357. std::string suffix = "_";
  4358. if(!config.empty())
  4359. {
  4360. suffix += cmSystemTools::UpperCase(config);
  4361. }
  4362. else
  4363. {
  4364. suffix += "NOCONFIG";
  4365. }
  4366. // How many repetitions are needed if this library has cyclic
  4367. // dependencies?
  4368. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  4369. propName += suffix;
  4370. if(const char* config_reps = this->GetProperty(propName))
  4371. {
  4372. sscanf(config_reps, "%u", &iface.Multiplicity);
  4373. }
  4374. else if(const char* reps =
  4375. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  4376. {
  4377. sscanf(reps, "%u", &iface.Multiplicity);
  4378. }
  4379. }
  4380. }
  4381. //----------------------------------------------------------------------------
  4382. const cmLinkInterfaceLibraries *
  4383. cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config,
  4384. cmGeneratorTarget const* head,
  4385. bool usage_requirements_only) const
  4386. {
  4387. // Imported targets have their own link interface.
  4388. if(this->IsImported())
  4389. {
  4390. return this->GetImportLinkInterface(config, head,
  4391. usage_requirements_only);
  4392. }
  4393. // Link interfaces are not supported for executables that do not
  4394. // export symbols.
  4395. if(this->GetType() == cmState::EXECUTABLE &&
  4396. !this->IsExecutableWithExports())
  4397. {
  4398. return 0;
  4399. }
  4400. // Lookup any existing link interface for this configuration.
  4401. std::string CONFIG = cmSystemTools::UpperCase(config);
  4402. cmHeadToLinkInterfaceMap& hm =
  4403. (usage_requirements_only ?
  4404. this->GetHeadToLinkInterfaceUsageRequirementsMap(config) :
  4405. this->GetHeadToLinkInterfaceMap(config));
  4406. // If the link interface does not depend on the head target
  4407. // then return the one we computed first.
  4408. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  4409. {
  4410. return &hm.begin()->second;
  4411. }
  4412. cmOptionalLinkInterface& iface = hm[head];
  4413. if(!iface.LibrariesDone)
  4414. {
  4415. iface.LibrariesDone = true;
  4416. this->ComputeLinkInterfaceLibraries(
  4417. config, iface, head, usage_requirements_only);
  4418. }
  4419. return iface.Exists? &iface : 0;
  4420. }
  4421. //----------------------------------------------------------------------------
  4422. std::string cmGeneratorTarget::GetDirectory(const std::string& config,
  4423. bool implib) const
  4424. {
  4425. if (this->IsImported())
  4426. {
  4427. // Return the directory from which the target is imported.
  4428. return
  4429. cmSystemTools::GetFilenamePath(
  4430. this->Target->ImportedGetFullPath(config, implib));
  4431. }
  4432. else if(OutputInfo const* info = this->GetOutputInfo(config))
  4433. {
  4434. // Return the directory in which the target will be built.
  4435. return implib? info->ImpDir : info->OutDir;
  4436. }
  4437. return "";
  4438. }
  4439. //----------------------------------------------------------------------------
  4440. bool cmGeneratorTarget::UsesDefaultOutputDir(const std::string& config,
  4441. bool implib) const
  4442. {
  4443. std::string dir;
  4444. return this->ComputeOutputDir(config, implib, dir);
  4445. }
  4446. //----------------------------------------------------------------------------
  4447. cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
  4448. const std::string& config) const
  4449. {
  4450. // There is no output information for imported targets.
  4451. if(this->IsImported())
  4452. {
  4453. return 0;
  4454. }
  4455. // Only libraries and executables have well-defined output files.
  4456. if(!this->HaveWellDefinedOutputFiles())
  4457. {
  4458. std::string msg = "cmGeneratorTarget::GetOutputInfo called for ";
  4459. msg += this->GetName();
  4460. msg += " which has type ";
  4461. msg += cmState::GetTargetTypeName(this->GetType());
  4462. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  4463. return 0;
  4464. }
  4465. // Lookup/compute/cache the output information for this configuration.
  4466. std::string config_upper;
  4467. if(!config.empty())
  4468. {
  4469. config_upper = cmSystemTools::UpperCase(config);
  4470. }
  4471. OutputInfoMapType::iterator i =
  4472. this->OutputInfoMap.find(config_upper);
  4473. if(i == this->OutputInfoMap.end())
  4474. {
  4475. // Add empty info in map to detect potential recursion.
  4476. OutputInfo info;
  4477. OutputInfoMapType::value_type entry(config_upper, info);
  4478. i = this->OutputInfoMap.insert(entry).first;
  4479. // Compute output directories.
  4480. this->ComputeOutputDir(config, false, info.OutDir);
  4481. this->ComputeOutputDir(config, true, info.ImpDir);
  4482. if(!this->ComputePDBOutputDir("PDB", config, info.PdbDir))
  4483. {
  4484. info.PdbDir = info.OutDir;
  4485. }
  4486. // Now update the previously-prepared map entry.
  4487. i->second = info;
  4488. }
  4489. else if(i->second.empty())
  4490. {
  4491. // An empty map entry indicates we have been called recursively
  4492. // from the above block.
  4493. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  4494. cmake::FATAL_ERROR,
  4495. "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
  4496. this->GetBacktrace());
  4497. return 0;
  4498. }
  4499. return &i->second;
  4500. }
  4501. //----------------------------------------------------------------------------
  4502. bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
  4503. bool implib, std::string& out) const
  4504. {
  4505. bool usesDefaultOutputDir = false;
  4506. std::string conf = config;
  4507. // Look for a target property defining the target output directory
  4508. // based on the target type.
  4509. std::string targetTypeName = this->GetOutputTargetType(implib);
  4510. const char* propertyName = 0;
  4511. std::string propertyNameStr = targetTypeName;
  4512. if(!propertyNameStr.empty())
  4513. {
  4514. propertyNameStr += "_OUTPUT_DIRECTORY";
  4515. propertyName = propertyNameStr.c_str();
  4516. }
  4517. // Check for a per-configuration output directory target property.
  4518. std::string configUpper = cmSystemTools::UpperCase(conf);
  4519. const char* configProp = 0;
  4520. std::string configPropStr = targetTypeName;
  4521. if(!configPropStr.empty())
  4522. {
  4523. configPropStr += "_OUTPUT_DIRECTORY_";
  4524. configPropStr += configUpper;
  4525. configProp = configPropStr.c_str();
  4526. }
  4527. // Select an output directory.
  4528. if(const char* config_outdir = this->GetProperty(configProp))
  4529. {
  4530. // Use the user-specified per-configuration output directory.
  4531. cmGeneratorExpression ge;
  4532. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  4533. ge.Parse(config_outdir);
  4534. out = cge->Evaluate(this->LocalGenerator, config);
  4535. // Skip per-configuration subdirectory.
  4536. conf = "";
  4537. }
  4538. else if(const char* outdir = this->GetProperty(propertyName))
  4539. {
  4540. // Use the user-specified output directory.
  4541. cmGeneratorExpression ge;
  4542. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  4543. ge.Parse(outdir);
  4544. out = cge->Evaluate(this->LocalGenerator, config);
  4545. // Skip per-configuration subdirectory if the value contained a
  4546. // generator expression.
  4547. if (out != outdir)
  4548. {
  4549. conf = "";
  4550. }
  4551. }
  4552. else if(this->GetType() == cmState::EXECUTABLE)
  4553. {
  4554. // Lookup the output path for executables.
  4555. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  4556. }
  4557. else if(this->GetType() == cmState::STATIC_LIBRARY ||
  4558. this->GetType() == cmState::SHARED_LIBRARY ||
  4559. this->GetType() == cmState::MODULE_LIBRARY)
  4560. {
  4561. // Lookup the output path for libraries.
  4562. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  4563. }
  4564. if(out.empty())
  4565. {
  4566. // Default to the current output directory.
  4567. usesDefaultOutputDir = true;
  4568. out = ".";
  4569. }
  4570. // Convert the output path to a full path in case it is
  4571. // specified as a relative path. Treat a relative path as
  4572. // relative to the current output directory for this makefile.
  4573. out = (cmSystemTools::CollapseFullPath
  4574. (out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  4575. // The generator may add the configuration's subdirectory.
  4576. if(!conf.empty())
  4577. {
  4578. bool iosPlatform = this->Makefile->PlatformIsAppleIos();
  4579. std::string suffix =
  4580. usesDefaultOutputDir && iosPlatform ? "${EFFECTIVE_PLATFORM_NAME}" : "";
  4581. this->LocalGenerator->GetGlobalGenerator()->
  4582. AppendDirectoryForConfig("/", conf, suffix, out);
  4583. }
  4584. return usesDefaultOutputDir;
  4585. }
  4586. //----------------------------------------------------------------------------
  4587. bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
  4588. const std::string& config,
  4589. std::string& out) const
  4590. {
  4591. // Look for a target property defining the target output directory
  4592. // based on the target type.
  4593. const char* propertyName = 0;
  4594. std::string propertyNameStr = kind;
  4595. if(!propertyNameStr.empty())
  4596. {
  4597. propertyNameStr += "_OUTPUT_DIRECTORY";
  4598. propertyName = propertyNameStr.c_str();
  4599. }
  4600. std::string conf = config;
  4601. // Check for a per-configuration output directory target property.
  4602. std::string configUpper = cmSystemTools::UpperCase(conf);
  4603. const char* configProp = 0;
  4604. std::string configPropStr = kind;
  4605. if(!configPropStr.empty())
  4606. {
  4607. configPropStr += "_OUTPUT_DIRECTORY_";
  4608. configPropStr += configUpper;
  4609. configProp = configPropStr.c_str();
  4610. }
  4611. // Select an output directory.
  4612. if(const char* config_outdir = this->GetProperty(configProp))
  4613. {
  4614. // Use the user-specified per-configuration output directory.
  4615. out = config_outdir;
  4616. // Skip per-configuration subdirectory.
  4617. conf = "";
  4618. }
  4619. else if(const char* outdir = this->GetProperty(propertyName))
  4620. {
  4621. // Use the user-specified output directory.
  4622. out = outdir;
  4623. }
  4624. if(out.empty())
  4625. {
  4626. return false;
  4627. }
  4628. // Convert the output path to a full path in case it is
  4629. // specified as a relative path. Treat a relative path as
  4630. // relative to the current output directory for this makefile.
  4631. out = (cmSystemTools::CollapseFullPath
  4632. (out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  4633. // The generator may add the configuration's subdirectory.
  4634. if(!conf.empty())
  4635. {
  4636. this->LocalGenerator->GetGlobalGenerator()->
  4637. AppendDirectoryForConfig("/", conf, "", out);
  4638. }
  4639. return true;
  4640. }
  4641. //----------------------------------------------------------------------------
  4642. bool cmGeneratorTarget::HaveInstallTreeRPATH() const
  4643. {
  4644. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  4645. return (install_rpath && *install_rpath) &&
  4646. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  4647. }
  4648. //----------------------------------------------------------------------------
  4649. void
  4650. cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  4651. const std::string& config,
  4652. cmOptionalLinkInterface& iface,
  4653. cmGeneratorTarget const* headTarget,
  4654. bool usage_requirements_only) const
  4655. {
  4656. // Construct the property name suffix for this configuration.
  4657. std::string suffix = "_";
  4658. if(!config.empty())
  4659. {
  4660. suffix += cmSystemTools::UpperCase(config);
  4661. }
  4662. else
  4663. {
  4664. suffix += "NOCONFIG";
  4665. }
  4666. // An explicit list of interface libraries may be set for shared
  4667. // libraries and executables that export symbols.
  4668. const char* explicitLibraries = 0;
  4669. std::string linkIfaceProp;
  4670. if(this->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  4671. this->GetPolicyStatusCMP0022() != cmPolicies::WARN)
  4672. {
  4673. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  4674. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  4675. explicitLibraries = this->GetProperty(linkIfaceProp);
  4676. }
  4677. else if(this->GetType() == cmState::SHARED_LIBRARY ||
  4678. this->IsExecutableWithExports())
  4679. {
  4680. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  4681. // shared lib or executable.
  4682. // Lookup the per-configuration property.
  4683. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4684. linkIfaceProp += suffix;
  4685. explicitLibraries = this->GetProperty(linkIfaceProp);
  4686. // If not set, try the generic property.
  4687. if(!explicitLibraries)
  4688. {
  4689. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4690. explicitLibraries = this->GetProperty(linkIfaceProp);
  4691. }
  4692. }
  4693. if(explicitLibraries &&
  4694. this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4695. !this->PolicyWarnedCMP0022)
  4696. {
  4697. // Compare the explicitly set old link interface properties to the
  4698. // preferred new link interface property one and warn if different.
  4699. const char* newExplicitLibraries =
  4700. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  4701. if (newExplicitLibraries
  4702. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  4703. {
  4704. std::ostringstream w;
  4705. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4706. "Target \"" << this->GetName() << "\" has an "
  4707. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  4708. linkIfaceProp << " properties."
  4709. "\n"
  4710. "INTERFACE_LINK_LIBRARIES:\n"
  4711. " " << newExplicitLibraries << "\n" <<
  4712. linkIfaceProp << ":\n"
  4713. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  4714. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  4715. this->PolicyWarnedCMP0022 = true;
  4716. }
  4717. }
  4718. // There is no implicit link interface for executables or modules
  4719. // so if none was explicitly set then there is no link interface.
  4720. if(!explicitLibraries &&
  4721. (this->GetType() == cmState::EXECUTABLE ||
  4722. (this->GetType() == cmState::MODULE_LIBRARY)))
  4723. {
  4724. return;
  4725. }
  4726. iface.Exists = true;
  4727. iface.ExplicitLibraries = explicitLibraries;
  4728. if(explicitLibraries)
  4729. {
  4730. // The interface libraries have been explicitly set.
  4731. this->ExpandLinkItems(linkIfaceProp, explicitLibraries,
  4732. config,
  4733. headTarget, usage_requirements_only,
  4734. iface.Libraries,
  4735. iface.HadHeadSensitiveCondition);
  4736. }
  4737. else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN
  4738. || this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  4739. // If CMP0022 is NEW then the plain tll signature sets the
  4740. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  4741. // cleared the property explicitly and we should not fall back
  4742. // to the link implementation.
  4743. {
  4744. // The link implementation is the default link interface.
  4745. cmLinkImplementationLibraries const* impl =
  4746. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  4747. iface.Libraries.insert(iface.Libraries.end(),
  4748. impl->Libraries.begin(), impl->Libraries.end());
  4749. if(this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4750. !this->PolicyWarnedCMP0022 && !usage_requirements_only)
  4751. {
  4752. // Compare the link implementation fallback link interface to the
  4753. // preferred new link interface property and warn if different.
  4754. std::vector<cmLinkItem> ifaceLibs;
  4755. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  4756. if(const char* newExplicitLibraries = this->GetProperty(newProp))
  4757. {
  4758. bool hadHeadSensitiveConditionDummy = false;
  4759. this->ExpandLinkItems(newProp, newExplicitLibraries, config,
  4760. headTarget,
  4761. usage_requirements_only,
  4762. ifaceLibs, hadHeadSensitiveConditionDummy);
  4763. }
  4764. if (ifaceLibs != iface.Libraries)
  4765. {
  4766. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  4767. std::string newLibraries = cmJoin(ifaceLibs, ";");
  4768. if(oldLibraries.empty())
  4769. { oldLibraries = "(empty)"; }
  4770. if(newLibraries.empty())
  4771. { newLibraries = "(empty)"; }
  4772. std::ostringstream w;
  4773. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4774. "Target \"" << this->GetName() << "\" has an "
  4775. "INTERFACE_LINK_LIBRARIES property. "
  4776. "This should be preferred as the source of the link interface "
  4777. "for this library but because CMP0022 is not set CMake is "
  4778. "ignoring the property and using the link implementation "
  4779. "as the link interface instead."
  4780. "\n"
  4781. "INTERFACE_LINK_LIBRARIES:\n"
  4782. " " << newLibraries << "\n"
  4783. "Link implementation:\n"
  4784. " " << oldLibraries << "\n";
  4785. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  4786. this->PolicyWarnedCMP0022 = true;
  4787. }
  4788. }
  4789. }
  4790. }
  4791. //----------------------------------------------------------------------------
  4792. const cmLinkInterface *
  4793. cmGeneratorTarget::GetImportLinkInterface(const std::string& config,
  4794. cmGeneratorTarget const* headTarget,
  4795. bool usage_requirements_only) const
  4796. {
  4797. cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config);
  4798. if(!info)
  4799. {
  4800. return 0;
  4801. }
  4802. std::string CONFIG = cmSystemTools::UpperCase(config);
  4803. cmHeadToLinkInterfaceMap& hm =
  4804. (usage_requirements_only ?
  4805. this->GetHeadToLinkInterfaceUsageRequirementsMap(config) :
  4806. this->GetHeadToLinkInterfaceMap(config));
  4807. // If the link interface does not depend on the head target
  4808. // then return the one we computed first.
  4809. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  4810. {
  4811. return &hm.begin()->second;
  4812. }
  4813. cmOptionalLinkInterface& iface = hm[headTarget];
  4814. if(!iface.AllDone)
  4815. {
  4816. iface.AllDone = true;
  4817. iface.Multiplicity = info->Multiplicity;
  4818. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  4819. this->ExpandLinkItems(info->LibrariesProp, info->Libraries,
  4820. config,
  4821. headTarget, usage_requirements_only,
  4822. iface.Libraries,
  4823. iface.HadHeadSensitiveCondition);
  4824. std::vector<std::string> deps;
  4825. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  4826. this->LookupLinkItems(deps, iface.SharedDeps);
  4827. }
  4828. return &iface;
  4829. }
  4830. //----------------------------------------------------------------------------
  4831. cmGeneratorTarget::ImportInfo const*
  4832. cmGeneratorTarget::GetImportInfo(const std::string& config) const
  4833. {
  4834. // There is no imported information for non-imported targets.
  4835. if(!this->IsImported())
  4836. {
  4837. return 0;
  4838. }
  4839. // Lookup/compute/cache the import information for this
  4840. // configuration.
  4841. std::string config_upper;
  4842. if(!config.empty())
  4843. {
  4844. config_upper = cmSystemTools::UpperCase(config);
  4845. }
  4846. else
  4847. {
  4848. config_upper = "NOCONFIG";
  4849. }
  4850. ImportInfoMapType::const_iterator i =
  4851. this->ImportInfoMap.find(config_upper);
  4852. if(i == this->ImportInfoMap.end())
  4853. {
  4854. ImportInfo info;
  4855. this->ComputeImportInfo(config_upper, info);
  4856. ImportInfoMapType::value_type entry(config_upper, info);
  4857. i = this->ImportInfoMap.insert(entry).first;
  4858. }
  4859. if(this->GetType() == cmState::INTERFACE_LIBRARY)
  4860. {
  4861. return &i->second;
  4862. }
  4863. // If the location is empty then the target is not available for
  4864. // this configuration.
  4865. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  4866. {
  4867. return 0;
  4868. }
  4869. // Return the import information.
  4870. return &i->second;
  4871. }
  4872. //----------------------------------------------------------------------------
  4873. void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config,
  4874. ImportInfo& info) const
  4875. {
  4876. // This method finds information about an imported target from its
  4877. // properties. The "IMPORTED_" namespace is reserved for properties
  4878. // defined by the project exporting the target.
  4879. // Initialize members.
  4880. info.NoSOName = false;
  4881. const char* loc = 0;
  4882. const char* imp = 0;
  4883. std::string suffix;
  4884. if (!this->Target->GetMappedConfig(desired_config, &loc, &imp, suffix))
  4885. {
  4886. return;
  4887. }
  4888. // Get the link interface.
  4889. {
  4890. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  4891. const char *propertyLibs = this->GetProperty(linkProp);
  4892. if (this->GetType() != cmState::INTERFACE_LIBRARY)
  4893. {
  4894. if(!propertyLibs)
  4895. {
  4896. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4897. linkProp += suffix;
  4898. propertyLibs = this->GetProperty(linkProp);
  4899. }
  4900. if(!propertyLibs)
  4901. {
  4902. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4903. propertyLibs = this->GetProperty(linkProp);
  4904. }
  4905. }
  4906. if(propertyLibs)
  4907. {
  4908. info.LibrariesProp = linkProp;
  4909. info.Libraries = propertyLibs;
  4910. }
  4911. }
  4912. if(this->GetType() == cmState::INTERFACE_LIBRARY)
  4913. {
  4914. return;
  4915. }
  4916. // A provided configuration has been chosen. Load the
  4917. // configuration's properties.
  4918. // Get the location.
  4919. if(loc)
  4920. {
  4921. info.Location = loc;
  4922. }
  4923. else
  4924. {
  4925. std::string impProp = "IMPORTED_LOCATION";
  4926. impProp += suffix;
  4927. if(const char* config_location = this->GetProperty(impProp))
  4928. {
  4929. info.Location = config_location;
  4930. }
  4931. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  4932. {
  4933. info.Location = location;
  4934. }
  4935. }
  4936. // Get the soname.
  4937. if(this->GetType() == cmState::SHARED_LIBRARY)
  4938. {
  4939. std::string soProp = "IMPORTED_SONAME";
  4940. soProp += suffix;
  4941. if(const char* config_soname = this->GetProperty(soProp))
  4942. {
  4943. info.SOName = config_soname;
  4944. }
  4945. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  4946. {
  4947. info.SOName = soname;
  4948. }
  4949. }
  4950. // Get the "no-soname" mark.
  4951. if(this->GetType() == cmState::SHARED_LIBRARY)
  4952. {
  4953. std::string soProp = "IMPORTED_NO_SONAME";
  4954. soProp += suffix;
  4955. if(const char* config_no_soname = this->GetProperty(soProp))
  4956. {
  4957. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  4958. }
  4959. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  4960. {
  4961. info.NoSOName = cmSystemTools::IsOn(no_soname);
  4962. }
  4963. }
  4964. // Get the import library.
  4965. if(imp)
  4966. {
  4967. info.ImportLibrary = imp;
  4968. }
  4969. else if(this->GetType() == cmState::SHARED_LIBRARY ||
  4970. this->IsExecutableWithExports())
  4971. {
  4972. std::string impProp = "IMPORTED_IMPLIB";
  4973. impProp += suffix;
  4974. if(const char* config_implib = this->GetProperty(impProp))
  4975. {
  4976. info.ImportLibrary = config_implib;
  4977. }
  4978. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  4979. {
  4980. info.ImportLibrary = implib;
  4981. }
  4982. }
  4983. // Get the link dependencies.
  4984. {
  4985. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  4986. linkProp += suffix;
  4987. if(const char* config_libs = this->GetProperty(linkProp))
  4988. {
  4989. info.SharedDeps = config_libs;
  4990. }
  4991. else if(const char* libs =
  4992. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  4993. {
  4994. info.SharedDeps = libs;
  4995. }
  4996. }
  4997. // Get the link languages.
  4998. if(this->Target->LinkLanguagePropagatesToDependents())
  4999. {
  5000. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  5001. linkProp += suffix;
  5002. if(const char* config_libs = this->GetProperty(linkProp))
  5003. {
  5004. info.Languages = config_libs;
  5005. }
  5006. else if(const char* libs =
  5007. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  5008. {
  5009. info.Languages = libs;
  5010. }
  5011. }
  5012. // Get the cyclic repetition count.
  5013. if(this->GetType() == cmState::STATIC_LIBRARY)
  5014. {
  5015. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  5016. linkProp += suffix;
  5017. if(const char* config_reps = this->GetProperty(linkProp))
  5018. {
  5019. sscanf(config_reps, "%u", &info.Multiplicity);
  5020. }
  5021. else if(const char* reps =
  5022. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  5023. {
  5024. sscanf(reps, "%u", &info.Multiplicity);
  5025. }
  5026. }
  5027. }
  5028. cmHeadToLinkInterfaceMap&
  5029. cmGeneratorTarget::GetHeadToLinkInterfaceMap(const std::string &config) const
  5030. {
  5031. std::string CONFIG = cmSystemTools::UpperCase(config);
  5032. return this->LinkInterfaceMap[CONFIG];
  5033. }
  5034. cmHeadToLinkInterfaceMap&
  5035. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  5036. const std::string &config) const
  5037. {
  5038. std::string CONFIG = cmSystemTools::UpperCase(config);
  5039. return this->LinkInterfaceUsageRequirementsOnlyMap[CONFIG];
  5040. }
  5041. //----------------------------------------------------------------------------
  5042. const cmLinkImplementation *
  5043. cmGeneratorTarget::GetLinkImplementation(const std::string& config) const
  5044. {
  5045. // There is no link implementation for imported targets.
  5046. if(this->IsImported())
  5047. {
  5048. return 0;
  5049. }
  5050. std::string CONFIG = cmSystemTools::UpperCase(config);
  5051. cmOptionalLinkImplementation& impl = this->LinkImplMap[CONFIG][this->Target];
  5052. if(!impl.LibrariesDone)
  5053. {
  5054. impl.LibrariesDone = true;
  5055. this->ComputeLinkImplementationLibraries(config, impl, this);
  5056. }
  5057. if(!impl.LanguagesDone)
  5058. {
  5059. impl.LanguagesDone = true;
  5060. this->ComputeLinkImplementationLanguages(config, impl);
  5061. }
  5062. return &impl;
  5063. }
  5064. //----------------------------------------------------------------------------
  5065. bool cmGeneratorTarget::GetConfigCommonSourceFiles(
  5066. std::vector<cmSourceFile*>& files) const
  5067. {
  5068. std::vector<std::string> configs;
  5069. this->Makefile->GetConfigurations(configs);
  5070. if (configs.empty())
  5071. {
  5072. configs.push_back("");
  5073. }
  5074. std::vector<std::string>::const_iterator it = configs.begin();
  5075. const std::string& firstConfig = *it;
  5076. this->GetSourceFiles(files, firstConfig);
  5077. for ( ; it != configs.end(); ++it)
  5078. {
  5079. std::vector<cmSourceFile*> configFiles;
  5080. this->GetSourceFiles(configFiles, *it);
  5081. if (configFiles != files)
  5082. {
  5083. std::string firstConfigFiles;
  5084. const char* sep = "";
  5085. for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
  5086. fi != files.end(); ++fi)
  5087. {
  5088. firstConfigFiles += sep;
  5089. firstConfigFiles += (*fi)->GetFullPath();
  5090. sep = "\n ";
  5091. }
  5092. std::string thisConfigFiles;
  5093. sep = "";
  5094. for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
  5095. fi != configFiles.end(); ++fi)
  5096. {
  5097. thisConfigFiles += sep;
  5098. thisConfigFiles += (*fi)->GetFullPath();
  5099. sep = "\n ";
  5100. }
  5101. std::ostringstream e;
  5102. e << "Target \"" << this->GetName()
  5103. << "\" has source files which vary by "
  5104. "configuration. This is not supported by the \""
  5105. << this->GlobalGenerator->GetName()
  5106. << "\" generator.\n"
  5107. "Config \"" << firstConfig << "\":\n"
  5108. " " << firstConfigFiles << "\n"
  5109. "Config \"" << *it << "\":\n"
  5110. " " << thisConfigFiles << "\n";
  5111. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  5112. return false;
  5113. }
  5114. }
  5115. return true;
  5116. }
  5117. //----------------------------------------------------------------------------
  5118. void cmGeneratorTarget::GetObjectLibrariesCMP0026(
  5119. std::vector<cmGeneratorTarget*>& objlibs) const
  5120. {
  5121. // At configure-time, this method can be called as part of getting the
  5122. // LOCATION property or to export() a file to be include()d. However
  5123. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  5124. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  5125. // behavior of CMP0024 and CMP0026 only.
  5126. cmStringRange rng = this->Target->GetSourceEntries();
  5127. for(std::vector<std::string>::const_iterator
  5128. i = rng.begin(); i != rng.end(); ++i)
  5129. {
  5130. std::string const& entry = *i;
  5131. std::vector<std::string> files;
  5132. cmSystemTools::ExpandListArgument(entry, files);
  5133. for (std::vector<std::string>::const_iterator
  5134. li = files.begin(); li != files.end(); ++li)
  5135. {
  5136. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  5137. (*li)[li->size() - 1] == '>')
  5138. {
  5139. std::string objLibName = li->substr(17, li->size()-18);
  5140. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  5141. {
  5142. continue;
  5143. }
  5144. cmGeneratorTarget *objLib =
  5145. this->LocalGenerator->FindGeneratorTargetToUse(objLibName);
  5146. if(objLib)
  5147. {
  5148. objlibs.push_back(objLib);
  5149. }
  5150. }
  5151. }
  5152. }
  5153. }
  5154. //----------------------------------------------------------------------------
  5155. std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
  5156. {
  5157. // Strip whitespace off the library names because we used to do this
  5158. // in case variables were expanded at generate time. We no longer
  5159. // do the expansion but users link to libraries like " ${VAR} ".
  5160. std::string lib = item;
  5161. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  5162. if(pos != lib.npos)
  5163. {
  5164. lib = lib.substr(pos, lib.npos);
  5165. }
  5166. pos = lib.find_last_not_of(" \t\r\n");
  5167. if(pos != lib.npos)
  5168. {
  5169. lib = lib.substr(0, pos+1);
  5170. }
  5171. if(lib != item)
  5172. {
  5173. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  5174. switch(this->GetPolicyStatusCMP0004())
  5175. {
  5176. case cmPolicies::WARN:
  5177. {
  5178. std::ostringstream w;
  5179. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  5180. << "Target \"" << this->GetName() << "\" links to item \""
  5181. << item << "\" which has leading or trailing whitespace.";
  5182. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  5183. this->GetBacktrace());
  5184. }
  5185. case cmPolicies::OLD:
  5186. break;
  5187. case cmPolicies::NEW:
  5188. {
  5189. std::ostringstream e;
  5190. e << "Target \"" << this->GetName() << "\" links to item \""
  5191. << item << "\" which has leading or trailing whitespace. "
  5192. << "This is now an error according to policy CMP0004.";
  5193. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  5194. this->GetBacktrace());
  5195. }
  5196. break;
  5197. case cmPolicies::REQUIRED_IF_USED:
  5198. case cmPolicies::REQUIRED_ALWAYS:
  5199. {
  5200. std::ostringstream e;
  5201. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  5202. << "Target \"" << this->GetName() << "\" links to item \""
  5203. << item << "\" which has leading or trailing whitespace.";
  5204. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  5205. this->GetBacktrace());
  5206. }
  5207. break;
  5208. }
  5209. }
  5210. return lib;
  5211. }
  5212. //----------------------------------------------------------------------------
  5213. void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
  5214. const std::string& config) const
  5215. {
  5216. std::vector<cmSourceFile*> sourceFiles;
  5217. this->GetSourceFiles(sourceFiles, config);
  5218. for(std::vector<cmSourceFile*>::const_iterator
  5219. i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
  5220. {
  5221. const std::string& lang = (*i)->GetLanguage();
  5222. if(!lang.empty())
  5223. {
  5224. languages.insert(lang);
  5225. }
  5226. }
  5227. std::vector<cmGeneratorTarget*> objectLibraries;
  5228. std::vector<cmSourceFile const*> externalObjects;
  5229. if (!this->GlobalGenerator->GetConfigureDoneCMP0026())
  5230. {
  5231. std::vector<cmGeneratorTarget*> objectTargets;
  5232. this->GetObjectLibrariesCMP0026(objectTargets);
  5233. objectLibraries.reserve(objectTargets.size());
  5234. for (std::vector<cmGeneratorTarget*>::const_iterator it =
  5235. objectTargets.begin(); it != objectTargets.end(); ++it)
  5236. {
  5237. objectLibraries.push_back(*it);
  5238. }
  5239. }
  5240. else
  5241. {
  5242. this->GetExternalObjects(externalObjects, config);
  5243. for(std::vector<cmSourceFile const*>::const_iterator
  5244. i = externalObjects.begin(); i != externalObjects.end(); ++i)
  5245. {
  5246. std::string objLib = (*i)->GetObjectLibrary();
  5247. if (cmGeneratorTarget* tgt =
  5248. this->LocalGenerator->FindGeneratorTargetToUse(objLib))
  5249. {
  5250. objectLibraries.push_back(tgt);
  5251. }
  5252. }
  5253. }
  5254. for(std::vector<cmGeneratorTarget*>::const_iterator
  5255. i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
  5256. {
  5257. (*i)->GetLanguages(languages, config);
  5258. }
  5259. }
  5260. //----------------------------------------------------------------------------
  5261. void cmGeneratorTarget::ComputeLinkImplementationLanguages(
  5262. const std::string& config,
  5263. cmOptionalLinkImplementation& impl) const
  5264. {
  5265. // This target needs runtime libraries for its source languages.
  5266. std::set<std::string> languages;
  5267. // Get languages used in our source files.
  5268. this->GetLanguages(languages, config);
  5269. // Copy the set of langauges to the link implementation.
  5270. impl.Languages.insert(impl.Languages.begin(),
  5271. languages.begin(), languages.end());
  5272. }
  5273. //----------------------------------------------------------------------------
  5274. bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const
  5275. {
  5276. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  5277. {
  5278. return false;
  5279. }
  5280. if(cmLinkImplementationLibraries const* impl =
  5281. this->GetLinkImplementationLibraries(config))
  5282. {
  5283. return !impl->Libraries.empty();
  5284. }
  5285. return false;
  5286. }
  5287. //----------------------------------------------------------------------------
  5288. cmLinkImplementationLibraries const*
  5289. cmGeneratorTarget::GetLinkImplementationLibraries(
  5290. const std::string& config) const
  5291. {
  5292. return this->GetLinkImplementationLibrariesInternal(config, this);
  5293. }
  5294. //----------------------------------------------------------------------------
  5295. cmLinkImplementationLibraries const*
  5296. cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
  5297. const std::string& config, cmGeneratorTarget const* head) const
  5298. {
  5299. // There is no link implementation for imported targets.
  5300. if(this->IsImported())
  5301. {
  5302. return 0;
  5303. }
  5304. // Populate the link implementation libraries for this configuration.
  5305. std::string CONFIG = cmSystemTools::UpperCase(config);
  5306. HeadToLinkImplementationMap& hm =
  5307. this->LinkImplMap[CONFIG];
  5308. // If the link implementation does not depend on the head target
  5309. // then return the one we computed first.
  5310. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  5311. {
  5312. return &hm.begin()->second;
  5313. }
  5314. cmOptionalLinkImplementation& impl = hm[head->Target];
  5315. if(!impl.LibrariesDone)
  5316. {
  5317. impl.LibrariesDone = true;
  5318. this->ComputeLinkImplementationLibraries(config, impl, head);
  5319. }
  5320. return &impl;
  5321. }
  5322. //----------------------------------------------------------------------------
  5323. bool
  5324. cmGeneratorTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
  5325. {
  5326. return this->LinkImplicitNullProperties.find(p)
  5327. != this->LinkImplicitNullProperties.end();
  5328. }
  5329. //----------------------------------------------------------------------------
  5330. void cmGeneratorTarget::ComputeLinkImplementationLibraries(
  5331. const std::string& config,
  5332. cmOptionalLinkImplementation& impl,
  5333. cmGeneratorTarget const* head) const
  5334. {
  5335. cmStringRange entryRange =
  5336. this->Target->GetLinkImplementationEntries();
  5337. cmBacktraceRange btRange =
  5338. this->Target->GetLinkImplementationBacktraces();
  5339. cmBacktraceRange::const_iterator btIt = btRange.begin();
  5340. // Collect libraries directly linked in this configuration.
  5341. for (cmStringRange::const_iterator le = entryRange.begin(),
  5342. end = entryRange.end(); le != end; ++le, ++btIt)
  5343. {
  5344. std::vector<std::string> llibs;
  5345. cmGeneratorExpressionDAGChecker dagChecker(
  5346. this->GetName(),
  5347. "LINK_LIBRARIES", 0, 0);
  5348. cmGeneratorExpression ge(*btIt);
  5349. cmsys::auto_ptr<cmCompiledGeneratorExpression> const cge =
  5350. ge.Parse(*le);
  5351. std::string const evaluated =
  5352. cge->Evaluate(this->LocalGenerator, config, false, head, &dagChecker);
  5353. cmSystemTools::ExpandListArgument(evaluated, llibs);
  5354. if(cge->GetHadHeadSensitiveCondition())
  5355. {
  5356. impl.HadHeadSensitiveCondition = true;
  5357. }
  5358. for(std::vector<std::string>::const_iterator li = llibs.begin();
  5359. li != llibs.end(); ++li)
  5360. {
  5361. // Skip entries that resolve to the target itself or are empty.
  5362. std::string name = this->CheckCMP0004(*li);
  5363. if(name == this->GetName() || name.empty())
  5364. {
  5365. if(name == this->GetName())
  5366. {
  5367. bool noMessage = false;
  5368. cmake::MessageType messageType = cmake::FATAL_ERROR;
  5369. std::ostringstream e;
  5370. switch(this->GetPolicyStatusCMP0038())
  5371. {
  5372. case cmPolicies::WARN:
  5373. {
  5374. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  5375. messageType = cmake::AUTHOR_WARNING;
  5376. }
  5377. break;
  5378. case cmPolicies::OLD:
  5379. noMessage = true;
  5380. case cmPolicies::REQUIRED_IF_USED:
  5381. case cmPolicies::REQUIRED_ALWAYS:
  5382. case cmPolicies::NEW:
  5383. // Issue the fatal message.
  5384. break;
  5385. }
  5386. if(!noMessage)
  5387. {
  5388. e << "Target \"" << this->GetName() << "\" links to itself.";
  5389. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  5390. messageType, e.str(), this->GetBacktrace());
  5391. if (messageType == cmake::FATAL_ERROR)
  5392. {
  5393. return;
  5394. }
  5395. }
  5396. }
  5397. continue;
  5398. }
  5399. // The entry is meant for this configuration.
  5400. impl.Libraries.push_back(
  5401. cmLinkImplItem(name, this->FindTargetToLink(name),
  5402. *btIt, evaluated != *le));
  5403. }
  5404. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  5405. for (std::set<std::string>::const_iterator it = seenProps.begin();
  5406. it != seenProps.end(); ++it)
  5407. {
  5408. if (!this->GetProperty(*it))
  5409. {
  5410. this->LinkImplicitNullProperties.insert(*it);
  5411. }
  5412. }
  5413. cge->GetMaxLanguageStandard(this,
  5414. this->MaxLanguageStandards);
  5415. }
  5416. // Get the list of configurations considered to be DEBUG.
  5417. std::vector<std::string> debugConfigs =
  5418. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  5419. cmTargetLinkLibraryType linkType =
  5420. CMP0003_ComputeLinkType(config, debugConfigs);
  5421. cmTarget::LinkLibraryVectorType const& oldllibs =
  5422. this->Target->GetOriginalLinkLibraries();
  5423. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  5424. li != oldllibs.end(); ++li)
  5425. {
  5426. if(li->second != GENERAL_LibraryType && li->second != linkType)
  5427. {
  5428. std::string name = this->CheckCMP0004(li->first);
  5429. if(name == this->GetName() || name.empty())
  5430. {
  5431. continue;
  5432. }
  5433. // Support OLD behavior for CMP0003.
  5434. impl.WrongConfigLibraries.push_back(
  5435. cmLinkItem(name, this->FindTargetToLink(name)));
  5436. }
  5437. }
  5438. }
  5439. //----------------------------------------------------------------------------
  5440. cmGeneratorTarget*
  5441. cmGeneratorTarget::FindTargetToLink(std::string const& name) const
  5442. {
  5443. cmGeneratorTarget* tgt =
  5444. this->LocalGenerator->FindGeneratorTargetToUse(name);
  5445. // Skip targets that will not really be linked. This is probably a
  5446. // name conflict between an external library and an executable
  5447. // within the project.
  5448. if(tgt && tgt->GetType() == cmState::EXECUTABLE &&
  5449. !tgt->IsExecutableWithExports())
  5450. {
  5451. tgt = 0;
  5452. }
  5453. if(tgt && tgt->GetType() == cmState::OBJECT_LIBRARY)
  5454. {
  5455. std::ostringstream e;
  5456. e << "Target \"" << this->GetName() << "\" links to "
  5457. "OBJECT library \"" << tgt->GetName() << "\" but this is not "
  5458. "allowed. "
  5459. "One may link only to STATIC or SHARED libraries, or to executables "
  5460. "with the ENABLE_EXPORTS property set.";
  5461. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  5462. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  5463. this->GetBacktrace());
  5464. tgt = 0;
  5465. }
  5466. return tgt;
  5467. }
  5468. //----------------------------------------------------------------------------
  5469. std::string
  5470. cmGeneratorTarget::GetPDBDirectory(const std::string& config) const
  5471. {
  5472. if(OutputInfo const* info = this->GetOutputInfo(config))
  5473. {
  5474. // Return the directory in which the target will be built.
  5475. return info->PdbDir;
  5476. }
  5477. return "";
  5478. }
  5479. //----------------------------------------------------------------------------
  5480. bool cmGeneratorTarget::HasImplibGNUtoMS() const
  5481. {
  5482. return this->HasImportLibrary()
  5483. && this->GetPropertyAsBool("GNUtoMS");
  5484. }
  5485. //----------------------------------------------------------------------------
  5486. bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& gnuName,
  5487. std::string& out, const char* newExt) const
  5488. {
  5489. if(this->HasImplibGNUtoMS() &&
  5490. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  5491. {
  5492. out = gnuName.substr(0, gnuName.size()-6);
  5493. out += newExt? newExt : ".lib";
  5494. return true;
  5495. }
  5496. return false;
  5497. }
  5498. //----------------------------------------------------------------------------
  5499. bool cmGeneratorTarget::IsExecutableWithExports() const
  5500. {
  5501. return (this->GetType() == cmState::EXECUTABLE &&
  5502. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  5503. }
  5504. //----------------------------------------------------------------------------
  5505. bool cmGeneratorTarget::HasImportLibrary() const
  5506. {
  5507. return (this->IsDLLPlatform() &&
  5508. (this->GetType() == cmState::SHARED_LIBRARY ||
  5509. this->IsExecutableWithExports()));
  5510. }
  5511. //----------------------------------------------------------------------------
  5512. std::string cmGeneratorTarget::GetSupportDirectory() const
  5513. {
  5514. std::string dir = this->LocalGenerator->GetCurrentBinaryDirectory();
  5515. dir += cmake::GetCMakeFilesDirectory();
  5516. dir += "/";
  5517. dir += this->GetName();
  5518. #if defined(__VMS)
  5519. dir += "_dir";
  5520. #else
  5521. dir += ".dir";
  5522. #endif
  5523. return dir;
  5524. }
  5525. //----------------------------------------------------------------------------
  5526. bool cmGeneratorTarget::IsLinkable() const
  5527. {
  5528. return (this->GetType() == cmState::STATIC_LIBRARY ||
  5529. this->GetType() == cmState::SHARED_LIBRARY ||
  5530. this->GetType() == cmState::MODULE_LIBRARY ||
  5531. this->GetType() == cmState::UNKNOWN_LIBRARY ||
  5532. this->GetType() == cmState::INTERFACE_LIBRARY ||
  5533. this->IsExecutableWithExports());
  5534. }
  5535. //----------------------------------------------------------------------------
  5536. bool cmGeneratorTarget::IsFrameworkOnApple() const
  5537. {
  5538. return (this->GetType() == cmState::SHARED_LIBRARY &&
  5539. this->Makefile->IsOn("APPLE") &&
  5540. this->GetPropertyAsBool("FRAMEWORK"));
  5541. }
  5542. //----------------------------------------------------------------------------
  5543. bool cmGeneratorTarget::IsAppBundleOnApple() const
  5544. {
  5545. return (this->GetType() == cmState::EXECUTABLE &&
  5546. this->Makefile->IsOn("APPLE") &&
  5547. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  5548. }
  5549. //----------------------------------------------------------------------------
  5550. bool cmGeneratorTarget::IsXCTestOnApple() const
  5551. {
  5552. return (this->IsCFBundleOnApple() &&
  5553. this->GetPropertyAsBool("XCTEST"));
  5554. }
  5555. //----------------------------------------------------------------------------
  5556. bool cmGeneratorTarget::IsCFBundleOnApple() const
  5557. {
  5558. return (this->GetType() == cmState::MODULE_LIBRARY &&
  5559. this->Makefile->IsOn("APPLE") &&
  5560. this->GetPropertyAsBool("BUNDLE"));
  5561. }