meson.build 154 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337
  1. project('qemu', ['c'], meson_version: '>=0.63.0',
  2. default_options: ['warning_level=1', 'c_std=gnu11', 'cpp_std=gnu++11', 'b_colorout=auto',
  3. 'b_staticpic=false', 'stdsplit=false', 'optimization=2', 'b_pie=true'],
  4. version: files('VERSION'))
  5. add_test_setup('quick', exclude_suites: ['slow', 'thorough'], is_default: true)
  6. add_test_setup('slow', exclude_suites: ['thorough'], env: ['G_TEST_SLOW=1', 'SPEED=slow'])
  7. add_test_setup('thorough', env: ['G_TEST_SLOW=1', 'SPEED=thorough'])
  8. meson.add_postconf_script(find_program('scripts/symlink-install-tree.py'))
  9. not_found = dependency('', required: false)
  10. keyval = import('keyval')
  11. ss = import('sourceset')
  12. fs = import('fs')
  13. targetos = host_machine.system()
  14. sh = find_program('sh')
  15. config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
  16. cc = meson.get_compiler('c')
  17. all_languages = ['c']
  18. if add_languages('cpp', required: false, native: false)
  19. all_languages += ['cpp']
  20. cxx = meson.get_compiler('cpp')
  21. endif
  22. if targetos == 'darwin' and \
  23. add_languages('objc', required: get_option('cocoa'), native: false)
  24. all_languages += ['objc']
  25. objc = meson.get_compiler('objc')
  26. endif
  27. # Temporary directory used for files created while
  28. # configure runs. Since it is in the build directory
  29. # we can safely blow away any previous version of it
  30. # (and we need not jump through hoops to try to delete
  31. # it when configure exits.)
  32. tmpdir = meson.current_build_dir() / 'meson-private/temp'
  33. if get_option('qemu_suffix').startswith('/')
  34. error('qemu_suffix cannot start with a /')
  35. endif
  36. qemu_confdir = get_option('sysconfdir') / get_option('qemu_suffix')
  37. qemu_datadir = get_option('datadir') / get_option('qemu_suffix')
  38. qemu_docdir = get_option('docdir') / get_option('qemu_suffix')
  39. qemu_moddir = get_option('libdir') / get_option('qemu_suffix')
  40. qemu_desktopdir = get_option('datadir') / 'applications'
  41. qemu_icondir = get_option('datadir') / 'icons'
  42. config_host_data = configuration_data()
  43. genh = []
  44. qapi_trace_events = []
  45. bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin']
  46. supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
  47. supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv', 'x86', 'x86_64',
  48. 'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64']
  49. cpu = host_machine.cpu_family()
  50. # Unify riscv* to a single family.
  51. if cpu in ['riscv32', 'riscv64']
  52. cpu = 'riscv'
  53. endif
  54. target_dirs = config_host['TARGET_DIRS'].split()
  55. have_linux_user = false
  56. have_bsd_user = false
  57. have_system = false
  58. foreach target : target_dirs
  59. have_linux_user = have_linux_user or target.endswith('linux-user')
  60. have_bsd_user = have_bsd_user or target.endswith('bsd-user')
  61. have_system = have_system or target.endswith('-softmmu')
  62. endforeach
  63. have_user = have_linux_user or have_bsd_user
  64. have_tools = get_option('tools') \
  65. .disable_auto_if(not have_system) \
  66. .allowed()
  67. have_ga = get_option('guest_agent') \
  68. .disable_auto_if(not have_system and not have_tools) \
  69. .require(targetos in ['sunos', 'linux', 'windows', 'freebsd', 'netbsd', 'openbsd'],
  70. error_message: 'unsupported OS for QEMU guest agent') \
  71. .allowed()
  72. enable_modules = get_option('modules') \
  73. .require(targetos != 'windows',
  74. error_message: 'Modules are not available for Windows') \
  75. .require(not get_option('prefer_static'),
  76. error_message: 'Modules are incompatible with static linking') \
  77. .allowed()
  78. have_block = have_system or have_tools
  79. python = import('python').find_installation()
  80. if cpu not in supported_cpus
  81. host_arch = 'unknown'
  82. elif cpu == 'x86'
  83. host_arch = 'i386'
  84. elif cpu == 'mips64'
  85. host_arch = 'mips'
  86. else
  87. host_arch = cpu
  88. endif
  89. if cpu in ['x86', 'x86_64']
  90. kvm_targets = ['i386-softmmu', 'x86_64-softmmu']
  91. elif cpu == 'aarch64'
  92. kvm_targets = ['aarch64-softmmu']
  93. elif cpu == 's390x'
  94. kvm_targets = ['s390x-softmmu']
  95. elif cpu in ['ppc', 'ppc64']
  96. kvm_targets = ['ppc-softmmu', 'ppc64-softmmu']
  97. elif cpu in ['mips', 'mips64']
  98. kvm_targets = ['mips-softmmu', 'mipsel-softmmu', 'mips64-softmmu', 'mips64el-softmmu']
  99. elif cpu in ['riscv']
  100. kvm_targets = ['riscv32-softmmu', 'riscv64-softmmu']
  101. else
  102. kvm_targets = []
  103. endif
  104. kvm_targets_c = '""'
  105. if get_option('kvm').allowed() and targetos == 'linux'
  106. kvm_targets_c = '"' + '" ,"'.join(kvm_targets) + '"'
  107. endif
  108. config_host_data.set('CONFIG_KVM_TARGETS', kvm_targets_c)
  109. accelerator_targets = { 'CONFIG_KVM': kvm_targets }
  110. if cpu in ['aarch64']
  111. accelerator_targets += {
  112. 'CONFIG_HVF': ['aarch64-softmmu']
  113. }
  114. endif
  115. if cpu in ['x86', 'x86_64', 'arm', 'aarch64']
  116. # i386 emulator provides xenpv machine type for multiple architectures
  117. accelerator_targets += {
  118. 'CONFIG_XEN': ['i386-softmmu', 'x86_64-softmmu'],
  119. }
  120. endif
  121. if cpu in ['x86', 'x86_64']
  122. accelerator_targets += {
  123. 'CONFIG_HAX': ['i386-softmmu', 'x86_64-softmmu'],
  124. 'CONFIG_HVF': ['x86_64-softmmu'],
  125. 'CONFIG_NVMM': ['i386-softmmu', 'x86_64-softmmu'],
  126. 'CONFIG_WHPX': ['i386-softmmu', 'x86_64-softmmu'],
  127. }
  128. endif
  129. modular_tcg = []
  130. # Darwin does not support references to thread-local variables in modules
  131. if targetos != 'darwin'
  132. modular_tcg = ['i386-softmmu', 'x86_64-softmmu']
  133. endif
  134. edk2_targets = [ 'arm-softmmu', 'aarch64-softmmu', 'i386-softmmu', 'x86_64-softmmu' ]
  135. unpack_edk2_blobs = false
  136. foreach target : edk2_targets
  137. if target in target_dirs
  138. bzip2 = find_program('bzip2', required: get_option('install_blobs'))
  139. unpack_edk2_blobs = bzip2.found()
  140. break
  141. endif
  142. endforeach
  143. dtrace = not_found
  144. stap = not_found
  145. if 'dtrace' in get_option('trace_backends')
  146. dtrace = find_program('dtrace', required: true)
  147. stap = find_program('stap', required: false)
  148. if stap.found()
  149. # Workaround to avoid dtrace(1) producing a file with 'hidden' symbol
  150. # visibility. Define STAP_SDT_V2 to produce 'default' symbol visibility
  151. # instead. QEMU --enable-modules depends on this because the SystemTap
  152. # semaphores are linked into the main binary and not the module's shared
  153. # object.
  154. add_global_arguments('-DSTAP_SDT_V2',
  155. native: false, language: all_languages)
  156. endif
  157. endif
  158. if get_option('iasl') == ''
  159. iasl = find_program('iasl', required: false)
  160. else
  161. iasl = find_program(get_option('iasl'), required: true)
  162. endif
  163. ##################
  164. # Compiler flags #
  165. ##################
  166. foreach lang : all_languages
  167. compiler = meson.get_compiler(lang)
  168. if compiler.get_id() == 'gcc' and compiler.version().version_compare('>=7.4')
  169. # ok
  170. elif compiler.get_id() == 'clang' and compiler.compiles('''
  171. #ifdef __apple_build_version__
  172. # if __clang_major__ < 12 || (__clang_major__ == 12 && __clang_minor__ < 0)
  173. # error You need at least XCode Clang v12.0 to compile QEMU
  174. # endif
  175. #else
  176. # if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
  177. # error You need at least Clang v10.0 to compile QEMU
  178. # endif
  179. #endif''')
  180. # ok
  181. else
  182. error('You either need GCC v7.4 or Clang v10.0 (or XCode Clang v12.0) to compile QEMU')
  183. endif
  184. endforeach
  185. # default flags for all hosts
  186. # We use -fwrapv to tell the compiler that we require a C dialect where
  187. # left shift of signed integers is well defined and has the expected
  188. # 2s-complement style results. (Both clang and gcc agree that it
  189. # provides these semantics.)
  190. qemu_common_flags = [
  191. '-D_GNU_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE',
  192. '-fno-strict-aliasing', '-fno-common', '-fwrapv' ]
  193. qemu_cflags = []
  194. qemu_ldflags = []
  195. if targetos == 'darwin'
  196. # Disable attempts to use ObjectiveC features in os/object.h since they
  197. # won't work when we're compiling with gcc as a C compiler.
  198. qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
  199. elif targetos == 'solaris'
  200. # needed for CMSG_ macros in sys/socket.h
  201. qemu_common_flags += '-D_XOPEN_SOURCE=600'
  202. # needed for TIOCWIN* defines in termios.h
  203. qemu_common_flags += '-D__EXTENSIONS__'
  204. elif targetos == 'haiku'
  205. qemu_common_flags += ['-DB_USE_POSITIVE_POSIX_ERRORS', '-D_BSD_SOURCE', '-fPIC']
  206. endif
  207. # __sync_fetch_and_and requires at least -march=i486. Many toolchains
  208. # use i686 as default anyway, but for those that don't, an explicit
  209. # specification is necessary
  210. if host_arch == 'i386' and not cc.links('''
  211. static int sfaa(int *ptr)
  212. {
  213. return __sync_fetch_and_and(ptr, 0);
  214. }
  215. int main(void)
  216. {
  217. int val = 42;
  218. val = __sync_val_compare_and_swap(&val, 0, 1);
  219. sfaa(&val);
  220. return val;
  221. }''')
  222. qemu_common_flags = ['-march=i486'] + qemu_common_flags
  223. endif
  224. if get_option('gprof')
  225. qemu_common_flags += ['-p']
  226. qemu_ldflags += ['-p']
  227. endif
  228. if get_option('prefer_static')
  229. qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static'
  230. endif
  231. # Meson currently only handles pie as a boolean for now, so if the user
  232. # has explicitly disabled PIE we need to extend our cflags.
  233. #
  234. # -no-pie is supposedly a linker flag that has no effect on the compiler
  235. # command line, but some distros, that didn't quite know what they were
  236. # doing, made local changes to gcc's specs file that turned it into
  237. # a compiler command-line flag.
  238. #
  239. # What about linker flags? For a static build, no PIE is implied by -static
  240. # which we added above (and if it's not because of the same specs patching,
  241. # there's nothing we can do: compilation will fail, report a bug to your
  242. # distro and do not use --disable-pie in the meanwhile). For dynamic linking,
  243. # instead, we can't add -no-pie because it overrides -shared: the linker then
  244. # tries to build an executable instead of a shared library and fails. So
  245. # don't add -no-pie anywhere and cross fingers. :(
  246. if not get_option('b_pie')
  247. qemu_common_flags += cc.get_supported_arguments('-fno-pie', '-no-pie')
  248. endif
  249. if not get_option('stack_protector').disabled()
  250. stack_protector_probe = '''
  251. int main(int argc, char *argv[])
  252. {
  253. char arr[64], *p = arr, *c = argv[argc - 1];
  254. while (*c) {
  255. *p++ = *c++;
  256. }
  257. return 0;
  258. }'''
  259. have_stack_protector = false
  260. foreach arg : ['-fstack-protector-strong', '-fstack-protector-all']
  261. # We need to check both a compile and a link, since some compiler
  262. # setups fail only on a .c->.o compile and some only at link time
  263. if cc.compiles(stack_protector_probe, args: ['-Werror', arg]) and \
  264. cc.links(stack_protector_probe, args: ['-Werror', arg])
  265. have_stack_protector = true
  266. qemu_cflags += arg
  267. qemu_ldflags += arg
  268. break
  269. endif
  270. endforeach
  271. get_option('stack_protector') \
  272. .require(have_stack_protector, error_message: 'Stack protector not supported')
  273. endif
  274. coroutine_backend = get_option('coroutine_backend')
  275. ucontext_probe = '''
  276. #include <ucontext.h>
  277. #ifdef __stub_makecontext
  278. #error Ignoring glibc stub makecontext which will always fail
  279. #endif
  280. int main(void) { makecontext(0, 0, 0); return 0; }'''
  281. # On Windows the only valid backend is the Windows specific one.
  282. # For POSIX prefer ucontext, but it's not always possible. The fallback
  283. # is sigcontext.
  284. supported_backends = []
  285. if targetos == 'windows'
  286. supported_backends += ['windows']
  287. else
  288. if targetos != 'darwin' and cc.links(ucontext_probe)
  289. supported_backends += ['ucontext']
  290. endif
  291. supported_backends += ['sigaltstack']
  292. endif
  293. if coroutine_backend == 'auto'
  294. coroutine_backend = supported_backends[0]
  295. elif coroutine_backend not in supported_backends
  296. error('"@0@" backend requested but not available. Available backends: @1@' \
  297. .format(coroutine_backend, ', '.join(supported_backends)))
  298. endif
  299. # Compiles if SafeStack *not* enabled
  300. safe_stack_probe = '''
  301. int main(void)
  302. {
  303. #if defined(__has_feature)
  304. #if __has_feature(safe_stack)
  305. #error SafeStack Enabled
  306. #endif
  307. #endif
  308. return 0;
  309. }'''
  310. if get_option('safe_stack') != not cc.compiles(safe_stack_probe)
  311. safe_stack_arg = get_option('safe_stack') ? '-fsanitize=safe-stack' : '-fno-sanitize=safe-stack'
  312. if get_option('safe_stack') != not cc.compiles(safe_stack_probe, args: safe_stack_arg)
  313. error(get_option('safe_stack') \
  314. ? 'SafeStack not supported by your compiler' \
  315. : 'Cannot disable SafeStack')
  316. endif
  317. qemu_cflags += safe_stack_arg
  318. qemu_ldflags += safe_stack_arg
  319. endif
  320. if get_option('safe_stack') and coroutine_backend != 'ucontext'
  321. error('SafeStack is only supported with the ucontext coroutine backend')
  322. endif
  323. if get_option('sanitizers')
  324. if cc.has_argument('-fsanitize=address')
  325. qemu_cflags = ['-fsanitize=address'] + qemu_cflags
  326. qemu_ldflags = ['-fsanitize=address'] + qemu_ldflags
  327. endif
  328. # Detect static linking issue with ubsan - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
  329. if cc.links('int main(int argc, char **argv) { return argc + 1; }',
  330. args: [qemu_ldflags, '-fsanitize=undefined'])
  331. qemu_cflags = ['-fsanitize=undefined'] + qemu_cflags
  332. qemu_ldflags = ['-fsanitize=undefined'] + qemu_ldflags
  333. endif
  334. endif
  335. # Thread sanitizer is, for now, much noisier than the other sanitizers;
  336. # keep it separate until that is not the case.
  337. if get_option('tsan')
  338. if get_option('sanitizers')
  339. error('TSAN is not supported with other sanitizers')
  340. endif
  341. if not cc.has_function('__tsan_create_fiber',
  342. args: '-fsanitize=thread',
  343. prefix: '#include <sanitizer/tsan_interface.h>')
  344. error('Cannot enable TSAN due to missing fiber annotation interface')
  345. endif
  346. qemu_cflags = ['-fsanitize=thread'] + qemu_cflags
  347. qemu_ldflags = ['-fsanitize=thread'] + qemu_ldflags
  348. endif
  349. # Detect support for PT_GNU_RELRO + DT_BIND_NOW.
  350. # The combination is known as "full relro", because .got.plt is read-only too.
  351. qemu_ldflags += cc.get_supported_link_arguments('-Wl,-z,relro', '-Wl,-z,now')
  352. if targetos == 'windows'
  353. qemu_ldflags += cc.get_supported_link_arguments('-Wl,--no-seh', '-Wl,--nxcompat')
  354. qemu_ldflags += cc.get_supported_link_arguments('-Wl,--dynamicbase', '-Wl,--high-entropy-va')
  355. endif
  356. # Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
  357. if targetos != 'sunos' and not get_option('tsan')
  358. qemu_ldflags += cc.get_supported_link_arguments('-Wl,--warn-common')
  359. endif
  360. if get_option('fuzzing')
  361. # Specify a filter to only instrument code that is directly related to
  362. # virtual-devices.
  363. configure_file(output: 'instrumentation-filter',
  364. input: 'scripts/oss-fuzz/instrumentation-filter-template',
  365. copy: true)
  366. if cc.compiles('int main () { return 0; }',
  367. name: '-fsanitize-coverage-allowlist=/dev/null',
  368. args: ['-fsanitize-coverage-allowlist=/dev/null',
  369. '-fsanitize-coverage=trace-pc'] )
  370. qemu_common_flags += ['-fsanitize-coverage-allowlist=instrumentation-filter']
  371. endif
  372. if get_option('fuzzing_engine') == ''
  373. # Add CFLAGS to tell clang to add fuzzer-related instrumentation to all the
  374. # compiled code. To build non-fuzzer binaries with --enable-fuzzing, link
  375. # everything with fsanitize=fuzzer-no-link. Otherwise, the linker will be
  376. # unable to bind the fuzzer-related callbacks added by instrumentation.
  377. qemu_common_flags += ['-fsanitize=fuzzer-no-link']
  378. qemu_ldflags += ['-fsanitize=fuzzer-no-link']
  379. # For the actual fuzzer binaries, we need to link against the libfuzzer
  380. # library. They need to be configurable, to support OSS-Fuzz
  381. fuzz_exe_ldflags = ['-fsanitize=fuzzer']
  382. else
  383. # LIB_FUZZING_ENGINE was set; assume we are running on OSS-Fuzz, and
  384. # the needed CFLAGS have already been provided
  385. fuzz_exe_ldflags = get_option('fuzzing_engine').split()
  386. endif
  387. endif
  388. add_global_arguments(qemu_common_flags, native: false, language: all_languages)
  389. add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
  390. # Collect warnings that we want to enable
  391. warn_flags = [
  392. '-Wundef',
  393. '-Wwrite-strings',
  394. '-Wmissing-prototypes',
  395. '-Wstrict-prototypes',
  396. '-Wredundant-decls',
  397. '-Wold-style-declaration',
  398. '-Wold-style-definition',
  399. '-Wtype-limits',
  400. '-Wformat-security',
  401. '-Wformat-y2k',
  402. '-Winit-self',
  403. '-Wignored-qualifiers',
  404. '-Wempty-body',
  405. '-Wnested-externs',
  406. '-Wendif-labels',
  407. '-Wexpansion-to-defined',
  408. '-Wimplicit-fallthrough=2',
  409. '-Wmissing-format-attribute',
  410. '-Wno-initializer-overrides',
  411. '-Wno-missing-include-dirs',
  412. '-Wno-shift-negative-value',
  413. '-Wno-string-plus-int',
  414. '-Wno-typedef-redefinition',
  415. '-Wno-tautological-type-limit-compare',
  416. '-Wno-psabi',
  417. '-Wno-gnu-variable-sized-type-not-at-end',
  418. ]
  419. if targetos != 'darwin'
  420. warn_flags += ['-Wthread-safety']
  421. endif
  422. # Check that the C++ compiler exists and works with the C compiler.
  423. link_language = 'c'
  424. linker = cc
  425. qemu_cxxflags = []
  426. if 'cpp' in all_languages
  427. qemu_cxxflags = ['-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS'] + qemu_cflags
  428. if cxx.links(files('scripts/main.c'), args: qemu_cflags)
  429. link_language = 'cpp'
  430. linker = cxx
  431. else
  432. message('C++ compiler does not work with C compiler')
  433. message('Disabling C++-specific optional code')
  434. endif
  435. endif
  436. # clang does not support glibc + FORTIFY_SOURCE (is it still true?)
  437. if get_option('optimization') != '0' and targetos == 'linux'
  438. if cc.get_id() == 'gcc'
  439. qemu_cflags += ['-U_FORTIFY_SOURCE', '-D_FORTIFY_SOURCE=2']
  440. endif
  441. if 'cpp' in all_languages and cxx.get_id() == 'gcc'
  442. qemu_cxxflags += ['-U_FORTIFY_SOURCE', '-D_FORTIFY_SOURCE=2']
  443. endif
  444. endif
  445. add_project_arguments(qemu_cflags, native: false, language: 'c')
  446. add_project_arguments(cc.get_supported_arguments(warn_flags), native: false, language: 'c')
  447. if 'cpp' in all_languages
  448. add_project_arguments(qemu_cxxflags, native: false, language: 'cpp')
  449. add_project_arguments(cxx.get_supported_arguments(warn_flags), native: false, language: 'cpp')
  450. endif
  451. if 'objc' in all_languages
  452. # Note sanitizer flags are not applied to Objective-C sources!
  453. add_project_arguments(objc.get_supported_arguments(warn_flags), native: false, language: 'objc')
  454. endif
  455. if targetos == 'linux'
  456. add_project_arguments('-isystem', meson.current_source_dir() / 'linux-headers',
  457. '-isystem', 'linux-headers',
  458. language: all_languages)
  459. endif
  460. add_project_arguments('-iquote', '.',
  461. '-iquote', meson.current_source_dir(),
  462. '-iquote', meson.current_source_dir() / 'include',
  463. language: all_languages)
  464. # If a host-specific include directory exists, list that first...
  465. host_include = meson.current_source_dir() / 'host/include/'
  466. if fs.is_dir(host_include / host_arch)
  467. add_project_arguments('-iquote', host_include / host_arch,
  468. language: all_languages)
  469. endif
  470. # ... followed by the generic fallback.
  471. add_project_arguments('-iquote', host_include / 'generic',
  472. language: all_languages)
  473. sparse = find_program('cgcc', required: get_option('sparse'))
  474. if sparse.found()
  475. run_target('sparse',
  476. command: [find_program('scripts/check_sparse.py'),
  477. 'compile_commands.json', sparse.full_path(), '-Wbitwise',
  478. '-Wno-transparent-union', '-Wno-old-initializer',
  479. '-Wno-non-pointer-null'])
  480. endif
  481. ###########################################
  482. # Target-specific checks and dependencies #
  483. ###########################################
  484. # Fuzzing
  485. if get_option('fuzzing') and get_option('fuzzing_engine') == '' and \
  486. not cc.links('''
  487. #include <stdint.h>
  488. #include <sys/types.h>
  489. int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
  490. int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { return 0; }
  491. ''',
  492. args: ['-Werror', '-fsanitize=fuzzer'])
  493. error('Your compiler does not support -fsanitize=fuzzer')
  494. endif
  495. # Tracing backends
  496. if 'ftrace' in get_option('trace_backends') and targetos != 'linux'
  497. error('ftrace is supported only on Linux')
  498. endif
  499. if 'syslog' in get_option('trace_backends') and not cc.compiles('''
  500. #include <syslog.h>
  501. int main(void) {
  502. openlog("qemu", LOG_PID, LOG_DAEMON);
  503. syslog(LOG_INFO, "configure");
  504. return 0;
  505. }''')
  506. error('syslog is not supported on this system')
  507. endif
  508. # Miscellaneous Linux-only features
  509. get_option('mpath') \
  510. .require(targetos == 'linux', error_message: 'Multipath is supported only on Linux')
  511. multiprocess_allowed = get_option('multiprocess') \
  512. .require(targetos == 'linux', error_message: 'Multiprocess QEMU is supported only on Linux') \
  513. .allowed()
  514. vfio_user_server_allowed = get_option('vfio_user_server') \
  515. .require(targetos == 'linux', error_message: 'vfio-user server is supported only on Linux') \
  516. .allowed()
  517. have_tpm = get_option('tpm') \
  518. .require(targetos != 'windows', error_message: 'TPM emulation only available on POSIX systems') \
  519. .allowed()
  520. # vhost
  521. have_vhost_user = get_option('vhost_user') \
  522. .disable_auto_if(targetos != 'linux') \
  523. .require(targetos != 'windows',
  524. error_message: 'vhost-user is not available on Windows').allowed()
  525. have_vhost_vdpa = get_option('vhost_vdpa') \
  526. .require(targetos == 'linux',
  527. error_message: 'vhost-vdpa is only available on Linux').allowed()
  528. have_vhost_kernel = get_option('vhost_kernel') \
  529. .require(targetos == 'linux',
  530. error_message: 'vhost-kernel is only available on Linux').allowed()
  531. have_vhost_user_crypto = get_option('vhost_crypto') \
  532. .require(have_vhost_user,
  533. error_message: 'vhost-crypto requires vhost-user to be enabled').allowed()
  534. have_vhost = have_vhost_user or have_vhost_vdpa or have_vhost_kernel
  535. have_vhost_net_user = have_vhost_user and get_option('vhost_net').allowed()
  536. have_vhost_net_vdpa = have_vhost_vdpa and get_option('vhost_net').allowed()
  537. have_vhost_net_kernel = have_vhost_kernel and get_option('vhost_net').allowed()
  538. have_vhost_net = have_vhost_net_kernel or have_vhost_net_user or have_vhost_net_vdpa
  539. # Target-specific libraries and flags
  540. libm = cc.find_library('m', required: false)
  541. threads = dependency('threads')
  542. util = cc.find_library('util', required: false)
  543. winmm = []
  544. socket = []
  545. version_res = []
  546. coref = []
  547. iokit = []
  548. emulator_link_args = []
  549. nvmm =not_found
  550. hvf = not_found
  551. midl = not_found
  552. widl = not_found
  553. pathcch = not_found
  554. host_dsosuf = '.so'
  555. if targetos == 'windows'
  556. midl = find_program('midl', required: false)
  557. widl = find_program('widl', required: false)
  558. pathcch = cc.find_library('pathcch')
  559. socket = cc.find_library('ws2_32')
  560. winmm = cc.find_library('winmm')
  561. win = import('windows')
  562. version_res = win.compile_resources('version.rc',
  563. depend_files: files('pc-bios/qemu-nsis.ico'),
  564. include_directories: include_directories('.'))
  565. host_dsosuf = '.dll'
  566. elif targetos == 'darwin'
  567. coref = dependency('appleframeworks', modules: 'CoreFoundation')
  568. iokit = dependency('appleframeworks', modules: 'IOKit', required: false)
  569. host_dsosuf = '.dylib'
  570. elif targetos == 'sunos'
  571. socket = [cc.find_library('socket'),
  572. cc.find_library('nsl'),
  573. cc.find_library('resolv')]
  574. elif targetos == 'haiku'
  575. socket = [cc.find_library('posix_error_mapper'),
  576. cc.find_library('network'),
  577. cc.find_library('bsd')]
  578. elif targetos == 'openbsd'
  579. if get_option('tcg').allowed() and target_dirs.length() > 0
  580. # Disable OpenBSD W^X if available
  581. emulator_link_args = cc.get_supported_link_arguments('-Wl,-z,wxneeded')
  582. endif
  583. endif
  584. # Target-specific configuration of accelerators
  585. accelerators = []
  586. if get_option('kvm').allowed() and targetos == 'linux'
  587. accelerators += 'CONFIG_KVM'
  588. endif
  589. if get_option('whpx').allowed() and targetos == 'windows'
  590. if get_option('whpx').enabled() and host_machine.cpu() != 'x86_64'
  591. error('WHPX requires 64-bit host')
  592. elif cc.has_header('WinHvPlatform.h', required: get_option('whpx')) and \
  593. cc.has_header('WinHvEmulation.h', required: get_option('whpx'))
  594. accelerators += 'CONFIG_WHPX'
  595. endif
  596. endif
  597. if get_option('hvf').allowed()
  598. hvf = dependency('appleframeworks', modules: 'Hypervisor',
  599. required: get_option('hvf'))
  600. if hvf.found()
  601. accelerators += 'CONFIG_HVF'
  602. endif
  603. endif
  604. if get_option('hax').allowed()
  605. if get_option('hax').enabled() or targetos in ['windows', 'darwin', 'netbsd']
  606. accelerators += 'CONFIG_HAX'
  607. endif
  608. endif
  609. if targetos == 'netbsd'
  610. nvmm = cc.find_library('nvmm', required: get_option('nvmm'))
  611. if nvmm.found()
  612. accelerators += 'CONFIG_NVMM'
  613. endif
  614. endif
  615. tcg_arch = host_arch
  616. if get_option('tcg').allowed()
  617. if host_arch == 'unknown'
  618. if get_option('tcg_interpreter')
  619. warning('Unsupported CPU @0@, will use TCG with TCI (slow)'.format(cpu))
  620. else
  621. error('Unsupported CPU @0@, try --enable-tcg-interpreter'.format(cpu))
  622. endif
  623. elif get_option('tcg_interpreter')
  624. warning('Use of the TCG interpreter is not recommended on this host')
  625. warning('architecture. There is a native TCG execution backend available')
  626. warning('which provides substantially better performance and reliability.')
  627. warning('It is strongly recommended to remove the --enable-tcg-interpreter')
  628. warning('configuration option on this architecture to use the native')
  629. warning('backend.')
  630. endif
  631. if get_option('tcg_interpreter')
  632. tcg_arch = 'tci'
  633. config_host += { 'CONFIG_TCG_INTERPRETER': 'y' }
  634. elif host_arch == 'x86_64'
  635. tcg_arch = 'i386'
  636. elif host_arch == 'ppc64'
  637. tcg_arch = 'ppc'
  638. endif
  639. add_project_arguments('-iquote', meson.current_source_dir() / 'tcg' / tcg_arch,
  640. language: all_languages)
  641. accelerators += 'CONFIG_TCG'
  642. config_host += { 'CONFIG_TCG': 'y' }
  643. endif
  644. if 'CONFIG_KVM' not in accelerators and get_option('kvm').enabled()
  645. error('KVM not available on this platform')
  646. endif
  647. if 'CONFIG_HVF' not in accelerators and get_option('hvf').enabled()
  648. error('HVF not available on this platform')
  649. endif
  650. if 'CONFIG_NVMM' not in accelerators and get_option('nvmm').enabled()
  651. error('NVMM not available on this platform')
  652. endif
  653. if 'CONFIG_WHPX' not in accelerators and get_option('whpx').enabled()
  654. error('WHPX not available on this platform')
  655. endif
  656. ################
  657. # Dependencies #
  658. ################
  659. # When bumping glib minimum version, please check also whether to increase
  660. # the _WIN32_WINNT setting in osdep.h according to the value from glib
  661. glib_req_ver = '>=2.56.0'
  662. glib_pc = dependency('glib-2.0', version: glib_req_ver, required: true,
  663. method: 'pkg-config')
  664. glib_cflags = []
  665. if enable_modules
  666. gmodule = dependency('gmodule-export-2.0', version: glib_req_ver, required: true,
  667. method: 'pkg-config')
  668. elif config_host.has_key('CONFIG_PLUGIN')
  669. gmodule = dependency('gmodule-no-export-2.0', version: glib_req_ver, required: true,
  670. method: 'pkg-config')
  671. else
  672. gmodule = not_found
  673. endif
  674. # This workaround is required due to a bug in pkg-config file for glib as it
  675. # doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
  676. if targetos == 'windows' and get_option('prefer_static')
  677. glib_cflags += ['-DGLIB_STATIC_COMPILATION']
  678. endif
  679. # Sanity check that the current size_t matches the
  680. # size that glib thinks it should be. This catches
  681. # problems on multi-arch where people try to build
  682. # 32-bit QEMU while pointing at 64-bit glib headers
  683. if not cc.compiles('''
  684. #include <glib.h>
  685. #include <unistd.h>
  686. #define QEMU_BUILD_BUG_ON(x) \
  687. typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
  688. int main(void) {
  689. QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
  690. return 0;
  691. }''', dependencies: glib_pc, args: glib_cflags)
  692. error('''sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T.
  693. You probably need to set PKG_CONFIG_LIBDIR" to point
  694. to the right pkg-config files for your build target.''')
  695. endif
  696. # Silence clang warnings triggered by glib < 2.57.2
  697. if not cc.compiles('''
  698. #include <glib.h>
  699. typedef struct Foo {
  700. int i;
  701. } Foo;
  702. static void foo_free(Foo *f)
  703. {
  704. g_free(f);
  705. }
  706. G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
  707. int main(void) { return 0; }''', dependencies: glib_pc, args: ['-Wunused-function', '-Werror'])
  708. glib_cflags += cc.get_supported_arguments('-Wno-unused-function')
  709. endif
  710. glib = declare_dependency(dependencies: [glib_pc, gmodule],
  711. compile_args: glib_cflags,
  712. version: glib_pc.version())
  713. # Check whether glib has gslice, which we have to avoid for correctness.
  714. # TODO: remove this check and the corresponding workaround (qtree) when
  715. # the minimum supported glib is >= 2.75.3
  716. glib_has_gslice = glib.version().version_compare('<2.75.3')
  717. # override glib dep to include the above refinements
  718. meson.override_dependency('glib-2.0', glib)
  719. # The path to glib.h is added to all compilation commands.
  720. add_project_dependencies(glib.partial_dependency(compile_args: true, includes: true),
  721. native: false, language: all_languages)
  722. gio = not_found
  723. gdbus_codegen = not_found
  724. gdbus_codegen_error = '@0@ requires gdbus-codegen, please install libgio'
  725. if not get_option('gio').auto() or have_system
  726. gio = dependency('gio-2.0', required: get_option('gio'),
  727. method: 'pkg-config')
  728. if gio.found() and not cc.links('''
  729. #include <gio/gio.h>
  730. int main(void)
  731. {
  732. g_dbus_proxy_new_sync(0, 0, 0, 0, 0, 0, 0, 0);
  733. return 0;
  734. }''', dependencies: [glib, gio])
  735. if get_option('gio').enabled()
  736. error('The installed libgio is broken for static linking')
  737. endif
  738. gio = not_found
  739. endif
  740. if gio.found()
  741. gdbus_codegen = find_program(gio.get_variable('gdbus_codegen'),
  742. required: get_option('gio'))
  743. gio_unix = dependency('gio-unix-2.0', required: get_option('gio'),
  744. method: 'pkg-config')
  745. gio = declare_dependency(dependencies: [gio, gio_unix],
  746. version: gio.version())
  747. endif
  748. endif
  749. if gdbus_codegen.found() and get_option('cfi')
  750. gdbus_codegen = not_found
  751. gdbus_codegen_error = '@0@ uses gdbus-codegen, which does not support control flow integrity'
  752. endif
  753. lttng = not_found
  754. if 'ust' in get_option('trace_backends')
  755. lttng = dependency('lttng-ust', required: true, version: '>= 2.1',
  756. method: 'pkg-config')
  757. endif
  758. pixman = not_found
  759. if have_system or have_tools
  760. pixman = dependency('pixman-1', required: have_system, version:'>=0.21.8',
  761. method: 'pkg-config')
  762. endif
  763. zlib = dependency('zlib', required: true)
  764. libaio = not_found
  765. if not get_option('linux_aio').auto() or have_block
  766. libaio = cc.find_library('aio', has_headers: ['libaio.h'],
  767. required: get_option('linux_aio'))
  768. endif
  769. linux_io_uring_test = '''
  770. #include <liburing.h>
  771. #include <linux/errqueue.h>
  772. int main(void) { return 0; }'''
  773. linux_io_uring = not_found
  774. if not get_option('linux_io_uring').auto() or have_block
  775. linux_io_uring = dependency('liburing', version: '>=0.3',
  776. required: get_option('linux_io_uring'),
  777. method: 'pkg-config')
  778. if not cc.links(linux_io_uring_test)
  779. linux_io_uring = not_found
  780. endif
  781. endif
  782. libnfs = not_found
  783. if not get_option('libnfs').auto() or have_block
  784. libnfs = dependency('libnfs', version: '>=1.9.3',
  785. required: get_option('libnfs'),
  786. method: 'pkg-config')
  787. endif
  788. libattr_test = '''
  789. #include <stddef.h>
  790. #include <sys/types.h>
  791. #ifdef CONFIG_LIBATTR
  792. #include <attr/xattr.h>
  793. #else
  794. #include <sys/xattr.h>
  795. #endif
  796. int main(void) { getxattr(NULL, NULL, NULL, 0); setxattr(NULL, NULL, NULL, 0, 0); return 0; }'''
  797. libattr = not_found
  798. have_old_libattr = false
  799. if get_option('attr').allowed()
  800. if cc.links(libattr_test)
  801. libattr = declare_dependency()
  802. else
  803. libattr = cc.find_library('attr', has_headers: ['attr/xattr.h'],
  804. required: get_option('attr'))
  805. if libattr.found() and not \
  806. cc.links(libattr_test, dependencies: libattr, args: '-DCONFIG_LIBATTR')
  807. libattr = not_found
  808. if get_option('attr').enabled()
  809. error('could not link libattr')
  810. else
  811. warning('could not link libattr, disabling')
  812. endif
  813. else
  814. have_old_libattr = libattr.found()
  815. endif
  816. endif
  817. endif
  818. cocoa = dependency('appleframeworks', modules: ['Cocoa', 'CoreVideo'],
  819. required: get_option('cocoa'))
  820. vmnet = dependency('appleframeworks', modules: 'vmnet', required: get_option('vmnet'))
  821. if vmnet.found() and not cc.has_header_symbol('vmnet/vmnet.h',
  822. 'VMNET_BRIDGED_MODE',
  823. dependencies: vmnet)
  824. vmnet = not_found
  825. if get_option('vmnet').enabled()
  826. error('vmnet.framework API is outdated')
  827. else
  828. warning('vmnet.framework API is outdated, disabling')
  829. endif
  830. endif
  831. seccomp = not_found
  832. seccomp_has_sysrawrc = false
  833. if not get_option('seccomp').auto() or have_system or have_tools
  834. seccomp = dependency('libseccomp', version: '>=2.3.0',
  835. required: get_option('seccomp'),
  836. method: 'pkg-config')
  837. if seccomp.found()
  838. seccomp_has_sysrawrc = cc.has_header_symbol('seccomp.h',
  839. 'SCMP_FLTATR_API_SYSRAWRC',
  840. dependencies: seccomp)
  841. endif
  842. endif
  843. libcap_ng = not_found
  844. if not get_option('cap_ng').auto() or have_system or have_tools
  845. libcap_ng = cc.find_library('cap-ng', has_headers: ['cap-ng.h'],
  846. required: get_option('cap_ng'))
  847. endif
  848. if libcap_ng.found() and not cc.links('''
  849. #include <cap-ng.h>
  850. int main(void)
  851. {
  852. capng_capability_to_name(CAPNG_EFFECTIVE);
  853. return 0;
  854. }''', dependencies: libcap_ng)
  855. libcap_ng = not_found
  856. if get_option('cap_ng').enabled()
  857. error('could not link libcap-ng')
  858. else
  859. warning('could not link libcap-ng, disabling')
  860. endif
  861. endif
  862. if get_option('xkbcommon').auto() and not have_system and not have_tools
  863. xkbcommon = not_found
  864. else
  865. xkbcommon = dependency('xkbcommon', required: get_option('xkbcommon'),
  866. method: 'pkg-config')
  867. endif
  868. slirp = not_found
  869. if not get_option('slirp').auto() or have_system
  870. slirp = dependency('slirp', required: get_option('slirp'),
  871. method: 'pkg-config')
  872. # slirp < 4.7 is incompatible with CFI support in QEMU. This is because
  873. # it passes function pointers within libslirp as callbacks for timers.
  874. # When using a system-wide shared libslirp, the type information for the
  875. # callback is missing and the timer call produces a false positive with CFI.
  876. # Do not use the "version" keyword argument to produce a better error.
  877. # with control-flow integrity.
  878. if get_option('cfi') and slirp.found() and slirp.version().version_compare('<4.7')
  879. if get_option('slirp').enabled()
  880. error('Control-Flow Integrity requires libslirp 4.7.')
  881. else
  882. warning('Cannot use libslirp since Control-Flow Integrity requires libslirp >= 4.7.')
  883. slirp = not_found
  884. endif
  885. endif
  886. endif
  887. vde = not_found
  888. if not get_option('vde').auto() or have_system or have_tools
  889. vde = cc.find_library('vdeplug', has_headers: ['libvdeplug.h'],
  890. required: get_option('vde'))
  891. endif
  892. if vde.found() and not cc.links('''
  893. #include <libvdeplug.h>
  894. int main(void)
  895. {
  896. struct vde_open_args a = {0, 0, 0};
  897. char s[] = "";
  898. vde_open(s, s, &a);
  899. return 0;
  900. }''', dependencies: vde)
  901. vde = not_found
  902. if get_option('cap_ng').enabled()
  903. error('could not link libvdeplug')
  904. else
  905. warning('could not link libvdeplug, disabling')
  906. endif
  907. endif
  908. pulse = not_found
  909. if not get_option('pa').auto() or (targetos == 'linux' and have_system)
  910. pulse = dependency('libpulse', required: get_option('pa'),
  911. method: 'pkg-config')
  912. endif
  913. alsa = not_found
  914. if not get_option('alsa').auto() or (targetos == 'linux' and have_system)
  915. alsa = dependency('alsa', required: get_option('alsa'),
  916. method: 'pkg-config')
  917. endif
  918. jack = not_found
  919. if not get_option('jack').auto() or have_system
  920. jack = dependency('jack', required: get_option('jack'),
  921. method: 'pkg-config')
  922. endif
  923. pipewire = not_found
  924. if not get_option('pipewire').auto() or (targetos == 'linux' and have_system)
  925. pipewire = dependency('libpipewire-0.3', version: '>=0.3.60',
  926. required: get_option('pipewire'),
  927. method: 'pkg-config')
  928. endif
  929. sndio = not_found
  930. if not get_option('sndio').auto() or have_system
  931. sndio = dependency('sndio', required: get_option('sndio'),
  932. method: 'pkg-config')
  933. endif
  934. spice_protocol = not_found
  935. if not get_option('spice_protocol').auto() or have_system
  936. spice_protocol = dependency('spice-protocol', version: '>=0.14.0',
  937. required: get_option('spice_protocol'),
  938. method: 'pkg-config')
  939. endif
  940. spice = not_found
  941. if not get_option('spice').auto() or have_system
  942. spice = dependency('spice-server', version: '>=0.14.0',
  943. required: get_option('spice'),
  944. method: 'pkg-config')
  945. endif
  946. spice_headers = spice.partial_dependency(compile_args: true, includes: true)
  947. rt = cc.find_library('rt', required: false)
  948. libiscsi = not_found
  949. if not get_option('libiscsi').auto() or have_block
  950. libiscsi = dependency('libiscsi', version: '>=1.9.0',
  951. required: get_option('libiscsi'),
  952. method: 'pkg-config')
  953. endif
  954. zstd = not_found
  955. if not get_option('zstd').auto() or have_block
  956. zstd = dependency('libzstd', version: '>=1.4.0',
  957. required: get_option('zstd'),
  958. method: 'pkg-config')
  959. endif
  960. virgl = not_found
  961. have_vhost_user_gpu = have_tools and targetos == 'linux' and pixman.found()
  962. if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu
  963. virgl = dependency('virglrenderer',
  964. method: 'pkg-config',
  965. required: get_option('virglrenderer'))
  966. endif
  967. blkio = not_found
  968. if not get_option('blkio').auto() or have_block
  969. blkio = dependency('blkio',
  970. method: 'pkg-config',
  971. required: get_option('blkio'))
  972. endif
  973. curl = not_found
  974. if not get_option('curl').auto() or have_block
  975. curl = dependency('libcurl', version: '>=7.29.0',
  976. method: 'pkg-config',
  977. required: get_option('curl'))
  978. endif
  979. libudev = not_found
  980. if targetos == 'linux' and (have_system or have_tools)
  981. libudev = dependency('libudev',
  982. method: 'pkg-config',
  983. required: get_option('libudev'))
  984. endif
  985. mpathlibs = [libudev]
  986. mpathpersist = not_found
  987. if targetos == 'linux' and have_tools and get_option('mpath').allowed()
  988. mpath_test_source = '''
  989. #include <libudev.h>
  990. #include <mpath_persist.h>
  991. unsigned mpath_mx_alloc_len = 1024;
  992. int logsink;
  993. static struct config *multipath_conf;
  994. extern struct udev *udev;
  995. extern struct config *get_multipath_config(void);
  996. extern void put_multipath_config(struct config *conf);
  997. struct udev *udev;
  998. struct config *get_multipath_config(void) { return multipath_conf; }
  999. void put_multipath_config(struct config *conf) { }
  1000. int main(void) {
  1001. udev = udev_new();
  1002. multipath_conf = mpath_lib_init();
  1003. return 0;
  1004. }'''
  1005. libmpathpersist = cc.find_library('mpathpersist',
  1006. required: get_option('mpath'))
  1007. if libmpathpersist.found()
  1008. mpathlibs += libmpathpersist
  1009. if get_option('prefer_static')
  1010. mpathlibs += cc.find_library('devmapper',
  1011. required: get_option('mpath'))
  1012. endif
  1013. mpathlibs += cc.find_library('multipath',
  1014. required: get_option('mpath'))
  1015. foreach lib: mpathlibs
  1016. if not lib.found()
  1017. mpathlibs = []
  1018. break
  1019. endif
  1020. endforeach
  1021. if mpathlibs.length() == 0
  1022. msg = 'Dependencies missing for libmpathpersist'
  1023. elif cc.links(mpath_test_source, dependencies: mpathlibs)
  1024. mpathpersist = declare_dependency(dependencies: mpathlibs)
  1025. else
  1026. msg = 'Cannot detect libmpathpersist API'
  1027. endif
  1028. if not mpathpersist.found()
  1029. if get_option('mpath').enabled()
  1030. error(msg)
  1031. else
  1032. warning(msg + ', disabling')
  1033. endif
  1034. endif
  1035. endif
  1036. endif
  1037. iconv = not_found
  1038. curses = not_found
  1039. if have_system and get_option('curses').allowed()
  1040. curses_test = '''
  1041. #if defined(__APPLE__) || defined(__OpenBSD__)
  1042. #define _XOPEN_SOURCE_EXTENDED 1
  1043. #endif
  1044. #include <locale.h>
  1045. #include <curses.h>
  1046. #include <wchar.h>
  1047. int main(void) {
  1048. wchar_t wch = L'w';
  1049. setlocale(LC_ALL, "");
  1050. resize_term(0, 0);
  1051. addwstr(L"wide chars\n");
  1052. addnwstr(&wch, 1);
  1053. add_wch(WACS_DEGREE);
  1054. return 0;
  1055. }'''
  1056. curses_dep_list = targetos == 'windows' ? ['ncurses', 'ncursesw'] : ['ncursesw']
  1057. curses = dependency(curses_dep_list,
  1058. required: false,
  1059. method: 'pkg-config')
  1060. msg = get_option('curses').enabled() ? 'curses library not found' : ''
  1061. curses_compile_args = ['-DNCURSES_WIDECHAR=1']
  1062. if curses.found()
  1063. if cc.links(curses_test, args: curses_compile_args, dependencies: [curses])
  1064. curses = declare_dependency(compile_args: curses_compile_args, dependencies: [curses],
  1065. version: curses.version())
  1066. else
  1067. msg = 'curses package not usable'
  1068. curses = not_found
  1069. endif
  1070. endif
  1071. if not curses.found()
  1072. has_curses_h = cc.has_header('curses.h', args: curses_compile_args)
  1073. if targetos != 'windows' and not has_curses_h
  1074. message('Trying with /usr/include/ncursesw')
  1075. curses_compile_args += ['-I/usr/include/ncursesw']
  1076. has_curses_h = cc.has_header('curses.h', args: curses_compile_args)
  1077. endif
  1078. if has_curses_h
  1079. curses_libname_list = (targetos == 'windows' ? ['pdcurses'] : ['ncursesw', 'cursesw'])
  1080. foreach curses_libname : curses_libname_list
  1081. libcurses = cc.find_library(curses_libname,
  1082. required: false)
  1083. if libcurses.found()
  1084. if cc.links(curses_test, args: curses_compile_args, dependencies: libcurses)
  1085. curses = declare_dependency(compile_args: curses_compile_args,
  1086. dependencies: [libcurses])
  1087. break
  1088. else
  1089. msg = 'curses library not usable'
  1090. endif
  1091. endif
  1092. endforeach
  1093. endif
  1094. endif
  1095. if get_option('iconv').allowed()
  1096. foreach link_args : [ ['-liconv'], [] ]
  1097. # Programs will be linked with glib and this will bring in libiconv on FreeBSD.
  1098. # We need to use libiconv if available because mixing libiconv's headers with
  1099. # the system libc does not work.
  1100. # However, without adding glib to the dependencies -L/usr/local/lib will not be
  1101. # included in the command line and libiconv will not be found.
  1102. if cc.links('''
  1103. #include <iconv.h>
  1104. int main(void) {
  1105. iconv_t conv = iconv_open("WCHAR_T", "UCS-2");
  1106. return conv != (iconv_t) -1;
  1107. }''', args: link_args, dependencies: glib)
  1108. iconv = declare_dependency(link_args: link_args, dependencies: glib)
  1109. break
  1110. endif
  1111. endforeach
  1112. endif
  1113. if curses.found() and not iconv.found()
  1114. if get_option('iconv').enabled()
  1115. error('iconv not available')
  1116. endif
  1117. msg = 'iconv required for curses UI but not available'
  1118. curses = not_found
  1119. endif
  1120. if not curses.found() and msg != ''
  1121. if get_option('curses').enabled()
  1122. error(msg)
  1123. else
  1124. warning(msg + ', disabling')
  1125. endif
  1126. endif
  1127. endif
  1128. brlapi = not_found
  1129. if not get_option('brlapi').auto() or have_system
  1130. brlapi = cc.find_library('brlapi', has_headers: ['brlapi.h'],
  1131. required: get_option('brlapi'))
  1132. if brlapi.found() and not cc.links('''
  1133. #include <brlapi.h>
  1134. #include <stddef.h>
  1135. int main(void) { return brlapi__openConnection (NULL, NULL, NULL); }''', dependencies: brlapi)
  1136. brlapi = not_found
  1137. if get_option('brlapi').enabled()
  1138. error('could not link brlapi')
  1139. else
  1140. warning('could not link brlapi, disabling')
  1141. endif
  1142. endif
  1143. endif
  1144. sdl = not_found
  1145. if not get_option('sdl').auto() or have_system
  1146. sdl = dependency('sdl2', required: get_option('sdl'))
  1147. sdl_image = not_found
  1148. endif
  1149. if sdl.found()
  1150. # Some versions of SDL have problems with -Wundef
  1151. if not cc.compiles('''
  1152. #include <SDL.h>
  1153. #include <SDL_syswm.h>
  1154. int main(int argc, char *argv[]) { return 0; }
  1155. ''', dependencies: sdl, args: '-Werror=undef')
  1156. sdl = declare_dependency(compile_args: '-Wno-undef',
  1157. dependencies: sdl,
  1158. version: sdl.version())
  1159. endif
  1160. sdl_image = dependency('SDL2_image', required: get_option('sdl_image'),
  1161. method: 'pkg-config')
  1162. else
  1163. if get_option('sdl_image').enabled()
  1164. error('sdl-image required, but SDL was @0@'.format(
  1165. get_option('sdl').disabled() ? 'disabled' : 'not found'))
  1166. endif
  1167. sdl_image = not_found
  1168. endif
  1169. rbd = not_found
  1170. if not get_option('rbd').auto() or have_block
  1171. librados = cc.find_library('rados', required: get_option('rbd'))
  1172. librbd = cc.find_library('rbd', has_headers: ['rbd/librbd.h'],
  1173. required: get_option('rbd'))
  1174. if librados.found() and librbd.found()
  1175. if cc.links('''
  1176. #include <stdio.h>
  1177. #include <rbd/librbd.h>
  1178. int main(void) {
  1179. rados_t cluster;
  1180. rados_create(&cluster, NULL);
  1181. #if LIBRBD_VERSION_CODE < LIBRBD_VERSION(1, 12, 0)
  1182. #error
  1183. #endif
  1184. return 0;
  1185. }''', dependencies: [librbd, librados])
  1186. rbd = declare_dependency(dependencies: [librbd, librados])
  1187. elif get_option('rbd').enabled()
  1188. error('librbd >= 1.12.0 required')
  1189. else
  1190. warning('librbd >= 1.12.0 not found, disabling')
  1191. endif
  1192. endif
  1193. endif
  1194. glusterfs = not_found
  1195. glusterfs_ftruncate_has_stat = false
  1196. glusterfs_iocb_has_stat = false
  1197. if not get_option('glusterfs').auto() or have_block
  1198. glusterfs = dependency('glusterfs-api', version: '>=3',
  1199. required: get_option('glusterfs'),
  1200. method: 'pkg-config')
  1201. if glusterfs.found()
  1202. glusterfs_ftruncate_has_stat = cc.links('''
  1203. #include <glusterfs/api/glfs.h>
  1204. int
  1205. main(void)
  1206. {
  1207. /* new glfs_ftruncate() passes two additional args */
  1208. return glfs_ftruncate(NULL, 0, NULL, NULL);
  1209. }
  1210. ''', dependencies: glusterfs)
  1211. glusterfs_iocb_has_stat = cc.links('''
  1212. #include <glusterfs/api/glfs.h>
  1213. /* new glfs_io_cbk() passes two additional glfs_stat structs */
  1214. static void
  1215. glusterfs_iocb(glfs_fd_t *fd, ssize_t ret, struct glfs_stat *prestat, struct glfs_stat *poststat, void *data)
  1216. {}
  1217. int
  1218. main(void)
  1219. {
  1220. glfs_io_cbk iocb = &glusterfs_iocb;
  1221. iocb(NULL, 0 , NULL, NULL, NULL);
  1222. return 0;
  1223. }
  1224. ''', dependencies: glusterfs)
  1225. endif
  1226. endif
  1227. libssh = not_found
  1228. if not get_option('libssh').auto() or have_block
  1229. libssh = dependency('libssh', version: '>=0.8.7',
  1230. method: 'pkg-config',
  1231. required: get_option('libssh'))
  1232. endif
  1233. libbzip2 = not_found
  1234. if not get_option('bzip2').auto() or have_block
  1235. libbzip2 = cc.find_library('bz2', has_headers: ['bzlib.h'],
  1236. required: get_option('bzip2'))
  1237. if libbzip2.found() and not cc.links('''
  1238. #include <bzlib.h>
  1239. int main(void) { BZ2_bzlibVersion(); return 0; }''', dependencies: libbzip2)
  1240. libbzip2 = not_found
  1241. if get_option('bzip2').enabled()
  1242. error('could not link libbzip2')
  1243. else
  1244. warning('could not link libbzip2, disabling')
  1245. endif
  1246. endif
  1247. endif
  1248. liblzfse = not_found
  1249. if not get_option('lzfse').auto() or have_block
  1250. liblzfse = cc.find_library('lzfse', has_headers: ['lzfse.h'],
  1251. required: get_option('lzfse'))
  1252. endif
  1253. if liblzfse.found() and not cc.links('''
  1254. #include <lzfse.h>
  1255. int main(void) { lzfse_decode_scratch_size(); return 0; }''', dependencies: liblzfse)
  1256. liblzfse = not_found
  1257. if get_option('lzfse').enabled()
  1258. error('could not link liblzfse')
  1259. else
  1260. warning('could not link liblzfse, disabling')
  1261. endif
  1262. endif
  1263. oss = not_found
  1264. if get_option('oss').allowed() and have_system
  1265. if not cc.has_header('sys/soundcard.h')
  1266. # not found
  1267. elif targetos == 'netbsd'
  1268. oss = cc.find_library('ossaudio', required: get_option('oss'))
  1269. else
  1270. oss = declare_dependency()
  1271. endif
  1272. if not oss.found()
  1273. if get_option('oss').enabled()
  1274. error('OSS not found')
  1275. endif
  1276. endif
  1277. endif
  1278. dsound = not_found
  1279. if not get_option('dsound').auto() or (targetos == 'windows' and have_system)
  1280. if cc.has_header('dsound.h')
  1281. dsound = declare_dependency(link_args: ['-lole32', '-ldxguid'])
  1282. endif
  1283. if not dsound.found()
  1284. if get_option('dsound').enabled()
  1285. error('DirectSound not found')
  1286. endif
  1287. endif
  1288. endif
  1289. coreaudio = not_found
  1290. if not get_option('coreaudio').auto() or (targetos == 'darwin' and have_system)
  1291. coreaudio = dependency('appleframeworks', modules: 'CoreAudio',
  1292. required: get_option('coreaudio'))
  1293. endif
  1294. opengl = not_found
  1295. if not get_option('opengl').auto() or have_system or have_vhost_user_gpu
  1296. epoxy = dependency('epoxy', method: 'pkg-config',
  1297. required: get_option('opengl'))
  1298. if cc.has_header('epoxy/egl.h', dependencies: epoxy)
  1299. opengl = epoxy
  1300. elif get_option('opengl').enabled()
  1301. error('epoxy/egl.h not found')
  1302. endif
  1303. endif
  1304. gbm = not_found
  1305. if (have_system or have_tools) and (virgl.found() or opengl.found())
  1306. gbm = dependency('gbm', method: 'pkg-config', required: false)
  1307. endif
  1308. have_vhost_user_gpu = have_vhost_user_gpu and virgl.found() and opengl.found() and gbm.found()
  1309. gnutls = not_found
  1310. gnutls_crypto = not_found
  1311. if get_option('gnutls').enabled() or (get_option('gnutls').auto() and have_system)
  1312. # For general TLS support our min gnutls matches
  1313. # that implied by our platform support matrix
  1314. #
  1315. # For the crypto backends, we look for a newer
  1316. # gnutls:
  1317. #
  1318. # Version 3.6.8 is needed to get XTS
  1319. # Version 3.6.13 is needed to get PBKDF
  1320. # Version 3.6.14 is needed to get HW accelerated XTS
  1321. #
  1322. # If newer enough gnutls isn't available, we can
  1323. # still use a different crypto backend to satisfy
  1324. # the platform support requirements
  1325. gnutls_crypto = dependency('gnutls', version: '>=3.6.14',
  1326. method: 'pkg-config',
  1327. required: false)
  1328. if gnutls_crypto.found()
  1329. gnutls = gnutls_crypto
  1330. else
  1331. # Our min version if all we need is TLS
  1332. gnutls = dependency('gnutls', version: '>=3.5.18',
  1333. method: 'pkg-config',
  1334. required: get_option('gnutls'))
  1335. endif
  1336. endif
  1337. # We prefer use of gnutls for crypto, unless the options
  1338. # explicitly asked for nettle or gcrypt.
  1339. #
  1340. # If gnutls isn't available for crypto, then we'll prefer
  1341. # gcrypt over nettle for performance reasons.
  1342. gcrypt = not_found
  1343. nettle = not_found
  1344. hogweed = not_found
  1345. xts = 'none'
  1346. if get_option('nettle').enabled() and get_option('gcrypt').enabled()
  1347. error('Only one of gcrypt & nettle can be enabled')
  1348. endif
  1349. # Explicit nettle/gcrypt request, so ignore gnutls for crypto
  1350. if get_option('nettle').enabled() or get_option('gcrypt').enabled()
  1351. gnutls_crypto = not_found
  1352. endif
  1353. if not gnutls_crypto.found()
  1354. if (not get_option('gcrypt').auto() or have_system) and not get_option('nettle').enabled()
  1355. gcrypt = dependency('libgcrypt', version: '>=1.8',
  1356. method: 'config-tool',
  1357. required: get_option('gcrypt'))
  1358. # Debian has removed -lgpg-error from libgcrypt-config
  1359. # as it "spreads unnecessary dependencies" which in
  1360. # turn breaks static builds...
  1361. if gcrypt.found() and get_option('prefer_static')
  1362. gcrypt = declare_dependency(dependencies:
  1363. [gcrypt,
  1364. cc.find_library('gpg-error', required: true)],
  1365. version: gcrypt.version())
  1366. endif
  1367. endif
  1368. if (not get_option('nettle').auto() or have_system) and not gcrypt.found()
  1369. nettle = dependency('nettle', version: '>=3.4',
  1370. method: 'pkg-config',
  1371. required: get_option('nettle'))
  1372. if nettle.found() and not cc.has_header('nettle/xts.h', dependencies: nettle)
  1373. xts = 'private'
  1374. endif
  1375. endif
  1376. endif
  1377. gmp = dependency('gmp', required: false, method: 'pkg-config')
  1378. if nettle.found() and gmp.found()
  1379. hogweed = dependency('hogweed', version: '>=3.4',
  1380. method: 'pkg-config',
  1381. required: get_option('nettle'))
  1382. endif
  1383. gtk = not_found
  1384. gtkx11 = not_found
  1385. vte = not_found
  1386. have_gtk_clipboard = get_option('gtk_clipboard').enabled()
  1387. if not get_option('gtk').auto() or have_system
  1388. gtk = dependency('gtk+-3.0', version: '>=3.22.0',
  1389. method: 'pkg-config',
  1390. required: get_option('gtk'))
  1391. if gtk.found()
  1392. gtkx11 = dependency('gtk+-x11-3.0', version: '>=3.22.0',
  1393. method: 'pkg-config',
  1394. required: false)
  1395. gtk = declare_dependency(dependencies: [gtk, gtkx11],
  1396. version: gtk.version())
  1397. if not get_option('vte').auto() or have_system
  1398. vte = dependency('vte-2.91',
  1399. method: 'pkg-config',
  1400. required: get_option('vte'))
  1401. endif
  1402. elif have_gtk_clipboard
  1403. error('GTK clipboard requested, but GTK not found')
  1404. endif
  1405. endif
  1406. x11 = not_found
  1407. if gtkx11.found()
  1408. x11 = dependency('x11', method: 'pkg-config', required: gtkx11.found())
  1409. endif
  1410. png = not_found
  1411. if get_option('png').allowed() and have_system
  1412. png = dependency('libpng', version: '>=1.6.34', required: get_option('png'),
  1413. method: 'pkg-config')
  1414. endif
  1415. vnc = not_found
  1416. jpeg = not_found
  1417. sasl = not_found
  1418. if get_option('vnc').allowed() and have_system
  1419. vnc = declare_dependency() # dummy dependency
  1420. jpeg = dependency('libjpeg', required: get_option('vnc_jpeg'),
  1421. method: 'pkg-config')
  1422. sasl = cc.find_library('sasl2', has_headers: ['sasl/sasl.h'],
  1423. required: get_option('vnc_sasl'))
  1424. if sasl.found()
  1425. sasl = declare_dependency(dependencies: sasl,
  1426. compile_args: '-DSTRUCT_IOVEC_DEFINED')
  1427. endif
  1428. endif
  1429. pam = not_found
  1430. if not get_option('auth_pam').auto() or have_system
  1431. pam = cc.find_library('pam', has_headers: ['security/pam_appl.h'],
  1432. required: get_option('auth_pam'))
  1433. endif
  1434. if pam.found() and not cc.links('''
  1435. #include <stddef.h>
  1436. #include <security/pam_appl.h>
  1437. int main(void) {
  1438. const char *service_name = "qemu";
  1439. const char *user = "frank";
  1440. const struct pam_conv pam_conv = { 0 };
  1441. pam_handle_t *pamh = NULL;
  1442. pam_start(service_name, user, &pam_conv, &pamh);
  1443. return 0;
  1444. }''', dependencies: pam)
  1445. pam = not_found
  1446. if get_option('auth_pam').enabled()
  1447. error('could not link libpam')
  1448. else
  1449. warning('could not link libpam, disabling')
  1450. endif
  1451. endif
  1452. snappy = not_found
  1453. if not get_option('snappy').auto() or have_system
  1454. snappy = cc.find_library('snappy', has_headers: ['snappy-c.h'],
  1455. required: get_option('snappy'))
  1456. endif
  1457. if snappy.found() and not linker.links('''
  1458. #include <snappy-c.h>
  1459. int main(void) { snappy_max_compressed_length(4096); return 0; }''', dependencies: snappy)
  1460. snappy = not_found
  1461. if get_option('snappy').enabled()
  1462. error('could not link libsnappy')
  1463. else
  1464. warning('could not link libsnappy, disabling')
  1465. endif
  1466. endif
  1467. lzo = not_found
  1468. if not get_option('lzo').auto() or have_system
  1469. lzo = cc.find_library('lzo2', has_headers: ['lzo/lzo1x.h'],
  1470. required: get_option('lzo'))
  1471. endif
  1472. if lzo.found() and not cc.links('''
  1473. #include <lzo/lzo1x.h>
  1474. int main(void) { lzo_version(); return 0; }''', dependencies: lzo)
  1475. lzo = not_found
  1476. if get_option('lzo').enabled()
  1477. error('could not link liblzo2')
  1478. else
  1479. warning('could not link liblzo2, disabling')
  1480. endif
  1481. endif
  1482. numa = not_found
  1483. if not get_option('numa').auto() or have_system or have_tools
  1484. numa = cc.find_library('numa', has_headers: ['numa.h'],
  1485. required: get_option('numa'))
  1486. endif
  1487. if numa.found() and not cc.links('''
  1488. #include <numa.h>
  1489. int main(void) { return numa_available(); }
  1490. ''', dependencies: numa)
  1491. numa = not_found
  1492. if get_option('numa').enabled()
  1493. error('could not link numa')
  1494. else
  1495. warning('could not link numa, disabling')
  1496. endif
  1497. endif
  1498. rdma = not_found
  1499. if not get_option('rdma').auto() or have_system
  1500. libumad = cc.find_library('ibumad', required: get_option('rdma'))
  1501. rdma_libs = [cc.find_library('rdmacm', has_headers: ['rdma/rdma_cma.h'],
  1502. required: get_option('rdma')),
  1503. cc.find_library('ibverbs', required: get_option('rdma')),
  1504. libumad]
  1505. rdma = declare_dependency(dependencies: rdma_libs)
  1506. foreach lib: rdma_libs
  1507. if not lib.found()
  1508. rdma = not_found
  1509. endif
  1510. endforeach
  1511. endif
  1512. xen = not_found
  1513. if get_option('xen').enabled() or (get_option('xen').auto() and have_system)
  1514. xencontrol = dependency('xencontrol', required: false,
  1515. method: 'pkg-config')
  1516. if xencontrol.found()
  1517. xen_pc = declare_dependency(version: xencontrol.version(),
  1518. dependencies: [
  1519. xencontrol,
  1520. # disabler: true makes xen_pc.found() return false if any is not found
  1521. dependency('xenstore', required: false,
  1522. method: 'pkg-config',
  1523. disabler: true),
  1524. dependency('xenforeignmemory', required: false,
  1525. method: 'pkg-config',
  1526. disabler: true),
  1527. dependency('xengnttab', required: false,
  1528. method: 'pkg-config',
  1529. disabler: true),
  1530. dependency('xenevtchn', required: false,
  1531. method: 'pkg-config',
  1532. disabler: true),
  1533. dependency('xendevicemodel', required: false,
  1534. method: 'pkg-config',
  1535. disabler: true),
  1536. # optional, no "disabler: true"
  1537. dependency('xentoolcore', required: false,
  1538. method: 'pkg-config')])
  1539. if xen_pc.found()
  1540. xen = xen_pc
  1541. endif
  1542. endif
  1543. if not xen.found()
  1544. xen_tests = [ '4.11.0', '4.10.0', '4.9.0', '4.8.0', '4.7.1' ]
  1545. xen_libs = {
  1546. '4.11.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemory', 'xengnttab', 'xenevtchn', 'xentoolcore' ],
  1547. '4.10.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemory', 'xengnttab', 'xenevtchn', 'xentoolcore' ],
  1548. '4.9.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemory', 'xengnttab', 'xenevtchn' ],
  1549. '4.8.0': [ 'xenstore', 'xenctrl', 'xenforeignmemory', 'xengnttab', 'xenevtchn' ],
  1550. '4.7.1': [ 'xenstore', 'xenctrl', 'xenforeignmemory', 'xengnttab', 'xenevtchn' ],
  1551. }
  1552. xen_deps = {}
  1553. foreach ver: xen_tests
  1554. # cache the various library tests to avoid polluting the logs
  1555. xen_test_deps = []
  1556. foreach l: xen_libs[ver]
  1557. if l not in xen_deps
  1558. xen_deps += { l: cc.find_library(l, required: false) }
  1559. endif
  1560. xen_test_deps += xen_deps[l]
  1561. endforeach
  1562. # Use -D to pick just one of the test programs in scripts/xen-detect.c
  1563. xen_version = ver.split('.')
  1564. xen_ctrl_version = xen_version[0] + \
  1565. ('0' + xen_version[1]).substring(-2) + \
  1566. ('0' + xen_version[2]).substring(-2)
  1567. if cc.links(files('scripts/xen-detect.c'),
  1568. args: '-DCONFIG_XEN_CTRL_INTERFACE_VERSION=' + xen_ctrl_version,
  1569. dependencies: xen_test_deps)
  1570. xen = declare_dependency(version: ver, dependencies: xen_test_deps)
  1571. break
  1572. endif
  1573. endforeach
  1574. endif
  1575. if xen.found()
  1576. accelerators += 'CONFIG_XEN'
  1577. elif get_option('xen').enabled()
  1578. error('could not compile and link Xen test program')
  1579. endif
  1580. endif
  1581. have_xen_pci_passthrough = get_option('xen_pci_passthrough') \
  1582. .require(xen.found(),
  1583. error_message: 'Xen PCI passthrough requested but Xen not enabled') \
  1584. .require(targetos == 'linux',
  1585. error_message: 'Xen PCI passthrough not available on this platform') \
  1586. .allowed()
  1587. cacard = not_found
  1588. if not get_option('smartcard').auto() or have_system
  1589. cacard = dependency('libcacard', required: get_option('smartcard'),
  1590. version: '>=2.5.1', method: 'pkg-config')
  1591. endif
  1592. u2f = not_found
  1593. if have_system
  1594. u2f = dependency('u2f-emu', required: get_option('u2f'),
  1595. method: 'pkg-config')
  1596. endif
  1597. canokey = not_found
  1598. if have_system
  1599. canokey = dependency('canokey-qemu', required: get_option('canokey'),
  1600. method: 'pkg-config')
  1601. endif
  1602. usbredir = not_found
  1603. if not get_option('usb_redir').auto() or have_system
  1604. usbredir = dependency('libusbredirparser-0.5', required: get_option('usb_redir'),
  1605. version: '>=0.6', method: 'pkg-config')
  1606. endif
  1607. libusb = not_found
  1608. if not get_option('libusb').auto() or have_system
  1609. libusb = dependency('libusb-1.0', required: get_option('libusb'),
  1610. version: '>=1.0.13', method: 'pkg-config')
  1611. endif
  1612. libpmem = not_found
  1613. if not get_option('libpmem').auto() or have_system
  1614. libpmem = dependency('libpmem', required: get_option('libpmem'),
  1615. method: 'pkg-config')
  1616. endif
  1617. libdaxctl = not_found
  1618. if not get_option('libdaxctl').auto() or have_system
  1619. libdaxctl = dependency('libdaxctl', required: get_option('libdaxctl'),
  1620. version: '>=57', method: 'pkg-config')
  1621. endif
  1622. tasn1 = not_found
  1623. if gnutls.found()
  1624. tasn1 = dependency('libtasn1',
  1625. method: 'pkg-config')
  1626. endif
  1627. keyutils = not_found
  1628. if get_option('keyring').enabled()
  1629. keyutils = dependency('libkeyutils', required: false, method: 'pkg-config')
  1630. endif
  1631. has_gettid = cc.has_function('gettid')
  1632. # libselinux
  1633. selinux = dependency('libselinux',
  1634. required: get_option('selinux'),
  1635. method: 'pkg-config')
  1636. # Malloc tests
  1637. malloc = []
  1638. if get_option('malloc') == 'system'
  1639. has_malloc_trim = \
  1640. get_option('malloc_trim').allowed() and \
  1641. cc.has_function('malloc_trim', prefix: '#include <malloc.h>')
  1642. else
  1643. has_malloc_trim = false
  1644. malloc = cc.find_library(get_option('malloc'), required: true)
  1645. endif
  1646. if not has_malloc_trim and get_option('malloc_trim').enabled()
  1647. if get_option('malloc') == 'system'
  1648. error('malloc_trim not available on this platform.')
  1649. else
  1650. error('malloc_trim not available with non-libc memory allocator')
  1651. endif
  1652. endif
  1653. gnu_source_prefix = '''
  1654. #ifndef _GNU_SOURCE
  1655. #define _GNU_SOURCE
  1656. #endif
  1657. '''
  1658. # Check whether the glibc provides STATX_BASIC_STATS
  1659. has_statx = cc.has_header_symbol('sys/stat.h', 'STATX_BASIC_STATS', prefix: gnu_source_prefix)
  1660. # Check whether statx() provides mount ID information
  1661. has_statx_mnt_id = cc.has_header_symbol('sys/stat.h', 'STATX_MNT_ID', prefix: gnu_source_prefix)
  1662. have_vhost_user_blk_server = get_option('vhost_user_blk_server') \
  1663. .require(targetos == 'linux',
  1664. error_message: 'vhost_user_blk_server requires linux') \
  1665. .require(have_vhost_user,
  1666. error_message: 'vhost_user_blk_server requires vhost-user support') \
  1667. .disable_auto_if(not have_tools and not have_system) \
  1668. .allowed()
  1669. if get_option('fuse').disabled() and get_option('fuse_lseek').enabled()
  1670. error('Cannot enable fuse-lseek while fuse is disabled')
  1671. endif
  1672. fuse = dependency('fuse3', required: get_option('fuse'),
  1673. version: '>=3.1', method: 'pkg-config')
  1674. fuse_lseek = not_found
  1675. if get_option('fuse_lseek').allowed()
  1676. if fuse.version().version_compare('>=3.8')
  1677. # Dummy dependency
  1678. fuse_lseek = declare_dependency()
  1679. elif get_option('fuse_lseek').enabled()
  1680. if fuse.found()
  1681. error('fuse-lseek requires libfuse >=3.8, found ' + fuse.version())
  1682. else
  1683. error('fuse-lseek requires libfuse, which was not found')
  1684. endif
  1685. endif
  1686. endif
  1687. have_libvduse = (targetos == 'linux')
  1688. if get_option('libvduse').enabled()
  1689. if targetos != 'linux'
  1690. error('libvduse requires linux')
  1691. endif
  1692. elif get_option('libvduse').disabled()
  1693. have_libvduse = false
  1694. endif
  1695. have_vduse_blk_export = (have_libvduse and targetos == 'linux')
  1696. if get_option('vduse_blk_export').enabled()
  1697. if targetos != 'linux'
  1698. error('vduse_blk_export requires linux')
  1699. elif not have_libvduse
  1700. error('vduse_blk_export requires libvduse support')
  1701. endif
  1702. elif get_option('vduse_blk_export').disabled()
  1703. have_vduse_blk_export = false
  1704. endif
  1705. # libbpf
  1706. libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config')
  1707. if libbpf.found() and not cc.links('''
  1708. #include <bpf/libbpf.h>
  1709. int main(void)
  1710. {
  1711. bpf_object__destroy_skeleton(NULL);
  1712. return 0;
  1713. }''', dependencies: libbpf)
  1714. libbpf = not_found
  1715. if get_option('bpf').enabled()
  1716. error('libbpf skeleton test failed')
  1717. else
  1718. warning('libbpf skeleton test failed, disabling')
  1719. endif
  1720. endif
  1721. # libdw
  1722. libdw = not_found
  1723. if not get_option('libdw').auto() or \
  1724. (not get_option('prefer_static') and (have_system or have_user))
  1725. libdw = dependency('libdw',
  1726. method: 'pkg-config',
  1727. required: get_option('libdw'))
  1728. endif
  1729. #################
  1730. # config-host.h #
  1731. #################
  1732. audio_drivers_selected = []
  1733. if have_system
  1734. audio_drivers_available = {
  1735. 'alsa': alsa.found(),
  1736. 'coreaudio': coreaudio.found(),
  1737. 'dsound': dsound.found(),
  1738. 'jack': jack.found(),
  1739. 'oss': oss.found(),
  1740. 'pa': pulse.found(),
  1741. 'pipewire': pipewire.found(),
  1742. 'sdl': sdl.found(),
  1743. 'sndio': sndio.found(),
  1744. }
  1745. foreach k, v: audio_drivers_available
  1746. config_host_data.set('CONFIG_AUDIO_' + k.to_upper(), v)
  1747. endforeach
  1748. # Default to native drivers first, OSS second, SDL third
  1749. audio_drivers_priority = \
  1750. [ 'pa', 'coreaudio', 'dsound', 'sndio', 'oss' ] + \
  1751. (targetos == 'linux' ? [] : [ 'sdl' ])
  1752. audio_drivers_default = []
  1753. foreach k: audio_drivers_priority
  1754. if audio_drivers_available[k]
  1755. audio_drivers_default += k
  1756. endif
  1757. endforeach
  1758. foreach k: get_option('audio_drv_list')
  1759. if k == 'default'
  1760. audio_drivers_selected += audio_drivers_default
  1761. elif not audio_drivers_available[k]
  1762. error('Audio driver "@0@" not available.'.format(k))
  1763. else
  1764. audio_drivers_selected += k
  1765. endif
  1766. endforeach
  1767. endif
  1768. config_host_data.set('CONFIG_AUDIO_DRIVERS',
  1769. '"' + '", "'.join(audio_drivers_selected) + '", ')
  1770. if get_option('cfi')
  1771. cfi_flags=[]
  1772. # Check for dependency on LTO
  1773. if not get_option('b_lto')
  1774. error('Selected Control-Flow Integrity but LTO is disabled')
  1775. endif
  1776. if enable_modules
  1777. error('Selected Control-Flow Integrity is not compatible with modules')
  1778. endif
  1779. # Check for cfi flags. CFI requires LTO so we can't use
  1780. # get_supported_arguments, but need a more complex "compiles" which allows
  1781. # custom arguments
  1782. if cc.compiles('int main () { return 0; }', name: '-fsanitize=cfi-icall',
  1783. args: ['-flto', '-fsanitize=cfi-icall'] )
  1784. cfi_flags += '-fsanitize=cfi-icall'
  1785. else
  1786. error('-fsanitize=cfi-icall is not supported by the compiler')
  1787. endif
  1788. if cc.compiles('int main () { return 0; }',
  1789. name: '-fsanitize-cfi-icall-generalize-pointers',
  1790. args: ['-flto', '-fsanitize=cfi-icall',
  1791. '-fsanitize-cfi-icall-generalize-pointers'] )
  1792. cfi_flags += '-fsanitize-cfi-icall-generalize-pointers'
  1793. else
  1794. error('-fsanitize-cfi-icall-generalize-pointers is not supported by the compiler')
  1795. endif
  1796. if get_option('cfi_debug')
  1797. if cc.compiles('int main () { return 0; }',
  1798. name: '-fno-sanitize-trap=cfi-icall',
  1799. args: ['-flto', '-fsanitize=cfi-icall',
  1800. '-fno-sanitize-trap=cfi-icall'] )
  1801. cfi_flags += '-fno-sanitize-trap=cfi-icall'
  1802. else
  1803. error('-fno-sanitize-trap=cfi-icall is not supported by the compiler')
  1804. endif
  1805. endif
  1806. add_global_arguments(cfi_flags, native: false, language: all_languages)
  1807. add_global_link_arguments(cfi_flags, native: false, language: all_languages)
  1808. endif
  1809. have_host_block_device = (targetos != 'darwin' or
  1810. cc.has_header('IOKit/storage/IOMedia.h'))
  1811. dbus_display = get_option('dbus_display') \
  1812. .require(gio.version().version_compare('>=2.64'),
  1813. error_message: '-display dbus requires glib>=2.64') \
  1814. .require(gdbus_codegen.found(),
  1815. error_message: gdbus_codegen_error.format('-display dbus')) \
  1816. .require(targetos != 'windows',
  1817. error_message: '-display dbus is not available on Windows') \
  1818. .allowed()
  1819. have_virtfs = get_option('virtfs') \
  1820. .require(targetos == 'linux' or targetos == 'darwin',
  1821. error_message: 'virtio-9p (virtfs) requires Linux or macOS') \
  1822. .require(targetos == 'linux' or cc.has_function('pthread_fchdir_np'),
  1823. error_message: 'virtio-9p (virtfs) on macOS requires the presence of pthread_fchdir_np') \
  1824. .require(targetos == 'darwin' or libattr.found(),
  1825. error_message: 'virtio-9p (virtfs) on Linux requires libattr-devel') \
  1826. .disable_auto_if(not have_tools and not have_system) \
  1827. .allowed()
  1828. have_virtfs_proxy_helper = get_option('virtfs_proxy_helper') \
  1829. .require(targetos != 'darwin', error_message: 'the virtfs proxy helper is incompatible with macOS') \
  1830. .require(have_virtfs, error_message: 'the virtfs proxy helper requires that virtfs is enabled') \
  1831. .disable_auto_if(not have_tools) \
  1832. .require(libcap_ng.found(), error_message: 'the virtfs proxy helper requires libcap-ng') \
  1833. .allowed()
  1834. if get_option('block_drv_ro_whitelist') == ''
  1835. config_host_data.set('CONFIG_BDRV_RO_WHITELIST', '')
  1836. else
  1837. config_host_data.set('CONFIG_BDRV_RO_WHITELIST',
  1838. '"' + get_option('block_drv_ro_whitelist').replace(',', '", "') + '", ')
  1839. endif
  1840. if get_option('block_drv_rw_whitelist') == ''
  1841. config_host_data.set('CONFIG_BDRV_RW_WHITELIST', '')
  1842. else
  1843. config_host_data.set('CONFIG_BDRV_RW_WHITELIST',
  1844. '"' + get_option('block_drv_rw_whitelist').replace(',', '", "') + '", ')
  1845. endif
  1846. foreach k : get_option('trace_backends')
  1847. config_host_data.set('CONFIG_TRACE_' + k.to_upper(), true)
  1848. endforeach
  1849. config_host_data.set_quoted('CONFIG_TRACE_FILE', get_option('trace_file'))
  1850. config_host_data.set_quoted('CONFIG_TLS_PRIORITY', get_option('tls_priority'))
  1851. if iasl.found()
  1852. config_host_data.set_quoted('CONFIG_IASL', iasl.full_path())
  1853. endif
  1854. config_host_data.set_quoted('CONFIG_BINDIR', get_option('prefix') / get_option('bindir'))
  1855. config_host_data.set_quoted('CONFIG_PREFIX', get_option('prefix'))
  1856. config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', get_option('prefix') / qemu_confdir)
  1857. config_host_data.set_quoted('CONFIG_QEMU_DATADIR', get_option('prefix') / qemu_datadir)
  1858. config_host_data.set_quoted('CONFIG_QEMU_DESKTOPDIR', get_option('prefix') / qemu_desktopdir)
  1859. qemu_firmwarepath = ''
  1860. foreach k : get_option('qemu_firmwarepath')
  1861. qemu_firmwarepath += '"' + get_option('prefix') / k + '", '
  1862. endforeach
  1863. config_host_data.set('CONFIG_QEMU_FIRMWAREPATH', qemu_firmwarepath)
  1864. config_host_data.set_quoted('CONFIG_QEMU_HELPERDIR', get_option('prefix') / get_option('libexecdir'))
  1865. config_host_data.set_quoted('CONFIG_QEMU_ICONDIR', get_option('prefix') / qemu_icondir)
  1866. config_host_data.set_quoted('CONFIG_QEMU_LOCALEDIR', get_option('prefix') / get_option('localedir'))
  1867. config_host_data.set_quoted('CONFIG_QEMU_LOCALSTATEDIR', get_option('prefix') / get_option('localstatedir'))
  1868. config_host_data.set_quoted('CONFIG_QEMU_MODDIR', get_option('prefix') / qemu_moddir)
  1869. config_host_data.set_quoted('CONFIG_SYSCONFDIR', get_option('prefix') / get_option('sysconfdir'))
  1870. if enable_modules
  1871. config_host_data.set('CONFIG_STAMP', run_command(
  1872. meson.current_source_dir() / 'scripts/qemu-stamp.py',
  1873. meson.project_version(), get_option('pkgversion'), '--',
  1874. meson.current_source_dir() / 'configure',
  1875. capture: true, check: true).stdout().strip())
  1876. endif
  1877. have_slirp_smbd = get_option('slirp_smbd') \
  1878. .require(targetos != 'windows', error_message: 'Host smbd not supported on this platform.') \
  1879. .allowed()
  1880. if have_slirp_smbd
  1881. smbd_path = get_option('smbd')
  1882. if smbd_path == ''
  1883. smbd_path = (targetos == 'solaris' ? '/usr/sfw/sbin/smbd' : '/usr/sbin/smbd')
  1884. endif
  1885. config_host_data.set_quoted('CONFIG_SMBD_COMMAND', smbd_path)
  1886. endif
  1887. config_host_data.set('HOST_' + host_arch.to_upper(), 1)
  1888. if get_option('module_upgrades') and not enable_modules
  1889. error('Cannot enable module-upgrades as modules are not enabled')
  1890. endif
  1891. config_host_data.set('CONFIG_MODULE_UPGRADES', get_option('module_upgrades'))
  1892. config_host_data.set('CONFIG_ATTR', libattr.found())
  1893. config_host_data.set('CONFIG_BDRV_WHITELIST_TOOLS', get_option('block_drv_whitelist_in_tools'))
  1894. config_host_data.set('CONFIG_BRLAPI', brlapi.found())
  1895. config_host_data.set('CONFIG_COCOA', cocoa.found())
  1896. config_host_data.set('CONFIG_FUZZ', get_option('fuzzing'))
  1897. config_host_data.set('CONFIG_GCOV', get_option('b_coverage'))
  1898. config_host_data.set('CONFIG_LIBUDEV', libudev.found())
  1899. config_host_data.set('CONFIG_LZO', lzo.found())
  1900. config_host_data.set('CONFIG_MPATH', mpathpersist.found())
  1901. config_host_data.set('CONFIG_BLKIO', blkio.found())
  1902. if blkio.found()
  1903. config_host_data.set('CONFIG_BLKIO_VHOST_VDPA_FD',
  1904. blkio.version().version_compare('>=1.3.0'))
  1905. endif
  1906. config_host_data.set('CONFIG_CURL', curl.found())
  1907. config_host_data.set('CONFIG_CURSES', curses.found())
  1908. config_host_data.set('CONFIG_GBM', gbm.found())
  1909. config_host_data.set('CONFIG_GIO', gio.found())
  1910. config_host_data.set('CONFIG_GLUSTERFS', glusterfs.found())
  1911. if glusterfs.found()
  1912. config_host_data.set('CONFIG_GLUSTERFS_XLATOR_OPT', glusterfs.version().version_compare('>=4'))
  1913. config_host_data.set('CONFIG_GLUSTERFS_DISCARD', glusterfs.version().version_compare('>=5'))
  1914. config_host_data.set('CONFIG_GLUSTERFS_FALLOCATE', glusterfs.version().version_compare('>=6'))
  1915. config_host_data.set('CONFIG_GLUSTERFS_ZEROFILL', glusterfs.version().version_compare('>=6'))
  1916. config_host_data.set('CONFIG_GLUSTERFS_FTRUNCATE_HAS_STAT', glusterfs_ftruncate_has_stat)
  1917. config_host_data.set('CONFIG_GLUSTERFS_IOCB_HAS_STAT', glusterfs_iocb_has_stat)
  1918. endif
  1919. config_host_data.set('CONFIG_GTK', gtk.found())
  1920. config_host_data.set('CONFIG_VTE', vte.found())
  1921. config_host_data.set('CONFIG_GTK_CLIPBOARD', have_gtk_clipboard)
  1922. config_host_data.set('CONFIG_HEXAGON_IDEF_PARSER', get_option('hexagon_idef_parser'))
  1923. config_host_data.set('CONFIG_LIBATTR', have_old_libattr)
  1924. config_host_data.set('CONFIG_LIBCAP_NG', libcap_ng.found())
  1925. config_host_data.set('CONFIG_EBPF', libbpf.found())
  1926. config_host_data.set('CONFIG_LIBDAXCTL', libdaxctl.found())
  1927. config_host_data.set('CONFIG_LIBISCSI', libiscsi.found())
  1928. config_host_data.set('CONFIG_LIBNFS', libnfs.found())
  1929. config_host_data.set('CONFIG_LIBSSH', libssh.found())
  1930. config_host_data.set('CONFIG_LINUX_AIO', libaio.found())
  1931. config_host_data.set('CONFIG_LINUX_IO_URING', linux_io_uring.found())
  1932. config_host_data.set('CONFIG_LIBPMEM', libpmem.found())
  1933. config_host_data.set('CONFIG_MODULES', enable_modules)
  1934. config_host_data.set('CONFIG_NUMA', numa.found())
  1935. if numa.found()
  1936. config_host_data.set('HAVE_NUMA_HAS_PREFERRED_MANY',
  1937. cc.has_function('numa_has_preferred_many',
  1938. dependencies: numa))
  1939. endif
  1940. config_host_data.set('CONFIG_OPENGL', opengl.found())
  1941. config_host_data.set('CONFIG_PROFILER', get_option('profiler'))
  1942. config_host_data.set('CONFIG_RBD', rbd.found())
  1943. config_host_data.set('CONFIG_RDMA', rdma.found())
  1944. config_host_data.set('CONFIG_SAFESTACK', get_option('safe_stack'))
  1945. config_host_data.set('CONFIG_SDL', sdl.found())
  1946. config_host_data.set('CONFIG_SDL_IMAGE', sdl_image.found())
  1947. config_host_data.set('CONFIG_SECCOMP', seccomp.found())
  1948. if seccomp.found()
  1949. config_host_data.set('CONFIG_SECCOMP_SYSRAWRC', seccomp_has_sysrawrc)
  1950. endif
  1951. config_host_data.set('CONFIG_SNAPPY', snappy.found())
  1952. config_host_data.set('CONFIG_TPM', have_tpm)
  1953. config_host_data.set('CONFIG_TSAN', get_option('tsan'))
  1954. config_host_data.set('CONFIG_USB_LIBUSB', libusb.found())
  1955. config_host_data.set('CONFIG_VDE', vde.found())
  1956. config_host_data.set('CONFIG_VHOST_NET', have_vhost_net)
  1957. config_host_data.set('CONFIG_VHOST_NET_USER', have_vhost_net_user)
  1958. config_host_data.set('CONFIG_VHOST_NET_VDPA', have_vhost_net_vdpa)
  1959. config_host_data.set('CONFIG_VHOST_KERNEL', have_vhost_kernel)
  1960. config_host_data.set('CONFIG_VHOST_USER', have_vhost_user)
  1961. config_host_data.set('CONFIG_VHOST_CRYPTO', have_vhost_user_crypto)
  1962. config_host_data.set('CONFIG_VHOST_VDPA', have_vhost_vdpa)
  1963. config_host_data.set('CONFIG_VMNET', vmnet.found())
  1964. config_host_data.set('CONFIG_VHOST_USER_BLK_SERVER', have_vhost_user_blk_server)
  1965. config_host_data.set('CONFIG_VDUSE_BLK_EXPORT', have_vduse_blk_export)
  1966. config_host_data.set('CONFIG_PNG', png.found())
  1967. config_host_data.set('CONFIG_VNC', vnc.found())
  1968. config_host_data.set('CONFIG_VNC_JPEG', jpeg.found())
  1969. config_host_data.set('CONFIG_VNC_SASL', sasl.found())
  1970. config_host_data.set('CONFIG_VIRTFS', have_virtfs)
  1971. config_host_data.set('CONFIG_VTE', vte.found())
  1972. config_host_data.set('CONFIG_XKBCOMMON', xkbcommon.found())
  1973. config_host_data.set('CONFIG_KEYUTILS', keyutils.found())
  1974. config_host_data.set('CONFIG_GETTID', has_gettid)
  1975. config_host_data.set('CONFIG_GNUTLS', gnutls.found())
  1976. config_host_data.set('CONFIG_GNUTLS_CRYPTO', gnutls_crypto.found())
  1977. config_host_data.set('CONFIG_TASN1', tasn1.found())
  1978. config_host_data.set('CONFIG_GCRYPT', gcrypt.found())
  1979. config_host_data.set('CONFIG_NETTLE', nettle.found())
  1980. config_host_data.set('CONFIG_HOGWEED', hogweed.found())
  1981. config_host_data.set('CONFIG_QEMU_PRIVATE_XTS', xts == 'private')
  1982. config_host_data.set('CONFIG_MALLOC_TRIM', has_malloc_trim)
  1983. config_host_data.set('CONFIG_STATX', has_statx)
  1984. config_host_data.set('CONFIG_STATX_MNT_ID', has_statx_mnt_id)
  1985. config_host_data.set('CONFIG_ZSTD', zstd.found())
  1986. config_host_data.set('CONFIG_FUSE', fuse.found())
  1987. config_host_data.set('CONFIG_FUSE_LSEEK', fuse_lseek.found())
  1988. config_host_data.set('CONFIG_SPICE_PROTOCOL', spice_protocol.found())
  1989. if spice_protocol.found()
  1990. config_host_data.set('CONFIG_SPICE_PROTOCOL_MAJOR', spice_protocol.version().split('.')[0])
  1991. config_host_data.set('CONFIG_SPICE_PROTOCOL_MINOR', spice_protocol.version().split('.')[1])
  1992. config_host_data.set('CONFIG_SPICE_PROTOCOL_MICRO', spice_protocol.version().split('.')[2])
  1993. endif
  1994. config_host_data.set('CONFIG_SPICE', spice.found())
  1995. config_host_data.set('CONFIG_X11', x11.found())
  1996. config_host_data.set('CONFIG_DBUS_DISPLAY', dbus_display)
  1997. config_host_data.set('CONFIG_CFI', get_option('cfi'))
  1998. config_host_data.set('CONFIG_SELINUX', selinux.found())
  1999. config_host_data.set('CONFIG_XEN_BACKEND', xen.found())
  2000. config_host_data.set('CONFIG_LIBDW', libdw.found())
  2001. if xen.found()
  2002. # protect from xen.version() having less than three components
  2003. xen_version = xen.version().split('.') + ['0', '0']
  2004. xen_ctrl_version = xen_version[0] + \
  2005. ('0' + xen_version[1]).substring(-2) + \
  2006. ('0' + xen_version[2]).substring(-2)
  2007. config_host_data.set('CONFIG_XEN_CTRL_INTERFACE_VERSION', xen_ctrl_version)
  2008. endif
  2009. config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version()))
  2010. config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('.')[0])
  2011. config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1])
  2012. config_host_data.set('QEMU_VERSION_MICRO', meson.project_version().split('.')[2])
  2013. config_host_data.set_quoted('CONFIG_HOST_DSOSUF', host_dsosuf)
  2014. config_host_data.set('HAVE_HOST_BLOCK_DEVICE', have_host_block_device)
  2015. have_coroutine_pool = get_option('coroutine_pool')
  2016. if get_option('debug_stack_usage') and have_coroutine_pool
  2017. message('Disabling coroutine pool to measure stack usage')
  2018. have_coroutine_pool = false
  2019. endif
  2020. config_host_data.set10('CONFIG_COROUTINE_POOL', have_coroutine_pool)
  2021. config_host_data.set('CONFIG_DEBUG_GRAPH_LOCK', get_option('debug_graph_lock'))
  2022. config_host_data.set('CONFIG_DEBUG_MUTEX', get_option('debug_mutex'))
  2023. config_host_data.set('CONFIG_DEBUG_STACK_USAGE', get_option('debug_stack_usage'))
  2024. config_host_data.set('CONFIG_GPROF', get_option('gprof'))
  2025. config_host_data.set('CONFIG_LIVE_BLOCK_MIGRATION', get_option('live_block_migration').allowed())
  2026. config_host_data.set('CONFIG_QOM_CAST_DEBUG', get_option('qom_cast_debug'))
  2027. config_host_data.set('CONFIG_REPLICATION', get_option('replication').allowed())
  2028. # has_header
  2029. config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h'))
  2030. config_host_data.set('CONFIG_LINUX_MAGIC_H', cc.has_header('linux/magic.h'))
  2031. config_host_data.set('CONFIG_VALGRIND_H', cc.has_header('valgrind/valgrind.h'))
  2032. config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h'))
  2033. config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h'))
  2034. config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h'))
  2035. config_host_data.set('HAVE_SYS_DISK_H', cc.has_header('sys/disk.h'))
  2036. config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h'))
  2037. config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h'))
  2038. if targetos == 'windows'
  2039. config_host_data.set('HAVE_AFUNIX_H', cc.has_header('afunix.h'))
  2040. endif
  2041. # has_function
  2042. config_host_data.set('CONFIG_CLOSE_RANGE', cc.has_function('close_range'))
  2043. config_host_data.set('CONFIG_ACCEPT4', cc.has_function('accept4'))
  2044. config_host_data.set('CONFIG_CLOCK_ADJTIME', cc.has_function('clock_adjtime'))
  2045. config_host_data.set('CONFIG_DUP3', cc.has_function('dup3'))
  2046. config_host_data.set('CONFIG_FALLOCATE', cc.has_function('fallocate'))
  2047. config_host_data.set('CONFIG_POSIX_FALLOCATE', cc.has_function('posix_fallocate'))
  2048. # Note that we need to specify prefix: here to avoid incorrectly
  2049. # thinking that Windows has posix_memalign()
  2050. config_host_data.set('CONFIG_POSIX_MEMALIGN', cc.has_function('posix_memalign', prefix: '#include <stdlib.h>'))
  2051. config_host_data.set('CONFIG_ALIGNED_MALLOC', cc.has_function('_aligned_malloc'))
  2052. config_host_data.set('CONFIG_VALLOC', cc.has_function('valloc'))
  2053. config_host_data.set('CONFIG_MEMALIGN', cc.has_function('memalign'))
  2054. config_host_data.set('CONFIG_PPOLL', cc.has_function('ppoll'))
  2055. config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#include <sys/uio.h>'))
  2056. config_host_data.set('CONFIG_PTHREAD_FCHDIR_NP', cc.has_function('pthread_fchdir_np'))
  2057. config_host_data.set('CONFIG_SENDFILE', cc.has_function('sendfile'))
  2058. config_host_data.set('CONFIG_SETNS', cc.has_function('setns') and cc.has_function('unshare'))
  2059. config_host_data.set('CONFIG_SYNCFS', cc.has_function('syncfs'))
  2060. config_host_data.set('CONFIG_SYNC_FILE_RANGE', cc.has_function('sync_file_range'))
  2061. config_host_data.set('CONFIG_TIMERFD', cc.has_function('timerfd_create'))
  2062. config_host_data.set('HAVE_COPY_FILE_RANGE', cc.has_function('copy_file_range'))
  2063. config_host_data.set('HAVE_GETIFADDRS', cc.has_function('getifaddrs'))
  2064. config_host_data.set('HAVE_GLIB_WITH_SLICE_ALLOCATOR', glib_has_gslice)
  2065. config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependencies: util))
  2066. config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul'))
  2067. config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include <stdlib.h>'))
  2068. if rbd.found()
  2069. config_host_data.set('HAVE_RBD_NAMESPACE_EXISTS',
  2070. cc.has_function('rbd_namespace_exists',
  2071. dependencies: rbd,
  2072. prefix: '#include <rbd/librbd.h>'))
  2073. endif
  2074. if rdma.found()
  2075. config_host_data.set('HAVE_IBV_ADVISE_MR',
  2076. cc.has_function('ibv_advise_mr',
  2077. dependencies: rdma,
  2078. prefix: '#include <infiniband/verbs.h>'))
  2079. endif
  2080. have_asan_fiber = false
  2081. if get_option('sanitizers') and \
  2082. not cc.has_function('__sanitizer_start_switch_fiber',
  2083. args: '-fsanitize=address',
  2084. prefix: '#include <sanitizer/asan_interface.h>')
  2085. warning('Missing ASAN due to missing fiber annotation interface')
  2086. warning('Without code annotation, the report may be inferior.')
  2087. else
  2088. have_asan_fiber = true
  2089. endif
  2090. config_host_data.set('CONFIG_ASAN_IFACE_FIBER', have_asan_fiber)
  2091. # has_header_symbol
  2092. config_host_data.set('CONFIG_BLKZONED',
  2093. cc.has_header_symbol('linux/blkzoned.h', 'BLKOPENZONE'))
  2094. config_host_data.set('CONFIG_EPOLL_CREATE1',
  2095. cc.has_header_symbol('sys/epoll.h', 'epoll_create1'))
  2096. config_host_data.set('CONFIG_FALLOCATE_PUNCH_HOLE',
  2097. cc.has_header_symbol('linux/falloc.h', 'FALLOC_FL_PUNCH_HOLE') and
  2098. cc.has_header_symbol('linux/falloc.h', 'FALLOC_FL_KEEP_SIZE'))
  2099. config_host_data.set('CONFIG_FALLOCATE_ZERO_RANGE',
  2100. cc.has_header_symbol('linux/falloc.h', 'FALLOC_FL_ZERO_RANGE'))
  2101. config_host_data.set('CONFIG_FIEMAP',
  2102. cc.has_header('linux/fiemap.h') and
  2103. cc.has_header_symbol('linux/fs.h', 'FS_IOC_FIEMAP'))
  2104. config_host_data.set('CONFIG_GETRANDOM',
  2105. cc.has_function('getrandom') and
  2106. cc.has_header_symbol('sys/random.h', 'GRND_NONBLOCK'))
  2107. config_host_data.set('CONFIG_INOTIFY',
  2108. cc.has_header_symbol('sys/inotify.h', 'inotify_init'))
  2109. config_host_data.set('CONFIG_INOTIFY1',
  2110. cc.has_header_symbol('sys/inotify.h', 'inotify_init1'))
  2111. config_host_data.set('CONFIG_PRCTL_PR_SET_TIMERSLACK',
  2112. cc.has_header_symbol('sys/prctl.h', 'PR_SET_TIMERSLACK'))
  2113. config_host_data.set('CONFIG_RTNETLINK',
  2114. cc.has_header_symbol('linux/rtnetlink.h', 'IFLA_PROTO_DOWN'))
  2115. config_host_data.set('CONFIG_SYSMACROS',
  2116. cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
  2117. config_host_data.set('HAVE_OPTRESET',
  2118. cc.has_header_symbol('getopt.h', 'optreset'))
  2119. config_host_data.set('HAVE_IPPROTO_MPTCP',
  2120. cc.has_header_symbol('netinet/in.h', 'IPPROTO_MPTCP'))
  2121. # has_member
  2122. config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID',
  2123. cc.has_member('struct sigevent', 'sigev_notify_thread_id',
  2124. prefix: '#include <signal.h>'))
  2125. config_host_data.set('HAVE_STRUCT_STAT_ST_ATIM',
  2126. cc.has_member('struct stat', 'st_atim',
  2127. prefix: '#include <sys/stat.h>'))
  2128. config_host_data.set('HAVE_BLK_ZONE_REP_CAPACITY',
  2129. cc.has_member('struct blk_zone', 'capacity',
  2130. prefix: '#include <linux/blkzoned.h>'))
  2131. # has_type
  2132. config_host_data.set('CONFIG_IOVEC',
  2133. cc.has_type('struct iovec',
  2134. prefix: '#include <sys/uio.h>'))
  2135. config_host_data.set('HAVE_UTMPX',
  2136. cc.has_type('struct utmpx',
  2137. prefix: '#include <utmpx.h>'))
  2138. config_host_data.set('CONFIG_EVENTFD', cc.links('''
  2139. #include <sys/eventfd.h>
  2140. int main(void) { return eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); }'''))
  2141. config_host_data.set('CONFIG_FDATASYNC', cc.links(gnu_source_prefix + '''
  2142. #include <unistd.h>
  2143. int main(void) {
  2144. #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
  2145. return fdatasync(0);
  2146. #else
  2147. #error Not supported
  2148. #endif
  2149. }'''))
  2150. has_madvise = cc.links(gnu_source_prefix + '''
  2151. #include <sys/types.h>
  2152. #include <sys/mman.h>
  2153. #include <stddef.h>
  2154. int main(void) { return madvise(NULL, 0, MADV_DONTNEED); }''')
  2155. missing_madvise_proto = false
  2156. if has_madvise
  2157. # Some platforms (illumos and Solaris before Solaris 11) provide madvise()
  2158. # but forget to prototype it. In this case, has_madvise will be true (the
  2159. # test program links despite a compile warning). To detect the
  2160. # missing-prototype case, we try again with a definitely-bogus prototype.
  2161. # This will only compile if the system headers don't provide the prototype;
  2162. # otherwise the conflicting prototypes will cause a compiler error.
  2163. missing_madvise_proto = cc.links(gnu_source_prefix + '''
  2164. #include <sys/types.h>
  2165. #include <sys/mman.h>
  2166. #include <stddef.h>
  2167. extern int madvise(int);
  2168. int main(void) { return madvise(0); }''')
  2169. endif
  2170. config_host_data.set('CONFIG_MADVISE', has_madvise)
  2171. config_host_data.set('HAVE_MADVISE_WITHOUT_PROTOTYPE', missing_madvise_proto)
  2172. config_host_data.set('CONFIG_MEMFD', cc.links(gnu_source_prefix + '''
  2173. #include <sys/mman.h>
  2174. int main(void) { return memfd_create("foo", MFD_ALLOW_SEALING); }'''))
  2175. config_host_data.set('CONFIG_OPEN_BY_HANDLE', cc.links(gnu_source_prefix + '''
  2176. #include <fcntl.h>
  2177. #if !defined(AT_EMPTY_PATH)
  2178. # error missing definition
  2179. #else
  2180. int main(void) { struct file_handle fh; return open_by_handle_at(0, &fh, 0); }
  2181. #endif'''))
  2182. config_host_data.set('CONFIG_POSIX_MADVISE', cc.links(gnu_source_prefix + '''
  2183. #include <sys/mman.h>
  2184. #include <stddef.h>
  2185. int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); }'''))
  2186. config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_W_TID', cc.links(gnu_source_prefix + '''
  2187. #include <pthread.h>
  2188. static void *f(void *p) { return NULL; }
  2189. int main(void)
  2190. {
  2191. pthread_t thread;
  2192. pthread_create(&thread, 0, f, 0);
  2193. pthread_setname_np(thread, "QEMU");
  2194. return 0;
  2195. }''', dependencies: threads))
  2196. config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_WO_TID', cc.links(gnu_source_prefix + '''
  2197. #include <pthread.h>
  2198. static void *f(void *p) { pthread_setname_np("QEMU"); return NULL; }
  2199. int main(void)
  2200. {
  2201. pthread_t thread;
  2202. pthread_create(&thread, 0, f, 0);
  2203. return 0;
  2204. }''', dependencies: threads))
  2205. config_host_data.set('CONFIG_PTHREAD_SET_NAME_NP', cc.links(gnu_source_prefix + '''
  2206. #include <pthread.h>
  2207. #include <pthread_np.h>
  2208. static void *f(void *p) { return NULL; }
  2209. int main(void)
  2210. {
  2211. pthread_t thread;
  2212. pthread_create(&thread, 0, f, 0);
  2213. pthread_set_name_np(thread, "QEMU");
  2214. return 0;
  2215. }''', dependencies: threads))
  2216. config_host_data.set('CONFIG_PTHREAD_CONDATTR_SETCLOCK', cc.links(gnu_source_prefix + '''
  2217. #include <pthread.h>
  2218. #include <time.h>
  2219. int main(void)
  2220. {
  2221. pthread_condattr_t attr
  2222. pthread_condattr_init(&attr);
  2223. pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
  2224. return 0;
  2225. }''', dependencies: threads))
  2226. config_host_data.set('CONFIG_PTHREAD_AFFINITY_NP', cc.links(gnu_source_prefix + '''
  2227. #include <pthread.h>
  2228. static void *f(void *p) { return NULL; }
  2229. int main(void)
  2230. {
  2231. int setsize = CPU_ALLOC_SIZE(64);
  2232. pthread_t thread;
  2233. cpu_set_t *cpuset;
  2234. pthread_create(&thread, 0, f, 0);
  2235. cpuset = CPU_ALLOC(64);
  2236. CPU_ZERO_S(setsize, cpuset);
  2237. pthread_setaffinity_np(thread, setsize, cpuset);
  2238. pthread_getaffinity_np(thread, setsize, cpuset);
  2239. CPU_FREE(cpuset);
  2240. return 0;
  2241. }''', dependencies: threads))
  2242. config_host_data.set('CONFIG_SIGNALFD', cc.links(gnu_source_prefix + '''
  2243. #include <sys/signalfd.h>
  2244. #include <stddef.h>
  2245. int main(void) { return signalfd(-1, NULL, SFD_CLOEXEC); }'''))
  2246. config_host_data.set('CONFIG_SPLICE', cc.links(gnu_source_prefix + '''
  2247. #include <unistd.h>
  2248. #include <fcntl.h>
  2249. #include <limits.h>
  2250. int main(void)
  2251. {
  2252. int len, fd = 0;
  2253. len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, SPLICE_F_NONBLOCK);
  2254. splice(STDIN_FILENO, NULL, fd, NULL, len, SPLICE_F_MOVE);
  2255. return 0;
  2256. }'''))
  2257. config_host_data.set('HAVE_MLOCKALL', cc.links(gnu_source_prefix + '''
  2258. #include <sys/mman.h>
  2259. int main(void) {
  2260. return mlockall(MCL_FUTURE);
  2261. }'''))
  2262. have_l2tpv3 = false
  2263. if get_option('l2tpv3').allowed() and have_system
  2264. have_l2tpv3 = cc.has_type('struct mmsghdr',
  2265. prefix: gnu_source_prefix + '''
  2266. #include <sys/socket.h>
  2267. #include <linux/ip.h>''')
  2268. endif
  2269. config_host_data.set('CONFIG_L2TPV3', have_l2tpv3)
  2270. have_netmap = false
  2271. if get_option('netmap').allowed() and have_system
  2272. have_netmap = cc.compiles('''
  2273. #include <inttypes.h>
  2274. #include <net/if.h>
  2275. #include <net/netmap.h>
  2276. #include <net/netmap_user.h>
  2277. #if (NETMAP_API < 11) || (NETMAP_API > 15)
  2278. #error
  2279. #endif
  2280. int main(void) { return 0; }''')
  2281. if not have_netmap and get_option('netmap').enabled()
  2282. error('Netmap headers not available')
  2283. endif
  2284. endif
  2285. config_host_data.set('CONFIG_NETMAP', have_netmap)
  2286. # Work around a system header bug with some kernel/XFS header
  2287. # versions where they both try to define 'struct fsxattr':
  2288. # xfs headers will not try to redefine structs from linux headers
  2289. # if this macro is set.
  2290. config_host_data.set('HAVE_FSXATTR', cc.links('''
  2291. #include <linux/fs.h>
  2292. struct fsxattr foo;
  2293. int main(void) {
  2294. return 0;
  2295. }'''))
  2296. # Some versions of Mac OS X incorrectly define SIZE_MAX
  2297. config_host_data.set('HAVE_BROKEN_SIZE_MAX', not cc.compiles('''
  2298. #include <stdint.h>
  2299. #include <stdio.h>
  2300. int main(void) {
  2301. return printf("%zu", SIZE_MAX);
  2302. }''', args: ['-Werror']))
  2303. # See if 64-bit atomic operations are supported.
  2304. # Note that without __atomic builtins, we can only
  2305. # assume atomic loads/stores max at pointer size.
  2306. config_host_data.set('CONFIG_ATOMIC64', cc.links('''
  2307. #include <stdint.h>
  2308. int main(void)
  2309. {
  2310. uint64_t x = 0, y = 0;
  2311. y = __atomic_load_n(&x, __ATOMIC_RELAXED);
  2312. __atomic_store_n(&x, y, __ATOMIC_RELAXED);
  2313. __atomic_compare_exchange_n(&x, &y, x, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
  2314. __atomic_exchange_n(&x, y, __ATOMIC_RELAXED);
  2315. __atomic_fetch_add(&x, y, __ATOMIC_RELAXED);
  2316. return 0;
  2317. }'''))
  2318. has_int128_type = cc.compiles('''
  2319. __int128_t a;
  2320. __uint128_t b;
  2321. int main(void) { b = a; }''')
  2322. config_host_data.set('CONFIG_INT128_TYPE', has_int128_type)
  2323. has_int128 = has_int128_type and cc.links('''
  2324. __int128_t a;
  2325. __uint128_t b;
  2326. int main (void) {
  2327. a = a + b;
  2328. b = a * b;
  2329. a = a * a;
  2330. return 0;
  2331. }''')
  2332. config_host_data.set('CONFIG_INT128', has_int128)
  2333. if has_int128_type
  2334. # "do we have 128-bit atomics which are handled inline and specifically not
  2335. # via libatomic". The reason we can't use libatomic is documented in the
  2336. # comment starting "GCC is a house divided" in include/qemu/atomic128.h.
  2337. # We only care about these operations on 16-byte aligned pointers, so
  2338. # force 16-byte alignment of the pointer, which may be greater than
  2339. # __alignof(unsigned __int128) for the host.
  2340. atomic_test_128 = '''
  2341. int main(int ac, char **av) {
  2342. __uint128_t *p = __builtin_assume_aligned(av[ac - 1], 16);
  2343. p[1] = __atomic_load_n(&p[0], __ATOMIC_RELAXED);
  2344. __atomic_store_n(&p[2], p[3], __ATOMIC_RELAXED);
  2345. __atomic_compare_exchange_n(&p[4], &p[5], p[6], 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
  2346. return 0;
  2347. }'''
  2348. has_atomic128 = cc.links(atomic_test_128)
  2349. config_host_data.set('CONFIG_ATOMIC128', has_atomic128)
  2350. if not has_atomic128
  2351. # Even with __builtin_assume_aligned, the above test may have failed
  2352. # without optimization enabled. Try again with optimizations locally
  2353. # enabled for the function. See
  2354. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107389
  2355. has_atomic128_opt = cc.links('__attribute__((optimize("O1")))' + atomic_test_128)
  2356. config_host_data.set('CONFIG_ATOMIC128_OPT', has_atomic128_opt)
  2357. if not has_atomic128_opt
  2358. config_host_data.set('CONFIG_CMPXCHG128', cc.links('''
  2359. int main(void)
  2360. {
  2361. __uint128_t x = 0, y = 0;
  2362. __sync_val_compare_and_swap_16(&x, y, x);
  2363. return 0;
  2364. }
  2365. '''))
  2366. endif
  2367. endif
  2368. endif
  2369. config_host_data.set('CONFIG_GETAUXVAL', cc.links(gnu_source_prefix + '''
  2370. #include <sys/auxv.h>
  2371. int main(void) {
  2372. return getauxval(AT_HWCAP) == 0;
  2373. }'''))
  2374. config_host_data.set('CONFIG_USBFS', have_linux_user and cc.compiles('''
  2375. #include <linux/usbdevice_fs.h>
  2376. #ifndef USBDEVFS_GET_CAPABILITIES
  2377. #error "USBDEVFS_GET_CAPABILITIES undefined"
  2378. #endif
  2379. #ifndef USBDEVFS_DISCONNECT_CLAIM
  2380. #error "USBDEVFS_DISCONNECT_CLAIM undefined"
  2381. #endif
  2382. int main(void) { return 0; }'''))
  2383. have_keyring = get_option('keyring') \
  2384. .require(targetos == 'linux', error_message: 'keyring is only available on Linux') \
  2385. .require(cc.compiles('''
  2386. #include <errno.h>
  2387. #include <asm/unistd.h>
  2388. #include <linux/keyctl.h>
  2389. #include <sys/syscall.h>
  2390. #include <unistd.h>
  2391. int main(void) {
  2392. return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
  2393. }'''), error_message: 'keyctl syscall not available on this system').allowed()
  2394. config_host_data.set('CONFIG_SECRET_KEYRING', have_keyring)
  2395. have_cpuid_h = cc.links('''
  2396. #include <cpuid.h>
  2397. int main(void) {
  2398. unsigned a, b, c, d;
  2399. unsigned max = __get_cpuid_max(0, 0);
  2400. if (max >= 1) {
  2401. __cpuid(1, a, b, c, d);
  2402. }
  2403. if (max >= 7) {
  2404. __cpuid_count(7, 0, a, b, c, d);
  2405. }
  2406. return 0;
  2407. }''')
  2408. config_host_data.set('CONFIG_CPUID_H', have_cpuid_h)
  2409. config_host_data.set('CONFIG_AVX2_OPT', get_option('avx2') \
  2410. .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX2') \
  2411. .require(cc.links('''
  2412. #include <cpuid.h>
  2413. #include <immintrin.h>
  2414. static int __attribute__((target("avx2"))) bar(void *a) {
  2415. __m256i x = *(__m256i *)a;
  2416. return _mm256_testz_si256(x, x);
  2417. }
  2418. int main(int argc, char *argv[]) { return bar(argv[argc - 1]); }
  2419. '''), error_message: 'AVX2 not available').allowed())
  2420. config_host_data.set('CONFIG_AVX512F_OPT', get_option('avx512f') \
  2421. .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX512F') \
  2422. .require(cc.links('''
  2423. #include <cpuid.h>
  2424. #include <immintrin.h>
  2425. static int __attribute__((target("avx512f"))) bar(void *a) {
  2426. __m512i x = *(__m512i *)a;
  2427. return _mm512_test_epi64_mask(x, x);
  2428. }
  2429. int main(int argc, char *argv[]) { return bar(argv[argc - 1]); }
  2430. '''), error_message: 'AVX512F not available').allowed())
  2431. config_host_data.set('CONFIG_AVX512BW_OPT', get_option('avx512bw') \
  2432. .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX512BW') \
  2433. .require(cc.links('''
  2434. #include <cpuid.h>
  2435. #include <immintrin.h>
  2436. static int __attribute__((target("avx512bw"))) bar(void *a) {
  2437. __m512i *x = a;
  2438. __m512i res= _mm512_abs_epi8(*x);
  2439. return res[1];
  2440. }
  2441. int main(int argc, char *argv[]) { return bar(argv[0]); }
  2442. '''), error_message: 'AVX512BW not available').allowed())
  2443. have_pvrdma = get_option('pvrdma') \
  2444. .require(rdma.found(), error_message: 'PVRDMA requires OpenFabrics libraries') \
  2445. .require(cc.compiles(gnu_source_prefix + '''
  2446. #include <sys/mman.h>
  2447. int main(void)
  2448. {
  2449. char buf = 0;
  2450. void *addr = &buf;
  2451. addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
  2452. return 0;
  2453. }'''), error_message: 'PVRDMA requires mremap').allowed()
  2454. if have_pvrdma
  2455. config_host_data.set('LEGACY_RDMA_REG_MR', not cc.links('''
  2456. #include <infiniband/verbs.h>
  2457. int main(void)
  2458. {
  2459. struct ibv_mr *mr;
  2460. struct ibv_pd *pd = NULL;
  2461. size_t length = 10;
  2462. uint64_t iova = 0;
  2463. int access = 0;
  2464. void *addr = NULL;
  2465. mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
  2466. ibv_dereg_mr(mr);
  2467. return 0;
  2468. }'''))
  2469. endif
  2470. if get_option('membarrier').disabled()
  2471. have_membarrier = false
  2472. elif targetos == 'windows'
  2473. have_membarrier = true
  2474. elif targetos == 'linux'
  2475. have_membarrier = cc.compiles('''
  2476. #include <linux/membarrier.h>
  2477. #include <sys/syscall.h>
  2478. #include <unistd.h>
  2479. #include <stdlib.h>
  2480. int main(void) {
  2481. syscall(__NR_membarrier, MEMBARRIER_CMD_QUERY, 0);
  2482. syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0);
  2483. exit(0);
  2484. }''')
  2485. endif
  2486. config_host_data.set('CONFIG_MEMBARRIER', get_option('membarrier') \
  2487. .require(have_membarrier, error_message: 'membarrier system call not available') \
  2488. .allowed())
  2489. have_afalg = get_option('crypto_afalg') \
  2490. .require(cc.compiles(gnu_source_prefix + '''
  2491. #include <errno.h>
  2492. #include <sys/types.h>
  2493. #include <sys/socket.h>
  2494. #include <linux/if_alg.h>
  2495. int main(void) {
  2496. int sock;
  2497. sock = socket(AF_ALG, SOCK_SEQPACKET, 0);
  2498. return sock;
  2499. }
  2500. '''), error_message: 'AF_ALG requested but could not be detected').allowed()
  2501. config_host_data.set('CONFIG_AF_ALG', have_afalg)
  2502. config_host_data.set('CONFIG_AF_VSOCK', cc.has_header_symbol(
  2503. 'linux/vm_sockets.h', 'AF_VSOCK',
  2504. prefix: '#include <sys/socket.h>',
  2505. ))
  2506. have_vss = false
  2507. have_vss_sdk = false # old xp/2003 SDK
  2508. if targetos == 'windows' and link_language == 'cpp'
  2509. have_vss = cxx.compiles('''
  2510. #define __MIDL_user_allocate_free_DEFINED__
  2511. #include <vss.h>
  2512. int main(void) { return VSS_CTX_BACKUP; }''')
  2513. have_vss_sdk = cxx.has_header('vscoordint.h')
  2514. endif
  2515. config_host_data.set('HAVE_VSS_SDK', have_vss_sdk)
  2516. foreach k, v: config_host
  2517. if k.startswith('CONFIG_')
  2518. config_host_data.set(k, v == 'y' ? 1 : v)
  2519. endif
  2520. endforeach
  2521. # Older versions of MinGW do not import _lock_file and _unlock_file properly.
  2522. # This was fixed for v6.0.0 with commit b48e3ac8969d.
  2523. if targetos == 'windows'
  2524. config_host_data.set('HAVE__LOCK_FILE', cc.links('''
  2525. #include <stdio.h>
  2526. int main(void) {
  2527. _lock_file(NULL);
  2528. _unlock_file(NULL);
  2529. return 0;
  2530. }''', name: '_lock_file and _unlock_file'))
  2531. endif
  2532. if targetos == 'windows'
  2533. mingw_has_setjmp_longjmp = cc.links('''
  2534. #include <setjmp.h>
  2535. int main(void) {
  2536. /*
  2537. * These functions are not available in setjmp header, but may be
  2538. * available at link time, from libmingwex.a.
  2539. */
  2540. extern int __mingw_setjmp(jmp_buf);
  2541. extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
  2542. jmp_buf env;
  2543. __mingw_setjmp(env);
  2544. __mingw_longjmp(env, 0);
  2545. }
  2546. ''', name: 'mingw setjmp and longjmp')
  2547. if cpu == 'aarch64' and not mingw_has_setjmp_longjmp
  2548. error('mingw must provide setjmp/longjmp for windows-arm64')
  2549. endif
  2550. endif
  2551. ########################
  2552. # Target configuration #
  2553. ########################
  2554. minikconf = find_program('scripts/minikconf.py')
  2555. config_all = {}
  2556. config_all_devices = {}
  2557. config_all_disas = {}
  2558. config_devices_mak_list = []
  2559. config_devices_h = {}
  2560. config_target_h = {}
  2561. config_target_mak = {}
  2562. disassemblers = {
  2563. 'alpha' : ['CONFIG_ALPHA_DIS'],
  2564. 'avr' : ['CONFIG_AVR_DIS'],
  2565. 'cris' : ['CONFIG_CRIS_DIS'],
  2566. 'hexagon' : ['CONFIG_HEXAGON_DIS'],
  2567. 'hppa' : ['CONFIG_HPPA_DIS'],
  2568. 'i386' : ['CONFIG_I386_DIS'],
  2569. 'x86_64' : ['CONFIG_I386_DIS'],
  2570. 'm68k' : ['CONFIG_M68K_DIS'],
  2571. 'microblaze' : ['CONFIG_MICROBLAZE_DIS'],
  2572. 'mips' : ['CONFIG_MIPS_DIS'],
  2573. 'nios2' : ['CONFIG_NIOS2_DIS'],
  2574. 'or1k' : ['CONFIG_OPENRISC_DIS'],
  2575. 'ppc' : ['CONFIG_PPC_DIS'],
  2576. 'riscv' : ['CONFIG_RISCV_DIS'],
  2577. 'rx' : ['CONFIG_RX_DIS'],
  2578. 's390' : ['CONFIG_S390_DIS'],
  2579. 'sh4' : ['CONFIG_SH4_DIS'],
  2580. 'sparc' : ['CONFIG_SPARC_DIS'],
  2581. 'xtensa' : ['CONFIG_XTENSA_DIS'],
  2582. 'loongarch' : ['CONFIG_LOONGARCH_DIS'],
  2583. }
  2584. have_ivshmem = config_host_data.get('CONFIG_EVENTFD')
  2585. host_kconfig = \
  2586. (get_option('fuzzing') ? ['CONFIG_FUZZ=y'] : []) + \
  2587. (have_tpm ? ['CONFIG_TPM=y'] : []) + \
  2588. (spice.found() ? ['CONFIG_SPICE=y'] : []) + \
  2589. (have_ivshmem ? ['CONFIG_IVSHMEM=y'] : []) + \
  2590. (opengl.found() ? ['CONFIG_OPENGL=y'] : []) + \
  2591. (x11.found() ? ['CONFIG_X11=y'] : []) + \
  2592. (have_vhost_user ? ['CONFIG_VHOST_USER=y'] : []) + \
  2593. (have_vhost_vdpa ? ['CONFIG_VHOST_VDPA=y'] : []) + \
  2594. (have_vhost_kernel ? ['CONFIG_VHOST_KERNEL=y'] : []) + \
  2595. (have_virtfs ? ['CONFIG_VIRTFS=y'] : []) + \
  2596. ('CONFIG_LINUX' in config_host ? ['CONFIG_LINUX=y'] : []) + \
  2597. (have_pvrdma ? ['CONFIG_PVRDMA=y'] : []) + \
  2598. (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) + \
  2599. (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=y'] : [])
  2600. ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ]
  2601. default_targets = 'CONFIG_DEFAULT_TARGETS' in config_host
  2602. actual_target_dirs = []
  2603. fdt_required = []
  2604. foreach target : target_dirs
  2605. config_target = { 'TARGET_NAME': target.split('-')[0] }
  2606. if target.endswith('linux-user')
  2607. if targetos != 'linux'
  2608. if default_targets
  2609. continue
  2610. endif
  2611. error('Target @0@ is only available on a Linux host'.format(target))
  2612. endif
  2613. config_target += { 'CONFIG_LINUX_USER': 'y' }
  2614. elif target.endswith('bsd-user')
  2615. if 'CONFIG_BSD' not in config_host
  2616. if default_targets
  2617. continue
  2618. endif
  2619. error('Target @0@ is only available on a BSD host'.format(target))
  2620. endif
  2621. config_target += { 'CONFIG_BSD_USER': 'y' }
  2622. elif target.endswith('softmmu')
  2623. config_target += { 'CONFIG_SOFTMMU': 'y' }
  2624. endif
  2625. if target.endswith('-user')
  2626. config_target += {
  2627. 'CONFIG_USER_ONLY': 'y',
  2628. 'CONFIG_QEMU_INTERP_PREFIX':
  2629. get_option('interp_prefix').replace('%M', config_target['TARGET_NAME'])
  2630. }
  2631. endif
  2632. accel_kconfig = []
  2633. foreach sym: accelerators
  2634. if sym == 'CONFIG_TCG' or target in accelerator_targets.get(sym, [])
  2635. config_target += { sym: 'y' }
  2636. config_all += { sym: 'y' }
  2637. if target in modular_tcg
  2638. config_target += { 'CONFIG_TCG_MODULAR': 'y' }
  2639. else
  2640. config_target += { 'CONFIG_TCG_BUILTIN': 'y' }
  2641. endif
  2642. accel_kconfig += [ sym + '=y' ]
  2643. endif
  2644. endforeach
  2645. if accel_kconfig.length() == 0
  2646. if default_targets
  2647. continue
  2648. endif
  2649. error('No accelerator available for target @0@'.format(target))
  2650. endif
  2651. actual_target_dirs += target
  2652. config_target += keyval.load('configs/targets' / target + '.mak')
  2653. config_target += { 'TARGET_' + config_target['TARGET_ARCH'].to_upper(): 'y' }
  2654. if 'TARGET_NEED_FDT' in config_target
  2655. fdt_required += target
  2656. endif
  2657. # Add default keys
  2658. if 'TARGET_BASE_ARCH' not in config_target
  2659. config_target += {'TARGET_BASE_ARCH': config_target['TARGET_ARCH']}
  2660. endif
  2661. if 'TARGET_ABI_DIR' not in config_target
  2662. config_target += {'TARGET_ABI_DIR': config_target['TARGET_ARCH']}
  2663. endif
  2664. if 'TARGET_BIG_ENDIAN' not in config_target
  2665. config_target += {'TARGET_BIG_ENDIAN': 'n'}
  2666. endif
  2667. foreach k, v: disassemblers
  2668. if host_arch.startswith(k) or config_target['TARGET_BASE_ARCH'].startswith(k)
  2669. foreach sym: v
  2670. config_target += { sym: 'y' }
  2671. config_all_disas += { sym: 'y' }
  2672. endforeach
  2673. endif
  2674. endforeach
  2675. config_target_data = configuration_data()
  2676. foreach k, v: config_target
  2677. if not k.startswith('TARGET_') and not k.startswith('CONFIG_')
  2678. # do nothing
  2679. elif ignored.contains(k)
  2680. # do nothing
  2681. elif k == 'TARGET_BASE_ARCH'
  2682. # Note that TARGET_BASE_ARCH ends up in config-target.h but it is
  2683. # not used to select files from sourcesets.
  2684. config_target_data.set('TARGET_' + v.to_upper(), 1)
  2685. elif k == 'TARGET_NAME' or k == 'CONFIG_QEMU_INTERP_PREFIX'
  2686. config_target_data.set_quoted(k, v)
  2687. elif v == 'y'
  2688. config_target_data.set(k, 1)
  2689. elif v == 'n'
  2690. config_target_data.set(k, 0)
  2691. else
  2692. config_target_data.set(k, v)
  2693. endif
  2694. endforeach
  2695. config_target_data.set('QEMU_ARCH',
  2696. 'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
  2697. config_target_h += {target: configure_file(output: target + '-config-target.h',
  2698. configuration: config_target_data)}
  2699. if target.endswith('-softmmu')
  2700. config_input = meson.get_external_property(target, 'default')
  2701. config_devices_mak = target + '-config-devices.mak'
  2702. config_devices_mak = configure_file(
  2703. input: ['configs/devices' / target / config_input + '.mak', 'Kconfig'],
  2704. output: config_devices_mak,
  2705. depfile: config_devices_mak + '.d',
  2706. capture: true,
  2707. command: [minikconf,
  2708. get_option('default_devices') ? '--defconfig' : '--allnoconfig',
  2709. config_devices_mak, '@DEPFILE@', '@INPUT@',
  2710. host_kconfig, accel_kconfig,
  2711. 'CONFIG_' + config_target['TARGET_ARCH'].to_upper() + '=y'])
  2712. config_devices_data = configuration_data()
  2713. config_devices = keyval.load(config_devices_mak)
  2714. foreach k, v: config_devices
  2715. config_devices_data.set(k, 1)
  2716. endforeach
  2717. config_devices_mak_list += config_devices_mak
  2718. config_devices_h += {target: configure_file(output: target + '-config-devices.h',
  2719. configuration: config_devices_data)}
  2720. config_target += config_devices
  2721. config_all_devices += config_devices
  2722. endif
  2723. config_target_mak += {target: config_target}
  2724. endforeach
  2725. target_dirs = actual_target_dirs
  2726. # This configuration is used to build files that are shared by
  2727. # multiple binaries, and then extracted out of the "common"
  2728. # static_library target.
  2729. #
  2730. # We do not use all_sources()/all_dependencies(), because it would
  2731. # build literally all source files, including devices only used by
  2732. # targets that are not built for this compilation. The CONFIG_ALL
  2733. # pseudo symbol replaces it.
  2734. config_all += config_all_devices
  2735. config_all += config_host
  2736. config_all += config_all_disas
  2737. config_all += {
  2738. 'CONFIG_XEN': xen.found(),
  2739. 'CONFIG_SOFTMMU': have_system,
  2740. 'CONFIG_USER_ONLY': have_user,
  2741. 'CONFIG_ALL': true,
  2742. }
  2743. target_configs_h = []
  2744. foreach target: target_dirs
  2745. target_configs_h += config_target_h[target]
  2746. target_configs_h += config_devices_h.get(target, [])
  2747. endforeach
  2748. genh += custom_target('config-poison.h',
  2749. input: [target_configs_h],
  2750. output: 'config-poison.h',
  2751. capture: true,
  2752. command: [find_program('scripts/make-config-poison.sh'),
  2753. target_configs_h])
  2754. ##############
  2755. # Submodules #
  2756. ##############
  2757. capstone = not_found
  2758. if not get_option('capstone').auto() or have_system or have_user
  2759. capstone = dependency('capstone', version: '>=3.0.5',
  2760. method: 'pkg-config',
  2761. required: get_option('capstone'))
  2762. # Some versions of capstone have broken pkg-config file
  2763. # that reports a wrong -I path, causing the #include to
  2764. # fail later. If the system has such a broken version
  2765. # do not use it.
  2766. if capstone.found() and not cc.compiles('#include <capstone.h>',
  2767. dependencies: [capstone])
  2768. capstone = not_found
  2769. if get_option('capstone').enabled()
  2770. error('capstone requested, but it does not appear to work')
  2771. endif
  2772. endif
  2773. endif
  2774. libvfio_user_dep = not_found
  2775. if have_system and vfio_user_server_allowed
  2776. libvfio_user_proj = subproject('libvfio-user', required: true)
  2777. libvfio_user_dep = libvfio_user_proj.get_variable('libvfio_user_dep')
  2778. endif
  2779. fdt = not_found
  2780. fdt_opt = get_option('fdt')
  2781. if fdt_required.length() > 0 or fdt_opt == 'enabled'
  2782. if fdt_opt == 'disabled'
  2783. error('fdt disabled but required by targets ' + ', '.join(fdt_required))
  2784. endif
  2785. if fdt_opt in ['enabled', 'auto', 'system']
  2786. fdt = cc.find_library('fdt', required: fdt_opt == 'system')
  2787. if fdt.found() and cc.links('''
  2788. #include <libfdt.h>
  2789. #include <libfdt_env.h>
  2790. int main(void) { fdt_find_max_phandle(NULL, NULL); return 0; }''',
  2791. dependencies: fdt)
  2792. fdt_opt = 'system'
  2793. elif fdt_opt == 'system'
  2794. error('system libfdt requested, but it is too old (1.5.1 or newer required)')
  2795. else
  2796. fdt_opt = 'internal'
  2797. fdt = not_found
  2798. endif
  2799. endif
  2800. if not fdt.found()
  2801. assert(fdt_opt == 'internal')
  2802. libfdt_proj = subproject('dtc', required: true,
  2803. default_options: ['tools=false', 'yaml=disabled',
  2804. 'python=disabled', 'default_library=static'])
  2805. fdt = libfdt_proj.get_variable('libfdt_dep')
  2806. endif
  2807. else
  2808. fdt_opt = 'disabled'
  2809. endif
  2810. config_host_data.set('CONFIG_CAPSTONE', capstone.found())
  2811. config_host_data.set('CONFIG_FDT', fdt.found())
  2812. config_host_data.set('CONFIG_SLIRP', slirp.found())
  2813. #####################
  2814. # Generated sources #
  2815. #####################
  2816. genh += configure_file(output: 'config-host.h', configuration: config_host_data)
  2817. hxtool = find_program('scripts/hxtool')
  2818. shaderinclude = find_program('scripts/shaderinclude.py')
  2819. qapi_gen = find_program('scripts/qapi-gen.py')
  2820. qapi_gen_depends = [ meson.current_source_dir() / 'scripts/qapi/__init__.py',
  2821. meson.current_source_dir() / 'scripts/qapi/commands.py',
  2822. meson.current_source_dir() / 'scripts/qapi/common.py',
  2823. meson.current_source_dir() / 'scripts/qapi/error.py',
  2824. meson.current_source_dir() / 'scripts/qapi/events.py',
  2825. meson.current_source_dir() / 'scripts/qapi/expr.py',
  2826. meson.current_source_dir() / 'scripts/qapi/gen.py',
  2827. meson.current_source_dir() / 'scripts/qapi/introspect.py',
  2828. meson.current_source_dir() / 'scripts/qapi/main.py',
  2829. meson.current_source_dir() / 'scripts/qapi/parser.py',
  2830. meson.current_source_dir() / 'scripts/qapi/schema.py',
  2831. meson.current_source_dir() / 'scripts/qapi/source.py',
  2832. meson.current_source_dir() / 'scripts/qapi/types.py',
  2833. meson.current_source_dir() / 'scripts/qapi/visit.py',
  2834. meson.current_source_dir() / 'scripts/qapi-gen.py'
  2835. ]
  2836. tracetool = [
  2837. python, files('scripts/tracetool.py'),
  2838. '--backend=' + ','.join(get_option('trace_backends'))
  2839. ]
  2840. tracetool_depends = files(
  2841. 'scripts/tracetool/backend/log.py',
  2842. 'scripts/tracetool/backend/__init__.py',
  2843. 'scripts/tracetool/backend/dtrace.py',
  2844. 'scripts/tracetool/backend/ftrace.py',
  2845. 'scripts/tracetool/backend/simple.py',
  2846. 'scripts/tracetool/backend/syslog.py',
  2847. 'scripts/tracetool/backend/ust.py',
  2848. 'scripts/tracetool/format/ust_events_c.py',
  2849. 'scripts/tracetool/format/ust_events_h.py',
  2850. 'scripts/tracetool/format/__init__.py',
  2851. 'scripts/tracetool/format/d.py',
  2852. 'scripts/tracetool/format/simpletrace_stap.py',
  2853. 'scripts/tracetool/format/c.py',
  2854. 'scripts/tracetool/format/h.py',
  2855. 'scripts/tracetool/format/log_stap.py',
  2856. 'scripts/tracetool/format/stap.py',
  2857. 'scripts/tracetool/__init__.py',
  2858. 'scripts/tracetool/vcpu.py'
  2859. )
  2860. qemu_version_cmd = [find_program('scripts/qemu-version.sh'),
  2861. meson.current_source_dir(),
  2862. get_option('pkgversion'), meson.project_version()]
  2863. qemu_version = custom_target('qemu-version.h',
  2864. output: 'qemu-version.h',
  2865. command: qemu_version_cmd,
  2866. capture: true,
  2867. build_by_default: true,
  2868. build_always_stale: true)
  2869. genh += qemu_version
  2870. hxdep = []
  2871. hx_headers = [
  2872. ['qemu-options.hx', 'qemu-options.def'],
  2873. ['qemu-img-cmds.hx', 'qemu-img-cmds.h'],
  2874. ]
  2875. if have_system
  2876. hx_headers += [
  2877. ['hmp-commands.hx', 'hmp-commands.h'],
  2878. ['hmp-commands-info.hx', 'hmp-commands-info.h'],
  2879. ]
  2880. endif
  2881. foreach d : hx_headers
  2882. hxdep += custom_target(d[1],
  2883. input: files(d[0]),
  2884. output: d[1],
  2885. capture: true,
  2886. build_by_default: true, # to be removed when added to a target
  2887. command: [hxtool, '-h', '@INPUT0@'])
  2888. endforeach
  2889. genh += hxdep
  2890. ###################
  2891. # Collect sources #
  2892. ###################
  2893. authz_ss = ss.source_set()
  2894. blockdev_ss = ss.source_set()
  2895. block_ss = ss.source_set()
  2896. chardev_ss = ss.source_set()
  2897. common_ss = ss.source_set()
  2898. crypto_ss = ss.source_set()
  2899. hwcore_ss = ss.source_set()
  2900. io_ss = ss.source_set()
  2901. qmp_ss = ss.source_set()
  2902. qom_ss = ss.source_set()
  2903. softmmu_ss = ss.source_set()
  2904. specific_fuzz_ss = ss.source_set()
  2905. specific_ss = ss.source_set()
  2906. stub_ss = ss.source_set()
  2907. trace_ss = ss.source_set()
  2908. user_ss = ss.source_set()
  2909. util_ss = ss.source_set()
  2910. # accel modules
  2911. qtest_module_ss = ss.source_set()
  2912. tcg_module_ss = ss.source_set()
  2913. modules = {}
  2914. target_modules = {}
  2915. hw_arch = {}
  2916. target_arch = {}
  2917. target_softmmu_arch = {}
  2918. target_user_arch = {}
  2919. ###############
  2920. # Trace files #
  2921. ###############
  2922. # TODO: add each directory to the subdirs from its own meson.build, once
  2923. # we have those
  2924. trace_events_subdirs = [
  2925. 'crypto',
  2926. 'qapi',
  2927. 'qom',
  2928. 'monitor',
  2929. 'util',
  2930. 'gdbstub',
  2931. ]
  2932. if have_linux_user
  2933. trace_events_subdirs += [ 'linux-user' ]
  2934. endif
  2935. if have_bsd_user
  2936. trace_events_subdirs += [ 'bsd-user' ]
  2937. endif
  2938. if have_block
  2939. trace_events_subdirs += [
  2940. 'authz',
  2941. 'block',
  2942. 'io',
  2943. 'nbd',
  2944. 'scsi',
  2945. ]
  2946. endif
  2947. if have_system
  2948. trace_events_subdirs += [
  2949. 'accel/kvm',
  2950. 'audio',
  2951. 'backends',
  2952. 'backends/tpm',
  2953. 'chardev',
  2954. 'ebpf',
  2955. 'hw/9pfs',
  2956. 'hw/acpi',
  2957. 'hw/adc',
  2958. 'hw/alpha',
  2959. 'hw/arm',
  2960. 'hw/audio',
  2961. 'hw/block',
  2962. 'hw/block/dataplane',
  2963. 'hw/char',
  2964. 'hw/display',
  2965. 'hw/dma',
  2966. 'hw/hyperv',
  2967. 'hw/i2c',
  2968. 'hw/i386',
  2969. 'hw/i386/xen',
  2970. 'hw/i386/kvm',
  2971. 'hw/ide',
  2972. 'hw/input',
  2973. 'hw/intc',
  2974. 'hw/isa',
  2975. 'hw/mem',
  2976. 'hw/mips',
  2977. 'hw/misc',
  2978. 'hw/misc/macio',
  2979. 'hw/net',
  2980. 'hw/net/can',
  2981. 'hw/nubus',
  2982. 'hw/nvme',
  2983. 'hw/nvram',
  2984. 'hw/pci',
  2985. 'hw/pci-host',
  2986. 'hw/ppc',
  2987. 'hw/rdma',
  2988. 'hw/rdma/vmw',
  2989. 'hw/rtc',
  2990. 'hw/s390x',
  2991. 'hw/scsi',
  2992. 'hw/sd',
  2993. 'hw/sh4',
  2994. 'hw/sparc',
  2995. 'hw/sparc64',
  2996. 'hw/ssi',
  2997. 'hw/timer',
  2998. 'hw/tpm',
  2999. 'hw/usb',
  3000. 'hw/vfio',
  3001. 'hw/virtio',
  3002. 'hw/watchdog',
  3003. 'hw/xen',
  3004. 'hw/gpio',
  3005. 'migration',
  3006. 'net',
  3007. 'softmmu',
  3008. 'ui',
  3009. 'hw/remote',
  3010. ]
  3011. endif
  3012. if have_system or have_user
  3013. trace_events_subdirs += [
  3014. 'accel/tcg',
  3015. 'hw/core',
  3016. 'target/arm',
  3017. 'target/arm/hvf',
  3018. 'target/hppa',
  3019. 'target/i386',
  3020. 'target/i386/kvm',
  3021. 'target/mips/tcg',
  3022. 'target/nios2',
  3023. 'target/ppc',
  3024. 'target/riscv',
  3025. 'target/s390x',
  3026. 'target/s390x/kvm',
  3027. 'target/sparc',
  3028. ]
  3029. endif
  3030. vhost_user = not_found
  3031. if targetos == 'linux' and have_vhost_user
  3032. libvhost_user = subproject('libvhost-user')
  3033. vhost_user = libvhost_user.get_variable('vhost_user_dep')
  3034. endif
  3035. libvduse = not_found
  3036. if have_libvduse
  3037. libvduse_proj = subproject('libvduse')
  3038. libvduse = libvduse_proj.get_variable('libvduse_dep')
  3039. endif
  3040. # NOTE: the trace/ subdirectory needs the qapi_trace_events variable
  3041. # that is filled in by qapi/.
  3042. subdir('qapi')
  3043. subdir('qobject')
  3044. subdir('stubs')
  3045. subdir('trace')
  3046. subdir('util')
  3047. subdir('qom')
  3048. subdir('authz')
  3049. subdir('crypto')
  3050. subdir('ui')
  3051. subdir('hw')
  3052. subdir('gdbstub')
  3053. if enable_modules
  3054. libmodulecommon = static_library('module-common', files('module-common.c') + genh, pic: true, c_args: '-DBUILD_DSO')
  3055. modulecommon = declare_dependency(link_whole: libmodulecommon, compile_args: '-DBUILD_DSO')
  3056. endif
  3057. qom_ss = qom_ss.apply(config_host, strict: false)
  3058. libqom = static_library('qom', qom_ss.sources() + genh,
  3059. dependencies: [qom_ss.dependencies()],
  3060. name_suffix: 'fa')
  3061. qom = declare_dependency(link_whole: libqom)
  3062. event_loop_base = files('event-loop-base.c')
  3063. event_loop_base = static_library('event-loop-base', sources: event_loop_base + genh,
  3064. build_by_default: true)
  3065. event_loop_base = declare_dependency(link_whole: event_loop_base,
  3066. dependencies: [qom])
  3067. stub_ss = stub_ss.apply(config_all, strict: false)
  3068. util_ss.add_all(trace_ss)
  3069. util_ss = util_ss.apply(config_all, strict: false)
  3070. libqemuutil = static_library('qemuutil',
  3071. sources: util_ss.sources() + stub_ss.sources() + genh,
  3072. dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman])
  3073. qemuutil = declare_dependency(link_with: libqemuutil,
  3074. sources: genh + version_res,
  3075. dependencies: [event_loop_base])
  3076. if have_system or have_user
  3077. decodetree = generator(find_program('scripts/decodetree.py'),
  3078. output: 'decode-@BASENAME@.c.inc',
  3079. arguments: ['@INPUT@', '@EXTRA_ARGS@', '-o', '@OUTPUT@'])
  3080. subdir('libdecnumber')
  3081. subdir('target')
  3082. endif
  3083. subdir('audio')
  3084. subdir('io')
  3085. subdir('chardev')
  3086. subdir('fsdev')
  3087. subdir('dump')
  3088. if have_block
  3089. block_ss.add(files(
  3090. 'block.c',
  3091. 'blockjob.c',
  3092. 'job.c',
  3093. 'qemu-io-cmds.c',
  3094. ))
  3095. if config_host_data.get('CONFIG_REPLICATION')
  3096. block_ss.add(files('replication.c'))
  3097. endif
  3098. subdir('nbd')
  3099. subdir('scsi')
  3100. subdir('block')
  3101. blockdev_ss.add(files(
  3102. 'blockdev.c',
  3103. 'blockdev-nbd.c',
  3104. 'iothread.c',
  3105. 'job-qmp.c',
  3106. ), gnutls)
  3107. # os-posix.c contains POSIX-specific functions used by qemu-storage-daemon,
  3108. # os-win32.c does not
  3109. blockdev_ss.add(when: 'CONFIG_POSIX', if_true: files('os-posix.c'))
  3110. softmmu_ss.add(when: 'CONFIG_WIN32', if_true: [files('os-win32.c')])
  3111. endif
  3112. common_ss.add(files('cpus-common.c'))
  3113. specific_ss.add(files('cpu.c'))
  3114. subdir('softmmu')
  3115. # Work around a gcc bug/misfeature wherein constant propagation looks
  3116. # through an alias:
  3117. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99696
  3118. # to guess that a const variable is always zero. Without lto, this is
  3119. # impossible, as the alias is restricted to page-vary-common.c. Indeed,
  3120. # without lto, not even the alias is required -- we simply use different
  3121. # declarations in different compilation units.
  3122. pagevary = files('page-vary-common.c')
  3123. if get_option('b_lto')
  3124. pagevary_flags = ['-fno-lto']
  3125. if get_option('cfi')
  3126. pagevary_flags += '-fno-sanitize=cfi-icall'
  3127. endif
  3128. pagevary = static_library('page-vary-common', sources: pagevary + genh,
  3129. c_args: pagevary_flags)
  3130. pagevary = declare_dependency(link_with: pagevary)
  3131. endif
  3132. common_ss.add(pagevary)
  3133. specific_ss.add(files('page-vary.c'))
  3134. subdir('backends')
  3135. subdir('disas')
  3136. subdir('migration')
  3137. subdir('monitor')
  3138. subdir('net')
  3139. subdir('replay')
  3140. subdir('semihosting')
  3141. subdir('stats')
  3142. subdir('tcg')
  3143. subdir('fpu')
  3144. subdir('accel')
  3145. subdir('plugins')
  3146. subdir('ebpf')
  3147. common_user_inc = []
  3148. subdir('common-user')
  3149. subdir('bsd-user')
  3150. subdir('linux-user')
  3151. # needed for fuzzing binaries
  3152. subdir('tests/qtest/libqos')
  3153. subdir('tests/qtest/fuzz')
  3154. # accel modules
  3155. tcg_real_module_ss = ss.source_set()
  3156. tcg_real_module_ss.add_all(when: 'CONFIG_TCG_MODULAR', if_true: tcg_module_ss)
  3157. specific_ss.add_all(when: 'CONFIG_TCG_BUILTIN', if_true: tcg_module_ss)
  3158. target_modules += { 'accel' : { 'qtest': qtest_module_ss,
  3159. 'tcg': tcg_real_module_ss }}
  3160. ########################
  3161. # Library dependencies #
  3162. ########################
  3163. modinfo_collect = find_program('scripts/modinfo-collect.py')
  3164. modinfo_generate = find_program('scripts/modinfo-generate.py')
  3165. modinfo_files = []
  3166. block_mods = []
  3167. softmmu_mods = []
  3168. foreach d, list : modules
  3169. if not (d == 'block' ? have_block : have_system)
  3170. continue
  3171. endif
  3172. foreach m, module_ss : list
  3173. if enable_modules
  3174. module_ss = module_ss.apply(config_all, strict: false)
  3175. sl = static_library(d + '-' + m, [genh, module_ss.sources()],
  3176. dependencies: [modulecommon, module_ss.dependencies()], pic: true)
  3177. if d == 'block'
  3178. block_mods += sl
  3179. else
  3180. softmmu_mods += sl
  3181. endif
  3182. if module_ss.sources() != []
  3183. # FIXME: Should use sl.extract_all_objects(recursive: true) as
  3184. # input. Sources can be used multiple times but objects are
  3185. # unique when it comes to lookup in compile_commands.json.
  3186. # Depnds on a mesion version with
  3187. # https://github.com/mesonbuild/meson/pull/8900
  3188. modinfo_files += custom_target(d + '-' + m + '.modinfo',
  3189. output: d + '-' + m + '.modinfo',
  3190. input: module_ss.sources() + genh,
  3191. capture: true,
  3192. command: [modinfo_collect, module_ss.sources()])
  3193. endif
  3194. else
  3195. if d == 'block'
  3196. block_ss.add_all(module_ss)
  3197. else
  3198. softmmu_ss.add_all(module_ss)
  3199. endif
  3200. endif
  3201. endforeach
  3202. endforeach
  3203. foreach d, list : target_modules
  3204. foreach m, module_ss : list
  3205. if enable_modules
  3206. foreach target : target_dirs
  3207. if target.endswith('-softmmu')
  3208. config_target = config_target_mak[target]
  3209. config_target += config_host
  3210. target_inc = [include_directories('target' / config_target['TARGET_BASE_ARCH'])]
  3211. c_args = ['-DNEED_CPU_H',
  3212. '-DCONFIG_TARGET="@0@-config-target.h"'.format(target),
  3213. '-DCONFIG_DEVICES="@0@-config-devices.h"'.format(target)]
  3214. target_module_ss = module_ss.apply(config_target, strict: false)
  3215. if target_module_ss.sources() != []
  3216. module_name = d + '-' + m + '-' + config_target['TARGET_NAME']
  3217. sl = static_library(module_name,
  3218. [genh, target_module_ss.sources()],
  3219. dependencies: [modulecommon, target_module_ss.dependencies()],
  3220. include_directories: target_inc,
  3221. c_args: c_args,
  3222. pic: true)
  3223. softmmu_mods += sl
  3224. # FIXME: Should use sl.extract_all_objects(recursive: true) too.
  3225. modinfo_files += custom_target(module_name + '.modinfo',
  3226. output: module_name + '.modinfo',
  3227. input: target_module_ss.sources() + genh,
  3228. capture: true,
  3229. command: [modinfo_collect, '--target', target, target_module_ss.sources()])
  3230. endif
  3231. endif
  3232. endforeach
  3233. else
  3234. specific_ss.add_all(module_ss)
  3235. endif
  3236. endforeach
  3237. endforeach
  3238. if enable_modules
  3239. foreach target : target_dirs
  3240. if target.endswith('-softmmu')
  3241. config_target = config_target_mak[target]
  3242. config_devices_mak = target + '-config-devices.mak'
  3243. modinfo_src = custom_target('modinfo-' + target + '.c',
  3244. output: 'modinfo-' + target + '.c',
  3245. input: modinfo_files,
  3246. command: [modinfo_generate, '--devices', config_devices_mak, '@INPUT@'],
  3247. capture: true)
  3248. modinfo_lib = static_library('modinfo-' + target + '.c', modinfo_src)
  3249. modinfo_dep = declare_dependency(link_with: modinfo_lib)
  3250. arch = config_target['TARGET_NAME'] == 'sparc64' ? 'sparc64' : config_target['TARGET_BASE_ARCH']
  3251. hw_arch[arch].add(modinfo_dep)
  3252. endif
  3253. endforeach
  3254. endif
  3255. nm = find_program('nm')
  3256. undefsym = find_program('scripts/undefsym.py')
  3257. block_syms = custom_target('block.syms', output: 'block.syms',
  3258. input: [libqemuutil, block_mods],
  3259. capture: true,
  3260. command: [undefsym, nm, '@INPUT@'])
  3261. qemu_syms = custom_target('qemu.syms', output: 'qemu.syms',
  3262. input: [libqemuutil, softmmu_mods],
  3263. capture: true,
  3264. command: [undefsym, nm, '@INPUT@'])
  3265. authz_ss = authz_ss.apply(config_host, strict: false)
  3266. libauthz = static_library('authz', authz_ss.sources() + genh,
  3267. dependencies: [authz_ss.dependencies()],
  3268. name_suffix: 'fa',
  3269. build_by_default: false)
  3270. authz = declare_dependency(link_whole: libauthz,
  3271. dependencies: qom)
  3272. crypto_ss = crypto_ss.apply(config_host, strict: false)
  3273. libcrypto = static_library('crypto', crypto_ss.sources() + genh,
  3274. dependencies: [crypto_ss.dependencies()],
  3275. name_suffix: 'fa',
  3276. build_by_default: false)
  3277. crypto = declare_dependency(link_whole: libcrypto,
  3278. dependencies: [authz, qom])
  3279. io_ss = io_ss.apply(config_host, strict: false)
  3280. libio = static_library('io', io_ss.sources() + genh,
  3281. dependencies: [io_ss.dependencies()],
  3282. link_with: libqemuutil,
  3283. name_suffix: 'fa',
  3284. build_by_default: false)
  3285. io = declare_dependency(link_whole: libio, dependencies: [crypto, qom])
  3286. libmigration = static_library('migration', sources: migration_files + genh,
  3287. name_suffix: 'fa',
  3288. build_by_default: false)
  3289. migration = declare_dependency(link_with: libmigration,
  3290. dependencies: [zlib, qom, io])
  3291. softmmu_ss.add(migration)
  3292. block_ss = block_ss.apply(config_host, strict: false)
  3293. libblock = static_library('block', block_ss.sources() + genh,
  3294. dependencies: block_ss.dependencies(),
  3295. link_depends: block_syms,
  3296. name_suffix: 'fa',
  3297. build_by_default: false)
  3298. block = declare_dependency(link_whole: [libblock],
  3299. link_args: '@block.syms',
  3300. dependencies: [crypto, io])
  3301. blockdev_ss = blockdev_ss.apply(config_host, strict: false)
  3302. libblockdev = static_library('blockdev', blockdev_ss.sources() + genh,
  3303. dependencies: blockdev_ss.dependencies(),
  3304. name_suffix: 'fa',
  3305. build_by_default: false)
  3306. blockdev = declare_dependency(link_whole: [libblockdev],
  3307. dependencies: [block, event_loop_base])
  3308. qmp_ss = qmp_ss.apply(config_host, strict: false)
  3309. libqmp = static_library('qmp', qmp_ss.sources() + genh,
  3310. dependencies: qmp_ss.dependencies(),
  3311. name_suffix: 'fa',
  3312. build_by_default: false)
  3313. qmp = declare_dependency(link_whole: [libqmp])
  3314. libchardev = static_library('chardev', chardev_ss.sources() + genh,
  3315. name_suffix: 'fa',
  3316. dependencies: chardev_ss.dependencies(),
  3317. build_by_default: false)
  3318. chardev = declare_dependency(link_whole: libchardev)
  3319. hwcore_ss = hwcore_ss.apply(config_host, strict: false)
  3320. libhwcore = static_library('hwcore', sources: hwcore_ss.sources() + genh,
  3321. name_suffix: 'fa',
  3322. build_by_default: false)
  3323. hwcore = declare_dependency(link_whole: libhwcore)
  3324. common_ss.add(hwcore)
  3325. ###########
  3326. # Targets #
  3327. ###########
  3328. emulator_modules = []
  3329. foreach m : block_mods + softmmu_mods
  3330. emulator_modules += shared_module(m.name(),
  3331. build_by_default: true,
  3332. name_prefix: '',
  3333. link_whole: m,
  3334. install: true,
  3335. install_dir: qemu_moddir)
  3336. endforeach
  3337. if emulator_modules.length() > 0
  3338. alias_target('modules', emulator_modules)
  3339. endif
  3340. softmmu_ss.add(authz, blockdev, chardev, crypto, io, qmp)
  3341. common_ss.add(qom, qemuutil)
  3342. common_ss.add_all(when: 'CONFIG_SOFTMMU', if_true: [softmmu_ss])
  3343. common_ss.add_all(when: 'CONFIG_USER_ONLY', if_true: user_ss)
  3344. common_all = common_ss.apply(config_all, strict: false)
  3345. common_all = static_library('common',
  3346. build_by_default: false,
  3347. sources: common_all.sources() + genh,
  3348. include_directories: common_user_inc,
  3349. implicit_include_directories: false,
  3350. dependencies: common_all.dependencies(),
  3351. name_suffix: 'fa')
  3352. feature_to_c = find_program('scripts/feature_to_c.sh')
  3353. if targetos == 'darwin'
  3354. entitlement = find_program('scripts/entitlement.sh')
  3355. endif
  3356. emulators = {}
  3357. foreach target : target_dirs
  3358. config_target = config_target_mak[target]
  3359. target_name = config_target['TARGET_NAME']
  3360. target_base_arch = config_target['TARGET_BASE_ARCH']
  3361. arch_srcs = [config_target_h[target]]
  3362. arch_deps = []
  3363. c_args = ['-DNEED_CPU_H',
  3364. '-DCONFIG_TARGET="@0@-config-target.h"'.format(target),
  3365. '-DCONFIG_DEVICES="@0@-config-devices.h"'.format(target)]
  3366. link_args = emulator_link_args
  3367. config_target += config_host
  3368. target_inc = [include_directories('target' / config_target['TARGET_BASE_ARCH'])]
  3369. if targetos == 'linux'
  3370. target_inc += include_directories('linux-headers', is_system: true)
  3371. endif
  3372. if target.endswith('-softmmu')
  3373. target_type='system'
  3374. t = target_softmmu_arch[target_base_arch].apply(config_target, strict: false)
  3375. arch_srcs += t.sources()
  3376. arch_deps += t.dependencies()
  3377. hw_dir = target_name == 'sparc64' ? 'sparc64' : target_base_arch
  3378. hw = hw_arch[hw_dir].apply(config_target, strict: false)
  3379. arch_srcs += hw.sources()
  3380. arch_deps += hw.dependencies()
  3381. arch_srcs += config_devices_h[target]
  3382. link_args += ['@block.syms', '@qemu.syms']
  3383. else
  3384. abi = config_target['TARGET_ABI_DIR']
  3385. target_type='user'
  3386. target_inc += common_user_inc
  3387. if target_base_arch in target_user_arch
  3388. t = target_user_arch[target_base_arch].apply(config_target, strict: false)
  3389. arch_srcs += t.sources()
  3390. arch_deps += t.dependencies()
  3391. endif
  3392. if 'CONFIG_LINUX_USER' in config_target
  3393. base_dir = 'linux-user'
  3394. endif
  3395. if 'CONFIG_BSD_USER' in config_target
  3396. base_dir = 'bsd-user'
  3397. target_inc += include_directories('bsd-user/' / targetos)
  3398. target_inc += include_directories('bsd-user/host/' / host_arch)
  3399. dir = base_dir / abi
  3400. arch_srcs += files(dir / 'signal.c', dir / 'target_arch_cpu.c')
  3401. endif
  3402. target_inc += include_directories(
  3403. base_dir,
  3404. base_dir / abi,
  3405. )
  3406. if 'CONFIG_LINUX_USER' in config_target
  3407. dir = base_dir / abi
  3408. arch_srcs += files(dir / 'signal.c', dir / 'cpu_loop.c')
  3409. if config_target.has_key('TARGET_SYSTBL_ABI')
  3410. arch_srcs += \
  3411. syscall_nr_generators[abi].process(base_dir / abi / config_target['TARGET_SYSTBL'],
  3412. extra_args : config_target['TARGET_SYSTBL_ABI'])
  3413. endif
  3414. endif
  3415. endif
  3416. if 'TARGET_XML_FILES' in config_target
  3417. gdbstub_xml = custom_target(target + '-gdbstub-xml.c',
  3418. output: target + '-gdbstub-xml.c',
  3419. input: files(config_target['TARGET_XML_FILES'].split()),
  3420. command: [feature_to_c, '@INPUT@'],
  3421. capture: true)
  3422. arch_srcs += gdbstub_xml
  3423. endif
  3424. t = target_arch[target_base_arch].apply(config_target, strict: false)
  3425. arch_srcs += t.sources()
  3426. arch_deps += t.dependencies()
  3427. target_common = common_ss.apply(config_target, strict: false)
  3428. objects = common_all.extract_objects(target_common.sources())
  3429. deps = target_common.dependencies()
  3430. target_specific = specific_ss.apply(config_target, strict: false)
  3431. arch_srcs += target_specific.sources()
  3432. arch_deps += target_specific.dependencies()
  3433. lib = static_library('qemu-' + target,
  3434. sources: arch_srcs + genh,
  3435. dependencies: arch_deps,
  3436. objects: objects,
  3437. include_directories: target_inc,
  3438. c_args: c_args,
  3439. build_by_default: false,
  3440. name_suffix: 'fa')
  3441. if target.endswith('-softmmu')
  3442. execs = [{
  3443. 'name': 'qemu-system-' + target_name,
  3444. 'win_subsystem': 'console',
  3445. 'sources': files('softmmu/main.c'),
  3446. 'dependencies': []
  3447. }]
  3448. if targetos == 'windows' and (sdl.found() or gtk.found())
  3449. execs += [{
  3450. 'name': 'qemu-system-' + target_name + 'w',
  3451. 'win_subsystem': 'windows',
  3452. 'sources': files('softmmu/main.c'),
  3453. 'dependencies': []
  3454. }]
  3455. endif
  3456. if get_option('fuzzing')
  3457. specific_fuzz = specific_fuzz_ss.apply(config_target, strict: false)
  3458. execs += [{
  3459. 'name': 'qemu-fuzz-' + target_name,
  3460. 'win_subsystem': 'console',
  3461. 'sources': specific_fuzz.sources(),
  3462. 'dependencies': specific_fuzz.dependencies(),
  3463. }]
  3464. endif
  3465. else
  3466. execs = [{
  3467. 'name': 'qemu-' + target_name,
  3468. 'win_subsystem': 'console',
  3469. 'sources': [],
  3470. 'dependencies': []
  3471. }]
  3472. endif
  3473. foreach exe: execs
  3474. exe_name = exe['name']
  3475. if targetos == 'darwin'
  3476. exe_name += '-unsigned'
  3477. endif
  3478. emulator = executable(exe_name, exe['sources'],
  3479. install: true,
  3480. c_args: c_args,
  3481. dependencies: arch_deps + deps + exe['dependencies'],
  3482. objects: lib.extract_all_objects(recursive: true),
  3483. link_language: link_language,
  3484. link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []),
  3485. link_args: link_args,
  3486. win_subsystem: exe['win_subsystem'])
  3487. if targetos == 'darwin'
  3488. icon = 'pc-bios/qemu.rsrc'
  3489. build_input = [emulator, files(icon)]
  3490. install_input = [
  3491. get_option('bindir') / exe_name,
  3492. meson.current_source_dir() / icon
  3493. ]
  3494. if 'CONFIG_HVF' in config_target
  3495. entitlements = 'accel/hvf/entitlements.plist'
  3496. build_input += files(entitlements)
  3497. install_input += meson.current_source_dir() / entitlements
  3498. endif
  3499. emulators += {exe['name'] : custom_target(exe['name'],
  3500. input: build_input,
  3501. output: exe['name'],
  3502. command: [entitlement, '@OUTPUT@', '@INPUT@'])
  3503. }
  3504. meson.add_install_script(entitlement, '--install',
  3505. get_option('bindir') / exe['name'],
  3506. install_input)
  3507. else
  3508. emulators += {exe['name']: emulator}
  3509. endif
  3510. if stap.found()
  3511. foreach stp: [
  3512. {'ext': '.stp-build', 'fmt': 'stap', 'bin': meson.current_build_dir() / exe['name'], 'install': false},
  3513. {'ext': '.stp', 'fmt': 'stap', 'bin': get_option('prefix') / get_option('bindir') / exe['name'], 'install': true},
  3514. {'ext': '-simpletrace.stp', 'fmt': 'simpletrace-stap', 'bin': '', 'install': true},
  3515. {'ext': '-log.stp', 'fmt': 'log-stap', 'bin': '', 'install': true},
  3516. ]
  3517. custom_target(exe['name'] + stp['ext'],
  3518. input: trace_events_all,
  3519. output: exe['name'] + stp['ext'],
  3520. install: stp['install'],
  3521. install_dir: get_option('datadir') / 'systemtap/tapset',
  3522. command: [
  3523. tracetool, '--group=all', '--format=' + stp['fmt'],
  3524. '--binary=' + stp['bin'],
  3525. '--target-name=' + target_name,
  3526. '--target-type=' + target_type,
  3527. '--probe-prefix=qemu.' + target_type + '.' + target_name,
  3528. '@INPUT@', '@OUTPUT@'
  3529. ],
  3530. depend_files: tracetool_depends)
  3531. endforeach
  3532. endif
  3533. endforeach
  3534. endforeach
  3535. # Other build targets
  3536. if 'CONFIG_PLUGIN' in config_host
  3537. install_headers('include/qemu/qemu-plugin.h')
  3538. endif
  3539. subdir('qga')
  3540. # Don't build qemu-keymap if xkbcommon is not explicitly enabled
  3541. # when we don't build tools or system
  3542. if xkbcommon.found()
  3543. # used for the update-keymaps target, so include rules even if !have_tools
  3544. qemu_keymap = executable('qemu-keymap', files('qemu-keymap.c', 'ui/input-keymap.c') + genh,
  3545. dependencies: [qemuutil, xkbcommon], install: have_tools)
  3546. endif
  3547. if have_tools
  3548. qemu_img = executable('qemu-img', [files('qemu-img.c'), hxdep],
  3549. dependencies: [authz, block, crypto, io, qom, qemuutil], install: true)
  3550. qemu_io = executable('qemu-io', files('qemu-io.c'),
  3551. dependencies: [block, qemuutil], install: true)
  3552. qemu_nbd = executable('qemu-nbd', files('qemu-nbd.c'),
  3553. dependencies: [blockdev, qemuutil, gnutls, selinux],
  3554. install: true)
  3555. subdir('storage-daemon')
  3556. subdir('contrib/rdmacm-mux')
  3557. subdir('contrib/elf2dmp')
  3558. executable('qemu-edid', files('qemu-edid.c', 'hw/display/edid-generate.c'),
  3559. dependencies: qemuutil,
  3560. install: true)
  3561. if have_vhost_user
  3562. subdir('contrib/vhost-user-blk')
  3563. subdir('contrib/vhost-user-gpu')
  3564. subdir('contrib/vhost-user-input')
  3565. subdir('contrib/vhost-user-scsi')
  3566. endif
  3567. if targetos == 'linux'
  3568. executable('qemu-bridge-helper', files('qemu-bridge-helper.c'),
  3569. dependencies: [qemuutil, libcap_ng],
  3570. install: true,
  3571. install_dir: get_option('libexecdir'))
  3572. executable('qemu-pr-helper', files('scsi/qemu-pr-helper.c', 'scsi/utils.c'),
  3573. dependencies: [authz, crypto, io, qom, qemuutil,
  3574. libcap_ng, mpathpersist],
  3575. install: true)
  3576. endif
  3577. if have_ivshmem
  3578. subdir('contrib/ivshmem-client')
  3579. subdir('contrib/ivshmem-server')
  3580. endif
  3581. endif
  3582. subdir('scripts')
  3583. subdir('tools')
  3584. subdir('pc-bios')
  3585. subdir('docs')
  3586. subdir('tests')
  3587. if gtk.found()
  3588. subdir('po')
  3589. endif
  3590. if host_machine.system() == 'windows'
  3591. nsis_cmd = [
  3592. find_program('scripts/nsis.py'),
  3593. '@OUTPUT@',
  3594. get_option('prefix'),
  3595. meson.current_source_dir(),
  3596. glib_pc.get_variable('bindir'),
  3597. host_machine.cpu(),
  3598. '--',
  3599. '-DDISPLAYVERSION=' + meson.project_version(),
  3600. ]
  3601. if build_docs
  3602. nsis_cmd += '-DCONFIG_DOCUMENTATION=y'
  3603. endif
  3604. if gtk.found()
  3605. nsis_cmd += '-DCONFIG_GTK=y'
  3606. endif
  3607. nsis = custom_target('nsis',
  3608. output: 'qemu-setup-' + meson.project_version() + '.exe',
  3609. input: files('qemu.nsi'),
  3610. build_always_stale: true,
  3611. command: nsis_cmd + ['@INPUT@'])
  3612. alias_target('installer', nsis)
  3613. endif
  3614. #########################
  3615. # Configuration summary #
  3616. #########################
  3617. # Build environment
  3618. summary_info = {}
  3619. summary_info += {'Build directory': meson.current_build_dir()}
  3620. summary_info += {'Source path': meson.current_source_dir()}
  3621. summary_info += {'Download dependencies': get_option('wrap_mode') != 'nodownload'}
  3622. summary(summary_info, bool_yn: true, section: 'Build environment')
  3623. # Directories
  3624. summary_info += {'Install prefix': get_option('prefix')}
  3625. summary_info += {'BIOS directory': qemu_datadir}
  3626. pathsep = targetos == 'windows' ? ';' : ':'
  3627. summary_info += {'firmware path': pathsep.join(get_option('qemu_firmwarepath'))}
  3628. summary_info += {'binary directory': get_option('prefix') / get_option('bindir')}
  3629. summary_info += {'library directory': get_option('prefix') / get_option('libdir')}
  3630. summary_info += {'module directory': qemu_moddir}
  3631. summary_info += {'libexec directory': get_option('prefix') / get_option('libexecdir')}
  3632. summary_info += {'include directory': get_option('prefix') / get_option('includedir')}
  3633. summary_info += {'config directory': get_option('prefix') / get_option('sysconfdir')}
  3634. if targetos != 'windows'
  3635. summary_info += {'local state directory': get_option('prefix') / get_option('localstatedir')}
  3636. summary_info += {'Manual directory': get_option('prefix') / get_option('mandir')}
  3637. else
  3638. summary_info += {'local state directory': 'queried at runtime'}
  3639. endif
  3640. summary_info += {'Doc directory': get_option('prefix') / get_option('docdir')}
  3641. summary(summary_info, bool_yn: true, section: 'Directories')
  3642. # Host binaries
  3643. summary_info = {}
  3644. summary_info += {'python': '@0@ (version: @1@)'.format(python.full_path(), python.language_version())}
  3645. summary_info += {'sphinx-build': sphinx_build}
  3646. if config_host.has_key('HAVE_GDB_BIN')
  3647. summary_info += {'gdb': config_host['HAVE_GDB_BIN']}
  3648. endif
  3649. summary_info += {'iasl': iasl}
  3650. summary_info += {'genisoimage': config_host['GENISOIMAGE']}
  3651. if targetos == 'windows' and have_ga
  3652. summary_info += {'wixl': wixl}
  3653. endif
  3654. if slirp.found() and have_system
  3655. summary_info += {'smbd': have_slirp_smbd ? smbd_path : false}
  3656. endif
  3657. summary(summary_info, bool_yn: true, section: 'Host binaries')
  3658. # Configurable features
  3659. summary_info = {}
  3660. summary_info += {'Documentation': build_docs}
  3661. summary_info += {'system-mode emulation': have_system}
  3662. summary_info += {'user-mode emulation': have_user}
  3663. summary_info += {'block layer': have_block}
  3664. summary_info += {'Install blobs': get_option('install_blobs')}
  3665. summary_info += {'module support': enable_modules}
  3666. if enable_modules
  3667. summary_info += {'alternative module path': get_option('module_upgrades')}
  3668. endif
  3669. summary_info += {'fuzzing support': get_option('fuzzing')}
  3670. if have_system
  3671. summary_info += {'Audio drivers': ' '.join(audio_drivers_selected)}
  3672. endif
  3673. summary_info += {'Trace backends': ','.join(get_option('trace_backends'))}
  3674. if 'simple' in get_option('trace_backends')
  3675. summary_info += {'Trace output file': get_option('trace_file') + '-<pid>'}
  3676. endif
  3677. summary_info += {'D-Bus display': dbus_display}
  3678. summary_info += {'QOM debugging': get_option('qom_cast_debug')}
  3679. summary_info += {'vhost-kernel support': have_vhost_kernel}
  3680. summary_info += {'vhost-net support': have_vhost_net}
  3681. summary_info += {'vhost-user support': have_vhost_user}
  3682. summary_info += {'vhost-user-crypto support': have_vhost_user_crypto}
  3683. summary_info += {'vhost-user-blk server support': have_vhost_user_blk_server}
  3684. summary_info += {'vhost-vdpa support': have_vhost_vdpa}
  3685. summary_info += {'build guest agent': have_ga}
  3686. summary(summary_info, bool_yn: true, section: 'Configurable features')
  3687. # Compilation information
  3688. summary_info = {}
  3689. summary_info += {'host CPU': cpu}
  3690. summary_info += {'host endianness': build_machine.endian()}
  3691. summary_info += {'C compiler': ' '.join(meson.get_compiler('c').cmd_array())}
  3692. summary_info += {'Host C compiler': ' '.join(meson.get_compiler('c', native: true).cmd_array())}
  3693. if link_language == 'cpp'
  3694. summary_info += {'C++ compiler': ' '.join(meson.get_compiler('cpp').cmd_array())}
  3695. else
  3696. summary_info += {'C++ compiler': false}
  3697. endif
  3698. if targetos == 'darwin'
  3699. summary_info += {'Objective-C compiler': ' '.join(meson.get_compiler('objc').cmd_array())}
  3700. endif
  3701. option_cflags = (get_option('debug') ? ['-g'] : [])
  3702. if get_option('optimization') != 'plain'
  3703. option_cflags += ['-O' + get_option('optimization')]
  3704. endif
  3705. summary_info += {'CFLAGS': ' '.join(get_option('c_args') + option_cflags)}
  3706. if link_language == 'cpp'
  3707. summary_info += {'CXXFLAGS': ' '.join(get_option('cpp_args') + option_cflags)}
  3708. endif
  3709. if targetos == 'darwin'
  3710. summary_info += {'OBJCFLAGS': ' '.join(get_option('objc_args') + option_cflags)}
  3711. endif
  3712. link_args = get_option(link_language + '_link_args')
  3713. if link_args.length() > 0
  3714. summary_info += {'LDFLAGS': ' '.join(link_args)}
  3715. endif
  3716. summary_info += {'QEMU_CFLAGS': ' '.join(qemu_common_flags + qemu_cflags)}
  3717. if 'cpp' in all_languages
  3718. summary_info += {'QEMU_CXXFLAGS': ' '.join(qemu_common_flags + qemu_cxxflags)}
  3719. endif
  3720. if 'objc' in all_languages
  3721. summary_info += {'QEMU_OBJCFLAGS': ' '.join(qemu_common_flags)}
  3722. endif
  3723. summary_info += {'QEMU_LDFLAGS': ' '.join(qemu_ldflags)}
  3724. summary_info += {'profiler': get_option('profiler')}
  3725. summary_info += {'link-time optimization (LTO)': get_option('b_lto')}
  3726. summary_info += {'PIE': get_option('b_pie')}
  3727. summary_info += {'static build': config_host.has_key('CONFIG_STATIC')}
  3728. summary_info += {'malloc trim support': has_malloc_trim}
  3729. summary_info += {'membarrier': have_membarrier}
  3730. summary_info += {'debug graph lock': get_option('debug_graph_lock')}
  3731. summary_info += {'debug stack usage': get_option('debug_stack_usage')}
  3732. summary_info += {'mutex debugging': get_option('debug_mutex')}
  3733. summary_info += {'memory allocator': get_option('malloc')}
  3734. summary_info += {'avx2 optimization': config_host_data.get('CONFIG_AVX2_OPT')}
  3735. summary_info += {'avx512bw optimization': config_host_data.get('CONFIG_AVX512BW_OPT')}
  3736. summary_info += {'avx512f optimization': config_host_data.get('CONFIG_AVX512F_OPT')}
  3737. if get_option('gprof')
  3738. gprof_info = 'YES (deprecated)'
  3739. else
  3740. gprof_info = get_option('gprof')
  3741. endif
  3742. summary_info += {'gprof': gprof_info}
  3743. summary_info += {'gcov': get_option('b_coverage')}
  3744. summary_info += {'thread sanitizer': get_option('tsan')}
  3745. summary_info += {'CFI support': get_option('cfi')}
  3746. if get_option('cfi')
  3747. summary_info += {'CFI debug support': get_option('cfi_debug')}
  3748. endif
  3749. summary_info += {'strip binaries': get_option('strip')}
  3750. summary_info += {'sparse': sparse}
  3751. summary_info += {'mingw32 support': targetos == 'windows'}
  3752. summary(summary_info, bool_yn: true, section: 'Compilation')
  3753. # snarf the cross-compilation information for tests
  3754. summary_info = {}
  3755. have_cross = false
  3756. foreach target: target_dirs
  3757. tcg_mak = meson.current_build_dir() / 'tests/tcg' / target / 'config-target.mak'
  3758. if fs.exists(tcg_mak)
  3759. config_cross_tcg = keyval.load(tcg_mak)
  3760. if 'CC' in config_cross_tcg
  3761. summary_info += {config_cross_tcg['TARGET_NAME']: config_cross_tcg['CC']}
  3762. have_cross = true
  3763. endif
  3764. endif
  3765. endforeach
  3766. if have_cross
  3767. summary(summary_info, bool_yn: true, section: 'Cross compilers')
  3768. endif
  3769. # Targets and accelerators
  3770. summary_info = {}
  3771. if have_system
  3772. summary_info += {'KVM support': config_all.has_key('CONFIG_KVM')}
  3773. summary_info += {'HAX support': config_all.has_key('CONFIG_HAX')}
  3774. summary_info += {'HVF support': config_all.has_key('CONFIG_HVF')}
  3775. summary_info += {'WHPX support': config_all.has_key('CONFIG_WHPX')}
  3776. summary_info += {'NVMM support': config_all.has_key('CONFIG_NVMM')}
  3777. summary_info += {'Xen support': xen.found()}
  3778. if xen.found()
  3779. summary_info += {'xen ctrl version': xen.version()}
  3780. endif
  3781. summary_info += {'Xen emulation': config_all.has_key('CONFIG_XEN_EMU')}
  3782. endif
  3783. summary_info += {'TCG support': config_all.has_key('CONFIG_TCG')}
  3784. if config_all.has_key('CONFIG_TCG')
  3785. if get_option('tcg_interpreter')
  3786. summary_info += {'TCG backend': 'TCI (TCG with bytecode interpreter, slow)'}
  3787. else
  3788. summary_info += {'TCG backend': 'native (@0@)'.format(cpu)}
  3789. endif
  3790. summary_info += {'TCG plugins': config_host.has_key('CONFIG_PLUGIN')}
  3791. summary_info += {'TCG debug enabled': config_host.has_key('CONFIG_DEBUG_TCG')}
  3792. endif
  3793. summary_info += {'target list': ' '.join(target_dirs)}
  3794. if have_system
  3795. summary_info += {'default devices': get_option('default_devices')}
  3796. summary_info += {'out of process emulation': multiprocess_allowed}
  3797. summary_info += {'vfio-user server': vfio_user_server_allowed}
  3798. endif
  3799. summary(summary_info, bool_yn: true, section: 'Targets and accelerators')
  3800. # Block layer
  3801. summary_info = {}
  3802. summary_info += {'coroutine backend': coroutine_backend}
  3803. summary_info += {'coroutine pool': have_coroutine_pool}
  3804. if have_block
  3805. summary_info += {'Block whitelist (rw)': get_option('block_drv_rw_whitelist')}
  3806. summary_info += {'Block whitelist (ro)': get_option('block_drv_ro_whitelist')}
  3807. summary_info += {'Use block whitelist in tools': get_option('block_drv_whitelist_in_tools')}
  3808. summary_info += {'VirtFS (9P) support': have_virtfs}
  3809. summary_info += {'VirtFS (9P) Proxy Helper support': have_virtfs_proxy_helper}
  3810. summary_info += {'Live block migration': config_host_data.get('CONFIG_LIVE_BLOCK_MIGRATION')}
  3811. summary_info += {'replication support': config_host_data.get('CONFIG_REPLICATION')}
  3812. summary_info += {'bochs support': get_option('bochs').allowed()}
  3813. summary_info += {'cloop support': get_option('cloop').allowed()}
  3814. summary_info += {'dmg support': get_option('dmg').allowed()}
  3815. summary_info += {'qcow v1 support': get_option('qcow1').allowed()}
  3816. summary_info += {'vdi support': get_option('vdi').allowed()}
  3817. summary_info += {'vhdx support': get_option('vhdx').allowed()}
  3818. summary_info += {'vmdk support': get_option('vmdk').allowed()}
  3819. summary_info += {'vpc support': get_option('vpc').allowed()}
  3820. summary_info += {'vvfat support': get_option('vvfat').allowed()}
  3821. summary_info += {'qed support': get_option('qed').allowed()}
  3822. summary_info += {'parallels support': get_option('parallels').allowed()}
  3823. summary_info += {'FUSE exports': fuse}
  3824. summary_info += {'VDUSE block exports': have_vduse_blk_export}
  3825. endif
  3826. summary(summary_info, bool_yn: true, section: 'Block layer support')
  3827. # Crypto
  3828. summary_info = {}
  3829. summary_info += {'TLS priority': get_option('tls_priority')}
  3830. summary_info += {'GNUTLS support': gnutls}
  3831. if gnutls.found()
  3832. summary_info += {' GNUTLS crypto': gnutls_crypto.found()}
  3833. endif
  3834. summary_info += {'libgcrypt': gcrypt}
  3835. summary_info += {'nettle': nettle}
  3836. if nettle.found()
  3837. summary_info += {' XTS': xts != 'private'}
  3838. endif
  3839. summary_info += {'AF_ALG support': have_afalg}
  3840. summary_info += {'rng-none': get_option('rng_none')}
  3841. summary_info += {'Linux keyring': have_keyring}
  3842. summary(summary_info, bool_yn: true, section: 'Crypto')
  3843. # UI
  3844. summary_info = {}
  3845. if targetos == 'darwin'
  3846. summary_info += {'Cocoa support': cocoa}
  3847. endif
  3848. summary_info += {'SDL support': sdl}
  3849. summary_info += {'SDL image support': sdl_image}
  3850. summary_info += {'GTK support': gtk}
  3851. summary_info += {'pixman': pixman}
  3852. summary_info += {'VTE support': vte}
  3853. summary_info += {'PNG support': png}
  3854. summary_info += {'VNC support': vnc}
  3855. if vnc.found()
  3856. summary_info += {'VNC SASL support': sasl}
  3857. summary_info += {'VNC JPEG support': jpeg}
  3858. endif
  3859. summary_info += {'spice protocol support': spice_protocol}
  3860. if spice_protocol.found()
  3861. summary_info += {' spice server support': spice}
  3862. endif
  3863. summary_info += {'curses support': curses}
  3864. summary_info += {'brlapi support': brlapi}
  3865. summary(summary_info, bool_yn: true, section: 'User interface')
  3866. # Audio backends
  3867. summary_info = {}
  3868. if targetos not in ['darwin', 'haiku', 'windows']
  3869. summary_info += {'OSS support': oss}
  3870. summary_info += {'sndio support': sndio}
  3871. elif targetos == 'darwin'
  3872. summary_info += {'CoreAudio support': coreaudio}
  3873. elif targetos == 'windows'
  3874. summary_info += {'DirectSound support': dsound}
  3875. endif
  3876. if targetos == 'linux'
  3877. summary_info += {'ALSA support': alsa}
  3878. summary_info += {'PulseAudio support': pulse}
  3879. endif
  3880. summary_info += {'Pipewire support': pipewire}
  3881. summary_info += {'JACK support': jack}
  3882. summary(summary_info, bool_yn: true, section: 'Audio backends')
  3883. # Network backends
  3884. summary_info = {}
  3885. if targetos == 'darwin'
  3886. summary_info += {'vmnet.framework support': vmnet}
  3887. endif
  3888. summary_info += {'slirp support': slirp}
  3889. summary_info += {'vde support': vde}
  3890. summary_info += {'netmap support': have_netmap}
  3891. summary_info += {'l2tpv3 support': have_l2tpv3}
  3892. summary(summary_info, bool_yn: true, section: 'Network backends')
  3893. # Libraries
  3894. summary_info = {}
  3895. summary_info += {'libtasn1': tasn1}
  3896. summary_info += {'PAM': pam}
  3897. summary_info += {'iconv support': iconv}
  3898. summary_info += {'virgl support': virgl}
  3899. summary_info += {'blkio support': blkio}
  3900. summary_info += {'curl support': curl}
  3901. summary_info += {'Multipath support': mpathpersist}
  3902. summary_info += {'Linux AIO support': libaio}
  3903. summary_info += {'Linux io_uring support': linux_io_uring}
  3904. summary_info += {'ATTR/XATTR support': libattr}
  3905. summary_info += {'RDMA support': rdma}
  3906. summary_info += {'PVRDMA support': have_pvrdma}
  3907. summary_info += {'fdt support': fdt_opt == 'disabled' ? false : fdt_opt}
  3908. summary_info += {'libcap-ng support': libcap_ng}
  3909. summary_info += {'bpf support': libbpf}
  3910. summary_info += {'rbd support': rbd}
  3911. summary_info += {'smartcard support': cacard}
  3912. summary_info += {'U2F support': u2f}
  3913. summary_info += {'libusb': libusb}
  3914. summary_info += {'usb net redir': usbredir}
  3915. summary_info += {'OpenGL support (epoxy)': opengl}
  3916. summary_info += {'GBM': gbm}
  3917. summary_info += {'libiscsi support': libiscsi}
  3918. summary_info += {'libnfs support': libnfs}
  3919. if targetos == 'windows'
  3920. if have_ga
  3921. summary_info += {'QGA VSS support': have_qga_vss}
  3922. endif
  3923. endif
  3924. summary_info += {'seccomp support': seccomp}
  3925. summary_info += {'GlusterFS support': glusterfs}
  3926. summary_info += {'TPM support': have_tpm}
  3927. summary_info += {'libssh support': libssh}
  3928. summary_info += {'lzo support': lzo}
  3929. summary_info += {'snappy support': snappy}
  3930. summary_info += {'bzip2 support': libbzip2}
  3931. summary_info += {'lzfse support': liblzfse}
  3932. summary_info += {'zstd support': zstd}
  3933. summary_info += {'NUMA host support': numa}
  3934. summary_info += {'capstone': capstone}
  3935. summary_info += {'libpmem support': libpmem}
  3936. summary_info += {'libdaxctl support': libdaxctl}
  3937. summary_info += {'libudev': libudev}
  3938. # Dummy dependency, keep .found()
  3939. summary_info += {'FUSE lseek': fuse_lseek.found()}
  3940. summary_info += {'selinux': selinux}
  3941. summary_info += {'libdw': libdw}
  3942. summary(summary_info, bool_yn: true, section: 'Dependencies')
  3943. if not supported_cpus.contains(cpu)
  3944. message()
  3945. warning('SUPPORT FOR THIS HOST CPU WILL GO AWAY IN FUTURE RELEASES!')
  3946. message()
  3947. message('CPU host architecture ' + cpu + ' support is not currently maintained.')
  3948. message('The QEMU project intends to remove support for this host CPU in')
  3949. message('a future release if nobody volunteers to maintain it and to')
  3950. message('provide a build host for our continuous integration setup.')
  3951. message('configure has succeeded and you can continue to build, but')
  3952. message('if you care about QEMU on this platform you should contact')
  3953. message('us upstream at qemu-devel@nongnu.org.')
  3954. endif
  3955. if not supported_oses.contains(targetos)
  3956. message()
  3957. warning('WARNING: SUPPORT FOR THIS HOST OS WILL GO AWAY IN FUTURE RELEASES!')
  3958. message()
  3959. message('Host OS ' + targetos + 'support is not currently maintained.')
  3960. message('The QEMU project intends to remove support for this host OS in')
  3961. message('a future release if nobody volunteers to maintain it and to')
  3962. message('provide a build host for our continuous integration setup.')
  3963. message('configure has succeeded and you can continue to build, but')
  3964. message('if you care about QEMU on this platform you should contact')
  3965. message('us upstream at qemu-devel@nongnu.org.')
  3966. endif