cmTarget.cxx 223 KB

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