cmTarget.cxx 223 KB

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