cmGeneratorTarget.cxx 184 KB

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