cmTarget.cxx 233 KB

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