cmGeneratorTarget.cxx 183 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGeneratorTarget.h"
  4. #include "cmsys/RegularExpression.hxx"
  5. #include <algorithm>
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <iterator>
  9. #include <queue>
  10. #include <sstream>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include "cmAlgorithms.h"
  15. #include "cmComputeLinkInformation.h"
  16. #include "cmCustomCommand.h"
  17. #include "cmCustomCommandGenerator.h"
  18. #include "cmCustomCommandLines.h"
  19. #include "cmGeneratorExpression.h"
  20. #include "cmGeneratorExpressionDAGChecker.h"
  21. #include "cmGlobalGenerator.h"
  22. #include "cmLocalGenerator.h"
  23. #include "cmMakefile.h"
  24. #include "cmPropertyMap.h"
  25. #include "cmSourceFile.h"
  26. #include "cmSourceFileLocation.h"
  27. #include "cmState.h"
  28. #include "cmSystemTools.h"
  29. #include "cmTarget.h"
  30. #include "cmTargetLinkLibraryType.h"
  31. #include "cmTargetPropertyComputer.h"
  32. #include "cm_auto_ptr.hxx"
  33. #include "cm_unordered_set.hxx"
  34. #include "cmake.h"
  35. class cmMessenger;
  36. template <>
  37. const char* cmTargetPropertyComputer::GetSources<cmGeneratorTarget>(
  38. cmGeneratorTarget const* tgt, cmMessenger* /* messenger */,
  39. cmListFileBacktrace const& /* context */)
  40. {
  41. return tgt->GetSourcesProperty();
  42. }
  43. template <>
  44. const char* cmTargetPropertyComputer::ComputeLocationForBuild<
  45. cmGeneratorTarget>(cmGeneratorTarget const* tgt)
  46. {
  47. return tgt->GetLocation("");
  48. }
  49. template <>
  50. const char* cmTargetPropertyComputer::ComputeLocation<cmGeneratorTarget>(
  51. cmGeneratorTarget const* tgt, const std::string& config)
  52. {
  53. return tgt->GetLocation(config);
  54. }
  55. class cmGeneratorTarget::TargetPropertyEntry
  56. {
  57. static cmLinkImplItem NoLinkImplItem;
  58. public:
  59. TargetPropertyEntry(CM_AUTO_PTR<cmCompiledGeneratorExpression> cge,
  60. cmLinkImplItem const& item = NoLinkImplItem)
  61. : ge(cge)
  62. , LinkImplItem(item)
  63. {
  64. }
  65. const CM_AUTO_PTR<cmCompiledGeneratorExpression> ge;
  66. cmLinkImplItem const& LinkImplItem;
  67. };
  68. cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
  69. void CreatePropertyGeneratorExpressions(
  70. cmStringRange const& entries, cmBacktraceRange const& backtraces,
  71. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items,
  72. bool evaluateForBuildsystem = false)
  73. {
  74. std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
  75. for (std::vector<std::string>::const_iterator it = entries.begin();
  76. it != entries.end(); ++it, ++btIt) {
  77. cmGeneratorExpression ge(*btIt);
  78. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
  79. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  80. items.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  81. }
  82. }
  83. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  84. : Target(t)
  85. , FortranModuleDirectoryCreated(false)
  86. , SourceFileFlagsConstructed(false)
  87. , PolicyWarnedCMP0022(false)
  88. , PolicyReportedCMP0069(false)
  89. , DebugIncludesDone(false)
  90. , DebugCompileOptionsDone(false)
  91. , DebugCompileFeaturesDone(false)
  92. , DebugCompileDefinitionsDone(false)
  93. , DebugSourcesDone(false)
  94. , LinkImplementationLanguageIsContextDependent(true)
  95. , UtilityItemsDone(false)
  96. {
  97. this->Makefile = this->Target->GetMakefile();
  98. this->LocalGenerator = lg;
  99. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  100. this->GlobalGenerator->ComputeTargetObjectDirectory(this);
  101. CreatePropertyGeneratorExpressions(t->GetIncludeDirectoriesEntries(),
  102. t->GetIncludeDirectoriesBacktraces(),
  103. this->IncludeDirectoriesEntries);
  104. CreatePropertyGeneratorExpressions(t->GetCompileOptionsEntries(),
  105. t->GetCompileOptionsBacktraces(),
  106. this->CompileOptionsEntries);
  107. CreatePropertyGeneratorExpressions(t->GetCompileFeaturesEntries(),
  108. t->GetCompileFeaturesBacktraces(),
  109. this->CompileFeaturesEntries);
  110. CreatePropertyGeneratorExpressions(t->GetCompileDefinitionsEntries(),
  111. t->GetCompileDefinitionsBacktraces(),
  112. this->CompileDefinitionsEntries);
  113. CreatePropertyGeneratorExpressions(t->GetSourceEntries(),
  114. t->GetSourceBacktraces(),
  115. this->SourceEntries, true);
  116. this->DLLPlatform =
  117. (this->Makefile->IsOn("WIN32") || this->Makefile->IsOn("CYGWIN") ||
  118. this->Makefile->IsOn("MINGW"));
  119. this->PolicyMap = t->PolicyMap;
  120. }
  121. cmGeneratorTarget::~cmGeneratorTarget()
  122. {
  123. cmDeleteAll(this->IncludeDirectoriesEntries);
  124. cmDeleteAll(this->CompileOptionsEntries);
  125. cmDeleteAll(this->CompileFeaturesEntries);
  126. cmDeleteAll(this->CompileDefinitionsEntries);
  127. cmDeleteAll(this->SourceEntries);
  128. cmDeleteAll(this->LinkInformation);
  129. }
  130. const char* cmGeneratorTarget::GetSourcesProperty() const
  131. {
  132. std::vector<std::string> values;
  133. for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
  134. it = this->SourceEntries.begin(),
  135. end = this->SourceEntries.end();
  136. it != end; ++it) {
  137. values.push_back((*it)->ge->GetInput());
  138. }
  139. static std::string value;
  140. value.clear();
  141. value = cmJoin(values, "");
  142. return value.c_str();
  143. }
  144. cmGlobalGenerator* cmGeneratorTarget::GetGlobalGenerator() const
  145. {
  146. return this->GetLocalGenerator()->GetGlobalGenerator();
  147. }
  148. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  149. {
  150. return this->LocalGenerator;
  151. }
  152. cmStateEnums::TargetType cmGeneratorTarget::GetType() const
  153. {
  154. return this->Target->GetType();
  155. }
  156. const std::string& cmGeneratorTarget::GetName() const
  157. {
  158. return this->Target->GetName();
  159. }
  160. std::string cmGeneratorTarget::GetExportName() const
  161. {
  162. const char* exportName = this->GetProperty("EXPORT_NAME");
  163. if (exportName && *exportName) {
  164. if (!cmGeneratorExpression::IsValidTargetName(exportName)) {
  165. std::ostringstream e;
  166. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  167. << this->GetName() << "\": is not valid.";
  168. cmSystemTools::Error(e.str().c_str());
  169. return "";
  170. }
  171. return exportName;
  172. }
  173. return this->GetName();
  174. }
  175. const char* cmGeneratorTarget::GetProperty(const std::string& prop) const
  176. {
  177. if (!cmTargetPropertyComputer::PassesWhitelist(
  178. this->GetType(), prop, this->Makefile->GetMessenger(),
  179. this->GetBacktrace())) {
  180. return CM_NULLPTR;
  181. }
  182. if (const char* result = cmTargetPropertyComputer::GetProperty(
  183. this, prop, this->Makefile->GetMessenger(), this->GetBacktrace())) {
  184. return result;
  185. }
  186. if (cmSystemTools::GetFatalErrorOccured()) {
  187. return CM_NULLPTR;
  188. }
  189. return this->Target->GetProperty(prop);
  190. }
  191. const char* cmGeneratorTarget::GetOutputTargetType(
  192. cmStateEnums::ArtifactType artifact) const
  193. {
  194. switch (this->GetType()) {
  195. case cmStateEnums::SHARED_LIBRARY:
  196. if (this->IsDLLPlatform()) {
  197. switch (artifact) {
  198. case cmStateEnums::RuntimeBinaryArtifact:
  199. // A DLL shared library is treated as a runtime target.
  200. return "RUNTIME";
  201. case cmStateEnums::ImportLibraryArtifact:
  202. // A DLL import library is treated as an archive target.
  203. return "ARCHIVE";
  204. }
  205. } else {
  206. // For non-DLL platforms shared libraries are treated as
  207. // library targets.
  208. return "LIBRARY";
  209. }
  210. break;
  211. case cmStateEnums::STATIC_LIBRARY:
  212. // Static libraries are always treated as archive targets.
  213. return "ARCHIVE";
  214. case cmStateEnums::MODULE_LIBRARY:
  215. switch (artifact) {
  216. case cmStateEnums::RuntimeBinaryArtifact:
  217. // Module import libraries are treated as archive targets.
  218. return "LIBRARY";
  219. case cmStateEnums::ImportLibraryArtifact:
  220. // Module libraries are always treated as library targets.
  221. return "ARCHIVE";
  222. }
  223. break;
  224. case cmStateEnums::EXECUTABLE:
  225. switch (artifact) {
  226. case cmStateEnums::RuntimeBinaryArtifact:
  227. // Executables are always treated as runtime targets.
  228. return "RUNTIME";
  229. case cmStateEnums::ImportLibraryArtifact:
  230. // Executable import libraries are treated as archive targets.
  231. return "ARCHIVE";
  232. }
  233. break;
  234. default:
  235. break;
  236. }
  237. return "";
  238. }
  239. std::string cmGeneratorTarget::GetOutputName(
  240. const std::string& config, cmStateEnums::ArtifactType artifact) const
  241. {
  242. // Lookup/compute/cache the output name for this configuration.
  243. OutputNameKey key(config, artifact);
  244. cmGeneratorTarget::OutputNameMapType::iterator i =
  245. this->OutputNameMap.find(key);
  246. if (i == this->OutputNameMap.end()) {
  247. // Add empty name in map to detect potential recursion.
  248. OutputNameMapType::value_type entry(key, "");
  249. i = this->OutputNameMap.insert(entry).first;
  250. // Compute output name.
  251. std::vector<std::string> props;
  252. std::string type = this->GetOutputTargetType(artifact);
  253. std::string configUpper = cmSystemTools::UpperCase(config);
  254. if (!type.empty() && !configUpper.empty()) {
  255. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  256. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  257. }
  258. if (!type.empty()) {
  259. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  260. props.push_back(type + "_OUTPUT_NAME");
  261. }
  262. if (!configUpper.empty()) {
  263. // OUTPUT_NAME_<CONFIG>
  264. props.push_back("OUTPUT_NAME_" + configUpper);
  265. // <CONFIG>_OUTPUT_NAME
  266. props.push_back(configUpper + "_OUTPUT_NAME");
  267. }
  268. // OUTPUT_NAME
  269. props.push_back("OUTPUT_NAME");
  270. std::string outName;
  271. for (std::vector<std::string>::const_iterator it = props.begin();
  272. it != props.end(); ++it) {
  273. if (const char* outNameProp = this->GetProperty(*it)) {
  274. outName = outNameProp;
  275. break;
  276. }
  277. }
  278. if (outName.empty()) {
  279. outName = this->GetName();
  280. }
  281. // Now evaluate genex and update the previously-prepared map entry.
  282. cmGeneratorExpression ge;
  283. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  284. i->second = cge->Evaluate(this->LocalGenerator, config);
  285. } else if (i->second.empty()) {
  286. // An empty map entry indicates we have been called recursively
  287. // from the above block.
  288. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  289. cmake::FATAL_ERROR,
  290. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  291. this->GetBacktrace());
  292. }
  293. return i->second;
  294. }
  295. void cmGeneratorTarget::AddSourceCommon(const std::string& src)
  296. {
  297. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  298. cmGeneratorExpression ge(lfbt);
  299. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  300. cge->SetEvaluateForBuildsystem(true);
  301. this->SourceEntries.push_back(new TargetPropertyEntry(cge));
  302. this->KindedSourcesMap.clear();
  303. this->LinkImplementationLanguageIsContextDependent = true;
  304. }
  305. void cmGeneratorTarget::AddSource(const std::string& src)
  306. {
  307. this->Target->AddSource(src);
  308. this->AddSourceCommon(src);
  309. }
  310. void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
  311. {
  312. this->Target->AddTracedSources(srcs);
  313. if (!srcs.empty()) {
  314. this->AddSourceCommon(cmJoin(srcs, ";"));
  315. }
  316. }
  317. void cmGeneratorTarget::AddIncludeDirectory(const std::string& src,
  318. bool before)
  319. {
  320. this->Target->InsertInclude(src, this->Makefile->GetBacktrace(), before);
  321. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  322. cmGeneratorExpression ge(lfbt);
  323. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  324. cge->SetEvaluateForBuildsystem(true);
  325. // Insert before begin/end
  326. std::vector<TargetPropertyEntry*>::iterator pos = before
  327. ? this->IncludeDirectoriesEntries.begin()
  328. : this->IncludeDirectoriesEntries.end();
  329. this->IncludeDirectoriesEntries.insert(pos, new TargetPropertyEntry(cge));
  330. }
  331. std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
  332. cmSourceFile const* sf) const
  333. {
  334. SourceEntriesType::const_iterator i = this->SourceDepends.find(sf);
  335. if (i != this->SourceDepends.end()) {
  336. return &i->second.Depends;
  337. }
  338. return CM_NULLPTR;
  339. }
  340. static void handleSystemIncludesDep(
  341. cmLocalGenerator* lg, cmGeneratorTarget const* depTgt,
  342. const std::string& config, cmGeneratorTarget const* headTarget,
  343. cmGeneratorExpressionDAGChecker* dagChecker,
  344. std::vector<std::string>& result, bool excludeImported)
  345. {
  346. if (const char* dirs =
  347. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
  348. cmGeneratorExpression ge;
  349. cmSystemTools::ExpandListArgument(
  350. ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
  351. dagChecker),
  352. result);
  353. }
  354. if (!depTgt->IsImported() || excludeImported) {
  355. return;
  356. }
  357. if (const char* dirs =
  358. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES")) {
  359. cmGeneratorExpression ge;
  360. cmSystemTools::ExpandListArgument(
  361. ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
  362. dagChecker),
  363. result);
  364. }
  365. }
  366. /* clang-format off */
  367. #define IMPLEMENT_VISIT(KIND) \
  368. { \
  369. KindedSources const& kinded = this->GetKindedSources(config); \
  370. for (std::vector<SourceAndKind>::const_iterator \
  371. si = kinded.Sources.begin(); si != kinded.Sources.end(); ++si) { \
  372. if (si->Kind == KIND) { \
  373. data.push_back(si->Source); \
  374. } \
  375. } \
  376. }
  377. /* clang-format on */
  378. void cmGeneratorTarget::GetObjectSources(
  379. std::vector<cmSourceFile const*>& data, const std::string& config) const
  380. {
  381. IMPLEMENT_VISIT(SourceKindObjectSource);
  382. if (!this->Objects.empty()) {
  383. return;
  384. }
  385. for (std::vector<cmSourceFile const*>::const_iterator it = data.begin();
  386. it != data.end(); ++it) {
  387. this->Objects[*it];
  388. }
  389. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  390. }
  391. void cmGeneratorTarget::ComputeObjectMapping()
  392. {
  393. if (!this->Objects.empty()) {
  394. return;
  395. }
  396. std::vector<std::string> configs;
  397. this->Makefile->GetConfigurations(configs);
  398. if (configs.empty()) {
  399. configs.push_back("");
  400. }
  401. for (std::vector<std::string>::const_iterator ci = configs.begin();
  402. ci != configs.end(); ++ci) {
  403. std::vector<cmSourceFile const*> sourceFiles;
  404. this->GetObjectSources(sourceFiles, *ci);
  405. }
  406. }
  407. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  408. const std::string& config) const
  409. {
  410. if (!config.empty()) {
  411. std::string featureConfig = feature;
  412. featureConfig += "_";
  413. featureConfig += cmSystemTools::UpperCase(config);
  414. if (const char* value = this->GetProperty(featureConfig)) {
  415. return value;
  416. }
  417. }
  418. if (const char* value = this->GetProperty(feature)) {
  419. return value;
  420. }
  421. return this->LocalGenerator->GetFeature(feature, config);
  422. }
  423. bool cmGeneratorTarget::IsIPOEnabled(const std::string& config) const
  424. {
  425. const char* feature = "INTERPROCEDURAL_OPTIMIZATION";
  426. const bool result = cmSystemTools::IsOn(this->GetFeature(feature, config));
  427. if (!result) {
  428. // 'INTERPROCEDURAL_OPTIMIZATION' is off, no need to check policies
  429. return false;
  430. }
  431. cmPolicies::PolicyStatus cmp0069 = this->GetPolicyStatusCMP0069();
  432. if (cmp0069 == cmPolicies::OLD || cmp0069 == cmPolicies::WARN) {
  433. if (this->Makefile->IsOn("_CMAKE_IPO_LEGACY_BEHAVIOR")) {
  434. return true;
  435. }
  436. if (this->PolicyReportedCMP0069) {
  437. // problem is already reported, no need to issue a message
  438. return false;
  439. }
  440. if (cmp0069 == cmPolicies::WARN) {
  441. std::ostringstream w;
  442. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0069) << "\n";
  443. w << "INTERPROCEDURAL_OPTIMIZATION property will be ignored for target "
  444. << "'" << this->GetName() << "'.";
  445. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  446. cmake::AUTHOR_WARNING, w.str(), this->GetBacktrace());
  447. this->PolicyReportedCMP0069 = true;
  448. }
  449. return false;
  450. }
  451. // Note: check consistency with messages from CheckIPOSupported
  452. const char* message = CM_NULLPTR;
  453. if (!this->Makefile->IsOn("_CMAKE_IPO_SUPPORTED_BY_CMAKE")) {
  454. message = "CMake doesn't support IPO for current compiler";
  455. } else if (!this->Makefile->IsOn(
  456. "_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER")) {
  457. message = "Compiler doesn't support IPO";
  458. } else if (!this->GlobalGenerator->IsIPOSupported()) {
  459. message = "CMake doesn't support IPO for current generator";
  460. }
  461. if (!message) {
  462. // No error/warning messages
  463. return true;
  464. }
  465. if (this->PolicyReportedCMP0069) {
  466. // problem is already reported, no need to issue a message
  467. return false;
  468. }
  469. this->PolicyReportedCMP0069 = true;
  470. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  471. cmake::FATAL_ERROR, message, this->GetBacktrace());
  472. return false;
  473. }
  474. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  475. {
  476. this->ComputeObjectMapping();
  477. return this->Objects[file];
  478. }
  479. const char* cmGeneratorTarget::GetCustomObjectExtension() const
  480. {
  481. static std::string extension;
  482. const bool has_ptx_extension =
  483. this->GetPropertyAsBool("CUDA_PTX_COMPILATION");
  484. if (has_ptx_extension) {
  485. extension = ".ptx";
  486. return extension.c_str();
  487. }
  488. return CM_NULLPTR;
  489. }
  490. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  491. {
  492. this->ExplicitObjectName.insert(sf);
  493. }
  494. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  495. {
  496. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  497. std::set<cmSourceFile const*>::const_iterator it =
  498. this->ExplicitObjectName.find(file);
  499. return it != this->ExplicitObjectName.end();
  500. }
  501. void cmGeneratorTarget::GetModuleDefinitionSources(
  502. std::vector<cmSourceFile const*>& data, const std::string& config) const
  503. {
  504. IMPLEMENT_VISIT(SourceKindModuleDefinition);
  505. }
  506. void cmGeneratorTarget::GetHeaderSources(
  507. std::vector<cmSourceFile const*>& data, const std::string& config) const
  508. {
  509. IMPLEMENT_VISIT(SourceKindHeader);
  510. }
  511. void cmGeneratorTarget::GetExtraSources(std::vector<cmSourceFile const*>& data,
  512. const std::string& config) const
  513. {
  514. IMPLEMENT_VISIT(SourceKindExtra);
  515. }
  516. void cmGeneratorTarget::GetCustomCommands(
  517. std::vector<cmSourceFile const*>& data, const std::string& config) const
  518. {
  519. IMPLEMENT_VISIT(SourceKindCustomCommand);
  520. }
  521. void cmGeneratorTarget::GetExternalObjects(
  522. std::vector<cmSourceFile const*>& data, const std::string& config) const
  523. {
  524. IMPLEMENT_VISIT(SourceKindExternalObject);
  525. }
  526. void cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& headers,
  527. const std::string& config) const
  528. {
  529. KindedSources const& kinded = this->GetKindedSources(config);
  530. headers = kinded.ExpectedResxHeaders;
  531. }
  532. void cmGeneratorTarget::GetResxSources(std::vector<cmSourceFile const*>& data,
  533. const std::string& config) const
  534. {
  535. IMPLEMENT_VISIT(SourceKindResx);
  536. }
  537. void cmGeneratorTarget::GetAppManifest(std::vector<cmSourceFile const*>& data,
  538. const std::string& config) const
  539. {
  540. IMPLEMENT_VISIT(SourceKindAppManifest);
  541. }
  542. void cmGeneratorTarget::GetManifests(std::vector<cmSourceFile const*>& data,
  543. const std::string& config) const
  544. {
  545. IMPLEMENT_VISIT(SourceKindManifest);
  546. }
  547. void cmGeneratorTarget::GetCertificates(std::vector<cmSourceFile const*>& data,
  548. const std::string& config) const
  549. {
  550. IMPLEMENT_VISIT(SourceKindCertificate);
  551. }
  552. void cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  553. const std::string& config) const
  554. {
  555. KindedSources const& kinded = this->GetKindedSources(config);
  556. headers = kinded.ExpectedXamlHeaders;
  557. }
  558. void cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  559. const std::string& config) const
  560. {
  561. KindedSources const& kinded = this->GetKindedSources(config);
  562. srcs = kinded.ExpectedXamlSources;
  563. }
  564. std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
  565. {
  566. if (!this->UtilityItemsDone) {
  567. this->UtilityItemsDone = true;
  568. std::set<std::string> const& utilities = this->GetUtilities();
  569. for (std::set<std::string>::const_iterator i = utilities.begin();
  570. i != utilities.end(); ++i) {
  571. cmGeneratorTarget* gt =
  572. this->LocalGenerator->FindGeneratorTargetToUse(*i);
  573. this->UtilityItems.insert(cmLinkItem(*i, gt));
  574. }
  575. }
  576. return this->UtilityItems;
  577. }
  578. void cmGeneratorTarget::GetXamlSources(std::vector<cmSourceFile const*>& data,
  579. const std::string& config) const
  580. {
  581. IMPLEMENT_VISIT(SourceKindXaml);
  582. }
  583. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  584. {
  585. static std::string location;
  586. if (this->IsImported()) {
  587. location = this->Target->ImportedGetFullPath(
  588. config, cmStateEnums::RuntimeBinaryArtifact);
  589. } else {
  590. location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  591. }
  592. return location.c_str();
  593. }
  594. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreBuildCommands()
  595. const
  596. {
  597. return this->Target->GetPreBuildCommands();
  598. }
  599. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreLinkCommands()
  600. const
  601. {
  602. return this->Target->GetPreLinkCommands();
  603. }
  604. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPostBuildCommands()
  605. const
  606. {
  607. return this->Target->GetPostBuildCommands();
  608. }
  609. bool cmGeneratorTarget::IsImported() const
  610. {
  611. return this->Target->IsImported();
  612. }
  613. bool cmGeneratorTarget::IsImportedGloballyVisible() const
  614. {
  615. return this->Target->IsImportedGloballyVisible();
  616. }
  617. const char* cmGeneratorTarget::GetLocationForBuild() const
  618. {
  619. static std::string location;
  620. if (this->IsImported()) {
  621. location = this->Target->ImportedGetFullPath(
  622. "", cmStateEnums::RuntimeBinaryArtifact);
  623. return location.c_str();
  624. }
  625. // Now handle the deprecated build-time configuration location.
  626. location = this->GetDirectory();
  627. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  628. if (cfgid && strcmp(cfgid, ".") != 0) {
  629. location += "/";
  630. location += cfgid;
  631. }
  632. if (this->IsAppBundleOnApple()) {
  633. std::string macdir = this->BuildBundleDirectory("", "", FullLevel);
  634. if (!macdir.empty()) {
  635. location += "/";
  636. location += macdir;
  637. }
  638. }
  639. location += "/";
  640. location += this->GetFullName("", cmStateEnums::RuntimeBinaryArtifact);
  641. return location.c_str();
  642. }
  643. bool cmGeneratorTarget::IsSystemIncludeDirectory(
  644. const std::string& dir, const std::string& config) const
  645. {
  646. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  647. std::string config_upper;
  648. if (!config.empty()) {
  649. config_upper = cmSystemTools::UpperCase(config);
  650. }
  651. typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
  652. IncludeCacheType::const_iterator iter =
  653. this->SystemIncludesCache.find(config_upper);
  654. if (iter == this->SystemIncludesCache.end()) {
  655. cmGeneratorExpressionDAGChecker dagChecker(
  656. this->GetName(), "SYSTEM_INCLUDE_DIRECTORIES", CM_NULLPTR, CM_NULLPTR);
  657. bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  658. std::vector<std::string> result;
  659. for (std::set<std::string>::const_iterator it =
  660. this->Target->GetSystemIncludeDirectories().begin();
  661. it != this->Target->GetSystemIncludeDirectories().end(); ++it) {
  662. cmGeneratorExpression ge;
  663. cmSystemTools::ExpandListArgument(
  664. ge.Parse(*it)->Evaluate(this->LocalGenerator, config, false, this,
  665. &dagChecker),
  666. result);
  667. }
  668. std::vector<cmGeneratorTarget const*> const& deps =
  669. this->GetLinkImplementationClosure(config);
  670. for (std::vector<cmGeneratorTarget const *>::const_iterator
  671. li = deps.begin(),
  672. le = deps.end();
  673. li != le; ++li) {
  674. handleSystemIncludesDep(this->LocalGenerator, *li, config, this,
  675. &dagChecker, result, excludeImported);
  676. }
  677. std::for_each(result.begin(), result.end(),
  678. cmSystemTools::ConvertToUnixSlashes);
  679. std::sort(result.begin(), result.end());
  680. result.erase(std::unique(result.begin(), result.end()), result.end());
  681. IncludeCacheType::value_type entry(config_upper, result);
  682. iter = this->SystemIncludesCache.insert(entry).first;
  683. }
  684. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  685. }
  686. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  687. {
  688. return this->Target->GetPropertyAsBool(prop);
  689. }
  690. static void AddInterfaceEntries(
  691. cmGeneratorTarget const* thisTarget, std::string const& config,
  692. std::string const& prop,
  693. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
  694. {
  695. if (cmLinkImplementationLibraries const* impl =
  696. thisTarget->GetLinkImplementationLibraries(config)) {
  697. for (std::vector<cmLinkImplItem>::const_iterator
  698. it = impl->Libraries.begin(),
  699. end = impl->Libraries.end();
  700. it != end; ++it) {
  701. if (it->Target) {
  702. std::string genex = "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
  703. cmGeneratorExpression ge(it->Backtrace);
  704. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  705. cge->SetEvaluateForBuildsystem(true);
  706. entries.push_back(
  707. new cmGeneratorTarget::TargetPropertyEntry(cge, *it));
  708. }
  709. }
  710. }
  711. }
  712. static bool processSources(
  713. cmGeneratorTarget const* tgt,
  714. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  715. std::vector<std::string>& srcs, CM_UNORDERED_SET<std::string>& uniqueSrcs,
  716. cmGeneratorExpressionDAGChecker* dagChecker, std::string const& config,
  717. bool debugSources)
  718. {
  719. cmMakefile* mf = tgt->Target->GetMakefile();
  720. bool contextDependent = false;
  721. for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
  722. it = entries.begin(),
  723. end = entries.end();
  724. it != end; ++it) {
  725. cmLinkImplItem const& item = (*it)->LinkImplItem;
  726. std::string const& targetName = item;
  727. std::vector<std::string> entrySources;
  728. cmSystemTools::ExpandListArgument(
  729. (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, tgt,
  730. dagChecker),
  731. entrySources);
  732. if ((*it)->ge->GetHadContextSensitiveCondition()) {
  733. contextDependent = true;
  734. }
  735. for (std::vector<std::string>::iterator i = entrySources.begin();
  736. i != entrySources.end(); ++i) {
  737. std::string& src = *i;
  738. cmSourceFile* sf = mf->GetOrCreateSource(src);
  739. std::string e;
  740. std::string fullPath = sf->GetFullPath(&e);
  741. if (fullPath.empty()) {
  742. if (!e.empty()) {
  743. cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance();
  744. cm->IssueMessage(cmake::FATAL_ERROR, e, tgt->GetBacktrace());
  745. }
  746. return contextDependent;
  747. }
  748. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str())) {
  749. std::ostringstream err;
  750. if (!targetName.empty()) {
  751. err << "Target \"" << targetName
  752. << "\" contains relative "
  753. "path in its INTERFACE_SOURCES:\n"
  754. " \""
  755. << src << "\"";
  756. } else {
  757. err << "Found relative path while evaluating sources of "
  758. "\""
  759. << tgt->GetName() << "\":\n \"" << src << "\"\n";
  760. }
  761. tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, err.str());
  762. return contextDependent;
  763. }
  764. src = fullPath;
  765. }
  766. std::string usedSources;
  767. for (std::vector<std::string>::iterator li = entrySources.begin();
  768. li != entrySources.end(); ++li) {
  769. std::string src = *li;
  770. if (uniqueSrcs.insert(src).second) {
  771. srcs.push_back(src);
  772. if (debugSources) {
  773. usedSources += " * " + src + "\n";
  774. }
  775. }
  776. }
  777. if (!usedSources.empty()) {
  778. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  779. cmake::LOG, std::string("Used sources for target ") + tgt->GetName() +
  780. ":\n" + usedSources,
  781. (*it)->ge->GetBacktrace());
  782. }
  783. }
  784. return contextDependent;
  785. }
  786. void cmGeneratorTarget::GetSourceFiles(std::vector<std::string>& files,
  787. const std::string& config) const
  788. {
  789. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  790. if (!this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  791. // At configure-time, this method can be called as part of getting the
  792. // LOCATION property or to export() a file to be include()d. However
  793. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  794. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  795. // behavior of CMP0024 and CMP0026 only.
  796. cmStringRange sourceEntries = this->Target->GetSourceEntries();
  797. for (cmStringRange::const_iterator i = sourceEntries.begin();
  798. i != sourceEntries.end(); ++i) {
  799. std::string const& entry = *i;
  800. std::vector<std::string> items;
  801. cmSystemTools::ExpandListArgument(entry, items);
  802. for (std::vector<std::string>::const_iterator li = items.begin();
  803. li != items.end(); ++li) {
  804. if (cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  805. (*li)[li->size() - 1] == '>') {
  806. continue;
  807. }
  808. files.push_back(*li);
  809. }
  810. }
  811. return;
  812. }
  813. std::vector<std::string> debugProperties;
  814. const char* debugProp =
  815. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  816. if (debugProp) {
  817. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  818. }
  819. bool debugSources = !this->DebugSourcesDone &&
  820. std::find(debugProperties.begin(), debugProperties.end(), "SOURCES") !=
  821. debugProperties.end();
  822. if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  823. this->DebugSourcesDone = true;
  824. }
  825. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), "SOURCES",
  826. CM_NULLPTR, CM_NULLPTR);
  827. CM_UNORDERED_SET<std::string> uniqueSrcs;
  828. bool contextDependentDirectSources =
  829. processSources(this, this->SourceEntries, files, uniqueSrcs, &dagChecker,
  830. config, debugSources);
  831. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  832. linkInterfaceSourcesEntries;
  833. AddInterfaceEntries(this, config, "INTERFACE_SOURCES",
  834. linkInterfaceSourcesEntries);
  835. std::vector<std::string>::size_type numFilesBefore = files.size();
  836. bool contextDependentInterfaceSources =
  837. processSources(this, linkInterfaceSourcesEntries, files, uniqueSrcs,
  838. &dagChecker, config, debugSources);
  839. if (!contextDependentDirectSources &&
  840. !(contextDependentInterfaceSources && numFilesBefore < files.size())) {
  841. this->LinkImplementationLanguageIsContextDependent = false;
  842. }
  843. cmDeleteAll(linkInterfaceSourcesEntries);
  844. }
  845. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*>& files,
  846. const std::string& config) const
  847. {
  848. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  849. // Since we are still configuring not all sources may exist yet,
  850. // so we need to avoid full source classification because that
  851. // requires the absolute paths to all sources to be determined.
  852. // Since this is only for compatibility with old policies that
  853. // projects should not depend on anymore, just compute the files
  854. // without memoizing them.
  855. std::vector<std::string> srcs;
  856. this->GetSourceFiles(srcs, config);
  857. std::set<cmSourceFile*> emitted;
  858. for (std::vector<std::string>::const_iterator i = srcs.begin();
  859. i != srcs.end(); ++i) {
  860. cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
  861. if (emitted.insert(sf).second) {
  862. files.push_back(sf);
  863. }
  864. }
  865. return;
  866. }
  867. KindedSources const& kinded = this->GetKindedSources(config);
  868. files.reserve(kinded.Sources.size());
  869. for (std::vector<SourceAndKind>::const_iterator si = kinded.Sources.begin();
  870. si != kinded.Sources.end(); ++si) {
  871. files.push_back(si->Source);
  872. }
  873. }
  874. void cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
  875. std::vector<cmSourceFile*>& files, const std::string& config) const
  876. {
  877. KindedSources const& kinded = this->GetKindedSources(config);
  878. files.reserve(kinded.Sources.size());
  879. for (std::vector<SourceAndKind>::const_iterator si = kinded.Sources.begin();
  880. si != kinded.Sources.end(); ++si) {
  881. if (si->Source->GetObjectLibrary().empty()) {
  882. files.push_back(si->Source);
  883. }
  884. }
  885. }
  886. cmGeneratorTarget::KindedSources const& cmGeneratorTarget::GetKindedSources(
  887. std::string const& config) const
  888. {
  889. // If we already processed one configuration and found no dependenc
  890. // on configuration then always use the one result.
  891. if (!this->LinkImplementationLanguageIsContextDependent) {
  892. return this->KindedSourcesMap.begin()->second;
  893. }
  894. // Lookup any existing link implementation for this configuration.
  895. std::string const key = cmSystemTools::UpperCase(config);
  896. KindedSourcesMapType::iterator it = this->KindedSourcesMap.find(key);
  897. if (it != this->KindedSourcesMap.end()) {
  898. return it->second;
  899. }
  900. // Add an entry to the map for this configuration.
  901. KindedSources& files = this->KindedSourcesMap[key];
  902. this->ComputeKindedSources(files, config);
  903. return files;
  904. }
  905. void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
  906. std::string const& config) const
  907. {
  908. // Get the source file paths by string.
  909. std::vector<std::string> srcs;
  910. this->GetSourceFiles(srcs, config);
  911. cmsys::RegularExpression header_regex(CM_HEADER_REGEX);
  912. std::vector<cmSourceFile*> badObjLib;
  913. std::set<cmSourceFile*> emitted;
  914. for (std::vector<std::string>::const_iterator i = srcs.begin();
  915. i != srcs.end(); ++i) {
  916. // Create each source at most once.
  917. cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
  918. if (!emitted.insert(sf).second) {
  919. continue;
  920. }
  921. // Compute the kind (classification) of this source file.
  922. SourceKind kind;
  923. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  924. if (sf->GetCustomCommand()) {
  925. kind = SourceKindCustomCommand;
  926. } else if (this->Target->GetType() == cmStateEnums::UTILITY) {
  927. kind = SourceKindExtra;
  928. } else if (sf->GetPropertyAsBool("HEADER_FILE_ONLY")) {
  929. kind = SourceKindHeader;
  930. } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  931. kind = SourceKindExternalObject;
  932. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  933. badObjLib.push_back(sf);
  934. }
  935. } else if (!sf->GetLanguage().empty()) {
  936. kind = SourceKindObjectSource;
  937. } else if (ext == "def") {
  938. kind = SourceKindModuleDefinition;
  939. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  940. badObjLib.push_back(sf);
  941. }
  942. } else if (ext == "idl") {
  943. kind = SourceKindIDL;
  944. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  945. badObjLib.push_back(sf);
  946. }
  947. } else if (ext == "resx") {
  948. kind = SourceKindResx;
  949. // Build and save the name of the corresponding .h file
  950. // This relationship will be used later when building the project files.
  951. // Both names would have been auto generated from Visual Studio
  952. // where the user supplied the file name and Visual Studio
  953. // appended the suffix.
  954. std::string resx = sf->GetFullPath();
  955. std::string hFileName = resx.substr(0, resx.find_last_of('.')) + ".h";
  956. files.ExpectedResxHeaders.insert(hFileName);
  957. } else if (ext == "appxmanifest") {
  958. kind = SourceKindAppManifest;
  959. } else if (ext == "manifest") {
  960. kind = SourceKindManifest;
  961. } else if (ext == "pfx") {
  962. kind = SourceKindCertificate;
  963. } else if (ext == "xaml") {
  964. kind = SourceKindXaml;
  965. // Build and save the name of the corresponding .h and .cpp file
  966. // This relationship will be used later when building the project files.
  967. // Both names would have been auto generated from Visual Studio
  968. // where the user supplied the file name and Visual Studio
  969. // appended the suffix.
  970. std::string xaml = sf->GetFullPath();
  971. std::string hFileName = xaml + ".h";
  972. std::string cppFileName = xaml + ".cpp";
  973. files.ExpectedXamlHeaders.insert(hFileName);
  974. files.ExpectedXamlSources.insert(cppFileName);
  975. } else if (header_regex.find(sf->GetFullPath().c_str())) {
  976. kind = SourceKindHeader;
  977. } else {
  978. kind = SourceKindExtra;
  979. }
  980. // Save this classified source file in the result vector.
  981. SourceAndKind entry = { sf, kind };
  982. files.Sources.push_back(entry);
  983. }
  984. if (!badObjLib.empty()) {
  985. std::ostringstream e;
  986. e << "OBJECT library \"" << this->GetName() << "\" contains:\n";
  987. for (std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
  988. i != badObjLib.end(); ++i) {
  989. e << " " << (*i)->GetLocation().GetName() << "\n";
  990. }
  991. e << "but may contain only sources that compile, header files, and "
  992. "other files that would not affect linking of a normal library.";
  993. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
  994. cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  995. }
  996. }
  997. std::vector<cmGeneratorTarget::AllConfigSource> const&
  998. cmGeneratorTarget::GetAllConfigSources() const
  999. {
  1000. if (this->AllConfigSources.empty()) {
  1001. this->ComputeAllConfigSources();
  1002. }
  1003. return this->AllConfigSources;
  1004. }
  1005. void cmGeneratorTarget::ComputeAllConfigSources() const
  1006. {
  1007. std::vector<std::string> configs;
  1008. this->Makefile->GetConfigurations(configs);
  1009. std::map<cmSourceFile const*, size_t> index;
  1010. for (size_t ci = 0; ci < configs.size(); ++ci) {
  1011. KindedSources const& sources = this->GetKindedSources(configs[ci]);
  1012. for (std::vector<cmGeneratorTarget::SourceAndKind>::const_iterator si =
  1013. sources.Sources.begin();
  1014. si != sources.Sources.end(); ++si) {
  1015. std::map<cmSourceFile const*, size_t>::iterator mi =
  1016. index.find(si->Source);
  1017. if (mi == index.end()) {
  1018. AllConfigSource acs;
  1019. acs.Source = si->Source;
  1020. acs.Kind = si->Kind;
  1021. this->AllConfigSources.push_back(acs);
  1022. std::map<cmSourceFile const*, size_t>::value_type entry(
  1023. si->Source, this->AllConfigSources.size() - 1);
  1024. mi = index.insert(entry).first;
  1025. }
  1026. this->AllConfigSources[mi->second].Configs.push_back(ci);
  1027. }
  1028. }
  1029. }
  1030. std::string cmGeneratorTarget::GetCompilePDBName(
  1031. const std::string& config) const
  1032. {
  1033. std::string prefix;
  1034. std::string base;
  1035. std::string suffix;
  1036. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  1037. prefix, base, suffix);
  1038. // Check for a per-configuration output directory target property.
  1039. std::string configUpper = cmSystemTools::UpperCase(config);
  1040. std::string configProp = "COMPILE_PDB_NAME_";
  1041. configProp += configUpper;
  1042. const char* config_name = this->GetProperty(configProp);
  1043. if (config_name && *config_name) {
  1044. return prefix + config_name + ".pdb";
  1045. }
  1046. const char* name = this->GetProperty("COMPILE_PDB_NAME");
  1047. if (name && *name) {
  1048. return prefix + name + ".pdb";
  1049. }
  1050. return "";
  1051. }
  1052. std::string cmGeneratorTarget::GetCompilePDBPath(
  1053. const std::string& config) const
  1054. {
  1055. std::string dir = this->GetCompilePDBDirectory(config);
  1056. std::string name = this->GetCompilePDBName(config);
  1057. if (dir.empty() && !name.empty() && this->HaveWellDefinedOutputFiles()) {
  1058. dir = this->GetPDBDirectory(config);
  1059. }
  1060. if (!dir.empty()) {
  1061. dir += "/";
  1062. }
  1063. return dir + name;
  1064. }
  1065. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  1066. {
  1067. // soname is supported only for shared libraries and modules,
  1068. // and then only when the platform supports an soname flag.
  1069. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY) &&
  1070. !this->GetPropertyAsBool("NO_SONAME") &&
  1071. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  1072. }
  1073. bool cmGeneratorTarget::NeedRelinkBeforeInstall(
  1074. const std::string& config) const
  1075. {
  1076. // Only executables and shared libraries can have an rpath and may
  1077. // need relinking.
  1078. if (this->GetType() != cmStateEnums::EXECUTABLE &&
  1079. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1080. this->GetType() != cmStateEnums::MODULE_LIBRARY) {
  1081. return false;
  1082. }
  1083. // If there is no install location this target will not be installed
  1084. // and therefore does not need relinking.
  1085. if (!this->Target->GetHaveInstallRule()) {
  1086. return false;
  1087. }
  1088. // If skipping all rpaths completely then no relinking is needed.
  1089. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1090. return false;
  1091. }
  1092. // If building with the install-tree rpath no relinking is needed.
  1093. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1094. return false;
  1095. }
  1096. // If chrpath is going to be used no relinking is needed.
  1097. if (this->IsChrpathUsed(config)) {
  1098. return false;
  1099. }
  1100. // Check for rpath support on this platform.
  1101. std::string ll = this->GetLinkerLanguage(config);
  1102. if (!ll.empty()) {
  1103. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1104. flagVar += ll;
  1105. flagVar += "_FLAG";
  1106. if (!this->Makefile->IsSet(flagVar)) {
  1107. // There is no rpath support on this platform so nothing needs
  1108. // relinking.
  1109. return false;
  1110. }
  1111. } else {
  1112. // No linker language is known. This error will be reported by
  1113. // other code.
  1114. return false;
  1115. }
  1116. // If either a build or install tree rpath is set then the rpath
  1117. // will likely change between the build tree and install tree and
  1118. // this target must be relinked.
  1119. bool have_rpath =
  1120. this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
  1121. bool is_ninja =
  1122. this->LocalGenerator->GetGlobalGenerator()->GetName() == "Ninja";
  1123. if (have_rpath && is_ninja) {
  1124. std::ostringstream w;
  1125. /* clang-format off */
  1126. w <<
  1127. "The install of the " << this->GetName() << " target requires "
  1128. "changing an RPATH from the build tree, but this is not supported "
  1129. "with the Ninja generator unless on an ELF-based platform. The "
  1130. "CMAKE_BUILD_WITH_INSTALL_RPATH variable may be set to avoid this "
  1131. "relinking step."
  1132. ;
  1133. /* clang-format on */
  1134. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1135. cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
  1136. }
  1137. return have_rpath;
  1138. }
  1139. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  1140. {
  1141. // Only certain target types have an rpath.
  1142. if (!(this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1143. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1144. this->GetType() == cmStateEnums::EXECUTABLE)) {
  1145. return false;
  1146. }
  1147. // If the target will not be installed we do not need to change its
  1148. // rpath.
  1149. if (!this->Target->GetHaveInstallRule()) {
  1150. return false;
  1151. }
  1152. // Skip chrpath if skipping rpath altogether.
  1153. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1154. return false;
  1155. }
  1156. // Skip chrpath if it does not need to be changed at install time.
  1157. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1158. return false;
  1159. }
  1160. // Allow the user to disable builtin chrpath explicitly.
  1161. if (this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH")) {
  1162. return false;
  1163. }
  1164. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1165. return true;
  1166. }
  1167. #if defined(CMAKE_USE_ELF_PARSER)
  1168. // Enable if the rpath flag uses a separator and the target uses ELF
  1169. // binaries.
  1170. std::string ll = this->GetLinkerLanguage(config);
  1171. if (!ll.empty()) {
  1172. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1173. sepVar += ll;
  1174. sepVar += "_FLAG_SEP";
  1175. const char* sep = this->Makefile->GetDefinition(sepVar);
  1176. if (sep && *sep) {
  1177. // TODO: Add ELF check to ABI detection and get rid of
  1178. // CMAKE_EXECUTABLE_FORMAT.
  1179. if (const char* fmt =
  1180. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT")) {
  1181. return strcmp(fmt, "ELF") == 0;
  1182. }
  1183. }
  1184. }
  1185. #endif
  1186. static_cast<void>(config);
  1187. return false;
  1188. }
  1189. bool cmGeneratorTarget::IsImportedSharedLibWithoutSOName(
  1190. const std::string& config) const
  1191. {
  1192. if (this->IsImported() && this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  1193. if (cmGeneratorTarget::ImportInfo const* info =
  1194. this->GetImportInfo(config)) {
  1195. return info->NoSOName;
  1196. }
  1197. }
  1198. return false;
  1199. }
  1200. bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir(
  1201. const std::string& config) const
  1202. {
  1203. bool install_name_is_rpath = false;
  1204. bool macosx_rpath = false;
  1205. if (!this->IsImported()) {
  1206. if (this->GetType() != cmStateEnums::SHARED_LIBRARY) {
  1207. return false;
  1208. }
  1209. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  1210. bool use_install_name = this->MacOSXUseInstallNameDir();
  1211. if (install_name && use_install_name &&
  1212. std::string(install_name) == "@rpath") {
  1213. install_name_is_rpath = true;
  1214. } else if (install_name && use_install_name) {
  1215. return false;
  1216. }
  1217. if (!install_name_is_rpath) {
  1218. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  1219. }
  1220. } else {
  1221. // Lookup the imported soname.
  1222. if (cmGeneratorTarget::ImportInfo const* info =
  1223. this->GetImportInfo(config)) {
  1224. if (!info->NoSOName && !info->SOName.empty()) {
  1225. if (info->SOName.find("@rpath/") == 0) {
  1226. install_name_is_rpath = true;
  1227. }
  1228. } else {
  1229. std::string install_name;
  1230. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  1231. if (install_name.find("@rpath") != std::string::npos) {
  1232. install_name_is_rpath = true;
  1233. }
  1234. }
  1235. }
  1236. }
  1237. if (!install_name_is_rpath && !macosx_rpath) {
  1238. return false;
  1239. }
  1240. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  1241. std::ostringstream w;
  1242. w << "Attempting to use ";
  1243. if (macosx_rpath) {
  1244. w << "MACOSX_RPATH";
  1245. } else {
  1246. w << "@rpath";
  1247. }
  1248. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  1249. w << " This could be because you are using a Mac OS X version";
  1250. w << " less than 10.5 or because CMake's platform configuration is";
  1251. w << " corrupt.";
  1252. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1253. cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
  1254. }
  1255. return true;
  1256. }
  1257. bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const
  1258. {
  1259. // we can't do rpaths when unsupported
  1260. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  1261. return false;
  1262. }
  1263. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  1264. if (macosx_rpath_str) {
  1265. return this->GetPropertyAsBool("MACOSX_RPATH");
  1266. }
  1267. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  1268. if (cmp0042 == cmPolicies::WARN) {
  1269. this->LocalGenerator->GetGlobalGenerator()->AddCMP0042WarnTarget(
  1270. this->GetName());
  1271. }
  1272. return cmp0042 == cmPolicies::NEW;
  1273. }
  1274. bool cmGeneratorTarget::MacOSXUseInstallNameDir() const
  1275. {
  1276. const char* build_with_install_name =
  1277. this->GetProperty("BUILD_WITH_INSTALL_NAME_DIR");
  1278. if (build_with_install_name) {
  1279. return cmSystemTools::IsOn(build_with_install_name);
  1280. }
  1281. cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068();
  1282. if (cmp0068 == cmPolicies::NEW) {
  1283. return false;
  1284. }
  1285. bool use_install_name = this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  1286. if (use_install_name && cmp0068 == cmPolicies::WARN) {
  1287. this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget(
  1288. this->GetName());
  1289. }
  1290. return use_install_name;
  1291. }
  1292. bool cmGeneratorTarget::CanGenerateInstallNameDir(
  1293. InstallNameType name_type) const
  1294. {
  1295. cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068();
  1296. if (cmp0068 == cmPolicies::NEW) {
  1297. return true;
  1298. }
  1299. bool skip = this->Makefile->IsOn("CMAKE_SKIP_RPATH");
  1300. if (name_type == INSTALL_NAME_FOR_INSTALL) {
  1301. skip |= this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  1302. } else {
  1303. skip |= this->GetPropertyAsBool("SKIP_BUILD_RPATH");
  1304. }
  1305. if (skip && cmp0068 == cmPolicies::WARN) {
  1306. this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget(
  1307. this->GetName());
  1308. }
  1309. return !skip;
  1310. }
  1311. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  1312. {
  1313. if (this->IsImported()) {
  1314. // Lookup the imported soname.
  1315. if (cmGeneratorTarget::ImportInfo const* info =
  1316. this->GetImportInfo(config)) {
  1317. if (info->NoSOName) {
  1318. // The imported library has no builtin soname so the name
  1319. // searched at runtime will be just the filename.
  1320. return cmSystemTools::GetFilenameName(info->Location);
  1321. }
  1322. // Use the soname given if any.
  1323. if (info->SOName.find("@rpath/") == 0) {
  1324. return info->SOName.substr(6);
  1325. }
  1326. return info->SOName;
  1327. }
  1328. return "";
  1329. }
  1330. // Compute the soname that will be built.
  1331. std::string name;
  1332. std::string soName;
  1333. std::string realName;
  1334. std::string impName;
  1335. std::string pdbName;
  1336. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  1337. return soName;
  1338. }
  1339. static bool shouldAddFullLevel(cmGeneratorTarget::BundleDirectoryLevel level)
  1340. {
  1341. return level == cmGeneratorTarget::FullLevel;
  1342. }
  1343. static bool shouldAddContentLevel(
  1344. cmGeneratorTarget::BundleDirectoryLevel level)
  1345. {
  1346. return level == cmGeneratorTarget::ContentLevel || shouldAddFullLevel(level);
  1347. }
  1348. std::string cmGeneratorTarget::GetAppBundleDirectory(
  1349. const std::string& config, BundleDirectoryLevel level) const
  1350. {
  1351. std::string fpath =
  1352. this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact);
  1353. fpath += ".";
  1354. const char* ext = this->GetProperty("BUNDLE_EXTENSION");
  1355. if (!ext) {
  1356. ext = "app";
  1357. }
  1358. fpath += ext;
  1359. if (shouldAddContentLevel(level) && !this->Makefile->PlatformIsAppleIos()) {
  1360. fpath += "/Contents";
  1361. if (shouldAddFullLevel(level)) {
  1362. fpath += "/MacOS";
  1363. }
  1364. }
  1365. return fpath;
  1366. }
  1367. bool cmGeneratorTarget::IsBundleOnApple() const
  1368. {
  1369. return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
  1370. this->IsCFBundleOnApple();
  1371. }
  1372. std::string cmGeneratorTarget::GetCFBundleDirectory(
  1373. const std::string& config, BundleDirectoryLevel level) const
  1374. {
  1375. std::string fpath;
  1376. fpath += this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact);
  1377. fpath += ".";
  1378. const char* ext = this->GetProperty("BUNDLE_EXTENSION");
  1379. if (!ext) {
  1380. if (this->IsXCTestOnApple()) {
  1381. ext = "xctest";
  1382. } else {
  1383. ext = "bundle";
  1384. }
  1385. }
  1386. fpath += ext;
  1387. if (shouldAddContentLevel(level) && !this->Makefile->PlatformIsAppleIos()) {
  1388. fpath += "/Contents";
  1389. if (shouldAddFullLevel(level)) {
  1390. fpath += "/MacOS";
  1391. }
  1392. }
  1393. return fpath;
  1394. }
  1395. std::string cmGeneratorTarget::GetFrameworkDirectory(
  1396. const std::string& config, BundleDirectoryLevel level) const
  1397. {
  1398. std::string fpath;
  1399. fpath += this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact);
  1400. fpath += ".";
  1401. const char* ext = this->GetProperty("BUNDLE_EXTENSION");
  1402. if (!ext) {
  1403. ext = "framework";
  1404. }
  1405. fpath += ext;
  1406. if (shouldAddFullLevel(level) && !this->Makefile->PlatformIsAppleIos()) {
  1407. fpath += "/Versions/";
  1408. fpath += this->GetFrameworkVersion();
  1409. }
  1410. return fpath;
  1411. }
  1412. std::string cmGeneratorTarget::GetFullName(
  1413. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1414. {
  1415. if (this->IsImported()) {
  1416. return this->GetFullNameImported(config, artifact);
  1417. }
  1418. return this->GetFullNameInternal(config, artifact);
  1419. }
  1420. std::string cmGeneratorTarget::GetInstallNameDirForBuildTree(
  1421. const std::string& config) const
  1422. {
  1423. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1424. // If building directly for installation then the build tree install_name
  1425. // is the same as the install tree.
  1426. if (this->MacOSXUseInstallNameDir()) {
  1427. return this->GetInstallNameDirForInstallTree();
  1428. }
  1429. // Use the build tree directory for the target.
  1430. if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_BUILD)) {
  1431. std::string dir;
  1432. if (this->MacOSXRpathInstallNameDirDefault()) {
  1433. dir = "@rpath";
  1434. } else {
  1435. dir = this->GetDirectory(config);
  1436. }
  1437. dir += "/";
  1438. return dir;
  1439. }
  1440. }
  1441. return "";
  1442. }
  1443. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
  1444. {
  1445. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1446. std::string dir;
  1447. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  1448. if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_INSTALL)) {
  1449. if (install_name_dir && *install_name_dir) {
  1450. dir = install_name_dir;
  1451. dir += "/";
  1452. }
  1453. }
  1454. if (!install_name_dir) {
  1455. if (this->MacOSXRpathInstallNameDirDefault()) {
  1456. dir = "@rpath/";
  1457. }
  1458. }
  1459. return dir;
  1460. }
  1461. return "";
  1462. }
  1463. cmListFileBacktrace cmGeneratorTarget::GetBacktrace() const
  1464. {
  1465. return this->Target->GetBacktrace();
  1466. }
  1467. const std::vector<std::string>& cmGeneratorTarget::GetLinkDirectories() const
  1468. {
  1469. return this->Target->GetLinkDirectories();
  1470. }
  1471. const std::set<std::string>& cmGeneratorTarget::GetUtilities() const
  1472. {
  1473. return this->Target->GetUtilities();
  1474. }
  1475. const cmListFileBacktrace* cmGeneratorTarget::GetUtilityBacktrace(
  1476. const std::string& u) const
  1477. {
  1478. return this->Target->GetUtilityBacktrace(u);
  1479. }
  1480. bool cmGeneratorTarget::HaveWellDefinedOutputFiles() const
  1481. {
  1482. return this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  1483. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1484. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1485. this->GetType() == cmStateEnums::EXECUTABLE;
  1486. }
  1487. const char* cmGeneratorTarget::GetExportMacro() const
  1488. {
  1489. // Define the symbol for targets that export symbols.
  1490. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1491. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1492. this->IsExecutableWithExports()) {
  1493. if (const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL")) {
  1494. this->ExportMacro = custom_export_name;
  1495. } else {
  1496. std::string in = this->GetName();
  1497. in += "_EXPORTS";
  1498. this->ExportMacro = cmSystemTools::MakeCidentifier(in);
  1499. }
  1500. return this->ExportMacro.c_str();
  1501. }
  1502. return CM_NULLPTR;
  1503. }
  1504. class cmTargetCollectLinkLanguages
  1505. {
  1506. public:
  1507. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  1508. const std::string& config,
  1509. CM_UNORDERED_SET<std::string>& languages,
  1510. cmGeneratorTarget const* head)
  1511. : Config(config)
  1512. , Languages(languages)
  1513. , HeadTarget(head)
  1514. , Target(target)
  1515. {
  1516. this->Visited.insert(target);
  1517. }
  1518. void Visit(cmLinkItem const& item)
  1519. {
  1520. if (!item.Target) {
  1521. if (item.find("::") != std::string::npos) {
  1522. bool noMessage = false;
  1523. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1524. std::ostringstream e;
  1525. switch (this->Target->GetLocalGenerator()->GetPolicyStatus(
  1526. cmPolicies::CMP0028)) {
  1527. case cmPolicies::WARN: {
  1528. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  1529. messageType = cmake::AUTHOR_WARNING;
  1530. } break;
  1531. case cmPolicies::OLD:
  1532. noMessage = true;
  1533. case cmPolicies::REQUIRED_IF_USED:
  1534. case cmPolicies::REQUIRED_ALWAYS:
  1535. case cmPolicies::NEW:
  1536. // Issue the fatal message.
  1537. break;
  1538. }
  1539. if (!noMessage) {
  1540. e << "Target \"" << this->Target->GetName()
  1541. << "\" links to target \"" << item
  1542. << "\" but the target was not found. Perhaps a find_package() "
  1543. "call is missing for an IMPORTED target, or an ALIAS target is "
  1544. "missing?";
  1545. this->Target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1546. messageType, e.str(), this->Target->GetBacktrace());
  1547. }
  1548. }
  1549. return;
  1550. }
  1551. if (!this->Visited.insert(item.Target).second) {
  1552. return;
  1553. }
  1554. cmLinkInterface const* iface =
  1555. item.Target->GetLinkInterface(this->Config, this->HeadTarget);
  1556. if (!iface) {
  1557. return;
  1558. }
  1559. for (std::vector<std::string>::const_iterator li =
  1560. iface->Languages.begin();
  1561. li != iface->Languages.end(); ++li) {
  1562. this->Languages.insert(*li);
  1563. }
  1564. for (std::vector<cmLinkItem>::const_iterator li = iface->Libraries.begin();
  1565. li != iface->Libraries.end(); ++li) {
  1566. this->Visit(*li);
  1567. }
  1568. }
  1569. private:
  1570. std::string Config;
  1571. CM_UNORDERED_SET<std::string>& Languages;
  1572. cmGeneratorTarget const* HeadTarget;
  1573. const cmGeneratorTarget* Target;
  1574. std::set<cmGeneratorTarget const*> Visited;
  1575. };
  1576. cmGeneratorTarget::LinkClosure const* cmGeneratorTarget::GetLinkClosure(
  1577. const std::string& config) const
  1578. {
  1579. std::string key(cmSystemTools::UpperCase(config));
  1580. LinkClosureMapType::iterator i = this->LinkClosureMap.find(key);
  1581. if (i == this->LinkClosureMap.end()) {
  1582. LinkClosure lc;
  1583. this->ComputeLinkClosure(config, lc);
  1584. LinkClosureMapType::value_type entry(key, lc);
  1585. i = this->LinkClosureMap.insert(entry).first;
  1586. }
  1587. return &i->second;
  1588. }
  1589. class cmTargetSelectLinker
  1590. {
  1591. int Preference;
  1592. cmGeneratorTarget const* Target;
  1593. cmGlobalGenerator* GG;
  1594. std::set<std::string> Preferred;
  1595. public:
  1596. cmTargetSelectLinker(cmGeneratorTarget const* target)
  1597. : Preference(0)
  1598. , Target(target)
  1599. {
  1600. this->GG = this->Target->GetLocalGenerator()->GetGlobalGenerator();
  1601. }
  1602. void Consider(const char* lang)
  1603. {
  1604. int preference = this->GG->GetLinkerPreference(lang);
  1605. if (preference > this->Preference) {
  1606. this->Preference = preference;
  1607. this->Preferred.clear();
  1608. }
  1609. if (preference == this->Preference) {
  1610. this->Preferred.insert(lang);
  1611. }
  1612. }
  1613. std::string Choose()
  1614. {
  1615. if (this->Preferred.empty()) {
  1616. return "";
  1617. }
  1618. if (this->Preferred.size() > 1) {
  1619. std::ostringstream e;
  1620. e << "Target " << this->Target->GetName()
  1621. << " contains multiple languages with the highest linker preference"
  1622. << " (" << this->Preference << "):\n";
  1623. for (std::set<std::string>::const_iterator li = this->Preferred.begin();
  1624. li != this->Preferred.end(); ++li) {
  1625. e << " " << *li << "\n";
  1626. }
  1627. e << "Set the LINKER_LANGUAGE property for this target.";
  1628. cmake* cm = this->Target->GetLocalGenerator()->GetCMakeInstance();
  1629. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  1630. this->Target->GetBacktrace());
  1631. }
  1632. return *this->Preferred.begin();
  1633. }
  1634. };
  1635. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  1636. LinkClosure& lc) const
  1637. {
  1638. // Get languages built in this target.
  1639. CM_UNORDERED_SET<std::string> languages;
  1640. cmLinkImplementation const* impl = this->GetLinkImplementation(config);
  1641. assert(impl);
  1642. for (std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1643. li != impl->Languages.end(); ++li) {
  1644. languages.insert(*li);
  1645. }
  1646. // Add interface languages from linked targets.
  1647. cmTargetCollectLinkLanguages cll(this, config, languages, this);
  1648. for (std::vector<cmLinkImplItem>::const_iterator li =
  1649. impl->Libraries.begin();
  1650. li != impl->Libraries.end(); ++li) {
  1651. cll.Visit(*li);
  1652. }
  1653. // Store the transitive closure of languages.
  1654. for (CM_UNORDERED_SET<std::string>::const_iterator li = languages.begin();
  1655. li != languages.end(); ++li) {
  1656. lc.Languages.push_back(*li);
  1657. }
  1658. // Choose the language whose linker should be used.
  1659. if (this->GetProperty("HAS_CXX")) {
  1660. lc.LinkerLanguage = "CXX";
  1661. } else if (const char* linkerLang = this->GetProperty("LINKER_LANGUAGE")) {
  1662. lc.LinkerLanguage = linkerLang;
  1663. } else {
  1664. // Find the language with the highest preference value.
  1665. cmTargetSelectLinker tsl(this);
  1666. // First select from the languages compiled directly in this target.
  1667. for (std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1668. li != impl->Languages.end(); ++li) {
  1669. tsl.Consider(li->c_str());
  1670. }
  1671. // Now consider languages that propagate from linked targets.
  1672. for (CM_UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
  1673. sit != languages.end(); ++sit) {
  1674. std::string propagates =
  1675. "CMAKE_" + *sit + "_LINKER_PREFERENCE_PROPAGATES";
  1676. if (this->Makefile->IsOn(propagates)) {
  1677. tsl.Consider(sit->c_str());
  1678. }
  1679. }
  1680. lc.LinkerLanguage = tsl.Choose();
  1681. }
  1682. }
  1683. void cmGeneratorTarget::GetFullNameComponents(
  1684. std::string& prefix, std::string& base, std::string& suffix,
  1685. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1686. {
  1687. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  1688. }
  1689. std::string cmGeneratorTarget::BuildBundleDirectory(
  1690. const std::string& base, const std::string& config,
  1691. BundleDirectoryLevel level) const
  1692. {
  1693. std::string fpath = base;
  1694. if (this->IsAppBundleOnApple()) {
  1695. fpath += this->GetAppBundleDirectory(config, level);
  1696. }
  1697. if (this->IsFrameworkOnApple()) {
  1698. fpath += this->GetFrameworkDirectory(config, level);
  1699. }
  1700. if (this->IsCFBundleOnApple()) {
  1701. fpath += this->GetCFBundleDirectory(config, level);
  1702. }
  1703. return fpath;
  1704. }
  1705. std::string cmGeneratorTarget::GetMacContentDirectory(
  1706. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1707. {
  1708. // Start with the output directory for the target.
  1709. std::string fpath = this->GetDirectory(config, artifact);
  1710. fpath += "/";
  1711. BundleDirectoryLevel level = ContentLevel;
  1712. if (this->IsFrameworkOnApple()) {
  1713. // additional files with a framework go into the version specific
  1714. // directory
  1715. level = FullLevel;
  1716. }
  1717. fpath = this->BuildBundleDirectory(fpath, config, level);
  1718. return fpath;
  1719. }
  1720. std::string cmGeneratorTarget::GetEffectiveFolderName() const
  1721. {
  1722. std::string effectiveFolder;
  1723. if (!this->GlobalGenerator->UseFolderProperty()) {
  1724. return effectiveFolder;
  1725. }
  1726. const char* targetFolder = this->GetProperty("FOLDER");
  1727. if (targetFolder) {
  1728. effectiveFolder += targetFolder;
  1729. }
  1730. return effectiveFolder;
  1731. }
  1732. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  1733. const std::string& config) const
  1734. {
  1735. // There is no compile information for imported targets.
  1736. if (this->IsImported()) {
  1737. return CM_NULLPTR;
  1738. }
  1739. if (this->GetType() > cmStateEnums::OBJECT_LIBRARY) {
  1740. std::string msg = "cmTarget::GetCompileInfo called for ";
  1741. msg += this->GetName();
  1742. msg += " which has type ";
  1743. msg += cmState::GetTargetTypeName(this->GetType());
  1744. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1745. return CM_NULLPTR;
  1746. }
  1747. // Lookup/compute/cache the compile information for this configuration.
  1748. std::string config_upper;
  1749. if (!config.empty()) {
  1750. config_upper = cmSystemTools::UpperCase(config);
  1751. }
  1752. CompileInfoMapType::const_iterator i =
  1753. this->CompileInfoMap.find(config_upper);
  1754. if (i == this->CompileInfoMap.end()) {
  1755. CompileInfo info;
  1756. this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  1757. CompileInfoMapType::value_type entry(config_upper, info);
  1758. i = this->CompileInfoMap.insert(entry).first;
  1759. }
  1760. return &i->second;
  1761. }
  1762. cmGeneratorTarget::ModuleDefinitionInfo const*
  1763. cmGeneratorTarget::GetModuleDefinitionInfo(std::string const& config) const
  1764. {
  1765. // A module definition file only makes sense on certain target types.
  1766. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1767. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  1768. !this->IsExecutableWithExports()) {
  1769. return CM_NULLPTR;
  1770. }
  1771. // Lookup/compute/cache the compile information for this configuration.
  1772. std::string config_upper;
  1773. if (!config.empty()) {
  1774. config_upper = cmSystemTools::UpperCase(config);
  1775. }
  1776. ModuleDefinitionInfoMapType::const_iterator i =
  1777. this->ModuleDefinitionInfoMap.find(config_upper);
  1778. if (i == this->ModuleDefinitionInfoMap.end()) {
  1779. ModuleDefinitionInfo info;
  1780. this->ComputeModuleDefinitionInfo(config, info);
  1781. ModuleDefinitionInfoMapType::value_type entry(config_upper, info);
  1782. i = this->ModuleDefinitionInfoMap.insert(entry).first;
  1783. }
  1784. return &i->second;
  1785. }
  1786. void cmGeneratorTarget::ComputeModuleDefinitionInfo(
  1787. std::string const& config, ModuleDefinitionInfo& info) const
  1788. {
  1789. this->GetModuleDefinitionSources(info.Sources, config);
  1790. info.WindowsExportAllSymbols =
  1791. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") &&
  1792. this->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS");
  1793. info.DefFileGenerated =
  1794. info.WindowsExportAllSymbols || info.Sources.size() > 1;
  1795. if (info.DefFileGenerated) {
  1796. info.DefFile = this->ObjectDirectory /* has slash */ + "exports.def";
  1797. } else if (!info.Sources.empty()) {
  1798. info.DefFile = info.Sources.front()->GetFullPath();
  1799. }
  1800. }
  1801. bool cmGeneratorTarget::IsDLLPlatform() const
  1802. {
  1803. return this->DLLPlatform;
  1804. }
  1805. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result,
  1806. const std::string& config) const
  1807. {
  1808. const char* prop =
  1809. this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS", config);
  1810. if (!prop) {
  1811. return;
  1812. }
  1813. cmGeneratorExpression ge;
  1814. cmGeneratorExpressionDAGChecker dagChecker(
  1815. this->GetName(), "AUTOUIC_OPTIONS", CM_NULLPTR, CM_NULLPTR);
  1816. cmSystemTools::ExpandListArgument(
  1817. ge.Parse(prop)->Evaluate(this->LocalGenerator, config, false, this,
  1818. &dagChecker),
  1819. result);
  1820. }
  1821. void processILibs(const std::string& config,
  1822. cmGeneratorTarget const* headTarget, cmLinkItem const& item,
  1823. cmGlobalGenerator* gg,
  1824. std::vector<cmGeneratorTarget const*>& tgts,
  1825. std::set<cmGeneratorTarget const*>& emitted)
  1826. {
  1827. if (item.Target && emitted.insert(item.Target).second) {
  1828. tgts.push_back(item.Target);
  1829. if (cmLinkInterfaceLibraries const* iface =
  1830. item.Target->GetLinkInterfaceLibraries(config, headTarget, true)) {
  1831. for (std::vector<cmLinkItem>::const_iterator it =
  1832. iface->Libraries.begin();
  1833. it != iface->Libraries.end(); ++it) {
  1834. processILibs(config, headTarget, *it, gg, tgts, emitted);
  1835. }
  1836. }
  1837. }
  1838. }
  1839. const std::vector<const cmGeneratorTarget*>&
  1840. cmGeneratorTarget::GetLinkImplementationClosure(
  1841. const std::string& config) const
  1842. {
  1843. LinkImplClosure& tgts = this->LinkImplClosureMap[config];
  1844. if (!tgts.Done) {
  1845. tgts.Done = true;
  1846. std::set<cmGeneratorTarget const*> emitted;
  1847. cmLinkImplementationLibraries const* impl =
  1848. this->GetLinkImplementationLibraries(config);
  1849. for (std::vector<cmLinkImplItem>::const_iterator it =
  1850. impl->Libraries.begin();
  1851. it != impl->Libraries.end(); ++it) {
  1852. processILibs(config, this, *it,
  1853. this->LocalGenerator->GetGlobalGenerator(), tgts, emitted);
  1854. }
  1855. }
  1856. return tgts;
  1857. }
  1858. class cmTargetTraceDependencies
  1859. {
  1860. public:
  1861. cmTargetTraceDependencies(cmGeneratorTarget* target);
  1862. void Trace();
  1863. private:
  1864. cmGeneratorTarget* GeneratorTarget;
  1865. cmMakefile* Makefile;
  1866. cmLocalGenerator* LocalGenerator;
  1867. cmGlobalGenerator const* GlobalGenerator;
  1868. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  1869. SourceEntry* CurrentEntry;
  1870. std::queue<cmSourceFile*> SourceQueue;
  1871. std::set<cmSourceFile*> SourcesQueued;
  1872. typedef std::map<std::string, cmSourceFile*> NameMapType;
  1873. NameMapType NameMap;
  1874. std::vector<std::string> NewSources;
  1875. void QueueSource(cmSourceFile* sf);
  1876. void FollowName(std::string const& name);
  1877. void FollowNames(std::vector<std::string> const& names);
  1878. bool IsUtility(std::string const& dep);
  1879. void CheckCustomCommand(cmCustomCommand const& cc);
  1880. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1881. void FollowCommandDepends(cmCustomCommand const& cc,
  1882. const std::string& config,
  1883. std::set<std::string>& emitted);
  1884. };
  1885. cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target)
  1886. : GeneratorTarget(target)
  1887. {
  1888. // Convenience.
  1889. this->Makefile = target->Target->GetMakefile();
  1890. this->LocalGenerator = target->GetLocalGenerator();
  1891. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  1892. this->CurrentEntry = CM_NULLPTR;
  1893. // Queue all the source files already specified for the target.
  1894. if (target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1895. std::vector<std::string> configs;
  1896. this->Makefile->GetConfigurations(configs);
  1897. if (configs.empty()) {
  1898. configs.push_back("");
  1899. }
  1900. std::set<cmSourceFile*> emitted;
  1901. for (std::vector<std::string>::const_iterator ci = configs.begin();
  1902. ci != configs.end(); ++ci) {
  1903. std::vector<cmSourceFile*> sources;
  1904. this->GeneratorTarget->GetSourceFiles(sources, *ci);
  1905. for (std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1906. si != sources.end(); ++si) {
  1907. cmSourceFile* sf = *si;
  1908. const std::set<cmGeneratorTarget const*> tgts =
  1909. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  1910. if (tgts.find(this->GeneratorTarget) != tgts.end()) {
  1911. std::ostringstream e;
  1912. e << "Evaluation output file\n \"" << sf->GetFullPath()
  1913. << "\"\ndepends on the sources of a target it is used in. This "
  1914. "is a dependency loop and is not allowed.";
  1915. this->GeneratorTarget->LocalGenerator->IssueMessage(
  1916. cmake::FATAL_ERROR, e.str());
  1917. return;
  1918. }
  1919. if (emitted.insert(sf).second &&
  1920. this->SourcesQueued.insert(sf).second) {
  1921. this->SourceQueue.push(sf);
  1922. }
  1923. }
  1924. }
  1925. }
  1926. // Queue pre-build, pre-link, and post-build rule dependencies.
  1927. this->CheckCustomCommands(this->GeneratorTarget->GetPreBuildCommands());
  1928. this->CheckCustomCommands(this->GeneratorTarget->GetPreLinkCommands());
  1929. this->CheckCustomCommands(this->GeneratorTarget->GetPostBuildCommands());
  1930. }
  1931. void cmTargetTraceDependencies::Trace()
  1932. {
  1933. // Process one dependency at a time until the queue is empty.
  1934. while (!this->SourceQueue.empty()) {
  1935. // Get the next source from the queue.
  1936. cmSourceFile* sf = this->SourceQueue.front();
  1937. this->SourceQueue.pop();
  1938. this->CurrentEntry = &this->GeneratorTarget->SourceDepends[sf];
  1939. // Queue dependencies added explicitly by the user.
  1940. if (const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS")) {
  1941. std::vector<std::string> objDeps;
  1942. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1943. for (std::vector<std::string>::iterator odi = objDeps.begin();
  1944. odi != objDeps.end(); ++odi) {
  1945. if (cmSystemTools::FileIsFullPath(*odi)) {
  1946. *odi = cmSystemTools::CollapseFullPath(*odi);
  1947. }
  1948. }
  1949. this->FollowNames(objDeps);
  1950. }
  1951. // Queue the source needed to generate this file, if any.
  1952. this->FollowName(sf->GetFullPath());
  1953. // Queue dependencies added programatically by commands.
  1954. this->FollowNames(sf->GetDepends());
  1955. // Queue custom command dependencies.
  1956. if (cmCustomCommand const* cc = sf->GetCustomCommand()) {
  1957. this->CheckCustomCommand(*cc);
  1958. }
  1959. }
  1960. this->CurrentEntry = CM_NULLPTR;
  1961. this->GeneratorTarget->AddTracedSources(this->NewSources);
  1962. }
  1963. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  1964. {
  1965. if (this->SourcesQueued.insert(sf).second) {
  1966. this->SourceQueue.push(sf);
  1967. // Make sure this file is in the target at the end.
  1968. this->NewSources.push_back(sf->GetFullPath());
  1969. }
  1970. }
  1971. void cmTargetTraceDependencies::FollowName(std::string const& name)
  1972. {
  1973. NameMapType::iterator i = this->NameMap.find(name);
  1974. if (i == this->NameMap.end()) {
  1975. // Check if we know how to generate this file.
  1976. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  1977. NameMapType::value_type entry(name, sf);
  1978. i = this->NameMap.insert(entry).first;
  1979. }
  1980. if (cmSourceFile* sf = i->second) {
  1981. // Record the dependency we just followed.
  1982. if (this->CurrentEntry) {
  1983. this->CurrentEntry->Depends.push_back(sf);
  1984. }
  1985. this->QueueSource(sf);
  1986. }
  1987. }
  1988. void cmTargetTraceDependencies::FollowNames(
  1989. std::vector<std::string> const& names)
  1990. {
  1991. for (std::vector<std::string>::const_iterator i = names.begin();
  1992. i != names.end(); ++i) {
  1993. this->FollowName(*i);
  1994. }
  1995. }
  1996. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  1997. {
  1998. // Dependencies on targets (utilities) are supposed to be named by
  1999. // just the target name. However for compatibility we support
  2000. // naming the output file generated by the target (assuming there is
  2001. // no output-name property which old code would not have set). In
  2002. // that case the target name will be the file basename of the
  2003. // dependency.
  2004. std::string util = cmSystemTools::GetFilenameName(dep);
  2005. if (cmSystemTools::GetFilenameLastExtension(util) == ".exe") {
  2006. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  2007. }
  2008. // Check for a target with this name.
  2009. if (cmGeneratorTarget* t =
  2010. this->GeneratorTarget->GetLocalGenerator()->FindGeneratorTargetToUse(
  2011. util)) {
  2012. // If we find the target and the dep was given as a full path,
  2013. // then make sure it was not a full path to something else, and
  2014. // the fact that the name matched a target was just a coincidence.
  2015. if (cmSystemTools::FileIsFullPath(dep.c_str())) {
  2016. if (t->GetType() >= cmStateEnums::EXECUTABLE &&
  2017. t->GetType() <= cmStateEnums::MODULE_LIBRARY) {
  2018. // This is really only for compatibility so we do not need to
  2019. // worry about configuration names and output names.
  2020. std::string tLocation = t->GetLocationForBuild();
  2021. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  2022. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  2023. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  2024. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  2025. if (depLocation == tLocation) {
  2026. this->GeneratorTarget->Target->AddUtility(util);
  2027. return true;
  2028. }
  2029. }
  2030. } else {
  2031. // The original name of the dependency was not a full path. It
  2032. // must name a target, so add the target-level dependency.
  2033. this->GeneratorTarget->Target->AddUtility(util);
  2034. return true;
  2035. }
  2036. }
  2037. // The dependency does not name a target built in this project.
  2038. return false;
  2039. }
  2040. void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
  2041. {
  2042. // Transform command names that reference targets built in this
  2043. // project to corresponding target-level dependencies.
  2044. cmGeneratorExpression ge(cc.GetBacktrace());
  2045. // Add target-level dependencies referenced by generator expressions.
  2046. std::set<cmGeneratorTarget*> targets;
  2047. for (cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  2048. cit != cc.GetCommandLines().end(); ++cit) {
  2049. std::string const& command = *cit->begin();
  2050. // Check for a target with this name.
  2051. if (cmGeneratorTarget* t =
  2052. this->LocalGenerator->FindGeneratorTargetToUse(command)) {
  2053. if (t->GetType() == cmStateEnums::EXECUTABLE) {
  2054. // The command refers to an executable target built in
  2055. // this project. Add the target-level dependency to make
  2056. // sure the executable is up to date before this custom
  2057. // command possibly runs.
  2058. this->GeneratorTarget->Target->AddUtility(command);
  2059. }
  2060. }
  2061. // Check for target references in generator expressions.
  2062. for (cmCustomCommandLine::const_iterator cli = cit->begin();
  2063. cli != cit->end(); ++cli) {
  2064. const CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(*cli);
  2065. cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), "", true);
  2066. std::set<cmGeneratorTarget*> geTargets = cge->GetTargets();
  2067. targets.insert(geTargets.begin(), geTargets.end());
  2068. }
  2069. }
  2070. for (std::set<cmGeneratorTarget*>::iterator ti = targets.begin();
  2071. ti != targets.end(); ++ti) {
  2072. this->GeneratorTarget->Target->AddUtility((*ti)->GetName());
  2073. }
  2074. // Queue the custom command dependencies.
  2075. std::vector<std::string> configs;
  2076. std::set<std::string> emitted;
  2077. this->Makefile->GetConfigurations(configs);
  2078. if (configs.empty()) {
  2079. configs.push_back("");
  2080. }
  2081. for (std::vector<std::string>::const_iterator ci = configs.begin();
  2082. ci != configs.end(); ++ci) {
  2083. this->FollowCommandDepends(cc, *ci, emitted);
  2084. }
  2085. }
  2086. void cmTargetTraceDependencies::FollowCommandDepends(
  2087. cmCustomCommand const& cc, const std::string& config,
  2088. std::set<std::string>& emitted)
  2089. {
  2090. cmCustomCommandGenerator ccg(cc, config,
  2091. this->GeneratorTarget->LocalGenerator);
  2092. const std::vector<std::string>& depends = ccg.GetDepends();
  2093. for (std::vector<std::string>::const_iterator di = depends.begin();
  2094. di != depends.end(); ++di) {
  2095. std::string const& dep = *di;
  2096. if (emitted.insert(dep).second) {
  2097. if (!this->IsUtility(dep)) {
  2098. // The dependency does not name a target and may be a file we
  2099. // know how to generate. Queue it.
  2100. this->FollowName(dep);
  2101. }
  2102. }
  2103. }
  2104. }
  2105. void cmTargetTraceDependencies::CheckCustomCommands(
  2106. const std::vector<cmCustomCommand>& commands)
  2107. {
  2108. for (std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  2109. cli != commands.end(); ++cli) {
  2110. this->CheckCustomCommand(*cli);
  2111. }
  2112. }
  2113. void cmGeneratorTarget::TraceDependencies()
  2114. {
  2115. // CMake-generated targets have no dependencies to trace. Normally tracing
  2116. // would find nothing anyway, but when building CMake itself the "install"
  2117. // target command ends up referencing the "cmake" target but we do not
  2118. // really want the dependency because "install" depend on "all" anyway.
  2119. if (this->GetType() == cmStateEnums::GLOBAL_TARGET) {
  2120. return;
  2121. }
  2122. // Use a helper object to trace the dependencies.
  2123. cmTargetTraceDependencies tracer(this);
  2124. tracer.Trace();
  2125. }
  2126. std::string cmGeneratorTarget::GetCompilePDBDirectory(
  2127. const std::string& config) const
  2128. {
  2129. if (CompileInfo const* info = this->GetCompileInfo(config)) {
  2130. return info->CompilePdbDir;
  2131. }
  2132. return "";
  2133. }
  2134. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  2135. std::vector<std::string>& archVec) const
  2136. {
  2137. const char* archs = CM_NULLPTR;
  2138. if (!config.empty()) {
  2139. std::string defVarName = "OSX_ARCHITECTURES_";
  2140. defVarName += cmSystemTools::UpperCase(config);
  2141. archs = this->GetProperty(defVarName);
  2142. }
  2143. if (!archs) {
  2144. archs = this->GetProperty("OSX_ARCHITECTURES");
  2145. }
  2146. if (archs) {
  2147. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  2148. }
  2149. }
  2150. //----------------------------------------------------------------------------
  2151. std::string cmGeneratorTarget::GetFeatureSpecificLinkRuleVariable(
  2152. std::string const& var, std::string const& config) const
  2153. {
  2154. if (this->IsIPOEnabled(config)) {
  2155. std::string varIPO = var + "_IPO";
  2156. if (this->Makefile->IsDefinitionSet(varIPO)) {
  2157. return varIPO;
  2158. }
  2159. }
  2160. return var;
  2161. }
  2162. //----------------------------------------------------------------------------
  2163. std::string cmGeneratorTarget::GetCreateRuleVariable(
  2164. std::string const& lang, std::string const& config) const
  2165. {
  2166. switch (this->GetType()) {
  2167. case cmStateEnums::STATIC_LIBRARY: {
  2168. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  2169. return this->GetFeatureSpecificLinkRuleVariable(var, config);
  2170. }
  2171. case cmStateEnums::SHARED_LIBRARY:
  2172. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  2173. case cmStateEnums::MODULE_LIBRARY:
  2174. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  2175. case cmStateEnums::EXECUTABLE:
  2176. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  2177. default:
  2178. break;
  2179. }
  2180. return "";
  2181. }
  2182. static void processIncludeDirectories(
  2183. cmGeneratorTarget const* tgt,
  2184. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2185. std::vector<std::string>& includes,
  2186. CM_UNORDERED_SET<std::string>& uniqueIncludes,
  2187. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2188. bool debugIncludes, const std::string& language)
  2189. {
  2190. for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
  2191. it = entries.begin(),
  2192. end = entries.end();
  2193. it != end; ++it) {
  2194. cmLinkImplItem const& item = (*it)->LinkImplItem;
  2195. std::string const& targetName = item;
  2196. bool const fromImported = item.Target && item.Target->IsImported();
  2197. bool const checkCMP0027 = item.FromGenex;
  2198. std::vector<std::string> entryIncludes;
  2199. cmSystemTools::ExpandListArgument(
  2200. (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
  2201. dagChecker, language),
  2202. entryIncludes);
  2203. std::string usedIncludes;
  2204. for (std::vector<std::string>::iterator li = entryIncludes.begin();
  2205. li != entryIncludes.end(); ++li) {
  2206. if (fromImported && !cmSystemTools::FileExists(li->c_str())) {
  2207. std::ostringstream e;
  2208. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2209. if (checkCMP0027) {
  2210. switch (tgt->GetPolicyStatusCMP0027()) {
  2211. case cmPolicies::WARN:
  2212. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  2213. case cmPolicies::OLD:
  2214. messageType = cmake::AUTHOR_WARNING;
  2215. break;
  2216. case cmPolicies::REQUIRED_ALWAYS:
  2217. case cmPolicies::REQUIRED_IF_USED:
  2218. case cmPolicies::NEW:
  2219. break;
  2220. }
  2221. }
  2222. /* clang-format off */
  2223. e << "Imported target \"" << targetName << "\" includes "
  2224. "non-existent path\n \"" << *li << "\"\nin its "
  2225. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  2226. "* The path was deleted, renamed, or moved to another "
  2227. "location.\n"
  2228. "* An install or uninstall procedure did not complete "
  2229. "successfully.\n"
  2230. "* The installation package was faulty and references files it "
  2231. "does not provide.\n";
  2232. /* clang-format on */
  2233. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2234. return;
  2235. }
  2236. if (!cmSystemTools::FileIsFullPath(li->c_str())) {
  2237. std::ostringstream e;
  2238. bool noMessage = false;
  2239. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2240. if (!targetName.empty()) {
  2241. /* clang-format off */
  2242. e << "Target \"" << targetName << "\" contains relative "
  2243. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  2244. " \"" << *li << "\"";
  2245. /* clang-format on */
  2246. } else {
  2247. switch (tgt->GetPolicyStatusCMP0021()) {
  2248. case cmPolicies::WARN: {
  2249. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  2250. messageType = cmake::AUTHOR_WARNING;
  2251. } break;
  2252. case cmPolicies::OLD:
  2253. noMessage = true;
  2254. case cmPolicies::REQUIRED_IF_USED:
  2255. case cmPolicies::REQUIRED_ALWAYS:
  2256. case cmPolicies::NEW:
  2257. // Issue the fatal message.
  2258. break;
  2259. }
  2260. e << "Found relative path while evaluating include directories of "
  2261. "\""
  2262. << tgt->GetName() << "\":\n \"" << *li << "\"\n";
  2263. }
  2264. if (!noMessage) {
  2265. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2266. if (messageType == cmake::FATAL_ERROR) {
  2267. return;
  2268. }
  2269. }
  2270. }
  2271. if (!cmSystemTools::IsOff(li->c_str())) {
  2272. cmSystemTools::ConvertToUnixSlashes(*li);
  2273. }
  2274. std::string inc = *li;
  2275. if (uniqueIncludes.insert(inc).second) {
  2276. includes.push_back(inc);
  2277. if (debugIncludes) {
  2278. usedIncludes += " * " + inc + "\n";
  2279. }
  2280. }
  2281. }
  2282. if (!usedIncludes.empty()) {
  2283. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  2284. cmake::LOG, std::string("Used includes for target ") + tgt->GetName() +
  2285. ":\n" + usedIncludes,
  2286. (*it)->ge->GetBacktrace());
  2287. }
  2288. }
  2289. }
  2290. std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
  2291. const std::string& config, const std::string& lang) const
  2292. {
  2293. std::vector<std::string> includes;
  2294. CM_UNORDERED_SET<std::string> uniqueIncludes;
  2295. cmGeneratorExpressionDAGChecker dagChecker(
  2296. this->GetName(), "INCLUDE_DIRECTORIES", CM_NULLPTR, CM_NULLPTR);
  2297. std::vector<std::string> debugProperties;
  2298. const char* debugProp =
  2299. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2300. if (debugProp) {
  2301. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2302. }
  2303. bool debugIncludes = !this->DebugIncludesDone &&
  2304. std::find(debugProperties.begin(), debugProperties.end(),
  2305. "INCLUDE_DIRECTORIES") != debugProperties.end();
  2306. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2307. this->DebugIncludesDone = true;
  2308. }
  2309. processIncludeDirectories(this, this->IncludeDirectoriesEntries, includes,
  2310. uniqueIncludes, &dagChecker, config, debugIncludes,
  2311. lang);
  2312. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2313. linkInterfaceIncludeDirectoriesEntries;
  2314. AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES",
  2315. linkInterfaceIncludeDirectoriesEntries);
  2316. if (this->Makefile->IsOn("APPLE")) {
  2317. cmLinkImplementationLibraries const* impl =
  2318. this->GetLinkImplementationLibraries(config);
  2319. for (std::vector<cmLinkImplItem>::const_iterator it =
  2320. impl->Libraries.begin();
  2321. it != impl->Libraries.end(); ++it) {
  2322. std::string libDir = cmSystemTools::CollapseFullPath(*it);
  2323. static cmsys::RegularExpression frameworkCheck(
  2324. "(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  2325. if (!frameworkCheck.find(libDir)) {
  2326. continue;
  2327. }
  2328. libDir = frameworkCheck.match(1);
  2329. cmGeneratorExpression ge;
  2330. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
  2331. ge.Parse(libDir.c_str());
  2332. linkInterfaceIncludeDirectoriesEntries.push_back(
  2333. new cmGeneratorTarget::TargetPropertyEntry(cge));
  2334. }
  2335. }
  2336. processIncludeDirectories(this, linkInterfaceIncludeDirectoriesEntries,
  2337. includes, uniqueIncludes, &dagChecker, config,
  2338. debugIncludes, lang);
  2339. cmDeleteAll(linkInterfaceIncludeDirectoriesEntries);
  2340. // Add standard include directories for this language.
  2341. std::string const standardIncludesVar =
  2342. "CMAKE_" + lang + "_STANDARD_INCLUDE_DIRECTORIES";
  2343. std::string const standardIncludes =
  2344. this->Makefile->GetSafeDefinition(standardIncludesVar);
  2345. std::vector<std::string>::size_type const before = includes.size();
  2346. cmSystemTools::ExpandListArgument(standardIncludes, includes);
  2347. for (std::vector<std::string>::iterator i = includes.begin() + before;
  2348. i != includes.end(); ++i) {
  2349. cmSystemTools::ConvertToUnixSlashes(*i);
  2350. }
  2351. return includes;
  2352. }
  2353. static void processCompileOptionsInternal(
  2354. cmGeneratorTarget const* tgt,
  2355. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2356. std::vector<std::string>& options,
  2357. CM_UNORDERED_SET<std::string>& uniqueOptions,
  2358. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2359. bool debugOptions, const char* logName, std::string const& language)
  2360. {
  2361. for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
  2362. it = entries.begin(),
  2363. end = entries.end();
  2364. it != end; ++it) {
  2365. std::vector<std::string> entryOptions;
  2366. cmSystemTools::ExpandListArgument(
  2367. (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
  2368. dagChecker, language),
  2369. entryOptions);
  2370. std::string usedOptions;
  2371. for (std::vector<std::string>::iterator li = entryOptions.begin();
  2372. li != entryOptions.end(); ++li) {
  2373. std::string const& opt = *li;
  2374. if (uniqueOptions.insert(opt).second) {
  2375. options.push_back(opt);
  2376. if (debugOptions) {
  2377. usedOptions += " * " + opt + "\n";
  2378. }
  2379. }
  2380. }
  2381. if (!usedOptions.empty()) {
  2382. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  2383. cmake::LOG, std::string("Used compile ") + logName +
  2384. std::string(" for target ") + tgt->GetName() + ":\n" + usedOptions,
  2385. (*it)->ge->GetBacktrace());
  2386. }
  2387. }
  2388. }
  2389. static void processCompileOptions(
  2390. cmGeneratorTarget const* tgt,
  2391. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2392. std::vector<std::string>& options,
  2393. CM_UNORDERED_SET<std::string>& uniqueOptions,
  2394. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2395. bool debugOptions, std::string const& language)
  2396. {
  2397. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2398. dagChecker, config, debugOptions, "options",
  2399. language);
  2400. }
  2401. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
  2402. const std::string& config,
  2403. const std::string& language) const
  2404. {
  2405. CM_UNORDERED_SET<std::string> uniqueOptions;
  2406. cmGeneratorExpressionDAGChecker dagChecker(
  2407. this->GetName(), "COMPILE_OPTIONS", CM_NULLPTR, CM_NULLPTR);
  2408. std::vector<std::string> debugProperties;
  2409. const char* debugProp =
  2410. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2411. if (debugProp) {
  2412. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2413. }
  2414. bool debugOptions = !this->DebugCompileOptionsDone &&
  2415. std::find(debugProperties.begin(), debugProperties.end(),
  2416. "COMPILE_OPTIONS") != debugProperties.end();
  2417. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2418. this->DebugCompileOptionsDone = true;
  2419. }
  2420. processCompileOptions(this, this->CompileOptionsEntries, result,
  2421. uniqueOptions, &dagChecker, config, debugOptions,
  2422. language);
  2423. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2424. linkInterfaceCompileOptionsEntries;
  2425. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_OPTIONS",
  2426. linkInterfaceCompileOptionsEntries);
  2427. processCompileOptions(this, linkInterfaceCompileOptionsEntries, result,
  2428. uniqueOptions, &dagChecker, config, debugOptions,
  2429. language);
  2430. cmDeleteAll(linkInterfaceCompileOptionsEntries);
  2431. }
  2432. static void processCompileFeatures(
  2433. cmGeneratorTarget const* tgt,
  2434. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2435. std::vector<std::string>& options,
  2436. CM_UNORDERED_SET<std::string>& uniqueOptions,
  2437. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2438. bool debugOptions)
  2439. {
  2440. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2441. dagChecker, config, debugOptions, "features",
  2442. std::string());
  2443. }
  2444. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
  2445. const std::string& config) const
  2446. {
  2447. CM_UNORDERED_SET<std::string> uniqueFeatures;
  2448. cmGeneratorExpressionDAGChecker dagChecker(
  2449. this->GetName(), "COMPILE_FEATURES", CM_NULLPTR, CM_NULLPTR);
  2450. std::vector<std::string> debugProperties;
  2451. const char* debugProp =
  2452. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2453. if (debugProp) {
  2454. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2455. }
  2456. bool debugFeatures = !this->DebugCompileFeaturesDone &&
  2457. std::find(debugProperties.begin(), debugProperties.end(),
  2458. "COMPILE_FEATURES") != debugProperties.end();
  2459. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2460. this->DebugCompileFeaturesDone = true;
  2461. }
  2462. processCompileFeatures(this, this->CompileFeaturesEntries, result,
  2463. uniqueFeatures, &dagChecker, config, debugFeatures);
  2464. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2465. linkInterfaceCompileFeaturesEntries;
  2466. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_FEATURES",
  2467. linkInterfaceCompileFeaturesEntries);
  2468. processCompileFeatures(this, linkInterfaceCompileFeaturesEntries, result,
  2469. uniqueFeatures, &dagChecker, config, debugFeatures);
  2470. cmDeleteAll(linkInterfaceCompileFeaturesEntries);
  2471. }
  2472. static void processCompileDefinitions(
  2473. cmGeneratorTarget const* tgt,
  2474. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2475. std::vector<std::string>& options,
  2476. CM_UNORDERED_SET<std::string>& uniqueOptions,
  2477. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2478. bool debugOptions, std::string const& language)
  2479. {
  2480. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2481. dagChecker, config, debugOptions,
  2482. "definitions", language);
  2483. }
  2484. void cmGeneratorTarget::GetCompileDefinitions(
  2485. std::vector<std::string>& list, const std::string& config,
  2486. const std::string& language) const
  2487. {
  2488. CM_UNORDERED_SET<std::string> uniqueOptions;
  2489. cmGeneratorExpressionDAGChecker dagChecker(
  2490. this->GetName(), "COMPILE_DEFINITIONS", CM_NULLPTR, CM_NULLPTR);
  2491. std::vector<std::string> debugProperties;
  2492. const char* debugProp =
  2493. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2494. if (debugProp) {
  2495. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2496. }
  2497. bool debugDefines = !this->DebugCompileDefinitionsDone &&
  2498. std::find(debugProperties.begin(), debugProperties.end(),
  2499. "COMPILE_DEFINITIONS") != debugProperties.end();
  2500. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2501. this->DebugCompileDefinitionsDone = true;
  2502. }
  2503. processCompileDefinitions(this, this->CompileDefinitionsEntries, list,
  2504. uniqueOptions, &dagChecker, config, debugDefines,
  2505. language);
  2506. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2507. linkInterfaceCompileDefinitionsEntries;
  2508. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_DEFINITIONS",
  2509. linkInterfaceCompileDefinitionsEntries);
  2510. if (!config.empty()) {
  2511. std::string configPropName =
  2512. "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
  2513. const char* configProp = this->GetProperty(configPropName);
  2514. if (configProp) {
  2515. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0043)) {
  2516. case cmPolicies::WARN: {
  2517. std::ostringstream e;
  2518. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
  2519. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  2520. }
  2521. case cmPolicies::OLD: {
  2522. cmGeneratorExpression ge;
  2523. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
  2524. ge.Parse(configProp);
  2525. linkInterfaceCompileDefinitionsEntries.push_back(
  2526. new cmGeneratorTarget::TargetPropertyEntry(cge));
  2527. } break;
  2528. case cmPolicies::NEW:
  2529. case cmPolicies::REQUIRED_ALWAYS:
  2530. case cmPolicies::REQUIRED_IF_USED:
  2531. break;
  2532. }
  2533. }
  2534. }
  2535. processCompileDefinitions(this, linkInterfaceCompileDefinitionsEntries, list,
  2536. uniqueOptions, &dagChecker, config, debugDefines,
  2537. language);
  2538. cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
  2539. }
  2540. void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
  2541. {
  2542. if (this->IsImported()) {
  2543. return;
  2544. }
  2545. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  2546. // Get the names.
  2547. std::string name;
  2548. std::string soName;
  2549. std::string realName;
  2550. std::string impName;
  2551. std::string pdbName;
  2552. if (this->GetType() == cmStateEnums::EXECUTABLE) {
  2553. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2554. } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  2555. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2556. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  2557. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2558. } else {
  2559. return;
  2560. }
  2561. // Get the directory.
  2562. std::string dir =
  2563. this->GetDirectory(config, cmStateEnums::RuntimeBinaryArtifact);
  2564. // Add each name.
  2565. std::string f;
  2566. if (!name.empty()) {
  2567. f = dir;
  2568. f += "/";
  2569. f += name;
  2570. gg->AddToManifest(f);
  2571. }
  2572. if (!soName.empty()) {
  2573. f = dir;
  2574. f += "/";
  2575. f += soName;
  2576. gg->AddToManifest(f);
  2577. }
  2578. if (!realName.empty()) {
  2579. f = dir;
  2580. f += "/";
  2581. f += realName;
  2582. gg->AddToManifest(f);
  2583. }
  2584. if (!pdbName.empty()) {
  2585. f = dir;
  2586. f += "/";
  2587. f += pdbName;
  2588. gg->AddToManifest(f);
  2589. }
  2590. if (!impName.empty()) {
  2591. f = this->GetDirectory(config, cmStateEnums::ImportLibraryArtifact);
  2592. f += "/";
  2593. f += impName;
  2594. gg->AddToManifest(f);
  2595. }
  2596. }
  2597. std::string cmGeneratorTarget::GetImportedLibName(
  2598. std::string const& config) const
  2599. {
  2600. if (cmGeneratorTarget::ImportInfo const* info =
  2601. this->GetImportInfo(config)) {
  2602. return info->LibName;
  2603. }
  2604. return std::string();
  2605. }
  2606. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  2607. cmStateEnums::ArtifactType artifact,
  2608. bool realname) const
  2609. {
  2610. if (this->IsImported()) {
  2611. return this->Target->ImportedGetFullPath(config, artifact);
  2612. }
  2613. return this->NormalGetFullPath(config, artifact, realname);
  2614. }
  2615. std::string cmGeneratorTarget::NormalGetFullPath(
  2616. const std::string& config, cmStateEnums::ArtifactType artifact,
  2617. bool realname) const
  2618. {
  2619. std::string fpath = this->GetDirectory(config, artifact);
  2620. fpath += "/";
  2621. if (this->IsAppBundleOnApple()) {
  2622. fpath = this->BuildBundleDirectory(fpath, config, FullLevel);
  2623. fpath += "/";
  2624. }
  2625. // Add the full name of the target.
  2626. switch (artifact) {
  2627. case cmStateEnums::RuntimeBinaryArtifact:
  2628. if (realname) {
  2629. fpath += this->NormalGetRealName(config);
  2630. } else {
  2631. fpath +=
  2632. this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact);
  2633. }
  2634. break;
  2635. case cmStateEnums::ImportLibraryArtifact:
  2636. fpath += this->GetFullName(config, cmStateEnums::ImportLibraryArtifact);
  2637. break;
  2638. }
  2639. return fpath;
  2640. }
  2641. std::string cmGeneratorTarget::NormalGetRealName(
  2642. const std::string& config) const
  2643. {
  2644. // This should not be called for imported targets.
  2645. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2646. // enforcement of the limited imported target API.
  2647. if (this->IsImported()) {
  2648. std::string msg = "NormalGetRealName called on imported target: ";
  2649. msg += this->GetName();
  2650. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2651. }
  2652. if (this->GetType() == cmStateEnums::EXECUTABLE) {
  2653. // Compute the real name that will be built.
  2654. std::string name;
  2655. std::string realName;
  2656. std::string impName;
  2657. std::string pdbName;
  2658. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2659. return realName;
  2660. }
  2661. // Compute the real name that will be built.
  2662. std::string name;
  2663. std::string soName;
  2664. std::string realName;
  2665. std::string impName;
  2666. std::string pdbName;
  2667. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2668. return realName;
  2669. }
  2670. void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName,
  2671. std::string& realName,
  2672. std::string& impName,
  2673. std::string& pdbName,
  2674. const std::string& config) const
  2675. {
  2676. // This should not be called for imported targets.
  2677. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2678. // enforcement of the limited imported target API.
  2679. if (this->IsImported()) {
  2680. std::string msg = "GetLibraryNames called on imported target: ";
  2681. msg += this->GetName();
  2682. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2683. return;
  2684. }
  2685. // Check for library version properties.
  2686. const char* version = this->GetProperty("VERSION");
  2687. const char* soversion = this->GetProperty("SOVERSION");
  2688. if (!this->HasSOName(config) ||
  2689. this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
  2690. this->IsFrameworkOnApple()) {
  2691. // Versioning is supported only for shared libraries and modules,
  2692. // and then only when the platform supports an soname flag.
  2693. version = CM_NULLPTR;
  2694. soversion = CM_NULLPTR;
  2695. }
  2696. if (version && !soversion) {
  2697. // The soversion must be set if the library version is set. Use
  2698. // the library version as the soversion.
  2699. soversion = version;
  2700. }
  2701. if (!version && soversion) {
  2702. // Use the soversion as the library version.
  2703. version = soversion;
  2704. }
  2705. // Get the components of the library name.
  2706. std::string prefix;
  2707. std::string base;
  2708. std::string suffix;
  2709. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  2710. prefix, base, suffix);
  2711. // The library name.
  2712. name = prefix + base + suffix;
  2713. if (this->IsFrameworkOnApple()) {
  2714. realName = prefix;
  2715. if (!this->Makefile->PlatformIsAppleIos()) {
  2716. realName += "Versions/";
  2717. realName += this->GetFrameworkVersion();
  2718. realName += "/";
  2719. }
  2720. realName += base;
  2721. soName = realName;
  2722. } else {
  2723. // The library's soname.
  2724. this->ComputeVersionedName(soName, prefix, base, suffix, name, soversion);
  2725. // The library's real name on disk.
  2726. this->ComputeVersionedName(realName, prefix, base, suffix, name, version);
  2727. }
  2728. // The import library name.
  2729. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2730. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  2731. impName =
  2732. this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
  2733. } else {
  2734. impName = "";
  2735. }
  2736. // The program database file name.
  2737. pdbName = this->GetPDBName(config);
  2738. }
  2739. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  2740. std::string& realName,
  2741. std::string& impName,
  2742. std::string& pdbName,
  2743. const std::string& config) const
  2744. {
  2745. // This should not be called for imported targets.
  2746. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2747. // enforcement of the limited imported target API.
  2748. if (this->IsImported()) {
  2749. std::string msg = "GetExecutableNames called on imported target: ";
  2750. msg += this->GetName();
  2751. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2752. }
  2753. // This versioning is supported only for executables and then only
  2754. // when the platform supports symbolic links.
  2755. #if defined(_WIN32) && !defined(__CYGWIN__)
  2756. const char* version = 0;
  2757. #else
  2758. // Check for executable version properties.
  2759. const char* version = this->GetProperty("VERSION");
  2760. if (this->GetType() != cmStateEnums::EXECUTABLE ||
  2761. this->Makefile->IsOn("XCODE")) {
  2762. version = CM_NULLPTR;
  2763. }
  2764. #endif
  2765. // Get the components of the executable name.
  2766. std::string prefix;
  2767. std::string base;
  2768. std::string suffix;
  2769. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  2770. prefix, base, suffix);
  2771. // The executable name.
  2772. name = prefix + base + suffix;
  2773. // The executable's real name on disk.
  2774. #if defined(__CYGWIN__)
  2775. realName = prefix + base;
  2776. #else
  2777. realName = name;
  2778. #endif
  2779. if (version) {
  2780. realName += "-";
  2781. realName += version;
  2782. }
  2783. #if defined(__CYGWIN__)
  2784. realName += suffix;
  2785. #endif
  2786. // The import library name.
  2787. impName =
  2788. this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
  2789. // The program database file name.
  2790. pdbName = this->GetPDBName(config);
  2791. }
  2792. std::string cmGeneratorTarget::GetFullNameInternal(
  2793. const std::string& config, cmStateEnums::ArtifactType artifact) const
  2794. {
  2795. std::string prefix;
  2796. std::string base;
  2797. std::string suffix;
  2798. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  2799. return prefix + base + suffix;
  2800. }
  2801. const char* cmGeneratorTarget::ImportedGetLocation(
  2802. const std::string& config) const
  2803. {
  2804. static std::string location;
  2805. assert(this->IsImported());
  2806. location = this->Target->ImportedGetFullPath(
  2807. config, cmStateEnums::RuntimeBinaryArtifact);
  2808. return location.c_str();
  2809. }
  2810. std::string cmGeneratorTarget::GetFullNameImported(
  2811. const std::string& config, cmStateEnums::ArtifactType artifact) const
  2812. {
  2813. return cmSystemTools::GetFilenameName(
  2814. this->Target->ImportedGetFullPath(config, artifact));
  2815. }
  2816. void cmGeneratorTarget::GetFullNameInternal(
  2817. const std::string& config, cmStateEnums::ArtifactType artifact,
  2818. std::string& outPrefix, std::string& outBase, std::string& outSuffix) const
  2819. {
  2820. // Use just the target name for non-main target types.
  2821. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  2822. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  2823. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  2824. this->GetType() != cmStateEnums::EXECUTABLE) {
  2825. outPrefix = "";
  2826. outBase = this->GetName();
  2827. outSuffix = "";
  2828. return;
  2829. }
  2830. const bool isImportedLibraryArtifact =
  2831. (artifact == cmStateEnums::ImportLibraryArtifact);
  2832. // Return an empty name for the import library if this platform
  2833. // does not support import libraries.
  2834. if (isImportedLibraryArtifact &&
  2835. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
  2836. outPrefix = "";
  2837. outBase = "";
  2838. outSuffix = "";
  2839. return;
  2840. }
  2841. // The implib option is only allowed for shared libraries, module
  2842. // libraries, and executables.
  2843. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  2844. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  2845. this->GetType() != cmStateEnums::EXECUTABLE) {
  2846. artifact = cmStateEnums::RuntimeBinaryArtifact;
  2847. }
  2848. // Compute the full name for main target types.
  2849. const char* targetPrefix =
  2850. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_PREFIX")
  2851. : this->GetProperty("PREFIX"));
  2852. const char* targetSuffix =
  2853. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_SUFFIX")
  2854. : this->GetProperty("SUFFIX"));
  2855. const char* configPostfix = CM_NULLPTR;
  2856. if (!config.empty()) {
  2857. std::string configProp = cmSystemTools::UpperCase(config);
  2858. configProp += "_POSTFIX";
  2859. configPostfix = this->GetProperty(configProp);
  2860. // Mac application bundles and frameworks have no postfix.
  2861. if (configPostfix &&
  2862. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple())) {
  2863. configPostfix = CM_NULLPTR;
  2864. }
  2865. }
  2866. const char* prefixVar = this->Target->GetPrefixVariableInternal(artifact);
  2867. const char* suffixVar = this->Target->GetSuffixVariableInternal(artifact);
  2868. // Check for language-specific default prefix and suffix.
  2869. std::string ll = this->GetLinkerLanguage(config);
  2870. if (!ll.empty()) {
  2871. if (!targetSuffix && suffixVar && *suffixVar) {
  2872. std::string langSuff = suffixVar + std::string("_") + ll;
  2873. targetSuffix = this->Makefile->GetDefinition(langSuff);
  2874. }
  2875. if (!targetPrefix && prefixVar && *prefixVar) {
  2876. std::string langPrefix = prefixVar + std::string("_") + ll;
  2877. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  2878. }
  2879. }
  2880. // if there is no prefix on the target use the cmake definition
  2881. if (!targetPrefix && prefixVar) {
  2882. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  2883. }
  2884. // if there is no suffix on the target use the cmake definition
  2885. if (!targetSuffix && suffixVar) {
  2886. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  2887. }
  2888. // frameworks have directory prefix but no suffix
  2889. std::string fw_prefix;
  2890. if (this->IsFrameworkOnApple()) {
  2891. fw_prefix = this->GetFrameworkDirectory(config, ContentLevel);
  2892. fw_prefix += "/";
  2893. targetPrefix = fw_prefix.c_str();
  2894. targetSuffix = CM_NULLPTR;
  2895. }
  2896. if (this->IsCFBundleOnApple()) {
  2897. fw_prefix = this->GetCFBundleDirectory(config, FullLevel);
  2898. fw_prefix += "/";
  2899. targetPrefix = fw_prefix.c_str();
  2900. targetSuffix = CM_NULLPTR;
  2901. }
  2902. // Begin the final name with the prefix.
  2903. outPrefix = targetPrefix ? targetPrefix : "";
  2904. // Append the target name or property-specified name.
  2905. outBase += this->GetOutputName(config, artifact);
  2906. // Append the per-configuration postfix.
  2907. outBase += configPostfix ? configPostfix : "";
  2908. // Name shared libraries with their version number on some platforms.
  2909. if (const char* soversion = this->GetProperty("SOVERSION")) {
  2910. if (this->GetType() == cmStateEnums::SHARED_LIBRARY &&
  2911. !isImportedLibraryArtifact &&
  2912. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION")) {
  2913. outBase += "-";
  2914. outBase += soversion;
  2915. }
  2916. }
  2917. // Append the suffix.
  2918. outSuffix = targetSuffix ? targetSuffix : "";
  2919. }
  2920. std::string cmGeneratorTarget::GetLinkerLanguage(
  2921. const std::string& config) const
  2922. {
  2923. return this->GetLinkClosure(config)->LinkerLanguage;
  2924. }
  2925. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  2926. {
  2927. std::string prefix;
  2928. std::string base;
  2929. std::string suffix;
  2930. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  2931. prefix, base, suffix);
  2932. std::vector<std::string> props;
  2933. std::string configUpper = cmSystemTools::UpperCase(config);
  2934. if (!configUpper.empty()) {
  2935. // PDB_NAME_<CONFIG>
  2936. props.push_back("PDB_NAME_" + configUpper);
  2937. }
  2938. // PDB_NAME
  2939. props.push_back("PDB_NAME");
  2940. for (std::vector<std::string>::const_iterator i = props.begin();
  2941. i != props.end(); ++i) {
  2942. if (const char* outName = this->GetProperty(*i)) {
  2943. base = outName;
  2944. break;
  2945. }
  2946. }
  2947. return prefix + base + ".pdb";
  2948. }
  2949. std::string cmGeneratorTarget::GetObjectDirectory(
  2950. std::string const& config) const
  2951. {
  2952. std::string obj_dir =
  2953. this->GlobalGenerator->ExpandCFGIntDir(this->ObjectDirectory, config);
  2954. #if defined(__APPLE__)
  2955. // find and replace $(PROJECT_NAME) xcode placeholder
  2956. const std::string projectName = this->LocalGenerator->GetProjectName();
  2957. cmSystemTools::ReplaceString(obj_dir, "$(PROJECT_NAME)", projectName);
  2958. #endif
  2959. return obj_dir;
  2960. }
  2961. void cmGeneratorTarget::GetTargetObjectNames(
  2962. std::string const& config, std::vector<std::string>& objects) const
  2963. {
  2964. std::vector<cmSourceFile const*> objectSources;
  2965. this->GetObjectSources(objectSources, config);
  2966. std::map<cmSourceFile const*, std::string> mapping;
  2967. for (std::vector<cmSourceFile const*>::const_iterator it =
  2968. objectSources.begin();
  2969. it != objectSources.end(); ++it) {
  2970. mapping[*it];
  2971. }
  2972. this->LocalGenerator->ComputeObjectFilenames(mapping, this);
  2973. for (std::vector<cmSourceFile const*>::const_iterator it =
  2974. objectSources.begin();
  2975. it != objectSources.end(); ++it) {
  2976. // Find the object file name corresponding to this source file.
  2977. std::map<cmSourceFile const*, std::string>::const_iterator map_it =
  2978. mapping.find(*it);
  2979. // It must exist because we populated the mapping just above.
  2980. assert(!map_it->second.empty());
  2981. objects.push_back(map_it->second);
  2982. }
  2983. }
  2984. bool cmGeneratorTarget::StrictTargetComparison::operator()(
  2985. cmGeneratorTarget const* t1, cmGeneratorTarget const* t2) const
  2986. {
  2987. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  2988. if (nameResult == 0) {
  2989. return strcmp(t1->GetLocalGenerator()->GetCurrentBinaryDirectory(),
  2990. t2->GetLocalGenerator()->GetCurrentBinaryDirectory()) < 0;
  2991. }
  2992. return nameResult < 0;
  2993. }
  2994. struct cmGeneratorTarget::SourceFileFlags
  2995. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  2996. {
  2997. struct SourceFileFlags flags;
  2998. this->ConstructSourceFileFlags();
  2999. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  3000. this->SourceFlagsMap.find(sf);
  3001. if (si != this->SourceFlagsMap.end()) {
  3002. flags = si->second;
  3003. } else {
  3004. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  3005. // were not listed in one of the other lists.
  3006. if (const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION")) {
  3007. flags.MacFolder = location;
  3008. const bool stripResources =
  3009. this->GlobalGenerator->ShouldStripResourcePath(this->Makefile);
  3010. if (strcmp(location, "Resources") == 0) {
  3011. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  3012. if (stripResources) {
  3013. flags.MacFolder = "";
  3014. }
  3015. } else if (cmSystemTools::StringStartsWith(location, "Resources/")) {
  3016. flags.Type = cmGeneratorTarget::SourceFileTypeDeepResource;
  3017. if (stripResources) {
  3018. flags.MacFolder += strlen("Resources/");
  3019. }
  3020. } else {
  3021. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  3022. }
  3023. }
  3024. }
  3025. return flags;
  3026. }
  3027. void cmGeneratorTarget::ConstructSourceFileFlags() const
  3028. {
  3029. if (this->SourceFileFlagsConstructed) {
  3030. return;
  3031. }
  3032. this->SourceFileFlagsConstructed = true;
  3033. // Process public headers to mark the source files.
  3034. if (const char* files = this->GetProperty("PUBLIC_HEADER")) {
  3035. std::vector<std::string> relFiles;
  3036. cmSystemTools::ExpandListArgument(files, relFiles);
  3037. for (std::vector<std::string>::iterator it = relFiles.begin();
  3038. it != relFiles.end(); ++it) {
  3039. if (cmSourceFile* sf = this->Makefile->GetSource(*it)) {
  3040. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3041. flags.MacFolder = "Headers";
  3042. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  3043. }
  3044. }
  3045. }
  3046. // Process private headers after public headers so that they take
  3047. // precedence if a file is listed in both.
  3048. if (const char* files = this->GetProperty("PRIVATE_HEADER")) {
  3049. std::vector<std::string> relFiles;
  3050. cmSystemTools::ExpandListArgument(files, relFiles);
  3051. for (std::vector<std::string>::iterator it = relFiles.begin();
  3052. it != relFiles.end(); ++it) {
  3053. if (cmSourceFile* sf = this->Makefile->GetSource(*it)) {
  3054. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3055. flags.MacFolder = "PrivateHeaders";
  3056. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  3057. }
  3058. }
  3059. }
  3060. // Mark sources listed as resources.
  3061. if (const char* files = this->GetProperty("RESOURCE")) {
  3062. std::vector<std::string> relFiles;
  3063. cmSystemTools::ExpandListArgument(files, relFiles);
  3064. for (std::vector<std::string>::iterator it = relFiles.begin();
  3065. it != relFiles.end(); ++it) {
  3066. if (cmSourceFile* sf = this->Makefile->GetSource(*it)) {
  3067. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3068. flags.MacFolder = "";
  3069. if (!this->GlobalGenerator->ShouldStripResourcePath(this->Makefile)) {
  3070. flags.MacFolder = "Resources";
  3071. }
  3072. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  3073. }
  3074. }
  3075. }
  3076. }
  3077. const cmGeneratorTarget::CompatibleInterfacesBase&
  3078. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  3079. {
  3080. cmGeneratorTarget::CompatibleInterfaces& compat =
  3081. this->CompatibleInterfacesMap[config];
  3082. if (!compat.Done) {
  3083. compat.Done = true;
  3084. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  3085. compat.PropsString.insert("AUTOUIC_OPTIONS");
  3086. std::vector<cmGeneratorTarget const*> const& deps =
  3087. this->GetLinkImplementationClosure(config);
  3088. for (std::vector<cmGeneratorTarget const*>::const_iterator li =
  3089. deps.begin();
  3090. li != deps.end(); ++li) {
  3091. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  3092. if (const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) { \
  3093. std::vector<std::string> props; \
  3094. cmSystemTools::ExpandListArgument(prop, props); \
  3095. compat.Props##x.insert(props.begin(), props.end()); \
  3096. }
  3097. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  3098. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  3099. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  3100. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  3101. #undef CM_READ_COMPATIBLE_INTERFACE
  3102. }
  3103. }
  3104. return compat;
  3105. }
  3106. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  3107. const std::string& p, const std::string& config) const
  3108. {
  3109. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3110. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3111. return false;
  3112. }
  3113. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  3114. }
  3115. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  3116. const std::string& p, const std::string& config) const
  3117. {
  3118. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3119. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3120. return false;
  3121. }
  3122. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  3123. }
  3124. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  3125. const std::string& p, const std::string& config) const
  3126. {
  3127. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3128. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3129. return false;
  3130. }
  3131. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  3132. }
  3133. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  3134. const std::string& p, const std::string& config) const
  3135. {
  3136. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3137. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3138. return false;
  3139. }
  3140. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  3141. }
  3142. enum CompatibleType
  3143. {
  3144. BoolType,
  3145. StringType,
  3146. NumberMinType,
  3147. NumberMaxType
  3148. };
  3149. template <typename PropertyType>
  3150. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3151. const std::string& prop,
  3152. const std::string& config,
  3153. CompatibleType, PropertyType*);
  3154. template <>
  3155. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3156. const std::string& prop,
  3157. const std::string& config,
  3158. CompatibleType /*unused*/,
  3159. bool* /*unused*/)
  3160. {
  3161. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  3162. }
  3163. template <>
  3164. const char* getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3165. const std::string& prop,
  3166. const std::string& config,
  3167. CompatibleType t,
  3168. const char** /*unused*/)
  3169. {
  3170. switch (t) {
  3171. case BoolType:
  3172. assert(false &&
  3173. "String compatibility check function called for boolean");
  3174. return CM_NULLPTR;
  3175. case StringType:
  3176. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  3177. case NumberMinType:
  3178. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  3179. case NumberMaxType:
  3180. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  3181. }
  3182. assert(false && "Unreachable!");
  3183. return CM_NULLPTR;
  3184. }
  3185. template <typename PropertyType>
  3186. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  3187. cmGeneratorTarget const* dependee,
  3188. const std::string& propName,
  3189. std::set<std::string>& emitted,
  3190. const std::string& config, CompatibleType t,
  3191. PropertyType* /*unused*/)
  3192. {
  3193. const char* prop = dependee->GetProperty(propName);
  3194. if (!prop) {
  3195. return;
  3196. }
  3197. std::vector<std::string> props;
  3198. cmSystemTools::ExpandListArgument(prop, props);
  3199. std::string pdir = cmSystemTools::GetCMakeRoot();
  3200. pdir += "/Help/prop_tgt/";
  3201. for (std::vector<std::string>::iterator pi = props.begin();
  3202. pi != props.end(); ++pi) {
  3203. std::string pname = cmSystemTools::HelpFileName(*pi);
  3204. std::string pfile = pdir + pname + ".rst";
  3205. if (cmSystemTools::FileExists(pfile.c_str(), true)) {
  3206. std::ostringstream e;
  3207. e << "Target \"" << dependee->GetName() << "\" has property \"" << *pi
  3208. << "\" listed in its " << propName
  3209. << " property. "
  3210. "This is not allowed. Only user-defined properties may appear "
  3211. "listed in the "
  3212. << propName << " property.";
  3213. depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
  3214. return;
  3215. }
  3216. if (emitted.insert(*pi).second) {
  3217. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config, t,
  3218. CM_NULLPTR);
  3219. if (cmSystemTools::GetErrorOccuredFlag()) {
  3220. return;
  3221. }
  3222. }
  3223. }
  3224. }
  3225. static std::string intersect(const std::set<std::string>& s1,
  3226. const std::set<std::string>& s2)
  3227. {
  3228. std::set<std::string> intersect;
  3229. std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(),
  3230. std::inserter(intersect, intersect.begin()));
  3231. if (!intersect.empty()) {
  3232. return *intersect.begin();
  3233. }
  3234. return "";
  3235. }
  3236. static std::string intersect(const std::set<std::string>& s1,
  3237. const std::set<std::string>& s2,
  3238. const std::set<std::string>& s3)
  3239. {
  3240. std::string result;
  3241. result = intersect(s1, s2);
  3242. if (!result.empty()) {
  3243. return result;
  3244. }
  3245. result = intersect(s1, s3);
  3246. if (!result.empty()) {
  3247. return result;
  3248. }
  3249. return intersect(s2, s3);
  3250. }
  3251. static std::string intersect(const std::set<std::string>& s1,
  3252. const std::set<std::string>& s2,
  3253. const std::set<std::string>& s3,
  3254. const std::set<std::string>& s4)
  3255. {
  3256. std::string result;
  3257. result = intersect(s1, s2);
  3258. if (!result.empty()) {
  3259. return result;
  3260. }
  3261. result = intersect(s1, s3);
  3262. if (!result.empty()) {
  3263. return result;
  3264. }
  3265. result = intersect(s1, s4);
  3266. if (!result.empty()) {
  3267. return result;
  3268. }
  3269. return intersect(s2, s3, s4);
  3270. }
  3271. void cmGeneratorTarget::CheckPropertyCompatibility(
  3272. cmComputeLinkInformation* info, const std::string& config) const
  3273. {
  3274. const cmComputeLinkInformation::ItemVector& deps = info->GetItems();
  3275. std::set<std::string> emittedBools;
  3276. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  3277. std::set<std::string> emittedStrings;
  3278. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  3279. std::set<std::string> emittedMinNumbers;
  3280. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  3281. std::set<std::string> emittedMaxNumbers;
  3282. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  3283. for (cmComputeLinkInformation::ItemVector::const_iterator li = deps.begin();
  3284. li != deps.end(); ++li) {
  3285. if (!li->Target) {
  3286. continue;
  3287. }
  3288. checkPropertyConsistency<bool>(this, li->Target, strBool, emittedBools,
  3289. config, BoolType, CM_NULLPTR);
  3290. if (cmSystemTools::GetErrorOccuredFlag()) {
  3291. return;
  3292. }
  3293. checkPropertyConsistency<const char*>(this, li->Target, strString,
  3294. emittedStrings, config, StringType,
  3295. CM_NULLPTR);
  3296. if (cmSystemTools::GetErrorOccuredFlag()) {
  3297. return;
  3298. }
  3299. checkPropertyConsistency<const char*>(this, li->Target, strNumMin,
  3300. emittedMinNumbers, config,
  3301. NumberMinType, CM_NULLPTR);
  3302. if (cmSystemTools::GetErrorOccuredFlag()) {
  3303. return;
  3304. }
  3305. checkPropertyConsistency<const char*>(this, li->Target, strNumMax,
  3306. emittedMaxNumbers, config,
  3307. NumberMaxType, CM_NULLPTR);
  3308. if (cmSystemTools::GetErrorOccuredFlag()) {
  3309. return;
  3310. }
  3311. }
  3312. std::string prop = intersect(emittedBools, emittedStrings, emittedMinNumbers,
  3313. emittedMaxNumbers);
  3314. if (!prop.empty()) {
  3315. // Use a sorted std::vector to keep the error message sorted.
  3316. std::vector<std::string> props;
  3317. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  3318. if (i != emittedBools.end()) {
  3319. props.push_back(strBool);
  3320. }
  3321. i = emittedStrings.find(prop);
  3322. if (i != emittedStrings.end()) {
  3323. props.push_back(strString);
  3324. }
  3325. i = emittedMinNumbers.find(prop);
  3326. if (i != emittedMinNumbers.end()) {
  3327. props.push_back(strNumMin);
  3328. }
  3329. i = emittedMaxNumbers.find(prop);
  3330. if (i != emittedMaxNumbers.end()) {
  3331. props.push_back(strNumMax);
  3332. }
  3333. std::sort(props.begin(), props.end());
  3334. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  3335. propsString += " and the " + props.back();
  3336. std::ostringstream e;
  3337. e << "Property \"" << prop << "\" appears in both the " << propsString
  3338. << " property in the dependencies of target \"" << this->GetName()
  3339. << "\". This is not allowed. A property may only require compatibility "
  3340. "in a boolean interpretation, a numeric minimum, a numeric maximum "
  3341. "or a "
  3342. "string interpretation, but not a mixture.";
  3343. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  3344. }
  3345. }
  3346. std::string compatibilityType(CompatibleType t)
  3347. {
  3348. switch (t) {
  3349. case BoolType:
  3350. return "Boolean compatibility";
  3351. case StringType:
  3352. return "String compatibility";
  3353. case NumberMaxType:
  3354. return "Numeric maximum compatibility";
  3355. case NumberMinType:
  3356. return "Numeric minimum compatibility";
  3357. }
  3358. assert(false && "Unreachable!");
  3359. return "";
  3360. }
  3361. std::string compatibilityAgree(CompatibleType t, bool dominant)
  3362. {
  3363. switch (t) {
  3364. case BoolType:
  3365. case StringType:
  3366. return dominant ? "(Disagree)\n" : "(Agree)\n";
  3367. case NumberMaxType:
  3368. case NumberMinType:
  3369. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  3370. }
  3371. assert(false && "Unreachable!");
  3372. return "";
  3373. }
  3374. template <typename PropertyType>
  3375. PropertyType getTypedProperty(cmGeneratorTarget const* tgt,
  3376. const std::string& prop);
  3377. template <>
  3378. bool getTypedProperty<bool>(cmGeneratorTarget const* tgt,
  3379. const std::string& prop)
  3380. {
  3381. return tgt->GetPropertyAsBool(prop);
  3382. }
  3383. template <>
  3384. const char* getTypedProperty<const char*>(cmGeneratorTarget const* tgt,
  3385. const std::string& prop)
  3386. {
  3387. return tgt->GetProperty(prop);
  3388. }
  3389. template <typename PropertyType>
  3390. std::string valueAsString(PropertyType);
  3391. template <>
  3392. std::string valueAsString<bool>(bool value)
  3393. {
  3394. return value ? "TRUE" : "FALSE";
  3395. }
  3396. template <>
  3397. std::string valueAsString<const char*>(const char* value)
  3398. {
  3399. return value ? value : "(unset)";
  3400. }
  3401. template <typename PropertyType>
  3402. PropertyType impliedValue(PropertyType);
  3403. template <>
  3404. bool impliedValue<bool>(bool /*unused*/)
  3405. {
  3406. return false;
  3407. }
  3408. template <>
  3409. const char* impliedValue<const char*>(const char* /*unused*/)
  3410. {
  3411. return "";
  3412. }
  3413. template <typename PropertyType>
  3414. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  3415. PropertyType rhs,
  3416. CompatibleType t);
  3417. template <>
  3418. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  3419. CompatibleType /*unused*/)
  3420. {
  3421. return std::make_pair(lhs == rhs, lhs);
  3422. }
  3423. std::pair<bool, const char*> consistentStringProperty(const char* lhs,
  3424. const char* rhs)
  3425. {
  3426. const bool b = strcmp(lhs, rhs) == 0;
  3427. return std::make_pair(b, b ? lhs : CM_NULLPTR);
  3428. }
  3429. std::pair<bool, const char*> consistentNumberProperty(const char* lhs,
  3430. const char* rhs,
  3431. CompatibleType t)
  3432. {
  3433. char* pEnd;
  3434. const char* const null_ptr = CM_NULLPTR;
  3435. long lnum = strtol(lhs, &pEnd, 0);
  3436. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) {
  3437. return std::pair<bool, const char*>(false, null_ptr);
  3438. }
  3439. long rnum = strtol(rhs, &pEnd, 0);
  3440. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE) {
  3441. return std::pair<bool, const char*>(false, null_ptr);
  3442. }
  3443. if (t == NumberMaxType) {
  3444. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  3445. }
  3446. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  3447. }
  3448. template <>
  3449. std::pair<bool, const char*> consistentProperty(const char* lhs,
  3450. const char* rhs,
  3451. CompatibleType t)
  3452. {
  3453. if (!lhs && !rhs) {
  3454. return std::make_pair(true, lhs);
  3455. }
  3456. if (!lhs) {
  3457. return std::make_pair(true, rhs);
  3458. }
  3459. if (!rhs) {
  3460. return std::make_pair(true, lhs);
  3461. }
  3462. const char* const null_ptr = CM_NULLPTR;
  3463. switch (t) {
  3464. case BoolType:
  3465. assert(false && "consistentProperty for strings called with BoolType");
  3466. return std::pair<bool, const char*>(false, null_ptr);
  3467. case StringType:
  3468. return consistentStringProperty(lhs, rhs);
  3469. case NumberMinType:
  3470. case NumberMaxType:
  3471. return consistentNumberProperty(lhs, rhs, t);
  3472. }
  3473. assert(false && "Unreachable!");
  3474. return std::pair<bool, const char*>(false, null_ptr);
  3475. }
  3476. template <typename PropertyType>
  3477. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  3478. const std::string& p,
  3479. const std::string& config,
  3480. const char* defaultValue,
  3481. CompatibleType t,
  3482. PropertyType* /*unused*/)
  3483. {
  3484. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
  3485. std::vector<std::string> headPropKeys = tgt->GetPropertyKeys();
  3486. const bool explicitlySet =
  3487. std::find(headPropKeys.begin(), headPropKeys.end(), p) !=
  3488. headPropKeys.end();
  3489. const bool impliedByUse = tgt->IsNullImpliedByLinkLibraries(p);
  3490. assert((impliedByUse ^ explicitlySet) || (!impliedByUse && !explicitlySet));
  3491. std::vector<cmGeneratorTarget const*> const& deps =
  3492. tgt->GetLinkImplementationClosure(config);
  3493. if (deps.empty()) {
  3494. return propContent;
  3495. }
  3496. bool propInitialized = explicitlySet;
  3497. std::string report = " * Target \"";
  3498. report += tgt->GetName();
  3499. if (explicitlySet) {
  3500. report += "\" has property content \"";
  3501. report += valueAsString<PropertyType>(propContent);
  3502. report += "\"\n";
  3503. } else if (impliedByUse) {
  3504. report += "\" property is implied by use.\n";
  3505. } else {
  3506. report += "\" property not set.\n";
  3507. }
  3508. std::string interfaceProperty = "INTERFACE_" + p;
  3509. for (std::vector<cmGeneratorTarget const*>::const_iterator li = deps.begin();
  3510. li != deps.end(); ++li) {
  3511. // An error should be reported if one dependency
  3512. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  3513. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  3514. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  3515. // with a dependency.
  3516. cmGeneratorTarget const* theTarget = *li;
  3517. std::vector<std::string> propKeys = theTarget->GetPropertyKeys();
  3518. const bool ifaceIsSet = std::find(propKeys.begin(), propKeys.end(),
  3519. interfaceProperty) != propKeys.end();
  3520. PropertyType ifacePropContent =
  3521. getTypedProperty<PropertyType>(theTarget, interfaceProperty);
  3522. std::string reportEntry;
  3523. if (ifaceIsSet) {
  3524. reportEntry += " * Target \"";
  3525. reportEntry += theTarget->GetName();
  3526. reportEntry += "\" property value \"";
  3527. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  3528. reportEntry += "\" ";
  3529. }
  3530. if (explicitlySet) {
  3531. if (ifaceIsSet) {
  3532. std::pair<bool, PropertyType> consistent =
  3533. consistentProperty(propContent, ifacePropContent, t);
  3534. report += reportEntry;
  3535. report += compatibilityAgree(t, propContent != consistent.second);
  3536. if (!consistent.first) {
  3537. std::ostringstream e;
  3538. e << "Property " << p << " on target \"" << tgt->GetName()
  3539. << "\" does\nnot match the "
  3540. "INTERFACE_"
  3541. << p << " property requirement\nof "
  3542. "dependency \""
  3543. << theTarget->GetName() << "\".\n";
  3544. cmSystemTools::Error(e.str().c_str());
  3545. break;
  3546. }
  3547. propContent = consistent.second;
  3548. continue;
  3549. }
  3550. // Explicitly set on target and not set in iface. Can't disagree.
  3551. continue;
  3552. }
  3553. if (impliedByUse) {
  3554. propContent = impliedValue<PropertyType>(propContent);
  3555. if (ifaceIsSet) {
  3556. std::pair<bool, PropertyType> consistent =
  3557. consistentProperty(propContent, ifacePropContent, t);
  3558. report += reportEntry;
  3559. report += compatibilityAgree(t, propContent != consistent.second);
  3560. if (!consistent.first) {
  3561. std::ostringstream e;
  3562. e << "Property " << p << " on target \"" << tgt->GetName()
  3563. << "\" is\nimplied to be " << defaultValue
  3564. << " because it was used to determine the link libraries\n"
  3565. "already. The INTERFACE_"
  3566. << p << " property on\ndependency \"" << theTarget->GetName()
  3567. << "\" is in conflict.\n";
  3568. cmSystemTools::Error(e.str().c_str());
  3569. break;
  3570. }
  3571. propContent = consistent.second;
  3572. continue;
  3573. }
  3574. // Implicitly set on target and not set in iface. Can't disagree.
  3575. continue;
  3576. }
  3577. if (ifaceIsSet) {
  3578. if (propInitialized) {
  3579. std::pair<bool, PropertyType> consistent =
  3580. consistentProperty(propContent, ifacePropContent, t);
  3581. report += reportEntry;
  3582. report += compatibilityAgree(t, propContent != consistent.second);
  3583. if (!consistent.first) {
  3584. std::ostringstream e;
  3585. e << "The INTERFACE_" << p << " property of \""
  3586. << theTarget->GetName() << "\" does\nnot agree with the value of "
  3587. << p << " already determined\nfor \"" << tgt->GetName() << "\".\n";
  3588. cmSystemTools::Error(e.str().c_str());
  3589. break;
  3590. }
  3591. propContent = consistent.second;
  3592. continue;
  3593. }
  3594. report += reportEntry + "(Interface set)\n";
  3595. propContent = ifacePropContent;
  3596. propInitialized = true;
  3597. } else {
  3598. // Not set. Nothing to agree on.
  3599. continue;
  3600. }
  3601. }
  3602. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  3603. report, compatibilityType(t));
  3604. return propContent;
  3605. }
  3606. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  3607. const std::string& p, const std::string& config) const
  3608. {
  3609. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  3610. BoolType, CM_NULLPTR);
  3611. }
  3612. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  3613. const std::string& p, const std::string& config) const
  3614. {
  3615. return checkInterfacePropertyCompatibility<const char*>(
  3616. this, p, config, "empty", StringType, CM_NULLPTR);
  3617. }
  3618. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  3619. const std::string& p, const std::string& config) const
  3620. {
  3621. return checkInterfacePropertyCompatibility<const char*>(
  3622. this, p, config, "empty", NumberMinType, CM_NULLPTR);
  3623. }
  3624. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  3625. const std::string& p, const std::string& config) const
  3626. {
  3627. return checkInterfacePropertyCompatibility<const char*>(
  3628. this, p, config, "empty", NumberMaxType, CM_NULLPTR);
  3629. }
  3630. cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
  3631. const std::string& config) const
  3632. {
  3633. // Lookup any existing information for this configuration.
  3634. std::string key(cmSystemTools::UpperCase(config));
  3635. cmTargetLinkInformationMap::iterator i = this->LinkInformation.find(key);
  3636. if (i == this->LinkInformation.end()) {
  3637. // Compute information for this configuration.
  3638. cmComputeLinkInformation* info =
  3639. new cmComputeLinkInformation(this, config);
  3640. if (!info || !info->Compute()) {
  3641. delete info;
  3642. info = CM_NULLPTR;
  3643. }
  3644. // Store the information for this configuration.
  3645. cmTargetLinkInformationMap::value_type entry(key, info);
  3646. i = this->LinkInformation.insert(entry).first;
  3647. if (info) {
  3648. this->CheckPropertyCompatibility(info, config);
  3649. }
  3650. }
  3651. return i->second;
  3652. }
  3653. void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
  3654. {
  3655. int patch;
  3656. this->GetTargetVersion(false, major, minor, patch);
  3657. }
  3658. void cmGeneratorTarget::GetTargetVersion(bool soversion, int& major,
  3659. int& minor, int& patch) const
  3660. {
  3661. // Set the default values.
  3662. major = 0;
  3663. minor = 0;
  3664. patch = 0;
  3665. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  3666. // Look for a VERSION or SOVERSION property.
  3667. const char* prop = soversion ? "SOVERSION" : "VERSION";
  3668. if (const char* version = this->GetProperty(prop)) {
  3669. // Try to parse the version number and store the results that were
  3670. // successfully parsed.
  3671. int parsed_major;
  3672. int parsed_minor;
  3673. int parsed_patch;
  3674. switch (sscanf(version, "%d.%d.%d", &parsed_major, &parsed_minor,
  3675. &parsed_patch)) {
  3676. case 3:
  3677. patch = parsed_patch; // no break!
  3678. case 2:
  3679. minor = parsed_minor; // no break!
  3680. case 1:
  3681. major = parsed_major; // no break!
  3682. default:
  3683. break;
  3684. }
  3685. }
  3686. }
  3687. std::string cmGeneratorTarget::GetFortranModuleDirectory(
  3688. std::string const& working_dir) const
  3689. {
  3690. if (!this->FortranModuleDirectoryCreated) {
  3691. this->FortranModuleDirectory =
  3692. this->CreateFortranModuleDirectory(working_dir);
  3693. this->FortranModuleDirectoryCreated = true;
  3694. }
  3695. return this->FortranModuleDirectory;
  3696. }
  3697. std::string cmGeneratorTarget::CreateFortranModuleDirectory(
  3698. std::string const& working_dir) const
  3699. {
  3700. std::string mod_dir;
  3701. std::string target_mod_dir;
  3702. if (const char* prop = this->GetProperty("Fortran_MODULE_DIRECTORY")) {
  3703. target_mod_dir = prop;
  3704. } else {
  3705. std::string const& default_mod_dir =
  3706. this->LocalGenerator->GetCurrentBinaryDirectory();
  3707. if (default_mod_dir != working_dir) {
  3708. target_mod_dir = default_mod_dir;
  3709. }
  3710. }
  3711. const char* moddir_flag =
  3712. this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
  3713. if (!target_mod_dir.empty() && moddir_flag) {
  3714. // Compute the full path to the module directory.
  3715. if (cmSystemTools::FileIsFullPath(target_mod_dir)) {
  3716. // Already a full path.
  3717. mod_dir = target_mod_dir;
  3718. } else {
  3719. // Interpret relative to the current output directory.
  3720. mod_dir = this->LocalGenerator->GetCurrentBinaryDirectory();
  3721. mod_dir += "/";
  3722. mod_dir += target_mod_dir;
  3723. }
  3724. // Make sure the module output directory exists.
  3725. cmSystemTools::MakeDirectory(mod_dir);
  3726. }
  3727. return mod_dir;
  3728. }
  3729. std::string cmGeneratorTarget::GetFrameworkVersion() const
  3730. {
  3731. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  3732. if (const char* fversion = this->GetProperty("FRAMEWORK_VERSION")) {
  3733. return fversion;
  3734. }
  3735. if (const char* tversion = this->GetProperty("VERSION")) {
  3736. return tversion;
  3737. }
  3738. return "A";
  3739. }
  3740. void cmGeneratorTarget::ComputeVersionedName(std::string& vName,
  3741. std::string const& prefix,
  3742. std::string const& base,
  3743. std::string const& suffix,
  3744. std::string const& name,
  3745. const char* version) const
  3746. {
  3747. vName = this->Makefile->IsOn("APPLE") ? (prefix + base) : name;
  3748. if (version) {
  3749. vName += ".";
  3750. vName += version;
  3751. }
  3752. vName += this->Makefile->IsOn("APPLE") ? suffix : std::string();
  3753. }
  3754. std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const
  3755. {
  3756. cmPropertyMap const& propsObject = this->Target->GetProperties();
  3757. std::vector<std::string> props;
  3758. props.reserve(propsObject.size());
  3759. for (cmPropertyMap::const_iterator it = propsObject.begin();
  3760. it != propsObject.end(); ++it) {
  3761. props.push_back(it->first);
  3762. }
  3763. return props;
  3764. }
  3765. void cmGeneratorTarget::ReportPropertyOrigin(
  3766. const std::string& p, const std::string& result, const std::string& report,
  3767. const std::string& compatibilityType) const
  3768. {
  3769. std::vector<std::string> debugProperties;
  3770. const char* debugProp = this->Target->GetMakefile()->GetDefinition(
  3771. "CMAKE_DEBUG_TARGET_PROPERTIES");
  3772. if (debugProp) {
  3773. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  3774. }
  3775. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p] &&
  3776. std::find(debugProperties.begin(), debugProperties.end(), p) !=
  3777. debugProperties.end();
  3778. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3779. this->DebugCompatiblePropertiesDone[p] = true;
  3780. }
  3781. if (!debugOrigin) {
  3782. return;
  3783. }
  3784. std::string areport = compatibilityType;
  3785. areport += std::string(" of property \"") + p + "\" for target \"";
  3786. areport += std::string(this->GetName());
  3787. areport += "\" (result: \"";
  3788. areport += result;
  3789. areport += "\"):\n" + report;
  3790. this->LocalGenerator->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  3791. }
  3792. void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
  3793. std::vector<cmLinkItem>& items) const
  3794. {
  3795. for (std::vector<std::string>::const_iterator i = names.begin();
  3796. i != names.end(); ++i) {
  3797. std::string name = this->CheckCMP0004(*i);
  3798. if (name == this->GetName() || name.empty()) {
  3799. continue;
  3800. }
  3801. items.push_back(cmLinkItem(name, this->FindTargetToLink(name)));
  3802. }
  3803. }
  3804. void cmGeneratorTarget::ExpandLinkItems(
  3805. std::string const& prop, std::string const& value, std::string const& config,
  3806. cmGeneratorTarget const* headTarget, bool usage_requirements_only,
  3807. std::vector<cmLinkItem>& items, bool& hadHeadSensitiveCondition) const
  3808. {
  3809. cmGeneratorExpression ge;
  3810. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, CM_NULLPTR,
  3811. CM_NULLPTR);
  3812. // The $<LINK_ONLY> expression may be in a link interface to specify private
  3813. // link dependencies that are otherwise excluded from usage requirements.
  3814. if (usage_requirements_only) {
  3815. dagChecker.SetTransitivePropertiesOnly();
  3816. }
  3817. std::vector<std::string> libs;
  3818. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  3819. cmSystemTools::ExpandListArgument(cge->Evaluate(this->LocalGenerator, config,
  3820. false, headTarget, this,
  3821. &dagChecker),
  3822. libs);
  3823. this->LookupLinkItems(libs, items);
  3824. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  3825. }
  3826. cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
  3827. const std::string& config, cmGeneratorTarget const* head) const
  3828. {
  3829. // Imported targets have their own link interface.
  3830. if (this->IsImported()) {
  3831. return this->GetImportLinkInterface(config, head, false);
  3832. }
  3833. // Link interfaces are not supported for executables that do not
  3834. // export symbols.
  3835. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  3836. !this->IsExecutableWithExports()) {
  3837. return CM_NULLPTR;
  3838. }
  3839. // Lookup any existing link interface for this configuration.
  3840. cmHeadToLinkInterfaceMap& hm = this->GetHeadToLinkInterfaceMap(config);
  3841. // If the link interface does not depend on the head target
  3842. // then return the one we computed first.
  3843. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  3844. return &hm.begin()->second;
  3845. }
  3846. cmOptionalLinkInterface& iface = hm[head];
  3847. if (!iface.LibrariesDone) {
  3848. iface.LibrariesDone = true;
  3849. this->ComputeLinkInterfaceLibraries(config, iface, head, false);
  3850. }
  3851. if (!iface.AllDone) {
  3852. iface.AllDone = true;
  3853. if (iface.Exists) {
  3854. this->ComputeLinkInterface(config, iface, head);
  3855. }
  3856. }
  3857. return iface.Exists ? &iface : CM_NULLPTR;
  3858. }
  3859. void cmGeneratorTarget::ComputeLinkInterface(
  3860. const std::string& config, cmOptionalLinkInterface& iface,
  3861. cmGeneratorTarget const* headTarget) const
  3862. {
  3863. if (iface.ExplicitLibraries) {
  3864. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  3865. this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  3866. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3867. // Shared libraries may have runtime implementation dependencies
  3868. // on other shared libraries that are not in the interface.
  3869. CM_UNORDERED_SET<std::string> emitted;
  3870. for (std::vector<cmLinkItem>::const_iterator li =
  3871. iface.Libraries.begin();
  3872. li != iface.Libraries.end(); ++li) {
  3873. emitted.insert(*li);
  3874. }
  3875. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  3876. cmLinkImplementation const* impl = this->GetLinkImplementation(config);
  3877. for (std::vector<cmLinkImplItem>::const_iterator li =
  3878. impl->Libraries.begin();
  3879. li != impl->Libraries.end(); ++li) {
  3880. if (emitted.insert(*li).second) {
  3881. if (li->Target) {
  3882. // This is a runtime dependency on another shared library.
  3883. if (li->Target->GetType() == cmStateEnums::SHARED_LIBRARY) {
  3884. iface.SharedDeps.push_back(*li);
  3885. }
  3886. } else {
  3887. // TODO: Recognize shared library file names. Perhaps this
  3888. // should be moved to cmComputeLinkInformation, but that creates
  3889. // a chicken-and-egg problem since this list is needed for its
  3890. // construction.
  3891. }
  3892. }
  3893. }
  3894. }
  3895. }
  3896. } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
  3897. this->GetPolicyStatusCMP0022() == cmPolicies::OLD) {
  3898. // The link implementation is the default link interface.
  3899. cmLinkImplementationLibraries const* impl =
  3900. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  3901. iface.ImplementationIsInterface = true;
  3902. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  3903. }
  3904. if (this->LinkLanguagePropagatesToDependents()) {
  3905. // Targets using this archive need its language runtime libraries.
  3906. if (cmLinkImplementation const* impl =
  3907. this->GetLinkImplementation(config)) {
  3908. iface.Languages = impl->Languages;
  3909. }
  3910. }
  3911. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  3912. // Construct the property name suffix for this configuration.
  3913. std::string suffix = "_";
  3914. if (!config.empty()) {
  3915. suffix += cmSystemTools::UpperCase(config);
  3916. } else {
  3917. suffix += "NOCONFIG";
  3918. }
  3919. // How many repetitions are needed if this library has cyclic
  3920. // dependencies?
  3921. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  3922. propName += suffix;
  3923. if (const char* config_reps = this->GetProperty(propName)) {
  3924. sscanf(config_reps, "%u", &iface.Multiplicity);
  3925. } else if (const char* reps =
  3926. this->GetProperty("LINK_INTERFACE_MULTIPLICITY")) {
  3927. sscanf(reps, "%u", &iface.Multiplicity);
  3928. }
  3929. }
  3930. }
  3931. const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
  3932. const std::string& config, cmGeneratorTarget const* head,
  3933. bool usage_requirements_only) const
  3934. {
  3935. // Imported targets have their own link interface.
  3936. if (this->IsImported()) {
  3937. return this->GetImportLinkInterface(config, head, usage_requirements_only);
  3938. }
  3939. // Link interfaces are not supported for executables that do not
  3940. // export symbols.
  3941. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  3942. !this->IsExecutableWithExports()) {
  3943. return CM_NULLPTR;
  3944. }
  3945. // Lookup any existing link interface for this configuration.
  3946. std::string CONFIG = cmSystemTools::UpperCase(config);
  3947. cmHeadToLinkInterfaceMap& hm =
  3948. (usage_requirements_only
  3949. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  3950. : this->GetHeadToLinkInterfaceMap(config));
  3951. // If the link interface does not depend on the head target
  3952. // then return the one we computed first.
  3953. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  3954. return &hm.begin()->second;
  3955. }
  3956. cmOptionalLinkInterface& iface = hm[head];
  3957. if (!iface.LibrariesDone) {
  3958. iface.LibrariesDone = true;
  3959. this->ComputeLinkInterfaceLibraries(config, iface, head,
  3960. usage_requirements_only);
  3961. }
  3962. return iface.Exists ? &iface : CM_NULLPTR;
  3963. }
  3964. std::string cmGeneratorTarget::GetDirectory(
  3965. const std::string& config, cmStateEnums::ArtifactType artifact) const
  3966. {
  3967. if (this->IsImported()) {
  3968. // Return the directory from which the target is imported.
  3969. return cmSystemTools::GetFilenamePath(
  3970. this->Target->ImportedGetFullPath(config, artifact));
  3971. }
  3972. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  3973. // Return the directory in which the target will be built.
  3974. switch (artifact) {
  3975. case cmStateEnums::RuntimeBinaryArtifact:
  3976. return info->OutDir;
  3977. case cmStateEnums::ImportLibraryArtifact:
  3978. return info->ImpDir;
  3979. }
  3980. }
  3981. return "";
  3982. }
  3983. bool cmGeneratorTarget::UsesDefaultOutputDir(
  3984. const std::string& config, cmStateEnums::ArtifactType artifact) const
  3985. {
  3986. std::string dir;
  3987. return this->ComputeOutputDir(config, artifact, dir);
  3988. }
  3989. cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
  3990. const std::string& config) const
  3991. {
  3992. // There is no output information for imported targets.
  3993. if (this->IsImported()) {
  3994. return CM_NULLPTR;
  3995. }
  3996. // Only libraries and executables have well-defined output files.
  3997. if (!this->HaveWellDefinedOutputFiles()) {
  3998. std::string msg = "cmGeneratorTarget::GetOutputInfo called for ";
  3999. msg += this->GetName();
  4000. msg += " which has type ";
  4001. msg += cmState::GetTargetTypeName(this->GetType());
  4002. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  4003. return CM_NULLPTR;
  4004. }
  4005. // Lookup/compute/cache the output information for this configuration.
  4006. std::string config_upper;
  4007. if (!config.empty()) {
  4008. config_upper = cmSystemTools::UpperCase(config);
  4009. }
  4010. OutputInfoMapType::iterator i = this->OutputInfoMap.find(config_upper);
  4011. if (i == this->OutputInfoMap.end()) {
  4012. // Add empty info in map to detect potential recursion.
  4013. OutputInfo info;
  4014. OutputInfoMapType::value_type entry(config_upper, info);
  4015. i = this->OutputInfoMap.insert(entry).first;
  4016. // Compute output directories.
  4017. this->ComputeOutputDir(config, cmStateEnums::RuntimeBinaryArtifact,
  4018. info.OutDir);
  4019. this->ComputeOutputDir(config, cmStateEnums::ImportLibraryArtifact,
  4020. info.ImpDir);
  4021. if (!this->ComputePDBOutputDir("PDB", config, info.PdbDir)) {
  4022. info.PdbDir = info.OutDir;
  4023. }
  4024. // Now update the previously-prepared map entry.
  4025. i->second = info;
  4026. } else if (i->second.empty()) {
  4027. // An empty map entry indicates we have been called recursively
  4028. // from the above block.
  4029. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  4030. cmake::FATAL_ERROR,
  4031. "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
  4032. this->GetBacktrace());
  4033. return CM_NULLPTR;
  4034. }
  4035. return &i->second;
  4036. }
  4037. bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
  4038. cmStateEnums::ArtifactType artifact,
  4039. std::string& out) const
  4040. {
  4041. bool usesDefaultOutputDir = false;
  4042. std::string conf = config;
  4043. // Look for a target property defining the target output directory
  4044. // based on the target type.
  4045. std::string targetTypeName = this->GetOutputTargetType(artifact);
  4046. const char* propertyName = CM_NULLPTR;
  4047. std::string propertyNameStr = targetTypeName;
  4048. if (!propertyNameStr.empty()) {
  4049. propertyNameStr += "_OUTPUT_DIRECTORY";
  4050. propertyName = propertyNameStr.c_str();
  4051. }
  4052. // Check for a per-configuration output directory target property.
  4053. std::string configUpper = cmSystemTools::UpperCase(conf);
  4054. const char* configProp = CM_NULLPTR;
  4055. std::string configPropStr = targetTypeName;
  4056. if (!configPropStr.empty()) {
  4057. configPropStr += "_OUTPUT_DIRECTORY_";
  4058. configPropStr += configUpper;
  4059. configProp = configPropStr.c_str();
  4060. }
  4061. // Select an output directory.
  4062. if (const char* config_outdir = this->GetProperty(configProp)) {
  4063. // Use the user-specified per-configuration output directory.
  4064. cmGeneratorExpression ge;
  4065. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(config_outdir);
  4066. out = cge->Evaluate(this->LocalGenerator, config);
  4067. // Skip per-configuration subdirectory.
  4068. conf = "";
  4069. } else if (const char* outdir = this->GetProperty(propertyName)) {
  4070. // Use the user-specified output directory.
  4071. cmGeneratorExpression ge;
  4072. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(outdir);
  4073. out = cge->Evaluate(this->LocalGenerator, config);
  4074. // Skip per-configuration subdirectory if the value contained a
  4075. // generator expression.
  4076. if (out != outdir) {
  4077. conf = "";
  4078. }
  4079. } else if (this->GetType() == cmStateEnums::EXECUTABLE) {
  4080. // Lookup the output path for executables.
  4081. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  4082. } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  4083. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4084. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  4085. // Lookup the output path for libraries.
  4086. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  4087. }
  4088. if (out.empty()) {
  4089. // Default to the current output directory.
  4090. usesDefaultOutputDir = true;
  4091. out = ".";
  4092. }
  4093. // Convert the output path to a full path in case it is
  4094. // specified as a relative path. Treat a relative path as
  4095. // relative to the current output directory for this makefile.
  4096. out = (cmSystemTools::CollapseFullPath(
  4097. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  4098. // The generator may add the configuration's subdirectory.
  4099. if (!conf.empty()) {
  4100. bool useEPN =
  4101. this->GlobalGenerator->UseEffectivePlatformName(this->Makefile);
  4102. std::string suffix =
  4103. usesDefaultOutputDir && useEPN ? "${EFFECTIVE_PLATFORM_NAME}" : "";
  4104. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  4105. "/", conf, suffix, out);
  4106. }
  4107. return usesDefaultOutputDir;
  4108. }
  4109. bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
  4110. const std::string& config,
  4111. std::string& out) const
  4112. {
  4113. // Look for a target property defining the target output directory
  4114. // based on the target type.
  4115. const char* propertyName = CM_NULLPTR;
  4116. std::string propertyNameStr = kind;
  4117. if (!propertyNameStr.empty()) {
  4118. propertyNameStr += "_OUTPUT_DIRECTORY";
  4119. propertyName = propertyNameStr.c_str();
  4120. }
  4121. std::string conf = config;
  4122. // Check for a per-configuration output directory target property.
  4123. std::string configUpper = cmSystemTools::UpperCase(conf);
  4124. const char* configProp = CM_NULLPTR;
  4125. std::string configPropStr = kind;
  4126. if (!configPropStr.empty()) {
  4127. configPropStr += "_OUTPUT_DIRECTORY_";
  4128. configPropStr += configUpper;
  4129. configProp = configPropStr.c_str();
  4130. }
  4131. // Select an output directory.
  4132. if (const char* config_outdir = this->GetProperty(configProp)) {
  4133. // Use the user-specified per-configuration output directory.
  4134. out = config_outdir;
  4135. // Skip per-configuration subdirectory.
  4136. conf = "";
  4137. } else if (const char* outdir = this->GetProperty(propertyName)) {
  4138. // Use the user-specified output directory.
  4139. out = outdir;
  4140. }
  4141. if (out.empty()) {
  4142. return false;
  4143. }
  4144. // Convert the output path to a full path in case it is
  4145. // specified as a relative path. Treat a relative path as
  4146. // relative to the current output directory for this makefile.
  4147. out = (cmSystemTools::CollapseFullPath(
  4148. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  4149. // The generator may add the configuration's subdirectory.
  4150. if (!conf.empty()) {
  4151. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  4152. "/", conf, "", out);
  4153. }
  4154. return true;
  4155. }
  4156. bool cmGeneratorTarget::HaveInstallTreeRPATH() const
  4157. {
  4158. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  4159. return (install_rpath && *install_rpath) &&
  4160. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  4161. }
  4162. void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  4163. const std::string& config, cmOptionalLinkInterface& iface,
  4164. cmGeneratorTarget const* headTarget, bool usage_requirements_only) const
  4165. {
  4166. // Construct the property name suffix for this configuration.
  4167. std::string suffix = "_";
  4168. if (!config.empty()) {
  4169. suffix += cmSystemTools::UpperCase(config);
  4170. } else {
  4171. suffix += "NOCONFIG";
  4172. }
  4173. // An explicit list of interface libraries may be set for shared
  4174. // libraries and executables that export symbols.
  4175. const char* explicitLibraries = CM_NULLPTR;
  4176. std::string linkIfaceProp;
  4177. if (this->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  4178. this->GetPolicyStatusCMP0022() != cmPolicies::WARN) {
  4179. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  4180. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  4181. explicitLibraries = this->GetProperty(linkIfaceProp);
  4182. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4183. this->IsExecutableWithExports()) {
  4184. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  4185. // shared lib or executable.
  4186. // Lookup the per-configuration property.
  4187. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4188. linkIfaceProp += suffix;
  4189. explicitLibraries = this->GetProperty(linkIfaceProp);
  4190. // If not set, try the generic property.
  4191. if (!explicitLibraries) {
  4192. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4193. explicitLibraries = this->GetProperty(linkIfaceProp);
  4194. }
  4195. }
  4196. if (explicitLibraries &&
  4197. this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4198. !this->PolicyWarnedCMP0022) {
  4199. // Compare the explicitly set old link interface properties to the
  4200. // preferred new link interface property one and warn if different.
  4201. const char* newExplicitLibraries =
  4202. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  4203. if (newExplicitLibraries &&
  4204. strcmp(newExplicitLibraries, explicitLibraries) != 0) {
  4205. std::ostringstream w;
  4206. /* clang-format off */
  4207. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4208. "Target \"" << this->GetName() << "\" has an "
  4209. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  4210. linkIfaceProp << " properties."
  4211. "\n"
  4212. "INTERFACE_LINK_LIBRARIES:\n"
  4213. " " << newExplicitLibraries << "\n" <<
  4214. linkIfaceProp << ":\n"
  4215. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  4216. /* clang-format on */
  4217. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  4218. this->PolicyWarnedCMP0022 = true;
  4219. }
  4220. }
  4221. // There is no implicit link interface for executables or modules
  4222. // so if none was explicitly set then there is no link interface.
  4223. if (!explicitLibraries &&
  4224. (this->GetType() == cmStateEnums::EXECUTABLE ||
  4225. (this->GetType() == cmStateEnums::MODULE_LIBRARY))) {
  4226. return;
  4227. }
  4228. iface.Exists = true;
  4229. iface.ExplicitLibraries = explicitLibraries;
  4230. if (explicitLibraries) {
  4231. // The interface libraries have been explicitly set.
  4232. this->ExpandLinkItems(linkIfaceProp, explicitLibraries, config, headTarget,
  4233. usage_requirements_only, iface.Libraries,
  4234. iface.HadHeadSensitiveCondition);
  4235. } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
  4236. this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  4237. // If CMP0022 is NEW then the plain tll signature sets the
  4238. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  4239. // cleared the property explicitly and we should not fall back
  4240. // to the link implementation.
  4241. {
  4242. // The link implementation is the default link interface.
  4243. cmLinkImplementationLibraries const* impl =
  4244. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  4245. iface.Libraries.insert(iface.Libraries.end(), impl->Libraries.begin(),
  4246. impl->Libraries.end());
  4247. if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4248. !this->PolicyWarnedCMP0022 && !usage_requirements_only) {
  4249. // Compare the link implementation fallback link interface to the
  4250. // preferred new link interface property and warn if different.
  4251. std::vector<cmLinkItem> ifaceLibs;
  4252. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  4253. if (const char* newExplicitLibraries = this->GetProperty(newProp)) {
  4254. bool hadHeadSensitiveConditionDummy = false;
  4255. this->ExpandLinkItems(newProp, newExplicitLibraries, config,
  4256. headTarget, usage_requirements_only, ifaceLibs,
  4257. hadHeadSensitiveConditionDummy);
  4258. }
  4259. if (ifaceLibs != iface.Libraries) {
  4260. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  4261. std::string newLibraries = cmJoin(ifaceLibs, ";");
  4262. if (oldLibraries.empty()) {
  4263. oldLibraries = "(empty)";
  4264. }
  4265. if (newLibraries.empty()) {
  4266. newLibraries = "(empty)";
  4267. }
  4268. std::ostringstream w;
  4269. /* clang-format off */
  4270. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4271. "Target \"" << this->GetName() << "\" has an "
  4272. "INTERFACE_LINK_LIBRARIES property. "
  4273. "This should be preferred as the source of the link interface "
  4274. "for this library but because CMP0022 is not set CMake is "
  4275. "ignoring the property and using the link implementation "
  4276. "as the link interface instead."
  4277. "\n"
  4278. "INTERFACE_LINK_LIBRARIES:\n"
  4279. " " << newLibraries << "\n"
  4280. "Link implementation:\n"
  4281. " " << oldLibraries << "\n";
  4282. /* clang-format on */
  4283. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  4284. this->PolicyWarnedCMP0022 = true;
  4285. }
  4286. }
  4287. }
  4288. }
  4289. const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
  4290. const std::string& config, cmGeneratorTarget const* headTarget,
  4291. bool usage_requirements_only) const
  4292. {
  4293. cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config);
  4294. if (!info) {
  4295. return CM_NULLPTR;
  4296. }
  4297. std::string CONFIG = cmSystemTools::UpperCase(config);
  4298. cmHeadToLinkInterfaceMap& hm =
  4299. (usage_requirements_only
  4300. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  4301. : this->GetHeadToLinkInterfaceMap(config));
  4302. // If the link interface does not depend on the head target
  4303. // then return the one we computed first.
  4304. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  4305. return &hm.begin()->second;
  4306. }
  4307. cmOptionalLinkInterface& iface = hm[headTarget];
  4308. if (!iface.AllDone) {
  4309. iface.AllDone = true;
  4310. iface.Multiplicity = info->Multiplicity;
  4311. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  4312. this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
  4313. headTarget, usage_requirements_only, iface.Libraries,
  4314. iface.HadHeadSensitiveCondition);
  4315. std::vector<std::string> deps;
  4316. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  4317. this->LookupLinkItems(deps, iface.SharedDeps);
  4318. }
  4319. return &iface;
  4320. }
  4321. cmGeneratorTarget::ImportInfo const* cmGeneratorTarget::GetImportInfo(
  4322. const std::string& config) const
  4323. {
  4324. // There is no imported information for non-imported targets.
  4325. if (!this->IsImported()) {
  4326. return CM_NULLPTR;
  4327. }
  4328. // Lookup/compute/cache the import information for this
  4329. // configuration.
  4330. std::string config_upper;
  4331. if (!config.empty()) {
  4332. config_upper = cmSystemTools::UpperCase(config);
  4333. } else {
  4334. config_upper = "NOCONFIG";
  4335. }
  4336. ImportInfoMapType::const_iterator i = this->ImportInfoMap.find(config_upper);
  4337. if (i == this->ImportInfoMap.end()) {
  4338. ImportInfo info;
  4339. this->ComputeImportInfo(config_upper, info);
  4340. ImportInfoMapType::value_type entry(config_upper, info);
  4341. i = this->ImportInfoMap.insert(entry).first;
  4342. }
  4343. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4344. return &i->second;
  4345. }
  4346. // If the location is empty then the target is not available for
  4347. // this configuration.
  4348. if (i->second.Location.empty() && i->second.ImportLibrary.empty()) {
  4349. return CM_NULLPTR;
  4350. }
  4351. // Return the import information.
  4352. return &i->second;
  4353. }
  4354. void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config,
  4355. ImportInfo& info) const
  4356. {
  4357. // This method finds information about an imported target from its
  4358. // properties. The "IMPORTED_" namespace is reserved for properties
  4359. // defined by the project exporting the target.
  4360. // Initialize members.
  4361. info.NoSOName = false;
  4362. const char* loc = CM_NULLPTR;
  4363. const char* imp = CM_NULLPTR;
  4364. std::string suffix;
  4365. if (!this->Target->GetMappedConfig(desired_config, &loc, &imp, suffix)) {
  4366. return;
  4367. }
  4368. // Get the link interface.
  4369. {
  4370. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  4371. const char* propertyLibs = this->GetProperty(linkProp);
  4372. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  4373. if (!propertyLibs) {
  4374. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4375. linkProp += suffix;
  4376. propertyLibs = this->GetProperty(linkProp);
  4377. }
  4378. if (!propertyLibs) {
  4379. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4380. propertyLibs = this->GetProperty(linkProp);
  4381. }
  4382. }
  4383. if (propertyLibs) {
  4384. info.LibrariesProp = linkProp;
  4385. info.Libraries = propertyLibs;
  4386. }
  4387. }
  4388. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4389. if (loc) {
  4390. info.LibName = loc;
  4391. }
  4392. return;
  4393. }
  4394. // A provided configuration has been chosen. Load the
  4395. // configuration's properties.
  4396. // Get the location.
  4397. if (loc) {
  4398. info.Location = loc;
  4399. } else {
  4400. std::string impProp = "IMPORTED_LOCATION";
  4401. impProp += suffix;
  4402. if (const char* config_location = this->GetProperty(impProp)) {
  4403. info.Location = config_location;
  4404. } else if (const char* location = this->GetProperty("IMPORTED_LOCATION")) {
  4405. info.Location = location;
  4406. }
  4407. }
  4408. // Get the soname.
  4409. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  4410. std::string soProp = "IMPORTED_SONAME";
  4411. soProp += suffix;
  4412. if (const char* config_soname = this->GetProperty(soProp)) {
  4413. info.SOName = config_soname;
  4414. } else if (const char* soname = this->GetProperty("IMPORTED_SONAME")) {
  4415. info.SOName = soname;
  4416. }
  4417. }
  4418. // Get the "no-soname" mark.
  4419. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  4420. std::string soProp = "IMPORTED_NO_SONAME";
  4421. soProp += suffix;
  4422. if (const char* config_no_soname = this->GetProperty(soProp)) {
  4423. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  4424. } else if (const char* no_soname =
  4425. this->GetProperty("IMPORTED_NO_SONAME")) {
  4426. info.NoSOName = cmSystemTools::IsOn(no_soname);
  4427. }
  4428. }
  4429. // Get the import library.
  4430. if (imp) {
  4431. info.ImportLibrary = imp;
  4432. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4433. this->IsExecutableWithExports()) {
  4434. std::string impProp = "IMPORTED_IMPLIB";
  4435. impProp += suffix;
  4436. if (const char* config_implib = this->GetProperty(impProp)) {
  4437. info.ImportLibrary = config_implib;
  4438. } else if (const char* implib = this->GetProperty("IMPORTED_IMPLIB")) {
  4439. info.ImportLibrary = implib;
  4440. }
  4441. }
  4442. // Get the link dependencies.
  4443. {
  4444. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  4445. linkProp += suffix;
  4446. if (const char* config_libs = this->GetProperty(linkProp)) {
  4447. info.SharedDeps = config_libs;
  4448. } else if (const char* libs =
  4449. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES")) {
  4450. info.SharedDeps = libs;
  4451. }
  4452. }
  4453. // Get the link languages.
  4454. if (this->LinkLanguagePropagatesToDependents()) {
  4455. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  4456. linkProp += suffix;
  4457. if (const char* config_libs = this->GetProperty(linkProp)) {
  4458. info.Languages = config_libs;
  4459. } else if (const char* libs =
  4460. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES")) {
  4461. info.Languages = libs;
  4462. }
  4463. }
  4464. // Get the cyclic repetition count.
  4465. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  4466. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  4467. linkProp += suffix;
  4468. if (const char* config_reps = this->GetProperty(linkProp)) {
  4469. sscanf(config_reps, "%u", &info.Multiplicity);
  4470. } else if (const char* reps =
  4471. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY")) {
  4472. sscanf(reps, "%u", &info.Multiplicity);
  4473. }
  4474. }
  4475. }
  4476. cmHeadToLinkInterfaceMap& cmGeneratorTarget::GetHeadToLinkInterfaceMap(
  4477. const std::string& config) const
  4478. {
  4479. std::string CONFIG = cmSystemTools::UpperCase(config);
  4480. return this->LinkInterfaceMap[CONFIG];
  4481. }
  4482. cmHeadToLinkInterfaceMap&
  4483. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  4484. const std::string& config) const
  4485. {
  4486. std::string CONFIG = cmSystemTools::UpperCase(config);
  4487. return this->LinkInterfaceUsageRequirementsOnlyMap[CONFIG];
  4488. }
  4489. const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation(
  4490. const std::string& config) const
  4491. {
  4492. // There is no link implementation for imported targets.
  4493. if (this->IsImported()) {
  4494. return CM_NULLPTR;
  4495. }
  4496. std::string CONFIG = cmSystemTools::UpperCase(config);
  4497. cmOptionalLinkImplementation& impl = this->LinkImplMap[CONFIG][this];
  4498. if (!impl.LibrariesDone) {
  4499. impl.LibrariesDone = true;
  4500. this->ComputeLinkImplementationLibraries(config, impl, this);
  4501. }
  4502. if (!impl.LanguagesDone) {
  4503. impl.LanguagesDone = true;
  4504. this->ComputeLinkImplementationLanguages(config, impl);
  4505. }
  4506. return &impl;
  4507. }
  4508. bool cmGeneratorTarget::GetConfigCommonSourceFiles(
  4509. std::vector<cmSourceFile*>& files) const
  4510. {
  4511. std::vector<std::string> configs;
  4512. this->Makefile->GetConfigurations(configs);
  4513. if (configs.empty()) {
  4514. configs.push_back("");
  4515. }
  4516. std::vector<std::string>::const_iterator it = configs.begin();
  4517. const std::string& firstConfig = *it;
  4518. this->GetSourceFilesWithoutObjectLibraries(files, firstConfig);
  4519. for (; it != configs.end(); ++it) {
  4520. std::vector<cmSourceFile*> configFiles;
  4521. this->GetSourceFilesWithoutObjectLibraries(configFiles, *it);
  4522. if (configFiles != files) {
  4523. std::string firstConfigFiles;
  4524. const char* sep = "";
  4525. for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
  4526. fi != files.end(); ++fi) {
  4527. firstConfigFiles += sep;
  4528. firstConfigFiles += (*fi)->GetFullPath();
  4529. sep = "\n ";
  4530. }
  4531. std::string thisConfigFiles;
  4532. sep = "";
  4533. for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
  4534. fi != configFiles.end(); ++fi) {
  4535. thisConfigFiles += sep;
  4536. thisConfigFiles += (*fi)->GetFullPath();
  4537. sep = "\n ";
  4538. }
  4539. std::ostringstream e;
  4540. /* clang-format off */
  4541. e << "Target \"" << this->GetName()
  4542. << "\" has source files which vary by "
  4543. "configuration. This is not supported by the \""
  4544. << this->GlobalGenerator->GetName()
  4545. << "\" generator.\n"
  4546. "Config \"" << firstConfig << "\":\n"
  4547. " " << firstConfigFiles << "\n"
  4548. "Config \"" << *it << "\":\n"
  4549. " " << thisConfigFiles << "\n";
  4550. /* clang-format on */
  4551. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  4552. return false;
  4553. }
  4554. }
  4555. return true;
  4556. }
  4557. void cmGeneratorTarget::GetObjectLibrariesCMP0026(
  4558. std::vector<cmGeneratorTarget*>& objlibs) const
  4559. {
  4560. // At configure-time, this method can be called as part of getting the
  4561. // LOCATION property or to export() a file to be include()d. However
  4562. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  4563. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  4564. // behavior of CMP0024 and CMP0026 only.
  4565. cmStringRange rng = this->Target->GetSourceEntries();
  4566. for (std::vector<std::string>::const_iterator i = rng.begin();
  4567. i != rng.end(); ++i) {
  4568. std::string const& entry = *i;
  4569. std::vector<std::string> files;
  4570. cmSystemTools::ExpandListArgument(entry, files);
  4571. for (std::vector<std::string>::const_iterator li = files.begin();
  4572. li != files.end(); ++li) {
  4573. if (cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  4574. (*li)[li->size() - 1] == '>') {
  4575. std::string objLibName = li->substr(17, li->size() - 18);
  4576. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  4577. continue;
  4578. }
  4579. cmGeneratorTarget* objLib =
  4580. this->LocalGenerator->FindGeneratorTargetToUse(objLibName);
  4581. if (objLib) {
  4582. objlibs.push_back(objLib);
  4583. }
  4584. }
  4585. }
  4586. }
  4587. }
  4588. std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
  4589. {
  4590. // Strip whitespace off the library names because we used to do this
  4591. // in case variables were expanded at generate time. We no longer
  4592. // do the expansion but users link to libraries like " ${VAR} ".
  4593. std::string lib = item;
  4594. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  4595. if (pos != lib.npos) {
  4596. lib = lib.substr(pos, lib.npos);
  4597. }
  4598. pos = lib.find_last_not_of(" \t\r\n");
  4599. if (pos != lib.npos) {
  4600. lib = lib.substr(0, pos + 1);
  4601. }
  4602. if (lib != item) {
  4603. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  4604. switch (this->GetPolicyStatusCMP0004()) {
  4605. case cmPolicies::WARN: {
  4606. std::ostringstream w;
  4607. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  4608. << "Target \"" << this->GetName() << "\" links to item \"" << item
  4609. << "\" which has leading or trailing whitespace.";
  4610. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(), this->GetBacktrace());
  4611. }
  4612. case cmPolicies::OLD:
  4613. break;
  4614. case cmPolicies::NEW: {
  4615. std::ostringstream e;
  4616. e << "Target \"" << this->GetName() << "\" links to item \"" << item
  4617. << "\" which has leading or trailing whitespace. "
  4618. << "This is now an error according to policy CMP0004.";
  4619. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4620. } break;
  4621. case cmPolicies::REQUIRED_IF_USED:
  4622. case cmPolicies::REQUIRED_ALWAYS: {
  4623. std::ostringstream e;
  4624. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  4625. << "Target \"" << this->GetName() << "\" links to item \"" << item
  4626. << "\" which has leading or trailing whitespace.";
  4627. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4628. } break;
  4629. }
  4630. }
  4631. return lib;
  4632. }
  4633. void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
  4634. const std::string& config) const
  4635. {
  4636. std::vector<cmSourceFile*> sourceFiles;
  4637. this->GetSourceFiles(sourceFiles, config);
  4638. for (std::vector<cmSourceFile*>::const_iterator i = sourceFiles.begin();
  4639. i != sourceFiles.end(); ++i) {
  4640. const std::string& lang = (*i)->GetLanguage();
  4641. if (!lang.empty()) {
  4642. languages.insert(lang);
  4643. }
  4644. }
  4645. std::vector<cmGeneratorTarget*> objectLibraries;
  4646. std::vector<cmSourceFile const*> externalObjects;
  4647. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  4648. std::vector<cmGeneratorTarget*> objectTargets;
  4649. this->GetObjectLibrariesCMP0026(objectTargets);
  4650. objectLibraries.reserve(objectTargets.size());
  4651. for (std::vector<cmGeneratorTarget*>::const_iterator it =
  4652. objectTargets.begin();
  4653. it != objectTargets.end(); ++it) {
  4654. objectLibraries.push_back(*it);
  4655. }
  4656. } else {
  4657. this->GetExternalObjects(externalObjects, config);
  4658. for (std::vector<cmSourceFile const*>::const_iterator i =
  4659. externalObjects.begin();
  4660. i != externalObjects.end(); ++i) {
  4661. std::string objLib = (*i)->GetObjectLibrary();
  4662. if (cmGeneratorTarget* tgt =
  4663. this->LocalGenerator->FindGeneratorTargetToUse(objLib)) {
  4664. objectLibraries.push_back(tgt);
  4665. }
  4666. }
  4667. }
  4668. for (std::vector<cmGeneratorTarget*>::const_iterator i =
  4669. objectLibraries.begin();
  4670. i != objectLibraries.end(); ++i) {
  4671. (*i)->GetLanguages(languages, config);
  4672. }
  4673. }
  4674. void cmGeneratorTarget::ComputeLinkImplementationLanguages(
  4675. const std::string& config, cmOptionalLinkImplementation& impl) const
  4676. {
  4677. // This target needs runtime libraries for its source languages.
  4678. std::set<std::string> languages;
  4679. // Get languages used in our source files.
  4680. this->GetLanguages(languages, config);
  4681. // Copy the set of langauges to the link implementation.
  4682. impl.Languages.insert(impl.Languages.begin(), languages.begin(),
  4683. languages.end());
  4684. }
  4685. bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const
  4686. {
  4687. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH")) {
  4688. return false;
  4689. }
  4690. if (this->GetProperty("BUILD_RPATH")) {
  4691. return true;
  4692. }
  4693. if (cmLinkImplementationLibraries const* impl =
  4694. this->GetLinkImplementationLibraries(config)) {
  4695. return !impl->Libraries.empty();
  4696. }
  4697. return false;
  4698. }
  4699. cmLinkImplementationLibraries const*
  4700. cmGeneratorTarget::GetLinkImplementationLibraries(
  4701. const std::string& config) const
  4702. {
  4703. return this->GetLinkImplementationLibrariesInternal(config, this);
  4704. }
  4705. cmLinkImplementationLibraries const*
  4706. cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
  4707. const std::string& config, cmGeneratorTarget const* head) const
  4708. {
  4709. // There is no link implementation for imported targets.
  4710. if (this->IsImported()) {
  4711. return CM_NULLPTR;
  4712. }
  4713. // Populate the link implementation libraries for this configuration.
  4714. std::string CONFIG = cmSystemTools::UpperCase(config);
  4715. HeadToLinkImplementationMap& hm = this->LinkImplMap[CONFIG];
  4716. // If the link implementation does not depend on the head target
  4717. // then return the one we computed first.
  4718. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  4719. return &hm.begin()->second;
  4720. }
  4721. cmOptionalLinkImplementation& impl = hm[head];
  4722. if (!impl.LibrariesDone) {
  4723. impl.LibrariesDone = true;
  4724. this->ComputeLinkImplementationLibraries(config, impl, head);
  4725. }
  4726. return &impl;
  4727. }
  4728. bool cmGeneratorTarget::IsNullImpliedByLinkLibraries(
  4729. const std::string& p) const
  4730. {
  4731. return this->LinkImplicitNullProperties.find(p) !=
  4732. this->LinkImplicitNullProperties.end();
  4733. }
  4734. void cmGeneratorTarget::ComputeLinkImplementationLibraries(
  4735. const std::string& config, cmOptionalLinkImplementation& impl,
  4736. cmGeneratorTarget const* head) const
  4737. {
  4738. cmStringRange entryRange = this->Target->GetLinkImplementationEntries();
  4739. cmBacktraceRange btRange = this->Target->GetLinkImplementationBacktraces();
  4740. cmBacktraceRange::const_iterator btIt = btRange.begin();
  4741. // Collect libraries directly linked in this configuration.
  4742. for (cmStringRange::const_iterator le = entryRange.begin(),
  4743. end = entryRange.end();
  4744. le != end; ++le, ++btIt) {
  4745. std::vector<std::string> llibs;
  4746. cmGeneratorExpressionDAGChecker dagChecker(
  4747. this->GetName(), "LINK_LIBRARIES", CM_NULLPTR, CM_NULLPTR);
  4748. cmGeneratorExpression ge(*btIt);
  4749. CM_AUTO_PTR<cmCompiledGeneratorExpression> const cge = ge.Parse(*le);
  4750. std::string const evaluated =
  4751. cge->Evaluate(this->LocalGenerator, config, false, head, &dagChecker);
  4752. cmSystemTools::ExpandListArgument(evaluated, llibs);
  4753. if (cge->GetHadHeadSensitiveCondition()) {
  4754. impl.HadHeadSensitiveCondition = true;
  4755. }
  4756. for (std::vector<std::string>::const_iterator li = llibs.begin();
  4757. li != llibs.end(); ++li) {
  4758. // Skip entries that resolve to the target itself or are empty.
  4759. std::string name = this->CheckCMP0004(*li);
  4760. if (name == this->GetName() || name.empty()) {
  4761. if (name == this->GetName()) {
  4762. bool noMessage = false;
  4763. cmake::MessageType messageType = cmake::FATAL_ERROR;
  4764. std::ostringstream e;
  4765. switch (this->GetPolicyStatusCMP0038()) {
  4766. case cmPolicies::WARN: {
  4767. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  4768. messageType = cmake::AUTHOR_WARNING;
  4769. } break;
  4770. case cmPolicies::OLD:
  4771. noMessage = true;
  4772. case cmPolicies::REQUIRED_IF_USED:
  4773. case cmPolicies::REQUIRED_ALWAYS:
  4774. case cmPolicies::NEW:
  4775. // Issue the fatal message.
  4776. break;
  4777. }
  4778. if (!noMessage) {
  4779. e << "Target \"" << this->GetName() << "\" links to itself.";
  4780. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  4781. messageType, e.str(), this->GetBacktrace());
  4782. if (messageType == cmake::FATAL_ERROR) {
  4783. return;
  4784. }
  4785. }
  4786. }
  4787. continue;
  4788. }
  4789. // The entry is meant for this configuration.
  4790. impl.Libraries.push_back(cmLinkImplItem(
  4791. name, this->FindTargetToLink(name), *btIt, evaluated != *le));
  4792. }
  4793. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  4794. for (std::set<std::string>::const_iterator it = seenProps.begin();
  4795. it != seenProps.end(); ++it) {
  4796. if (!this->GetProperty(*it)) {
  4797. this->LinkImplicitNullProperties.insert(*it);
  4798. }
  4799. }
  4800. cge->GetMaxLanguageStandard(this, this->MaxLanguageStandards);
  4801. }
  4802. // Get the list of configurations considered to be DEBUG.
  4803. std::vector<std::string> debugConfigs =
  4804. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  4805. cmTargetLinkLibraryType linkType =
  4806. CMP0003_ComputeLinkType(config, debugConfigs);
  4807. cmTarget::LinkLibraryVectorType const& oldllibs =
  4808. this->Target->GetOriginalLinkLibraries();
  4809. for (cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  4810. li != oldllibs.end(); ++li) {
  4811. if (li->second != GENERAL_LibraryType && li->second != linkType) {
  4812. std::string name = this->CheckCMP0004(li->first);
  4813. if (name == this->GetName() || name.empty()) {
  4814. continue;
  4815. }
  4816. // Support OLD behavior for CMP0003.
  4817. impl.WrongConfigLibraries.push_back(
  4818. cmLinkItem(name, this->FindTargetToLink(name)));
  4819. }
  4820. }
  4821. }
  4822. cmGeneratorTarget* cmGeneratorTarget::FindTargetToLink(
  4823. std::string const& name) const
  4824. {
  4825. cmGeneratorTarget* tgt =
  4826. this->LocalGenerator->FindGeneratorTargetToUse(name);
  4827. // Skip targets that will not really be linked. This is probably a
  4828. // name conflict between an external library and an executable
  4829. // within the project.
  4830. if (tgt && tgt->GetType() == cmStateEnums::EXECUTABLE &&
  4831. !tgt->IsExecutableWithExports()) {
  4832. tgt = CM_NULLPTR;
  4833. }
  4834. if (tgt && tgt->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  4835. std::ostringstream e;
  4836. e << "Target \"" << this->GetName() << "\" links to "
  4837. "OBJECT library \""
  4838. << tgt->GetName()
  4839. << "\" but this is not "
  4840. "allowed. "
  4841. "One may link only to STATIC or SHARED libraries, or to executables "
  4842. "with the ENABLE_EXPORTS property set.";
  4843. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  4844. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4845. tgt = CM_NULLPTR;
  4846. }
  4847. return tgt;
  4848. }
  4849. std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const
  4850. {
  4851. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  4852. // Return the directory in which the target will be built.
  4853. return info->PdbDir;
  4854. }
  4855. return "";
  4856. }
  4857. bool cmGeneratorTarget::HasImplibGNUtoMS() const
  4858. {
  4859. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  4860. }
  4861. bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& gnuName,
  4862. std::string& out,
  4863. const char* newExt) const
  4864. {
  4865. if (this->HasImplibGNUtoMS() && gnuName.size() > 6 &&
  4866. gnuName.substr(gnuName.size() - 6) == ".dll.a") {
  4867. out = gnuName.substr(0, gnuName.size() - 6);
  4868. out += newExt ? newExt : ".lib";
  4869. return true;
  4870. }
  4871. return false;
  4872. }
  4873. bool cmGeneratorTarget::IsExecutableWithExports() const
  4874. {
  4875. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  4876. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  4877. }
  4878. bool cmGeneratorTarget::HasImportLibrary() const
  4879. {
  4880. return (this->IsDLLPlatform() &&
  4881. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4882. this->IsExecutableWithExports()));
  4883. }
  4884. std::string cmGeneratorTarget::GetSupportDirectory() const
  4885. {
  4886. std::string dir = this->LocalGenerator->GetCurrentBinaryDirectory();
  4887. dir += cmake::GetCMakeFilesDirectory();
  4888. dir += "/";
  4889. dir += this->GetName();
  4890. #if defined(__VMS)
  4891. dir += "_dir";
  4892. #else
  4893. dir += ".dir";
  4894. #endif
  4895. return dir;
  4896. }
  4897. bool cmGeneratorTarget::IsLinkable() const
  4898. {
  4899. return (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  4900. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4901. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  4902. this->GetType() == cmStateEnums::UNKNOWN_LIBRARY ||
  4903. this->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
  4904. this->IsExecutableWithExports());
  4905. }
  4906. bool cmGeneratorTarget::IsFrameworkOnApple() const
  4907. {
  4908. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4909. this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  4910. this->Makefile->IsOn("APPLE") &&
  4911. this->GetPropertyAsBool("FRAMEWORK"));
  4912. }
  4913. bool cmGeneratorTarget::IsAppBundleOnApple() const
  4914. {
  4915. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  4916. this->Makefile->IsOn("APPLE") &&
  4917. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  4918. }
  4919. bool cmGeneratorTarget::IsXCTestOnApple() const
  4920. {
  4921. return (this->IsCFBundleOnApple() && this->GetPropertyAsBool("XCTEST"));
  4922. }
  4923. bool cmGeneratorTarget::IsCFBundleOnApple() const
  4924. {
  4925. return (this->GetType() == cmStateEnums::MODULE_LIBRARY &&
  4926. this->Makefile->IsOn("APPLE") && this->GetPropertyAsBool("BUNDLE"));
  4927. }