cmTarget.cxx 249 KB

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