cmTarget.cxx 210 KB

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