cmGeneratorTarget.cxx 181 KB

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