Skip to content

Commit

Permalink
macOS: more generic search for Homebrew Liquid-dsp
Browse files Browse the repository at this point in the history
Now we query homebrew itself as to where liquid might be installed.
  • Loading branch information
windytan committed Jul 24, 2024
1 parent 59a22f6 commit 0fdb4de
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 43 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# redsea changelog

## HEAD

* Fixes:
* macOS: ask Homebrew about liquid-dsp installation path instead of hardcoding it

## 1.0.1

* Fixes:
Expand Down
90 changes: 47 additions & 43 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
project('redsea', 'cpp', default_options : ['warning_level=3', 'buildtype=release', 'optimization=3'],
version: '1.0.1')
project(
'redsea',
'cpp',
default_options: ['warning_level=3', 'buildtype=release', 'optimization=3'],
version: '1.0.2-SNAPSHOT',
)

# Store version number to be compiled in
conf = configuration_data()
conf.set_quoted('VERSION', meson.project_version())
configure_file(output : 'config.h',
configuration : conf)

configure_file(output: 'config.h', configuration: conf)

########################
### Compiler options ###
########################


cc = meson.get_compiler('cpp')
add_project_arguments(cc.get_supported_arguments([
'-Wno-unknown-pragmas']), language: 'cpp')
add_project_arguments(cc.get_supported_arguments(['-Wno-unknown-pragmas']), language: 'cpp')

# We want to use M_PI on Windows
if build_machine.system() == 'windows'
add_project_arguments('-D_USE_MATH_DEFINES=1', language : 'cpp')
add_project_arguments('-D_USE_MATH_DEFINES=1', language: 'cpp')
endif

# Explicit GNU extensions on Cygwin
if build_machine.system() == 'cygwin'
add_project_arguments('-std=gnu++14', language : 'cpp')
add_project_arguments('-std=gnu++14', language: 'cpp')
else
add_project_arguments('-std=c++14', language : 'cpp')
add_project_arguments('-std=c++14', language: 'cpp')
endif


####################
### Dependencies ###
####################


# Find libsndfile
sndfile = dependency('sndfile')

# Find nlohmann's json
json = dependency('nlohmann_json', version : '>=3.9.0')
json = dependency('nlohmann_json', version: '>=3.9.0')

# Find iconv; may require -liconv
foreach linker_args : [ ['-liconv'], [] ]
if cc.links('''
foreach linker_args : [['-liconv'], []]
if cc.links(
'''
#include <iconv.h>
int main() {
iconv_open("UTF-8", "ISO-8859-1");
}''', args: linker_args)
}''',
args: linker_args,
)
iconv = declare_dependency(link_args: linker_args)
break
endif
Expand All @@ -58,36 +59,33 @@ if not iconv.found()
endif

# Find liquid-dsp
if build_machine.system() == 'darwin'
liquid = cc.find_library('liquid', required: false)
# macOS: The above mechanism sometimes fails, so let's look deeper
if not liquid.found() and build_machine.system() == 'darwin'
fs = import('fs')
# Homebrew system
if fs.is_dir('/opt/homebrew/lib')
liquid_lib = cc.find_library('liquid',
dirs : ['/opt/homebrew/lib'])
liquid_inc = include_directories('/opt/homebrew/include')
# MacPorts system
else
liquid_lib = cc.find_library('liquid',
dirs : ['/opt/local/lib'])
brew = find_program('brew', required: false)
if brew.found()
# Homebrew system
liquid_prefix = run_command(brew, '--prefix', 'liquid-dsp', check: true).stdout().strip()
liquid_lib = cc.find_library('liquid', dirs: [liquid_prefix + '/lib'])
liquid_inc = include_directories(liquid_prefix + '/include')
liquid = declare_dependency(dependencies: liquid_lib, include_directories: liquid_inc)
elif fs.is_dir('/opt/local/lib')
# MacPorts system
liquid_lib = cc.find_library('liquid', dirs: ['/opt/local/lib'])
liquid_inc = include_directories('/opt/local/include')
liquid = declare_dependency(dependencies: liquid_lib, include_directories: liquid_inc)
endif
liquid = declare_dependency(dependencies : liquid_lib,
include_directories : liquid_inc)
else
liquid = cc.find_library('liquid')
endif
if cc.has_function('modemcf_create',
prefix : '#include <liquid/liquid.h>',
dependencies : liquid)
add_project_arguments('-DMODEM_IS_MODEMCF', language : 'cpp')
# API for modem/modemcf changed recently, but we can deal with either
if liquid.found() and cc.has_function('modemcf_create', prefix: '#include <liquid/liquid.h>', dependencies: liquid)
add_project_arguments('-DMODEM_IS_MODEMCF', language: 'cpp')
endif


############################
### Sources & Executable ###
############################


sources_no_main = [
'src/block_sync.cc',
'src/channel.cc',
Expand All @@ -101,12 +99,15 @@ sources_no_main = [
'src/tmc/csv.cc',
'src/tmc/tmc.cc',
'src/tmc/locationdb.cc',
'src/util.cc'
'src/util.cc',
]

executable('redsea', [sources_no_main, 'src/redsea.cc'], dependencies: [iconv, json, liquid, sndfile],
install: true)

executable(
'redsea',
[sources_no_main, 'src/redsea.cc'],
dependencies: [iconv, json, liquid, sndfile],
install: true,
)

##################
### Unit tests ###
Expand All @@ -115,7 +116,10 @@ executable('redsea', [sources_no_main, 'src/redsea.cc'], dependencies: [iconv, j
catch2 = dependency('catch2-with-main', required: false)

if catch2.found()
test_exec = executable('redsea-test', [sources_no_main, 'test/unit.cc'],
dependencies: [iconv, json, liquid, sndfile, catch2])
test_exec = executable(
'redsea-test',
[sources_no_main, 'test/unit.cc'],
dependencies: [iconv, json, liquid, sndfile, catch2],
)
test('Smoke tests', test_exec)
endif

0 comments on commit 0fdb4de

Please sign in to comment.