cmTarget.cxx 230 KB

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