cmTarget.cxx 226 KB

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