Skip to content

Commit

Permalink
Merge pull request #350 from openzim/use-libmagic-pkgconfig
Browse files Browse the repository at this point in the history
Meson using libmagic pkgconfig
  • Loading branch information
kelson42 authored May 21, 2023
2 parents 3c48df6 + 328e2ca commit 6c1d2f5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:
- win32_dyn
include:
- target: native_static
image_variant: bionic
image_variant: focal
lib_postfix: '/x86_64-linux-gnu'
- target: native_dyn
image_variant: bionic
image_variant: focal
lib_postfix: '/x86_64-linux-gnu'
- target: win32_static
image_variant: f35
Expand Down
64 changes: 37 additions & 27 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,50 @@ if with_writer
thread_dep = dependency('threads')
zlib_dep = dependency('zlib', static:static_linkage)
gumbo_dep = dependency('gumbo', static:static_linkage)
magic_dep = dependency('libmagic', static:static_linkage, required:false)

magic_include_path = ''
magic_prefix_install = get_option('magic-install-prefix')
if magic_prefix_install == ''
if compiler.has_header('magic.h')
if find_library_in_compiler
magic_lib = compiler.find_library('magic')
# libmagic.pc has been introduced in version 5.39 of
# File. Unfortunately Ubuntu 20.04 (Focal) still uses version
# 5.38. Therefore we have to keep this special handling. As
# soon as Ubuntu 20.04 will move forward we will be able to remove
# this custom code. Check https://launchpad.net/ubuntu/+source/file
# and https://bugs.launchpad.net/ubuntu/+source/file/+bug/1951594
if not magic_dep.found()
magic_include_path = ''
magic_prefix_install = get_option('magic-install-prefix')
if magic_prefix_install == ''
if compiler.has_header('magic.h')
if find_library_in_compiler
magic_lib = compiler.find_library('magic')
else
magic_lib = find_library('magic')
endif
magic_dep = declare_dependency(link_args:['-lmagic'])
else
magic_lib = find_library('magic')
error('magic.h not found')
endif
magic_dep = declare_dependency(link_args:['-lmagic'])
else
error('magic.h not found')
endif
else
if not find_library_in_compiler
error('For custom magic_prefix_install you need a meson version >=0.31.0')
endif
magic_include_path = magic_prefix_install + '/include'
magic_include_args = ['-I'+magic_include_path]
if compiler.has_header('magic.h', args:magic_include_args)
magic_include_dir = include_directories(magic_include_path, is_system:true)
magic_lib_path = join_paths(magic_prefix_install, get_option('libdir'))
magic_lib = compiler.find_library('magic', dirs:magic_lib_path, required:false)
if not magic_lib.found()
magic_lib_path = join_paths(magic_prefix_install, 'lib')
magic_lib = compiler.find_library('magic', dirs:magic_lib_path)
if not find_library_in_compiler
error('For custom magic_prefix_install you need a meson version >=0.31.0')
endif
magic_include_path = magic_prefix_install + '/include'
magic_include_args = ['-I'+magic_include_path]
if compiler.has_header('magic.h', args:magic_include_args)
magic_include_dir = include_directories(magic_include_path, is_system:true)
magic_lib_path = join_paths(magic_prefix_install, get_option('libdir'))
magic_lib = compiler.find_library('magic', dirs:magic_lib_path, required:false)
if not magic_lib.found()
magic_lib_path = join_paths(magic_prefix_install, 'lib')
magic_lib = compiler.find_library('magic', dirs:magic_lib_path)
endif
magic_link_args = ['-L'+magic_lib_path, '-lmagic']
magic_dep = declare_dependency(include_directories:magic_include_dir, link_args:magic_link_args)
else
error('magic.h not found')
endif
magic_link_args = ['-L'+magic_lib_path, '-lmagic']
magic_dep = declare_dependency(include_directories:magic_include_dir, link_args:magic_link_args)
else
error('magic.h not found')
endif
endif

endif

subdir('src')
Expand Down

0 comments on commit 6c1d2f5

Please sign in to comment.