| 1 |
# Copyright (C) 2025 Rob Hall |
| 2 |
# SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
project('libdvdread', 'c', |
| 5 |
version: '7.1.1', |
| 6 |
meson_version: '>= 0.60.0', |
| 7 |
default_options: ['buildtype=debugoptimized', |
| 8 |
'c_std=c11', |
| 9 |
'default_library=both', |
| 10 |
'warning_level=2']) |
| 11 |
|
| 12 |
dvdread_src_root = meson.current_source_dir() |
| 13 |
dvdread_build_root = meson.current_build_dir() |
| 14 |
cc = meson.get_compiler('c') |
| 15 |
|
| 16 |
# Configuration data for config.h |
| 17 |
cdata = configuration_data() |
| 18 |
|
| 19 |
# Include directories |
| 20 |
dvdread_inc_dirs = include_directories('.', 'src', 'src/dvdread') |
| 21 |
if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' |
| 22 |
# extra POSIX headers not found in the Windows SDK |
| 23 |
dvdread_inc_dirs = [dvdread_inc_dirs, include_directories('msvc/include', 'msvc/contrib/dirent')] |
| 24 |
endif |
| 25 |
|
| 26 |
# The version number for the shared library |
| 27 |
dvdread_soname_version = '8.2.0' |
| 28 |
|
| 29 |
dvdread_version = meson.project_version() |
| 30 |
dvdread_version_split = dvdread_version.split('.') |
| 31 |
cdata.set_quoted('PACKAGE_VERSION', dvdread_version) |
| 32 |
|
| 33 |
# |
| 34 |
# OS/Compiler checks and defines |
| 35 |
# |
| 36 |
|
| 37 |
# Arguments in test_args will be used even on feature tests |
| 38 |
test_args = ['-D_DEFAULT_SOURCE', '-D_LARGEFILE64_SOURCE'] |
| 39 |
|
| 40 |
optional_arguments = [] |
| 41 |
optional_link_arguments = [] |
| 42 |
extra_dependencies = [] |
| 43 |
|
| 44 |
if host_machine.system() == 'sunos' |
| 45 |
test_args += '-D__EXTENSIONS__' |
| 46 |
endif |
| 47 |
|
| 48 |
# Header checks |
| 49 |
|
| 50 |
check_headers = [ |
| 51 |
'sys/param.h', |
| 52 |
'limits.h', |
| 53 |
'dirent.h', |
| 54 |
] |
| 55 |
|
| 56 |
foreach h : check_headers |
| 57 |
if cc.has_header(h, args: test_args) |
| 58 |
cdata.set('HAVE_' + h.underscorify().to_upper(), 1) |
| 59 |
endif |
| 60 |
endforeach |
| 61 |
|
| 62 |
cdata.set('UNUSED', cc.has_function_attribute('unused') ? '__attribute__((unused))' : '') |
| 63 |
|
| 64 |
if host_machine.endian() == 'big' |
| 65 |
cdata.set('WORDS_BIGENDIAN', 1) |
| 66 |
endif |
| 67 |
|
| 68 |
if host_machine.system() == 'windows' |
| 69 |
# dvdread_headers += files('msvc/contrib/win32_cs.h') |
| 70 |
if cc.has_function('gettimeofday', prefix: '#include <sys/time.h>', args: test_args) |
| 71 |
cdata.set('HAVE_GETTIMEOFDAY', 1) |
| 72 |
endif |
| 73 |
elif host_machine.system() == 'linux' |
| 74 |
if cc.has_function('getmntent_r', prefix: '#include <mntent.h>', args: test_args) |
| 75 |
cdata.set('HAVE_GETMNTENT_R', 1) |
| 76 |
endif |
| 77 |
endif |
| 78 |
|
| 79 |
if cc.has_function('strerror_r', prefix: '#include <string.h>', args: test_args) |
| 80 |
cdata.set('HAVE_STRERROR_R', 1) |
| 81 |
cdata.set('HAVE_DECL_STRERROR_R', 1) |
| 82 |
elif cc.has_function('strerror_s', prefix: '#include <string.h>', args: test_args) |
| 83 |
cdata.set('HAVE_STRERROR_S', 1) |
| 84 |
endif |
| 85 |
|
| 86 |
cdata.set10('HAVE_STATIC_ASSERT', cc.compiles('_Static_assert(1, "The impossible happened.");', name : '_Static_assert')) |
| 87 |
|
| 88 |
# External dependencies and libraries |
| 89 |
|
| 90 |
# libdvdcss is loaded dynamically if it is not found or requested |
| 91 |
libdl_dependency = [] |
| 92 |
libdvdcss_dependency = dependency('libdvdcss', |
| 93 |
version: '>= 1.2', method: 'pkg-config', required: get_option('libdvdcss')) |
| 94 |
if libdvdcss_dependency.found() |
| 95 |
cdata.set('HAVE_DVDCSS_DVDCSS_H', 1) |
| 96 |
elif host_machine.system() != 'windows' |
| 97 |
# Using builtin dlfcn (may require linking to libdl depending on the system) |
| 98 |
if not cc.has_function('dlopen', prefix: '#include <dlfcn.h>', args: test_args) |
| 99 |
libdl_dependency = cc.find_library('dl') |
| 100 |
endif |
| 101 |
cdata.set('HAVE_DLFCN_H', 1) |
| 102 |
endif |
| 103 |
|
| 104 |
if libdvdcss_dependency.found() |
| 105 |
if cc.has_header('dvdcss/dvdcpxm.h', dependencies: libdvdcss_dependency) |
| 106 |
cdata.set('HAVE_DVDCSS_DVDCPXM_H', 1) |
| 107 |
endif |
| 108 |
endif |
| 109 |
# Compiler flag tests |
| 110 |
|
| 111 |
# Compiler flags that should be set |
| 112 |
# But when the compiler does not supports them |
| 113 |
# it is not an error and silently tolerated |
| 114 |
|
| 115 |
if get_option('warning_level') in ['2', '3', 'everything'] or get_option('extra_checks') |
| 116 |
optional_arguments += [ |
| 117 |
'-Wsign-compare', |
| 118 |
'-Wundef', |
| 119 |
'-Wpointer-arith', |
| 120 |
'-Wvolatile-register-var', |
| 121 |
'-Wformat', |
| 122 |
'-Wformat-security', |
| 123 |
'-Wduplicated-branches', |
| 124 |
'-Wduplicated-cond', |
| 125 |
'-Wbad-function-cast', |
| 126 |
'-Wwrite-strings', |
| 127 |
'-Wmissing-prototypes', |
| 128 |
'-Winit-self', |
| 129 |
'-Wlogical-op', |
| 130 |
'-Wshadow=local', |
| 131 |
'-Wmultistatement-macros', |
| 132 |
] |
| 133 |
endif |
| 134 |
|
| 135 |
if get_option('extra_checks') |
| 136 |
optional_arguments += [ |
| 137 |
'-Werror-implicit-function-declaration', |
| 138 |
'-Werror=missing-field-initializers', |
| 139 |
'-Werror=format', |
| 140 |
'-Werror=return-mismatch', |
| 141 |
'-Werror=incompatible-pointer-types', |
| 142 |
'-Werror=restrict', |
| 143 |
'-Werror=int-conversion', |
| 144 |
'-Werror=implicit-int', |
| 145 |
'-Werror=declaration-missing-parameter-type', |
| 146 |
'-Werror=excess-initializers', |
| 147 |
'-Werror=unterminated-string-initialization', |
| 148 |
] |
| 149 |
endif |
| 150 |
|
| 151 |
add_project_arguments(cc.get_supported_arguments(optional_arguments), language: 'c') |
| 152 |
add_project_link_arguments(cc.get_supported_link_arguments(optional_link_arguments), language: 'c') |
| 153 |
add_project_arguments(test_args, language: 'c') |
| 154 |
|
| 155 |
# Generate config.h |
| 156 |
config_h_target = configure_file(output: 'config.h', configuration: cdata) |
| 157 |
|
| 158 |
install_data(['AUTHORS', 'COPYING', 'NEWS', 'README.md'], |
| 159 |
install_dir: get_option('datadir') / 'doc/libdvdread', |
| 160 |
install_tag: 'doc') |
| 161 |
|
| 162 |
if import('fs').is_file('.git/logs/HEAD') |
| 163 |
git_exe = find_program('git', required: false, disabler: true) |
| 164 |
custom_target('ChangeLog', output: 'ChangeLog', |
| 165 |
depend_files: '.git/logs/HEAD', |
| 166 |
command: ['git', 'log'], capture: true, |
| 167 |
install: true, |
| 168 |
install_dir: get_option('datadir') / 'doc/libdvdread', |
| 169 |
install_tag: 'doc') |
| 170 |
endif |
| 171 |
|
| 172 |
# Include subdir meson.build files |
| 173 |
# The order is important! |
| 174 |
|
| 175 |
subdir('src/dvdread') |
| 176 |
|
| 177 |
subdir('src') |
| 178 |
|
| 179 |
subdir('doc') |
| 180 |
|