cmTarget.cxx 212 KB

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