cmTarget.cxx 223 KB

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