cmTarget.cxx 231 KB

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