cmTarget.cxx 221 KB

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