win32: Fix meson build system for Windows.
authorEdward Lee <e45lee@uwaterloo.ca>
Thu, 1 Oct 2020 14:24:40 +0000 (10:24 -0400)
committerArun Raghavan <arun@asymptotic.io>
Wed, 16 Dec 2020 16:05:28 +0000 (11:05 -0500)
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/360>

meson.build
src/daemon/meson.build
src/meson.build
src/modules/meson.build
src/pulse/meson.build
src/pulsecore/meson.build
src/utils/meson.build

index 437fc80..cd617c6 100644 (file)
@@ -158,6 +158,10 @@ cdata.set('top_srcdir', meson.source_root())
 # First some defaults to keep config file generation happy
 cdata.set('HAVE_COREAUDIO', 0)
 cdata.set('HAVE_WAVEOUT', 0)
+
+platform_socket_dep = []
+platform_dep = []
+
 # FIXME: This was not tested. Maybe some flags should better be CFLAGS,
 # rather than ending up in the config.h file?
 if host_machine.system() == 'darwin'
@@ -165,7 +169,20 @@ if host_machine.system() == 'darwin'
   cdata.set('_DARWIN_C_SOURCE', '200112L') # Needed to get NSIG on Mac OS
 elif host_machine.system() == 'windows'
   cdata.set('OS_IS_WIN32', 1)
+  cdata.set('HAVE_WINDOWS_H', 1)
+  cdata.set('HAVE_WAVEOUT', 1)
+  cdata.set('HAVE_WINSOCK2_H', 1)
+  cdata.set('HAVE_WS2TCPIP_H', 1)
   cdata.set('WIN32_LEAN_AND_MEAN', 1) # Needed to avoid including unnecessary headers on Windows
+  cdata.set('gid_t', 'int')
+  cdata.set('uid_t', 'int')
+  ws2_32_dep = meson.get_compiler('c').find_library('ws2_32')
+  winsock_dep = meson.get_compiler('c').find_library('wsock32')
+  ole32_dep = meson.get_compiler('c').find_library('ole32')
+  ssp_dep = meson.get_compiler('c').find_library('ssp')
+  pcreposix_dep = meson.get_compiler('c').find_library('pcreposix')
+  platform_socket_dep = [ws2_32_dep, winsock_dep]
+  platform_dep = [ole32_dep, ssp_dep, pcreposix_dep]
 #elif host_machine.system() == 'solaris'
 #  # Apparently meson has no solaris support?
 #  # Needed to get declarations for msg_control and msg_controllen on Solaris
@@ -236,8 +253,10 @@ if cc.has_header('valgrind/memcheck.h', required: get_option('valgrind'))
 endif
 
 # FIXME: move this to the above set
-if cc.has_header('pthread.h')
-  cdata.set('HAVE_PTHREAD', 1)
+if host_machine.system() != 'windows'
+  if cc.has_header('pthread.h')
+    cdata.set('HAVE_PTHREAD', 1)
+  endif
 endif
 
 if cc.has_header_symbol('pthread.h', 'PTHREAD_PRIO_INHERIT')
