cmTarget.cxx 231 KB

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