From b8ac55cf21545a6ca9c4fa5695cf61a4d081b5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oona=20R=C3=A4is=C3=A4nen?= Date: Tue, 23 Jul 2024 21:27:52 +0300 Subject: [PATCH] macOS: more generic search for Homebrew Liquid-dsp Now we query homebrew itself as to where liquid might be installed. --- .github/workflows/tidy.yml | 2 +- CHANGES.md | 5 +++ meson.build | 90 ++++++++++++++++++++------------------ 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/.github/workflows/tidy.yml b/.github/workflows/tidy.yml index 99dd3fa..bd47208 100644 --- a/.github/workflows/tidy.yml +++ b/.github/workflows/tidy.yml @@ -2,7 +2,7 @@ name: tidy on: push: - branches: [ master ] + branches: [ master, dev ] pull_request: branches: [ master ] diff --git a/CHANGES.md b/CHANGES.md index e6c9a36..8cbc044 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,10 @@ # redsea changelog +## HEAD + +* Fixes: + * macOS: ask Homebrew about liquid-dsp installation path instead of hardcoding it + ## 1.0.1 * Fixes: diff --git a/meson.build b/meson.build index 57e8dcc..eae231a 100644 --- a/meson.build +++ b/meson.build @@ -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 int main() { iconv_open("UTF-8", "ISO-8859-1"); - }''', args: linker_args) + }''', + args: linker_args, + ) iconv = declare_dependency(link_args: linker_args) break endif @@ -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 ', - 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 ', dependencies: liquid) + add_project_arguments('-DMODEM_IS_MODEMCF', language: 'cpp') endif - ############################ ### Sources & Executable ### ############################ - sources_no_main = [ 'src/block_sync.cc', 'src/channel.cc', @@ -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 ### @@ -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