@@ -297,7 +316,16 @@ check_functions = [
 foreach f : check_functions
   if cc.has_function(f)
     define = 'HAVE_' + f.underscorify().to_upper()
-    cdata.set(define, 1)
+
+    if f == 'posix_memalign' and host_machine.system() == 'windows'
+      message('Win32/mingw32 does not properly define posix_memalign.')
+    elif f == 'fork' and host_machine.system() == 'windows'
+      # __builtin_fork is defined and compiles properly, but calling __builtin_fork() does not.
+      # This causes Meson to think that Windows has a fork() which causes a link error...
+      message('Win32/mingw32 does not properly define fork.')
+    else
+      cdata.set(define, 1)
+    endif
   endif
 endforeach
 
@@ -306,7 +334,11 @@ if cc.has_header_symbol('sys/syscall.h', 'SYS_memfd_create')
 endif
 
 if cc.has_function('dgettext')
-  libintl_dep = []
+  if host_machine.system() != 'windows'
+    libintl_dep = []
+  else
+    libintl_dep = cc.find_library('intl')
+  endif
 else
   libintl_dep = cc.find_library('intl')
 endif
@@ -357,7 +389,12 @@ cdata.set('MESON_BUILD', 1)
 # On ELF systems we don't want the libraries to be unloaded since we don't clean them up properly,
 # so we request the nodelete flag to be enabled.
 # On other systems, we don't really know how to do that, but it's welcome if somebody can tell.
-nodelete_link_args = ['-Wl,-z,nodelete']
+# Windows doesn't support this flag.
+if host_machine.system() != 'windows'
+  nodelete_link_args = ['-Wl,-z,nodelete']
+else
+  nodelete_link_args = []
+endif
 
 # Code coverage
 
index 9c9f807..4a57d7b 100644 (file)
@@ -31,7 +31,7 @@ executable('pulseaudio',
   include_directories : [configinc, topinc],
   link_args : ['-ffast-math'],
   link_with : [libpulsecore, libpulsecommon, libpulse],
-  dependencies : [ltdl_dep, cap_dep, dbus_dep, libsystemd_dep, dl_dep, libintl_dep],
+  dependencies : [ltdl_dep, cap_dep, dbus_dep, libsystemd_dep, dl_dep, libintl_dep, platform_dep, platform_socket_dep],
   c_args : pa_c_args,
 )
 
index b84112e..0842db2 100644 (file)
@@ -39,7 +39,6 @@ libpulsecommon_sources = [
   'pulsecore/memblock.c',
   'pulsecore/memblockq.c',
   'pulsecore/memchunk.c',
-  'pulsecore/mutex-posix.c',
   'pulsecore/native-common.c',
   'pulsecore/once.c',
   'pulsecore/packet.c',
@@ -56,7 +55,6 @@ libpulsecommon_sources = [
   'pulsecore/random.c',
   'pulsecore/srbchannel.c',
   'pulsecore/sample-util.c',
-  'pulsecore/semaphore-posix.c',
   'pulsecore/shm.c',
   'pulsecore/bitset.c',
   'pulsecore/socket-client.c',
@@ -65,7 +63,6 @@ libpulsecommon_sources = [
   'pulsecore/strbuf.c',
   'pulsecore/strlist.c',
   'pulsecore/tagstruct.c',
-  'pulsecore/thread-posix.c',
   'pulsecore/time-smoother.c',
   'pulsecore/tokenizer.c',
   'pulsecore/usergroup.c',
@@ -177,6 +174,20 @@ if x11_dep.found()
 endif
 
 # FIXME: Do non-POSIX thread things
+if host_machine.system() == 'windows'
+  libpulsecommon_sources += [
+    'pulsecore/mutex-win32.c',
+    'pulsecore/poll-win32.c',
+    'pulsecore/semaphore-win32.c',
+    'pulsecore/thread-win32.c',
+  ]
+else
+  libpulsecommon_sources += [
+    'pulsecore/mutex-posix.c',
+    'pulsecore/semaphore-posix.c',
+    'pulsecore/thread-posix.c'
+  ]
+endif
 # FIXME: Do SIMD things
 
 libpulsecommon = shared_library('pulsecommon-' + pa_version_major_minor,
@@ -190,6 +201,7 @@ libpulsecommon = shared_library('pulsecommon-' + pa_version_major_minor,
   dependencies : [
     libm_dep, thread_dep, dl_dep, shm_dep, iconv_dep, sndfile_dep, dbus_dep,
     x11_dep, libsystemd_dep, glib_dep, gtk_dep, asyncns_dep, libintl_dep,
+    platform_dep, platform_socket_dep,
   ],
   implicit_include_directories : false)
 
index a4da633..dcfc432 100644 (file)
@@ -1,4 +1,6 @@
-subdir('rtp')
+if host_machine.system() != 'windows'
+  subdir('rtp')
+endif
 
 # module name, sources, [headers, extra flags, extra deps, extra libs]
 all_modules = [
@@ -44,8 +46,6 @@ all_modules = [
   [ 'module-rescue-streams', 'module-rescue-streams.c' ],
   [ 'module-role-cork', ['module-role-cork.c', 'stream-interaction.c'], 'stream-interaction.h' ],
   [ 'module-role-ducking', ['module-role-ducking.c', 'stream-interaction.c'], 'stream-interaction.h' ],
-  [ 'module-rtp-recv', 'rtp/module-rtp-recv.c', [], [], [], librtp ],
-  [ 'module-rtp-send', 'rtp/module-rtp-send.c' , [], [], [], librtp ],
   [ 'module-simple-protocol-tcp', 'module-protocol-stub.c', [], ['-DUSE_PROTOCOL_SIMPLE', '-DUSE_TCP_SOCKETS'], [], libprotocol_simple ],
   [ 'module-simple-protocol-unix', 'module-protocol-stub.c', [], ['-DUSE_PROTOCOL_SIMPLE', '-DUSE_UNIX_SOCKETS'], [], libprotocol_simple ],
   [ 'module-sine', 'module-sine.c' ],
@@ -62,9 +62,23 @@ all_modules = [
   [ 'module-virtual-sink', 'module-virtual-sink.c' ],
   [ 'module-virtual-source', 'module-virtual-source.c' ],
   [ 'module-volume-restore', 'module-volume-restore.c' ],
-#  [ 'module-waveout', 'module-waveout.c' ],
 ]
 
+if host_machine.system() == 'windows'
+  winmm_dep = meson.get_compiler('c').find_library('winmm')
+  ksuser_dep = meson.get_compiler('c').find_library('ksuser')
+  all_modules += [
+    [ 'module-waveout', 'module-waveout.c', [], [], [winmm_dep, ksuser_dep] ],
+  ]
+endif
+
+if host_machine.system() != 'windows'
+  all_modules += [
+    [ 'module-rtp-recv', 'rtp/module-rtp-recv.c', [], [], [], librtp ],
+    [ 'module-rtp-send', 'rtp/module-rtp-send.c' , [], [], [], librtp ],
+  ]
+endif
+
 # Modules enabled by headers
 
 if cc.has_header('linux/input.h')
@@ -176,10 +190,13 @@ if lirc_dep.found()
 endif
 
 if openssl_dep.found()
-  subdir('raop')
-  all_modules += [
-    [ 'module-raop-sink', 'raop/module-raop-sink.c', [], [], [], libraop ],
-  ]
+  if host_machine.system() != 'windows'
+    subdir('raop')
+    all_modules += [
+      [ 'module-raop-sink', 'raop/module-raop-sink.c', [], [], [], libraop ],
+    ]
+  endif
+
   if avahi_dep.found()
     all_modules += [
       [ 'module-raop-discover', 'raop/module-raop-discover.c', [], [], [avahi_dep], libavahi_wrap ],
@@ -289,7 +306,7 @@ foreach m : all_modules
     install : true,
     install_rpath : rpath_dirs,
     install_dir : modlibexecdir,
-    dependencies : [thread_dep, libpulse_dep, libpulsecommon_dep, libpulsecore_dep, libintl_dep] + extra_deps,
+    dependencies : [thread_dep, libpulse_dep, libpulsecommon_dep, libpulsecore_dep, libintl_dep, platform_dep, platform_socket_dep] + extra_deps,
     link_args : [nodelete_link_args, '-Wl,--no-undefined' ],
     link_with : extra_libs,
     name_prefix : '',
index abc1e79..8341bfc 100644 (file)
@@ -83,7 +83,7 @@ libpulse = shared_library('pulse',
   link_args : [nodelete_link_args, versioning_link_args],
   install : true,
   install_rpath : privlibdir,
-  dependencies : [libm_dep, thread_dep, libpulsecommon_dep, dbus_dep, dl_dep, iconv_dep, libintl_dep],
+  dependencies : [libm_dep, thread_dep, libpulsecommon_dep, dbus_dep, dl_dep, iconv_dep, libintl_dep, platform_dep, platform_socket_dep],
   implicit_include_directories : false)
 
 libpulse_dep = declare_dependency(link_with: libpulse)
index 5f78be0..e8ce293 100644 (file)
@@ -182,11 +182,13 @@ libpulsecore_simd = simd.check('libpulsecore_simd',
 libpulsecore_simd_lib = libpulsecore_simd[0]
 cdata.merge_from(libpulsecore_simd[1])
 
-# FIXME: Implement Windows support
-#'mutex-win32.c',
-#'poll-win32.c',
-#'semaphore-win32.c',
-#'thread-win32.c',
+if host_machine.system() == 'windows'
+  libpulsecore_sources += ['mutex-win32.c',
+    'poll-win32.c',
+    'semaphore-win32.c',
+    'thread-win32.c',
+  ]
+endif
 
 libpulsecore = shared_library('pulsecore-' + pa_version_major_minor,
   libpulsecore_sources, libpulsecore_headers,
@@ -198,7 +200,7 @@ libpulsecore = shared_library('pulsecore-' + pa_version_major_minor,
   install_rpath : privlibdir,
   install_dir : privlibdir,
   link_with : libpulsecore_simd_lib,
-  dependencies : [libm_dep, libpulsecommon_dep, ltdl_dep, shm_dep, sndfile_dep, database_dep, dbus_dep, libatomic_ops_dep, orc_dep, samplerate_dep, soxr_dep, speex_dep, x11_dep, libintl_dep],
+  dependencies : [libm_dep, libpulsecommon_dep, ltdl_dep, shm_dep, sndfile_dep, database_dep, dbus_dep, libatomic_ops_dep, orc_dep, samplerate_dep, soxr_dep, speex_dep, x11_dep, libintl_dep, platform_dep, platform_socket_dep,],
   implicit_include_directories : false)
 
 libpulsecore_dep = declare_dependency(link_with: libpulsecore)
index a070198..f40eaff 100644 (file)
@@ -19,12 +19,14 @@ executable('pacat',
   c_args : pa_c_args,
 )
 
-foreach alias : pacat_aliases
-  # FIXME How to handle extension (.exe on windows)?
-  dst = join_paths(bindir, alias)
-  cmd = 'ln -fs @0@ $DESTDIR@1@'.format('pacat', dst)
-  meson.add_install_script('sh', '-c', cmd)
-endforeach
+# Windows doesn't support symbolic links.
+if host_machine.system() != 'windows'
+  foreach alias : pacat_aliases
+    dst = join_paths(bindir, alias)
+    cmd = 'ln -fs @0@ $DESTDIR@1@'.format('pacat', dst)
+    meson.add_install_script('sh', '-c', cmd)
+  endforeach
+endif
 
 pactl_sources = [
   'pactl.c',
@@ -40,33 +42,35 @@ executable('pactl',
   c_args : pa_c_args,
 )
 
-pasuspender_sources = [
-  'pasuspender.c',
-]
+if host_machine.system() != 'windows'
+  pasuspender_sources = [
+    'pasuspender.c',
+  ]
 
-executable('pasuspender',
-  pasuspender_sources,
-  install: true,
-  install_rpath : privlibdir,
-  include_directories : [configinc, topinc],
-  link_with : [libpulsecommon, libpulse],
-  dependencies: [libintl_dep],
-  c_args : pa_c_args,
-)
+  executable('pasuspender',
+    pasuspender_sources,
+    install: true,
+    install_rpath : privlibdir,
+    include_directories : [configinc, topinc],
+    link_with : [libpulsecommon, libpulse],
+    dependencies: [libintl_dep],
+    c_args : pa_c_args,
+  )
 
-pacmd_sources = [
-  'pacmd.c',
-]
+  pacmd_sources = [
+    'pacmd.c',
+  ]
 
-executable('pacmd',
-  pacmd_sources,
-  install: true,
-  install_rpath : privlibdir,
-  include_directories : [configinc, topinc],
-  link_with : [libpulsecommon, libpulse],
-  dependencies: [libintl_dep],
-  c_args : pa_c_args,
-)
+  executable('pacmd',
+    pacmd_sources,
+    install: true,
+    install_rpath : privlibdir,
+    include_directories : [configinc, topinc],
+    link_with : [libpulsecommon, libpulse],
+    dependencies: [libintl_dep],
+    c_args : pa_c_args,
+  )
+endif
 
 if x11_dep.found()
   pax11publish_sources = [