|  | 
|  | 1 | +project( | 
|  | 2 | +  'libserialport', | 
|  | 3 | +  'c', | 
|  | 4 | +  version: '0.1.2', | 
|  | 5 | +  license: 'LGPL-3.0-or-later', | 
|  | 6 | +  meson_version: '>= 0.49.0', | 
|  | 7 | +) | 
|  | 8 | + | 
|  | 9 | +libserialport_includes = include_directories(['.']) | 
|  | 10 | + | 
|  | 11 | +libserialport_headers = files('libserialport.h') | 
|  | 12 | + | 
|  | 13 | +libserialport_sources = files('serialport.c', 'timing.c') | 
|  | 14 | + | 
|  | 15 | +libserialport_cflags = [] | 
|  | 16 | +libserialport_ldflags = [] | 
|  | 17 | + | 
|  | 18 | +cc = meson.get_compiler('c') | 
|  | 19 | + | 
|  | 20 | +# Check for visibility control | 
|  | 21 | +if cc.compiles( | 
|  | 22 | +  'void foo(void) __attribute__((visibility("hidden")));', | 
|  | 23 | +  name: 'visibility attribute check', | 
|  | 24 | +) | 
|  | 25 | +  sp_api = '__attribute__((visibility("default")))' | 
|  | 26 | +  sp_priv = '__attribute__((visibility("hidden")))' | 
|  | 27 | +elif cc.get_id() == 'msvc' or cc.compiles( | 
|  | 28 | +  '__declspec(dllexport) void foo(void);', | 
|  | 29 | +  name: 'declspec check', | 
|  | 30 | +) | 
|  | 31 | +  sp_api = '__declspec(dllexport)' | 
|  | 32 | +  sp_priv = '' | 
|  | 33 | +else | 
|  | 34 | +  sp_api = '' | 
|  | 35 | +  sp_priv = '' | 
|  | 36 | +endif | 
|  | 37 | + | 
|  | 38 | +cdata = configuration_data( | 
|  | 39 | +  { | 
|  | 40 | +    'SP_API': sp_api, | 
|  | 41 | +    'SP_PRIV': sp_priv, | 
|  | 42 | +  }, | 
|  | 43 | +) | 
|  | 44 | + | 
|  | 45 | +# Function checks | 
|  | 46 | +cdata.set('HAVE_REALPATH', cc.has_function('realpath')) | 
|  | 47 | +cdata.set('HAVE_FLOCK', cc.has_function('flock')) | 
|  | 48 | +cdata.set('HAVE_CLOCK_GETTIME', cc.has_function('clock_gettime')) | 
|  | 49 | + | 
|  | 50 | +# Header checks | 
|  | 51 | +cdata.set('HAVE_SYS_FILE_H', cc.has_header('sys/file.h')) | 
|  | 52 | + | 
|  | 53 | +# Type checks | 
|  | 54 | +cdata.set( | 
|  | 55 | +  'HAVE_STRUCT_TERMIOS2', | 
|  | 56 | +  cc.has_type( | 
|  | 57 | +    'struct termios2', | 
|  | 58 | +    prefix: '#include <linux/termios.h>', | 
|  | 59 | +  ), | 
|  | 60 | +) | 
|  | 61 | +cdata.set( | 
|  | 62 | +  'HAVE_STRUCT_SERIAL_STRUCT', | 
|  | 63 | +  cc.has_type( | 
|  | 64 | +    'struct serial_struct', | 
|  | 65 | +    prefix: '#include <linux/serial.h>', | 
|  | 66 | +  ), | 
|  | 67 | +) | 
|  | 68 | +cdata.set( | 
|  | 69 | +  'HAVE_STRUCT_TERMIOX', | 
|  | 70 | +  cc.has_type( | 
|  | 71 | +    'struct termiox', | 
|  | 72 | +    prefix: '#include <linux/termios.h>', | 
|  | 73 | +  ), | 
|  | 74 | +) | 
|  | 75 | + | 
|  | 76 | +# Member checks | 
|  | 77 | +cdata.set( | 
|  | 78 | +  'HAVE_STRUCT_TERMIOS_C_ISPEED', | 
|  | 79 | +  cc.has_member( | 
|  | 80 | +    'struct termios', | 
|  | 81 | +    'c_ispeed', | 
|  | 82 | +    prefix: '#include <linux/termios.h>', | 
|  | 83 | +  ), | 
|  | 84 | +) | 
|  | 85 | +cdata.set( | 
|  | 86 | +  'HAVE_STRUCT_TERMIOS_C_OSPEED', | 
|  | 87 | +  cc.has_member( | 
|  | 88 | +    'struct termios', | 
|  | 89 | +    'c_ospeed', | 
|  | 90 | +    prefix: '#include <linux/termios.h>', | 
|  | 91 | +  ), | 
|  | 92 | +) | 
|  | 93 | +cdata.set( | 
|  | 94 | +  'HAVE_STRUCT_TERMIOS2_C_ISPEED', | 
|  | 95 | +  cc.has_member( | 
|  | 96 | +    'struct termios2', | 
|  | 97 | +    'c_ispeed', | 
|  | 98 | +    prefix: '#include <linux/termios.h>', | 
|  | 99 | +  ), | 
|  | 100 | +) | 
|  | 101 | +cdata.set( | 
|  | 102 | +  'HAVE_STRUCT_TERMIOS2_C_OSPEED', | 
|  | 103 | +  cc.has_member( | 
|  | 104 | +    'struct termios2', | 
|  | 105 | +    'c_ospeed', | 
|  | 106 | +    prefix: '#include <linux/termios.h>', | 
|  | 107 | +  ), | 
|  | 108 | +) | 
|  | 109 | + | 
|  | 110 | +# Header symbol check | 
|  | 111 | +cdata.set10( | 
|  | 112 | +  'HAVE_DECL_BOTHER', | 
|  | 113 | +  cc.has_header_symbol('linux/termios.h', 'BOTHER'), | 
|  | 114 | +) | 
|  | 115 | + | 
|  | 116 | +# Derived defines | 
|  | 117 | +if cdata.get('HAVE_STRUCT_TERMIOS_C_ISPEED') and cdata.get( | 
|  | 118 | +  'HAVE_STRUCT_TERMIOS_C_OSPEED', | 
|  | 119 | +) | 
|  | 120 | +  cdata.set('HAVE_TERMIOS_SPEED', 1) | 
|  | 121 | +endif | 
|  | 122 | +if cdata.get('HAVE_STRUCT_TERMIOS2_C_ISPEED') and cdata.get( | 
|  | 123 | +  'HAVE_STRUCT_TERMIOS2_C_OSPEED', | 
|  | 124 | +) | 
|  | 125 | +  cdata.set('HAVE_TERMIOS2_SPEED', 1) | 
|  | 126 | +endif | 
|  | 127 | + | 
|  | 128 | +if host_machine.system() == 'linux' | 
|  | 129 | +  libserialport_sources += files('linux.c', 'linux_termios.c') | 
|  | 130 | +  libserialport_cflags += '-DLIBSERIALPORT_ATBUILD' | 
|  | 131 | +elif host_machine.system() == 'windows' | 
|  | 132 | +  libserialport_sources += files('windows.c') | 
|  | 133 | +  libserialport_cflags += '-DLIBSERIALPORT_MSBUILD' | 
|  | 134 | +  libserialport_ldflags += '-lsetupapi' | 
|  | 135 | +elif host_machine.system() == 'darwin' | 
|  | 136 | +  libserialport_sources += files('macosx.c') | 
|  | 137 | +  libserialport_cflags += '-DLIBSERIALPORT_ATBUILD' | 
|  | 138 | +  libserialport_ldflags += [ | 
|  | 139 | +    '-framework', | 
|  | 140 | +    'IOKit', | 
|  | 141 | +    '-framework', | 
|  | 142 | +    'CoreFoundation', | 
|  | 143 | +  ] | 
|  | 144 | +elif host_machine.system() == 'freebsd' | 
|  | 145 | +  libserialport_sources += files('freebsd.c') | 
|  | 146 | +  libserialport_cflags += '-DLIBSERIALPORT_ATBUILD' | 
|  | 147 | +endif | 
|  | 148 | + | 
|  | 149 | +configure_file( | 
|  | 150 | +  output: 'config.h', | 
|  | 151 | +  configuration: cdata, | 
|  | 152 | +) | 
|  | 153 | + | 
|  | 154 | +libserialport_lib = library( | 
|  | 155 | +  'libserialport', | 
|  | 156 | +  libserialport_sources, | 
|  | 157 | +  c_args: libserialport_cflags, | 
|  | 158 | +  link_args: libserialport_ldflags, | 
|  | 159 | +  include_directories: libserialport_includes, | 
|  | 160 | +  version: '0.1.0', | 
|  | 161 | +  install: true, | 
|  | 162 | +) | 
|  | 163 | + | 
|  | 164 | +pkg = import('pkgconfig') | 
|  | 165 | +pkg.generate(libserialport_lib) | 
|  | 166 | + | 
|  | 167 | +install_headers(libserialport_headers) | 
|  | 168 | + | 
|  | 169 | +libserialport_dep = declare_dependency( | 
|  | 170 | +  include_directories: libserialport_includes, | 
|  | 171 | +  link_with: libserialport_lib, | 
|  | 172 | +) | 
|  | 173 | + | 
|  | 174 | +if meson.version().version_compare('>=0.54.0') | 
|  | 175 | +  meson.override_dependency('libserialport', libserialport_dep) | 
|  | 176 | +endif | 
0 commit comments