cmTarget.cxx 221 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmTarget.h"
  11. #include "cmake.h"
  12. #include "cmMakefile.h"
  13. #include "cmSourceFile.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmComputeLinkInformation.h"
  17. #include "cmListFileCache.h"
  18. #include "cmGeneratorExpression.h"
  19. #include "cmGeneratorExpressionDAGChecker.h"
  20. #include <cmsys/RegularExpression.hxx>
  21. #include <map>
  22. #include <set>
  23. #include <stdlib.h> // required for atof
  24. #include <assert.h>
  25. #include <errno.h>
  26. const char* cmTarget::GetTargetTypeName(TargetType targetType)
  27. {
  28. switch( targetType )
  29. {
  30. case cmTarget::STATIC_LIBRARY:
  31. return "STATIC_LIBRARY";
  32. case cmTarget::MODULE_LIBRARY:
  33. return "MODULE_LIBRARY";
  34. case cmTarget::SHARED_LIBRARY:
  35. return "SHARED_LIBRARY";
  36. case cmTarget::OBJECT_LIBRARY:
  37. return "OBJECT_LIBRARY";
  38. case cmTarget::EXECUTABLE:
  39. return "EXECUTABLE";
  40. case cmTarget::UTILITY:
  41. return "UTILITY";
  42. case cmTarget::GLOBAL_TARGET:
  43. return "GLOBAL_TARGET";
  44. case cmTarget::INTERFACE_LIBRARY:
  45. return "INTERFACE_LIBRARY";
  46. case cmTarget::UNKNOWN_LIBRARY:
  47. return "UNKNOWN_LIBRARY";
  48. }
  49. assert(0 && "Unexpected target type");
  50. return 0;
  51. }
  52. //----------------------------------------------------------------------------
  53. struct cmTarget::OutputInfo
  54. {
  55. std::string OutDir;
  56. std::string ImpDir;
  57. std::string PdbDir;
  58. };
  59. //----------------------------------------------------------------------------
  60. struct cmTarget::ImportInfo
  61. {
  62. bool NoSOName;
  63. std::string Location;
  64. std::string SOName;
  65. std::string ImportLibrary;
  66. cmTarget::LinkInterface LinkInterface;
  67. };
  68. //----------------------------------------------------------------------------
  69. struct cmTarget::CompileInfo
  70. {
  71. std::string CompilePdbDir;
  72. };
  73. struct TargetConfigPair : public std::pair<cmTarget const* , std::string> {
  74. TargetConfigPair(cmTarget const* tgt, const std::string &config)
  75. : std::pair<cmTarget const* , std::string>(tgt, config) {}
  76. };
  77. //----------------------------------------------------------------------------
  78. class cmTargetInternals
  79. {
  80. public:
  81. cmTargetInternals()
  82. {
  83. this->PolicyWarnedCMP0022 = false;
  84. }
  85. cmTargetInternals(cmTargetInternals const&)
  86. {
  87. this->PolicyWarnedCMP0022 = false;
  88. }
  89. ~cmTargetInternals();
  90. // The backtrace when the target was created.
  91. cmListFileBacktrace Backtrace;
  92. // Cache link interface computation from each configuration.
  93. struct OptionalLinkInterface: public cmTarget::LinkInterface
  94. {
  95. OptionalLinkInterface():
  96. Exists(false), Complete(false), ExplicitLibraries(0) {}
  97. bool Exists;
  98. bool Complete;
  99. const char* ExplicitLibraries;
  100. };
  101. void ComputeLinkInterface(cmTarget const* thisTarget,
  102. const std::string& config,
  103. OptionalLinkInterface& iface,
  104. cmTarget const* head,
  105. const char *explicitLibraries) const;
  106. typedef std::map<TargetConfigPair, OptionalLinkInterface>
  107. LinkInterfaceMapType;
  108. LinkInterfaceMapType LinkInterfaceMap;
  109. bool PolicyWarnedCMP0022;
  110. typedef std::map<std::string, cmTarget::OutputInfo> OutputInfoMapType;
  111. OutputInfoMapType OutputInfoMap;
  112. typedef std::map<TargetConfigPair, cmTarget::ImportInfo>
  113. ImportInfoMapType;
  114. ImportInfoMapType ImportInfoMap;
  115. typedef std::map<std::string, cmTarget::CompileInfo> CompileInfoMapType;
  116. CompileInfoMapType CompileInfoMap;
  117. // Cache link implementation computation from each configuration.
  118. typedef std::map<TargetConfigPair,
  119. cmTarget::LinkImplementation> LinkImplMapType;
  120. LinkImplMapType LinkImplMap;
  121. typedef std::map<TargetConfigPair, cmTarget::LinkClosure>
  122. LinkClosureMapType;
  123. LinkClosureMapType LinkClosureMap;
  124. struct TargetPropertyEntry {
  125. TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
  126. const std::string &targetName = std::string())
  127. : ge(cge), TargetName(targetName)
  128. {}
  129. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  130. std::vector<std::string> CachedEntries;
  131. const std::string TargetName;
  132. };
  133. std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
  134. std::vector<TargetPropertyEntry*> CompileOptionsEntries;
  135. std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
  136. std::vector<TargetPropertyEntry*> SourceEntries;
  137. std::vector<cmValueWithOrigin> LinkImplementationPropertyEntries;
  138. mutable std::map<std::string, std::vector<TargetPropertyEntry*> >
  139. CachedLinkInterfaceIncludeDirectoriesEntries;
  140. mutable std::map<std::string, std::vector<TargetPropertyEntry*> >
  141. CachedLinkInterfaceCompileOptionsEntries;
  142. mutable std::map<std::string, std::vector<TargetPropertyEntry*> >
  143. CachedLinkInterfaceCompileDefinitionsEntries;
  144. mutable std::map<std::string, std::vector<TargetPropertyEntry*> >
  145. CachedLinkInterfaceSourcesEntries;
  146. mutable std::map<std::string, bool> CacheLinkInterfaceIncludeDirectoriesDone;
  147. mutable std::map<std::string, bool> CacheLinkInterfaceCompileDefinitionsDone;
  148. mutable std::map<std::string, bool> CacheLinkInterfaceCompileOptionsDone;
  149. mutable std::map<std::string, bool> CacheLinkInterfaceSourcesDone;
  150. };
  151. //----------------------------------------------------------------------------
  152. void deleteAndClear(
  153. std::vector<cmTargetInternals::TargetPropertyEntry*> &entries)
  154. {
  155. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  156. it = entries.begin(),
  157. end = entries.end();
  158. it != end; ++it)
  159. {
  160. delete *it;
  161. }
  162. entries.clear();
  163. }
  164. //----------------------------------------------------------------------------
  165. void deleteAndClear(
  166. std::map<std::string,
  167. std::vector<cmTargetInternals::TargetPropertyEntry*> > &entries)
  168. {
  169. for (std::map<std::string,
  170. std::vector<cmTargetInternals::TargetPropertyEntry*> >::iterator
  171. it = entries.begin(), end = entries.end(); it != end; ++it)
  172. {
  173. deleteAndClear(it->second);
  174. }
  175. }
  176. //----------------------------------------------------------------------------
  177. cmTargetInternals::~cmTargetInternals()
  178. {
  179. deleteAndClear(this->CachedLinkInterfaceIncludeDirectoriesEntries);
  180. deleteAndClear(this->CachedLinkInterfaceCompileOptionsEntries);
  181. deleteAndClear(this->CachedLinkInterfaceCompileDefinitionsEntries);
  182. deleteAndClear(this->CachedLinkInterfaceSourcesEntries);
  183. }
  184. //----------------------------------------------------------------------------
  185. cmTarget::cmTarget()
  186. {
  187. #define INITIALIZE_TARGET_POLICY_MEMBER(POLICY) \
  188. this->PolicyStatus ## POLICY = cmPolicies::WARN;
  189. CM_FOR_EACH_TARGET_POLICY(INITIALIZE_TARGET_POLICY_MEMBER)
  190. #undef INITIALIZE_TARGET_POLICY_MEMBER
  191. this->Makefile = 0;
  192. this->LinkLibrariesAnalyzed = false;
  193. this->HaveInstallRule = false;
  194. this->DLLPlatform = false;
  195. this->IsApple = false;
  196. this->IsImportedTarget = false;
  197. this->BuildInterfaceIncludesAppended = false;
  198. this->DebugIncludesDone = false;
  199. this->DebugCompileOptionsDone = false;
  200. this->DebugCompileDefinitionsDone = false;
  201. this->DebugSourcesDone = false;
  202. }
  203. //----------------------------------------------------------------------------
  204. void cmTarget::DefineProperties(cmake *cm)
  205. {
  206. cm->DefineProperty
  207. ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
  208. "", "", true);
  209. cm->DefineProperty
  210. ("RULE_LAUNCH_LINK", cmProperty::TARGET,
  211. "", "", true);
  212. cm->DefineProperty
  213. ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
  214. "", "", true);
  215. }
  216. void cmTarget::SetType(TargetType type, const std::string& name)
  217. {
  218. this->Name = name;
  219. // only add dependency information for library targets
  220. this->TargetTypeValue = type;
  221. if(this->TargetTypeValue >= STATIC_LIBRARY
  222. && this->TargetTypeValue <= MODULE_LIBRARY)
  223. {
  224. this->RecordDependencies = true;
  225. }
  226. else
  227. {
  228. this->RecordDependencies = false;
  229. }
  230. }
  231. //----------------------------------------------------------------------------
  232. void cmTarget::SetMakefile(cmMakefile* mf)
  233. {
  234. // Set our makefile.
  235. this->Makefile = mf;
  236. // set the cmake instance of the properties
  237. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  238. // Check whether this is a DLL platform.
  239. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  240. this->Makefile->IsOn("CYGWIN") ||
  241. this->Makefile->IsOn("MINGW"));
  242. // Check whether we are targeting an Apple platform.
  243. this->IsApple = this->Makefile->IsOn("APPLE");
  244. // Setup default property values.
  245. if (this->GetType() != INTERFACE_LIBRARY)
  246. {
  247. this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
  248. this->SetPropertyDefault("INSTALL_RPATH", "");
  249. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  250. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  251. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  252. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  253. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  254. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  255. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
  256. this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", 0);
  257. this->SetPropertyDefault("Fortran_FORMAT", 0);
  258. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  259. this->SetPropertyDefault("GNUtoMS", 0);
  260. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  261. this->SetPropertyDefault("AUTOMOC", 0);
  262. this->SetPropertyDefault("AUTOUIC", 0);
  263. this->SetPropertyDefault("AUTORCC", 0);
  264. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  265. this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
  266. this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
  267. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
  268. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  269. this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
  270. this->SetPropertyDefault("MACOSX_BUNDLE", 0);
  271. this->SetPropertyDefault("MACOSX_RPATH", 0);
  272. this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
  273. }
  274. // Collect the set of configuration types.
  275. std::vector<std::string> configNames;
  276. mf->GetConfigurations(configNames);
  277. // Setup per-configuration property default values.
  278. const char* configProps[] = {
  279. "ARCHIVE_OUTPUT_DIRECTORY_",
  280. "LIBRARY_OUTPUT_DIRECTORY_",
  281. "RUNTIME_OUTPUT_DIRECTORY_",
  282. "PDB_OUTPUT_DIRECTORY_",
  283. "COMPILE_PDB_OUTPUT_DIRECTORY_",
  284. "MAP_IMPORTED_CONFIG_",
  285. 0};
  286. for(std::vector<std::string>::iterator ci = configNames.begin();
  287. ci != configNames.end(); ++ci)
  288. {
  289. std::string configUpper = cmSystemTools::UpperCase(*ci);
  290. for(const char** p = configProps; *p; ++p)
  291. {
  292. if (this->TargetTypeValue == INTERFACE_LIBRARY
  293. && strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0)
  294. {
  295. continue;
  296. }
  297. std::string property = *p;
  298. property += configUpper;
  299. this->SetPropertyDefault(property, 0);
  300. }
  301. // Initialize per-configuration name postfix property from the
  302. // variable only for non-executable targets. This preserves
  303. // compatibility with previous CMake versions in which executables
  304. // did not support this variable. Projects may still specify the
  305. // property directly.
  306. if(this->TargetTypeValue != cmTarget::EXECUTABLE
  307. && this->TargetTypeValue != cmTarget::INTERFACE_LIBRARY)
  308. {
  309. std::string property = cmSystemTools::UpperCase(*ci);
  310. property += "_POSTFIX";
  311. this->SetPropertyDefault(property, 0);
  312. }
  313. }
  314. // Save the backtrace of target construction.
  315. this->Makefile->GetBacktrace(this->Internal->Backtrace);
  316. if (!this->IsImported())
  317. {
  318. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  319. // of the same directory property:
  320. const std::vector<cmValueWithOrigin> parentIncludes =
  321. this->Makefile->GetIncludeDirectoriesEntries();
  322. for (std::vector<cmValueWithOrigin>::const_iterator it
  323. = parentIncludes.begin(); it != parentIncludes.end(); ++it)
  324. {
  325. this->InsertInclude(*it);
  326. }
  327. const std::set<std::string> parentSystemIncludes =
  328. this->Makefile->GetSystemIncludeDirectories();
  329. for (std::set<std::string>::const_iterator it
  330. = parentSystemIncludes.begin();
  331. it != parentSystemIncludes.end(); ++it)
  332. {
  333. this->SystemIncludeDirectories.insert(*it);
  334. }
  335. const std::vector<cmValueWithOrigin> parentOptions =
  336. this->Makefile->GetCompileOptionsEntries();
  337. for (std::vector<cmValueWithOrigin>::const_iterator it
  338. = parentOptions.begin(); it != parentOptions.end(); ++it)
  339. {
  340. this->InsertCompileOption(*it);
  341. }
  342. }
  343. if (this->GetType() != INTERFACE_LIBRARY)
  344. {
  345. this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
  346. this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
  347. this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
  348. }
  349. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
  350. || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
  351. {
  352. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  353. }
  354. if (this->GetType() != INTERFACE_LIBRARY)
  355. {
  356. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
  357. }
  358. // Record current policies for later use.
  359. #define CAPTURE_TARGET_POLICY(POLICY) \
  360. this->PolicyStatus ## POLICY = \
  361. this->Makefile->GetPolicyStatus(cmPolicies::POLICY);
  362. CM_FOR_EACH_TARGET_POLICY(CAPTURE_TARGET_POLICY)
  363. #undef CAPTURE_TARGET_POLICY
  364. if (this->TargetTypeValue == INTERFACE_LIBRARY)
  365. {
  366. // This policy is checked in a few conditions. The properties relevant
  367. // to the policy are always ignored for INTERFACE_LIBRARY targets,
  368. // so ensure that the conditions don't lead to nonsense.
  369. this->PolicyStatusCMP0022 = cmPolicies::NEW;
  370. }
  371. this->SetPropertyDefault("JOB_POOL_COMPILE", 0);
  372. this->SetPropertyDefault("JOB_POOL_LINK", 0);
  373. }
  374. //----------------------------------------------------------------------------
  375. void cmTarget::AddUtility(const std::string& u, cmMakefile *makefile)
  376. {
  377. if(this->Utilities.insert(u).second && makefile)
  378. {
  379. makefile->GetBacktrace(UtilityBacktraces[u]);
  380. }
  381. }
  382. //----------------------------------------------------------------------------
  383. cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
  384. const std::string& u) const
  385. {
  386. std::map<std::string, cmListFileBacktrace>::const_iterator i =
  387. this->UtilityBacktraces.find(u);
  388. if(i == this->UtilityBacktraces.end()) return 0;
  389. return &i->second;
  390. }
  391. //----------------------------------------------------------------------------
  392. void cmTarget::FinishConfigure()
  393. {
  394. // Erase any cached link information that might have been comptued
  395. // on-demand during the configuration. This ensures that build
  396. // system generation uses up-to-date information even if other cache
  397. // invalidation code in this source file is buggy.
  398. this->ClearLinkMaps();
  399. // Do old-style link dependency analysis.
  400. this->AnalyzeLibDependencies(*this->Makefile);
  401. }
  402. //----------------------------------------------------------------------------
  403. void cmTarget::ClearLinkMaps()
  404. {
  405. this->Internal->LinkImplMap.clear();
  406. this->Internal->LinkInterfaceMap.clear();
  407. this->Internal->LinkClosureMap.clear();
  408. for (cmTargetLinkInformationMap::const_iterator it
  409. = this->LinkInformation.begin();
  410. it != this->LinkInformation.end(); ++it)
  411. {
  412. delete it->second;
  413. }
  414. this->LinkInformation.clear();
  415. }
  416. //----------------------------------------------------------------------------
  417. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  418. {
  419. return this->Internal->Backtrace;
  420. }
  421. //----------------------------------------------------------------------------
  422. std::string cmTarget::GetSupportDirectory() const
  423. {
  424. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  425. dir += cmake::GetCMakeFilesDirectory();
  426. dir += "/";
  427. dir += this->Name;
  428. #if defined(__VMS)
  429. dir += "_dir";
  430. #else
  431. dir += ".dir";
  432. #endif
  433. return dir;
  434. }
  435. //----------------------------------------------------------------------------
  436. bool cmTarget::IsExecutableWithExports() const
  437. {
  438. return (this->GetType() == cmTarget::EXECUTABLE &&
  439. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  440. }
  441. //----------------------------------------------------------------------------
  442. bool cmTarget::IsLinkable() const
  443. {
  444. return (this->GetType() == cmTarget::STATIC_LIBRARY ||
  445. this->GetType() == cmTarget::SHARED_LIBRARY ||
  446. this->GetType() == cmTarget::MODULE_LIBRARY ||
  447. this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
  448. this->GetType() == cmTarget::INTERFACE_LIBRARY ||
  449. this->IsExecutableWithExports());
  450. }
  451. //----------------------------------------------------------------------------
  452. bool cmTarget::HasImportLibrary() const
  453. {
  454. return (this->DLLPlatform &&
  455. (this->GetType() == cmTarget::SHARED_LIBRARY ||
  456. this->IsExecutableWithExports()));
  457. }
  458. //----------------------------------------------------------------------------
  459. bool cmTarget::IsFrameworkOnApple() const
  460. {
  461. return (this->GetType() == cmTarget::SHARED_LIBRARY &&
  462. this->Makefile->IsOn("APPLE") &&
  463. this->GetPropertyAsBool("FRAMEWORK"));
  464. }
  465. //----------------------------------------------------------------------------
  466. bool cmTarget::IsAppBundleOnApple() const
  467. {
  468. return (this->GetType() == cmTarget::EXECUTABLE &&
  469. this->Makefile->IsOn("APPLE") &&
  470. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  471. }
  472. //----------------------------------------------------------------------------
  473. bool cmTarget::IsCFBundleOnApple() const
  474. {
  475. return (this->GetType() == cmTarget::MODULE_LIBRARY &&
  476. this->Makefile->IsOn("APPLE") &&
  477. this->GetPropertyAsBool("BUNDLE"));
  478. }
  479. //----------------------------------------------------------------------------
  480. bool cmTarget::IsBundleOnApple() const
  481. {
  482. return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
  483. this->IsCFBundleOnApple();
  484. }
  485. //----------------------------------------------------------------------------
  486. static void processSources(cmTarget const* tgt,
  487. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  488. std::vector<std::string> &srcs,
  489. std::set<std::string> &uniqueSrcs,
  490. cmGeneratorExpressionDAGChecker *dagChecker,
  491. cmTarget const* head,
  492. std::string const& config, bool debugSources)
  493. {
  494. cmMakefile *mf = tgt->GetMakefile();
  495. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  496. it = entries.begin(), end = entries.end(); it != end; ++it)
  497. {
  498. bool cacheSources = false;
  499. std::vector<std::string> entrySources = (*it)->CachedEntries;
  500. if(entrySources.empty())
  501. {
  502. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  503. config,
  504. false,
  505. head ? head : tgt,
  506. tgt,
  507. dagChecker),
  508. entrySources);
  509. if (mf->IsGeneratingBuildSystem()
  510. && !(*it)->ge->GetHadContextSensitiveCondition())
  511. {
  512. cacheSources = true;
  513. }
  514. for(std::vector<std::string>::iterator i = entrySources.begin();
  515. i != entrySources.end(); ++i)
  516. {
  517. std::string& src = *i;
  518. cmSourceFile* sf = mf->GetOrCreateSource(src);
  519. std::string e;
  520. src = sf->GetFullPath(&e);
  521. if(src.empty())
  522. {
  523. if(!e.empty())
  524. {
  525. cmake* cm = mf->GetCMakeInstance();
  526. cm->IssueMessage(cmake::FATAL_ERROR, e,
  527. tgt->GetBacktrace());
  528. }
  529. return;
  530. }
  531. }
  532. if (cacheSources)
  533. {
  534. (*it)->CachedEntries = entrySources;
  535. }
  536. }
  537. std::string usedSources;
  538. for(std::vector<std::string>::iterator
  539. li = entrySources.begin(); li != entrySources.end(); ++li)
  540. {
  541. std::string src = *li;
  542. if(uniqueSrcs.insert(src).second)
  543. {
  544. srcs.push_back(src);
  545. if (debugSources)
  546. {
  547. usedSources += " * " + src + "\n";
  548. }
  549. }
  550. }
  551. if (!usedSources.empty())
  552. {
  553. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  554. std::string("Used sources for target ")
  555. + tgt->GetName() + ":\n"
  556. + usedSources, (*it)->ge->GetBacktrace());
  557. }
  558. }
  559. }
  560. //----------------------------------------------------------------------------
  561. void cmTarget::GetSourceFiles(std::vector<std::string> &files,
  562. const std::string& config,
  563. cmTarget const* head) const
  564. {
  565. assert(this->GetType() != INTERFACE_LIBRARY);
  566. std::vector<std::string> debugProperties;
  567. const char *debugProp =
  568. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  569. if (debugProp)
  570. {
  571. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  572. }
  573. bool debugSources = !this->DebugSourcesDone
  574. && std::find(debugProperties.begin(),
  575. debugProperties.end(),
  576. "SOURCES")
  577. != debugProperties.end();
  578. if (this->Makefile->IsGeneratingBuildSystem())
  579. {
  580. this->DebugSourcesDone = true;
  581. }
  582. cmListFileBacktrace lfbt;
  583. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  584. this->GetName(),
  585. "SOURCES", 0, 0);
  586. std::set<std::string> uniqueSrcs;
  587. processSources(this,
  588. this->Internal->SourceEntries,
  589. files,
  590. uniqueSrcs,
  591. &dagChecker,
  592. head,
  593. config,
  594. debugSources);
  595. if (!this->Internal->CacheLinkInterfaceSourcesDone[config])
  596. {
  597. for (std::vector<cmValueWithOrigin>::const_iterator
  598. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  599. end = this->Internal->LinkImplementationPropertyEntries.end();
  600. it != end; ++it)
  601. {
  602. if (!cmGeneratorExpression::IsValidTargetName(it->Value)
  603. && cmGeneratorExpression::Find(it->Value) == std::string::npos)
  604. {
  605. continue;
  606. }
  607. {
  608. cmGeneratorExpression ge(lfbt);
  609. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  610. ge.Parse(it->Value);
  611. std::string targetResult = cge->Evaluate(this->Makefile, config,
  612. false, this, 0, &dagChecker);
  613. if (!this->Makefile->FindTargetToUse(targetResult))
  614. {
  615. continue;
  616. }
  617. }
  618. std::string sourceGenex = "$<TARGET_PROPERTY:" +
  619. it->Value + ",INTERFACE_SOURCES>";
  620. if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
  621. {
  622. // Because it->Value is a generator expression, ensure that it
  623. // evaluates to the non-empty string before being used in the
  624. // TARGET_PROPERTY expression.
  625. sourceGenex = "$<$<BOOL:" + it->Value + ">:" + sourceGenex + ">";
  626. }
  627. cmGeneratorExpression ge(it->Backtrace);
  628. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
  629. sourceGenex);
  630. this->Internal
  631. ->CachedLinkInterfaceSourcesEntries[config].push_back(
  632. new cmTargetInternals::TargetPropertyEntry(cge,
  633. it->Value));
  634. }
  635. }
  636. processSources(this,
  637. this->Internal->CachedLinkInterfaceSourcesEntries[config],
  638. files,
  639. uniqueSrcs,
  640. &dagChecker,
  641. head,
  642. config,
  643. debugSources);
  644. if (!this->Makefile->IsGeneratingBuildSystem())
  645. {
  646. deleteAndClear(this->Internal->CachedLinkInterfaceSourcesEntries);
  647. }
  648. else
  649. {
  650. this->Internal->CacheLinkInterfaceSourcesDone[config] = true;
  651. }
  652. }
  653. //----------------------------------------------------------------------------
  654. bool
  655. cmTarget::GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const
  656. {
  657. std::vector<std::string> configs;
  658. this->Makefile->GetConfigurations(configs);
  659. if (configs.empty())
  660. {
  661. configs.push_back("");
  662. }
  663. std::vector<std::string>::const_iterator it = configs.begin();
  664. const std::string& firstConfig = *it;
  665. this->GetSourceFiles(files, firstConfig);
  666. for ( ; it != configs.end(); ++it)
  667. {
  668. std::vector<cmSourceFile*> configFiles;
  669. this->GetSourceFiles(configFiles, *it);
  670. if (configFiles != files)
  671. {
  672. std::string firstConfigFiles;
  673. const char* sep = "";
  674. for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
  675. fi != files.end(); ++fi)
  676. {
  677. firstConfigFiles += sep;
  678. firstConfigFiles += (*fi)->GetFullPath();
  679. sep = "\n ";
  680. }
  681. std::string thisConfigFiles;
  682. sep = "";
  683. for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
  684. fi != configFiles.end(); ++fi)
  685. {
  686. thisConfigFiles += sep;
  687. thisConfigFiles += (*fi)->GetFullPath();
  688. sep = "\n ";
  689. }
  690. cmOStringStream e;
  691. e << "Target \"" << this->Name << "\" has source files which vary by "
  692. "configuration. This is not supported by the \""
  693. << this->Makefile->GetLocalGenerator()
  694. ->GetGlobalGenerator()->GetName()
  695. << "\" generator.\n"
  696. "Config \"" << firstConfig << "\":\n"
  697. " " << firstConfigFiles << "\n"
  698. "Config \"" << *it << "\":\n"
  699. " " << thisConfigFiles << "\n";
  700. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  701. return false;
  702. }
  703. }
  704. return true;
  705. }
  706. //----------------------------------------------------------------------------
  707. void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  708. const std::string& config,
  709. cmTarget const* head) const
  710. {
  711. std::vector<std::string> srcs;
  712. this->GetSourceFiles(srcs, config, head);
  713. std::set<cmSourceFile*> emitted;
  714. for(std::vector<std::string>::const_iterator i = srcs.begin();
  715. i != srcs.end(); ++i)
  716. {
  717. cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
  718. if (emitted.insert(sf).second)
  719. {
  720. files.push_back(sf);
  721. }
  722. }
  723. }
  724. //----------------------------------------------------------------------------
  725. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  726. {
  727. std::string srcFiles;
  728. const char* sep = "";
  729. for(std::vector<std::string>::const_iterator i = srcs.begin();
  730. i != srcs.end(); ++i)
  731. {
  732. std::string filename = *i;
  733. const char* src = filename.c_str();
  734. if(!(src[0] == '$' && src[1] == '<'))
  735. {
  736. filename = this->ProcessSourceItemCMP0049(filename);
  737. if (cmSystemTools::GetErrorOccuredFlag())
  738. {
  739. return;
  740. }
  741. this->Makefile->GetOrCreateSource(filename);
  742. }
  743. srcFiles += sep;
  744. srcFiles += filename;
  745. sep = ";";
  746. }
  747. if (!srcFiles.empty())
  748. {
  749. cmListFileBacktrace lfbt;
  750. this->Makefile->GetBacktrace(lfbt);
  751. cmGeneratorExpression ge(lfbt);
  752. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  753. cge->SetEvaluateForBuildsystem(true);
  754. this->Internal->SourceEntries.push_back(
  755. new cmTargetInternals::TargetPropertyEntry(cge));
  756. }
  757. }
  758. //----------------------------------------------------------------------------
  759. std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
  760. {
  761. std::string src = s;
  762. // For backwards compatibility replace varibles in source names.
  763. // This should eventually be removed.
  764. this->Makefile->ExpandVariablesInString(src);
  765. if (src != s)
  766. {
  767. cmOStringStream e;
  768. bool noMessage = false;
  769. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  770. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0049))
  771. {
  772. case cmPolicies::WARN:
  773. e << (this->Makefile->GetPolicies()
  774. ->GetPolicyWarning(cmPolicies::CMP0049)) << "\n";
  775. break;
  776. case cmPolicies::OLD:
  777. noMessage = true;
  778. break;
  779. case cmPolicies::REQUIRED_ALWAYS:
  780. case cmPolicies::REQUIRED_IF_USED:
  781. case cmPolicies::NEW:
  782. messageType = cmake::FATAL_ERROR;
  783. }
  784. if (!noMessage)
  785. {
  786. e << "Legacy variable expansion in source file \""
  787. << s << "\" expanded to \"" << src << "\" in target \""
  788. << this->GetName() << "\". This behavior will be removed in a "
  789. "future version of CMake.";
  790. this->Makefile->IssueMessage(messageType, e.str());
  791. if (messageType == cmake::FATAL_ERROR)
  792. {
  793. return "";
  794. }
  795. }
  796. }
  797. return src;
  798. }
  799. //----------------------------------------------------------------------------
  800. cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
  801. {
  802. std::string src = this->ProcessSourceItemCMP0049(s);
  803. if (cmSystemTools::GetErrorOccuredFlag())
  804. {
  805. return 0;
  806. }
  807. return this->AddSource(src);
  808. }
  809. //----------------------------------------------------------------------------
  810. struct CreateLocation
  811. {
  812. cmMakefile const* Makefile;
  813. CreateLocation(cmMakefile const* mf)
  814. : Makefile(mf)
  815. {
  816. }
  817. cmSourceFileLocation operator()(const std::string& filename)
  818. {
  819. return cmSourceFileLocation(this->Makefile, filename);
  820. }
  821. };
  822. //----------------------------------------------------------------------------
  823. struct LocationMatcher
  824. {
  825. const cmSourceFileLocation& Needle;
  826. LocationMatcher(const cmSourceFileLocation& needle)
  827. : Needle(needle)
  828. {
  829. }
  830. bool operator()(cmSourceFileLocation &loc)
  831. {
  832. return loc.Matches(this->Needle);
  833. }
  834. };
  835. //----------------------------------------------------------------------------
  836. struct TargetPropertyEntryFinder
  837. {
  838. private:
  839. const cmSourceFileLocation& Needle;
  840. public:
  841. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  842. : Needle(needle)
  843. {
  844. }
  845. bool operator()(cmTargetInternals::TargetPropertyEntry* entry)
  846. {
  847. std::vector<std::string> files;
  848. cmSystemTools::ExpandListArgument(entry->ge->GetInput(), files);
  849. std::vector<cmSourceFileLocation> locations(files.size());
  850. std::transform(files.begin(), files.end(), locations.begin(),
  851. CreateLocation(this->Needle.GetMakefile()));
  852. return std::find_if(locations.begin(), locations.end(),
  853. LocationMatcher(this->Needle)) != locations.end();
  854. }
  855. };
  856. //----------------------------------------------------------------------------
  857. cmSourceFile* cmTarget::AddSource(const std::string& src)
  858. {
  859. cmSourceFileLocation sfl(this->Makefile, src);
  860. if (std::find_if(this->Internal->SourceEntries.begin(),
  861. this->Internal->SourceEntries.end(),
  862. TargetPropertyEntryFinder(sfl))
  863. == this->Internal->SourceEntries.end())
  864. {
  865. cmListFileBacktrace lfbt;
  866. this->Makefile->GetBacktrace(lfbt);
  867. cmGeneratorExpression ge(lfbt);
  868. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  869. cge->SetEvaluateForBuildsystem(true);
  870. this->Internal->SourceEntries.push_back(
  871. new cmTargetInternals::TargetPropertyEntry(cge));
  872. }
  873. if (cmGeneratorExpression::Find(src) != std::string::npos)
  874. {
  875. return 0;
  876. }
  877. return this->Makefile->GetOrCreateSource(src);
  878. }
  879. //----------------------------------------------------------------------------
  880. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  881. const std::string& selfname,
  882. const LinkLibraryVectorType& libs )
  883. {
  884. // Only add on libraries we haven't added on before.
  885. // Assumption: the global link libraries could only grow, never shrink
  886. LinkLibraryVectorType::const_iterator i = libs.begin();
  887. i += this->PrevLinkedLibraries.size();
  888. for( ; i != libs.end(); ++i )
  889. {
  890. // This is equivalent to the target_link_libraries plain signature.
  891. this->AddLinkLibrary( mf, selfname, i->first, i->second );
  892. this->AppendProperty("INTERFACE_LINK_LIBRARIES",
  893. this->GetDebugGeneratorExpressions(i->first, i->second).c_str());
  894. }
  895. this->PrevLinkedLibraries = libs;
  896. }
  897. //----------------------------------------------------------------------------
  898. void cmTarget::AddLinkDirectory(const std::string& d)
  899. {
  900. // Make sure we don't add unnecessary search directories.
  901. if(this->LinkDirectoriesEmmitted.insert(d).second)
  902. {
  903. this->LinkDirectories.push_back(d);
  904. }
  905. }
  906. //----------------------------------------------------------------------------
  907. const std::vector<std::string>& cmTarget::GetLinkDirectories() const
  908. {
  909. return this->LinkDirectories;
  910. }
  911. //----------------------------------------------------------------------------
  912. cmTarget::LinkLibraryType cmTarget::ComputeLinkType(
  913. const std::string& config) const
  914. {
  915. // No configuration is always optimized.
  916. if(config.empty())
  917. {
  918. return cmTarget::OPTIMIZED;
  919. }
  920. // Get the list of configurations considered to be DEBUG.
  921. std::vector<std::string> const& debugConfigs =
  922. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  923. // Check if any entry in the list matches this configuration.
  924. std::string configUpper = cmSystemTools::UpperCase(config);
  925. for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
  926. i != debugConfigs.end(); ++i)
  927. {
  928. if(*i == configUpper)
  929. {
  930. return cmTarget::DEBUG;
  931. }
  932. }
  933. // The current configuration is not a debug configuration.
  934. return cmTarget::OPTIMIZED;
  935. }
  936. //----------------------------------------------------------------------------
  937. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  938. const std::string& target )
  939. {
  940. // Clear the dependencies. The cache variable must exist iff we are
  941. // recording dependency information for this target.
  942. std::string depname = target;
  943. depname += "_LIB_DEPENDS";
  944. if (this->RecordDependencies)
  945. {
  946. mf.AddCacheDefinition(depname, "",
  947. "Dependencies for target", cmCacheManager::STATIC);
  948. }
  949. else
  950. {
  951. if (mf.GetDefinition( depname ))
  952. {
  953. std::string message = "Target ";
  954. message += target;
  955. message += " has dependency information when it shouldn't.\n";
  956. message += "Your cache is probably stale. Please remove the entry\n ";
  957. message += depname;
  958. message += "\nfrom the cache.";
  959. cmSystemTools::Error( message.c_str() );
  960. }
  961. }
  962. }
  963. //----------------------------------------------------------------------------
  964. bool cmTarget::NameResolvesToFramework(const std::string& libname) const
  965. {
  966. return this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  967. NameResolvesToFramework(libname);
  968. }
  969. //----------------------------------------------------------------------------
  970. void cmTarget::GetDirectLinkLibraries(const std::string& config,
  971. std::vector<std::string> &libs,
  972. cmTarget const* head) const
  973. {
  974. const char *prop = this->GetProperty("LINK_LIBRARIES");
  975. if (prop)
  976. {
  977. cmListFileBacktrace lfbt;
  978. cmGeneratorExpression ge(lfbt);
  979. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  980. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  981. this->GetName(),
  982. "LINK_LIBRARIES", 0, 0);
  983. cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile,
  984. config,
  985. false,
  986. head,
  987. &dagChecker),
  988. libs);
  989. std::set<std::string> seenProps = cge->GetSeenTargetProperties();
  990. for (std::set<std::string>::const_iterator it = seenProps.begin();
  991. it != seenProps.end(); ++it)
  992. {
  993. if (!this->GetProperty(*it))
  994. {
  995. this->LinkImplicitNullProperties.insert(*it);
  996. }
  997. }
  998. }
  999. }
  1000. //----------------------------------------------------------------------------
  1001. void cmTarget::GetInterfaceLinkLibraries(const std::string& config,
  1002. std::vector<std::string> &libs,
  1003. cmTarget const* head) const
  1004. {
  1005. const char *prop = this->GetProperty("INTERFACE_LINK_LIBRARIES");
  1006. if (prop)
  1007. {
  1008. cmListFileBacktrace lfbt;
  1009. cmGeneratorExpression ge(lfbt);
  1010. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  1011. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  1012. this->GetName(),
  1013. "INTERFACE_LINK_LIBRARIES", 0, 0);
  1014. cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile,
  1015. config,
  1016. false,
  1017. head,
  1018. &dagChecker),
  1019. libs);
  1020. }
  1021. }
  1022. //----------------------------------------------------------------------------
  1023. std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
  1024. cmTarget::LinkLibraryType llt) const
  1025. {
  1026. if (llt == GENERAL)
  1027. {
  1028. return value;
  1029. }
  1030. // Get the list of configurations considered to be DEBUG.
  1031. std::vector<std::string> const& debugConfigs =
  1032. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1033. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  1034. if (debugConfigs.size() > 1)
  1035. {
  1036. for(std::vector<std::string>::const_iterator
  1037. li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
  1038. {
  1039. configString += ",$<CONFIG:" + *li + ">";
  1040. }
  1041. configString = "$<OR:" + configString + ">";
  1042. }
  1043. if (llt == OPTIMIZED)
  1044. {
  1045. configString = "$<NOT:" + configString + ">";
  1046. }
  1047. return "$<" + configString + ":" + value + ">";
  1048. }
  1049. //----------------------------------------------------------------------------
  1050. static std::string targetNameGenex(const std::string& lib)
  1051. {
  1052. return "$<TARGET_NAME:" + lib + ">";
  1053. }
  1054. //----------------------------------------------------------------------------
  1055. bool cmTarget::PushTLLCommandTrace(TLLSignature signature)
  1056. {
  1057. bool ret = true;
  1058. if (!this->TLLCommands.empty())
  1059. {
  1060. if (this->TLLCommands.back().first != signature)
  1061. {
  1062. ret = false;
  1063. }
  1064. }
  1065. cmListFileBacktrace lfbt;
  1066. this->Makefile->GetBacktrace(lfbt);
  1067. this->TLLCommands.push_back(std::make_pair(signature, lfbt));
  1068. return ret;
  1069. }
  1070. //----------------------------------------------------------------------------
  1071. void cmTarget::GetTllSignatureTraces(cmOStringStream &s,
  1072. TLLSignature sig) const
  1073. {
  1074. std::vector<cmListFileBacktrace> sigs;
  1075. typedef std::vector<std::pair<TLLSignature, cmListFileBacktrace> > Container;
  1076. for(Container::const_iterator it = this->TLLCommands.begin();
  1077. it != this->TLLCommands.end(); ++it)
  1078. {
  1079. if (it->first == sig)
  1080. {
  1081. sigs.push_back(it->second);
  1082. }
  1083. }
  1084. if (!sigs.empty())
  1085. {
  1086. const char *sigString
  1087. = (sig == cmTarget::KeywordTLLSignature ? "keyword"
  1088. : "plain");
  1089. s << "The uses of the " << sigString << " signature are here:\n";
  1090. std::set<std::string> emitted;
  1091. for(std::vector<cmListFileBacktrace>::const_iterator it = sigs.begin();
  1092. it != sigs.end(); ++it)
  1093. {
  1094. cmListFileBacktrace::const_iterator i = it->begin();
  1095. if(i != it->end())
  1096. {
  1097. cmListFileContext const& lfc = *i;
  1098. cmOStringStream line;
  1099. line << " * " << (lfc.Line? "": " in ") << lfc << std::endl;
  1100. if (emitted.insert(line.str()).second)
  1101. {
  1102. s << line.str();
  1103. }
  1104. ++i;
  1105. }
  1106. }
  1107. }
  1108. }
  1109. //----------------------------------------------------------------------------
  1110. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  1111. const std::string& target,
  1112. const std::string& lib,
  1113. LinkLibraryType llt)
  1114. {
  1115. cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
  1116. {
  1117. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  1118. const std::string libName = (isNonImportedTarget && llt != GENERAL)
  1119. ? targetNameGenex(lib)
  1120. : lib;
  1121. this->AppendProperty("LINK_LIBRARIES",
  1122. this->GetDebugGeneratorExpressions(libName,
  1123. llt).c_str());
  1124. }
  1125. if (cmGeneratorExpression::Find(lib) != std::string::npos
  1126. || (tgt && tgt->GetType() == INTERFACE_LIBRARY)
  1127. || (target == lib ))
  1128. {
  1129. return;
  1130. }
  1131. cmTarget::LibraryID tmp;
  1132. tmp.first = lib;
  1133. tmp.second = llt;
  1134. this->LinkLibraries.push_back( tmp );
  1135. this->OriginalLinkLibraries.push_back(tmp);
  1136. this->ClearLinkMaps();
  1137. // Add the explicit dependency information for this target. This is
  1138. // simply a set of libraries separated by ";". There should always
  1139. // be a trailing ";". These library names are not canonical, in that
  1140. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  1141. // We shouldn't remove duplicates here because external libraries
  1142. // may be purposefully duplicated to handle recursive dependencies,
  1143. // and we removing one instance will break the link line. Duplicates
  1144. // will be appropriately eliminated at emit time.
  1145. if(this->RecordDependencies)
  1146. {
  1147. std::string targetEntry = target;
  1148. targetEntry += "_LIB_DEPENDS";
  1149. std::string dependencies;
  1150. const char* old_val = mf.GetDefinition( targetEntry );
  1151. if( old_val )
  1152. {
  1153. dependencies += old_val;
  1154. }
  1155. switch (llt)
  1156. {
  1157. case cmTarget::GENERAL:
  1158. dependencies += "general";
  1159. break;
  1160. case cmTarget::DEBUG:
  1161. dependencies += "debug";
  1162. break;
  1163. case cmTarget::OPTIMIZED:
  1164. dependencies += "optimized";
  1165. break;
  1166. }
  1167. dependencies += ";";
  1168. dependencies += lib;
  1169. dependencies += ";";
  1170. mf.AddCacheDefinition( targetEntry, dependencies.c_str(),
  1171. "Dependencies for the target",
  1172. cmCacheManager::STATIC );
  1173. }
  1174. }
  1175. //----------------------------------------------------------------------------
  1176. void
  1177. cmTarget::AddSystemIncludeDirectories(const std::set<std::string> &incs)
  1178. {
  1179. for(std::set<std::string>::const_iterator li = incs.begin();
  1180. li != incs.end(); ++li)
  1181. {
  1182. this->SystemIncludeDirectories.insert(*li);
  1183. }
  1184. }
  1185. //----------------------------------------------------------------------------
  1186. void
  1187. cmTarget::AddSystemIncludeDirectories(const std::vector<std::string> &incs)
  1188. {
  1189. for(std::vector<std::string>::const_iterator li = incs.begin();
  1190. li != incs.end(); ++li)
  1191. {
  1192. this->SystemIncludeDirectories.insert(*li);
  1193. }
  1194. }
  1195. //----------------------------------------------------------------------------
  1196. void
  1197. cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
  1198. {
  1199. // There are two key parts of the dependency analysis: (1)
  1200. // determining the libraries in the link line, and (2) constructing
  1201. // the dependency graph for those libraries.
  1202. //
  1203. // The latter is done using the cache entries that record the
  1204. // dependencies of each library.
  1205. //
  1206. // The former is a more thorny issue, since it is not clear how to
  1207. // determine if two libraries listed on the link line refer to the a
  1208. // single library or not. For example, consider the link "libraries"
  1209. // /usr/lib/libtiff.so -ltiff
  1210. // Is this one library or two? The solution implemented here is the
  1211. // simplest (and probably the only practical) one: two libraries are
  1212. // the same if their "link strings" are identical. Thus, the two
  1213. // libraries above are considered distinct. This also means that for
  1214. // dependency analysis to be effective, the CMake user must specify
  1215. // libraries build by his project without using any linker flags or
  1216. // file extensions. That is,
  1217. // LINK_LIBRARIES( One Two )
  1218. // instead of
  1219. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  1220. // The former is probably what most users would do, but it never
  1221. // hurts to document the assumptions. :-) Therefore, in the analysis
  1222. // code, the "canonical name" of a library is simply its name as
  1223. // given to a LINK_LIBRARIES command.
  1224. //
  1225. // Also, we will leave the original link line intact; we will just add any
  1226. // dependencies that were missing.
  1227. //
  1228. // There is a problem with recursive external libraries
  1229. // (i.e. libraries with no dependency information that are
  1230. // recursively dependent). We must make sure that the we emit one of
  1231. // the libraries twice to satisfy the recursion, but we shouldn't
  1232. // emit it more times than necessary. In particular, we must make
  1233. // sure that handling this improbable case doesn't cost us when
  1234. // dealing with the common case of non-recursive libraries. The
  1235. // solution is to assume that the recursion is satisfied at one node
  1236. // of the dependency tree. To illustrate, assume libA and libB are
  1237. // extrenal and mutually dependent. Suppose libX depends on
  1238. // libA, and libY on libA and libX. Then
  1239. // TARGET_LINK_LIBRARIES( Y X A B A )
  1240. // TARGET_LINK_LIBRARIES( X A B A )
  1241. // TARGET_LINK_LIBRARIES( Exec Y )
  1242. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  1243. // specify the dependencies, since the mutual dependency of A and B
  1244. // is resolved *every time libA is specified*.
  1245. //
  1246. // Something like
  1247. // TARGET_LINK_LIBRARIES( Y X A B A )
  1248. // TARGET_LINK_LIBRARIES( X A B )
  1249. // TARGET_LINK_LIBRARIES( Exec Y )
  1250. // would result in "-lY -lX -lA -lB", and the mutual dependency
  1251. // information is lost. This is because in some case (Y), the mutual
  1252. // dependency of A and B is listed, while in another other case (X),
  1253. // it is not. Depending on which line actually emits A, the mutual
  1254. // dependency may or may not be on the final link line. We can't
  1255. // handle this pathalogical case cleanly without emitting extra
  1256. // libraries for the normal cases. Besides, the dependency
  1257. // information for X is wrong anyway: if we build an executable
  1258. // depending on X alone, we would not have the mutual dependency on
  1259. // A and B resolved.
  1260. //
  1261. // IMPROVEMENTS:
  1262. // -- The current algorithm will not always pick the "optimal" link line
  1263. // when recursive dependencies are present. It will instead break the
  1264. // cycles at an aribtrary point. The majority of projects won't have
  1265. // cyclic dependencies, so this is probably not a big deal. Note that
  1266. // the link line is always correct, just not necessary optimal.
  1267. {
  1268. // Expand variables in link library names. This is for backwards
  1269. // compatibility with very early CMake versions and should
  1270. // eventually be removed. This code was moved here from the end of
  1271. // old source list processing code which was called just before this
  1272. // method.
  1273. for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
  1274. p != this->LinkLibraries.end(); ++p)
  1275. {
  1276. this->Makefile->ExpandVariablesInString(p->first, true, true);
  1277. }
  1278. }
  1279. // The dependency map.
  1280. DependencyMap dep_map;
  1281. // 1. Build the dependency graph
  1282. //
  1283. for(LinkLibraryVectorType::reverse_iterator lib
  1284. = this->LinkLibraries.rbegin();
  1285. lib != this->LinkLibraries.rend(); ++lib)
  1286. {
  1287. this->GatherDependencies( mf, *lib, dep_map);
  1288. }
  1289. // 2. Remove any dependencies that are already satisfied in the original
  1290. // link line.
  1291. //
  1292. for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
  1293. lib != this->LinkLibraries.end(); ++lib)
  1294. {
  1295. for( LinkLibraryVectorType::iterator lib2 = lib;
  1296. lib2 != this->LinkLibraries.end(); ++lib2)
  1297. {
  1298. this->DeleteDependency( dep_map, *lib, *lib2);
  1299. }
  1300. }
  1301. // 3. Create the new link line by simply emitting any dependencies that are
  1302. // missing. Start from the back and keep adding.
  1303. //
  1304. std::set<DependencyMap::key_type> done, visited;
  1305. std::vector<DependencyMap::key_type> newLinkLibraries;
  1306. for(LinkLibraryVectorType::reverse_iterator lib =
  1307. this->LinkLibraries.rbegin();
  1308. lib != this->LinkLibraries.rend(); ++lib)
  1309. {
  1310. // skip zero size library entries, this may happen
  1311. // if a variable expands to nothing.
  1312. if (lib->first.size() != 0)
  1313. {
  1314. this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
  1315. }
  1316. }
  1317. // 4. Add the new libraries to the link line.
  1318. //
  1319. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  1320. newLinkLibraries.rbegin();
  1321. k != newLinkLibraries.rend(); ++k )
  1322. {
  1323. // get the llt from the dep_map
  1324. this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
  1325. }
  1326. this->LinkLibrariesAnalyzed = true;
  1327. }
  1328. //----------------------------------------------------------------------------
  1329. void cmTarget::InsertDependency( DependencyMap& depMap,
  1330. const LibraryID& lib,
  1331. const LibraryID& dep)
  1332. {
  1333. depMap[lib].push_back(dep);
  1334. }
  1335. //----------------------------------------------------------------------------
  1336. void cmTarget::DeleteDependency( DependencyMap& depMap,
  1337. const LibraryID& lib,
  1338. const LibraryID& dep)
  1339. {
  1340. // Make sure there is an entry in the map for lib. If so, delete all
  1341. // dependencies to dep. There may be repeated entries because of
  1342. // external libraries that are specified multiple times.
  1343. DependencyMap::iterator map_itr = depMap.find( lib );
  1344. if( map_itr != depMap.end() )
  1345. {
  1346. DependencyList& depList = map_itr->second;
  1347. DependencyList::iterator itr;
  1348. while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
  1349. depList.end() )
  1350. {
  1351. depList.erase( itr );
  1352. }
  1353. }
  1354. }
  1355. //----------------------------------------------------------------------------
  1356. void cmTarget::Emit(const LibraryID lib,
  1357. const DependencyMap& dep_map,
  1358. std::set<LibraryID>& emitted,
  1359. std::set<LibraryID>& visited,
  1360. DependencyList& link_line )
  1361. {
  1362. // It's already been emitted
  1363. if( emitted.find(lib) != emitted.end() )
  1364. {
  1365. return;
  1366. }
  1367. // Emit the dependencies only if this library node hasn't been
  1368. // visited before. If it has, then we have a cycle. The recursion
  1369. // that got us here should take care of everything.
  1370. if( visited.insert(lib).second )
  1371. {
  1372. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  1373. {
  1374. const DependencyList& dep_on = dep_map.find( lib )->second;
  1375. DependencyList::const_reverse_iterator i;
  1376. // To cater for recursive external libraries, we must emit
  1377. // duplicates on this link line *unless* they were emitted by
  1378. // some other node, in which case we assume that the recursion
  1379. // was resolved then. We making the simplifying assumption that
  1380. // any duplicates on a single link line are on purpose, and must
  1381. // be preserved.
  1382. // This variable will keep track of the libraries that were
  1383. // emitted directly from the current node, and not from a
  1384. // recursive call. This way, if we come across a library that
  1385. // has already been emitted, we repeat it iff it has been
  1386. // emitted here.
  1387. std::set<DependencyMap::key_type> emitted_here;
  1388. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  1389. {
  1390. if( emitted_here.find(*i) != emitted_here.end() )
  1391. {
  1392. // a repeat. Must emit.
  1393. emitted.insert(*i);
  1394. link_line.push_back( *i );
  1395. }
  1396. else
  1397. {
  1398. // Emit only if no-one else has
  1399. if( emitted.find(*i) == emitted.end() )
  1400. {
  1401. // emit dependencies
  1402. Emit( *i, dep_map, emitted, visited, link_line );
  1403. // emit self
  1404. emitted.insert(*i);
  1405. emitted_here.insert(*i);
  1406. link_line.push_back( *i );
  1407. }
  1408. }
  1409. }
  1410. }
  1411. }
  1412. }
  1413. //----------------------------------------------------------------------------
  1414. void cmTarget::GatherDependencies( const cmMakefile& mf,
  1415. const LibraryID& lib,
  1416. DependencyMap& dep_map)
  1417. {
  1418. // If the library is already in the dependency map, then it has
  1419. // already been fully processed.
  1420. if( dep_map.find(lib) != dep_map.end() )
  1421. {
  1422. return;
  1423. }
  1424. const char* deps = mf.GetDefinition( lib.first+"_LIB_DEPENDS" );
  1425. if( deps && strcmp(deps,"") != 0 )
  1426. {
  1427. // Make sure this library is in the map, even if it has an empty
  1428. // set of dependencies. This distinguishes the case of explicitly
  1429. // no dependencies with that of unspecified dependencies.
  1430. dep_map[lib];
  1431. // Parse the dependency information, which is a set of
  1432. // type, library pairs separated by ";". There is always a trailing ";".
  1433. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  1434. std::string depline = deps;
  1435. std::string::size_type start = 0;
  1436. std::string::size_type end;
  1437. end = depline.find( ";", start );
  1438. while( end != std::string::npos )
  1439. {
  1440. std::string l = depline.substr( start, end-start );
  1441. if( l.size() != 0 )
  1442. {
  1443. if (l == "debug")
  1444. {
  1445. llt = cmTarget::DEBUG;
  1446. }
  1447. else if (l == "optimized")
  1448. {
  1449. llt = cmTarget::OPTIMIZED;
  1450. }
  1451. else if (l == "general")
  1452. {
  1453. llt = cmTarget::GENERAL;
  1454. }
  1455. else
  1456. {
  1457. LibraryID lib2(l,llt);
  1458. this->InsertDependency( dep_map, lib, lib2);
  1459. this->GatherDependencies( mf, lib2, dep_map);
  1460. llt = cmTarget::GENERAL;
  1461. }
  1462. }
  1463. start = end+1; // skip the ;
  1464. end = depline.find( ";", start );
  1465. }
  1466. // cannot depend on itself
  1467. this->DeleteDependency( dep_map, lib, lib);
  1468. }
  1469. }
  1470. //----------------------------------------------------------------------------
  1471. static bool whiteListedInterfaceProperty(const std::string& prop)
  1472. {
  1473. if(cmHasLiteralPrefix(prop, "INTERFACE_"))
  1474. {
  1475. return true;
  1476. }
  1477. static const char* builtIns[] = {
  1478. // ###: This must remain sorted. It is processed with a binary search.
  1479. "COMPATIBLE_INTERFACE_BOOL",
  1480. "COMPATIBLE_INTERFACE_NUMBER_MAX",
  1481. "COMPATIBLE_INTERFACE_NUMBER_MIN",
  1482. "COMPATIBLE_INTERFACE_STRING",
  1483. "EXPORT_NAME",
  1484. "IMPORTED",
  1485. "NAME",
  1486. "TYPE"
  1487. };
  1488. if (std::binary_search(cmArrayBegin(builtIns),
  1489. cmArrayEnd(builtIns),
  1490. prop.c_str(),
  1491. cmStrCmp(prop)))
  1492. {
  1493. return true;
  1494. }
  1495. if (cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_"))
  1496. {
  1497. return true;
  1498. }
  1499. return false;
  1500. }
  1501. //----------------------------------------------------------------------------
  1502. void cmTarget::SetProperty(const std::string& prop, const char* value)
  1503. {
  1504. if (this->GetType() == INTERFACE_LIBRARY
  1505. && !whiteListedInterfaceProperty(prop))
  1506. {
  1507. cmOStringStream e;
  1508. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1509. "The property \"" << prop << "\" is not allowed.";
  1510. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1511. return;
  1512. }
  1513. if (prop == "NAME")
  1514. {
  1515. cmOStringStream e;
  1516. e << "NAME property is read-only\n";
  1517. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1518. return;
  1519. }
  1520. if(prop == "INCLUDE_DIRECTORIES")
  1521. {
  1522. cmListFileBacktrace lfbt;
  1523. this->Makefile->GetBacktrace(lfbt);
  1524. cmGeneratorExpression ge(lfbt);
  1525. deleteAndClear(this->Internal->IncludeDirectoriesEntries);
  1526. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1527. this->Internal->IncludeDirectoriesEntries.push_back(
  1528. new cmTargetInternals::TargetPropertyEntry(cge));
  1529. return;
  1530. }
  1531. if(prop == "COMPILE_OPTIONS")
  1532. {
  1533. cmListFileBacktrace lfbt;
  1534. this->Makefile->GetBacktrace(lfbt);
  1535. cmGeneratorExpression ge(lfbt);
  1536. deleteAndClear(this->Internal->CompileOptionsEntries);
  1537. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1538. this->Internal->CompileOptionsEntries.push_back(
  1539. new cmTargetInternals::TargetPropertyEntry(cge));
  1540. return;
  1541. }
  1542. if(prop == "COMPILE_DEFINITIONS")
  1543. {
  1544. cmListFileBacktrace lfbt;
  1545. this->Makefile->GetBacktrace(lfbt);
  1546. cmGeneratorExpression ge(lfbt);
  1547. deleteAndClear(this->Internal->CompileDefinitionsEntries);
  1548. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1549. this->Internal->CompileDefinitionsEntries.push_back(
  1550. new cmTargetInternals::TargetPropertyEntry(cge));
  1551. return;
  1552. }
  1553. if(prop == "EXPORT_NAME" && this->IsImported())
  1554. {
  1555. cmOStringStream e;
  1556. e << "EXPORT_NAME property can't be set on imported targets (\""
  1557. << this->Name << "\")\n";
  1558. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1559. return;
  1560. }
  1561. if (prop == "LINK_LIBRARIES")
  1562. {
  1563. this->Internal->LinkImplementationPropertyEntries.clear();
  1564. cmListFileBacktrace lfbt;
  1565. this->Makefile->GetBacktrace(lfbt);
  1566. cmValueWithOrigin entry(value, lfbt);
  1567. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1568. return;
  1569. }
  1570. if (prop == "SOURCES")
  1571. {
  1572. if(this->IsImported())
  1573. {
  1574. cmOStringStream e;
  1575. e << "SOURCES property can't be set on imported targets (\""
  1576. << this->Name << "\")\n";
  1577. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1578. return;
  1579. }
  1580. cmListFileBacktrace lfbt;
  1581. this->Makefile->GetBacktrace(lfbt);
  1582. cmGeneratorExpression ge(lfbt);
  1583. this->Internal->SourceEntries.clear();
  1584. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1585. this->Internal->SourceEntries.push_back(
  1586. new cmTargetInternals::TargetPropertyEntry(cge));
  1587. return;
  1588. }
  1589. this->Properties.SetProperty(prop, value, cmProperty::TARGET);
  1590. this->MaybeInvalidatePropertyCache(prop);
  1591. }
  1592. //----------------------------------------------------------------------------
  1593. void cmTarget::AppendProperty(const std::string& prop, const char* value,
  1594. bool asString)
  1595. {
  1596. if (this->GetType() == INTERFACE_LIBRARY
  1597. && !whiteListedInterfaceProperty(prop))
  1598. {
  1599. cmOStringStream e;
  1600. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1601. "The property \"" << prop << "\" is not allowed.";
  1602. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1603. return;
  1604. }
  1605. if (prop == "NAME")
  1606. {
  1607. cmOStringStream e;
  1608. e << "NAME property is read-only\n";
  1609. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1610. return;
  1611. }
  1612. if(prop == "INCLUDE_DIRECTORIES")
  1613. {
  1614. cmListFileBacktrace lfbt;
  1615. this->Makefile->GetBacktrace(lfbt);
  1616. cmGeneratorExpression ge(lfbt);
  1617. this->Internal->IncludeDirectoriesEntries.push_back(
  1618. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1619. return;
  1620. }
  1621. if(prop == "COMPILE_OPTIONS")
  1622. {
  1623. cmListFileBacktrace lfbt;
  1624. this->Makefile->GetBacktrace(lfbt);
  1625. cmGeneratorExpression ge(lfbt);
  1626. this->Internal->CompileOptionsEntries.push_back(
  1627. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1628. return;
  1629. }
  1630. if(prop == "COMPILE_DEFINITIONS")
  1631. {
  1632. cmListFileBacktrace lfbt;
  1633. this->Makefile->GetBacktrace(lfbt);
  1634. cmGeneratorExpression ge(lfbt);
  1635. this->Internal->CompileDefinitionsEntries.push_back(
  1636. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1637. return;
  1638. }
  1639. if(prop == "EXPORT_NAME" && this->IsImported())
  1640. {
  1641. cmOStringStream e;
  1642. e << "EXPORT_NAME property can't be set on imported targets (\""
  1643. << this->Name << "\")\n";
  1644. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1645. return;
  1646. }
  1647. if (prop == "LINK_LIBRARIES")
  1648. {
  1649. cmListFileBacktrace lfbt;
  1650. this->Makefile->GetBacktrace(lfbt);
  1651. cmValueWithOrigin entry(value, lfbt);
  1652. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1653. return;
  1654. }
  1655. if (prop == "SOURCES")
  1656. {
  1657. if(this->IsImported())
  1658. {
  1659. cmOStringStream e;
  1660. e << "SOURCES property can't be set on imported targets (\""
  1661. << this->Name << "\")\n";
  1662. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1663. return;
  1664. }
  1665. cmListFileBacktrace lfbt;
  1666. this->Makefile->GetBacktrace(lfbt);
  1667. cmGeneratorExpression ge(lfbt);
  1668. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1669. this->Internal->SourceEntries.push_back(
  1670. new cmTargetInternals::TargetPropertyEntry(cge));
  1671. return;
  1672. }
  1673. this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
  1674. this->MaybeInvalidatePropertyCache(prop);
  1675. }
  1676. //----------------------------------------------------------------------------
  1677. std::string cmTarget::GetExportName() const
  1678. {
  1679. const char *exportName = this->GetProperty("EXPORT_NAME");
  1680. if (exportName && *exportName)
  1681. {
  1682. if (!cmGeneratorExpression::IsValidTargetName(exportName))
  1683. {
  1684. cmOStringStream e;
  1685. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  1686. << this->GetName() << "\": is not valid.";
  1687. cmSystemTools::Error(e.str().c_str());
  1688. return "";
  1689. }
  1690. return exportName;
  1691. }
  1692. return this->GetName();
  1693. }
  1694. //----------------------------------------------------------------------------
  1695. void cmTarget::AppendBuildInterfaceIncludes()
  1696. {
  1697. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  1698. this->GetType() != cmTarget::STATIC_LIBRARY &&
  1699. this->GetType() != cmTarget::MODULE_LIBRARY &&
  1700. this->GetType() != cmTarget::INTERFACE_LIBRARY &&
  1701. !this->IsExecutableWithExports())
  1702. {
  1703. return;
  1704. }
  1705. if (this->BuildInterfaceIncludesAppended)
  1706. {
  1707. return;
  1708. }
  1709. this->BuildInterfaceIncludesAppended = true;
  1710. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
  1711. {
  1712. const char *binDir = this->Makefile->GetStartOutputDirectory();
  1713. const char *srcDir = this->Makefile->GetStartDirectory();
  1714. const std::string dirs = std::string(binDir ? binDir : "")
  1715. + std::string(binDir ? ";" : "")
  1716. + std::string(srcDir ? srcDir : "");
  1717. if (!dirs.empty())
  1718. {
  1719. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  1720. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  1721. }
  1722. }
  1723. }
  1724. //----------------------------------------------------------------------------
  1725. void cmTarget::InsertInclude(const cmValueWithOrigin &entry,
  1726. bool before)
  1727. {
  1728. cmGeneratorExpression ge(entry.Backtrace);
  1729. std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
  1730. = before ? this->Internal->IncludeDirectoriesEntries.begin()
  1731. : this->Internal->IncludeDirectoriesEntries.end();
  1732. this->Internal->IncludeDirectoriesEntries.insert(position,
  1733. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
  1734. }
  1735. //----------------------------------------------------------------------------
  1736. void cmTarget::InsertCompileOption(const cmValueWithOrigin &entry,
  1737. bool before)
  1738. {
  1739. cmGeneratorExpression ge(entry.Backtrace);
  1740. std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
  1741. = before ? this->Internal->CompileOptionsEntries.begin()
  1742. : this->Internal->CompileOptionsEntries.end();
  1743. this->Internal->CompileOptionsEntries.insert(position,
  1744. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
  1745. }
  1746. //----------------------------------------------------------------------------
  1747. void cmTarget::InsertCompileDefinition(const cmValueWithOrigin &entry)
  1748. {
  1749. cmGeneratorExpression ge(entry.Backtrace);
  1750. this->Internal->CompileDefinitionsEntries.push_back(
  1751. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
  1752. }
  1753. //----------------------------------------------------------------------------
  1754. static void processIncludeDirectories(cmTarget const* tgt,
  1755. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1756. std::vector<std::string> &includes,
  1757. std::set<std::string> &uniqueIncludes,
  1758. cmGeneratorExpressionDAGChecker *dagChecker,
  1759. const std::string& config, bool debugIncludes)
  1760. {
  1761. cmMakefile *mf = tgt->GetMakefile();
  1762. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  1763. it = entries.begin(), end = entries.end(); it != end; ++it)
  1764. {
  1765. bool testIsOff = true;
  1766. bool cacheIncludes = false;
  1767. std::vector<std::string>& entryIncludes = (*it)->CachedEntries;
  1768. if(!entryIncludes.empty())
  1769. {
  1770. testIsOff = false;
  1771. }
  1772. else
  1773. {
  1774. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  1775. config,
  1776. false,
  1777. tgt,
  1778. dagChecker),
  1779. entryIncludes);
  1780. if (mf->IsGeneratingBuildSystem()
  1781. && !(*it)->ge->GetHadContextSensitiveCondition())
  1782. {
  1783. cacheIncludes = true;
  1784. }
  1785. }
  1786. std::string usedIncludes;
  1787. cmListFileBacktrace lfbt;
  1788. for(std::vector<std::string>::iterator
  1789. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  1790. {
  1791. std::string targetName = (*it)->TargetName;
  1792. std::string evaluatedTargetName;
  1793. {
  1794. cmGeneratorExpression ge(lfbt);
  1795. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1796. ge.Parse(targetName);
  1797. evaluatedTargetName = cge->Evaluate(mf, config, false, tgt, 0, 0);
  1798. }
  1799. cmTarget *dependentTarget = mf->FindTargetToUse(targetName);
  1800. const bool fromImported = dependentTarget
  1801. && dependentTarget->IsImported();
  1802. cmTarget *evaluatedDependentTarget =
  1803. (targetName != evaluatedTargetName)
  1804. ? mf->FindTargetToUse(evaluatedTargetName)
  1805. : 0;
  1806. targetName = evaluatedTargetName;
  1807. const bool fromEvaluatedImported = evaluatedDependentTarget
  1808. && evaluatedDependentTarget->IsImported();
  1809. if ((fromImported || fromEvaluatedImported)
  1810. && !cmSystemTools::FileExists(li->c_str()))
  1811. {
  1812. cmOStringStream e;
  1813. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1814. if (fromEvaluatedImported)
  1815. {
  1816. switch(tgt->GetPolicyStatusCMP0027())
  1817. {
  1818. case cmPolicies::WARN:
  1819. e << (mf->GetPolicies()
  1820. ->GetPolicyWarning(cmPolicies::CMP0027)) << "\n";
  1821. case cmPolicies::OLD:
  1822. messageType = cmake::AUTHOR_WARNING;
  1823. break;
  1824. case cmPolicies::REQUIRED_ALWAYS:
  1825. case cmPolicies::REQUIRED_IF_USED:
  1826. case cmPolicies::NEW:
  1827. break;
  1828. }
  1829. }
  1830. e << "Imported target \"" << targetName << "\" includes "
  1831. "non-existent path\n \"" << *li << "\"\nin its "
  1832. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  1833. "* The path was deleted, renamed, or moved to another "
  1834. "location.\n"
  1835. "* An install or uninstall procedure did not complete "
  1836. "successfully.\n"
  1837. "* The installation package was faulty and references files it "
  1838. "does not provide.\n";
  1839. tgt->GetMakefile()->IssueMessage(messageType, e.str());
  1840. return;
  1841. }
  1842. if (!cmSystemTools::FileIsFullPath(li->c_str()))
  1843. {
  1844. cmOStringStream e;
  1845. bool noMessage = false;
  1846. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1847. if (!targetName.empty())
  1848. {
  1849. e << "Target \"" << targetName << "\" contains relative "
  1850. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  1851. " \"" << *li << "\"";
  1852. }
  1853. else
  1854. {
  1855. switch(tgt->GetPolicyStatusCMP0021())
  1856. {
  1857. case cmPolicies::WARN:
  1858. {
  1859. e << (mf->GetPolicies()
  1860. ->GetPolicyWarning(cmPolicies::CMP0021)) << "\n";
  1861. messageType = cmake::AUTHOR_WARNING;
  1862. }
  1863. break;
  1864. case cmPolicies::OLD:
  1865. noMessage = true;
  1866. case cmPolicies::REQUIRED_IF_USED:
  1867. case cmPolicies::REQUIRED_ALWAYS:
  1868. case cmPolicies::NEW:
  1869. // Issue the fatal message.
  1870. break;
  1871. }
  1872. e << "Found relative path while evaluating include directories of "
  1873. "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n";
  1874. }
  1875. if (!noMessage)
  1876. {
  1877. tgt->GetMakefile()->IssueMessage(messageType, e.str());
  1878. if (messageType == cmake::FATAL_ERROR)
  1879. {
  1880. return;
  1881. }
  1882. }
  1883. }
  1884. if (testIsOff && !cmSystemTools::IsOff(li->c_str()))
  1885. {
  1886. cmSystemTools::ConvertToUnixSlashes(*li);
  1887. }
  1888. std::string inc = *li;
  1889. if(uniqueIncludes.insert(inc).second)
  1890. {
  1891. includes.push_back(inc);
  1892. if (debugIncludes)
  1893. {
  1894. usedIncludes += " * " + inc + "\n";
  1895. }
  1896. }
  1897. }
  1898. if (cacheIncludes)
  1899. {
  1900. (*it)->CachedEntries = entryIncludes;
  1901. }
  1902. if (!usedIncludes.empty())
  1903. {
  1904. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  1905. std::string("Used includes for target ")
  1906. + tgt->GetName() + ":\n"
  1907. + usedIncludes, (*it)->ge->GetBacktrace());
  1908. }
  1909. }
  1910. }
  1911. //----------------------------------------------------------------------------
  1912. std::vector<std::string>
  1913. cmTarget::GetIncludeDirectories(const std::string& config) const
  1914. {
  1915. std::vector<std::string> includes;
  1916. std::set<std::string> uniqueIncludes;
  1917. cmListFileBacktrace lfbt;
  1918. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  1919. this->GetName(),
  1920. "INCLUDE_DIRECTORIES", 0, 0);
  1921. std::vector<std::string> debugProperties;
  1922. const char *debugProp =
  1923. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  1924. if (debugProp)
  1925. {
  1926. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  1927. }
  1928. bool debugIncludes = !this->DebugIncludesDone
  1929. && std::find(debugProperties.begin(),
  1930. debugProperties.end(),
  1931. "INCLUDE_DIRECTORIES")
  1932. != debugProperties.end();
  1933. if (this->Makefile->IsGeneratingBuildSystem())
  1934. {
  1935. this->DebugIncludesDone = true;
  1936. }
  1937. processIncludeDirectories(this,
  1938. this->Internal->IncludeDirectoriesEntries,
  1939. includes,
  1940. uniqueIncludes,
  1941. &dagChecker,
  1942. config,
  1943. debugIncludes);
  1944. if (!this->Internal->CacheLinkInterfaceIncludeDirectoriesDone[config])
  1945. {
  1946. for (std::vector<cmValueWithOrigin>::const_iterator
  1947. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  1948. end = this->Internal->LinkImplementationPropertyEntries.end();
  1949. it != end; ++it)
  1950. {
  1951. if (!cmGeneratorExpression::IsValidTargetName(it->Value)
  1952. && cmGeneratorExpression::Find(it->Value) == std::string::npos)
  1953. {
  1954. continue;
  1955. }
  1956. {
  1957. cmGeneratorExpression ge(lfbt);
  1958. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1959. ge.Parse(it->Value);
  1960. std::string result = cge->Evaluate(this->Makefile, config,
  1961. false, this, 0, 0);
  1962. if (!this->Makefile->FindTargetToUse(result))
  1963. {
  1964. continue;
  1965. }
  1966. }
  1967. std::string includeGenex = "$<TARGET_PROPERTY:" +
  1968. it->Value + ",INTERFACE_INCLUDE_DIRECTORIES>";
  1969. if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
  1970. {
  1971. // Because it->Value is a generator expression, ensure that it
  1972. // evaluates to the non-empty string before being used in the
  1973. // TARGET_PROPERTY expression.
  1974. includeGenex = "$<$<BOOL:" + it->Value + ">:" + includeGenex + ">";
  1975. }
  1976. cmGeneratorExpression ge(it->Backtrace);
  1977. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
  1978. includeGenex);
  1979. this->Internal
  1980. ->CachedLinkInterfaceIncludeDirectoriesEntries[config].push_back(
  1981. new cmTargetInternals::TargetPropertyEntry(cge,
  1982. it->Value));
  1983. }
  1984. if(this->Makefile->IsOn("APPLE"))
  1985. {
  1986. LinkImplementation const* impl = this->GetLinkImplementation(config,
  1987. this);
  1988. for(std::vector<std::string>::const_iterator
  1989. it = impl->Libraries.begin();
  1990. it != impl->Libraries.end(); ++it)
  1991. {
  1992. std::string libDir = cmSystemTools::CollapseFullPath(it->c_str());
  1993. static cmsys::RegularExpression
  1994. frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  1995. if(!frameworkCheck.find(libDir))
  1996. {
  1997. continue;
  1998. }
  1999. libDir = frameworkCheck.match(1);
  2000. cmGeneratorExpression ge(lfbt);
  2001. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2002. ge.Parse(libDir.c_str());
  2003. this->Internal
  2004. ->CachedLinkInterfaceIncludeDirectoriesEntries[config]
  2005. .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  2006. }
  2007. }
  2008. }
  2009. processIncludeDirectories(this,
  2010. this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries[config],
  2011. includes,
  2012. uniqueIncludes,
  2013. &dagChecker,
  2014. config,
  2015. debugIncludes);
  2016. if (!this->Makefile->IsGeneratingBuildSystem())
  2017. {
  2018. deleteAndClear(
  2019. this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries);
  2020. }
  2021. else
  2022. {
  2023. this->Internal->CacheLinkInterfaceIncludeDirectoriesDone[config]
  2024. = true;
  2025. }
  2026. return includes;
  2027. }
  2028. //----------------------------------------------------------------------------
  2029. static void processCompileOptionsInternal(cmTarget const* tgt,
  2030. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2031. std::vector<std::string> &options,
  2032. std::set<std::string> &uniqueOptions,
  2033. cmGeneratorExpressionDAGChecker *dagChecker,
  2034. const std::string& config, bool debugOptions, const char *logName)
  2035. {
  2036. cmMakefile *mf = tgt->GetMakefile();
  2037. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  2038. it = entries.begin(), end = entries.end(); it != end; ++it)
  2039. {
  2040. bool cacheOptions = false;
  2041. std::vector<std::string> entryOptions = (*it)->CachedEntries;
  2042. if(entryOptions.empty())
  2043. {
  2044. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  2045. config,
  2046. false,
  2047. tgt,
  2048. dagChecker),
  2049. entryOptions);
  2050. if (mf->IsGeneratingBuildSystem()
  2051. && !(*it)->ge->GetHadContextSensitiveCondition())
  2052. {
  2053. cacheOptions = true;
  2054. }
  2055. }
  2056. std::string usedOptions;
  2057. for(std::vector<std::string>::iterator
  2058. li = entryOptions.begin(); li != entryOptions.end(); ++li)
  2059. {
  2060. std::string opt = *li;
  2061. if(uniqueOptions.insert(opt).second)
  2062. {
  2063. options.push_back(opt);
  2064. if (debugOptions)
  2065. {
  2066. usedOptions += " * " + opt + "\n";
  2067. }
  2068. }
  2069. }
  2070. if (cacheOptions)
  2071. {
  2072. (*it)->CachedEntries = entryOptions;
  2073. }
  2074. if (!usedOptions.empty())
  2075. {
  2076. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2077. std::string("Used compile ") + logName
  2078. + std::string(" for target ")
  2079. + tgt->GetName() + ":\n"
  2080. + usedOptions, (*it)->ge->GetBacktrace());
  2081. }
  2082. }
  2083. }
  2084. //----------------------------------------------------------------------------
  2085. static void processCompileOptions(cmTarget const* tgt,
  2086. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2087. std::vector<std::string> &options,
  2088. std::set<std::string> &uniqueOptions,
  2089. cmGeneratorExpressionDAGChecker *dagChecker,
  2090. const std::string& config, bool debugOptions)
  2091. {
  2092. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2093. dagChecker, config, debugOptions, "options");
  2094. }
  2095. //----------------------------------------------------------------------------
  2096. void cmTarget::GetAutoUicOptions(std::vector<std::string> &result,
  2097. const std::string& config) const
  2098. {
  2099. const char *prop
  2100. = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  2101. config);
  2102. if (!prop)
  2103. {
  2104. return;
  2105. }
  2106. cmListFileBacktrace lfbt;
  2107. cmGeneratorExpression ge(lfbt);
  2108. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  2109. this->GetName(),
  2110. "AUTOUIC_OPTIONS", 0, 0);
  2111. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  2112. ->Evaluate(this->Makefile,
  2113. config,
  2114. false,
  2115. this,
  2116. &dagChecker),
  2117. result);
  2118. }
  2119. //----------------------------------------------------------------------------
  2120. void cmTarget::GetCompileOptions(std::vector<std::string> &result,
  2121. const std::string& config) const
  2122. {
  2123. std::set<std::string> uniqueOptions;
  2124. cmListFileBacktrace lfbt;
  2125. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  2126. this->GetName(),
  2127. "COMPILE_OPTIONS", 0, 0);
  2128. std::vector<std::string> debugProperties;
  2129. const char *debugProp =
  2130. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2131. if (debugProp)
  2132. {
  2133. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2134. }
  2135. bool debugOptions = !this->DebugCompileOptionsDone
  2136. && std::find(debugProperties.begin(),
  2137. debugProperties.end(),
  2138. "COMPILE_OPTIONS")
  2139. != debugProperties.end();
  2140. if (this->Makefile->IsGeneratingBuildSystem())
  2141. {
  2142. this->DebugCompileOptionsDone = true;
  2143. }
  2144. processCompileOptions(this,
  2145. this->Internal->CompileOptionsEntries,
  2146. result,
  2147. uniqueOptions,
  2148. &dagChecker,
  2149. config,
  2150. debugOptions);
  2151. if (!this->Internal->CacheLinkInterfaceCompileOptionsDone[config])
  2152. {
  2153. for (std::vector<cmValueWithOrigin>::const_iterator
  2154. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  2155. end = this->Internal->LinkImplementationPropertyEntries.end();
  2156. it != end; ++it)
  2157. {
  2158. if (!cmGeneratorExpression::IsValidTargetName(it->Value)
  2159. && cmGeneratorExpression::Find(it->Value) == std::string::npos)
  2160. {
  2161. continue;
  2162. }
  2163. {
  2164. cmGeneratorExpression ge(lfbt);
  2165. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2166. ge.Parse(it->Value);
  2167. std::string targetResult = cge->Evaluate(this->Makefile, config,
  2168. false, this, 0, 0);
  2169. if (!this->Makefile->FindTargetToUse(targetResult))
  2170. {
  2171. continue;
  2172. }
  2173. }
  2174. std::string optionGenex = "$<TARGET_PROPERTY:" +
  2175. it->Value + ",INTERFACE_COMPILE_OPTIONS>";
  2176. if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
  2177. {
  2178. // Because it->Value is a generator expression, ensure that it
  2179. // evaluates to the non-empty string before being used in the
  2180. // TARGET_PROPERTY expression.
  2181. optionGenex = "$<$<BOOL:" + it->Value + ">:" + optionGenex + ">";
  2182. }
  2183. cmGeneratorExpression ge(it->Backtrace);
  2184. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
  2185. optionGenex);
  2186. this->Internal
  2187. ->CachedLinkInterfaceCompileOptionsEntries[config].push_back(
  2188. new cmTargetInternals::TargetPropertyEntry(cge,
  2189. it->Value));
  2190. }
  2191. }
  2192. processCompileOptions(this,
  2193. this->Internal->CachedLinkInterfaceCompileOptionsEntries[config],
  2194. result,
  2195. uniqueOptions,
  2196. &dagChecker,
  2197. config,
  2198. debugOptions);
  2199. if (!this->Makefile->IsGeneratingBuildSystem())
  2200. {
  2201. deleteAndClear(this->Internal->CachedLinkInterfaceCompileOptionsEntries);
  2202. }
  2203. else
  2204. {
  2205. this->Internal->CacheLinkInterfaceCompileOptionsDone[config] = true;
  2206. }
  2207. }
  2208. //----------------------------------------------------------------------------
  2209. static void processCompileDefinitions(cmTarget const* tgt,
  2210. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2211. std::vector<std::string> &options,
  2212. std::set<std::string> &uniqueOptions,
  2213. cmGeneratorExpressionDAGChecker *dagChecker,
  2214. const std::string& config, bool debugOptions)
  2215. {
  2216. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2217. dagChecker, config, debugOptions,
  2218. "definitions");
  2219. }
  2220. //----------------------------------------------------------------------------
  2221. void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
  2222. const std::string& config) const
  2223. {
  2224. std::set<std::string> uniqueOptions;
  2225. cmListFileBacktrace lfbt;
  2226. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  2227. this->GetName(),
  2228. "COMPILE_DEFINITIONS", 0, 0);
  2229. std::vector<std::string> debugProperties;
  2230. const char *debugProp =
  2231. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2232. if (debugProp)
  2233. {
  2234. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2235. }
  2236. bool debugDefines = !this->DebugCompileDefinitionsDone
  2237. && std::find(debugProperties.begin(),
  2238. debugProperties.end(),
  2239. "COMPILE_DEFINITIONS")
  2240. != debugProperties.end();
  2241. if (this->Makefile->IsGeneratingBuildSystem())
  2242. {
  2243. this->DebugCompileDefinitionsDone = true;
  2244. }
  2245. processCompileDefinitions(this,
  2246. this->Internal->CompileDefinitionsEntries,
  2247. list,
  2248. uniqueOptions,
  2249. &dagChecker,
  2250. config,
  2251. debugDefines);
  2252. if (!this->Internal->CacheLinkInterfaceCompileDefinitionsDone[config])
  2253. {
  2254. for (std::vector<cmValueWithOrigin>::const_iterator
  2255. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  2256. end = this->Internal->LinkImplementationPropertyEntries.end();
  2257. it != end; ++it)
  2258. {
  2259. if (!cmGeneratorExpression::IsValidTargetName(it->Value)
  2260. && cmGeneratorExpression::Find(it->Value) == std::string::npos)
  2261. {
  2262. continue;
  2263. }
  2264. {
  2265. cmGeneratorExpression ge(lfbt);
  2266. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2267. ge.Parse(it->Value);
  2268. std::string targetResult = cge->Evaluate(this->Makefile, config,
  2269. false, this, 0, 0);
  2270. if (!this->Makefile->FindTargetToUse(targetResult))
  2271. {
  2272. continue;
  2273. }
  2274. }
  2275. std::string defsGenex = "$<TARGET_PROPERTY:" +
  2276. it->Value + ",INTERFACE_COMPILE_DEFINITIONS>";
  2277. if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
  2278. {
  2279. // Because it->Value is a generator expression, ensure that it
  2280. // evaluates to the non-empty string before being used in the
  2281. // TARGET_PROPERTY expression.
  2282. defsGenex = "$<$<BOOL:" + it->Value + ">:" + defsGenex + ">";
  2283. }
  2284. cmGeneratorExpression ge(it->Backtrace);
  2285. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
  2286. defsGenex);
  2287. this->Internal
  2288. ->CachedLinkInterfaceCompileDefinitionsEntries[config].push_back(
  2289. new cmTargetInternals::TargetPropertyEntry(cge,
  2290. it->Value));
  2291. }
  2292. if (!config.empty())
  2293. {
  2294. std::string configPropName = "COMPILE_DEFINITIONS_"
  2295. + cmSystemTools::UpperCase(config);
  2296. const char *configProp = this->GetProperty(configPropName);
  2297. if (configProp)
  2298. {
  2299. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
  2300. {
  2301. case cmPolicies::WARN:
  2302. {
  2303. cmOStringStream e;
  2304. e << this->Makefile->GetCMakeInstance()->GetPolicies()
  2305. ->GetPolicyWarning(cmPolicies::CMP0043);
  2306. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
  2307. e.str());
  2308. }
  2309. case cmPolicies::OLD:
  2310. {
  2311. cmGeneratorExpression ge(lfbt);
  2312. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2313. ge.Parse(configProp);
  2314. this->Internal
  2315. ->CachedLinkInterfaceCompileDefinitionsEntries[config]
  2316. .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  2317. }
  2318. break;
  2319. case cmPolicies::NEW:
  2320. case cmPolicies::REQUIRED_ALWAYS:
  2321. case cmPolicies::REQUIRED_IF_USED:
  2322. break;
  2323. }
  2324. }
  2325. }
  2326. }
  2327. processCompileDefinitions(this,
  2328. this->Internal->CachedLinkInterfaceCompileDefinitionsEntries[config],
  2329. list,
  2330. uniqueOptions,
  2331. &dagChecker,
  2332. config,
  2333. debugDefines);
  2334. if (!this->Makefile->IsGeneratingBuildSystem())
  2335. {
  2336. deleteAndClear(this->Internal
  2337. ->CachedLinkInterfaceCompileDefinitionsEntries);
  2338. }
  2339. else
  2340. {
  2341. this->Internal->CacheLinkInterfaceCompileDefinitionsDone[config]
  2342. = true;
  2343. }
  2344. }
  2345. //----------------------------------------------------------------------------
  2346. void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop)
  2347. {
  2348. // Wipe out maps caching information affected by this property.
  2349. if(this->IsImported() && cmHasLiteralPrefix(prop, "IMPORTED"))
  2350. {
  2351. this->Internal->ImportInfoMap.clear();
  2352. }
  2353. if(!this->IsImported() && cmHasLiteralPrefix(prop, "LINK_INTERFACE_"))
  2354. {
  2355. this->ClearLinkMaps();
  2356. }
  2357. }
  2358. //----------------------------------------------------------------------------
  2359. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  2360. const std::string& prop, const char* value, cmMakefile* context,
  2361. bool imported)
  2362. {
  2363. // Look for link-type keywords in the value.
  2364. static cmsys::RegularExpression
  2365. keys("(^|;)(debug|optimized|general)(;|$)");
  2366. if(!keys.find(value))
  2367. {
  2368. return;
  2369. }
  2370. // Support imported and non-imported versions of the property.
  2371. const char* base = (imported?
  2372. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  2373. "LINK_INTERFACE_LIBRARIES");
  2374. // Report an error.
  2375. cmOStringStream e;
  2376. e << "Property " << prop << " may not contain link-type keyword \""
  2377. << keys.match(2) << "\". "
  2378. << "The " << base << " property has a per-configuration "
  2379. << "version called " << base << "_<CONFIG> which may be "
  2380. << "used to specify per-configuration rules.";
  2381. if(!imported)
  2382. {
  2383. e << " "
  2384. << "Alternatively, an IMPORTED library may be created, configured "
  2385. << "with a per-configuration location, and then named in the "
  2386. << "property value. "
  2387. << "See the add_library command's IMPORTED mode for details."
  2388. << "\n"
  2389. << "If you have a list of libraries that already contains the "
  2390. << "keyword, use the target_link_libraries command with its "
  2391. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  2392. << "The command automatically recognizes link-type keywords and sets "
  2393. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  2394. << "properties accordingly.";
  2395. }
  2396. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2397. }
  2398. //----------------------------------------------------------------------------
  2399. static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
  2400. cmMakefile* context)
  2401. {
  2402. // Look for link-type keywords in the value.
  2403. static cmsys::RegularExpression
  2404. keys("(^|;)(debug|optimized|general)(;|$)");
  2405. if(!keys.find(value))
  2406. {
  2407. return;
  2408. }
  2409. // Report an error.
  2410. cmOStringStream e;
  2411. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  2412. "keyword \"" << keys.match(2) << "\". The INTERFACE_LINK_LIBRARIES "
  2413. "property may contain configuration-sensitive generator-expressions "
  2414. "which may be used to specify per-configuration rules.";
  2415. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2416. }
  2417. //----------------------------------------------------------------------------
  2418. void cmTarget::CheckProperty(const std::string& prop,
  2419. cmMakefile* context) const
  2420. {
  2421. // Certain properties need checking.
  2422. if(cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES"))
  2423. {
  2424. if(const char* value = this->GetProperty(prop))
  2425. {
  2426. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  2427. }
  2428. }
  2429. if(cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES"))
  2430. {
  2431. if(const char* value = this->GetProperty(prop))
  2432. {
  2433. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  2434. }
  2435. }
  2436. if(cmHasLiteralPrefix(prop, "INTERFACE_LINK_LIBRARIES"))
  2437. {
  2438. if(const char* value = this->GetProperty(prop))
  2439. {
  2440. cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
  2441. }
  2442. }
  2443. }
  2444. //----------------------------------------------------------------------------
  2445. void cmTarget::MarkAsImported()
  2446. {
  2447. this->IsImportedTarget = true;
  2448. }
  2449. //----------------------------------------------------------------------------
  2450. bool cmTarget::HaveWellDefinedOutputFiles() const
  2451. {
  2452. return
  2453. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2454. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2455. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2456. this->GetType() == cmTarget::EXECUTABLE;
  2457. }
  2458. //----------------------------------------------------------------------------
  2459. cmTarget::OutputInfo const* cmTarget::GetOutputInfo(
  2460. const std::string& config) const
  2461. {
  2462. // There is no output information for imported targets.
  2463. if(this->IsImported())
  2464. {
  2465. return 0;
  2466. }
  2467. // Only libraries and executables have well-defined output files.
  2468. if(!this->HaveWellDefinedOutputFiles())
  2469. {
  2470. std::string msg = "cmTarget::GetOutputInfo called for ";
  2471. msg += this->GetName();
  2472. msg += " which has type ";
  2473. msg += cmTarget::GetTargetTypeName(this->GetType());
  2474. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2475. return 0;
  2476. }
  2477. // Lookup/compute/cache the output information for this configuration.
  2478. std::string config_upper;
  2479. if(!config.empty())
  2480. {
  2481. config_upper = cmSystemTools::UpperCase(config);
  2482. }
  2483. typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
  2484. OutputInfoMapType::const_iterator i =
  2485. this->Internal->OutputInfoMap.find(config_upper);
  2486. if(i == this->Internal->OutputInfoMap.end())
  2487. {
  2488. OutputInfo info;
  2489. this->ComputeOutputDir(config, false, info.OutDir);
  2490. this->ComputeOutputDir(config, true, info.ImpDir);
  2491. if(!this->ComputePDBOutputDir("PDB", config, info.PdbDir))
  2492. {
  2493. info.PdbDir = info.OutDir;
  2494. }
  2495. OutputInfoMapType::value_type entry(config_upper, info);
  2496. i = this->Internal->OutputInfoMap.insert(entry).first;
  2497. }
  2498. return &i->second;
  2499. }
  2500. //----------------------------------------------------------------------------
  2501. cmTarget::CompileInfo const* cmTarget::GetCompileInfo(
  2502. const std::string& config) const
  2503. {
  2504. // There is no compile information for imported targets.
  2505. if(this->IsImported())
  2506. {
  2507. return 0;
  2508. }
  2509. if(this->GetType() > cmTarget::OBJECT_LIBRARY)
  2510. {
  2511. std::string msg = "cmTarget::GetCompileInfo called for ";
  2512. msg += this->GetName();
  2513. msg += " which has type ";
  2514. msg += cmTarget::GetTargetTypeName(this->GetType());
  2515. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2516. return 0;
  2517. }
  2518. // Lookup/compute/cache the compile information for this configuration.
  2519. std::string config_upper;
  2520. if(!config.empty())
  2521. {
  2522. config_upper = cmSystemTools::UpperCase(config);
  2523. }
  2524. typedef cmTargetInternals::CompileInfoMapType CompileInfoMapType;
  2525. CompileInfoMapType::const_iterator i =
  2526. this->Internal->CompileInfoMap.find(config_upper);
  2527. if(i == this->Internal->CompileInfoMap.end())
  2528. {
  2529. CompileInfo info;
  2530. this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  2531. CompileInfoMapType::value_type entry(config_upper, info);
  2532. i = this->Internal->CompileInfoMap.insert(entry).first;
  2533. }
  2534. return &i->second;
  2535. }
  2536. //----------------------------------------------------------------------------
  2537. std::string cmTarget::GetDirectory(const std::string& config,
  2538. bool implib) const
  2539. {
  2540. if (this->IsImported())
  2541. {
  2542. // Return the directory from which the target is imported.
  2543. return
  2544. cmSystemTools::GetFilenamePath(
  2545. this->ImportedGetFullPath(config, implib));
  2546. }
  2547. else if(OutputInfo const* info = this->GetOutputInfo(config))
  2548. {
  2549. // Return the directory in which the target will be built.
  2550. return implib? info->ImpDir : info->OutDir;
  2551. }
  2552. return "";
  2553. }
  2554. //----------------------------------------------------------------------------
  2555. std::string cmTarget::GetPDBDirectory(const std::string& config) const
  2556. {
  2557. if(OutputInfo const* info = this->GetOutputInfo(config))
  2558. {
  2559. // Return the directory in which the target will be built.
  2560. return info->PdbDir;
  2561. }
  2562. return "";
  2563. }
  2564. //----------------------------------------------------------------------------
  2565. std::string cmTarget::GetCompilePDBDirectory(const std::string& config) const
  2566. {
  2567. if(CompileInfo const* info = this->GetCompileInfo(config))
  2568. {
  2569. return info->CompilePdbDir;
  2570. }
  2571. return "";
  2572. }
  2573. //----------------------------------------------------------------------------
  2574. const char* cmTarget::GetLocation(const std::string& config) const
  2575. {
  2576. static std::string location;
  2577. if (this->IsImported())
  2578. {
  2579. location = this->ImportedGetFullPath(config, false);
  2580. }
  2581. else
  2582. {
  2583. location = this->GetFullPath(config, false);
  2584. }
  2585. return location.c_str();
  2586. }
  2587. //----------------------------------------------------------------------------
  2588. const char* cmTarget::GetLocationForBuild() const
  2589. {
  2590. static std::string location;
  2591. if(this->IsImported())
  2592. {
  2593. location = this->ImportedGetFullPath("", false);
  2594. return location.c_str();
  2595. }
  2596. // Now handle the deprecated build-time configuration location.
  2597. location = this->GetDirectory();
  2598. if(!location.empty())
  2599. {
  2600. location += "/";
  2601. }
  2602. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  2603. if(cfgid && strcmp(cfgid, ".") != 0)
  2604. {
  2605. location += "/";
  2606. location += cfgid;
  2607. location += "/";
  2608. }
  2609. if(this->IsAppBundleOnApple())
  2610. {
  2611. std::string macdir = this->BuildMacContentDirectory("", "", false);
  2612. if(!macdir.empty())
  2613. {
  2614. location += "/";
  2615. location += macdir;
  2616. }
  2617. }
  2618. location += "/";
  2619. location += this->GetFullName("", false);
  2620. return location.c_str();
  2621. }
  2622. //----------------------------------------------------------------------------
  2623. void cmTarget::GetTargetVersion(int& major, int& minor) const
  2624. {
  2625. int patch;
  2626. this->GetTargetVersion(false, major, minor, patch);
  2627. }
  2628. //----------------------------------------------------------------------------
  2629. void cmTarget::GetTargetVersion(bool soversion,
  2630. int& major, int& minor, int& patch) const
  2631. {
  2632. // Set the default values.
  2633. major = 0;
  2634. minor = 0;
  2635. patch = 0;
  2636. assert(this->GetType() != INTERFACE_LIBRARY);
  2637. // Look for a VERSION or SOVERSION property.
  2638. const char* prop = soversion? "SOVERSION" : "VERSION";
  2639. if(const char* version = this->GetProperty(prop))
  2640. {
  2641. // Try to parse the version number and store the results that were
  2642. // successfully parsed.
  2643. int parsed_major;
  2644. int parsed_minor;
  2645. int parsed_patch;
  2646. switch(sscanf(version, "%d.%d.%d",
  2647. &parsed_major, &parsed_minor, &parsed_patch))
  2648. {
  2649. case 3: patch = parsed_patch; // no break!
  2650. case 2: minor = parsed_minor; // no break!
  2651. case 1: major = parsed_major; // no break!
  2652. default: break;
  2653. }
  2654. }
  2655. }
  2656. //----------------------------------------------------------------------------
  2657. const char* cmTarget::GetFeature(const std::string& feature,
  2658. const std::string& config) const
  2659. {
  2660. if(!config.empty())
  2661. {
  2662. std::string featureConfig = feature;
  2663. featureConfig += "_";
  2664. featureConfig += cmSystemTools::UpperCase(config);
  2665. if(const char* value = this->GetProperty(featureConfig))
  2666. {
  2667. return value;
  2668. }
  2669. }
  2670. if(const char* value = this->GetProperty(feature))
  2671. {
  2672. return value;
  2673. }
  2674. return this->Makefile->GetFeature(feature, config);
  2675. }
  2676. //----------------------------------------------------------------------------
  2677. const char *cmTarget::GetProperty(const std::string& prop) const
  2678. {
  2679. return this->GetProperty(prop, cmProperty::TARGET);
  2680. }
  2681. //----------------------------------------------------------------------------
  2682. bool cmTarget::HandleLocationPropertyPolicy() const
  2683. {
  2684. if (this->IsImported())
  2685. {
  2686. return true;
  2687. }
  2688. cmOStringStream e;
  2689. const char *modal = 0;
  2690. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  2691. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0026))
  2692. {
  2693. case cmPolicies::WARN:
  2694. e << (this->Makefile->GetPolicies()
  2695. ->GetPolicyWarning(cmPolicies::CMP0026)) << "\n";
  2696. modal = "should";
  2697. case cmPolicies::OLD:
  2698. break;
  2699. case cmPolicies::REQUIRED_ALWAYS:
  2700. case cmPolicies::REQUIRED_IF_USED:
  2701. case cmPolicies::NEW:
  2702. modal = "may";
  2703. messageType = cmake::FATAL_ERROR;
  2704. }
  2705. if (modal)
  2706. {
  2707. e << "The LOCATION property " << modal << " not be read from target \""
  2708. << this->GetName() << "\". Use the target name directly with "
  2709. "add_custom_command, or use the generator expression $<TARGET_FILE>, "
  2710. "as appropriate.\n";
  2711. this->Makefile->IssueMessage(messageType, e.str());
  2712. }
  2713. return messageType != cmake::FATAL_ERROR;
  2714. }
  2715. //----------------------------------------------------------------------------
  2716. const char *cmTarget::GetProperty(const std::string& prop,
  2717. cmProperty::ScopeType scope) const
  2718. {
  2719. if (this->GetType() == INTERFACE_LIBRARY
  2720. && !whiteListedInterfaceProperty(prop))
  2721. {
  2722. cmOStringStream e;
  2723. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  2724. "The property \"" << prop << "\" is not allowed.";
  2725. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  2726. return 0;
  2727. }
  2728. if (prop == "NAME")
  2729. {
  2730. return this->GetName().c_str();
  2731. }
  2732. // Watch for special "computed" properties that are dependent on
  2733. // other properties or variables. Always recompute them.
  2734. if(this->GetType() == cmTarget::EXECUTABLE ||
  2735. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2736. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2737. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2738. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  2739. {
  2740. if(prop == "LOCATION")
  2741. {
  2742. if (!this->HandleLocationPropertyPolicy())
  2743. {
  2744. return 0;
  2745. }
  2746. // Set the LOCATION property of the target.
  2747. //
  2748. // For an imported target this is the location of an arbitrary
  2749. // available configuration.
  2750. //
  2751. // For a non-imported target this is deprecated because it
  2752. // cannot take into account the per-configuration name of the
  2753. // target because the configuration type may not be known at
  2754. // CMake time.
  2755. this->Properties.SetProperty("LOCATION", this->GetLocationForBuild(),
  2756. cmProperty::TARGET);
  2757. }
  2758. // Support "LOCATION_<CONFIG>".
  2759. if(cmHasLiteralPrefix(prop, "LOCATION_"))
  2760. {
  2761. if (!this->HandleLocationPropertyPolicy())
  2762. {
  2763. return 0;
  2764. }
  2765. const char* configName = prop.c_str() + 9;
  2766. this->Properties.SetProperty(prop,
  2767. this->GetLocation(configName),
  2768. cmProperty::TARGET);
  2769. }
  2770. // Support "<CONFIG>_LOCATION".
  2771. if(cmHasLiteralSuffix(prop, "_LOCATION"))
  2772. {
  2773. std::string configName(prop.c_str(), prop.size() - 9);
  2774. if(configName != "IMPORTED")
  2775. {
  2776. if (!this->HandleLocationPropertyPolicy())
  2777. {
  2778. return 0;
  2779. }
  2780. this->Properties.SetProperty(prop,
  2781. this->GetLocation(configName),
  2782. cmProperty::TARGET);
  2783. }
  2784. }
  2785. }
  2786. if(prop == "INCLUDE_DIRECTORIES")
  2787. {
  2788. static std::string output;
  2789. output = "";
  2790. std::string sep;
  2791. typedef cmTargetInternals::TargetPropertyEntry
  2792. TargetPropertyEntry;
  2793. for (std::vector<TargetPropertyEntry*>::const_iterator
  2794. it = this->Internal->IncludeDirectoriesEntries.begin(),
  2795. end = this->Internal->IncludeDirectoriesEntries.end();
  2796. it != end; ++it)
  2797. {
  2798. output += sep;
  2799. output += (*it)->ge->GetInput();
  2800. sep = ";";
  2801. }
  2802. return output.c_str();
  2803. }
  2804. if(prop == "COMPILE_OPTIONS")
  2805. {
  2806. static std::string output;
  2807. output = "";
  2808. std::string sep;
  2809. typedef cmTargetInternals::TargetPropertyEntry
  2810. TargetPropertyEntry;
  2811. for (std::vector<TargetPropertyEntry*>::const_iterator
  2812. it = this->Internal->CompileOptionsEntries.begin(),
  2813. end = this->Internal->CompileOptionsEntries.end();
  2814. it != end; ++it)
  2815. {
  2816. output += sep;
  2817. output += (*it)->ge->GetInput();
  2818. sep = ";";
  2819. }
  2820. return output.c_str();
  2821. }
  2822. if(prop == "COMPILE_DEFINITIONS")
  2823. {
  2824. static std::string output;
  2825. output = "";
  2826. std::string sep;
  2827. typedef cmTargetInternals::TargetPropertyEntry
  2828. TargetPropertyEntry;
  2829. for (std::vector<TargetPropertyEntry*>::const_iterator
  2830. it = this->Internal->CompileDefinitionsEntries.begin(),
  2831. end = this->Internal->CompileDefinitionsEntries.end();
  2832. it != end; ++it)
  2833. {
  2834. output += sep;
  2835. output += (*it)->ge->GetInput();
  2836. sep = ";";
  2837. }
  2838. return output.c_str();
  2839. }
  2840. if(prop == "LINK_LIBRARIES")
  2841. {
  2842. static std::string output;
  2843. output = "";
  2844. std::string sep;
  2845. for (std::vector<cmValueWithOrigin>::const_iterator
  2846. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  2847. end = this->Internal->LinkImplementationPropertyEntries.end();
  2848. it != end; ++it)
  2849. {
  2850. output += sep;
  2851. output += it->Value;
  2852. sep = ";";
  2853. }
  2854. return output.c_str();
  2855. }
  2856. if (prop == "IMPORTED")
  2857. {
  2858. return this->IsImported()?"TRUE":"FALSE";
  2859. }
  2860. if(prop == "SOURCES")
  2861. {
  2862. cmOStringStream ss;
  2863. const char* sep = "";
  2864. typedef cmTargetInternals::TargetPropertyEntry
  2865. TargetPropertyEntry;
  2866. for(std::vector<TargetPropertyEntry*>::const_iterator
  2867. i = this->Internal->SourceEntries.begin();
  2868. i != this->Internal->SourceEntries.end(); ++i)
  2869. {
  2870. std::string entry = (*i)->ge->GetInput();
  2871. std::vector<std::string> files;
  2872. cmSystemTools::ExpandListArgument(entry, files);
  2873. for (std::vector<std::string>::const_iterator
  2874. li = files.begin(); li != files.end(); ++li)
  2875. {
  2876. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  2877. (*li)[li->size() - 1] == '>')
  2878. {
  2879. std::string objLibName = li->substr(17, li->size()-18);
  2880. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  2881. {
  2882. ss << sep;
  2883. sep = ";";
  2884. ss << *li;
  2885. continue;
  2886. }
  2887. bool addContent = false;
  2888. bool noMessage = true;
  2889. cmOStringStream e;
  2890. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  2891. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0051))
  2892. {
  2893. case cmPolicies::WARN:
  2894. e << (this->Makefile->GetPolicies()
  2895. ->GetPolicyWarning(cmPolicies::CMP0051)) << "\n";
  2896. noMessage = false;
  2897. case cmPolicies::OLD:
  2898. break;
  2899. case cmPolicies::REQUIRED_ALWAYS:
  2900. case cmPolicies::REQUIRED_IF_USED:
  2901. case cmPolicies::NEW:
  2902. addContent = true;
  2903. }
  2904. if (!noMessage)
  2905. {
  2906. e << "Target \"" << this->Name << "\" contains $<TARGET_OBJECTS> "
  2907. "generator expression in its sources list. This content was not "
  2908. "previously part of the SOURCES property when that property was "
  2909. "read at configure time. Code reading that property needs to be "
  2910. "adapted to ignore the generator expression using the "
  2911. "string(GENEX_STRIP) command.";
  2912. this->Makefile->IssueMessage(messageType, e.str());
  2913. }
  2914. if (addContent)
  2915. {
  2916. ss << sep;
  2917. sep = ";";
  2918. ss << *li;
  2919. }
  2920. }
  2921. else if (cmGeneratorExpression::Find(*li) == std::string::npos)
  2922. {
  2923. ss << sep;
  2924. sep = ";";
  2925. ss << *li;
  2926. }
  2927. else
  2928. {
  2929. cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li);
  2930. // Construct what is known about this source file location.
  2931. cmSourceFileLocation const& location = sf->GetLocation();
  2932. std::string sname = location.GetDirectory();
  2933. if(!sname.empty())
  2934. {
  2935. sname += "/";
  2936. }
  2937. sname += location.GetName();
  2938. ss << sep;
  2939. sep = ";";
  2940. // Append this list entry.
  2941. ss << sname;
  2942. }
  2943. }
  2944. }
  2945. this->Properties.SetProperty("SOURCES", ss.str().c_str(),
  2946. cmProperty::TARGET);
  2947. }
  2948. // the type property returns what type the target is
  2949. if (prop == "TYPE")
  2950. {
  2951. return cmTarget::GetTargetTypeName(this->GetType());
  2952. }
  2953. bool chain = false;
  2954. const char *retVal =
  2955. this->Properties.GetPropertyValue(prop, scope, chain);
  2956. if (chain)
  2957. {
  2958. return this->Makefile->GetProperty(prop,scope);
  2959. }
  2960. return retVal;
  2961. }
  2962. //----------------------------------------------------------------------------
  2963. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  2964. {
  2965. return cmSystemTools::IsOn(this->GetProperty(prop));
  2966. }
  2967. //----------------------------------------------------------------------------
  2968. class cmTargetCollectLinkLanguages
  2969. {
  2970. public:
  2971. cmTargetCollectLinkLanguages(cmTarget const* target,
  2972. const std::string& config,
  2973. std::set<std::string>& languages,
  2974. cmTarget const* head):
  2975. Config(config), Languages(languages), HeadTarget(head),
  2976. Makefile(target->GetMakefile()), Target(target)
  2977. { this->Visited.insert(target); }
  2978. void Visit(const std::string& name)
  2979. {
  2980. cmTarget *target = this->Makefile->FindTargetToUse(name);
  2981. if(!target)
  2982. {
  2983. if(name.find("::") != std::string::npos)
  2984. {
  2985. bool noMessage = false;
  2986. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2987. cmOStringStream e;
  2988. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
  2989. {
  2990. case cmPolicies::WARN:
  2991. {
  2992. e << (this->Makefile->GetPolicies()
  2993. ->GetPolicyWarning(cmPolicies::CMP0028)) << "\n";
  2994. messageType = cmake::AUTHOR_WARNING;
  2995. }
  2996. break;
  2997. case cmPolicies::OLD:
  2998. noMessage = true;
  2999. case cmPolicies::REQUIRED_IF_USED:
  3000. case cmPolicies::REQUIRED_ALWAYS:
  3001. case cmPolicies::NEW:
  3002. // Issue the fatal message.
  3003. break;
  3004. }
  3005. if(!noMessage)
  3006. {
  3007. e << "Target \"" << this->Target->GetName()
  3008. << "\" links to target \"" << name
  3009. << "\" but the target was not found. Perhaps a find_package() "
  3010. "call is missing for an IMPORTED target, or an ALIAS target is "
  3011. "missing?";
  3012. this->Makefile->GetCMakeInstance()->IssueMessage(messageType,
  3013. e.str(),
  3014. this->Target->GetBacktrace());
  3015. }
  3016. }
  3017. return;
  3018. }
  3019. if(!this->Visited.insert(target).second)
  3020. {
  3021. return;
  3022. }
  3023. cmTarget::LinkInterface const* iface =
  3024. target->GetLinkInterface(this->Config, this->HeadTarget);
  3025. if(!iface) { return; }
  3026. for(std::vector<std::string>::const_iterator
  3027. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  3028. {
  3029. this->Languages.insert(*li);
  3030. }
  3031. for(std::vector<std::string>::const_iterator
  3032. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  3033. {
  3034. this->Visit(*li);
  3035. }
  3036. }
  3037. private:
  3038. std::string Config;
  3039. std::set<std::string>& Languages;
  3040. cmTarget const* HeadTarget;
  3041. cmMakefile* Makefile;
  3042. const cmTarget* Target;
  3043. std::set<cmTarget const*> Visited;
  3044. };
  3045. //----------------------------------------------------------------------------
  3046. std::string cmTarget::GetLinkerLanguage(const std::string& config,
  3047. cmTarget const* head) const
  3048. {
  3049. cmTarget const* headTarget = head ? head : this;
  3050. return this->GetLinkClosure(config, headTarget)->LinkerLanguage;
  3051. }
  3052. //----------------------------------------------------------------------------
  3053. cmTarget::LinkClosure const* cmTarget::GetLinkClosure(
  3054. const std::string& config,
  3055. cmTarget const* head) const
  3056. {
  3057. TargetConfigPair key(head, cmSystemTools::UpperCase(config));
  3058. cmTargetInternals::LinkClosureMapType::iterator
  3059. i = this->Internal->LinkClosureMap.find(key);
  3060. if(i == this->Internal->LinkClosureMap.end())
  3061. {
  3062. LinkClosure lc;
  3063. this->ComputeLinkClosure(config, lc, head);
  3064. cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
  3065. i = this->Internal->LinkClosureMap.insert(entry).first;
  3066. }
  3067. return &i->second;
  3068. }
  3069. //----------------------------------------------------------------------------
  3070. class cmTargetSelectLinker
  3071. {
  3072. int Preference;
  3073. cmTarget const* Target;
  3074. cmMakefile* Makefile;
  3075. cmGlobalGenerator* GG;
  3076. std::set<std::string> Preferred;
  3077. public:
  3078. cmTargetSelectLinker(cmTarget const* target): Preference(0), Target(target)
  3079. {
  3080. this->Makefile = this->Target->GetMakefile();
  3081. this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  3082. }
  3083. void Consider(const std::string& lang)
  3084. {
  3085. int preference = this->GG->GetLinkerPreference(lang);
  3086. if(preference > this->Preference)
  3087. {
  3088. this->Preference = preference;
  3089. this->Preferred.clear();
  3090. }
  3091. if(preference == this->Preference)
  3092. {
  3093. this->Preferred.insert(lang);
  3094. }
  3095. }
  3096. std::string Choose()
  3097. {
  3098. if(this->Preferred.empty())
  3099. {
  3100. return "";
  3101. }
  3102. else if(this->Preferred.size() > 1)
  3103. {
  3104. cmOStringStream e;
  3105. e << "Target " << this->Target->GetName()
  3106. << " contains multiple languages with the highest linker preference"
  3107. << " (" << this->Preference << "):\n";
  3108. for(std::set<std::string>::const_iterator
  3109. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  3110. {
  3111. e << " " << *li << "\n";
  3112. }
  3113. e << "Set the LINKER_LANGUAGE property for this target.";
  3114. cmake* cm = this->Makefile->GetCMakeInstance();
  3115. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  3116. this->Target->GetBacktrace());
  3117. }
  3118. return *this->Preferred.begin();
  3119. }
  3120. };
  3121. //----------------------------------------------------------------------------
  3122. void cmTarget::ComputeLinkClosure(const std::string& config, LinkClosure& lc,
  3123. cmTarget const* head) const
  3124. {
  3125. // Get languages built in this target.
  3126. std::set<std::string> languages;
  3127. LinkImplementation const* impl = this->GetLinkImplementation(config, head);
  3128. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3129. li != impl->Languages.end(); ++li)
  3130. {
  3131. languages.insert(*li);
  3132. }
  3133. // Add interface languages from linked targets.
  3134. cmTargetCollectLinkLanguages cll(this, config, languages, head);
  3135. for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
  3136. li != impl->Libraries.end(); ++li)
  3137. {
  3138. cll.Visit(*li);
  3139. }
  3140. // Store the transitive closure of languages.
  3141. for(std::set<std::string>::const_iterator li = languages.begin();
  3142. li != languages.end(); ++li)
  3143. {
  3144. lc.Languages.push_back(*li);
  3145. }
  3146. // Choose the language whose linker should be used.
  3147. if(this->GetProperty("HAS_CXX"))
  3148. {
  3149. lc.LinkerLanguage = "CXX";
  3150. }
  3151. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  3152. {
  3153. lc.LinkerLanguage = linkerLang;
  3154. }
  3155. else
  3156. {
  3157. // Find the language with the highest preference value.
  3158. cmTargetSelectLinker tsl(this);
  3159. // First select from the languages compiled directly in this target.
  3160. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3161. li != impl->Languages.end(); ++li)
  3162. {
  3163. tsl.Consider(*li);
  3164. }
  3165. // Now consider languages that propagate from linked targets.
  3166. for(std::set<std::string>::const_iterator sit = languages.begin();
  3167. sit != languages.end(); ++sit)
  3168. {
  3169. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  3170. if(this->Makefile->IsOn(propagates))
  3171. {
  3172. tsl.Consider(*sit);
  3173. }
  3174. }
  3175. lc.LinkerLanguage = tsl.Choose();
  3176. }
  3177. }
  3178. //----------------------------------------------------------------------------
  3179. const char* cmTarget::GetSuffixVariableInternal(bool implib) const
  3180. {
  3181. switch(this->GetType())
  3182. {
  3183. case cmTarget::STATIC_LIBRARY:
  3184. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  3185. case cmTarget::SHARED_LIBRARY:
  3186. return (implib
  3187. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3188. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  3189. case cmTarget::MODULE_LIBRARY:
  3190. return (implib
  3191. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3192. : "CMAKE_SHARED_MODULE_SUFFIX");
  3193. case cmTarget::EXECUTABLE:
  3194. return (implib
  3195. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3196. : "CMAKE_EXECUTABLE_SUFFIX");
  3197. default:
  3198. break;
  3199. }
  3200. return "";
  3201. }
  3202. //----------------------------------------------------------------------------
  3203. const char* cmTarget::GetPrefixVariableInternal(bool implib) const
  3204. {
  3205. switch(this->GetType())
  3206. {
  3207. case cmTarget::STATIC_LIBRARY:
  3208. return "CMAKE_STATIC_LIBRARY_PREFIX";
  3209. case cmTarget::SHARED_LIBRARY:
  3210. return (implib
  3211. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3212. : "CMAKE_SHARED_LIBRARY_PREFIX");
  3213. case cmTarget::MODULE_LIBRARY:
  3214. return (implib
  3215. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3216. : "CMAKE_SHARED_MODULE_PREFIX");
  3217. case cmTarget::EXECUTABLE:
  3218. return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
  3219. default:
  3220. break;
  3221. }
  3222. return "";
  3223. }
  3224. //----------------------------------------------------------------------------
  3225. std::string cmTarget::GetPDBName(const std::string& config) const
  3226. {
  3227. std::string prefix;
  3228. std::string base;
  3229. std::string suffix;
  3230. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3231. std::vector<std::string> props;
  3232. std::string configUpper = cmSystemTools::UpperCase(config);
  3233. if(!configUpper.empty())
  3234. {
  3235. // PDB_NAME_<CONFIG>
  3236. props.push_back("PDB_NAME_" + configUpper);
  3237. }
  3238. // PDB_NAME
  3239. props.push_back("PDB_NAME");
  3240. for(std::vector<std::string>::const_iterator i = props.begin();
  3241. i != props.end(); ++i)
  3242. {
  3243. if(const char* outName = this->GetProperty(*i))
  3244. {
  3245. base = outName;
  3246. break;
  3247. }
  3248. }
  3249. return prefix+base+".pdb";
  3250. }
  3251. //----------------------------------------------------------------------------
  3252. std::string cmTarget::GetCompilePDBName(const std::string& config) const
  3253. {
  3254. std::string prefix;
  3255. std::string base;
  3256. std::string suffix;
  3257. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3258. // Check for a per-configuration output directory target property.
  3259. std::string configUpper = cmSystemTools::UpperCase(config);
  3260. std::string configProp = "COMPILE_PDB_NAME_";
  3261. configProp += configUpper;
  3262. const char* config_name = this->GetProperty(configProp);
  3263. if(config_name && *config_name)
  3264. {
  3265. return prefix + config_name + ".pdb";
  3266. }
  3267. const char* name = this->GetProperty("COMPILE_PDB_NAME");
  3268. if(name && *name)
  3269. {
  3270. return prefix + name + ".pdb";
  3271. }
  3272. return "";
  3273. }
  3274. //----------------------------------------------------------------------------
  3275. std::string cmTarget::GetCompilePDBPath(const std::string& config) const
  3276. {
  3277. std::string dir = this->GetCompilePDBDirectory(config);
  3278. std::string name = this->GetCompilePDBName(config);
  3279. if(dir.empty() && !name.empty())
  3280. {
  3281. dir = this->GetPDBDirectory(config);
  3282. }
  3283. if(!dir.empty())
  3284. {
  3285. dir += "/";
  3286. }
  3287. return dir + name;
  3288. }
  3289. //----------------------------------------------------------------------------
  3290. bool cmTarget::HasSOName(const std::string& config) const
  3291. {
  3292. // soname is supported only for shared libraries and modules,
  3293. // and then only when the platform supports an soname flag.
  3294. return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
  3295. this->GetType() == cmTarget::MODULE_LIBRARY) &&
  3296. !this->GetPropertyAsBool("NO_SONAME") &&
  3297. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config,
  3298. this)));
  3299. }
  3300. //----------------------------------------------------------------------------
  3301. std::string cmTarget::GetSOName(const std::string& config) const
  3302. {
  3303. if(this->IsImported())
  3304. {
  3305. // Lookup the imported soname.
  3306. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3307. {
  3308. if(info->NoSOName)
  3309. {
  3310. // The imported library has no builtin soname so the name
  3311. // searched at runtime will be just the filename.
  3312. return cmSystemTools::GetFilenameName(info->Location);
  3313. }
  3314. else
  3315. {
  3316. // Use the soname given if any.
  3317. if(info->SOName.find("@rpath/") == 0)
  3318. {
  3319. return info->SOName.substr(6);
  3320. }
  3321. return info->SOName;
  3322. }
  3323. }
  3324. else
  3325. {
  3326. return "";
  3327. }
  3328. }
  3329. else
  3330. {
  3331. // Compute the soname that will be built.
  3332. std::string name;
  3333. std::string soName;
  3334. std::string realName;
  3335. std::string impName;
  3336. std::string pdbName;
  3337. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3338. return soName;
  3339. }
  3340. }
  3341. //----------------------------------------------------------------------------
  3342. bool cmTarget::HasMacOSXRpathInstallNameDir(const std::string& config) const
  3343. {
  3344. bool install_name_is_rpath = false;
  3345. bool macosx_rpath = false;
  3346. if(!this->IsImportedTarget)
  3347. {
  3348. if(this->GetType() != cmTarget::SHARED_LIBRARY)
  3349. {
  3350. return false;
  3351. }
  3352. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  3353. bool use_install_name =
  3354. this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  3355. if(install_name && use_install_name &&
  3356. std::string(install_name) == "@rpath")
  3357. {
  3358. install_name_is_rpath = true;
  3359. }
  3360. else if(install_name && use_install_name)
  3361. {
  3362. return false;
  3363. }
  3364. if(!install_name_is_rpath)
  3365. {
  3366. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  3367. }
  3368. }
  3369. else
  3370. {
  3371. // Lookup the imported soname.
  3372. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3373. {
  3374. if(!info->NoSOName && !info->SOName.empty())
  3375. {
  3376. if(info->SOName.find("@rpath/") == 0)
  3377. {
  3378. install_name_is_rpath = true;
  3379. }
  3380. }
  3381. else
  3382. {
  3383. std::string install_name;
  3384. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  3385. if(install_name.find("@rpath") != std::string::npos)
  3386. {
  3387. install_name_is_rpath = true;
  3388. }
  3389. }
  3390. }
  3391. }
  3392. if(!install_name_is_rpath && !macosx_rpath)
  3393. {
  3394. return false;
  3395. }
  3396. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  3397. {
  3398. cmOStringStream w;
  3399. w << "Attempting to use";
  3400. if(macosx_rpath)
  3401. {
  3402. w << " MACOSX_RPATH";
  3403. }
  3404. else
  3405. {
  3406. w << " @rpath";
  3407. }
  3408. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  3409. w << " This could be because you are using a Mac OS X version";
  3410. w << " less than 10.5 or because CMake's platform configuration is";
  3411. w << " corrupt.";
  3412. cmake* cm = this->Makefile->GetCMakeInstance();
  3413. cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
  3414. }
  3415. return true;
  3416. }
  3417. //----------------------------------------------------------------------------
  3418. bool cmTarget::MacOSXRpathInstallNameDirDefault() const
  3419. {
  3420. // we can't do rpaths when unsupported
  3421. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  3422. {
  3423. return false;
  3424. }
  3425. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  3426. if(macosx_rpath_str)
  3427. {
  3428. return this->GetPropertyAsBool("MACOSX_RPATH");
  3429. }
  3430. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  3431. if(cmp0042 == cmPolicies::WARN)
  3432. {
  3433. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3434. AddCMP0042WarnTarget(this->GetName());
  3435. }
  3436. if(cmp0042 == cmPolicies::NEW)
  3437. {
  3438. return true;
  3439. }
  3440. return false;
  3441. }
  3442. //----------------------------------------------------------------------------
  3443. bool cmTarget::IsImportedSharedLibWithoutSOName(
  3444. const std::string& config) const
  3445. {
  3446. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  3447. {
  3448. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3449. {
  3450. return info->NoSOName;
  3451. }
  3452. }
  3453. return false;
  3454. }
  3455. //----------------------------------------------------------------------------
  3456. std::string cmTarget::NormalGetRealName(const std::string& config) const
  3457. {
  3458. // This should not be called for imported targets.
  3459. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3460. // enforcement of the limited imported target API.
  3461. if(this->IsImported())
  3462. {
  3463. std::string msg = "NormalGetRealName called on imported target: ";
  3464. msg += this->GetName();
  3465. this->GetMakefile()->
  3466. IssueMessage(cmake::INTERNAL_ERROR,
  3467. msg);
  3468. }
  3469. if(this->GetType() == cmTarget::EXECUTABLE)
  3470. {
  3471. // Compute the real name that will be built.
  3472. std::string name;
  3473. std::string realName;
  3474. std::string impName;
  3475. std::string pdbName;
  3476. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3477. return realName;
  3478. }
  3479. else
  3480. {
  3481. // Compute the real name that will be built.
  3482. std::string name;
  3483. std::string soName;
  3484. std::string realName;
  3485. std::string impName;
  3486. std::string pdbName;
  3487. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3488. return realName;
  3489. }
  3490. }
  3491. //----------------------------------------------------------------------------
  3492. std::string cmTarget::GetFullName(const std::string& config,
  3493. bool implib) const
  3494. {
  3495. if(this->IsImported())
  3496. {
  3497. return this->GetFullNameImported(config, implib);
  3498. }
  3499. else
  3500. {
  3501. return this->GetFullNameInternal(config, implib);
  3502. }
  3503. }
  3504. //----------------------------------------------------------------------------
  3505. std::string
  3506. cmTarget::GetFullNameImported(const std::string& config, bool implib) const
  3507. {
  3508. return cmSystemTools::GetFilenameName(
  3509. this->ImportedGetFullPath(config, implib));
  3510. }
  3511. //----------------------------------------------------------------------------
  3512. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  3513. std::string& suffix,
  3514. const std::string& config,
  3515. bool implib) const
  3516. {
  3517. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3518. }
  3519. //----------------------------------------------------------------------------
  3520. std::string cmTarget::GetFullPath(const std::string& config, bool implib,
  3521. bool realname) const
  3522. {
  3523. if(this->IsImported())
  3524. {
  3525. return this->ImportedGetFullPath(config, implib);
  3526. }
  3527. else
  3528. {
  3529. return this->NormalGetFullPath(config, implib, realname);
  3530. }
  3531. }
  3532. //----------------------------------------------------------------------------
  3533. std::string cmTarget::NormalGetFullPath(const std::string& config,
  3534. bool implib, bool realname) const
  3535. {
  3536. std::string fpath = this->GetDirectory(config, implib);
  3537. fpath += "/";
  3538. if(this->IsAppBundleOnApple())
  3539. {
  3540. fpath = this->BuildMacContentDirectory(fpath, config, false);
  3541. fpath += "/";
  3542. }
  3543. // Add the full name of the target.
  3544. if(implib)
  3545. {
  3546. fpath += this->GetFullName(config, true);
  3547. }
  3548. else if(realname)
  3549. {
  3550. fpath += this->NormalGetRealName(config);
  3551. }
  3552. else
  3553. {
  3554. fpath += this->GetFullName(config, false);
  3555. }
  3556. return fpath;
  3557. }
  3558. //----------------------------------------------------------------------------
  3559. std::string
  3560. cmTarget::ImportedGetFullPath(const std::string& config, bool implib) const
  3561. {
  3562. std::string result;
  3563. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3564. {
  3565. result = implib? info->ImportLibrary : info->Location;
  3566. }
  3567. if(result.empty())
  3568. {
  3569. result = this->GetName();
  3570. result += "-NOTFOUND";
  3571. }
  3572. return result;
  3573. }
  3574. //----------------------------------------------------------------------------
  3575. std::string
  3576. cmTarget::GetFullNameInternal(const std::string& config, bool implib) const
  3577. {
  3578. std::string prefix;
  3579. std::string base;
  3580. std::string suffix;
  3581. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3582. return prefix+base+suffix;
  3583. }
  3584. //----------------------------------------------------------------------------
  3585. void cmTarget::GetFullNameInternal(const std::string& config,
  3586. bool implib,
  3587. std::string& outPrefix,
  3588. std::string& outBase,
  3589. std::string& outSuffix) const
  3590. {
  3591. // Use just the target name for non-main target types.
  3592. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  3593. this->GetType() != cmTarget::SHARED_LIBRARY &&
  3594. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3595. this->GetType() != cmTarget::EXECUTABLE)
  3596. {
  3597. outPrefix = "";
  3598. outBase = this->GetName();
  3599. outSuffix = "";
  3600. return;
  3601. }
  3602. // Return an empty name for the import library if this platform
  3603. // does not support import libraries.
  3604. if(implib &&
  3605. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  3606. {
  3607. outPrefix = "";
  3608. outBase = "";
  3609. outSuffix = "";
  3610. return;
  3611. }
  3612. // The implib option is only allowed for shared libraries, module
  3613. // libraries, and executables.
  3614. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  3615. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3616. this->GetType() != cmTarget::EXECUTABLE)
  3617. {
  3618. implib = false;
  3619. }
  3620. // Compute the full name for main target types.
  3621. const char* targetPrefix = (implib
  3622. ? this->GetProperty("IMPORT_PREFIX")
  3623. : this->GetProperty("PREFIX"));
  3624. const char* targetSuffix = (implib
  3625. ? this->GetProperty("IMPORT_SUFFIX")
  3626. : this->GetProperty("SUFFIX"));
  3627. const char* configPostfix = 0;
  3628. if(!config.empty())
  3629. {
  3630. std::string configProp = cmSystemTools::UpperCase(config);
  3631. configProp += "_POSTFIX";
  3632. configPostfix = this->GetProperty(configProp);
  3633. // Mac application bundles and frameworks have no postfix.
  3634. if(configPostfix &&
  3635. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  3636. {
  3637. configPostfix = 0;
  3638. }
  3639. }
  3640. const char* prefixVar = this->GetPrefixVariableInternal(implib);
  3641. const char* suffixVar = this->GetSuffixVariableInternal(implib);
  3642. // Check for language-specific default prefix and suffix.
  3643. std::string ll = this->GetLinkerLanguage(config, this);
  3644. if(!ll.empty())
  3645. {
  3646. if(!targetSuffix && suffixVar && *suffixVar)
  3647. {
  3648. std::string langSuff = suffixVar + std::string("_") + ll;
  3649. targetSuffix = this->Makefile->GetDefinition(langSuff);
  3650. }
  3651. if(!targetPrefix && prefixVar && *prefixVar)
  3652. {
  3653. std::string langPrefix = prefixVar + std::string("_") + ll;
  3654. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  3655. }
  3656. }
  3657. // if there is no prefix on the target use the cmake definition
  3658. if(!targetPrefix && prefixVar)
  3659. {
  3660. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  3661. }
  3662. // if there is no suffix on the target use the cmake definition
  3663. if(!targetSuffix && suffixVar)
  3664. {
  3665. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  3666. }
  3667. // frameworks have directory prefix but no suffix
  3668. std::string fw_prefix;
  3669. if(this->IsFrameworkOnApple())
  3670. {
  3671. fw_prefix = this->GetOutputName(config, false);
  3672. fw_prefix += ".framework/";
  3673. targetPrefix = fw_prefix.c_str();
  3674. targetSuffix = 0;
  3675. }
  3676. if(this->IsCFBundleOnApple())
  3677. {
  3678. fw_prefix = this->GetOutputName(config, false);
  3679. fw_prefix += ".";
  3680. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  3681. if (!ext)
  3682. {
  3683. ext = "bundle";
  3684. }
  3685. fw_prefix += ext;
  3686. fw_prefix += "/Contents/MacOS/";
  3687. targetPrefix = fw_prefix.c_str();
  3688. targetSuffix = 0;
  3689. }
  3690. // Begin the final name with the prefix.
  3691. outPrefix = targetPrefix?targetPrefix:"";
  3692. // Append the target name or property-specified name.
  3693. outBase += this->GetOutputName(config, implib);
  3694. // Append the per-configuration postfix.
  3695. outBase += configPostfix?configPostfix:"";
  3696. // Name shared libraries with their version number on some platforms.
  3697. if(const char* soversion = this->GetProperty("SOVERSION"))
  3698. {
  3699. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  3700. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  3701. {
  3702. outBase += "-";
  3703. outBase += soversion;
  3704. }
  3705. }
  3706. // Append the suffix.
  3707. outSuffix = targetSuffix?targetSuffix:"";
  3708. }
  3709. //----------------------------------------------------------------------------
  3710. void cmTarget::GetLibraryNames(std::string& name,
  3711. std::string& soName,
  3712. std::string& realName,
  3713. std::string& impName,
  3714. std::string& pdbName,
  3715. const std::string& config) const
  3716. {
  3717. // This should not be called for imported targets.
  3718. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3719. // enforcement of the limited imported target API.
  3720. if(this->IsImported())
  3721. {
  3722. std::string msg = "GetLibraryNames called on imported target: ";
  3723. msg += this->GetName();
  3724. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  3725. msg);
  3726. return;
  3727. }
  3728. assert(this->GetType() != INTERFACE_LIBRARY);
  3729. // Check for library version properties.
  3730. const char* version = this->GetProperty("VERSION");
  3731. const char* soversion = this->GetProperty("SOVERSION");
  3732. if(!this->HasSOName(config) ||
  3733. this->IsFrameworkOnApple())
  3734. {
  3735. // Versioning is supported only for shared libraries and modules,
  3736. // and then only when the platform supports an soname flag.
  3737. version = 0;
  3738. soversion = 0;
  3739. }
  3740. if(version && !soversion)
  3741. {
  3742. // The soversion must be set if the library version is set. Use
  3743. // the library version as the soversion.
  3744. soversion = version;
  3745. }
  3746. if(!version && soversion)
  3747. {
  3748. // Use the soversion as the library version.
  3749. version = soversion;
  3750. }
  3751. // Get the components of the library name.
  3752. std::string prefix;
  3753. std::string base;
  3754. std::string suffix;
  3755. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3756. // The library name.
  3757. name = prefix+base+suffix;
  3758. if(this->IsFrameworkOnApple())
  3759. {
  3760. realName = prefix;
  3761. realName += "Versions/";
  3762. realName += this->GetFrameworkVersion();
  3763. realName += "/";
  3764. realName += base;
  3765. soName = realName;
  3766. }
  3767. else
  3768. {
  3769. // The library's soname.
  3770. this->ComputeVersionedName(soName, prefix, base, suffix,
  3771. name, soversion);
  3772. // The library's real name on disk.
  3773. this->ComputeVersionedName(realName, prefix, base, suffix,
  3774. name, version);
  3775. }
  3776. // The import library name.
  3777. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3778. this->GetType() == cmTarget::MODULE_LIBRARY)
  3779. {
  3780. impName = this->GetFullNameInternal(config, true);
  3781. }
  3782. else
  3783. {
  3784. impName = "";
  3785. }
  3786. // The program database file name.
  3787. pdbName = this->GetPDBName(config);
  3788. }
  3789. //----------------------------------------------------------------------------
  3790. void cmTarget::ComputeVersionedName(std::string& vName,
  3791. std::string const& prefix,
  3792. std::string const& base,
  3793. std::string const& suffix,
  3794. std::string const& name,
  3795. const char* version) const
  3796. {
  3797. vName = this->IsApple? (prefix+base) : name;
  3798. if(version)
  3799. {
  3800. vName += ".";
  3801. vName += version;
  3802. }
  3803. vName += this->IsApple? suffix : std::string();
  3804. }
  3805. //----------------------------------------------------------------------------
  3806. void cmTarget::GetExecutableNames(std::string& name,
  3807. std::string& realName,
  3808. std::string& impName,
  3809. std::string& pdbName,
  3810. const std::string& config) const
  3811. {
  3812. // This should not be called for imported targets.
  3813. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3814. // enforcement of the limited imported target API.
  3815. if(this->IsImported())
  3816. {
  3817. std::string msg =
  3818. "GetExecutableNames called on imported target: ";
  3819. msg += this->GetName();
  3820. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  3821. }
  3822. // This versioning is supported only for executables and then only
  3823. // when the platform supports symbolic links.
  3824. #if defined(_WIN32) && !defined(__CYGWIN__)
  3825. const char* version = 0;
  3826. #else
  3827. // Check for executable version properties.
  3828. const char* version = this->GetProperty("VERSION");
  3829. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  3830. {
  3831. version = 0;
  3832. }
  3833. #endif
  3834. // Get the components of the executable name.
  3835. std::string prefix;
  3836. std::string base;
  3837. std::string suffix;
  3838. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3839. // The executable name.
  3840. name = prefix+base+suffix;
  3841. // The executable's real name on disk.
  3842. #if defined(__CYGWIN__)
  3843. realName = prefix+base;
  3844. #else
  3845. realName = name;
  3846. #endif
  3847. if(version)
  3848. {
  3849. realName += "-";
  3850. realName += version;
  3851. }
  3852. #if defined(__CYGWIN__)
  3853. realName += suffix;
  3854. #endif
  3855. // The import library name.
  3856. impName = this->GetFullNameInternal(config, true);
  3857. // The program database file name.
  3858. pdbName = this->GetPDBName(config);
  3859. }
  3860. //----------------------------------------------------------------------------
  3861. bool cmTarget::HasImplibGNUtoMS() const
  3862. {
  3863. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  3864. }
  3865. //----------------------------------------------------------------------------
  3866. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  3867. std::string& out, const char* newExt) const
  3868. {
  3869. if(this->HasImplibGNUtoMS() &&
  3870. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  3871. {
  3872. out = gnuName.substr(0, gnuName.size()-6);
  3873. out += newExt? newExt : ".lib";
  3874. return true;
  3875. }
  3876. return false;
  3877. }
  3878. //----------------------------------------------------------------------------
  3879. void cmTarget::SetPropertyDefault(const std::string& property,
  3880. const char* default_value)
  3881. {
  3882. // Compute the name of the variable holding the default value.
  3883. std::string var = "CMAKE_";
  3884. var += property;
  3885. if(const char* value = this->Makefile->GetDefinition(var))
  3886. {
  3887. this->SetProperty(property, value);
  3888. }
  3889. else if(default_value)
  3890. {
  3891. this->SetProperty(property, default_value);
  3892. }
  3893. }
  3894. //----------------------------------------------------------------------------
  3895. bool cmTarget::HaveBuildTreeRPATH(const std::string& config) const
  3896. {
  3897. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3898. {
  3899. return false;
  3900. }
  3901. std::vector<std::string> libs;
  3902. this->GetDirectLinkLibraries(config, libs, this);
  3903. return !libs.empty();
  3904. }
  3905. //----------------------------------------------------------------------------
  3906. bool cmTarget::HaveInstallTreeRPATH() const
  3907. {
  3908. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3909. return (install_rpath && *install_rpath) &&
  3910. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  3911. }
  3912. //----------------------------------------------------------------------------
  3913. bool cmTarget::NeedRelinkBeforeInstall(const std::string& config) const
  3914. {
  3915. // Only executables and shared libraries can have an rpath and may
  3916. // need relinking.
  3917. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  3918. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  3919. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  3920. {
  3921. return false;
  3922. }
  3923. // If there is no install location this target will not be installed
  3924. // and therefore does not need relinking.
  3925. if(!this->GetHaveInstallRule())
  3926. {
  3927. return false;
  3928. }
  3929. // If skipping all rpaths completely then no relinking is needed.
  3930. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3931. {
  3932. return false;
  3933. }
  3934. // If building with the install-tree rpath no relinking is needed.
  3935. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3936. {
  3937. return false;
  3938. }
  3939. // If chrpath is going to be used no relinking is needed.
  3940. if(this->IsChrpathUsed(config))
  3941. {
  3942. return false;
  3943. }
  3944. // Check for rpath support on this platform.
  3945. std::string ll = this->GetLinkerLanguage(config, this);
  3946. if(!ll.empty())
  3947. {
  3948. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3949. flagVar += ll;
  3950. flagVar += "_FLAG";
  3951. if(!this->Makefile->IsSet(flagVar))
  3952. {
  3953. // There is no rpath support on this platform so nothing needs
  3954. // relinking.
  3955. return false;
  3956. }
  3957. }
  3958. else
  3959. {
  3960. // No linker language is known. This error will be reported by
  3961. // other code.
  3962. return false;
  3963. }
  3964. // If either a build or install tree rpath is set then the rpath
  3965. // will likely change between the build tree and install tree and
  3966. // this target must be relinked.
  3967. return this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
  3968. }
  3969. //----------------------------------------------------------------------------
  3970. std::string cmTarget::GetInstallNameDirForBuildTree(
  3971. const std::string& config) const
  3972. {
  3973. // If building directly for installation then the build tree install_name
  3974. // is the same as the install tree.
  3975. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3976. {
  3977. return GetInstallNameDirForInstallTree();
  3978. }
  3979. // Use the build tree directory for the target.
  3980. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  3981. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3982. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3983. {
  3984. std::string dir;
  3985. bool macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  3986. if(macosx_rpath)
  3987. {
  3988. dir = "@rpath";
  3989. }
  3990. else
  3991. {
  3992. dir = this->GetDirectory(config);
  3993. }
  3994. dir += "/";
  3995. return dir;
  3996. }
  3997. else
  3998. {
  3999. return "";
  4000. }
  4001. }
  4002. //----------------------------------------------------------------------------
  4003. std::string cmTarget::GetInstallNameDirForInstallTree() const
  4004. {
  4005. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  4006. {
  4007. std::string dir;
  4008. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  4009. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  4010. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  4011. {
  4012. if(install_name_dir && *install_name_dir)
  4013. {
  4014. dir = install_name_dir;
  4015. dir += "/";
  4016. }
  4017. }
  4018. if(!install_name_dir)
  4019. {
  4020. if(this->MacOSXRpathInstallNameDirDefault())
  4021. {
  4022. dir = "@rpath/";
  4023. }
  4024. }
  4025. return dir;
  4026. }
  4027. else
  4028. {
  4029. return "";
  4030. }
  4031. }
  4032. //----------------------------------------------------------------------------
  4033. const char* cmTarget::GetOutputTargetType(bool implib) const
  4034. {
  4035. switch(this->GetType())
  4036. {
  4037. case cmTarget::SHARED_LIBRARY:
  4038. if(this->DLLPlatform)
  4039. {
  4040. if(implib)
  4041. {
  4042. // A DLL import library is treated as an archive target.
  4043. return "ARCHIVE";
  4044. }
  4045. else
  4046. {
  4047. // A DLL shared library is treated as a runtime target.
  4048. return "RUNTIME";
  4049. }
  4050. }
  4051. else
  4052. {
  4053. // For non-DLL platforms shared libraries are treated as
  4054. // library targets.
  4055. return "LIBRARY";
  4056. }
  4057. case cmTarget::STATIC_LIBRARY:
  4058. // Static libraries are always treated as archive targets.
  4059. return "ARCHIVE";
  4060. case cmTarget::MODULE_LIBRARY:
  4061. if(implib)
  4062. {
  4063. // Module libraries are always treated as library targets.
  4064. return "ARCHIVE";
  4065. }
  4066. else
  4067. {
  4068. // Module import libraries are treated as archive targets.
  4069. return "LIBRARY";
  4070. }
  4071. case cmTarget::EXECUTABLE:
  4072. if(implib)
  4073. {
  4074. // Executable import libraries are treated as archive targets.
  4075. return "ARCHIVE";
  4076. }
  4077. else
  4078. {
  4079. // Executables are always treated as runtime targets.
  4080. return "RUNTIME";
  4081. }
  4082. default:
  4083. break;
  4084. }
  4085. return "";
  4086. }
  4087. //----------------------------------------------------------------------------
  4088. bool cmTarget::ComputeOutputDir(const std::string& config,
  4089. bool implib, std::string& out) const
  4090. {
  4091. bool usesDefaultOutputDir = false;
  4092. std::string conf = config;
  4093. // Look for a target property defining the target output directory
  4094. // based on the target type.
  4095. std::string targetTypeName = this->GetOutputTargetType(implib);
  4096. const char* propertyName = 0;
  4097. std::string propertyNameStr = targetTypeName;
  4098. if(!propertyNameStr.empty())
  4099. {
  4100. propertyNameStr += "_OUTPUT_DIRECTORY";
  4101. propertyName = propertyNameStr.c_str();
  4102. }
  4103. // Check for a per-configuration output directory target property.
  4104. std::string configUpper = cmSystemTools::UpperCase(conf);
  4105. const char* configProp = 0;
  4106. std::string configPropStr = targetTypeName;
  4107. if(!configPropStr.empty())
  4108. {
  4109. configPropStr += "_OUTPUT_DIRECTORY_";
  4110. configPropStr += configUpper;
  4111. configProp = configPropStr.c_str();
  4112. }
  4113. // Select an output directory.
  4114. if(const char* config_outdir = this->GetProperty(configProp))
  4115. {
  4116. // Use the user-specified per-configuration output directory.
  4117. out = config_outdir;
  4118. // Skip per-configuration subdirectory.
  4119. conf = "";
  4120. }
  4121. else if(const char* outdir = this->GetProperty(propertyName))
  4122. {
  4123. // Use the user-specified output directory.
  4124. out = outdir;
  4125. }
  4126. else if(this->GetType() == cmTarget::EXECUTABLE)
  4127. {
  4128. // Lookup the output path for executables.
  4129. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  4130. }
  4131. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  4132. this->GetType() == cmTarget::SHARED_LIBRARY ||
  4133. this->GetType() == cmTarget::MODULE_LIBRARY)
  4134. {
  4135. // Lookup the output path for libraries.
  4136. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  4137. }
  4138. if(out.empty())
  4139. {
  4140. // Default to the current output directory.
  4141. usesDefaultOutputDir = true;
  4142. out = ".";
  4143. }
  4144. // Convert the output path to a full path in case it is
  4145. // specified as a relative path. Treat a relative path as
  4146. // relative to the current output directory for this makefile.
  4147. out = (cmSystemTools::CollapseFullPath
  4148. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  4149. // The generator may add the configuration's subdirectory.
  4150. if(!conf.empty())
  4151. {
  4152. const char *platforms = this->Makefile->GetDefinition(
  4153. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  4154. std::string suffix =
  4155. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  4156. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  4157. AppendDirectoryForConfig("/", conf, suffix, out);
  4158. }
  4159. return usesDefaultOutputDir;
  4160. }
  4161. //----------------------------------------------------------------------------
  4162. bool cmTarget::ComputePDBOutputDir(const std::string& kind,
  4163. const std::string& config,
  4164. std::string& out) const
  4165. {
  4166. // Look for a target property defining the target output directory
  4167. // based on the target type.
  4168. const char* propertyName = 0;
  4169. std::string propertyNameStr = kind;
  4170. if(!propertyNameStr.empty())
  4171. {
  4172. propertyNameStr += "_OUTPUT_DIRECTORY";
  4173. propertyName = propertyNameStr.c_str();
  4174. }
  4175. std::string conf = config;
  4176. // Check for a per-configuration output directory target property.
  4177. std::string configUpper = cmSystemTools::UpperCase(conf);
  4178. const char* configProp = 0;
  4179. std::string configPropStr = kind;
  4180. if(!configPropStr.empty())
  4181. {
  4182. configPropStr += "_OUTPUT_DIRECTORY_";
  4183. configPropStr += configUpper;
  4184. configProp = configPropStr.c_str();
  4185. }
  4186. // Select an output directory.
  4187. if(const char* config_outdir = this->GetProperty(configProp))
  4188. {
  4189. // Use the user-specified per-configuration output directory.
  4190. out = config_outdir;
  4191. // Skip per-configuration subdirectory.
  4192. conf = "";
  4193. }
  4194. else if(const char* outdir = this->GetProperty(propertyName))
  4195. {
  4196. // Use the user-specified output directory.
  4197. out = outdir;
  4198. }
  4199. if(out.empty())
  4200. {
  4201. return false;
  4202. }
  4203. // Convert the output path to a full path in case it is
  4204. // specified as a relative path. Treat a relative path as
  4205. // relative to the current output directory for this makefile.
  4206. out = (cmSystemTools::CollapseFullPath
  4207. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  4208. // The generator may add the configuration's subdirectory.
  4209. if(!conf.empty())
  4210. {
  4211. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  4212. AppendDirectoryForConfig("/", conf, "", out);
  4213. }
  4214. return true;
  4215. }
  4216. //----------------------------------------------------------------------------
  4217. bool cmTarget::UsesDefaultOutputDir(const std::string& config,
  4218. bool implib) const
  4219. {
  4220. std::string dir;
  4221. return this->ComputeOutputDir(config, implib, dir);
  4222. }
  4223. //----------------------------------------------------------------------------
  4224. std::string cmTarget::GetOutputName(const std::string& config,
  4225. bool implib) const
  4226. {
  4227. std::vector<std::string> props;
  4228. std::string type = this->GetOutputTargetType(implib);
  4229. std::string configUpper = cmSystemTools::UpperCase(config);
  4230. if(!type.empty() && !configUpper.empty())
  4231. {
  4232. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  4233. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  4234. }
  4235. if(!type.empty())
  4236. {
  4237. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  4238. props.push_back(type + "_OUTPUT_NAME");
  4239. }
  4240. if(!configUpper.empty())
  4241. {
  4242. // OUTPUT_NAME_<CONFIG>
  4243. props.push_back("OUTPUT_NAME_" + configUpper);
  4244. // <CONFIG>_OUTPUT_NAME
  4245. props.push_back(configUpper + "_OUTPUT_NAME");
  4246. }
  4247. // OUTPUT_NAME
  4248. props.push_back("OUTPUT_NAME");
  4249. for(std::vector<std::string>::const_iterator i = props.begin();
  4250. i != props.end(); ++i)
  4251. {
  4252. if(const char* outName = this->GetProperty(*i))
  4253. {
  4254. return outName;
  4255. }
  4256. }
  4257. return this->GetName();
  4258. }
  4259. //----------------------------------------------------------------------------
  4260. std::string cmTarget::GetFrameworkVersion() const
  4261. {
  4262. assert(this->GetType() != INTERFACE_LIBRARY);
  4263. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  4264. {
  4265. return fversion;
  4266. }
  4267. else if(const char* tversion = this->GetProperty("VERSION"))
  4268. {
  4269. return tversion;
  4270. }
  4271. else
  4272. {
  4273. return "A";
  4274. }
  4275. }
  4276. //----------------------------------------------------------------------------
  4277. const char* cmTarget::GetExportMacro() const
  4278. {
  4279. // Define the symbol for targets that export symbols.
  4280. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4281. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4282. this->IsExecutableWithExports())
  4283. {
  4284. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  4285. {
  4286. this->ExportMacro = custom_export_name;
  4287. }
  4288. else
  4289. {
  4290. std::string in = this->GetName();
  4291. in += "_EXPORTS";
  4292. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  4293. }
  4294. return this->ExportMacro.c_str();
  4295. }
  4296. else
  4297. {
  4298. return 0;
  4299. }
  4300. }
  4301. //----------------------------------------------------------------------------
  4302. bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
  4303. {
  4304. return this->LinkImplicitNullProperties.find(p)
  4305. != this->LinkImplicitNullProperties.end();
  4306. }
  4307. //----------------------------------------------------------------------------
  4308. template<typename PropertyType>
  4309. PropertyType getTypedProperty(cmTarget const* tgt, const char *prop,
  4310. PropertyType *);
  4311. //----------------------------------------------------------------------------
  4312. template<>
  4313. bool getTypedProperty<bool>(cmTarget const* tgt, const char *prop, bool *)
  4314. {
  4315. return tgt->GetPropertyAsBool(prop);
  4316. }
  4317. //----------------------------------------------------------------------------
  4318. template<>
  4319. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  4320. const char *prop,
  4321. const char **)
  4322. {
  4323. return tgt->GetProperty(prop);
  4324. }
  4325. enum CompatibleType
  4326. {
  4327. BoolType,
  4328. StringType,
  4329. NumberMinType,
  4330. NumberMaxType
  4331. };
  4332. //----------------------------------------------------------------------------
  4333. template<typename PropertyType>
  4334. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  4335. PropertyType rhs,
  4336. CompatibleType t);
  4337. //----------------------------------------------------------------------------
  4338. template<>
  4339. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs, CompatibleType)
  4340. {
  4341. return std::make_pair(lhs == rhs, lhs);
  4342. }
  4343. //----------------------------------------------------------------------------
  4344. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  4345. const char *rhs)
  4346. {
  4347. const bool b = strcmp(lhs, rhs) == 0;
  4348. return std::make_pair(b, b ? lhs : 0);
  4349. }
  4350. #if defined(_MSC_VER) && _MSC_VER <= 1200
  4351. template<typename T> const T&
  4352. cmMaximum(const T& l, const T& r) {return l > r ? l : r;}
  4353. template<typename T> const T&
  4354. cmMinimum(const T& l, const T& r) {return l < r ? l : r;}
  4355. #else
  4356. #define cmMinimum std::min
  4357. #define cmMaximum std::max
  4358. #endif
  4359. //----------------------------------------------------------------------------
  4360. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  4361. const char *rhs,
  4362. CompatibleType t)
  4363. {
  4364. char *pEnd;
  4365. #if defined(_MSC_VER)
  4366. static const char* const null_ptr = 0;
  4367. #else
  4368. # define null_ptr 0
  4369. #endif
  4370. long lnum = strtol(lhs, &pEnd, 0);
  4371. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  4372. {
  4373. return std::pair<bool, const char*>(false, null_ptr);
  4374. }
  4375. long rnum = strtol(rhs, &pEnd, 0);
  4376. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  4377. {
  4378. return std::pair<bool, const char*>(false, null_ptr);
  4379. }
  4380. #if !defined(_MSC_VER)
  4381. #undef null_ptr
  4382. #endif
  4383. if (t == NumberMaxType)
  4384. {
  4385. return std::make_pair(true, cmMaximum(lnum, rnum) == lnum ? lhs : rhs);
  4386. }
  4387. else
  4388. {
  4389. return std::make_pair(true, cmMinimum(lnum, rnum) == lnum ? lhs : rhs);
  4390. }
  4391. }
  4392. //----------------------------------------------------------------------------
  4393. template<>
  4394. std::pair<bool, const char*> consistentProperty(const char *lhs,
  4395. const char *rhs,
  4396. CompatibleType t)
  4397. {
  4398. if (!lhs && !rhs)
  4399. {
  4400. return std::make_pair(true, lhs);
  4401. }
  4402. if (!lhs)
  4403. {
  4404. return std::make_pair(true, rhs);
  4405. }
  4406. if (!rhs)
  4407. {
  4408. return std::make_pair(true, lhs);
  4409. }
  4410. #if defined(_MSC_VER)
  4411. static const char* const null_ptr = 0;
  4412. #else
  4413. # define null_ptr 0
  4414. #endif
  4415. switch(t)
  4416. {
  4417. case BoolType:
  4418. assert(!"consistentProperty for strings called with BoolType");
  4419. return std::pair<bool, const char*>(false, null_ptr);
  4420. case StringType:
  4421. return consistentStringProperty(lhs, rhs);
  4422. case NumberMinType:
  4423. case NumberMaxType:
  4424. return consistentNumberProperty(lhs, rhs, t);
  4425. }
  4426. assert(!"Unreachable!");
  4427. return std::pair<bool, const char*>(false, null_ptr);
  4428. #if !defined(_MSC_VER)
  4429. #undef null_ptr
  4430. #endif
  4431. }
  4432. template<typename PropertyType>
  4433. PropertyType impliedValue(PropertyType);
  4434. template<>
  4435. bool impliedValue<bool>(bool)
  4436. {
  4437. return false;
  4438. }
  4439. template<>
  4440. const char* impliedValue<const char*>(const char*)
  4441. {
  4442. return "";
  4443. }
  4444. template<typename PropertyType>
  4445. std::string valueAsString(PropertyType);
  4446. template<>
  4447. std::string valueAsString<bool>(bool value)
  4448. {
  4449. return value ? "TRUE" : "FALSE";
  4450. }
  4451. template<>
  4452. std::string valueAsString<const char*>(const char* value)
  4453. {
  4454. return value ? value : "(unset)";
  4455. }
  4456. //----------------------------------------------------------------------------
  4457. void
  4458. cmTarget::ReportPropertyOrigin(const std::string &p,
  4459. const std::string &result,
  4460. const std::string &report,
  4461. const std::string &compatibilityType) const
  4462. {
  4463. std::vector<std::string> debugProperties;
  4464. const char *debugProp =
  4465. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  4466. if (debugProp)
  4467. {
  4468. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  4469. }
  4470. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  4471. && std::find(debugProperties.begin(),
  4472. debugProperties.end(),
  4473. p)
  4474. != debugProperties.end();
  4475. if (this->Makefile->IsGeneratingBuildSystem())
  4476. {
  4477. this->DebugCompatiblePropertiesDone[p] = true;
  4478. }
  4479. if (!debugOrigin)
  4480. {
  4481. return;
  4482. }
  4483. std::string areport = compatibilityType;
  4484. areport += std::string(" of property \"") + p + "\" for target \"";
  4485. areport += std::string(this->GetName());
  4486. areport += "\" (result: \"";
  4487. areport += result;
  4488. areport += "\"):\n" + report;
  4489. cmListFileBacktrace lfbt;
  4490. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport, lfbt);
  4491. }
  4492. //----------------------------------------------------------------------------
  4493. std::string compatibilityType(CompatibleType t)
  4494. {
  4495. switch(t)
  4496. {
  4497. case BoolType:
  4498. return "Boolean compatibility";
  4499. case StringType:
  4500. return "String compatibility";
  4501. case NumberMaxType:
  4502. return "Numeric maximum compatibility";
  4503. case NumberMinType:
  4504. return "Numeric minimum compatibility";
  4505. }
  4506. assert(!"Unreachable!");
  4507. return "";
  4508. }
  4509. //----------------------------------------------------------------------------
  4510. std::string compatibilityAgree(CompatibleType t, bool dominant)
  4511. {
  4512. switch(t)
  4513. {
  4514. case BoolType:
  4515. case StringType:
  4516. return dominant ? "(Disagree)\n" : "(Agree)\n";
  4517. case NumberMaxType:
  4518. case NumberMinType:
  4519. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  4520. }
  4521. assert(!"Unreachable!");
  4522. return "";
  4523. }
  4524. //----------------------------------------------------------------------------
  4525. template<typename PropertyType>
  4526. PropertyType checkInterfacePropertyCompatibility(cmTarget const* tgt,
  4527. const std::string &p,
  4528. const std::string& config,
  4529. const char *defaultValue,
  4530. CompatibleType t,
  4531. PropertyType *)
  4532. {
  4533. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p.c_str(),
  4534. 0);
  4535. const bool explicitlySet = tgt->GetProperties()
  4536. .find(p)
  4537. != tgt->GetProperties().end();
  4538. const bool impliedByUse =
  4539. tgt->IsNullImpliedByLinkLibraries(p);
  4540. assert((impliedByUse ^ explicitlySet)
  4541. || (!impliedByUse && !explicitlySet));
  4542. std::vector<cmTarget*> deps;
  4543. tgt->GetTransitiveTargetClosure(config, tgt, deps);
  4544. if(deps.empty())
  4545. {
  4546. return propContent;
  4547. }
  4548. bool propInitialized = explicitlySet;
  4549. std::string report = " * Target \"";
  4550. report += tgt->GetName();
  4551. if (explicitlySet)
  4552. {
  4553. report += "\" has property content \"";
  4554. report += valueAsString<PropertyType>(propContent);
  4555. report += "\"\n";
  4556. }
  4557. else if (impliedByUse)
  4558. {
  4559. report += "\" property is implied by use.\n";
  4560. }
  4561. else
  4562. {
  4563. report += "\" property not set.\n";
  4564. }
  4565. for(std::vector<cmTarget*>::const_iterator li =
  4566. deps.begin();
  4567. li != deps.end(); ++li)
  4568. {
  4569. // An error should be reported if one dependency
  4570. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  4571. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  4572. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  4573. // with a dependency.
  4574. cmTarget const* theTarget = *li;
  4575. const bool ifaceIsSet = theTarget->GetProperties()
  4576. .find("INTERFACE_" + p)
  4577. != theTarget->GetProperties().end();
  4578. PropertyType ifacePropContent =
  4579. getTypedProperty<PropertyType>(theTarget,
  4580. ("INTERFACE_" + p).c_str(), 0);
  4581. std::string reportEntry;
  4582. if (ifaceIsSet)
  4583. {
  4584. reportEntry += " * Target \"";
  4585. reportEntry += theTarget->GetName();
  4586. reportEntry += "\" property value \"";
  4587. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  4588. reportEntry += "\" ";
  4589. }
  4590. if (explicitlySet)
  4591. {
  4592. if (ifaceIsSet)
  4593. {
  4594. std::pair<bool, PropertyType> consistent =
  4595. consistentProperty(propContent,
  4596. ifacePropContent, t);
  4597. report += reportEntry;
  4598. report += compatibilityAgree(t, propContent != consistent.second);
  4599. if (!consistent.first)
  4600. {
  4601. cmOStringStream e;
  4602. e << "Property " << p << " on target \""
  4603. << tgt->GetName() << "\" does\nnot match the "
  4604. "INTERFACE_" << p << " property requirement\nof "
  4605. "dependency \"" << theTarget->GetName() << "\".\n";
  4606. cmSystemTools::Error(e.str().c_str());
  4607. break;
  4608. }
  4609. else
  4610. {
  4611. propContent = consistent.second;
  4612. continue;
  4613. }
  4614. }
  4615. else
  4616. {
  4617. // Explicitly set on target and not set in iface. Can't disagree.
  4618. continue;
  4619. }
  4620. }
  4621. else if (impliedByUse)
  4622. {
  4623. propContent = impliedValue<PropertyType>(propContent);
  4624. if (ifaceIsSet)
  4625. {
  4626. std::pair<bool, PropertyType> consistent =
  4627. consistentProperty(propContent,
  4628. ifacePropContent, t);
  4629. report += reportEntry;
  4630. report += compatibilityAgree(t, propContent != consistent.second);
  4631. if (!consistent.first)
  4632. {
  4633. cmOStringStream e;
  4634. e << "Property " << p << " on target \""
  4635. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  4636. << " because it was used to determine the link libraries\n"
  4637. "already. The INTERFACE_" << p << " property on\ndependency \""
  4638. << theTarget->GetName() << "\" is in conflict.\n";
  4639. cmSystemTools::Error(e.str().c_str());
  4640. break;
  4641. }
  4642. else
  4643. {
  4644. propContent = consistent.second;
  4645. continue;
  4646. }
  4647. }
  4648. else
  4649. {
  4650. // Implicitly set on target and not set in iface. Can't disagree.
  4651. continue;
  4652. }
  4653. }
  4654. else
  4655. {
  4656. if (ifaceIsSet)
  4657. {
  4658. if (propInitialized)
  4659. {
  4660. std::pair<bool, PropertyType> consistent =
  4661. consistentProperty(propContent,
  4662. ifacePropContent, t);
  4663. report += reportEntry;
  4664. report += compatibilityAgree(t, propContent != consistent.second);
  4665. if (!consistent.first)
  4666. {
  4667. cmOStringStream e;
  4668. e << "The INTERFACE_" << p << " property of \""
  4669. << theTarget->GetName() << "\" does\nnot agree with the value "
  4670. "of " << p << " already determined\nfor \""
  4671. << tgt->GetName() << "\".\n";
  4672. cmSystemTools::Error(e.str().c_str());
  4673. break;
  4674. }
  4675. else
  4676. {
  4677. propContent = consistent.second;
  4678. continue;
  4679. }
  4680. }
  4681. else
  4682. {
  4683. report += reportEntry + "(Interface set)\n";
  4684. propContent = ifacePropContent;
  4685. propInitialized = true;
  4686. }
  4687. }
  4688. else
  4689. {
  4690. // Not set. Nothing to agree on.
  4691. continue;
  4692. }
  4693. }
  4694. }
  4695. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  4696. report, compatibilityType(t));
  4697. return propContent;
  4698. }
  4699. //----------------------------------------------------------------------------
  4700. bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
  4701. const std::string& config) const
  4702. {
  4703. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  4704. BoolType, 0);
  4705. }
  4706. //----------------------------------------------------------------------------
  4707. const char * cmTarget::GetLinkInterfaceDependentStringProperty(
  4708. const std::string &p,
  4709. const std::string& config) const
  4710. {
  4711. return checkInterfacePropertyCompatibility<const char *>(this,
  4712. p,
  4713. config,
  4714. "empty",
  4715. StringType, 0);
  4716. }
  4717. //----------------------------------------------------------------------------
  4718. const char * cmTarget::GetLinkInterfaceDependentNumberMinProperty(
  4719. const std::string &p,
  4720. const std::string& config) const
  4721. {
  4722. return checkInterfacePropertyCompatibility<const char *>(this,
  4723. p,
  4724. config,
  4725. "empty",
  4726. NumberMinType, 0);
  4727. }
  4728. //----------------------------------------------------------------------------
  4729. const char * cmTarget::GetLinkInterfaceDependentNumberMaxProperty(
  4730. const std::string &p,
  4731. const std::string& config) const
  4732. {
  4733. return checkInterfacePropertyCompatibility<const char *>(this,
  4734. p,
  4735. config,
  4736. "empty",
  4737. NumberMaxType, 0);
  4738. }
  4739. //----------------------------------------------------------------------------
  4740. bool isLinkDependentProperty(cmTarget const* tgt, const std::string &p,
  4741. const std::string& interfaceProperty,
  4742. const std::string& config)
  4743. {
  4744. std::vector<cmTarget*> deps;
  4745. tgt->GetTransitiveTargetClosure(config, tgt, deps);
  4746. if(deps.empty())
  4747. {
  4748. return false;
  4749. }
  4750. for(std::vector<cmTarget*>::const_iterator li =
  4751. deps.begin();
  4752. li != deps.end(); ++li)
  4753. {
  4754. const char *prop = (*li)->GetProperty(interfaceProperty);
  4755. if (!prop)
  4756. {
  4757. continue;
  4758. }
  4759. std::vector<std::string> props;
  4760. cmSystemTools::ExpandListArgument(prop, props);
  4761. for(std::vector<std::string>::iterator pi = props.begin();
  4762. pi != props.end(); ++pi)
  4763. {
  4764. if (*pi == p)
  4765. {
  4766. return true;
  4767. }
  4768. }
  4769. }
  4770. return false;
  4771. }
  4772. //----------------------------------------------------------------------------
  4773. bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
  4774. const std::string& config) const
  4775. {
  4776. if (this->TargetTypeValue == OBJECT_LIBRARY
  4777. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4778. {
  4779. return false;
  4780. }
  4781. return (p == "POSITION_INDEPENDENT_CODE") ||
  4782. isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_BOOL",
  4783. config);
  4784. }
  4785. //----------------------------------------------------------------------------
  4786. bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
  4787. const std::string& config) const
  4788. {
  4789. if (this->TargetTypeValue == OBJECT_LIBRARY
  4790. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4791. {
  4792. return false;
  4793. }
  4794. return (p == "AUTOUIC_OPTIONS") ||
  4795. isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_STRING",
  4796. config);
  4797. }
  4798. //----------------------------------------------------------------------------
  4799. bool cmTarget::IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
  4800. const std::string& config) const
  4801. {
  4802. if (this->TargetTypeValue == OBJECT_LIBRARY
  4803. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4804. {
  4805. return false;
  4806. }
  4807. return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_NUMBER_MIN",
  4808. config);
  4809. }
  4810. //----------------------------------------------------------------------------
  4811. bool cmTarget::IsLinkInterfaceDependentNumberMaxProperty(const std::string &p,
  4812. const std::string& config) const
  4813. {
  4814. if (this->TargetTypeValue == OBJECT_LIBRARY
  4815. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4816. {
  4817. return false;
  4818. }
  4819. return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_NUMBER_MAX",
  4820. config);
  4821. }
  4822. //----------------------------------------------------------------------------
  4823. void cmTarget::GetLanguages(std::set<std::string>& languages,
  4824. const std::string& config,
  4825. cmTarget const* head) const
  4826. {
  4827. std::vector<cmSourceFile*> sourceFiles;
  4828. this->GetSourceFiles(sourceFiles, config, head);
  4829. for(std::vector<cmSourceFile*>::const_iterator
  4830. i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
  4831. {
  4832. const std::string& lang = (*i)->GetLanguage();
  4833. if(!lang.empty())
  4834. {
  4835. languages.insert(lang);
  4836. }
  4837. }
  4838. std::vector<cmTarget*> objectLibraries;
  4839. std::vector<cmSourceFile const*> externalObjects;
  4840. if (this->Makefile->GetGeneratorTargets().empty())
  4841. {
  4842. // At configure-time, this method can be called as part of getting the
  4843. // LOCATION property or to export() a file to be include()d. However
  4844. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  4845. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  4846. // behavior of CMP0024 and CMP0026 only.
  4847. std::vector<std::string> srcs;
  4848. cmSystemTools::ExpandListArgument(this->GetProperty("SOURCES"), srcs);
  4849. for(std::vector<std::string>::const_iterator it = srcs.begin();
  4850. it != srcs.end(); ++it)
  4851. {
  4852. if (cmHasLiteralPrefix(*it, "$<TARGET_OBJECTS:")
  4853. && cmHasLiteralSuffix(*it, ">"))
  4854. {
  4855. std::string objLibName = it->substr(17, it->size()-18);
  4856. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLibName))
  4857. {
  4858. objectLibraries.push_back(tgt);
  4859. }
  4860. }
  4861. }
  4862. }
  4863. else
  4864. {
  4865. cmGeneratorTarget* gt = this->Makefile->GetLocalGenerator()
  4866. ->GetGlobalGenerator()
  4867. ->GetGeneratorTarget(this);
  4868. gt->GetExternalObjects(externalObjects, config);
  4869. for(std::vector<cmSourceFile const*>::const_iterator
  4870. i = externalObjects.begin(); i != externalObjects.end(); ++i)
  4871. {
  4872. std::string objLib = (*i)->GetObjectLibrary();
  4873. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  4874. {
  4875. objectLibraries.push_back(tgt);
  4876. }
  4877. }
  4878. }
  4879. for(std::vector<cmTarget*>::const_iterator
  4880. i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
  4881. {
  4882. (*i)->GetLanguages(languages, config, head);
  4883. }
  4884. }
  4885. //----------------------------------------------------------------------------
  4886. bool cmTarget::IsChrpathUsed(const std::string& config) const
  4887. {
  4888. // Only certain target types have an rpath.
  4889. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4890. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4891. this->GetType() == cmTarget::EXECUTABLE))
  4892. {
  4893. return false;
  4894. }
  4895. // If the target will not be installed we do not need to change its
  4896. // rpath.
  4897. if(!this->GetHaveInstallRule())
  4898. {
  4899. return false;
  4900. }
  4901. // Skip chrpath if skipping rpath altogether.
  4902. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  4903. {
  4904. return false;
  4905. }
  4906. // Skip chrpath if it does not need to be changed at install time.
  4907. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  4908. {
  4909. return false;
  4910. }
  4911. // Allow the user to disable builtin chrpath explicitly.
  4912. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  4913. {
  4914. return false;
  4915. }
  4916. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  4917. {
  4918. return true;
  4919. }
  4920. #if defined(CMAKE_USE_ELF_PARSER)
  4921. // Enable if the rpath flag uses a separator and the target uses ELF
  4922. // binaries.
  4923. std::string ll = this->GetLinkerLanguage(config, this);
  4924. if(!ll.empty())
  4925. {
  4926. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  4927. sepVar += ll;
  4928. sepVar += "_FLAG_SEP";
  4929. const char* sep = this->Makefile->GetDefinition(sepVar);
  4930. if(sep && *sep)
  4931. {
  4932. // TODO: Add ELF check to ABI detection and get rid of
  4933. // CMAKE_EXECUTABLE_FORMAT.
  4934. if(const char* fmt =
  4935. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  4936. {
  4937. return strcmp(fmt, "ELF") == 0;
  4938. }
  4939. }
  4940. }
  4941. #endif
  4942. static_cast<void>(config);
  4943. return false;
  4944. }
  4945. //----------------------------------------------------------------------------
  4946. cmTarget::ImportInfo const*
  4947. cmTarget::GetImportInfo(const std::string& config,
  4948. cmTarget const* headTarget) const
  4949. {
  4950. // There is no imported information for non-imported targets.
  4951. if(!this->IsImported())
  4952. {
  4953. return 0;
  4954. }
  4955. // Lookup/compute/cache the import information for this
  4956. // configuration.
  4957. std::string config_upper;
  4958. if(!config.empty())
  4959. {
  4960. config_upper = cmSystemTools::UpperCase(config);
  4961. }
  4962. else
  4963. {
  4964. config_upper = "NOCONFIG";
  4965. }
  4966. TargetConfigPair key(headTarget, config_upper);
  4967. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  4968. ImportInfoMapType::const_iterator i =
  4969. this->Internal->ImportInfoMap.find(key);
  4970. if(i == this->Internal->ImportInfoMap.end())
  4971. {
  4972. ImportInfo info;
  4973. this->ComputeImportInfo(config_upper, info, headTarget);
  4974. ImportInfoMapType::value_type entry(key, info);
  4975. i = this->Internal->ImportInfoMap.insert(entry).first;
  4976. }
  4977. if(this->GetType() == INTERFACE_LIBRARY)
  4978. {
  4979. return &i->second;
  4980. }
  4981. // If the location is empty then the target is not available for
  4982. // this configuration.
  4983. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  4984. {
  4985. return 0;
  4986. }
  4987. // Return the import information.
  4988. return &i->second;
  4989. }
  4990. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  4991. const char** loc,
  4992. const char** imp,
  4993. std::string& suffix) const
  4994. {
  4995. if (this->GetType() == INTERFACE_LIBRARY)
  4996. {
  4997. // This method attempts to find a config-specific LOCATION for the
  4998. // IMPORTED library. In the case of INTERFACE_LIBRARY, there is no
  4999. // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
  5000. // and valid response.
  5001. return true;
  5002. }
  5003. // Track the configuration-specific property suffix.
  5004. suffix = "_";
  5005. suffix += desired_config;
  5006. std::vector<std::string> mappedConfigs;
  5007. {
  5008. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  5009. mapProp += desired_config;
  5010. if(const char* mapValue = this->GetProperty(mapProp))
  5011. {
  5012. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  5013. }
  5014. }
  5015. // If we needed to find one of the mapped configurations but did not
  5016. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  5017. // library or an executable with exports.
  5018. bool allowImp = this->HasImportLibrary();
  5019. // If a mapping was found, check its configurations.
  5020. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  5021. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  5022. {
  5023. // Look for this configuration.
  5024. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  5025. std::string locProp = "IMPORTED_LOCATION_";
  5026. locProp += mcUpper;
  5027. *loc = this->GetProperty(locProp);
  5028. if(allowImp)
  5029. {
  5030. std::string impProp = "IMPORTED_IMPLIB_";
  5031. impProp += mcUpper;
  5032. *imp = this->GetProperty(impProp);
  5033. }
  5034. // If it was found, use it for all properties below.
  5035. if(*loc || *imp)
  5036. {
  5037. suffix = "_";
  5038. suffix += mcUpper;
  5039. }
  5040. }
  5041. // If we needed to find one of the mapped configurations but did not
  5042. // then the target is not found. The project does not want any
  5043. // other configuration.
  5044. if(!mappedConfigs.empty() && !*loc && !*imp)
  5045. {
  5046. return false;
  5047. }
  5048. // If we have not yet found it then there are no mapped
  5049. // configurations. Look for an exact-match.
  5050. if(!*loc && !*imp)
  5051. {
  5052. std::string locProp = "IMPORTED_LOCATION";
  5053. locProp += suffix;
  5054. *loc = this->GetProperty(locProp);
  5055. if(allowImp)
  5056. {
  5057. std::string impProp = "IMPORTED_IMPLIB";
  5058. impProp += suffix;
  5059. *imp = this->GetProperty(impProp);
  5060. }
  5061. }
  5062. // If we have not yet found it then there are no mapped
  5063. // configurations and no exact match.
  5064. if(!*loc && !*imp)
  5065. {
  5066. // The suffix computed above is not useful.
  5067. suffix = "";
  5068. // Look for a configuration-less location. This may be set by
  5069. // manually-written code.
  5070. *loc = this->GetProperty("IMPORTED_LOCATION");
  5071. if(allowImp)
  5072. {
  5073. *imp = this->GetProperty("IMPORTED_IMPLIB");
  5074. }
  5075. }
  5076. // If we have not yet found it then the project is willing to try
  5077. // any available configuration.
  5078. if(!*loc && !*imp)
  5079. {
  5080. std::vector<std::string> availableConfigs;
  5081. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  5082. {
  5083. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  5084. }
  5085. for(std::vector<std::string>::const_iterator
  5086. aci = availableConfigs.begin();
  5087. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  5088. {
  5089. suffix = "_";
  5090. suffix += cmSystemTools::UpperCase(*aci);
  5091. std::string locProp = "IMPORTED_LOCATION";
  5092. locProp += suffix;
  5093. *loc = this->GetProperty(locProp);
  5094. if(allowImp)
  5095. {
  5096. std::string impProp = "IMPORTED_IMPLIB";
  5097. impProp += suffix;
  5098. *imp = this->GetProperty(impProp);
  5099. }
  5100. }
  5101. }
  5102. // If we have not yet found it then the target is not available.
  5103. if(!*loc && !*imp)
  5104. {
  5105. return false;
  5106. }
  5107. return true;
  5108. }
  5109. //----------------------------------------------------------------------------
  5110. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  5111. ImportInfo& info,
  5112. cmTarget const* headTarget) const
  5113. {
  5114. // This method finds information about an imported target from its
  5115. // properties. The "IMPORTED_" namespace is reserved for properties
  5116. // defined by the project exporting the target.
  5117. // Initialize members.
  5118. info.NoSOName = false;
  5119. const char* loc = 0;
  5120. const char* imp = 0;
  5121. std::string suffix;
  5122. if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
  5123. {
  5124. return;
  5125. }
  5126. // Get the link interface.
  5127. {
  5128. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  5129. const char *propertyLibs = this->GetProperty(linkProp);
  5130. if (this->GetType() != INTERFACE_LIBRARY)
  5131. {
  5132. if(!propertyLibs)
  5133. {
  5134. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  5135. linkProp += suffix;
  5136. propertyLibs = this->GetProperty(linkProp);
  5137. }
  5138. if(!propertyLibs)
  5139. {
  5140. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  5141. propertyLibs = this->GetProperty(linkProp);
  5142. }
  5143. }
  5144. if(propertyLibs)
  5145. {
  5146. cmListFileBacktrace lfbt;
  5147. cmGeneratorExpression ge(lfbt);
  5148. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  5149. this->GetName(),
  5150. linkProp, 0, 0);
  5151. cmSystemTools::ExpandListArgument(ge.Parse(propertyLibs)
  5152. ->Evaluate(this->Makefile,
  5153. desired_config,
  5154. false,
  5155. headTarget,
  5156. this,
  5157. &dagChecker),
  5158. info.LinkInterface.Libraries);
  5159. }
  5160. }
  5161. if(this->GetType() == INTERFACE_LIBRARY)
  5162. {
  5163. return;
  5164. }
  5165. // A provided configuration has been chosen. Load the
  5166. // configuration's properties.
  5167. // Get the location.
  5168. if(loc)
  5169. {
  5170. info.Location = loc;
  5171. }
  5172. else
  5173. {
  5174. std::string impProp = "IMPORTED_LOCATION";
  5175. impProp += suffix;
  5176. if(const char* config_location = this->GetProperty(impProp))
  5177. {
  5178. info.Location = config_location;
  5179. }
  5180. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  5181. {
  5182. info.Location = location;
  5183. }
  5184. }
  5185. // Get the soname.
  5186. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  5187. {
  5188. std::string soProp = "IMPORTED_SONAME";
  5189. soProp += suffix;
  5190. if(const char* config_soname = this->GetProperty(soProp))
  5191. {
  5192. info.SOName = config_soname;
  5193. }
  5194. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  5195. {
  5196. info.SOName = soname;
  5197. }
  5198. }
  5199. // Get the "no-soname" mark.
  5200. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  5201. {
  5202. std::string soProp = "IMPORTED_NO_SONAME";
  5203. soProp += suffix;
  5204. if(const char* config_no_soname = this->GetProperty(soProp))
  5205. {
  5206. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  5207. }
  5208. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  5209. {
  5210. info.NoSOName = cmSystemTools::IsOn(no_soname);
  5211. }
  5212. }
  5213. // Get the import library.
  5214. if(imp)
  5215. {
  5216. info.ImportLibrary = imp;
  5217. }
  5218. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  5219. this->IsExecutableWithExports())
  5220. {
  5221. std::string impProp = "IMPORTED_IMPLIB";
  5222. impProp += suffix;
  5223. if(const char* config_implib = this->GetProperty(impProp))
  5224. {
  5225. info.ImportLibrary = config_implib;
  5226. }
  5227. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  5228. {
  5229. info.ImportLibrary = implib;
  5230. }
  5231. }
  5232. // Get the link dependencies.
  5233. {
  5234. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  5235. linkProp += suffix;
  5236. if(const char* config_libs = this->GetProperty(linkProp))
  5237. {
  5238. cmSystemTools::ExpandListArgument(config_libs,
  5239. info.LinkInterface.SharedDeps);
  5240. }
  5241. else if(const char* libs =
  5242. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  5243. {
  5244. cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
  5245. }
  5246. }
  5247. // Get the link languages.
  5248. if(this->LinkLanguagePropagatesToDependents())
  5249. {
  5250. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  5251. linkProp += suffix;
  5252. if(const char* config_libs = this->GetProperty(linkProp))
  5253. {
  5254. cmSystemTools::ExpandListArgument(config_libs,
  5255. info.LinkInterface.Languages);
  5256. }
  5257. else if(const char* libs =
  5258. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  5259. {
  5260. cmSystemTools::ExpandListArgument(libs,
  5261. info.LinkInterface.Languages);
  5262. }
  5263. }
  5264. // Get the cyclic repetition count.
  5265. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  5266. {
  5267. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  5268. linkProp += suffix;
  5269. if(const char* config_reps = this->GetProperty(linkProp))
  5270. {
  5271. sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
  5272. }
  5273. else if(const char* reps =
  5274. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  5275. {
  5276. sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
  5277. }
  5278. }
  5279. }
  5280. //----------------------------------------------------------------------------
  5281. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(
  5282. const std::string& config,
  5283. cmTarget const* head) const
  5284. {
  5285. // Imported targets have their own link interface.
  5286. if(this->IsImported())
  5287. {
  5288. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, head))
  5289. {
  5290. return &info->LinkInterface;
  5291. }
  5292. return 0;
  5293. }
  5294. // Link interfaces are not supported for executables that do not
  5295. // export symbols.
  5296. if(this->GetType() == cmTarget::EXECUTABLE &&
  5297. !this->IsExecutableWithExports())
  5298. {
  5299. return 0;
  5300. }
  5301. // Lookup any existing link interface for this configuration.
  5302. TargetConfigPair key(head, cmSystemTools::UpperCase(config));
  5303. cmTargetInternals::LinkInterfaceMapType::iterator
  5304. i = this->Internal->LinkInterfaceMap.find(key);
  5305. if(i == this->Internal->LinkInterfaceMap.end())
  5306. {
  5307. // Compute the link interface for this configuration.
  5308. cmTargetInternals::OptionalLinkInterface iface;
  5309. iface.ExplicitLibraries =
  5310. this->ComputeLinkInterfaceLibraries(config, iface, head, iface.Exists);
  5311. if (iface.Exists)
  5312. {
  5313. this->Internal->ComputeLinkInterface(this, config, iface,
  5314. head, iface.ExplicitLibraries);
  5315. }
  5316. // Store the information for this configuration.
  5317. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  5318. i = this->Internal->LinkInterfaceMap.insert(entry).first;
  5319. }
  5320. else if(!i->second.Complete && i->second.Exists)
  5321. {
  5322. this->Internal->ComputeLinkInterface(this, config, i->second, head,
  5323. i->second.ExplicitLibraries);
  5324. }
  5325. return i->second.Exists ? &i->second : 0;
  5326. }
  5327. //----------------------------------------------------------------------------
  5328. cmTarget::LinkInterface const*
  5329. cmTarget::GetLinkInterfaceLibraries(const std::string& config,
  5330. cmTarget const* head) const
  5331. {
  5332. // Imported targets have their own link interface.
  5333. if(this->IsImported())
  5334. {
  5335. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, head))
  5336. {
  5337. return &info->LinkInterface;
  5338. }
  5339. return 0;
  5340. }
  5341. // Link interfaces are not supported for executables that do not
  5342. // export symbols.
  5343. if(this->GetType() == cmTarget::EXECUTABLE &&
  5344. !this->IsExecutableWithExports())
  5345. {
  5346. return 0;
  5347. }
  5348. // Lookup any existing link interface for this configuration.
  5349. TargetConfigPair key(head, cmSystemTools::UpperCase(config));
  5350. cmTargetInternals::LinkInterfaceMapType::iterator
  5351. i = this->Internal->LinkInterfaceMap.find(key);
  5352. if(i == this->Internal->LinkInterfaceMap.end())
  5353. {
  5354. // Compute the link interface for this configuration.
  5355. cmTargetInternals::OptionalLinkInterface iface;
  5356. iface.ExplicitLibraries = this->ComputeLinkInterfaceLibraries(config,
  5357. iface,
  5358. head,
  5359. iface.Exists);
  5360. // Store the information for this configuration.
  5361. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  5362. i = this->Internal->LinkInterfaceMap.insert(entry).first;
  5363. }
  5364. return i->second.Exists ? &i->second : 0;
  5365. }
  5366. //----------------------------------------------------------------------------
  5367. void processILibs(const std::string& config,
  5368. cmTarget const* headTarget,
  5369. std::string const& name,
  5370. std::vector<cmTarget*>& tgts, std::set<cmTarget*>& emitted)
  5371. {
  5372. if (cmTarget* tgt = headTarget->GetMakefile()
  5373. ->FindTargetToUse(name))
  5374. {
  5375. if (emitted.insert(tgt).second)
  5376. {
  5377. tgts.push_back(tgt);
  5378. std::vector<std::string> ilibs;
  5379. cmTarget::LinkInterface const* iface =
  5380. tgt->GetLinkInterfaceLibraries(config, headTarget);
  5381. if (iface)
  5382. {
  5383. for(std::vector<std::string>::const_iterator
  5384. it = iface->Libraries.begin();
  5385. it != iface->Libraries.end(); ++it)
  5386. {
  5387. processILibs(config, headTarget, *it, tgts, emitted);
  5388. }
  5389. }
  5390. }
  5391. }
  5392. }
  5393. //----------------------------------------------------------------------------
  5394. void cmTarget::GetTransitiveTargetClosure(const std::string& config,
  5395. cmTarget const* headTarget,
  5396. std::vector<cmTarget*> &tgts) const
  5397. {
  5398. std::set<cmTarget*> emitted;
  5399. cmTarget::LinkImplementation const* impl
  5400. = this->GetLinkImplementationLibraries(config, headTarget);
  5401. for(std::vector<std::string>::const_iterator it = impl->Libraries.begin();
  5402. it != impl->Libraries.end(); ++it)
  5403. {
  5404. processILibs(config, headTarget, *it, tgts, emitted);
  5405. }
  5406. }
  5407. //----------------------------------------------------------------------------
  5408. void cmTarget::GetTransitivePropertyTargets(const std::string& config,
  5409. cmTarget const* headTarget,
  5410. std::vector<cmTarget*> &tgts) const
  5411. {
  5412. cmTarget::LinkInterface const* iface
  5413. = this->GetLinkInterfaceLibraries(config, headTarget);
  5414. if (!iface)
  5415. {
  5416. return;
  5417. }
  5418. if(this->GetType() != STATIC_LIBRARY
  5419. || this->GetPolicyStatusCMP0022() == cmPolicies::WARN
  5420. || this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  5421. {
  5422. for(std::vector<std::string>::const_iterator it = iface->Libraries.begin();
  5423. it != iface->Libraries.end(); ++it)
  5424. {
  5425. if (cmTarget* tgt = headTarget->GetMakefile()
  5426. ->FindTargetToUse(*it))
  5427. {
  5428. tgts.push_back(tgt);
  5429. }
  5430. }
  5431. return;
  5432. }
  5433. const char* linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  5434. const char* interfaceLibs = this->GetProperty(linkIfaceProp);
  5435. if (!interfaceLibs)
  5436. {
  5437. return;
  5438. }
  5439. // The interface libraries have been explicitly set.
  5440. cmListFileBacktrace lfbt;
  5441. cmGeneratorExpression ge(lfbt);
  5442. cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
  5443. linkIfaceProp, 0, 0);
  5444. dagChecker.SetTransitivePropertiesOnly();
  5445. std::vector<std::string> libs;
  5446. cmSystemTools::ExpandListArgument(ge.Parse(interfaceLibs)->Evaluate(
  5447. this->Makefile,
  5448. config,
  5449. false,
  5450. headTarget,
  5451. this, &dagChecker), libs);
  5452. for(std::vector<std::string>::const_iterator it = libs.begin();
  5453. it != libs.end(); ++it)
  5454. {
  5455. if (cmTarget* tgt = headTarget->GetMakefile()
  5456. ->FindTargetToUse(*it))
  5457. {
  5458. tgts.push_back(tgt);
  5459. }
  5460. }
  5461. }
  5462. //----------------------------------------------------------------------------
  5463. const char* cmTarget::ComputeLinkInterfaceLibraries(const std::string& config,
  5464. LinkInterface& iface,
  5465. cmTarget const* headTarget,
  5466. bool &exists) const
  5467. {
  5468. // Construct the property name suffix for this configuration.
  5469. std::string suffix = "_";
  5470. if(!config.empty())
  5471. {
  5472. suffix += cmSystemTools::UpperCase(config);
  5473. }
  5474. else
  5475. {
  5476. suffix += "NOCONFIG";
  5477. }
  5478. // An explicit list of interface libraries may be set for shared
  5479. // libraries and executables that export symbols.
  5480. const char* explicitLibraries = 0;
  5481. std::string linkIfaceProp;
  5482. if(this->PolicyStatusCMP0022 != cmPolicies::OLD &&
  5483. this->PolicyStatusCMP0022 != cmPolicies::WARN)
  5484. {
  5485. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  5486. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  5487. explicitLibraries = this->GetProperty(linkIfaceProp);
  5488. }
  5489. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  5490. this->IsExecutableWithExports())
  5491. {
  5492. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  5493. // shared lib or executable.
  5494. // Lookup the per-configuration property.
  5495. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5496. linkIfaceProp += suffix;
  5497. explicitLibraries = this->GetProperty(linkIfaceProp);
  5498. // If not set, try the generic property.
  5499. if(!explicitLibraries)
  5500. {
  5501. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5502. explicitLibraries = this->GetProperty(linkIfaceProp);
  5503. }
  5504. }
  5505. if(explicitLibraries && this->PolicyStatusCMP0022 == cmPolicies::WARN &&
  5506. !this->Internal->PolicyWarnedCMP0022)
  5507. {
  5508. // Compare the explicitly set old link interface properties to the
  5509. // preferred new link interface property one and warn if different.
  5510. const char* newExplicitLibraries =
  5511. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  5512. if (newExplicitLibraries
  5513. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  5514. {
  5515. cmOStringStream w;
  5516. w <<
  5517. (this->Makefile->GetPolicies()
  5518. ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
  5519. "Target \"" << this->GetName() << "\" has an "
  5520. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  5521. linkIfaceProp << " properties."
  5522. "\n"
  5523. "INTERFACE_LINK_LIBRARIES:\n"
  5524. " " << newExplicitLibraries << "\n" <<
  5525. linkIfaceProp << ":\n"
  5526. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  5527. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  5528. this->Internal->PolicyWarnedCMP0022 = true;
  5529. }
  5530. }
  5531. // There is no implicit link interface for executables or modules
  5532. // so if none was explicitly set then there is no link interface.
  5533. if(!explicitLibraries &&
  5534. (this->GetType() == cmTarget::EXECUTABLE ||
  5535. (this->GetType() == cmTarget::MODULE_LIBRARY)))
  5536. {
  5537. exists = false;
  5538. return 0;
  5539. }
  5540. exists = true;
  5541. if(explicitLibraries)
  5542. {
  5543. // The interface libraries have been explicitly set.
  5544. cmListFileBacktrace lfbt;
  5545. cmGeneratorExpression ge(lfbt);
  5546. cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
  5547. linkIfaceProp, 0, 0);
  5548. cmSystemTools::ExpandListArgument(ge.Parse(explicitLibraries)->Evaluate(
  5549. this->Makefile,
  5550. config,
  5551. false,
  5552. headTarget,
  5553. this, &dagChecker), iface.Libraries);
  5554. }
  5555. else if (this->PolicyStatusCMP0022 == cmPolicies::WARN
  5556. || this->PolicyStatusCMP0022 == cmPolicies::OLD)
  5557. // If CMP0022 is NEW then the plain tll signature sets the
  5558. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  5559. // cleared the property explicitly and we should not fall back
  5560. // to the link implementation.
  5561. {
  5562. // The link implementation is the default link interface.
  5563. LinkImplementation const* impl =
  5564. this->GetLinkImplementationLibraries(config, headTarget);
  5565. iface.Libraries = impl->Libraries;
  5566. if(this->PolicyStatusCMP0022 == cmPolicies::WARN &&
  5567. !this->Internal->PolicyWarnedCMP0022)
  5568. {
  5569. // Compare the link implementation fallback link interface to the
  5570. // preferred new link interface property and warn if different.
  5571. cmListFileBacktrace lfbt;
  5572. cmGeneratorExpression ge(lfbt);
  5573. cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
  5574. "INTERFACE_LINK_LIBRARIES", 0, 0);
  5575. std::vector<std::string> ifaceLibs;
  5576. const char* newExplicitLibraries =
  5577. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  5578. cmSystemTools::ExpandListArgument(
  5579. ge.Parse(newExplicitLibraries)->Evaluate(this->Makefile,
  5580. config,
  5581. false,
  5582. headTarget,
  5583. this, &dagChecker),
  5584. ifaceLibs);
  5585. if (ifaceLibs != impl->Libraries)
  5586. {
  5587. std::string oldLibraries;
  5588. std::string newLibraries;
  5589. const char *sep = "";
  5590. for(std::vector<std::string>::const_iterator it
  5591. = impl->Libraries.begin(); it != impl->Libraries.end(); ++it)
  5592. {
  5593. oldLibraries += sep;
  5594. oldLibraries += *it;
  5595. sep = ";";
  5596. }
  5597. sep = "";
  5598. for(std::vector<std::string>::const_iterator it
  5599. = ifaceLibs.begin(); it != ifaceLibs.end(); ++it)
  5600. {
  5601. newLibraries += sep;
  5602. newLibraries += *it;
  5603. sep = ";";
  5604. }
  5605. if(oldLibraries.empty())
  5606. { oldLibraries = "(empty)"; }
  5607. if(newLibraries.empty())
  5608. { newLibraries = "(empty)"; }
  5609. cmOStringStream w;
  5610. w <<
  5611. (this->Makefile->GetPolicies()
  5612. ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
  5613. "Target \"" << this->GetName() << "\" has an "
  5614. "INTERFACE_LINK_LIBRARIES property. "
  5615. "This should be preferred as the source of the link interface "
  5616. "for this library but because CMP0022 is not set CMake is "
  5617. "ignoring the property and using the link implementation "
  5618. "as the link interface instead."
  5619. "\n"
  5620. "INTERFACE_LINK_LIBRARIES:\n"
  5621. " " << newLibraries << "\n"
  5622. "Link implementation:\n"
  5623. " " << oldLibraries << "\n";
  5624. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  5625. this->Internal->PolicyWarnedCMP0022 = true;
  5626. }
  5627. }
  5628. }
  5629. return explicitLibraries;
  5630. }
  5631. //----------------------------------------------------------------------------
  5632. void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
  5633. const std::string& config,
  5634. OptionalLinkInterface& iface,
  5635. cmTarget const* headTarget,
  5636. const char* explicitLibraries) const
  5637. {
  5638. if(explicitLibraries)
  5639. {
  5640. if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY
  5641. || thisTarget->GetType() == cmTarget::STATIC_LIBRARY
  5642. || thisTarget->GetType() == cmTarget::INTERFACE_LIBRARY)
  5643. {
  5644. // Shared libraries may have runtime implementation dependencies
  5645. // on other shared libraries that are not in the interface.
  5646. std::set<std::string> emitted;
  5647. for(std::vector<std::string>::const_iterator
  5648. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  5649. {
  5650. emitted.insert(*li);
  5651. }
  5652. if (thisTarget->GetType() != cmTarget::INTERFACE_LIBRARY)
  5653. {
  5654. cmTarget::LinkImplementation const* impl =
  5655. thisTarget->GetLinkImplementation(config, headTarget);
  5656. for(std::vector<std::string>::const_iterator
  5657. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  5658. {
  5659. if(emitted.insert(*li).second)
  5660. {
  5661. if(cmTarget* tgt = thisTarget->Makefile->FindTargetToUse(*li))
  5662. {
  5663. // This is a runtime dependency on another shared library.
  5664. if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
  5665. {
  5666. iface.SharedDeps.push_back(*li);
  5667. }
  5668. }
  5669. else
  5670. {
  5671. // TODO: Recognize shared library file names. Perhaps this
  5672. // should be moved to cmComputeLinkInformation, but that creates
  5673. // a chicken-and-egg problem since this list is needed for its
  5674. // construction.
  5675. }
  5676. }
  5677. }
  5678. if(thisTarget->LinkLanguagePropagatesToDependents())
  5679. {
  5680. // Targets using this archive need its language runtime libraries.
  5681. iface.Languages = impl->Languages;
  5682. }
  5683. }
  5684. }
  5685. }
  5686. else if (thisTarget->PolicyStatusCMP0022 == cmPolicies::WARN
  5687. || thisTarget->PolicyStatusCMP0022 == cmPolicies::OLD)
  5688. {
  5689. // The link implementation is the default link interface.
  5690. cmTarget::LinkImplementation const*
  5691. impl = thisTarget->GetLinkImplementation(config, headTarget);
  5692. iface.ImplementationIsInterface = true;
  5693. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  5694. if(thisTarget->LinkLanguagePropagatesToDependents())
  5695. {
  5696. // Targets using this archive need its language runtime libraries.
  5697. iface.Languages = impl->Languages;
  5698. }
  5699. }
  5700. if(thisTarget->GetType() == cmTarget::STATIC_LIBRARY)
  5701. {
  5702. // Construct the property name suffix for this configuration.
  5703. std::string suffix = "_";
  5704. if(!config.empty())
  5705. {
  5706. suffix += cmSystemTools::UpperCase(config);
  5707. }
  5708. else
  5709. {
  5710. suffix += "NOCONFIG";
  5711. }
  5712. // How many repetitions are needed if this library has cyclic
  5713. // dependencies?
  5714. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  5715. propName += suffix;
  5716. if(const char* config_reps = thisTarget->GetProperty(propName))
  5717. {
  5718. sscanf(config_reps, "%u", &iface.Multiplicity);
  5719. }
  5720. else if(const char* reps =
  5721. thisTarget->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  5722. {
  5723. sscanf(reps, "%u", &iface.Multiplicity);
  5724. }
  5725. }
  5726. iface.Complete = true;
  5727. }
  5728. //----------------------------------------------------------------------------
  5729. cmTarget::LinkImplementation const*
  5730. cmTarget::GetLinkImplementation(const std::string& config,
  5731. cmTarget const* head) const
  5732. {
  5733. // There is no link implementation for imported targets.
  5734. if(this->IsImported())
  5735. {
  5736. return 0;
  5737. }
  5738. // Lookup any existing link implementation for this configuration.
  5739. TargetConfigPair key(head, cmSystemTools::UpperCase(config));
  5740. cmTargetInternals::LinkImplMapType::iterator
  5741. i = this->Internal->LinkImplMap.find(key);
  5742. if(i == this->Internal->LinkImplMap.end())
  5743. {
  5744. // Compute the link implementation for this configuration.
  5745. LinkImplementation impl;
  5746. this->ComputeLinkImplementation(config, impl, head);
  5747. this->ComputeLinkImplementationLanguages(config, impl, head);
  5748. // Store the information for this configuration.
  5749. cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
  5750. i = this->Internal->LinkImplMap.insert(entry).first;
  5751. }
  5752. else if (i->second.Languages.empty())
  5753. {
  5754. this->ComputeLinkImplementationLanguages(config, i->second, head);
  5755. }
  5756. return &i->second;
  5757. }
  5758. //----------------------------------------------------------------------------
  5759. cmTarget::LinkImplementation const*
  5760. cmTarget::GetLinkImplementationLibraries(const std::string& config,
  5761. cmTarget const* head) const
  5762. {
  5763. // There is no link implementation for imported targets.
  5764. if(this->IsImported())
  5765. {
  5766. return 0;
  5767. }
  5768. // Lookup any existing link implementation for this configuration.
  5769. TargetConfigPair key(head, cmSystemTools::UpperCase(config));
  5770. cmTargetInternals::LinkImplMapType::iterator
  5771. i = this->Internal->LinkImplMap.find(key);
  5772. if(i == this->Internal->LinkImplMap.end())
  5773. {
  5774. // Compute the link implementation for this configuration.
  5775. LinkImplementation impl;
  5776. this->ComputeLinkImplementation(config, impl, head);
  5777. // Store the information for this configuration.
  5778. cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
  5779. i = this->Internal->LinkImplMap.insert(entry).first;
  5780. }
  5781. return &i->second;
  5782. }
  5783. //----------------------------------------------------------------------------
  5784. void cmTarget::ComputeLinkImplementation(const std::string& config,
  5785. LinkImplementation& impl,
  5786. cmTarget const* head) const
  5787. {
  5788. // Collect libraries directly linked in this configuration.
  5789. std::vector<std::string> llibs;
  5790. this->GetDirectLinkLibraries(config, llibs, head);
  5791. for(std::vector<std::string>::const_iterator li = llibs.begin();
  5792. li != llibs.end(); ++li)
  5793. {
  5794. // Skip entries that resolve to the target itself or are empty.
  5795. std::string item = this->CheckCMP0004(*li);
  5796. if(item == this->GetName() || item.empty())
  5797. {
  5798. if(item == this->GetName())
  5799. {
  5800. bool noMessage = false;
  5801. cmake::MessageType messageType = cmake::FATAL_ERROR;
  5802. cmOStringStream e;
  5803. switch(this->GetPolicyStatusCMP0038())
  5804. {
  5805. case cmPolicies::WARN:
  5806. {
  5807. e << (this->Makefile->GetPolicies()
  5808. ->GetPolicyWarning(cmPolicies::CMP0038)) << "\n";
  5809. messageType = cmake::AUTHOR_WARNING;
  5810. }
  5811. break;
  5812. case cmPolicies::OLD:
  5813. noMessage = true;
  5814. case cmPolicies::REQUIRED_IF_USED:
  5815. case cmPolicies::REQUIRED_ALWAYS:
  5816. case cmPolicies::NEW:
  5817. // Issue the fatal message.
  5818. break;
  5819. }
  5820. if(!noMessage)
  5821. {
  5822. e << "Target \"" << this->GetName() << "\" links to itself.";
  5823. this->Makefile->GetCMakeInstance()->IssueMessage(messageType,
  5824. e.str(),
  5825. this->GetBacktrace());
  5826. if (messageType == cmake::FATAL_ERROR)
  5827. {
  5828. return;
  5829. }
  5830. }
  5831. }
  5832. continue;
  5833. }
  5834. // The entry is meant for this configuration.
  5835. impl.Libraries.push_back(item);
  5836. }
  5837. cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
  5838. LinkLibraryVectorType const& oldllibs = this->GetOriginalLinkLibraries();
  5839. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  5840. li != oldllibs.end(); ++li)
  5841. {
  5842. if(li->second != cmTarget::GENERAL && li->second != linkType)
  5843. {
  5844. std::string item = this->CheckCMP0004(li->first);
  5845. if(item == this->GetName() || item.empty())
  5846. {
  5847. continue;
  5848. }
  5849. // Support OLD behavior for CMP0003.
  5850. impl.WrongConfigLibraries.push_back(item);
  5851. }
  5852. }
  5853. }
  5854. //----------------------------------------------------------------------------
  5855. void
  5856. cmTarget::ComputeLinkImplementationLanguages(const std::string& config,
  5857. LinkImplementation& impl,
  5858. cmTarget const* head) const
  5859. {
  5860. // This target needs runtime libraries for its source languages.
  5861. std::set<std::string> languages;
  5862. // Get languages used in our source files.
  5863. this->GetLanguages(languages, config, head);
  5864. // Copy the set of langauges to the link implementation.
  5865. for(std::set<std::string>::iterator li = languages.begin();
  5866. li != languages.end(); ++li)
  5867. {
  5868. impl.Languages.push_back(*li);
  5869. }
  5870. }
  5871. //----------------------------------------------------------------------------
  5872. std::string cmTarget::CheckCMP0004(std::string const& item) const
  5873. {
  5874. // Strip whitespace off the library names because we used to do this
  5875. // in case variables were expanded at generate time. We no longer
  5876. // do the expansion but users link to libraries like " ${VAR} ".
  5877. std::string lib = item;
  5878. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  5879. if(pos != lib.npos)
  5880. {
  5881. lib = lib.substr(pos, lib.npos);
  5882. }
  5883. pos = lib.find_last_not_of(" \t\r\n");
  5884. if(pos != lib.npos)
  5885. {
  5886. lib = lib.substr(0, pos+1);
  5887. }
  5888. if(lib != item)
  5889. {
  5890. cmake* cm = this->Makefile->GetCMakeInstance();
  5891. switch(this->PolicyStatusCMP0004)
  5892. {
  5893. case cmPolicies::WARN:
  5894. {
  5895. cmOStringStream w;
  5896. w << (this->Makefile->GetPolicies()
  5897. ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
  5898. << "Target \"" << this->GetName() << "\" links to item \""
  5899. << item << "\" which has leading or trailing whitespace.";
  5900. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  5901. this->GetBacktrace());
  5902. }
  5903. case cmPolicies::OLD:
  5904. break;
  5905. case cmPolicies::NEW:
  5906. {
  5907. cmOStringStream e;
  5908. e << "Target \"" << this->GetName() << "\" links to item \""
  5909. << item << "\" which has leading or trailing whitespace. "
  5910. << "This is now an error according to policy CMP0004.";
  5911. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5912. }
  5913. break;
  5914. case cmPolicies::REQUIRED_IF_USED:
  5915. case cmPolicies::REQUIRED_ALWAYS:
  5916. {
  5917. cmOStringStream e;
  5918. e << (this->Makefile->GetPolicies()
  5919. ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
  5920. << "Target \"" << this->GetName() << "\" links to item \""
  5921. << item << "\" which has leading or trailing whitespace.";
  5922. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5923. }
  5924. break;
  5925. }
  5926. }
  5927. return lib;
  5928. }
  5929. template<typename PropertyType>
  5930. PropertyType getLinkInterfaceDependentProperty(cmTarget const* tgt,
  5931. const std::string& prop,
  5932. const std::string& config,
  5933. CompatibleType,
  5934. PropertyType *);
  5935. template<>
  5936. bool getLinkInterfaceDependentProperty(cmTarget const* tgt,
  5937. const std::string& prop,
  5938. const std::string& config,
  5939. CompatibleType, bool *)
  5940. {
  5941. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  5942. }
  5943. template<>
  5944. const char * getLinkInterfaceDependentProperty(cmTarget const* tgt,
  5945. const std::string& prop,
  5946. const std::string& config,
  5947. CompatibleType t,
  5948. const char **)
  5949. {
  5950. switch(t)
  5951. {
  5952. case BoolType:
  5953. assert(!"String compatibility check function called for boolean");
  5954. return 0;
  5955. case StringType:
  5956. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  5957. case NumberMinType:
  5958. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  5959. case NumberMaxType:
  5960. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  5961. }
  5962. assert(!"Unreachable!");
  5963. return 0;
  5964. }
  5965. //----------------------------------------------------------------------------
  5966. template<typename PropertyType>
  5967. void checkPropertyConsistency(cmTarget const* depender,
  5968. cmTarget const* dependee,
  5969. const std::string& propName,
  5970. std::set<std::string> &emitted,
  5971. const std::string& config,
  5972. CompatibleType t,
  5973. PropertyType *)
  5974. {
  5975. const char *prop = dependee->GetProperty(propName);
  5976. if (!prop)
  5977. {
  5978. return;
  5979. }
  5980. std::vector<std::string> props;
  5981. cmSystemTools::ExpandListArgument(prop, props);
  5982. std::string pdir =
  5983. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  5984. pdir += "/Help/prop_tgt/";
  5985. for(std::vector<std::string>::iterator pi = props.begin();
  5986. pi != props.end(); ++pi)
  5987. {
  5988. std::string pname = cmSystemTools::HelpFileName(*pi);
  5989. std::string pfile = pdir + pname + ".rst";
  5990. if(cmSystemTools::FileExists(pfile.c_str(), true))
  5991. {
  5992. cmOStringStream e;
  5993. e << "Target \"" << dependee->GetName() << "\" has property \""
  5994. << *pi << "\" listed in its " << propName << " property. "
  5995. "This is not allowed. Only user-defined properties may appear "
  5996. "listed in the " << propName << " property.";
  5997. depender->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
  5998. return;
  5999. }
  6000. if(emitted.insert(*pi).second)
  6001. {
  6002. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  6003. t, 0);
  6004. if (cmSystemTools::GetErrorOccuredFlag())
  6005. {
  6006. return;
  6007. }
  6008. }
  6009. }
  6010. }
  6011. static std::string intersect(const std::set<std::string> &s1,
  6012. const std::set<std::string> &s2)
  6013. {
  6014. std::set<std::string> intersect;
  6015. std::set_intersection(s1.begin(),s1.end(),
  6016. s2.begin(),s2.end(),
  6017. std::inserter(intersect,intersect.begin()));
  6018. if (!intersect.empty())
  6019. {
  6020. return *intersect.begin();
  6021. }
  6022. return "";
  6023. }
  6024. static std::string intersect(const std::set<std::string> &s1,
  6025. const std::set<std::string> &s2,
  6026. const std::set<std::string> &s3)
  6027. {
  6028. std::string result;
  6029. result = intersect(s1, s2);
  6030. if (!result.empty())
  6031. return result;
  6032. result = intersect(s1, s3);
  6033. if (!result.empty())
  6034. return result;
  6035. return intersect(s2, s3);
  6036. }
  6037. static std::string intersect(const std::set<std::string> &s1,
  6038. const std::set<std::string> &s2,
  6039. const std::set<std::string> &s3,
  6040. const std::set<std::string> &s4)
  6041. {
  6042. std::string result;
  6043. result = intersect(s1, s2);
  6044. if (!result.empty())
  6045. return result;
  6046. result = intersect(s1, s3);
  6047. if (!result.empty())
  6048. return result;
  6049. result = intersect(s1, s4);
  6050. if (!result.empty())
  6051. return result;
  6052. return intersect(s2, s3, s4);
  6053. }
  6054. //----------------------------------------------------------------------------
  6055. void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
  6056. const std::string& config) const
  6057. {
  6058. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  6059. std::set<std::string> emittedBools;
  6060. std::set<std::string> emittedStrings;
  6061. std::set<std::string> emittedMinNumbers;
  6062. std::set<std::string> emittedMaxNumbers;
  6063. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  6064. deps.begin();
  6065. li != deps.end(); ++li)
  6066. {
  6067. if (!li->Target)
  6068. {
  6069. continue;
  6070. }
  6071. checkPropertyConsistency<bool>(this, li->Target,
  6072. std::string("COMPATIBLE_INTERFACE_BOOL"),
  6073. emittedBools, config, BoolType, 0);
  6074. if (cmSystemTools::GetErrorOccuredFlag())
  6075. {
  6076. return;
  6077. }
  6078. checkPropertyConsistency<const char *>(this, li->Target,
  6079. std::string("COMPATIBLE_INTERFACE_STRING"),
  6080. emittedStrings, config,
  6081. StringType, 0);
  6082. if (cmSystemTools::GetErrorOccuredFlag())
  6083. {
  6084. return;
  6085. }
  6086. checkPropertyConsistency<const char *>(this, li->Target,
  6087. std::string("COMPATIBLE_INTERFACE_NUMBER_MIN"),
  6088. emittedMinNumbers, config,
  6089. NumberMinType, 0);
  6090. if (cmSystemTools::GetErrorOccuredFlag())
  6091. {
  6092. return;
  6093. }
  6094. checkPropertyConsistency<const char *>(this, li->Target,
  6095. std::string("COMPATIBLE_INTERFACE_NUMBER_MAX"),
  6096. emittedMaxNumbers, config,
  6097. NumberMaxType, 0);
  6098. if (cmSystemTools::GetErrorOccuredFlag())
  6099. {
  6100. return;
  6101. }
  6102. }
  6103. std::string prop = intersect(emittedBools,
  6104. emittedStrings,
  6105. emittedMinNumbers,
  6106. emittedMaxNumbers);
  6107. if (!prop.empty())
  6108. {
  6109. std::set<std::string> props;
  6110. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  6111. if (i != emittedBools.end())
  6112. {
  6113. props.insert("COMPATIBLE_INTERFACE_BOOL");
  6114. }
  6115. i = emittedStrings.find(prop);
  6116. if (i != emittedStrings.end())
  6117. {
  6118. props.insert("COMPATIBLE_INTERFACE_STRING");
  6119. }
  6120. i = emittedMinNumbers.find(prop);
  6121. if (i != emittedMinNumbers.end())
  6122. {
  6123. props.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
  6124. }
  6125. i = emittedMaxNumbers.find(prop);
  6126. if (i != emittedMaxNumbers.end())
  6127. {
  6128. props.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
  6129. }
  6130. std::string propsString = *props.begin();
  6131. props.erase(props.begin());
  6132. while (props.size() > 1)
  6133. {
  6134. propsString += ", " + *props.begin();
  6135. props.erase(props.begin());
  6136. }
  6137. if (props.size() == 1)
  6138. {
  6139. propsString += " and the " + *props.begin();
  6140. }
  6141. cmOStringStream e;
  6142. e << "Property \"" << prop << "\" appears in both the "
  6143. << propsString <<
  6144. " property in the dependencies of target \"" << this->GetName() <<
  6145. "\". This is not allowed. A property may only require compatibility "
  6146. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  6147. "string interpretation, but not a mixture.";
  6148. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  6149. }
  6150. }
  6151. //----------------------------------------------------------------------------
  6152. cmComputeLinkInformation*
  6153. cmTarget::GetLinkInformation(const std::string& config,
  6154. cmTarget const* head) const
  6155. {
  6156. cmTarget const* headTarget = head ? head : this;
  6157. // Lookup any existing information for this configuration.
  6158. TargetConfigPair key(headTarget, cmSystemTools::UpperCase(config));
  6159. cmTargetLinkInformationMap::iterator
  6160. i = this->LinkInformation.find(key);
  6161. if(i == this->LinkInformation.end())
  6162. {
  6163. // Compute information for this configuration.
  6164. cmComputeLinkInformation* info =
  6165. new cmComputeLinkInformation(this, config, headTarget);
  6166. if(!info || !info->Compute())
  6167. {
  6168. delete info;
  6169. info = 0;
  6170. }
  6171. // Store the information for this configuration.
  6172. cmTargetLinkInformationMap::value_type entry(key, info);
  6173. i = this->LinkInformation.insert(entry).first;
  6174. if (info)
  6175. {
  6176. this->CheckPropertyCompatibility(info, config);
  6177. }
  6178. }
  6179. return i->second;
  6180. }
  6181. //----------------------------------------------------------------------------
  6182. std::string cmTarget::GetFrameworkDirectory(const std::string& config,
  6183. bool rootDir) const
  6184. {
  6185. std::string fpath;
  6186. fpath += this->GetOutputName(config, false);
  6187. fpath += ".framework";
  6188. if(!rootDir)
  6189. {
  6190. fpath += "/Versions/";
  6191. fpath += this->GetFrameworkVersion();
  6192. }
  6193. return fpath;
  6194. }
  6195. //----------------------------------------------------------------------------
  6196. std::string cmTarget::GetCFBundleDirectory(const std::string& config,
  6197. bool contentOnly) const
  6198. {
  6199. std::string fpath;
  6200. fpath += this->GetOutputName(config, false);
  6201. fpath += ".";
  6202. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  6203. if (!ext)
  6204. {
  6205. ext = "bundle";
  6206. }
  6207. fpath += ext;
  6208. fpath += "/Contents";
  6209. if(!contentOnly)
  6210. fpath += "/MacOS";
  6211. return fpath;
  6212. }
  6213. //----------------------------------------------------------------------------
  6214. std::string cmTarget::GetAppBundleDirectory(const std::string& config,
  6215. bool contentOnly) const
  6216. {
  6217. std::string fpath = this->GetFullName(config, false);
  6218. fpath += ".app/Contents";
  6219. if(!contentOnly)
  6220. fpath += "/MacOS";
  6221. return fpath;
  6222. }
  6223. //----------------------------------------------------------------------------
  6224. std::string cmTarget::BuildMacContentDirectory(const std::string& base,
  6225. const std::string& config,
  6226. bool contentOnly) const
  6227. {
  6228. std::string fpath = base;
  6229. if(this->IsAppBundleOnApple())
  6230. {
  6231. fpath += this->GetAppBundleDirectory(config, contentOnly);
  6232. }
  6233. if(this->IsFrameworkOnApple())
  6234. {
  6235. fpath += this->GetFrameworkDirectory(config, contentOnly);
  6236. }
  6237. if(this->IsCFBundleOnApple())
  6238. {
  6239. fpath += this->GetCFBundleDirectory(config, contentOnly);
  6240. }
  6241. return fpath;
  6242. }
  6243. //----------------------------------------------------------------------------
  6244. std::string cmTarget::GetMacContentDirectory(const std::string& config,
  6245. bool implib) const
  6246. {
  6247. // Start with the output directory for the target.
  6248. std::string fpath = this->GetDirectory(config, implib);
  6249. fpath += "/";
  6250. bool contentOnly = true;
  6251. if(this->IsFrameworkOnApple())
  6252. {
  6253. // additional files with a framework go into the version specific
  6254. // directory
  6255. contentOnly = false;
  6256. }
  6257. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  6258. return fpath;
  6259. }
  6260. //----------------------------------------------------------------------------
  6261. cmTargetLinkInformationMap
  6262. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  6263. {
  6264. // Ideally cmTarget instances should never be copied. However until
  6265. // we can make a sweep to remove that, this copy constructor avoids
  6266. // allowing the resources (LinkInformation) from getting copied. In
  6267. // the worst case this will lead to extra cmComputeLinkInformation
  6268. // instances. We also enforce in debug mode that the map be emptied
  6269. // when copied.
  6270. static_cast<void>(r);
  6271. assert(r.empty());
  6272. }
  6273. //----------------------------------------------------------------------------
  6274. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  6275. {
  6276. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  6277. {
  6278. delete i->second;
  6279. }
  6280. }
  6281. //----------------------------------------------------------------------------
  6282. cmTargetInternalPointer::cmTargetInternalPointer()
  6283. {
  6284. this->Pointer = new cmTargetInternals;
  6285. }
  6286. //----------------------------------------------------------------------------
  6287. cmTargetInternalPointer
  6288. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  6289. {
  6290. // Ideally cmTarget instances should never be copied. However until
  6291. // we can make a sweep to remove that, this copy constructor avoids
  6292. // allowing the resources (Internals) to be copied.
  6293. this->Pointer = new cmTargetInternals(*r.Pointer);
  6294. }
  6295. //----------------------------------------------------------------------------
  6296. cmTargetInternalPointer::~cmTargetInternalPointer()
  6297. {
  6298. deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
  6299. deleteAndClear(this->Pointer->CompileOptionsEntries);
  6300. deleteAndClear(this->Pointer->CompileDefinitionsEntries);
  6301. deleteAndClear(this->Pointer->SourceEntries);
  6302. delete this->Pointer;
  6303. }
  6304. //----------------------------------------------------------------------------
  6305. cmTargetInternalPointer&
  6306. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  6307. {
  6308. if(this == &r) { return *this; } // avoid warning on HP about self check
  6309. // Ideally cmTarget instances should never be copied. However until
  6310. // we can make a sweep to remove that, this copy constructor avoids
  6311. // allowing the resources (Internals) to be copied.
  6312. cmTargetInternals* oldPointer = this->Pointer;
  6313. this->Pointer = new cmTargetInternals(*r.Pointer);
  6314. delete oldPointer;
  6315. return *this;
  6316. }