cmTarget.cxx 250 KB

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