cmTarget.cxx 232 KB

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