cmTarget.cxx 232 KB

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