cmTarget.cxx 231 KB

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