cmTarget.cxx 187 KB

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