cmTarget.cxx 223 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913
  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::ImportedGetLocation(const std::string& config) const
  2491. {
  2492. static std::string location;
  2493. assert(this->IsImported());
  2494. location = this->ImportedGetFullPath(config, false);
  2495. return location.c_str();
  2496. }
  2497. //----------------------------------------------------------------------------
  2498. const char* cmTarget::GetLocationForBuild() const
  2499. {
  2500. static std::string location;
  2501. if(this->IsImported())
  2502. {
  2503. location = this->ImportedGetFullPath("", false);
  2504. return location.c_str();
  2505. }
  2506. // Now handle the deprecated build-time configuration location.
  2507. location = this->GetDirectory();
  2508. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  2509. if(cfgid && strcmp(cfgid, ".") != 0)
  2510. {
  2511. location += "/";
  2512. location += cfgid;
  2513. }
  2514. if(this->IsAppBundleOnApple())
  2515. {
  2516. std::string macdir = this->BuildMacContentDirectory("", "", false);
  2517. if(!macdir.empty())
  2518. {
  2519. location += "/";
  2520. location += macdir;
  2521. }
  2522. }
  2523. location += "/";
  2524. location += this->GetFullName("", false);
  2525. return location.c_str();
  2526. }
  2527. //----------------------------------------------------------------------------
  2528. void cmTarget::GetTargetVersion(int& major, int& minor) const
  2529. {
  2530. int patch;
  2531. this->GetTargetVersion(false, major, minor, patch);
  2532. }
  2533. //----------------------------------------------------------------------------
  2534. void cmTarget::GetTargetVersion(bool soversion,
  2535. int& major, int& minor, int& patch) const
  2536. {
  2537. // Set the default values.
  2538. major = 0;
  2539. minor = 0;
  2540. patch = 0;
  2541. assert(this->GetType() != INTERFACE_LIBRARY);
  2542. // Look for a VERSION or SOVERSION property.
  2543. const char* prop = soversion? "SOVERSION" : "VERSION";
  2544. if(const char* version = this->GetProperty(prop))
  2545. {
  2546. // Try to parse the version number and store the results that were
  2547. // successfully parsed.
  2548. int parsed_major;
  2549. int parsed_minor;
  2550. int parsed_patch;
  2551. switch(sscanf(version, "%d.%d.%d",
  2552. &parsed_major, &parsed_minor, &parsed_patch))
  2553. {
  2554. case 3: patch = parsed_patch; // no break!
  2555. case 2: minor = parsed_minor; // no break!
  2556. case 1: major = parsed_major; // no break!
  2557. default: break;
  2558. }
  2559. }
  2560. }
  2561. //----------------------------------------------------------------------------
  2562. bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const
  2563. {
  2564. if (this->IsImported())
  2565. {
  2566. return true;
  2567. }
  2568. std::ostringstream e;
  2569. const char *modal = 0;
  2570. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  2571. switch (context->GetPolicyStatus(cmPolicies::CMP0026))
  2572. {
  2573. case cmPolicies::WARN:
  2574. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
  2575. modal = "should";
  2576. case cmPolicies::OLD:
  2577. break;
  2578. case cmPolicies::REQUIRED_ALWAYS:
  2579. case cmPolicies::REQUIRED_IF_USED:
  2580. case cmPolicies::NEW:
  2581. modal = "may";
  2582. messageType = cmake::FATAL_ERROR;
  2583. }
  2584. if (modal)
  2585. {
  2586. e << "The LOCATION property " << modal << " not be read from target \""
  2587. << this->GetName() << "\". Use the target name directly with "
  2588. "add_custom_command, or use the generator expression $<TARGET_FILE>, "
  2589. "as appropriate.\n";
  2590. context->IssueMessage(messageType, e.str());
  2591. }
  2592. return messageType != cmake::FATAL_ERROR;
  2593. }
  2594. //----------------------------------------------------------------------------
  2595. static void MakePropertyList(std::string& output,
  2596. std::vector<cmTargetInternals::TargetPropertyEntry*> const& values)
  2597. {
  2598. output = "";
  2599. std::string sep;
  2600. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  2601. it = values.begin(), end = values.end();
  2602. it != end; ++it)
  2603. {
  2604. output += sep;
  2605. output += (*it)->ge->GetInput();
  2606. sep = ";";
  2607. }
  2608. }
  2609. //----------------------------------------------------------------------------
  2610. const char *cmTarget::GetProperty(const std::string& prop) const
  2611. {
  2612. return this->GetProperty(prop, this->Makefile);
  2613. }
  2614. //----------------------------------------------------------------------------
  2615. const char *cmTarget::GetProperty(const std::string& prop,
  2616. cmMakefile* context) const
  2617. {
  2618. if (this->GetType() == INTERFACE_LIBRARY
  2619. && !whiteListedInterfaceProperty(prop))
  2620. {
  2621. std::ostringstream e;
  2622. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  2623. "The property \"" << prop << "\" is not allowed.";
  2624. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2625. return 0;
  2626. }
  2627. // Watch for special "computed" properties that are dependent on
  2628. // other properties or variables. Always recompute them.
  2629. if(this->GetType() == cmTarget::EXECUTABLE ||
  2630. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2631. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2632. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2633. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  2634. {
  2635. static const std::string propLOCATION = "LOCATION";
  2636. if(prop == propLOCATION)
  2637. {
  2638. if (!this->HandleLocationPropertyPolicy(context))
  2639. {
  2640. return 0;
  2641. }
  2642. // Set the LOCATION property of the target.
  2643. //
  2644. // For an imported target this is the location of an arbitrary
  2645. // available configuration.
  2646. //
  2647. if(this->IsImported())
  2648. {
  2649. this->Properties.SetProperty(
  2650. propLOCATION, this->ImportedGetFullPath("", false).c_str());
  2651. }
  2652. else
  2653. {
  2654. // For a non-imported target this is deprecated because it
  2655. // cannot take into account the per-configuration name of the
  2656. // target because the configuration type may not be known at
  2657. // CMake time.
  2658. this->Properties.SetProperty(
  2659. propLOCATION, this->GetLocationForBuild());
  2660. }
  2661. }
  2662. // Support "LOCATION_<CONFIG>".
  2663. else if(cmHasLiteralPrefix(prop, "LOCATION_"))
  2664. {
  2665. if (!this->HandleLocationPropertyPolicy(context))
  2666. {
  2667. return 0;
  2668. }
  2669. const char* configName = prop.c_str() + 9;
  2670. if (this->IsImported())
  2671. {
  2672. this->Properties.SetProperty(
  2673. prop, this->ImportedGetFullPath(configName, false).c_str());
  2674. }
  2675. else
  2676. {
  2677. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  2678. gg->CreateGenerationObjects();
  2679. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  2680. this->Properties.SetProperty(
  2681. prop, gt->Target->GetFullPath(configName, false).c_str());
  2682. }
  2683. }
  2684. // Support "<CONFIG>_LOCATION".
  2685. else if(cmHasLiteralSuffix(prop, "_LOCATION"))
  2686. {
  2687. std::string configName(prop.c_str(), prop.size() - 9);
  2688. if(configName != "IMPORTED")
  2689. {
  2690. if (!this->HandleLocationPropertyPolicy(context))
  2691. {
  2692. return 0;
  2693. }
  2694. if (this->IsImported())
  2695. {
  2696. this->Properties.SetProperty(
  2697. prop, this->ImportedGetFullPath(configName, false).c_str());
  2698. }
  2699. else
  2700. {
  2701. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  2702. gg->CreateGenerationObjects();
  2703. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  2704. this->Properties.SetProperty(
  2705. prop, gt->Target->GetFullPath(configName, false).c_str());
  2706. }
  2707. }
  2708. }
  2709. }
  2710. static UNORDERED_SET<std::string> specialProps;
  2711. #define MAKE_STATIC_PROP(PROP) \
  2712. static const std::string prop##PROP = #PROP
  2713. MAKE_STATIC_PROP(LINK_LIBRARIES);
  2714. MAKE_STATIC_PROP(TYPE);
  2715. MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
  2716. MAKE_STATIC_PROP(COMPILE_FEATURES);
  2717. MAKE_STATIC_PROP(COMPILE_OPTIONS);
  2718. MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
  2719. MAKE_STATIC_PROP(IMPORTED);
  2720. MAKE_STATIC_PROP(NAME);
  2721. MAKE_STATIC_PROP(BINARY_DIR);
  2722. MAKE_STATIC_PROP(SOURCE_DIR);
  2723. MAKE_STATIC_PROP(SOURCES);
  2724. #undef MAKE_STATIC_PROP
  2725. if(specialProps.empty())
  2726. {
  2727. specialProps.insert(propLINK_LIBRARIES);
  2728. specialProps.insert(propTYPE);
  2729. specialProps.insert(propINCLUDE_DIRECTORIES);
  2730. specialProps.insert(propCOMPILE_FEATURES);
  2731. specialProps.insert(propCOMPILE_OPTIONS);
  2732. specialProps.insert(propCOMPILE_DEFINITIONS);
  2733. specialProps.insert(propIMPORTED);
  2734. specialProps.insert(propNAME);
  2735. specialProps.insert(propBINARY_DIR);
  2736. specialProps.insert(propSOURCE_DIR);
  2737. specialProps.insert(propSOURCES);
  2738. }
  2739. if(specialProps.count(prop))
  2740. {
  2741. if(prop == propLINK_LIBRARIES)
  2742. {
  2743. if (this->Internal->LinkImplementationPropertyEntries.empty())
  2744. {
  2745. return 0;
  2746. }
  2747. static std::string output;
  2748. output = "";
  2749. std::string sep;
  2750. for (std::vector<cmValueWithOrigin>::const_iterator
  2751. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  2752. end = this->Internal->LinkImplementationPropertyEntries.end();
  2753. it != end; ++it)
  2754. {
  2755. output += sep;
  2756. output += it->Value;
  2757. sep = ";";
  2758. }
  2759. return output.c_str();
  2760. }
  2761. // the type property returns what type the target is
  2762. else if (prop == propTYPE)
  2763. {
  2764. return cmTarget::GetTargetTypeName(this->GetType());
  2765. }
  2766. else if(prop == propINCLUDE_DIRECTORIES)
  2767. {
  2768. if (this->Internal->IncludeDirectoriesEntries.empty())
  2769. {
  2770. return 0;
  2771. }
  2772. static std::string output;
  2773. MakePropertyList(output, this->Internal->IncludeDirectoriesEntries);
  2774. return output.c_str();
  2775. }
  2776. else if(prop == propCOMPILE_FEATURES)
  2777. {
  2778. if (this->Internal->CompileFeaturesEntries.empty())
  2779. {
  2780. return 0;
  2781. }
  2782. static std::string output;
  2783. MakePropertyList(output, this->Internal->CompileFeaturesEntries);
  2784. return output.c_str();
  2785. }
  2786. else if(prop == propCOMPILE_OPTIONS)
  2787. {
  2788. if (this->Internal->CompileOptionsEntries.empty())
  2789. {
  2790. return 0;
  2791. }
  2792. static std::string output;
  2793. MakePropertyList(output, this->Internal->CompileOptionsEntries);
  2794. return output.c_str();
  2795. }
  2796. else if(prop == propCOMPILE_DEFINITIONS)
  2797. {
  2798. if (this->Internal->CompileDefinitionsEntries.empty())
  2799. {
  2800. return 0;
  2801. }
  2802. static std::string output;
  2803. MakePropertyList(output, this->Internal->CompileDefinitionsEntries);
  2804. return output.c_str();
  2805. }
  2806. else if (prop == propIMPORTED)
  2807. {
  2808. return this->IsImported()?"TRUE":"FALSE";
  2809. }
  2810. else if (prop == propNAME)
  2811. {
  2812. return this->GetName().c_str();
  2813. }
  2814. else if (prop == propBINARY_DIR)
  2815. {
  2816. return this->GetMakefile()->GetCurrentBinaryDirectory();
  2817. }
  2818. else if (prop == propSOURCE_DIR)
  2819. {
  2820. return this->GetMakefile()->GetCurrentSourceDirectory();
  2821. }
  2822. else if(prop == propSOURCES)
  2823. {
  2824. if (this->Internal->SourceEntries.empty())
  2825. {
  2826. return 0;
  2827. }
  2828. std::ostringstream ss;
  2829. const char* sep = "";
  2830. typedef cmTargetInternals::TargetPropertyEntry
  2831. TargetPropertyEntry;
  2832. for(std::vector<TargetPropertyEntry*>::const_iterator
  2833. i = this->Internal->SourceEntries.begin();
  2834. i != this->Internal->SourceEntries.end(); ++i)
  2835. {
  2836. std::string entry = (*i)->ge->GetInput();
  2837. std::vector<std::string> files;
  2838. cmSystemTools::ExpandListArgument(entry, files);
  2839. for (std::vector<std::string>::const_iterator
  2840. li = files.begin(); li != files.end(); ++li)
  2841. {
  2842. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  2843. (*li)[li->size() - 1] == '>')
  2844. {
  2845. std::string objLibName = li->substr(17, li->size()-18);
  2846. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  2847. {
  2848. ss << sep;
  2849. sep = ";";
  2850. ss << *li;
  2851. continue;
  2852. }
  2853. bool addContent = false;
  2854. bool noMessage = true;
  2855. std::ostringstream e;
  2856. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  2857. switch(context->GetPolicyStatus(cmPolicies::CMP0051))
  2858. {
  2859. case cmPolicies::WARN:
  2860. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
  2861. noMessage = false;
  2862. case cmPolicies::OLD:
  2863. break;
  2864. case cmPolicies::REQUIRED_ALWAYS:
  2865. case cmPolicies::REQUIRED_IF_USED:
  2866. case cmPolicies::NEW:
  2867. addContent = true;
  2868. }
  2869. if (!noMessage)
  2870. {
  2871. e << "Target \"" << this->Name << "\" contains "
  2872. "$<TARGET_OBJECTS> generator expression in its sources list. "
  2873. "This content was not previously part of the SOURCES property "
  2874. "when that property was read at configure time. Code reading "
  2875. "that property needs to be adapted to ignore the generator "
  2876. "expression using the string(GENEX_STRIP) command.";
  2877. context->IssueMessage(messageType, e.str());
  2878. }
  2879. if (addContent)
  2880. {
  2881. ss << sep;
  2882. sep = ";";
  2883. ss << *li;
  2884. }
  2885. }
  2886. else if (cmGeneratorExpression::Find(*li) == std::string::npos)
  2887. {
  2888. ss << sep;
  2889. sep = ";";
  2890. ss << *li;
  2891. }
  2892. else
  2893. {
  2894. cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li);
  2895. // Construct what is known about this source file location.
  2896. cmSourceFileLocation const& location = sf->GetLocation();
  2897. std::string sname = location.GetDirectory();
  2898. if(!sname.empty())
  2899. {
  2900. sname += "/";
  2901. }
  2902. sname += location.GetName();
  2903. ss << sep;
  2904. sep = ";";
  2905. // Append this list entry.
  2906. ss << sname;
  2907. }
  2908. }
  2909. }
  2910. this->Properties.SetProperty("SOURCES", ss.str().c_str());
  2911. }
  2912. }
  2913. const char *retVal = this->Properties.GetPropertyValue(prop);
  2914. if (!retVal)
  2915. {
  2916. const bool chain = this->GetMakefile()->GetState()->
  2917. IsPropertyChained(prop, cmProperty::TARGET);
  2918. if (chain)
  2919. {
  2920. return this->Makefile->GetProperty(prop, chain);
  2921. }
  2922. }
  2923. return retVal;
  2924. }
  2925. //----------------------------------------------------------------------------
  2926. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  2927. {
  2928. return cmSystemTools::IsOn(this->GetProperty(prop));
  2929. }
  2930. //----------------------------------------------------------------------------
  2931. class cmTargetCollectLinkLanguages
  2932. {
  2933. public:
  2934. cmTargetCollectLinkLanguages(cmTarget const* target,
  2935. const std::string& config,
  2936. UNORDERED_SET<std::string>& languages,
  2937. cmTarget const* head):
  2938. Config(config), Languages(languages), HeadTarget(head),
  2939. Makefile(target->GetMakefile()), Target(target)
  2940. { this->Visited.insert(target); }
  2941. void Visit(cmLinkItem const& item)
  2942. {
  2943. if(!item.Target)
  2944. {
  2945. if(item.find("::") != std::string::npos)
  2946. {
  2947. bool noMessage = false;
  2948. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2949. std::ostringstream e;
  2950. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
  2951. {
  2952. case cmPolicies::WARN:
  2953. {
  2954. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  2955. messageType = cmake::AUTHOR_WARNING;
  2956. }
  2957. break;
  2958. case cmPolicies::OLD:
  2959. noMessage = true;
  2960. case cmPolicies::REQUIRED_IF_USED:
  2961. case cmPolicies::REQUIRED_ALWAYS:
  2962. case cmPolicies::NEW:
  2963. // Issue the fatal message.
  2964. break;
  2965. }
  2966. if(!noMessage)
  2967. {
  2968. e << "Target \"" << this->Target->GetName()
  2969. << "\" links to target \"" << item
  2970. << "\" but the target was not found. Perhaps a find_package() "
  2971. "call is missing for an IMPORTED target, or an ALIAS target is "
  2972. "missing?";
  2973. this->Makefile->GetCMakeInstance()->IssueMessage(messageType,
  2974. e.str(),
  2975. this->Target->GetBacktrace());
  2976. }
  2977. }
  2978. return;
  2979. }
  2980. if(!this->Visited.insert(item.Target).second)
  2981. {
  2982. return;
  2983. }
  2984. cmTarget::LinkInterface const* iface =
  2985. item.Target->GetLinkInterface(this->Config, this->HeadTarget);
  2986. if(!iface) { return; }
  2987. for(std::vector<std::string>::const_iterator
  2988. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  2989. {
  2990. this->Languages.insert(*li);
  2991. }
  2992. for(std::vector<cmLinkItem>::const_iterator
  2993. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  2994. {
  2995. this->Visit(*li);
  2996. }
  2997. }
  2998. private:
  2999. std::string Config;
  3000. UNORDERED_SET<std::string>& Languages;
  3001. cmTarget const* HeadTarget;
  3002. cmMakefile* Makefile;
  3003. const cmTarget* Target;
  3004. std::set<cmTarget const*> Visited;
  3005. };
  3006. //----------------------------------------------------------------------------
  3007. std::string cmTarget::GetLinkerLanguage(const std::string& config) const
  3008. {
  3009. return this->GetLinkClosure(config)->LinkerLanguage;
  3010. }
  3011. //----------------------------------------------------------------------------
  3012. cmTarget::LinkClosure const*
  3013. cmTarget::GetLinkClosure(const std::string& config) const
  3014. {
  3015. std::string key(cmSystemTools::UpperCase(config));
  3016. cmTargetInternals::LinkClosureMapType::iterator
  3017. i = this->Internal->LinkClosureMap.find(key);
  3018. if(i == this->Internal->LinkClosureMap.end())
  3019. {
  3020. LinkClosure lc;
  3021. this->ComputeLinkClosure(config, lc);
  3022. cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
  3023. i = this->Internal->LinkClosureMap.insert(entry).first;
  3024. }
  3025. return &i->second;
  3026. }
  3027. //----------------------------------------------------------------------------
  3028. class cmTargetSelectLinker
  3029. {
  3030. int Preference;
  3031. cmTarget const* Target;
  3032. cmMakefile* Makefile;
  3033. cmGlobalGenerator* GG;
  3034. UNORDERED_SET<std::string> Preferred;
  3035. public:
  3036. cmTargetSelectLinker(cmTarget const* target): Preference(0), Target(target)
  3037. {
  3038. this->Makefile = this->Target->GetMakefile();
  3039. this->GG = this->Makefile->GetGlobalGenerator();
  3040. }
  3041. void Consider(const std::string& lang)
  3042. {
  3043. int preference = this->GG->GetLinkerPreference(lang);
  3044. if(preference > this->Preference)
  3045. {
  3046. this->Preference = preference;
  3047. this->Preferred.clear();
  3048. }
  3049. if(preference == this->Preference)
  3050. {
  3051. this->Preferred.insert(lang);
  3052. }
  3053. }
  3054. std::string Choose()
  3055. {
  3056. if(this->Preferred.empty())
  3057. {
  3058. return "";
  3059. }
  3060. else if(this->Preferred.size() > 1)
  3061. {
  3062. std::ostringstream e;
  3063. e << "Target " << this->Target->GetName()
  3064. << " contains multiple languages with the highest linker preference"
  3065. << " (" << this->Preference << "):\n";
  3066. for(UNORDERED_SET<std::string>::const_iterator
  3067. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  3068. {
  3069. e << " " << *li << "\n";
  3070. }
  3071. e << "Set the LINKER_LANGUAGE property for this target.";
  3072. cmake* cm = this->Makefile->GetCMakeInstance();
  3073. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  3074. this->Target->GetBacktrace());
  3075. }
  3076. return *this->Preferred.begin();
  3077. }
  3078. };
  3079. //----------------------------------------------------------------------------
  3080. void cmTarget::ComputeLinkClosure(const std::string& config,
  3081. LinkClosure& lc) const
  3082. {
  3083. // Get languages built in this target.
  3084. UNORDERED_SET<std::string> languages;
  3085. LinkImplementation const* impl = this->GetLinkImplementation(config);
  3086. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3087. li != impl->Languages.end(); ++li)
  3088. {
  3089. languages.insert(*li);
  3090. }
  3091. // Add interface languages from linked targets.
  3092. cmTargetCollectLinkLanguages cll(this, config, languages, this);
  3093. for(std::vector<cmLinkImplItem>::const_iterator
  3094. li = impl->Libraries.begin();
  3095. li != impl->Libraries.end(); ++li)
  3096. {
  3097. cll.Visit(*li);
  3098. }
  3099. // Store the transitive closure of languages.
  3100. for(UNORDERED_SET<std::string>::const_iterator li = languages.begin();
  3101. li != languages.end(); ++li)
  3102. {
  3103. lc.Languages.push_back(*li);
  3104. }
  3105. // Choose the language whose linker should be used.
  3106. if(this->GetProperty("HAS_CXX"))
  3107. {
  3108. lc.LinkerLanguage = "CXX";
  3109. }
  3110. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  3111. {
  3112. lc.LinkerLanguage = linkerLang;
  3113. }
  3114. else
  3115. {
  3116. // Find the language with the highest preference value.
  3117. cmTargetSelectLinker tsl(this);
  3118. // First select from the languages compiled directly in this target.
  3119. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3120. li != impl->Languages.end(); ++li)
  3121. {
  3122. tsl.Consider(*li);
  3123. }
  3124. // Now consider languages that propagate from linked targets.
  3125. for(UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
  3126. sit != languages.end(); ++sit)
  3127. {
  3128. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  3129. if(this->Makefile->IsOn(propagates))
  3130. {
  3131. tsl.Consider(*sit);
  3132. }
  3133. }
  3134. lc.LinkerLanguage = tsl.Choose();
  3135. }
  3136. }
  3137. //----------------------------------------------------------------------------
  3138. void cmTarget::ExpandLinkItems(std::string const& prop,
  3139. std::string const& value,
  3140. std::string const& config,
  3141. cmTarget const* headTarget,
  3142. bool usage_requirements_only,
  3143. std::vector<cmLinkItem>& items,
  3144. bool& hadHeadSensitiveCondition) const
  3145. {
  3146. cmGeneratorExpression ge;
  3147. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0);
  3148. // The $<LINK_ONLY> expression may be in a link interface to specify private
  3149. // link dependencies that are otherwise excluded from usage requirements.
  3150. if(usage_requirements_only)
  3151. {
  3152. dagChecker.SetTransitivePropertiesOnly();
  3153. }
  3154. std::vector<std::string> libs;
  3155. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  3156. cmSystemTools::ExpandListArgument(cge->Evaluate(
  3157. this->Makefile,
  3158. config,
  3159. false,
  3160. headTarget,
  3161. this, &dagChecker), libs);
  3162. this->LookupLinkItems(libs, items);
  3163. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  3164. }
  3165. //----------------------------------------------------------------------------
  3166. void cmTarget::LookupLinkItems(std::vector<std::string> const& names,
  3167. std::vector<cmLinkItem>& items) const
  3168. {
  3169. for(std::vector<std::string>::const_iterator i = names.begin();
  3170. i != names.end(); ++i)
  3171. {
  3172. std::string name = this->CheckCMP0004(*i);
  3173. if(name == this->GetName() || name.empty())
  3174. {
  3175. continue;
  3176. }
  3177. items.push_back(cmLinkItem(name, this->FindTargetToLink(name)));
  3178. }
  3179. }
  3180. //----------------------------------------------------------------------------
  3181. const char* cmTarget::GetSuffixVariableInternal(bool implib) const
  3182. {
  3183. switch(this->GetType())
  3184. {
  3185. case cmTarget::STATIC_LIBRARY:
  3186. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  3187. case cmTarget::SHARED_LIBRARY:
  3188. return (implib
  3189. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3190. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  3191. case cmTarget::MODULE_LIBRARY:
  3192. return (implib
  3193. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3194. : "CMAKE_SHARED_MODULE_SUFFIX");
  3195. case cmTarget::EXECUTABLE:
  3196. return (implib
  3197. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3198. // Android GUI application packages store the native
  3199. // binary as a shared library.
  3200. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  3201. "CMAKE_SHARED_LIBRARY_SUFFIX" : "CMAKE_EXECUTABLE_SUFFIX"));
  3202. default:
  3203. break;
  3204. }
  3205. return "";
  3206. }
  3207. //----------------------------------------------------------------------------
  3208. const char* cmTarget::GetPrefixVariableInternal(bool implib) const
  3209. {
  3210. switch(this->GetType())
  3211. {
  3212. case cmTarget::STATIC_LIBRARY:
  3213. return "CMAKE_STATIC_LIBRARY_PREFIX";
  3214. case cmTarget::SHARED_LIBRARY:
  3215. return (implib
  3216. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3217. : "CMAKE_SHARED_LIBRARY_PREFIX");
  3218. case cmTarget::MODULE_LIBRARY:
  3219. return (implib
  3220. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3221. : "CMAKE_SHARED_MODULE_PREFIX");
  3222. case cmTarget::EXECUTABLE:
  3223. return (implib
  3224. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3225. // Android GUI application packages store the native
  3226. // binary as a shared library.
  3227. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  3228. "CMAKE_SHARED_LIBRARY_PREFIX" : ""));
  3229. default:
  3230. break;
  3231. }
  3232. return "";
  3233. }
  3234. //----------------------------------------------------------------------------
  3235. std::string cmTarget::GetPDBName(const std::string& config) const
  3236. {
  3237. std::string prefix;
  3238. std::string base;
  3239. std::string suffix;
  3240. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3241. std::vector<std::string> props;
  3242. std::string configUpper = cmSystemTools::UpperCase(config);
  3243. if(!configUpper.empty())
  3244. {
  3245. // PDB_NAME_<CONFIG>
  3246. props.push_back("PDB_NAME_" + configUpper);
  3247. }
  3248. // PDB_NAME
  3249. props.push_back("PDB_NAME");
  3250. for(std::vector<std::string>::const_iterator i = props.begin();
  3251. i != props.end(); ++i)
  3252. {
  3253. if(const char* outName = this->GetProperty(*i))
  3254. {
  3255. base = outName;
  3256. break;
  3257. }
  3258. }
  3259. return prefix+base+".pdb";
  3260. }
  3261. //----------------------------------------------------------------------------
  3262. std::string cmTarget::GetCompilePDBName(const std::string& config) const
  3263. {
  3264. std::string prefix;
  3265. std::string base;
  3266. std::string suffix;
  3267. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3268. // Check for a per-configuration output directory target property.
  3269. std::string configUpper = cmSystemTools::UpperCase(config);
  3270. std::string configProp = "COMPILE_PDB_NAME_";
  3271. configProp += configUpper;
  3272. const char* config_name = this->GetProperty(configProp);
  3273. if(config_name && *config_name)
  3274. {
  3275. return prefix + config_name + ".pdb";
  3276. }
  3277. const char* name = this->GetProperty("COMPILE_PDB_NAME");
  3278. if(name && *name)
  3279. {
  3280. return prefix + name + ".pdb";
  3281. }
  3282. return "";
  3283. }
  3284. //----------------------------------------------------------------------------
  3285. std::string cmTarget::GetCompilePDBPath(const std::string& config) const
  3286. {
  3287. std::string dir = this->GetCompilePDBDirectory(config);
  3288. std::string name = this->GetCompilePDBName(config);
  3289. if(dir.empty() && !name.empty())
  3290. {
  3291. dir = this->GetPDBDirectory(config);
  3292. }
  3293. if(!dir.empty())
  3294. {
  3295. dir += "/";
  3296. }
  3297. return dir + name;
  3298. }
  3299. //----------------------------------------------------------------------------
  3300. bool cmTarget::HasSOName(const std::string& config) const
  3301. {
  3302. // soname is supported only for shared libraries and modules,
  3303. // and then only when the platform supports an soname flag.
  3304. return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
  3305. this->GetType() == cmTarget::MODULE_LIBRARY) &&
  3306. !this->GetPropertyAsBool("NO_SONAME") &&
  3307. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  3308. }
  3309. //----------------------------------------------------------------------------
  3310. std::string cmTarget::GetSOName(const std::string& config) const
  3311. {
  3312. if(this->IsImported())
  3313. {
  3314. // Lookup the imported soname.
  3315. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3316. {
  3317. if(info->NoSOName)
  3318. {
  3319. // The imported library has no builtin soname so the name
  3320. // searched at runtime will be just the filename.
  3321. return cmSystemTools::GetFilenameName(info->Location);
  3322. }
  3323. else
  3324. {
  3325. // Use the soname given if any.
  3326. if(info->SOName.find("@rpath/") == 0)
  3327. {
  3328. return info->SOName.substr(6);
  3329. }
  3330. return info->SOName;
  3331. }
  3332. }
  3333. else
  3334. {
  3335. return "";
  3336. }
  3337. }
  3338. else
  3339. {
  3340. // Compute the soname that will be built.
  3341. std::string name;
  3342. std::string soName;
  3343. std::string realName;
  3344. std::string impName;
  3345. std::string pdbName;
  3346. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3347. return soName;
  3348. }
  3349. }
  3350. //----------------------------------------------------------------------------
  3351. bool cmTarget::HasMacOSXRpathInstallNameDir(const std::string& config) const
  3352. {
  3353. bool install_name_is_rpath = false;
  3354. bool macosx_rpath = false;
  3355. if(!this->IsImportedTarget)
  3356. {
  3357. if(this->GetType() != cmTarget::SHARED_LIBRARY)
  3358. {
  3359. return false;
  3360. }
  3361. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  3362. bool use_install_name =
  3363. this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  3364. if(install_name && use_install_name &&
  3365. std::string(install_name) == "@rpath")
  3366. {
  3367. install_name_is_rpath = true;
  3368. }
  3369. else if(install_name && use_install_name)
  3370. {
  3371. return false;
  3372. }
  3373. if(!install_name_is_rpath)
  3374. {
  3375. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  3376. }
  3377. }
  3378. else
  3379. {
  3380. // Lookup the imported soname.
  3381. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3382. {
  3383. if(!info->NoSOName && !info->SOName.empty())
  3384. {
  3385. if(info->SOName.find("@rpath/") == 0)
  3386. {
  3387. install_name_is_rpath = true;
  3388. }
  3389. }
  3390. else
  3391. {
  3392. std::string install_name;
  3393. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  3394. if(install_name.find("@rpath") != std::string::npos)
  3395. {
  3396. install_name_is_rpath = true;
  3397. }
  3398. }
  3399. }
  3400. }
  3401. if(!install_name_is_rpath && !macosx_rpath)
  3402. {
  3403. return false;
  3404. }
  3405. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  3406. {
  3407. std::ostringstream w;
  3408. w << "Attempting to use";
  3409. if(macosx_rpath)
  3410. {
  3411. w << " MACOSX_RPATH";
  3412. }
  3413. else
  3414. {
  3415. w << " @rpath";
  3416. }
  3417. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  3418. w << " This could be because you are using a Mac OS X version";
  3419. w << " less than 10.5 or because CMake's platform configuration is";
  3420. w << " corrupt.";
  3421. cmake* cm = this->Makefile->GetCMakeInstance();
  3422. cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
  3423. }
  3424. return true;
  3425. }
  3426. //----------------------------------------------------------------------------
  3427. bool cmTarget::MacOSXRpathInstallNameDirDefault() const
  3428. {
  3429. // we can't do rpaths when unsupported
  3430. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  3431. {
  3432. return false;
  3433. }
  3434. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  3435. if(macosx_rpath_str)
  3436. {
  3437. return this->GetPropertyAsBool("MACOSX_RPATH");
  3438. }
  3439. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  3440. if(cmp0042 == cmPolicies::WARN)
  3441. {
  3442. this->Makefile->GetGlobalGenerator()->
  3443. AddCMP0042WarnTarget(this->GetName());
  3444. }
  3445. if(cmp0042 == cmPolicies::NEW)
  3446. {
  3447. return true;
  3448. }
  3449. return false;
  3450. }
  3451. //----------------------------------------------------------------------------
  3452. bool cmTarget::IsImportedSharedLibWithoutSOName(
  3453. const std::string& config) const
  3454. {
  3455. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  3456. {
  3457. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3458. {
  3459. return info->NoSOName;
  3460. }
  3461. }
  3462. return false;
  3463. }
  3464. //----------------------------------------------------------------------------
  3465. std::string cmTarget::NormalGetRealName(const std::string& config) const
  3466. {
  3467. // This should not be called for imported targets.
  3468. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3469. // enforcement of the limited imported target API.
  3470. if(this->IsImported())
  3471. {
  3472. std::string msg = "NormalGetRealName called on imported target: ";
  3473. msg += this->GetName();
  3474. this->GetMakefile()->
  3475. IssueMessage(cmake::INTERNAL_ERROR,
  3476. msg);
  3477. }
  3478. if(this->GetType() == cmTarget::EXECUTABLE)
  3479. {
  3480. // Compute the real name that will be built.
  3481. std::string name;
  3482. std::string realName;
  3483. std::string impName;
  3484. std::string pdbName;
  3485. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3486. return realName;
  3487. }
  3488. else
  3489. {
  3490. // Compute the real name that will be built.
  3491. std::string name;
  3492. std::string soName;
  3493. std::string realName;
  3494. std::string impName;
  3495. std::string pdbName;
  3496. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3497. return realName;
  3498. }
  3499. }
  3500. //----------------------------------------------------------------------------
  3501. std::string cmTarget::GetFullName(const std::string& config,
  3502. bool implib) const
  3503. {
  3504. if(this->IsImported())
  3505. {
  3506. return this->GetFullNameImported(config, implib);
  3507. }
  3508. else
  3509. {
  3510. return this->GetFullNameInternal(config, implib);
  3511. }
  3512. }
  3513. //----------------------------------------------------------------------------
  3514. std::string
  3515. cmTarget::GetFullNameImported(const std::string& config, bool implib) const
  3516. {
  3517. return cmSystemTools::GetFilenameName(
  3518. this->ImportedGetFullPath(config, implib));
  3519. }
  3520. //----------------------------------------------------------------------------
  3521. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  3522. std::string& suffix,
  3523. const std::string& config,
  3524. bool implib) const
  3525. {
  3526. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3527. }
  3528. //----------------------------------------------------------------------------
  3529. std::string cmTarget::GetFullPath(const std::string& config, bool implib,
  3530. bool realname) const
  3531. {
  3532. if(this->IsImported())
  3533. {
  3534. return this->ImportedGetFullPath(config, implib);
  3535. }
  3536. else
  3537. {
  3538. return this->NormalGetFullPath(config, implib, realname);
  3539. }
  3540. }
  3541. //----------------------------------------------------------------------------
  3542. std::string cmTarget::NormalGetFullPath(const std::string& config,
  3543. bool implib, bool realname) const
  3544. {
  3545. std::string fpath = this->GetDirectory(config, implib);
  3546. fpath += "/";
  3547. if(this->IsAppBundleOnApple())
  3548. {
  3549. fpath = this->BuildMacContentDirectory(fpath, config, false);
  3550. fpath += "/";
  3551. }
  3552. // Add the full name of the target.
  3553. if(implib)
  3554. {
  3555. fpath += this->GetFullName(config, true);
  3556. }
  3557. else if(realname)
  3558. {
  3559. fpath += this->NormalGetRealName(config);
  3560. }
  3561. else
  3562. {
  3563. fpath += this->GetFullName(config, false);
  3564. }
  3565. return fpath;
  3566. }
  3567. //----------------------------------------------------------------------------
  3568. std::string
  3569. cmTarget::ImportedGetFullPath(const std::string& config, bool implib) const
  3570. {
  3571. std::string result;
  3572. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3573. {
  3574. result = implib? info->ImportLibrary : info->Location;
  3575. }
  3576. if(result.empty())
  3577. {
  3578. result = this->GetName();
  3579. result += "-NOTFOUND";
  3580. }
  3581. return result;
  3582. }
  3583. //----------------------------------------------------------------------------
  3584. std::string
  3585. cmTarget::GetFullNameInternal(const std::string& config, bool implib) const
  3586. {
  3587. std::string prefix;
  3588. std::string base;
  3589. std::string suffix;
  3590. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3591. return prefix+base+suffix;
  3592. }
  3593. //----------------------------------------------------------------------------
  3594. void cmTarget::GetFullNameInternal(const std::string& config,
  3595. bool implib,
  3596. std::string& outPrefix,
  3597. std::string& outBase,
  3598. std::string& outSuffix) const
  3599. {
  3600. // Use just the target name for non-main target types.
  3601. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  3602. this->GetType() != cmTarget::SHARED_LIBRARY &&
  3603. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3604. this->GetType() != cmTarget::EXECUTABLE)
  3605. {
  3606. outPrefix = "";
  3607. outBase = this->GetName();
  3608. outSuffix = "";
  3609. return;
  3610. }
  3611. // Return an empty name for the import library if this platform
  3612. // does not support import libraries.
  3613. if(implib &&
  3614. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  3615. {
  3616. outPrefix = "";
  3617. outBase = "";
  3618. outSuffix = "";
  3619. return;
  3620. }
  3621. // The implib option is only allowed for shared libraries, module
  3622. // libraries, and executables.
  3623. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  3624. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3625. this->GetType() != cmTarget::EXECUTABLE)
  3626. {
  3627. implib = false;
  3628. }
  3629. // Compute the full name for main target types.
  3630. const char* targetPrefix = (implib
  3631. ? this->GetProperty("IMPORT_PREFIX")
  3632. : this->GetProperty("PREFIX"));
  3633. const char* targetSuffix = (implib
  3634. ? this->GetProperty("IMPORT_SUFFIX")
  3635. : this->GetProperty("SUFFIX"));
  3636. const char* configPostfix = 0;
  3637. if(!config.empty())
  3638. {
  3639. std::string configProp = cmSystemTools::UpperCase(config);
  3640. configProp += "_POSTFIX";
  3641. configPostfix = this->GetProperty(configProp);
  3642. // Mac application bundles and frameworks have no postfix.
  3643. if(configPostfix &&
  3644. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  3645. {
  3646. configPostfix = 0;
  3647. }
  3648. }
  3649. const char* prefixVar = this->GetPrefixVariableInternal(implib);
  3650. const char* suffixVar = this->GetSuffixVariableInternal(implib);
  3651. // Check for language-specific default prefix and suffix.
  3652. std::string ll = this->GetLinkerLanguage(config);
  3653. if(!ll.empty())
  3654. {
  3655. if(!targetSuffix && suffixVar && *suffixVar)
  3656. {
  3657. std::string langSuff = suffixVar + std::string("_") + ll;
  3658. targetSuffix = this->Makefile->GetDefinition(langSuff);
  3659. }
  3660. if(!targetPrefix && prefixVar && *prefixVar)
  3661. {
  3662. std::string langPrefix = prefixVar + std::string("_") + ll;
  3663. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  3664. }
  3665. }
  3666. // if there is no prefix on the target use the cmake definition
  3667. if(!targetPrefix && prefixVar)
  3668. {
  3669. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  3670. }
  3671. // if there is no suffix on the target use the cmake definition
  3672. if(!targetSuffix && suffixVar)
  3673. {
  3674. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  3675. }
  3676. // frameworks have directory prefix but no suffix
  3677. std::string fw_prefix;
  3678. if(this->IsFrameworkOnApple())
  3679. {
  3680. fw_prefix = this->GetOutputName(config, false);
  3681. fw_prefix += ".framework/";
  3682. targetPrefix = fw_prefix.c_str();
  3683. targetSuffix = 0;
  3684. }
  3685. if(this->IsCFBundleOnApple())
  3686. {
  3687. fw_prefix = this->GetCFBundleDirectory(config, false);
  3688. fw_prefix += "/";
  3689. targetPrefix = fw_prefix.c_str();
  3690. targetSuffix = 0;
  3691. }
  3692. // Begin the final name with the prefix.
  3693. outPrefix = targetPrefix?targetPrefix:"";
  3694. // Append the target name or property-specified name.
  3695. outBase += this->GetOutputName(config, implib);
  3696. // Append the per-configuration postfix.
  3697. outBase += configPostfix?configPostfix:"";
  3698. // Name shared libraries with their version number on some platforms.
  3699. if(const char* soversion = this->GetProperty("SOVERSION"))
  3700. {
  3701. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  3702. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  3703. {
  3704. outBase += "-";
  3705. outBase += soversion;
  3706. }
  3707. }
  3708. // Append the suffix.
  3709. outSuffix = targetSuffix?targetSuffix:"";
  3710. }
  3711. //----------------------------------------------------------------------------
  3712. void cmTarget::GetLibraryNames(std::string& name,
  3713. std::string& soName,
  3714. std::string& realName,
  3715. std::string& impName,
  3716. std::string& pdbName,
  3717. const std::string& config) const
  3718. {
  3719. // This should not be called for imported targets.
  3720. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3721. // enforcement of the limited imported target API.
  3722. if(this->IsImported())
  3723. {
  3724. std::string msg = "GetLibraryNames called on imported target: ";
  3725. msg += this->GetName();
  3726. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  3727. msg);
  3728. return;
  3729. }
  3730. assert(this->GetType() != INTERFACE_LIBRARY);
  3731. // Check for library version properties.
  3732. const char* version = this->GetProperty("VERSION");
  3733. const char* soversion = this->GetProperty("SOVERSION");
  3734. if(!this->HasSOName(config) ||
  3735. this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
  3736. this->IsFrameworkOnApple())
  3737. {
  3738. // Versioning is supported only for shared libraries and modules,
  3739. // and then only when the platform supports an soname flag.
  3740. version = 0;
  3741. soversion = 0;
  3742. }
  3743. if(version && !soversion)
  3744. {
  3745. // The soversion must be set if the library version is set. Use
  3746. // the library version as the soversion.
  3747. soversion = version;
  3748. }
  3749. if(!version && soversion)
  3750. {
  3751. // Use the soversion as the library version.
  3752. version = soversion;
  3753. }
  3754. // Get the components of the library name.
  3755. std::string prefix;
  3756. std::string base;
  3757. std::string suffix;
  3758. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3759. // The library name.
  3760. name = prefix+base+suffix;
  3761. if(this->IsFrameworkOnApple())
  3762. {
  3763. realName = prefix;
  3764. realName += "Versions/";
  3765. realName += this->GetFrameworkVersion();
  3766. realName += "/";
  3767. realName += base;
  3768. soName = realName;
  3769. }
  3770. else
  3771. {
  3772. // The library's soname.
  3773. this->ComputeVersionedName(soName, prefix, base, suffix,
  3774. name, soversion);
  3775. // The library's real name on disk.
  3776. this->ComputeVersionedName(realName, prefix, base, suffix,
  3777. name, version);
  3778. }
  3779. // The import library name.
  3780. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3781. this->GetType() == cmTarget::MODULE_LIBRARY)
  3782. {
  3783. impName = this->GetFullNameInternal(config, true);
  3784. }
  3785. else
  3786. {
  3787. impName = "";
  3788. }
  3789. // The program database file name.
  3790. pdbName = this->GetPDBName(config);
  3791. }
  3792. //----------------------------------------------------------------------------
  3793. void cmTarget::ComputeVersionedName(std::string& vName,
  3794. std::string const& prefix,
  3795. std::string const& base,
  3796. std::string const& suffix,
  3797. std::string const& name,
  3798. const char* version) const
  3799. {
  3800. vName = this->IsApple? (prefix+base) : name;
  3801. if(version)
  3802. {
  3803. vName += ".";
  3804. vName += version;
  3805. }
  3806. vName += this->IsApple? suffix : std::string();
  3807. }
  3808. //----------------------------------------------------------------------------
  3809. void cmTarget::GetExecutableNames(std::string& name,
  3810. std::string& realName,
  3811. std::string& impName,
  3812. std::string& pdbName,
  3813. const std::string& config) const
  3814. {
  3815. // This should not be called for imported targets.
  3816. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3817. // enforcement of the limited imported target API.
  3818. if(this->IsImported())
  3819. {
  3820. std::string msg =
  3821. "GetExecutableNames called on imported target: ";
  3822. msg += this->GetName();
  3823. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  3824. }
  3825. // This versioning is supported only for executables and then only
  3826. // when the platform supports symbolic links.
  3827. #if defined(_WIN32) && !defined(__CYGWIN__)
  3828. const char* version = 0;
  3829. #else
  3830. // Check for executable version properties.
  3831. const char* version = this->GetProperty("VERSION");
  3832. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  3833. {
  3834. version = 0;
  3835. }
  3836. #endif
  3837. // Get the components of the executable name.
  3838. std::string prefix;
  3839. std::string base;
  3840. std::string suffix;
  3841. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3842. // The executable name.
  3843. name = prefix+base+suffix;
  3844. // The executable's real name on disk.
  3845. #if defined(__CYGWIN__)
  3846. realName = prefix+base;
  3847. #else
  3848. realName = name;
  3849. #endif
  3850. if(version)
  3851. {
  3852. realName += "-";
  3853. realName += version;
  3854. }
  3855. #if defined(__CYGWIN__)
  3856. realName += suffix;
  3857. #endif
  3858. // The import library name.
  3859. impName = this->GetFullNameInternal(config, true);
  3860. // The program database file name.
  3861. pdbName = this->GetPDBName(config);
  3862. }
  3863. //----------------------------------------------------------------------------
  3864. bool cmTarget::HasImplibGNUtoMS() const
  3865. {
  3866. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  3867. }
  3868. //----------------------------------------------------------------------------
  3869. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  3870. std::string& out, const char* newExt) const
  3871. {
  3872. if(this->HasImplibGNUtoMS() &&
  3873. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  3874. {
  3875. out = gnuName.substr(0, gnuName.size()-6);
  3876. out += newExt? newExt : ".lib";
  3877. return true;
  3878. }
  3879. return false;
  3880. }
  3881. //----------------------------------------------------------------------------
  3882. void cmTarget::SetPropertyDefault(const std::string& property,
  3883. const char* default_value)
  3884. {
  3885. // Compute the name of the variable holding the default value.
  3886. std::string var = "CMAKE_";
  3887. var += property;
  3888. if(const char* value = this->Makefile->GetDefinition(var))
  3889. {
  3890. this->SetProperty(property, value);
  3891. }
  3892. else if(default_value)
  3893. {
  3894. this->SetProperty(property, default_value);
  3895. }
  3896. }
  3897. //----------------------------------------------------------------------------
  3898. bool cmTarget::HaveBuildTreeRPATH(const std::string& config) const
  3899. {
  3900. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3901. {
  3902. return false;
  3903. }
  3904. if(LinkImplementationLibraries const* impl =
  3905. this->GetLinkImplementationLibraries(config))
  3906. {
  3907. return !impl->Libraries.empty();
  3908. }
  3909. return false;
  3910. }
  3911. //----------------------------------------------------------------------------
  3912. bool cmTarget::HaveInstallTreeRPATH() const
  3913. {
  3914. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3915. return (install_rpath && *install_rpath) &&
  3916. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  3917. }
  3918. //----------------------------------------------------------------------------
  3919. bool cmTarget::NeedRelinkBeforeInstall(const std::string& config) const
  3920. {
  3921. // Only executables and shared libraries can have an rpath and may
  3922. // need relinking.
  3923. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  3924. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  3925. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  3926. {
  3927. return false;
  3928. }
  3929. // If there is no install location this target will not be installed
  3930. // and therefore does not need relinking.
  3931. if(!this->GetHaveInstallRule())
  3932. {
  3933. return false;
  3934. }
  3935. // If skipping all rpaths completely then no relinking is needed.
  3936. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3937. {
  3938. return false;
  3939. }
  3940. // If building with the install-tree rpath no relinking is needed.
  3941. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3942. {
  3943. return false;
  3944. }
  3945. // If chrpath is going to be used no relinking is needed.
  3946. if(this->IsChrpathUsed(config))
  3947. {
  3948. return false;
  3949. }
  3950. // Check for rpath support on this platform.
  3951. std::string ll = this->GetLinkerLanguage(config);
  3952. if(!ll.empty())
  3953. {
  3954. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3955. flagVar += ll;
  3956. flagVar += "_FLAG";
  3957. if(!this->Makefile->IsSet(flagVar))
  3958. {
  3959. // There is no rpath support on this platform so nothing needs
  3960. // relinking.
  3961. return false;
  3962. }
  3963. }
  3964. else
  3965. {
  3966. // No linker language is known. This error will be reported by
  3967. // other code.
  3968. return false;
  3969. }
  3970. // If either a build or install tree rpath is set then the rpath
  3971. // will likely change between the build tree and install tree and
  3972. // this target must be relinked.
  3973. return this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
  3974. }
  3975. //----------------------------------------------------------------------------
  3976. std::string cmTarget::GetInstallNameDirForBuildTree(
  3977. const std::string& config) const
  3978. {
  3979. // If building directly for installation then the build tree install_name
  3980. // is the same as the install tree.
  3981. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3982. {
  3983. return GetInstallNameDirForInstallTree();
  3984. }
  3985. // Use the build tree directory for the target.
  3986. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  3987. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3988. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3989. {
  3990. std::string dir;
  3991. bool macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  3992. if(macosx_rpath)
  3993. {
  3994. dir = "@rpath";
  3995. }
  3996. else
  3997. {
  3998. dir = this->GetDirectory(config);
  3999. }
  4000. dir += "/";
  4001. return dir;
  4002. }
  4003. else
  4004. {
  4005. return "";
  4006. }
  4007. }
  4008. //----------------------------------------------------------------------------
  4009. std::string cmTarget::GetInstallNameDirForInstallTree() const
  4010. {
  4011. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  4012. {
  4013. std::string dir;
  4014. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  4015. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  4016. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  4017. {
  4018. if(install_name_dir && *install_name_dir)
  4019. {
  4020. dir = install_name_dir;
  4021. dir += "/";
  4022. }
  4023. }
  4024. if(!install_name_dir)
  4025. {
  4026. if(this->MacOSXRpathInstallNameDirDefault())
  4027. {
  4028. dir = "@rpath/";
  4029. }
  4030. }
  4031. return dir;
  4032. }
  4033. else
  4034. {
  4035. return "";
  4036. }
  4037. }
  4038. //----------------------------------------------------------------------------
  4039. const char* cmTarget::GetOutputTargetType(bool implib) const
  4040. {
  4041. switch(this->GetType())
  4042. {
  4043. case cmTarget::SHARED_LIBRARY:
  4044. if(this->DLLPlatform)
  4045. {
  4046. if(implib)
  4047. {
  4048. // A DLL import library is treated as an archive target.
  4049. return "ARCHIVE";
  4050. }
  4051. else
  4052. {
  4053. // A DLL shared library is treated as a runtime target.
  4054. return "RUNTIME";
  4055. }
  4056. }
  4057. else
  4058. {
  4059. // For non-DLL platforms shared libraries are treated as
  4060. // library targets.
  4061. return "LIBRARY";
  4062. }
  4063. case cmTarget::STATIC_LIBRARY:
  4064. // Static libraries are always treated as archive targets.
  4065. return "ARCHIVE";
  4066. case cmTarget::MODULE_LIBRARY:
  4067. if(implib)
  4068. {
  4069. // Module libraries are always treated as library targets.
  4070. return "ARCHIVE";
  4071. }
  4072. else
  4073. {
  4074. // Module import libraries are treated as archive targets.
  4075. return "LIBRARY";
  4076. }
  4077. case cmTarget::EXECUTABLE:
  4078. if(implib)
  4079. {
  4080. // Executable import libraries are treated as archive targets.
  4081. return "ARCHIVE";
  4082. }
  4083. else
  4084. {
  4085. // Executables are always treated as runtime targets.
  4086. return "RUNTIME";
  4087. }
  4088. default:
  4089. break;
  4090. }
  4091. return "";
  4092. }
  4093. //----------------------------------------------------------------------------
  4094. bool cmTarget::ComputeOutputDir(const std::string& config,
  4095. bool implib, std::string& out) const
  4096. {
  4097. bool usesDefaultOutputDir = false;
  4098. std::string conf = config;
  4099. // Look for a target property defining the target output directory
  4100. // based on the target type.
  4101. std::string targetTypeName = this->GetOutputTargetType(implib);
  4102. const char* propertyName = 0;
  4103. std::string propertyNameStr = targetTypeName;
  4104. if(!propertyNameStr.empty())
  4105. {
  4106. propertyNameStr += "_OUTPUT_DIRECTORY";
  4107. propertyName = propertyNameStr.c_str();
  4108. }
  4109. // Check for a per-configuration output directory target property.
  4110. std::string configUpper = cmSystemTools::UpperCase(conf);
  4111. const char* configProp = 0;
  4112. std::string configPropStr = targetTypeName;
  4113. if(!configPropStr.empty())
  4114. {
  4115. configPropStr += "_OUTPUT_DIRECTORY_";
  4116. configPropStr += configUpper;
  4117. configProp = configPropStr.c_str();
  4118. }
  4119. // Select an output directory.
  4120. if(const char* config_outdir = this->GetProperty(configProp))
  4121. {
  4122. // Use the user-specified per-configuration output directory.
  4123. out = config_outdir;
  4124. // Skip per-configuration subdirectory.
  4125. conf = "";
  4126. }
  4127. else if(const char* outdir = this->GetProperty(propertyName))
  4128. {
  4129. // Use the user-specified output directory.
  4130. out = outdir;
  4131. }
  4132. else if(this->GetType() == cmTarget::EXECUTABLE)
  4133. {
  4134. // Lookup the output path for executables.
  4135. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  4136. }
  4137. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  4138. this->GetType() == cmTarget::SHARED_LIBRARY ||
  4139. this->GetType() == cmTarget::MODULE_LIBRARY)
  4140. {
  4141. // Lookup the output path for libraries.
  4142. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  4143. }
  4144. if(out.empty())
  4145. {
  4146. // Default to the current output directory.
  4147. usesDefaultOutputDir = true;
  4148. out = ".";
  4149. }
  4150. // Convert the output path to a full path in case it is
  4151. // specified as a relative path. Treat a relative path as
  4152. // relative to the current output directory for this makefile.
  4153. out = (cmSystemTools::CollapseFullPath
  4154. (out, this->Makefile->GetCurrentBinaryDirectory()));
  4155. // The generator may add the configuration's subdirectory.
  4156. if(!conf.empty())
  4157. {
  4158. const char *platforms = this->Makefile->GetDefinition(
  4159. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  4160. std::string suffix =
  4161. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  4162. this->Makefile->GetGlobalGenerator()->
  4163. AppendDirectoryForConfig("/", conf, suffix, out);
  4164. }
  4165. return usesDefaultOutputDir;
  4166. }
  4167. //----------------------------------------------------------------------------
  4168. bool cmTarget::ComputePDBOutputDir(const std::string& kind,
  4169. const std::string& config,
  4170. std::string& out) const
  4171. {
  4172. // Look for a target property defining the target output directory
  4173. // based on the target type.
  4174. const char* propertyName = 0;
  4175. std::string propertyNameStr = kind;
  4176. if(!propertyNameStr.empty())
  4177. {
  4178. propertyNameStr += "_OUTPUT_DIRECTORY";
  4179. propertyName = propertyNameStr.c_str();
  4180. }
  4181. std::string conf = config;
  4182. // Check for a per-configuration output directory target property.
  4183. std::string configUpper = cmSystemTools::UpperCase(conf);
  4184. const char* configProp = 0;
  4185. std::string configPropStr = kind;
  4186. if(!configPropStr.empty())
  4187. {
  4188. configPropStr += "_OUTPUT_DIRECTORY_";
  4189. configPropStr += configUpper;
  4190. configProp = configPropStr.c_str();
  4191. }
  4192. // Select an output directory.
  4193. if(const char* config_outdir = this->GetProperty(configProp))
  4194. {
  4195. // Use the user-specified per-configuration output directory.
  4196. out = config_outdir;
  4197. // Skip per-configuration subdirectory.
  4198. conf = "";
  4199. }
  4200. else if(const char* outdir = this->GetProperty(propertyName))
  4201. {
  4202. // Use the user-specified output directory.
  4203. out = outdir;
  4204. }
  4205. if(out.empty())
  4206. {
  4207. return false;
  4208. }
  4209. // Convert the output path to a full path in case it is
  4210. // specified as a relative path. Treat a relative path as
  4211. // relative to the current output directory for this makefile.
  4212. out = (cmSystemTools::CollapseFullPath
  4213. (out, this->Makefile->GetCurrentBinaryDirectory()));
  4214. // The generator may add the configuration's subdirectory.
  4215. if(!conf.empty())
  4216. {
  4217. this->Makefile->GetGlobalGenerator()->
  4218. AppendDirectoryForConfig("/", conf, "", out);
  4219. }
  4220. return true;
  4221. }
  4222. //----------------------------------------------------------------------------
  4223. bool cmTarget::UsesDefaultOutputDir(const std::string& config,
  4224. bool implib) const
  4225. {
  4226. std::string dir;
  4227. return this->ComputeOutputDir(config, implib, dir);
  4228. }
  4229. //----------------------------------------------------------------------------
  4230. std::string cmTarget::GetOutputName(const std::string& config,
  4231. bool implib) const
  4232. {
  4233. std::vector<std::string> props;
  4234. std::string type = this->GetOutputTargetType(implib);
  4235. std::string configUpper = cmSystemTools::UpperCase(config);
  4236. if(!type.empty() && !configUpper.empty())
  4237. {
  4238. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  4239. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  4240. }
  4241. if(!type.empty())
  4242. {
  4243. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  4244. props.push_back(type + "_OUTPUT_NAME");
  4245. }
  4246. if(!configUpper.empty())
  4247. {
  4248. // OUTPUT_NAME_<CONFIG>
  4249. props.push_back("OUTPUT_NAME_" + configUpper);
  4250. // <CONFIG>_OUTPUT_NAME
  4251. props.push_back(configUpper + "_OUTPUT_NAME");
  4252. }
  4253. // OUTPUT_NAME
  4254. props.push_back("OUTPUT_NAME");
  4255. std::string outName;
  4256. for(std::vector<std::string>::const_iterator i = props.begin();
  4257. i != props.end(); ++i)
  4258. {
  4259. if (const char* outNameProp = this->GetProperty(*i))
  4260. {
  4261. outName = outNameProp;
  4262. break;
  4263. }
  4264. }
  4265. if (outName.empty())
  4266. {
  4267. outName = this->GetName();
  4268. }
  4269. cmGeneratorExpression ge;
  4270. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  4271. return cge->Evaluate(this->Makefile, config);
  4272. }
  4273. //----------------------------------------------------------------------------
  4274. std::string cmTarget::GetFrameworkVersion() const
  4275. {
  4276. assert(this->GetType() != INTERFACE_LIBRARY);
  4277. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  4278. {
  4279. return fversion;
  4280. }
  4281. else if(const char* tversion = this->GetProperty("VERSION"))
  4282. {
  4283. return tversion;
  4284. }
  4285. else
  4286. {
  4287. return "A";
  4288. }
  4289. }
  4290. //----------------------------------------------------------------------------
  4291. const char* cmTarget::GetExportMacro() const
  4292. {
  4293. // Define the symbol for targets that export symbols.
  4294. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4295. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4296. this->IsExecutableWithExports())
  4297. {
  4298. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  4299. {
  4300. this->ExportMacro = custom_export_name;
  4301. }
  4302. else
  4303. {
  4304. std::string in = this->GetName();
  4305. in += "_EXPORTS";
  4306. this->ExportMacro = cmSystemTools::MakeCindentifier(in);
  4307. }
  4308. return this->ExportMacro.c_str();
  4309. }
  4310. else
  4311. {
  4312. return 0;
  4313. }
  4314. }
  4315. //----------------------------------------------------------------------------
  4316. bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
  4317. {
  4318. return this->LinkImplicitNullProperties.find(p)
  4319. != this->LinkImplicitNullProperties.end();
  4320. }
  4321. //----------------------------------------------------------------------------
  4322. template<typename PropertyType>
  4323. PropertyType getTypedProperty(cmTarget const* tgt, const std::string& prop);
  4324. //----------------------------------------------------------------------------
  4325. template<>
  4326. bool getTypedProperty<bool>(cmTarget const* tgt, const std::string& prop)
  4327. {
  4328. return tgt->GetPropertyAsBool(prop);
  4329. }
  4330. //----------------------------------------------------------------------------
  4331. template<>
  4332. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  4333. const std::string& prop)
  4334. {
  4335. return tgt->GetProperty(prop);
  4336. }
  4337. enum CompatibleType
  4338. {
  4339. BoolType,
  4340. StringType,
  4341. NumberMinType,
  4342. NumberMaxType
  4343. };
  4344. //----------------------------------------------------------------------------
  4345. template<typename PropertyType>
  4346. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  4347. PropertyType rhs,
  4348. CompatibleType t);
  4349. //----------------------------------------------------------------------------
  4350. template<>
  4351. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs, CompatibleType)
  4352. {
  4353. return std::make_pair(lhs == rhs, lhs);
  4354. }
  4355. //----------------------------------------------------------------------------
  4356. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  4357. const char *rhs)
  4358. {
  4359. const bool b = strcmp(lhs, rhs) == 0;
  4360. return std::make_pair(b, b ? lhs : 0);
  4361. }
  4362. //----------------------------------------------------------------------------
  4363. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  4364. const char *rhs,
  4365. CompatibleType t)
  4366. {
  4367. char *pEnd;
  4368. const char* const null_ptr = 0;
  4369. long lnum = strtol(lhs, &pEnd, 0);
  4370. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  4371. {
  4372. return std::pair<bool, const char*>(false, null_ptr);
  4373. }
  4374. long rnum = strtol(rhs, &pEnd, 0);
  4375. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  4376. {
  4377. return std::pair<bool, const char*>(false, null_ptr);
  4378. }
  4379. if (t == NumberMaxType)
  4380. {
  4381. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  4382. }
  4383. else
  4384. {
  4385. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  4386. }
  4387. }
  4388. //----------------------------------------------------------------------------
  4389. template<>
  4390. std::pair<bool, const char*> consistentProperty(const char *lhs,
  4391. const char *rhs,
  4392. CompatibleType t)
  4393. {
  4394. if (!lhs && !rhs)
  4395. {
  4396. return std::make_pair(true, lhs);
  4397. }
  4398. if (!lhs)
  4399. {
  4400. return std::make_pair(true, rhs);
  4401. }
  4402. if (!rhs)
  4403. {
  4404. return std::make_pair(true, lhs);
  4405. }
  4406. const char* const null_ptr = 0;
  4407. switch(t)
  4408. {
  4409. case BoolType:
  4410. assert(0 && "consistentProperty for strings called with BoolType");
  4411. return std::pair<bool, const char*>(false, null_ptr);
  4412. case StringType:
  4413. return consistentStringProperty(lhs, rhs);
  4414. case NumberMinType:
  4415. case NumberMaxType:
  4416. return consistentNumberProperty(lhs, rhs, t);
  4417. }
  4418. assert(0 && "Unreachable!");
  4419. return std::pair<bool, const char*>(false, null_ptr);
  4420. }
  4421. template<typename PropertyType>
  4422. PropertyType impliedValue(PropertyType);
  4423. template<>
  4424. bool impliedValue<bool>(bool)
  4425. {
  4426. return false;
  4427. }
  4428. template<>
  4429. const char* impliedValue<const char*>(const char*)
  4430. {
  4431. return "";
  4432. }
  4433. template<typename PropertyType>
  4434. std::string valueAsString(PropertyType);
  4435. template<>
  4436. std::string valueAsString<bool>(bool value)
  4437. {
  4438. return value ? "TRUE" : "FALSE";
  4439. }
  4440. template<>
  4441. std::string valueAsString<const char*>(const char* value)
  4442. {
  4443. return value ? value : "(unset)";
  4444. }
  4445. //----------------------------------------------------------------------------
  4446. void
  4447. cmTarget::ReportPropertyOrigin(const std::string &p,
  4448. const std::string &result,
  4449. const std::string &report,
  4450. const std::string &compatibilityType) const
  4451. {
  4452. std::vector<std::string> debugProperties;
  4453. const char *debugProp =
  4454. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  4455. if (debugProp)
  4456. {
  4457. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  4458. }
  4459. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  4460. && std::find(debugProperties.begin(),
  4461. debugProperties.end(),
  4462. p)
  4463. != debugProperties.end();
  4464. if (this->Makefile->IsConfigured())
  4465. {
  4466. this->DebugCompatiblePropertiesDone[p] = true;
  4467. }
  4468. if (!debugOrigin)
  4469. {
  4470. return;
  4471. }
  4472. std::string areport = compatibilityType;
  4473. areport += std::string(" of property \"") + p + "\" for target \"";
  4474. areport += std::string(this->GetName());
  4475. areport += "\" (result: \"";
  4476. areport += result;
  4477. areport += "\"):\n" + report;
  4478. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  4479. }
  4480. //----------------------------------------------------------------------------
  4481. std::string compatibilityType(CompatibleType t)
  4482. {
  4483. switch(t)
  4484. {
  4485. case BoolType:
  4486. return "Boolean compatibility";
  4487. case StringType:
  4488. return "String compatibility";
  4489. case NumberMaxType:
  4490. return "Numeric maximum compatibility";
  4491. case NumberMinType:
  4492. return "Numeric minimum compatibility";
  4493. }
  4494. assert(0 && "Unreachable!");
  4495. return "";
  4496. }
  4497. //----------------------------------------------------------------------------
  4498. std::string compatibilityAgree(CompatibleType t, bool dominant)
  4499. {
  4500. switch(t)
  4501. {
  4502. case BoolType:
  4503. case StringType:
  4504. return dominant ? "(Disagree)\n" : "(Agree)\n";
  4505. case NumberMaxType:
  4506. case NumberMinType:
  4507. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  4508. }
  4509. assert(0 && "Unreachable!");
  4510. return "";
  4511. }
  4512. //----------------------------------------------------------------------------
  4513. template<typename PropertyType>
  4514. PropertyType checkInterfacePropertyCompatibility(cmTarget const* tgt,
  4515. const std::string &p,
  4516. const std::string& config,
  4517. const char *defaultValue,
  4518. CompatibleType t,
  4519. PropertyType *)
  4520. {
  4521. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
  4522. const bool explicitlySet = tgt->GetProperties()
  4523. .find(p)
  4524. != tgt->GetProperties().end();
  4525. const bool impliedByUse =
  4526. tgt->IsNullImpliedByLinkLibraries(p);
  4527. assert((impliedByUse ^ explicitlySet)
  4528. || (!impliedByUse && !explicitlySet));
  4529. std::vector<cmTarget const*> const& deps =
  4530. tgt->GetLinkImplementationClosure(config);
  4531. if(deps.empty())
  4532. {
  4533. return propContent;
  4534. }
  4535. bool propInitialized = explicitlySet;
  4536. std::string report = " * Target \"";
  4537. report += tgt->GetName();
  4538. if (explicitlySet)
  4539. {
  4540. report += "\" has property content \"";
  4541. report += valueAsString<PropertyType>(propContent);
  4542. report += "\"\n";
  4543. }
  4544. else if (impliedByUse)
  4545. {
  4546. report += "\" property is implied by use.\n";
  4547. }
  4548. else
  4549. {
  4550. report += "\" property not set.\n";
  4551. }
  4552. std::string interfaceProperty = "INTERFACE_" + p;
  4553. for(std::vector<cmTarget const*>::const_iterator li =
  4554. deps.begin();
  4555. li != deps.end(); ++li)
  4556. {
  4557. // An error should be reported if one dependency
  4558. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  4559. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  4560. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  4561. // with a dependency.
  4562. cmTarget const* theTarget = *li;
  4563. const bool ifaceIsSet = theTarget->GetProperties()
  4564. .find(interfaceProperty)
  4565. != theTarget->GetProperties().end();
  4566. PropertyType ifacePropContent =
  4567. getTypedProperty<PropertyType>(theTarget,
  4568. interfaceProperty);
  4569. std::string reportEntry;
  4570. if (ifaceIsSet)
  4571. {
  4572. reportEntry += " * Target \"";
  4573. reportEntry += theTarget->GetName();
  4574. reportEntry += "\" property value \"";
  4575. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  4576. reportEntry += "\" ";
  4577. }
  4578. if (explicitlySet)
  4579. {
  4580. if (ifaceIsSet)
  4581. {
  4582. std::pair<bool, PropertyType> consistent =
  4583. consistentProperty(propContent,
  4584. ifacePropContent, t);
  4585. report += reportEntry;
  4586. report += compatibilityAgree(t, propContent != consistent.second);
  4587. if (!consistent.first)
  4588. {
  4589. std::ostringstream e;
  4590. e << "Property " << p << " on target \""
  4591. << tgt->GetName() << "\" does\nnot match the "
  4592. "INTERFACE_" << p << " property requirement\nof "
  4593. "dependency \"" << theTarget->GetName() << "\".\n";
  4594. cmSystemTools::Error(e.str().c_str());
  4595. break;
  4596. }
  4597. else
  4598. {
  4599. propContent = consistent.second;
  4600. continue;
  4601. }
  4602. }
  4603. else
  4604. {
  4605. // Explicitly set on target and not set in iface. Can't disagree.
  4606. continue;
  4607. }
  4608. }
  4609. else if (impliedByUse)
  4610. {
  4611. propContent = impliedValue<PropertyType>(propContent);
  4612. if (ifaceIsSet)
  4613. {
  4614. std::pair<bool, PropertyType> consistent =
  4615. consistentProperty(propContent,
  4616. ifacePropContent, t);
  4617. report += reportEntry;
  4618. report += compatibilityAgree(t, propContent != consistent.second);
  4619. if (!consistent.first)
  4620. {
  4621. std::ostringstream e;
  4622. e << "Property " << p << " on target \""
  4623. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  4624. << " because it was used to determine the link libraries\n"
  4625. "already. The INTERFACE_" << p << " property on\ndependency \""
  4626. << theTarget->GetName() << "\" is in conflict.\n";
  4627. cmSystemTools::Error(e.str().c_str());
  4628. break;
  4629. }
  4630. else
  4631. {
  4632. propContent = consistent.second;
  4633. continue;
  4634. }
  4635. }
  4636. else
  4637. {
  4638. // Implicitly set on target and not set in iface. Can't disagree.
  4639. continue;
  4640. }
  4641. }
  4642. else
  4643. {
  4644. if (ifaceIsSet)
  4645. {
  4646. if (propInitialized)
  4647. {
  4648. std::pair<bool, PropertyType> consistent =
  4649. consistentProperty(propContent,
  4650. ifacePropContent, t);
  4651. report += reportEntry;
  4652. report += compatibilityAgree(t, propContent != consistent.second);
  4653. if (!consistent.first)
  4654. {
  4655. std::ostringstream e;
  4656. e << "The INTERFACE_" << p << " property of \""
  4657. << theTarget->GetName() << "\" does\nnot agree with the value "
  4658. "of " << p << " already determined\nfor \""
  4659. << tgt->GetName() << "\".\n";
  4660. cmSystemTools::Error(e.str().c_str());
  4661. break;
  4662. }
  4663. else
  4664. {
  4665. propContent = consistent.second;
  4666. continue;
  4667. }
  4668. }
  4669. else
  4670. {
  4671. report += reportEntry + "(Interface set)\n";
  4672. propContent = ifacePropContent;
  4673. propInitialized = true;
  4674. }
  4675. }
  4676. else
  4677. {
  4678. // Not set. Nothing to agree on.
  4679. continue;
  4680. }
  4681. }
  4682. }
  4683. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  4684. report, compatibilityType(t));
  4685. return propContent;
  4686. }
  4687. //----------------------------------------------------------------------------
  4688. bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
  4689. const std::string& config) const
  4690. {
  4691. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  4692. BoolType, 0);
  4693. }
  4694. //----------------------------------------------------------------------------
  4695. const char * cmTarget::GetLinkInterfaceDependentStringProperty(
  4696. const std::string &p,
  4697. const std::string& config) const
  4698. {
  4699. return checkInterfacePropertyCompatibility<const char *>(this,
  4700. p,
  4701. config,
  4702. "empty",
  4703. StringType, 0);
  4704. }
  4705. //----------------------------------------------------------------------------
  4706. const char * cmTarget::GetLinkInterfaceDependentNumberMinProperty(
  4707. const std::string &p,
  4708. const std::string& config) const
  4709. {
  4710. return checkInterfacePropertyCompatibility<const char *>(this,
  4711. p,
  4712. config,
  4713. "empty",
  4714. NumberMinType, 0);
  4715. }
  4716. //----------------------------------------------------------------------------
  4717. const char * cmTarget::GetLinkInterfaceDependentNumberMaxProperty(
  4718. const std::string &p,
  4719. const std::string& config) const
  4720. {
  4721. return checkInterfacePropertyCompatibility<const char *>(this,
  4722. p,
  4723. config,
  4724. "empty",
  4725. NumberMaxType, 0);
  4726. }
  4727. //----------------------------------------------------------------------------
  4728. bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
  4729. const std::string& config) const
  4730. {
  4731. if (this->TargetTypeValue == OBJECT_LIBRARY
  4732. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4733. {
  4734. return false;
  4735. }
  4736. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  4737. }
  4738. //----------------------------------------------------------------------------
  4739. bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
  4740. const std::string& config) const
  4741. {
  4742. if (this->TargetTypeValue == OBJECT_LIBRARY
  4743. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4744. {
  4745. return false;
  4746. }
  4747. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  4748. }
  4749. //----------------------------------------------------------------------------
  4750. bool cmTarget::IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
  4751. const std::string& config) const
  4752. {
  4753. if (this->TargetTypeValue == OBJECT_LIBRARY
  4754. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4755. {
  4756. return false;
  4757. }
  4758. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  4759. }
  4760. //----------------------------------------------------------------------------
  4761. bool cmTarget::IsLinkInterfaceDependentNumberMaxProperty(const std::string &p,
  4762. const std::string& config) const
  4763. {
  4764. if (this->TargetTypeValue == OBJECT_LIBRARY
  4765. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4766. {
  4767. return false;
  4768. }
  4769. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  4770. }
  4771. //----------------------------------------------------------------------------
  4772. void
  4773. cmTarget::GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const
  4774. {
  4775. // At configure-time, this method can be called as part of getting the
  4776. // LOCATION property or to export() a file to be include()d. However
  4777. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  4778. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  4779. // behavior of CMP0024 and CMP0026 only.
  4780. typedef cmTargetInternals::TargetPropertyEntry
  4781. TargetPropertyEntry;
  4782. for(std::vector<TargetPropertyEntry*>::const_iterator
  4783. i = this->Internal->SourceEntries.begin();
  4784. i != this->Internal->SourceEntries.end(); ++i)
  4785. {
  4786. std::string entry = (*i)->ge->GetInput();
  4787. std::vector<std::string> files;
  4788. cmSystemTools::ExpandListArgument(entry, files);
  4789. for (std::vector<std::string>::const_iterator
  4790. li = files.begin(); li != files.end(); ++li)
  4791. {
  4792. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  4793. (*li)[li->size() - 1] == '>')
  4794. {
  4795. std::string objLibName = li->substr(17, li->size()-18);
  4796. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  4797. {
  4798. continue;
  4799. }
  4800. cmTarget *objLib = this->Makefile->FindTargetToUse(objLibName);
  4801. if(objLib)
  4802. {
  4803. objlibs.push_back(objLib);
  4804. }
  4805. }
  4806. }
  4807. }
  4808. }
  4809. //----------------------------------------------------------------------------
  4810. void cmTarget::GetLanguages(std::set<std::string>& languages,
  4811. const std::string& config) const
  4812. {
  4813. std::vector<cmSourceFile*> sourceFiles;
  4814. this->GetSourceFiles(sourceFiles, config);
  4815. for(std::vector<cmSourceFile*>::const_iterator
  4816. i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
  4817. {
  4818. const std::string& lang = (*i)->GetLanguage();
  4819. if(!lang.empty())
  4820. {
  4821. languages.insert(lang);
  4822. }
  4823. }
  4824. std::vector<cmTarget*> objectLibraries;
  4825. std::vector<cmSourceFile const*> externalObjects;
  4826. if (!this->Makefile->IsConfigured())
  4827. {
  4828. this->GetObjectLibrariesCMP0026(objectLibraries);
  4829. }
  4830. else
  4831. {
  4832. cmGeneratorTarget* gt = this->Makefile->GetGlobalGenerator()
  4833. ->GetGeneratorTarget(this);
  4834. gt->GetExternalObjects(externalObjects, config);
  4835. for(std::vector<cmSourceFile const*>::const_iterator
  4836. i = externalObjects.begin(); i != externalObjects.end(); ++i)
  4837. {
  4838. std::string objLib = (*i)->GetObjectLibrary();
  4839. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  4840. {
  4841. objectLibraries.push_back(tgt);
  4842. }
  4843. }
  4844. }
  4845. for(std::vector<cmTarget*>::const_iterator
  4846. i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
  4847. {
  4848. (*i)->GetLanguages(languages, config);
  4849. }
  4850. }
  4851. //----------------------------------------------------------------------------
  4852. bool cmTarget::IsChrpathUsed(const std::string& config) const
  4853. {
  4854. // Only certain target types have an rpath.
  4855. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4856. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4857. this->GetType() == cmTarget::EXECUTABLE))
  4858. {
  4859. return false;
  4860. }
  4861. // If the target will not be installed we do not need to change its
  4862. // rpath.
  4863. if(!this->GetHaveInstallRule())
  4864. {
  4865. return false;
  4866. }
  4867. // Skip chrpath if skipping rpath altogether.
  4868. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  4869. {
  4870. return false;
  4871. }
  4872. // Skip chrpath if it does not need to be changed at install time.
  4873. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  4874. {
  4875. return false;
  4876. }
  4877. // Allow the user to disable builtin chrpath explicitly.
  4878. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  4879. {
  4880. return false;
  4881. }
  4882. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  4883. {
  4884. return true;
  4885. }
  4886. #if defined(CMAKE_USE_ELF_PARSER)
  4887. // Enable if the rpath flag uses a separator and the target uses ELF
  4888. // binaries.
  4889. std::string ll = this->GetLinkerLanguage(config);
  4890. if(!ll.empty())
  4891. {
  4892. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  4893. sepVar += ll;
  4894. sepVar += "_FLAG_SEP";
  4895. const char* sep = this->Makefile->GetDefinition(sepVar);
  4896. if(sep && *sep)
  4897. {
  4898. // TODO: Add ELF check to ABI detection and get rid of
  4899. // CMAKE_EXECUTABLE_FORMAT.
  4900. if(const char* fmt =
  4901. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  4902. {
  4903. return strcmp(fmt, "ELF") == 0;
  4904. }
  4905. }
  4906. }
  4907. #endif
  4908. static_cast<void>(config);
  4909. return false;
  4910. }
  4911. //----------------------------------------------------------------------------
  4912. cmTarget::ImportInfo const*
  4913. cmTarget::GetImportInfo(const std::string& config) const
  4914. {
  4915. // There is no imported information for non-imported targets.
  4916. if(!this->IsImported())
  4917. {
  4918. return 0;
  4919. }
  4920. // Lookup/compute/cache the import information for this
  4921. // configuration.
  4922. std::string config_upper;
  4923. if(!config.empty())
  4924. {
  4925. config_upper = cmSystemTools::UpperCase(config);
  4926. }
  4927. else
  4928. {
  4929. config_upper = "NOCONFIG";
  4930. }
  4931. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  4932. ImportInfoMapType::const_iterator i =
  4933. this->Internal->ImportInfoMap.find(config_upper);
  4934. if(i == this->Internal->ImportInfoMap.end())
  4935. {
  4936. ImportInfo info;
  4937. this->ComputeImportInfo(config_upper, info);
  4938. ImportInfoMapType::value_type entry(config_upper, info);
  4939. i = this->Internal->ImportInfoMap.insert(entry).first;
  4940. }
  4941. if(this->GetType() == INTERFACE_LIBRARY)
  4942. {
  4943. return &i->second;
  4944. }
  4945. // If the location is empty then the target is not available for
  4946. // this configuration.
  4947. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  4948. {
  4949. return 0;
  4950. }
  4951. // Return the import information.
  4952. return &i->second;
  4953. }
  4954. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  4955. const char** loc,
  4956. const char** imp,
  4957. std::string& suffix) const
  4958. {
  4959. if (this->GetType() == INTERFACE_LIBRARY)
  4960. {
  4961. // This method attempts to find a config-specific LOCATION for the
  4962. // IMPORTED library. In the case of INTERFACE_LIBRARY, there is no
  4963. // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
  4964. // and valid response.
  4965. return true;
  4966. }
  4967. // Track the configuration-specific property suffix.
  4968. suffix = "_";
  4969. suffix += desired_config;
  4970. std::vector<std::string> mappedConfigs;
  4971. {
  4972. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  4973. mapProp += desired_config;
  4974. if(const char* mapValue = this->GetProperty(mapProp))
  4975. {
  4976. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  4977. }
  4978. }
  4979. // If we needed to find one of the mapped configurations but did not
  4980. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  4981. // library or an executable with exports.
  4982. bool allowImp = this->HasImportLibrary();
  4983. // If a mapping was found, check its configurations.
  4984. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  4985. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  4986. {
  4987. // Look for this configuration.
  4988. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  4989. std::string locProp = "IMPORTED_LOCATION_";
  4990. locProp += mcUpper;
  4991. *loc = this->GetProperty(locProp);
  4992. if(allowImp)
  4993. {
  4994. std::string impProp = "IMPORTED_IMPLIB_";
  4995. impProp += mcUpper;
  4996. *imp = this->GetProperty(impProp);
  4997. }
  4998. // If it was found, use it for all properties below.
  4999. if(*loc || *imp)
  5000. {
  5001. suffix = "_";
  5002. suffix += mcUpper;
  5003. }
  5004. }
  5005. // If we needed to find one of the mapped configurations but did not
  5006. // then the target is not found. The project does not want any
  5007. // other configuration.
  5008. if(!mappedConfigs.empty() && !*loc && !*imp)
  5009. {
  5010. return false;
  5011. }
  5012. // If we have not yet found it then there are no mapped
  5013. // configurations. Look for an exact-match.
  5014. if(!*loc && !*imp)
  5015. {
  5016. std::string locProp = "IMPORTED_LOCATION";
  5017. locProp += suffix;
  5018. *loc = this->GetProperty(locProp);
  5019. if(allowImp)
  5020. {
  5021. std::string impProp = "IMPORTED_IMPLIB";
  5022. impProp += suffix;
  5023. *imp = this->GetProperty(impProp);
  5024. }
  5025. }
  5026. // If we have not yet found it then there are no mapped
  5027. // configurations and no exact match.
  5028. if(!*loc && !*imp)
  5029. {
  5030. // The suffix computed above is not useful.
  5031. suffix = "";
  5032. // Look for a configuration-less location. This may be set by
  5033. // manually-written code.
  5034. *loc = this->GetProperty("IMPORTED_LOCATION");
  5035. if(allowImp)
  5036. {
  5037. *imp = this->GetProperty("IMPORTED_IMPLIB");
  5038. }
  5039. }
  5040. // If we have not yet found it then the project is willing to try
  5041. // any available configuration.
  5042. if(!*loc && !*imp)
  5043. {
  5044. std::vector<std::string> availableConfigs;
  5045. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  5046. {
  5047. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  5048. }
  5049. for(std::vector<std::string>::const_iterator
  5050. aci = availableConfigs.begin();
  5051. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  5052. {
  5053. suffix = "_";
  5054. suffix += cmSystemTools::UpperCase(*aci);
  5055. std::string locProp = "IMPORTED_LOCATION";
  5056. locProp += suffix;
  5057. *loc = this->GetProperty(locProp);
  5058. if(allowImp)
  5059. {
  5060. std::string impProp = "IMPORTED_IMPLIB";
  5061. impProp += suffix;
  5062. *imp = this->GetProperty(impProp);
  5063. }
  5064. }
  5065. }
  5066. // If we have not yet found it then the target is not available.
  5067. if(!*loc && !*imp)
  5068. {
  5069. return false;
  5070. }
  5071. return true;
  5072. }
  5073. //----------------------------------------------------------------------------
  5074. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  5075. ImportInfo& info) const
  5076. {
  5077. // This method finds information about an imported target from its
  5078. // properties. The "IMPORTED_" namespace is reserved for properties
  5079. // defined by the project exporting the target.
  5080. // Initialize members.
  5081. info.NoSOName = false;
  5082. const char* loc = 0;
  5083. const char* imp = 0;
  5084. std::string suffix;
  5085. if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
  5086. {
  5087. return;
  5088. }
  5089. // Get the link interface.
  5090. {
  5091. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  5092. const char *propertyLibs = this->GetProperty(linkProp);
  5093. if (this->GetType() != INTERFACE_LIBRARY)
  5094. {
  5095. if(!propertyLibs)
  5096. {
  5097. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  5098. linkProp += suffix;
  5099. propertyLibs = this->GetProperty(linkProp);
  5100. }
  5101. if(!propertyLibs)
  5102. {
  5103. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  5104. propertyLibs = this->GetProperty(linkProp);
  5105. }
  5106. }
  5107. if(propertyLibs)
  5108. {
  5109. info.LibrariesProp = linkProp;
  5110. info.Libraries = propertyLibs;
  5111. }
  5112. }
  5113. if(this->GetType() == INTERFACE_LIBRARY)
  5114. {
  5115. return;
  5116. }
  5117. // A provided configuration has been chosen. Load the
  5118. // configuration's properties.
  5119. // Get the location.
  5120. if(loc)
  5121. {
  5122. info.Location = loc;
  5123. }
  5124. else
  5125. {
  5126. std::string impProp = "IMPORTED_LOCATION";
  5127. impProp += suffix;
  5128. if(const char* config_location = this->GetProperty(impProp))
  5129. {
  5130. info.Location = config_location;
  5131. }
  5132. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  5133. {
  5134. info.Location = location;
  5135. }
  5136. }
  5137. // Get the soname.
  5138. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  5139. {
  5140. std::string soProp = "IMPORTED_SONAME";
  5141. soProp += suffix;
  5142. if(const char* config_soname = this->GetProperty(soProp))
  5143. {
  5144. info.SOName = config_soname;
  5145. }
  5146. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  5147. {
  5148. info.SOName = soname;
  5149. }
  5150. }
  5151. // Get the "no-soname" mark.
  5152. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  5153. {
  5154. std::string soProp = "IMPORTED_NO_SONAME";
  5155. soProp += suffix;
  5156. if(const char* config_no_soname = this->GetProperty(soProp))
  5157. {
  5158. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  5159. }
  5160. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  5161. {
  5162. info.NoSOName = cmSystemTools::IsOn(no_soname);
  5163. }
  5164. }
  5165. // Get the import library.
  5166. if(imp)
  5167. {
  5168. info.ImportLibrary = imp;
  5169. }
  5170. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  5171. this->IsExecutableWithExports())
  5172. {
  5173. std::string impProp = "IMPORTED_IMPLIB";
  5174. impProp += suffix;
  5175. if(const char* config_implib = this->GetProperty(impProp))
  5176. {
  5177. info.ImportLibrary = config_implib;
  5178. }
  5179. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  5180. {
  5181. info.ImportLibrary = implib;
  5182. }
  5183. }
  5184. // Get the link dependencies.
  5185. {
  5186. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  5187. linkProp += suffix;
  5188. if(const char* config_libs = this->GetProperty(linkProp))
  5189. {
  5190. info.SharedDeps = config_libs;
  5191. }
  5192. else if(const char* libs =
  5193. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  5194. {
  5195. info.SharedDeps = libs;
  5196. }
  5197. }
  5198. // Get the link languages.
  5199. if(this->LinkLanguagePropagatesToDependents())
  5200. {
  5201. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  5202. linkProp += suffix;
  5203. if(const char* config_libs = this->GetProperty(linkProp))
  5204. {
  5205. info.Languages = config_libs;
  5206. }
  5207. else if(const char* libs =
  5208. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  5209. {
  5210. info.Languages = libs;
  5211. }
  5212. }
  5213. // Get the cyclic repetition count.
  5214. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  5215. {
  5216. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  5217. linkProp += suffix;
  5218. if(const char* config_reps = this->GetProperty(linkProp))
  5219. {
  5220. sscanf(config_reps, "%u", &info.Multiplicity);
  5221. }
  5222. else if(const char* reps =
  5223. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  5224. {
  5225. sscanf(reps, "%u", &info.Multiplicity);
  5226. }
  5227. }
  5228. }
  5229. //----------------------------------------------------------------------------
  5230. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(
  5231. const std::string& config,
  5232. cmTarget const* head) const
  5233. {
  5234. // Imported targets have their own link interface.
  5235. if(this->IsImported())
  5236. {
  5237. return this->GetImportLinkInterface(config, head, false);
  5238. }
  5239. // Link interfaces are not supported for executables that do not
  5240. // export symbols.
  5241. if(this->GetType() == cmTarget::EXECUTABLE &&
  5242. !this->IsExecutableWithExports())
  5243. {
  5244. return 0;
  5245. }
  5246. // Lookup any existing link interface for this configuration.
  5247. std::string CONFIG = cmSystemTools::UpperCase(config);
  5248. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  5249. this->Internal->LinkInterfaceMap[CONFIG];
  5250. // If the link interface does not depend on the head target
  5251. // then return the one we computed first.
  5252. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  5253. {
  5254. return &hm.begin()->second;
  5255. }
  5256. cmTargetInternals::OptionalLinkInterface& iface = hm[head];
  5257. if(!iface.LibrariesDone)
  5258. {
  5259. iface.LibrariesDone = true;
  5260. this->Internal->ComputeLinkInterfaceLibraries(
  5261. this, config, iface, head, false);
  5262. }
  5263. if(!iface.AllDone)
  5264. {
  5265. iface.AllDone = true;
  5266. if(iface.Exists)
  5267. {
  5268. this->Internal->ComputeLinkInterface(this, config, iface, head);
  5269. }
  5270. }
  5271. return iface.Exists? &iface : 0;
  5272. }
  5273. //----------------------------------------------------------------------------
  5274. cmTarget::LinkInterfaceLibraries const*
  5275. cmTarget::GetLinkInterfaceLibraries(const std::string& config,
  5276. cmTarget const* head,
  5277. bool usage_requirements_only) const
  5278. {
  5279. // Imported targets have their own link interface.
  5280. if(this->IsImported())
  5281. {
  5282. return this->GetImportLinkInterface(config, head, usage_requirements_only);
  5283. }
  5284. // Link interfaces are not supported for executables that do not
  5285. // export symbols.
  5286. if(this->GetType() == cmTarget::EXECUTABLE &&
  5287. !this->IsExecutableWithExports())
  5288. {
  5289. return 0;
  5290. }
  5291. // Lookup any existing link interface for this configuration.
  5292. std::string CONFIG = cmSystemTools::UpperCase(config);
  5293. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  5294. (usage_requirements_only ?
  5295. this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] :
  5296. this->Internal->LinkInterfaceMap[CONFIG]);
  5297. // If the link interface does not depend on the head target
  5298. // then return the one we computed first.
  5299. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  5300. {
  5301. return &hm.begin()->second;
  5302. }
  5303. cmTargetInternals::OptionalLinkInterface& iface = hm[head];
  5304. if(!iface.LibrariesDone)
  5305. {
  5306. iface.LibrariesDone = true;
  5307. this->Internal->ComputeLinkInterfaceLibraries(
  5308. this, config, iface, head, usage_requirements_only);
  5309. }
  5310. return iface.Exists? &iface : 0;
  5311. }
  5312. //----------------------------------------------------------------------------
  5313. cmTarget::LinkInterface const*
  5314. cmTarget::GetImportLinkInterface(const std::string& config,
  5315. cmTarget const* headTarget,
  5316. bool usage_requirements_only) const
  5317. {
  5318. cmTarget::ImportInfo const* info = this->GetImportInfo(config);
  5319. if(!info)
  5320. {
  5321. return 0;
  5322. }
  5323. std::string CONFIG = cmSystemTools::UpperCase(config);
  5324. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  5325. (usage_requirements_only ?
  5326. this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] :
  5327. this->Internal->LinkInterfaceMap[CONFIG]);
  5328. // If the link interface does not depend on the head target
  5329. // then return the one we computed first.
  5330. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  5331. {
  5332. return &hm.begin()->second;
  5333. }
  5334. cmTargetInternals::OptionalLinkInterface& iface = hm[headTarget];
  5335. if(!iface.AllDone)
  5336. {
  5337. iface.AllDone = true;
  5338. iface.Multiplicity = info->Multiplicity;
  5339. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  5340. this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
  5341. headTarget, usage_requirements_only,
  5342. iface.Libraries,
  5343. iface.HadHeadSensitiveCondition);
  5344. std::vector<std::string> deps;
  5345. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  5346. this->LookupLinkItems(deps, iface.SharedDeps);
  5347. }
  5348. return &iface;
  5349. }
  5350. //----------------------------------------------------------------------------
  5351. void processILibs(const std::string& config,
  5352. cmTarget const* headTarget,
  5353. cmLinkItem const& item,
  5354. std::vector<cmTarget const*>& tgts,
  5355. std::set<cmTarget const*>& emitted)
  5356. {
  5357. if (item.Target && emitted.insert(item.Target).second)
  5358. {
  5359. tgts.push_back(item.Target);
  5360. if(cmTarget::LinkInterfaceLibraries const* iface =
  5361. item.Target->GetLinkInterfaceLibraries(config, headTarget, true))
  5362. {
  5363. for(std::vector<cmLinkItem>::const_iterator
  5364. it = iface->Libraries.begin();
  5365. it != iface->Libraries.end(); ++it)
  5366. {
  5367. processILibs(config, headTarget, *it, tgts, emitted);
  5368. }
  5369. }
  5370. }
  5371. }
  5372. //----------------------------------------------------------------------------
  5373. std::vector<cmTarget const*> const&
  5374. cmTarget::GetLinkImplementationClosure(const std::string& config) const
  5375. {
  5376. cmTargetInternals::LinkImplClosure& tgts =
  5377. this->Internal->LinkImplClosureMap[config];
  5378. if(!tgts.Done)
  5379. {
  5380. tgts.Done = true;
  5381. std::set<cmTarget const*> emitted;
  5382. cmTarget::LinkImplementationLibraries const* impl
  5383. = this->GetLinkImplementationLibraries(config);
  5384. for(std::vector<cmLinkImplItem>::const_iterator
  5385. it = impl->Libraries.begin();
  5386. it != impl->Libraries.end(); ++it)
  5387. {
  5388. processILibs(config, this, *it, tgts , emitted);
  5389. }
  5390. }
  5391. return tgts;
  5392. }
  5393. //----------------------------------------------------------------------------
  5394. cmTarget::CompatibleInterfaces const&
  5395. cmTarget::GetCompatibleInterfaces(std::string const& config) const
  5396. {
  5397. cmTargetInternals::CompatibleInterfaces& compat =
  5398. this->Internal->CompatibleInterfacesMap[config];
  5399. if(!compat.Done)
  5400. {
  5401. compat.Done = true;
  5402. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  5403. compat.PropsString.insert("AUTOUIC_OPTIONS");
  5404. std::vector<cmTarget const*> const& deps =
  5405. this->GetLinkImplementationClosure(config);
  5406. for(std::vector<cmTarget const*>::const_iterator li = deps.begin();
  5407. li != deps.end(); ++li)
  5408. {
  5409. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  5410. if(const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) \
  5411. { \
  5412. std::vector<std::string> props; \
  5413. cmSystemTools::ExpandListArgument(prop, props); \
  5414. compat.Props##x.insert(props.begin(), props.end()); \
  5415. }
  5416. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  5417. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  5418. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  5419. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  5420. #undef CM_READ_COMPATIBLE_INTERFACE
  5421. }
  5422. }
  5423. return compat;
  5424. }
  5425. //----------------------------------------------------------------------------
  5426. void
  5427. cmTargetInternals::ComputeLinkInterfaceLibraries(
  5428. cmTarget const* thisTarget,
  5429. const std::string& config,
  5430. OptionalLinkInterface& iface,
  5431. cmTarget const* headTarget,
  5432. bool usage_requirements_only)
  5433. {
  5434. // Construct the property name suffix for this configuration.
  5435. std::string suffix = "_";
  5436. if(!config.empty())
  5437. {
  5438. suffix += cmSystemTools::UpperCase(config);
  5439. }
  5440. else
  5441. {
  5442. suffix += "NOCONFIG";
  5443. }
  5444. // An explicit list of interface libraries may be set for shared
  5445. // libraries and executables that export symbols.
  5446. const char* explicitLibraries = 0;
  5447. std::string linkIfaceProp;
  5448. if(thisTarget->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  5449. thisTarget->GetPolicyStatusCMP0022() != cmPolicies::WARN)
  5450. {
  5451. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  5452. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  5453. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  5454. }
  5455. else if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY ||
  5456. thisTarget->IsExecutableWithExports())
  5457. {
  5458. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  5459. // shared lib or executable.
  5460. // Lookup the per-configuration property.
  5461. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5462. linkIfaceProp += suffix;
  5463. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  5464. // If not set, try the generic property.
  5465. if(!explicitLibraries)
  5466. {
  5467. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5468. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  5469. }
  5470. }
  5471. if(explicitLibraries &&
  5472. thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  5473. !this->PolicyWarnedCMP0022)
  5474. {
  5475. // Compare the explicitly set old link interface properties to the
  5476. // preferred new link interface property one and warn if different.
  5477. const char* newExplicitLibraries =
  5478. thisTarget->GetProperty("INTERFACE_LINK_LIBRARIES");
  5479. if (newExplicitLibraries
  5480. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  5481. {
  5482. std::ostringstream w;
  5483. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  5484. "Target \"" << thisTarget->GetName() << "\" has an "
  5485. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  5486. linkIfaceProp << " properties."
  5487. "\n"
  5488. "INTERFACE_LINK_LIBRARIES:\n"
  5489. " " << newExplicitLibraries << "\n" <<
  5490. linkIfaceProp << ":\n"
  5491. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  5492. thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  5493. this->PolicyWarnedCMP0022 = true;
  5494. }
  5495. }
  5496. // There is no implicit link interface for executables or modules
  5497. // so if none was explicitly set then there is no link interface.
  5498. if(!explicitLibraries &&
  5499. (thisTarget->GetType() == cmTarget::EXECUTABLE ||
  5500. (thisTarget->GetType() == cmTarget::MODULE_LIBRARY)))
  5501. {
  5502. return;
  5503. }
  5504. iface.Exists = true;
  5505. iface.ExplicitLibraries = explicitLibraries;
  5506. if(explicitLibraries)
  5507. {
  5508. // The interface libraries have been explicitly set.
  5509. thisTarget->ExpandLinkItems(linkIfaceProp, explicitLibraries, config,
  5510. headTarget, usage_requirements_only,
  5511. iface.Libraries,
  5512. iface.HadHeadSensitiveCondition);
  5513. }
  5514. else if (thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN
  5515. || thisTarget->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  5516. // If CMP0022 is NEW then the plain tll signature sets the
  5517. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  5518. // cleared the property explicitly and we should not fall back
  5519. // to the link implementation.
  5520. {
  5521. // The link implementation is the default link interface.
  5522. cmTarget::LinkImplementationLibraries const* impl =
  5523. thisTarget->GetLinkImplementationLibrariesInternal(config, headTarget);
  5524. iface.Libraries.insert(iface.Libraries.end(),
  5525. impl->Libraries.begin(), impl->Libraries.end());
  5526. if(thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  5527. !this->PolicyWarnedCMP0022 && !usage_requirements_only)
  5528. {
  5529. // Compare the link implementation fallback link interface to the
  5530. // preferred new link interface property and warn if different.
  5531. std::vector<cmLinkItem> ifaceLibs;
  5532. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  5533. if(const char* newExplicitLibraries = thisTarget->GetProperty(newProp))
  5534. {
  5535. bool hadHeadSensitiveConditionDummy = false;
  5536. thisTarget->ExpandLinkItems(newProp, newExplicitLibraries, config,
  5537. headTarget, usage_requirements_only,
  5538. ifaceLibs, hadHeadSensitiveConditionDummy);
  5539. }
  5540. if (ifaceLibs != iface.Libraries)
  5541. {
  5542. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  5543. std::string newLibraries = cmJoin(ifaceLibs, ";");
  5544. if(oldLibraries.empty())
  5545. { oldLibraries = "(empty)"; }
  5546. if(newLibraries.empty())
  5547. { newLibraries = "(empty)"; }
  5548. std::ostringstream w;
  5549. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  5550. "Target \"" << thisTarget->GetName() << "\" has an "
  5551. "INTERFACE_LINK_LIBRARIES property. "
  5552. "This should be preferred as the source of the link interface "
  5553. "for this library but because CMP0022 is not set CMake is "
  5554. "ignoring the property and using the link implementation "
  5555. "as the link interface instead."
  5556. "\n"
  5557. "INTERFACE_LINK_LIBRARIES:\n"
  5558. " " << newLibraries << "\n"
  5559. "Link implementation:\n"
  5560. " " << oldLibraries << "\n";
  5561. thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  5562. this->PolicyWarnedCMP0022 = true;
  5563. }
  5564. }
  5565. }
  5566. }
  5567. //----------------------------------------------------------------------------
  5568. void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
  5569. const std::string& config,
  5570. OptionalLinkInterface& iface,
  5571. cmTarget const* headTarget) const
  5572. {
  5573. if(iface.ExplicitLibraries)
  5574. {
  5575. if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY
  5576. || thisTarget->GetType() == cmTarget::STATIC_LIBRARY
  5577. || thisTarget->GetType() == cmTarget::INTERFACE_LIBRARY)
  5578. {
  5579. // Shared libraries may have runtime implementation dependencies
  5580. // on other shared libraries that are not in the interface.
  5581. UNORDERED_SET<std::string> emitted;
  5582. for(std::vector<cmLinkItem>::const_iterator
  5583. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  5584. {
  5585. emitted.insert(*li);
  5586. }
  5587. if (thisTarget->GetType() != cmTarget::INTERFACE_LIBRARY)
  5588. {
  5589. cmTarget::LinkImplementation const* impl =
  5590. thisTarget->GetLinkImplementation(config);
  5591. for(std::vector<cmLinkImplItem>::const_iterator
  5592. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  5593. {
  5594. if(emitted.insert(*li).second)
  5595. {
  5596. if(li->Target)
  5597. {
  5598. // This is a runtime dependency on another shared library.
  5599. if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
  5600. {
  5601. iface.SharedDeps.push_back(*li);
  5602. }
  5603. }
  5604. else
  5605. {
  5606. // TODO: Recognize shared library file names. Perhaps this
  5607. // should be moved to cmComputeLinkInformation, but that creates
  5608. // a chicken-and-egg problem since this list is needed for its
  5609. // construction.
  5610. }
  5611. }
  5612. }
  5613. }
  5614. }
  5615. }
  5616. else if (thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN
  5617. || thisTarget->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  5618. {
  5619. // The link implementation is the default link interface.
  5620. cmTarget::LinkImplementationLibraries const*
  5621. impl = thisTarget->GetLinkImplementationLibrariesInternal(config,
  5622. headTarget);
  5623. iface.ImplementationIsInterface = true;
  5624. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  5625. }
  5626. if(thisTarget->LinkLanguagePropagatesToDependents())
  5627. {
  5628. // Targets using this archive need its language runtime libraries.
  5629. if(cmTarget::LinkImplementation const* impl =
  5630. thisTarget->GetLinkImplementation(config))
  5631. {
  5632. iface.Languages = impl->Languages;
  5633. }
  5634. }
  5635. if(thisTarget->GetType() == cmTarget::STATIC_LIBRARY)
  5636. {
  5637. // Construct the property name suffix for this configuration.
  5638. std::string suffix = "_";
  5639. if(!config.empty())
  5640. {
  5641. suffix += cmSystemTools::UpperCase(config);
  5642. }
  5643. else
  5644. {
  5645. suffix += "NOCONFIG";
  5646. }
  5647. // How many repetitions are needed if this library has cyclic
  5648. // dependencies?
  5649. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  5650. propName += suffix;
  5651. if(const char* config_reps = thisTarget->GetProperty(propName))
  5652. {
  5653. sscanf(config_reps, "%u", &iface.Multiplicity);
  5654. }
  5655. else if(const char* reps =
  5656. thisTarget->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  5657. {
  5658. sscanf(reps, "%u", &iface.Multiplicity);
  5659. }
  5660. }
  5661. }
  5662. //----------------------------------------------------------------------------
  5663. void cmTargetInternals::AddInterfaceEntries(
  5664. cmTarget const* thisTarget, std::string const& config,
  5665. std::string const& prop, std::vector<TargetPropertyEntry*>& entries)
  5666. {
  5667. if(cmTarget::LinkImplementationLibraries const* impl =
  5668. thisTarget->GetLinkImplementationLibraries(config))
  5669. {
  5670. for (std::vector<cmLinkImplItem>::const_iterator
  5671. it = impl->Libraries.begin(), end = impl->Libraries.end();
  5672. it != end; ++it)
  5673. {
  5674. if(it->Target)
  5675. {
  5676. std::string genex =
  5677. "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
  5678. cmGeneratorExpression ge(it->Backtrace);
  5679. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  5680. cge->SetEvaluateForBuildsystem(true);
  5681. entries.push_back(
  5682. new cmTargetInternals::TargetPropertyEntry(cge, *it));
  5683. }
  5684. }
  5685. }
  5686. }
  5687. //----------------------------------------------------------------------------
  5688. cmTarget::LinkImplementation const*
  5689. cmTarget::GetLinkImplementation(const std::string& config) const
  5690. {
  5691. // There is no link implementation for imported targets.
  5692. if(this->IsImported())
  5693. {
  5694. return 0;
  5695. }
  5696. // Populate the link implementation for this configuration.
  5697. std::string CONFIG = cmSystemTools::UpperCase(config);
  5698. cmTargetInternals::OptionalLinkImplementation&
  5699. impl = this->Internal->LinkImplMap[CONFIG][this];
  5700. if(!impl.LibrariesDone)
  5701. {
  5702. impl.LibrariesDone = true;
  5703. this->Internal
  5704. ->ComputeLinkImplementationLibraries(this, config, impl, this);
  5705. }
  5706. if(!impl.LanguagesDone)
  5707. {
  5708. impl.LanguagesDone = true;
  5709. this->Internal->ComputeLinkImplementationLanguages(this, config, impl);
  5710. }
  5711. return &impl;
  5712. }
  5713. //----------------------------------------------------------------------------
  5714. cmTarget::LinkImplementationLibraries const*
  5715. cmTarget::GetLinkImplementationLibraries(const std::string& config) const
  5716. {
  5717. return this->GetLinkImplementationLibrariesInternal(config, this);
  5718. }
  5719. //----------------------------------------------------------------------------
  5720. cmTarget::LinkImplementationLibraries const*
  5721. cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config,
  5722. cmTarget const* head) const
  5723. {
  5724. // There is no link implementation for imported targets.
  5725. if(this->IsImported())
  5726. {
  5727. return 0;
  5728. }
  5729. // Populate the link implementation libraries for this configuration.
  5730. std::string CONFIG = cmSystemTools::UpperCase(config);
  5731. cmTargetInternals::HeadToLinkImplementationMap& hm =
  5732. this->Internal->LinkImplMap[CONFIG];
  5733. // If the link implementation does not depend on the head target
  5734. // then return the one we computed first.
  5735. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  5736. {
  5737. return &hm.begin()->second;
  5738. }
  5739. cmTargetInternals::OptionalLinkImplementation& impl = hm[head];
  5740. if(!impl.LibrariesDone)
  5741. {
  5742. impl.LibrariesDone = true;
  5743. this->Internal
  5744. ->ComputeLinkImplementationLibraries(this, config, impl, head);
  5745. }
  5746. return &impl;
  5747. }
  5748. //----------------------------------------------------------------------------
  5749. void
  5750. cmTargetInternals::ComputeLinkImplementationLibraries(
  5751. cmTarget const* thisTarget,
  5752. const std::string& config,
  5753. OptionalLinkImplementation& impl,
  5754. cmTarget const* head) const
  5755. {
  5756. // Collect libraries directly linked in this configuration.
  5757. for (std::vector<cmValueWithOrigin>::const_iterator
  5758. le = this->LinkImplementationPropertyEntries.begin(),
  5759. end = this->LinkImplementationPropertyEntries.end();
  5760. le != end; ++le)
  5761. {
  5762. std::vector<std::string> llibs;
  5763. cmGeneratorExpressionDAGChecker dagChecker(
  5764. thisTarget->GetName(),
  5765. "LINK_LIBRARIES", 0, 0);
  5766. cmGeneratorExpression ge(le->Backtrace);
  5767. cmsys::auto_ptr<cmCompiledGeneratorExpression> const cge =
  5768. ge.Parse(le->Value);
  5769. std::string const evaluated =
  5770. cge->Evaluate(thisTarget->Makefile, config, false, head, &dagChecker);
  5771. cmSystemTools::ExpandListArgument(evaluated, llibs);
  5772. if(cge->GetHadHeadSensitiveCondition())
  5773. {
  5774. impl.HadHeadSensitiveCondition = true;
  5775. }
  5776. for(std::vector<std::string>::const_iterator li = llibs.begin();
  5777. li != llibs.end(); ++li)
  5778. {
  5779. // Skip entries that resolve to the target itself or are empty.
  5780. std::string name = thisTarget->CheckCMP0004(*li);
  5781. if(name == thisTarget->GetName() || name.empty())
  5782. {
  5783. if(name == thisTarget->GetName())
  5784. {
  5785. bool noMessage = false;
  5786. cmake::MessageType messageType = cmake::FATAL_ERROR;
  5787. std::ostringstream e;
  5788. switch(thisTarget->GetPolicyStatusCMP0038())
  5789. {
  5790. case cmPolicies::WARN:
  5791. {
  5792. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  5793. messageType = cmake::AUTHOR_WARNING;
  5794. }
  5795. break;
  5796. case cmPolicies::OLD:
  5797. noMessage = true;
  5798. case cmPolicies::REQUIRED_IF_USED:
  5799. case cmPolicies::REQUIRED_ALWAYS:
  5800. case cmPolicies::NEW:
  5801. // Issue the fatal message.
  5802. break;
  5803. }
  5804. if(!noMessage)
  5805. {
  5806. e << "Target \"" << thisTarget->GetName() << "\" links to itself.";
  5807. thisTarget->Makefile->GetCMakeInstance()->IssueMessage(
  5808. messageType, e.str(), thisTarget->GetBacktrace());
  5809. if (messageType == cmake::FATAL_ERROR)
  5810. {
  5811. return;
  5812. }
  5813. }
  5814. }
  5815. continue;
  5816. }
  5817. // The entry is meant for this configuration.
  5818. impl.Libraries.push_back(
  5819. cmLinkImplItem(name, thisTarget->FindTargetToLink(name),
  5820. le->Backtrace, evaluated != le->Value));
  5821. }
  5822. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  5823. for (std::set<std::string>::const_iterator it = seenProps.begin();
  5824. it != seenProps.end(); ++it)
  5825. {
  5826. if (!thisTarget->GetProperty(*it))
  5827. {
  5828. thisTarget->LinkImplicitNullProperties.insert(*it);
  5829. }
  5830. }
  5831. cge->GetMaxLanguageStandard(thisTarget, thisTarget->MaxLanguageStandards);
  5832. }
  5833. cmTarget::LinkLibraryType linkType = thisTarget->ComputeLinkType(config);
  5834. cmTarget::LinkLibraryVectorType const& oldllibs =
  5835. thisTarget->GetOriginalLinkLibraries();
  5836. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  5837. li != oldllibs.end(); ++li)
  5838. {
  5839. if(li->second != cmTarget::GENERAL && li->second != linkType)
  5840. {
  5841. std::string name = thisTarget->CheckCMP0004(li->first);
  5842. if(name == thisTarget->GetName() || name.empty())
  5843. {
  5844. continue;
  5845. }
  5846. // Support OLD behavior for CMP0003.
  5847. impl.WrongConfigLibraries.push_back(
  5848. cmLinkItem(name, thisTarget->FindTargetToLink(name)));
  5849. }
  5850. }
  5851. }
  5852. //----------------------------------------------------------------------------
  5853. void
  5854. cmTargetInternals::ComputeLinkImplementationLanguages(
  5855. cmTarget const* thisTarget,
  5856. const std::string& config,
  5857. OptionalLinkImplementation& impl) const
  5858. {
  5859. // This target needs runtime libraries for its source languages.
  5860. std::set<std::string> languages;
  5861. // Get languages used in our source files.
  5862. thisTarget->GetLanguages(languages, config);
  5863. // Copy the set of langauges to the link implementation.
  5864. impl.Languages.insert(impl.Languages.begin(),
  5865. languages.begin(), languages.end());
  5866. }
  5867. //----------------------------------------------------------------------------
  5868. cmTarget const* cmTarget::FindTargetToLink(std::string const& name) const
  5869. {
  5870. cmTarget const* tgt = this->Makefile->FindTargetToUse(name);
  5871. // Skip targets that will not really be linked. This is probably a
  5872. // name conflict between an external library and an executable
  5873. // within the project.
  5874. if(tgt && tgt->GetType() == cmTarget::EXECUTABLE &&
  5875. !tgt->IsExecutableWithExports())
  5876. {
  5877. tgt = 0;
  5878. }
  5879. if(tgt && tgt->GetType() == cmTarget::OBJECT_LIBRARY)
  5880. {
  5881. std::ostringstream e;
  5882. e << "Target \"" << this->GetName() << "\" links to "
  5883. "OBJECT library \"" << tgt->GetName() << "\" but this is not "
  5884. "allowed. "
  5885. "One may link only to STATIC or SHARED libraries, or to executables "
  5886. "with the ENABLE_EXPORTS property set.";
  5887. cmake* cm = this->Makefile->GetCMakeInstance();
  5888. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5889. tgt = 0;
  5890. }
  5891. // Return the target found, if any.
  5892. return tgt;
  5893. }
  5894. //----------------------------------------------------------------------------
  5895. std::string cmTarget::CheckCMP0004(std::string const& item) const
  5896. {
  5897. // Strip whitespace off the library names because we used to do this
  5898. // in case variables were expanded at generate time. We no longer
  5899. // do the expansion but users link to libraries like " ${VAR} ".
  5900. std::string lib = item;
  5901. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  5902. if(pos != lib.npos)
  5903. {
  5904. lib = lib.substr(pos, lib.npos);
  5905. }
  5906. pos = lib.find_last_not_of(" \t\r\n");
  5907. if(pos != lib.npos)
  5908. {
  5909. lib = lib.substr(0, pos+1);
  5910. }
  5911. if(lib != item)
  5912. {
  5913. cmake* cm = this->Makefile->GetCMakeInstance();
  5914. switch(this->GetPolicyStatusCMP0004())
  5915. {
  5916. case cmPolicies::WARN:
  5917. {
  5918. std::ostringstream w;
  5919. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  5920. << "Target \"" << this->GetName() << "\" links to item \""
  5921. << item << "\" which has leading or trailing whitespace.";
  5922. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  5923. this->GetBacktrace());
  5924. }
  5925. case cmPolicies::OLD:
  5926. break;
  5927. case cmPolicies::NEW:
  5928. {
  5929. std::ostringstream e;
  5930. e << "Target \"" << this->GetName() << "\" links to item \""
  5931. << item << "\" which has leading or trailing whitespace. "
  5932. << "This is now an error according to policy CMP0004.";
  5933. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5934. }
  5935. break;
  5936. case cmPolicies::REQUIRED_IF_USED:
  5937. case cmPolicies::REQUIRED_ALWAYS:
  5938. {
  5939. std::ostringstream e;
  5940. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  5941. << "Target \"" << this->GetName() << "\" links to item \""
  5942. << item << "\" which has leading or trailing whitespace.";
  5943. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5944. }
  5945. break;
  5946. }
  5947. }
  5948. return lib;
  5949. }
  5950. template<typename PropertyType>
  5951. PropertyType getLinkInterfaceDependentProperty(cmTarget const* tgt,
  5952. const std::string& prop,
  5953. const std::string& config,
  5954. CompatibleType,
  5955. PropertyType *);
  5956. template<>
  5957. bool getLinkInterfaceDependentProperty(cmTarget const* tgt,
  5958. const std::string& prop,
  5959. const std::string& config,
  5960. CompatibleType, bool *)
  5961. {
  5962. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  5963. }
  5964. template<>
  5965. const char * getLinkInterfaceDependentProperty(cmTarget const* tgt,
  5966. const std::string& prop,
  5967. const std::string& config,
  5968. CompatibleType t,
  5969. const char **)
  5970. {
  5971. switch(t)
  5972. {
  5973. case BoolType:
  5974. assert(0 && "String compatibility check function called for boolean");
  5975. return 0;
  5976. case StringType:
  5977. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  5978. case NumberMinType:
  5979. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  5980. case NumberMaxType:
  5981. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  5982. }
  5983. assert(0 && "Unreachable!");
  5984. return 0;
  5985. }
  5986. //----------------------------------------------------------------------------
  5987. template<typename PropertyType>
  5988. void checkPropertyConsistency(cmTarget const* depender,
  5989. cmTarget const* dependee,
  5990. const std::string& propName,
  5991. std::set<std::string> &emitted,
  5992. const std::string& config,
  5993. CompatibleType t,
  5994. PropertyType *)
  5995. {
  5996. const char *prop = dependee->GetProperty(propName);
  5997. if (!prop)
  5998. {
  5999. return;
  6000. }
  6001. std::vector<std::string> props;
  6002. cmSystemTools::ExpandListArgument(prop, props);
  6003. std::string pdir =
  6004. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  6005. pdir += "/Help/prop_tgt/";
  6006. for(std::vector<std::string>::iterator pi = props.begin();
  6007. pi != props.end(); ++pi)
  6008. {
  6009. std::string pname = cmSystemTools::HelpFileName(*pi);
  6010. std::string pfile = pdir + pname + ".rst";
  6011. if(cmSystemTools::FileExists(pfile.c_str(), true))
  6012. {
  6013. std::ostringstream e;
  6014. e << "Target \"" << dependee->GetName() << "\" has property \""
  6015. << *pi << "\" listed in its " << propName << " property. "
  6016. "This is not allowed. Only user-defined properties may appear "
  6017. "listed in the " << propName << " property.";
  6018. depender->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
  6019. return;
  6020. }
  6021. if(emitted.insert(*pi).second)
  6022. {
  6023. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  6024. t, 0);
  6025. if (cmSystemTools::GetErrorOccuredFlag())
  6026. {
  6027. return;
  6028. }
  6029. }
  6030. }
  6031. }
  6032. static std::string intersect(const std::set<std::string> &s1,
  6033. const std::set<std::string> &s2)
  6034. {
  6035. std::set<std::string> intersect;
  6036. std::set_intersection(s1.begin(),s1.end(),
  6037. s2.begin(),s2.end(),
  6038. std::inserter(intersect,intersect.begin()));
  6039. if (!intersect.empty())
  6040. {
  6041. return *intersect.begin();
  6042. }
  6043. return "";
  6044. }
  6045. static std::string intersect(const std::set<std::string> &s1,
  6046. const std::set<std::string> &s2,
  6047. const std::set<std::string> &s3)
  6048. {
  6049. std::string result;
  6050. result = intersect(s1, s2);
  6051. if (!result.empty())
  6052. return result;
  6053. result = intersect(s1, s3);
  6054. if (!result.empty())
  6055. return result;
  6056. return intersect(s2, s3);
  6057. }
  6058. static std::string intersect(const std::set<std::string> &s1,
  6059. const std::set<std::string> &s2,
  6060. const std::set<std::string> &s3,
  6061. const std::set<std::string> &s4)
  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. result = intersect(s1, s4);
  6071. if (!result.empty())
  6072. return result;
  6073. return intersect(s2, s3, s4);
  6074. }
  6075. //----------------------------------------------------------------------------
  6076. void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
  6077. const std::string& config) const
  6078. {
  6079. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  6080. std::set<std::string> emittedBools;
  6081. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  6082. std::set<std::string> emittedStrings;
  6083. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  6084. std::set<std::string> emittedMinNumbers;
  6085. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  6086. std::set<std::string> emittedMaxNumbers;
  6087. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  6088. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  6089. deps.begin();
  6090. li != deps.end(); ++li)
  6091. {
  6092. if (!li->Target)
  6093. {
  6094. continue;
  6095. }
  6096. checkPropertyConsistency<bool>(this, li->Target,
  6097. strBool,
  6098. emittedBools, config, BoolType, 0);
  6099. if (cmSystemTools::GetErrorOccuredFlag())
  6100. {
  6101. return;
  6102. }
  6103. checkPropertyConsistency<const char *>(this, li->Target,
  6104. strString,
  6105. emittedStrings, config,
  6106. StringType, 0);
  6107. if (cmSystemTools::GetErrorOccuredFlag())
  6108. {
  6109. return;
  6110. }
  6111. checkPropertyConsistency<const char *>(this, li->Target,
  6112. strNumMin,
  6113. emittedMinNumbers, config,
  6114. NumberMinType, 0);
  6115. if (cmSystemTools::GetErrorOccuredFlag())
  6116. {
  6117. return;
  6118. }
  6119. checkPropertyConsistency<const char *>(this, li->Target,
  6120. strNumMax,
  6121. emittedMaxNumbers, config,
  6122. NumberMaxType, 0);
  6123. if (cmSystemTools::GetErrorOccuredFlag())
  6124. {
  6125. return;
  6126. }
  6127. }
  6128. std::string prop = intersect(emittedBools,
  6129. emittedStrings,
  6130. emittedMinNumbers,
  6131. emittedMaxNumbers);
  6132. if (!prop.empty())
  6133. {
  6134. // Use a sorted std::vector to keep the error message sorted.
  6135. std::vector<std::string> props;
  6136. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  6137. if (i != emittedBools.end())
  6138. {
  6139. props.push_back(strBool);
  6140. }
  6141. i = emittedStrings.find(prop);
  6142. if (i != emittedStrings.end())
  6143. {
  6144. props.push_back(strString);
  6145. }
  6146. i = emittedMinNumbers.find(prop);
  6147. if (i != emittedMinNumbers.end())
  6148. {
  6149. props.push_back(strNumMin);
  6150. }
  6151. i = emittedMaxNumbers.find(prop);
  6152. if (i != emittedMaxNumbers.end())
  6153. {
  6154. props.push_back(strNumMax);
  6155. }
  6156. std::sort(props.begin(), props.end());
  6157. std::string propsString = cmJoin(cmRange(props).retreat(1), ", ");
  6158. propsString += " and the " + props.back();
  6159. std::ostringstream e;
  6160. e << "Property \"" << prop << "\" appears in both the "
  6161. << propsString <<
  6162. " property in the dependencies of target \"" << this->GetName() <<
  6163. "\". This is not allowed. A property may only require compatibility "
  6164. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  6165. "string interpretation, but not a mixture.";
  6166. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  6167. }
  6168. }
  6169. //----------------------------------------------------------------------------
  6170. cmComputeLinkInformation*
  6171. cmTarget::GetLinkInformation(const std::string& config) const
  6172. {
  6173. // Lookup any existing information for this configuration.
  6174. std::string key(cmSystemTools::UpperCase(config));
  6175. cmTargetLinkInformationMap::iterator
  6176. i = this->LinkInformation.find(key);
  6177. if(i == this->LinkInformation.end())
  6178. {
  6179. // Compute information for this configuration.
  6180. cmComputeLinkInformation* info =
  6181. new cmComputeLinkInformation(this, config);
  6182. if(!info || !info->Compute())
  6183. {
  6184. delete info;
  6185. info = 0;
  6186. }
  6187. // Store the information for this configuration.
  6188. cmTargetLinkInformationMap::value_type entry(key, info);
  6189. i = this->LinkInformation.insert(entry).first;
  6190. if (info)
  6191. {
  6192. this->CheckPropertyCompatibility(info, config);
  6193. }
  6194. }
  6195. return i->second;
  6196. }
  6197. //----------------------------------------------------------------------------
  6198. std::string cmTarget::GetFrameworkDirectory(const std::string& config,
  6199. bool rootDir) const
  6200. {
  6201. std::string fpath;
  6202. fpath += this->GetOutputName(config, false);
  6203. fpath += ".framework";
  6204. if(!rootDir)
  6205. {
  6206. fpath += "/Versions/";
  6207. fpath += this->GetFrameworkVersion();
  6208. }
  6209. return fpath;
  6210. }
  6211. //----------------------------------------------------------------------------
  6212. std::string cmTarget::GetCFBundleDirectory(const std::string& config,
  6213. bool contentOnly) const
  6214. {
  6215. std::string fpath;
  6216. fpath += this->GetOutputName(config, false);
  6217. fpath += ".";
  6218. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  6219. if (!ext)
  6220. {
  6221. if (this->IsXCTestOnApple())
  6222. {
  6223. ext = "xctest";
  6224. }
  6225. else
  6226. {
  6227. ext = "bundle";
  6228. }
  6229. }
  6230. fpath += ext;
  6231. fpath += "/Contents";
  6232. if(!contentOnly)
  6233. fpath += "/MacOS";
  6234. return fpath;
  6235. }
  6236. //----------------------------------------------------------------------------
  6237. std::string cmTarget::GetAppBundleDirectory(const std::string& config,
  6238. bool contentOnly) const
  6239. {
  6240. std::string fpath = this->GetFullName(config, false);
  6241. fpath += ".app/Contents";
  6242. if(!contentOnly)
  6243. fpath += "/MacOS";
  6244. return fpath;
  6245. }
  6246. //----------------------------------------------------------------------------
  6247. std::string cmTarget::BuildMacContentDirectory(const std::string& base,
  6248. const std::string& config,
  6249. bool contentOnly) const
  6250. {
  6251. std::string fpath = base;
  6252. if(this->IsAppBundleOnApple())
  6253. {
  6254. fpath += this->GetAppBundleDirectory(config, contentOnly);
  6255. }
  6256. if(this->IsFrameworkOnApple())
  6257. {
  6258. fpath += this->GetFrameworkDirectory(config, contentOnly);
  6259. }
  6260. if(this->IsCFBundleOnApple())
  6261. {
  6262. fpath += this->GetCFBundleDirectory(config, contentOnly);
  6263. }
  6264. return fpath;
  6265. }
  6266. //----------------------------------------------------------------------------
  6267. std::string cmTarget::GetMacContentDirectory(const std::string& config,
  6268. bool implib) const
  6269. {
  6270. // Start with the output directory for the target.
  6271. std::string fpath = this->GetDirectory(config, implib);
  6272. fpath += "/";
  6273. bool contentOnly = true;
  6274. if(this->IsFrameworkOnApple())
  6275. {
  6276. // additional files with a framework go into the version specific
  6277. // directory
  6278. contentOnly = false;
  6279. }
  6280. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  6281. return fpath;
  6282. }
  6283. //----------------------------------------------------------------------------
  6284. cmTargetLinkInformationMap
  6285. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  6286. {
  6287. // Ideally cmTarget instances should never be copied. However until
  6288. // we can make a sweep to remove that, this copy constructor avoids
  6289. // allowing the resources (LinkInformation) from getting copied. In
  6290. // the worst case this will lead to extra cmComputeLinkInformation
  6291. // instances. We also enforce in debug mode that the map be emptied
  6292. // when copied.
  6293. static_cast<void>(r);
  6294. assert(r.empty());
  6295. }
  6296. //----------------------------------------------------------------------------
  6297. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  6298. {
  6299. cmDeleteAll(*this);
  6300. }
  6301. //----------------------------------------------------------------------------
  6302. cmTargetInternalPointer::cmTargetInternalPointer()
  6303. {
  6304. this->Pointer = new cmTargetInternals;
  6305. }
  6306. //----------------------------------------------------------------------------
  6307. cmTargetInternalPointer
  6308. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  6309. {
  6310. // Ideally cmTarget instances should never be copied. However until
  6311. // we can make a sweep to remove that, this copy constructor avoids
  6312. // allowing the resources (Internals) to be copied.
  6313. this->Pointer = new cmTargetInternals(*r.Pointer);
  6314. }
  6315. //----------------------------------------------------------------------------
  6316. cmTargetInternalPointer::~cmTargetInternalPointer()
  6317. {
  6318. cmDeleteAll(this->Pointer->IncludeDirectoriesEntries);
  6319. cmDeleteAll(this->Pointer->CompileOptionsEntries);
  6320. cmDeleteAll(this->Pointer->CompileFeaturesEntries);
  6321. cmDeleteAll(this->Pointer->CompileDefinitionsEntries);
  6322. cmDeleteAll(this->Pointer->SourceEntries);
  6323. delete this->Pointer;
  6324. }
  6325. //----------------------------------------------------------------------------
  6326. cmTargetInternalPointer&
  6327. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  6328. {
  6329. if(this == &r) { return *this; } // avoid warning on HP about self check
  6330. // Ideally cmTarget instances should never be copied. However until
  6331. // we can make a sweep to remove that, this copy constructor avoids
  6332. // allowing the resources (Internals) to be copied.
  6333. cmTargetInternals* oldPointer = this->Pointer;
  6334. this->Pointer = new cmTargetInternals(*r.Pointer);
  6335. delete oldPointer;
  6336. return *this;
  6337. }