cmTarget.cxx 232 KB

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