-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: meson build #120
base: master
Are you sure you want to change the base?
WIP: meson build #120
Changes from all commits
63e93f5
fc52493
72f696e
8f0731e
7056bbc
d823821
3f29010
070a65d
132cde1
fc9655e
0ffc20d
aca1aa2
ae73fa4
0f2859d
96e2d96
f51a11f
be2a23a
8a7b9b1
a83a638
859f821
fb6b458
24ad34e
efcb02e
d45e486
7105a71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,362 @@ | ||
# SPDX-License-Identifier: 0BSD | ||
# Author: Vincent Torri | ||
|
||
project( | ||
'xz', | ||
'c', | ||
version: '5.6.99', | ||
license: '0BSD', | ||
license_files: [ | ||
'COPYING', | ||
'COPYING.0BSD', | ||
'COPYING.GPLv2', | ||
'COPYING.GPLv3', | ||
'COPYING.LGPLv2.1' | ||
], | ||
default_options: [ | ||
'b_ndebug=if-release', | ||
'c_std=c11', | ||
'warning_level=3', | ||
], | ||
meson_version: '>= 1.1.0', | ||
) | ||
|
||
v_array = meson.project_version().split('.') | ||
v_maj = v_array[0] | ||
|
||
# config.h | ||
|
||
config_dir = [include_directories('.')] | ||
|
||
config_h = configuration_data() | ||
config_h.set_quoted('PACKAGE', 'xz') | ||
config_h.set_quoted('PACKAGE_BUGREPORT', '[email protected]') | ||
config_h.set_quoted('PACKAGE_NAME', meson.project_name()) | ||
config_h.set_quoted('PACKAGE_URL', 'https://tukaani.org/xz/') | ||
|
||
# host | ||
|
||
config_h.set('WORDS_BIGENDIAN', | ||
host_machine.endian() == 'big', | ||
description: 'Defined if the processor stores words with the most significant byte first.' | ||
) | ||
vtorri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
host_os = host_machine.system() | ||
|
||
cygwin = 'cygwin' | ||
windows = 'windows' | ||
linux = 'linux' | ||
sunos = 'sunos' | ||
asm_os = [ 'linux', 'dragonfly', 'freebsd', 'netbsd', 'openbsd', 'windows', 'cygwin' ] | ||
sys_cygwin = cygwin.contains(host_os) | ||
sys_windows = windows.contains(host_os) | ||
sys_sunos = sunos.contains(host_os) | ||
|
||
COND_W32 = sys_cygwin or sys_windows | ||
|
||
# binaries | ||
cc = meson.get_compiler('c') | ||
|
||
# try mimic AC_USE_SYSTEM_EXTENSIONS | ||
add_project_arguments('-D_GNU_SOURCE', language: 'c') | ||
add_project_arguments('-D__EXTENSIONS__', language: 'c') | ||
if host_machine.system() == 'sunos' | ||
add_project_arguments('-D_POSIX_PTHREAD_SEMANTICS', language: 'c') | ||
else | ||
add_project_arguments('-D_TANDEM_SOURCE', language: 'c') | ||
add_project_arguments('-D_ALL_SOURCE', language: 'c') | ||
endif | ||
|
||
# unconditionally define macro for C99 headers | ||
add_project_arguments('-DHAVE_INTTYPES_H', language: 'c') | ||
add_project_arguments('-DHAVE_STDBOOL_H', language: 'c') | ||
add_project_arguments('-DHAVE_STDINT_H', language: 'c') | ||
# unconditionally define macro for C99 functions | ||
add_project_arguments('-DHAVE_MBRTOWC', language: 'c') | ||
|
||
lzma_c_args = [] | ||
cflags_try = [] | ||
|
||
if cc.get_argument_syntax() == 'gcc' | ||
cflags_try += [ | ||
'-Wvla', | ||
'-Wformat=2', | ||
'-Winit-self', | ||
'-Wmissing-include-dirs', | ||
'-Wshift-overflow=2', | ||
'-Wstrict-overflow=3', | ||
'-Walloc-zero', | ||
'-Wduplicated-cond', | ||
'-Wfloat-equal', | ||
'-Wundef', | ||
'-Wshadow', | ||
'-Wpointer-arith', | ||
'-Wbad-function-cast', | ||
'-Wwrite-strings', | ||
'-Wdate-time', | ||
'-Wsign-conversion', | ||
'-Wfloat-conversion', | ||
'-Wlogical-op', | ||
'-Waggregate-return', | ||
'-Wstrict-prototypes', | ||
'-Wold-style-definition', | ||
'-Wmissing-prototypes', | ||
'-Wmissing-declarations', | ||
'-Wredundant-decls', | ||
# | ||
'-Wc99-compat', | ||
'-Wc11-extensions', | ||
'-Wc2x-compat', | ||
'-Wc2x-extensions', | ||
'-Wpre-c2x-compat', | ||
'-Warray-bounds-pointer-arithmetic', | ||
'-Wassign-enum', | ||
'-Wconditional-uninitialized', | ||
'-Wdocumentation', | ||
'-Wduplicate-enum', | ||
'-Wempty-translation-unit', | ||
'-Wflexible-array-extensions', | ||
'-Wmissing-variable-declarations', | ||
'-Wnewline-eof', | ||
'-Wshift-sign-overflow', | ||
'-Wstring-conversion', | ||
] | ||
|
||
lzma_c_args += cc.get_supported_arguments(cflags_try) | ||
endif | ||
|
||
config_h.set10('HAVE_VISIBILITY', | ||
cc.has_function_attribute('visibility'), | ||
description: 'Defined to 1 if the compiler supports simple visibility declarations.' | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eli-schwartz: Elsewhere there is Gnulib's visibility.m4 checks that both attribute and compiler option are supported using It's also a bit unfortunate if visibility support requires an option in both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meson internally handles -Werror for exactly that reason: Most projects I have seen, actually check for Certain versions of... SunPro, if I recall correctly, are the only commonly known compiler that handles visibility but isn't either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Great! Documenting it could be nice to give more confidence. Or perhaps it's that coming from other build systems one is constantly suspecting that corner cases aren't handled well enough, sorry.
liblzma checks in this order in the C code:
My note in b0d1422 says that SunPro (or whatever its name is this year) supports the GNU C attribute since 2007. At least modern releases support the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
results in a warning with GCC 14.1.1 on x86-64 GNU/Linux:
But There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, sorry, I'm wrong. I just fell into the exact trap of |
||
|
||
|
||
config_h.set('HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR', | ||
cc.has_function_attribute('constructor'), | ||
description: 'Defined if __attribute__((__constructor__)) is supported for functions.', | ||
) | ||
|
||
time_fcts = [ | ||
[ 'futimens', [ '#include <sys/stat.h>' ] ], | ||
[ 'futimes', [ '#include <sys/time.h>' ] ], | ||
[ 'futimesat', [ '#include <fcntl.h>', '#include <sys/time.h>' ] ], | ||
[ 'utimes', [ '#include <sys/time.h>' ] ], | ||
[ '_futime', [ '#include <sys/utime.h>' ] ], | ||
[ 'utime', [ '#include <sys/types.h>', '#include <utime.h>' ] ], | ||
] | ||
|
||
foreach f : time_fcts | ||
res = cc.has_function(f[0], prefix : f[1]) | ||
config_h.set('HAVE_' + f[0].to_upper(), | ||
res, | ||
description: 'Defined if the ' + f[0] + '() function is available.' | ||
) | ||
if res | ||
break | ||
endif | ||
endforeach | ||
|
||
config_h.set('HAVE_POSIX_FADVISE', | ||
cc.has_function('posix_fadvise', prefix : '#include <fcntl.h>'), | ||
description: 'Defined if the posix_fadvise() function is available.' | ||
) | ||
|
||
### Filters | ||
|
||
## encoders | ||
encoder_msg = '' | ||
decoder_msg = '' | ||
|
||
simple_filters = [ | ||
'x86', | ||
'powerpc', | ||
'ia64', | ||
'arm', | ||
'armthumb', | ||
'arm64', | ||
'sparc', | ||
'riscv', | ||
] | ||
|
||
# FIXME foreach i in array; set_variable(f'have_@i@', true) endforeach | ||
|
||
foreach f : get_option('encoders') | ||
config_h.set('HAVE_ENCODER_' + f.underscorify().to_upper(), | ||
true, | ||
description: 'Defined if ' + f + ' encoder is enabled.' | ||
) | ||
encoder_msg += f + ' ' | ||
endforeach | ||
|
||
foreach f : get_option('decoders') | ||
config_h.set('HAVE_DECODER_' + f.underscorify().to_upper(), | ||
true, | ||
description: 'Defined if ' + f + ' decoder is enabled.' | ||
) | ||
decoder_msg += f + ' ' | ||
endforeach | ||
|
||
have_encoder_simple_filters = false | ||
have_decoder_simple_filters = false | ||
foreach f : simple_filters | ||
if f in get_option('encoders') | ||
have_encoder_simple_filters = true | ||
endif | ||
if f in get_option('decoders') | ||
have_decoder_simple_filters = true | ||
endif | ||
endforeach | ||
|
||
if ('lzma2' in get_option('encoders') and not ('lzma1' in get_option('encoders'))) or('lzma2' in get_option('decoders') and not ('lzma1' in get_option('decoders'))) | ||
error('LZMA2 requires that LZMA1 is also enabled') | ||
endif | ||
|
||
if get_option('encoders').length() > 0 | ||
config_h.set('HAVE_ENCODERS', | ||
true, | ||
description: 'Defined if at least one encoder has been enabled.' | ||
) | ||
endif | ||
|
||
if get_option('decoders').length() > 0 | ||
config_h.set('HAVE_DECODERS', | ||
true, | ||
description: 'Defined if at least one decoder has been enabled.' | ||
) | ||
endif | ||
|
||
### Match finders | ||
|
||
match_finder_msg = '' | ||
|
||
if 'lzma1' in get_option('encoders') or 'lzma2' in get_option('encoders') | ||
if get_option('match-finders').length() == 0 | ||
error('at least one match finder is required for an LZ-based encoder') | ||
endif | ||
|
||
foreach m : get_option('match-finders') | ||
config_h.set('HAVE_MF_' + m.underscorify().to_upper(), | ||
true, | ||
description: 'Defined to enable ' + m + ' match finder.' | ||
) | ||
match_finder_msg += m + ' ' | ||
endforeach | ||
endif | ||
|
||
### Integrity checks | ||
|
||
check_msg = '' | ||
|
||
if not ('crc32' in get_option('checks')) | ||
error('For now, the CRC32 check must always be enabled') | ||
endif | ||
|
||
foreach c : get_option('checks') | ||
config_h.set('HAVE_CHECK_' + c.underscorify().to_upper(), | ||
true, | ||
description: 'Define to 1 if ' + c + ' integrity check is enabled.' | ||
) | ||
check_msg += c + ' ' | ||
endforeach | ||
|
||
### microLZMA | ||
|
||
if get_option('microlzma') == true | ||
vtorri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
endif | ||
|
||
### .lz (lzip) format support | ||
|
||
have_lzip = false | ||
if not ('lzma1' in get_option('encoders')) | ||
lzip_msg = 'no (LZMA1 disabled)' | ||
elif get_option('lzip-decoder') | ||
lzip_msg = 'yes' | ||
have_lzip = true | ||
config_h.set('HAVE_LZIP_DECODER', | ||
true, | ||
description: 'Defined if .lz (lzip) decompression support is enabled.' | ||
) | ||
else | ||
lzip_msg = 'no' | ||
endif | ||
|
||
### assembler optimizations | ||
|
||
have_assembler_x86 = false | ||
if get_option('assembler') | ||
if host_os in asm_os and host_machine.cpu_family() == 'x86' | ||
have_assembler_x86 = true | ||
endif | ||
endif | ||
|
||
### size optimization | ||
|
||
config_h.set('HAVE_SMALL', | ||
get_option('small'), | ||
description: 'Defined if optimizing for size.' | ||
) | ||
|
||
### threading | ||
|
||
have_threads = false | ||
|
||
if get_option('threads') == true | ||
if sys_windows == true | ||
config_h.set('MYTHREAD_WIN95', | ||
host_machine.cpu_family() == 'x86', | ||
description: 'Defined when using Windows 95 (and thus XP) compatible threads. This avoids use of features that were added in Windows Vista.' | ||
) | ||
config_h.set('MYTHREAD_VISTA', | ||
host_machine.cpu_family() != 'x86', | ||
description: 'Defined when using Windows Vista compatible threads. This uses features that are not available on Windows XP.' | ||
) | ||
have_threads = true | ||
else | ||
# FIXME: pthread detection should be fixed | ||
pthread_dep = dependency('threads', required : false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is incorrect usage.
pthreads have to be detected separately, like with CC: @eli-schwartz There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At glance this sounds odd. XZ Utils can use pthreads and Windows threads. C11 threads are available on some platforms too but XZ Utils doesn't support those for now (they don't seem to add any practical value for now). MinGW-w64 supports pthreads and Windows threads, the latter being preferred. Very recent MSVC supports C11 threads in addition to Windows threads. When using MinGW-w64 and Windows threads, one specifically wants to ensure that the pthreads flags are not used. Thus the Autotools and CMake builds don't add any threading related options to the build when using Windows threads. Autotools build assumes that pthreads is available on non-Windows, thus the build fails, for example, on MINIX 3 where pthreads isn't available. One has to manually use |
||
config_h.set('MYTHREAD_POSIX', | ||
pthread_dep.found(), | ||
description: 'Defined when using POSIX threads (pthreads).' | ||
) | ||
have_threads = pthread_dep.found() | ||
endif | ||
endif | ||
|
||
|
||
### subdirectories | ||
|
||
subdir('src') | ||
subdir('tests') | ||
|
||
configure_file(output: 'config.h', configuration: config_h) | ||
|
||
# summary | ||
|
||
summary( | ||
{ | ||
'OS': host_os, | ||
'endianness': host_machine.endian(), | ||
'assembler': get_option('assembler').to_string('yes', 'no'), | ||
'encoders': encoder_msg, | ||
'decoders': decoder_msg, | ||
'match finders': match_finder_msg, | ||
'checks': check_msg, | ||
'external sha256': get_option('external-sha256').to_string('yes', 'no'), | ||
'microLZMA': get_option('microlzma').to_string('yes', 'no'), | ||
'lzip decompression': lzip_msg, | ||
'small': get_option('small').to_string('yes', 'no'), | ||
'threads': have_threads.to_string('yes', 'no'), | ||
'fast unaligned access': fast_unaligned_access.to_string('yes', 'no'), | ||
'unsafe type punning': get_option('unsafe-type-punning').to_string('yes', 'no') | ||
}, | ||
section: 'Configuration Options Summary:', | ||
) | ||
|
||
summary( | ||
{ | ||
'xzdec': get_option('xzdec').to_string('yes', 'no'), | ||
'lzmadec': get_option('lzmadec').to_string('yes', 'no'), | ||
'xz': get_option('xz').to_string('yes', 'no') + ((get_option('assume-ram') > 0) ? ' (' + get_option('assume-ram').to_string() + ' MiB)' : ''), | ||
}, | ||
section: 'Tools', | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Meson 1.3.0 it's possible to have a list. For example,
c_std=gnu99,c11,c99
would prefergnu99
but then tryc11
beforec99
. I don't know if MSVC counts as C99 as it officially supports only C11, I think, perhaps due to C99 having a few mandatory features that are optional in C11.GNU extensions are used when they are available, thus
gnu99
can make sense.gnu99
vs.c99
also affect the predefined macros. On my system with GCC 13.2.1,-std=c99
defines__STRICT_ANSI__
while-std=gnu99
doesn't. It can then affect the behavior of system headers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that some project leaders do not like to use the latest version of meson. If there is no problem for you to use meson >= 1.3, then ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't know right now which Meson (or muon) version is OK to require. I just get an impression that a single value doesn't work everywhere (if MSVC needs C11 mode). I haven't checked in detail how the
c_std
option in Meson exactly works.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/mesonbuild/meson/blob/master/mesonbuild/compilers/c.py#L453-L485
For MSVC, meson ignores c99 and passes /std:XXX when the mode is c11 or c17. The difference is really about whether you want to opt into GNU extensions (which MSVC obviously doesn't support). Doing that might require bumping the minimum meson requirement, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vaguely remember that, a very long time ago, using
gnu99
was better in practice when the intention was to use non-standard extensions (language or library) when they are available.If
gnu99
doesn't put MSVC into C11/C17 mode then MSVC needs some otherc_std
option. MSVC is a special case in so many ways that handling it specially here could be OK too, assuming it's easy to do.Using
gnu11
with GCC and Clang and strict C11 with compilers that don't support GNU extensions could be OK too. But if compiler doesn't support C11 then it should fallback to C99 if that is supported.The list method that requires Meson >= 1.3.0 would make all this trivially easy. muon says it's currently at meson compat version 1.1.
So, oh well, maybe try
gnu11
for now if that helps getting MSVC to C11 mode. This is a small detail in the big picture and can be worried more a little later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what I did for muon with cl.exe compiler: I just pass the required standard. So, no problem with c11. (there will be a message from the compiler if the standard is not correct)
I maybe should pass the standard if it is only c11 or c17 like meson. I'll ask the author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Meson docs give an impression that
c_std=gnu11
would fallback to C11 with MSVC but this might become deprecated and eventually an error. So one would need to list the possible standards.I think requiring new enough Meson and using
c_std=gnu99,c11,c99
orc_std=gnu11,gnu99,c11,c99
is fine for now. It might not be muon compatible right now but I would expect this kind of feature to get implemented at some point in muon too. Very probably the first versions of Meson support won't be as portable as the Autotools build is and it doesn't need to be. Progress happens one step at a time.