cmTarget.cxx 232 KB

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