Build system: more Meson rewrite

- add proper detection of Boost
- add logic for making FlexLexer.h always available
- statically link the executable if prefer_static=true
- add Homebrew native file
- add Windows cross file
master
Sébastien Villemot 2023-06-08 18:01:58 +02:00
parent 9011668f3a
commit 1d305ca12b
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
3 changed files with 41 additions and 8 deletions

6
homebrew-native.ini Normal file
View File

@ -0,0 +1,6 @@
# Meson native file for compiling under Homebrew
[binaries]
cpp = 'g++-13'
flex = '/usr/local/opt/flex/bin/flex'
bison = '/usr/local/opt/bison/bin/bison'

View File

@ -1,9 +1,6 @@
# TODO for reaching feature parity with current autotools-based build system:
# - Detection of Boost Graph library and corresponding include directory
# - Detection of FlexLexer.h and corresponding include directory
# - Build and install documentation (with a configuration option to disable it explicitly)
# - Link with pthread with old glibc
# - Add -Wold-style-cast flag when building flex-generated files
# - Add -Wold-style-cast flag except when building flex-generated files
project('dynare-preprocessor', 'cpp',
version : '6-unstable',
@ -11,20 +8,34 @@ project('dynare-preprocessor', 'cpp',
add_global_arguments('-DPACKAGE_VERSION="' + meson.project_version() + '"', language : 'cpp')
boost_dep = dependency('boost')
## Flex stuff
flex_exe = find_program('flex')
# The -Ca flag comes from hitting a hard-coded size limit.
# Partial explanation: https://www.owlfolio.org/possibly-useful/flex-input-scanner-rules-are-too-complicated
# There is a Debian bug report about this: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=642040
flex_gen = generator(flex_exe, output : '@BASENAME@.cc',
arguments : ['-Ca', '-o', '@OUTPUT@', '@INPUT@'])
flex_src = flex_gen.process('src/macro/Tokenizer.ll', 'src/DynareFlex.ll')
# If FlexLexer.h is not found by the compiler, copy it to the build directory
# (adding an include directory could create problems for cross-compilation, because
# flex is typically provided by the system of the build machine)
compiler = meson.get_compiler('cpp')
if not compiler.has_header('FlexLexer.h')
message('FlexLexer.h cannot be found by the compiler, it will be manually copied to the build directory')
fs = import('fs')
flexlexer_h = fs.copyfile(fs.parent(fs.parent(flex_exe.full_path())) / 'include' / 'FlexLexer.h', 'FlexLexer.h')
else
flexlexer_h = []
endif
## Bison stuff
bison_exe = find_program('bison')
# By convention, all our Bison source files define the api.location.file variable
# so that the generated location file follows the @BASENAME@Location.hh pattern
bison_gen = generator(bison_exe, output : ['@BASENAME@.cc', '@BASENAME@.hh', '@BASENAME@Location.hh'],
arguments : ['-W', '-o', '@OUTPUT0@', '@INPUT@'])
flex_src = flex_gen.process('src/macro/Tokenizer.ll', 'src/DynareFlex.ll')
bison_src = bison_gen.process('src/macro/Parser.yy', 'src/DynareBison.yy')
incdir = include_directories('src', 'src/macro')
@ -58,5 +69,7 @@ main_src = [ 'src/ComputingTasks.cc',
'src/macro/Expressions.cc',
'src/macro/Directives.cc' ]
executable('dynare-preprocessor', main_src, flex_src, bison_src,
include_directories : incdir, install : true)
executable('dynare-preprocessor', main_src, flex_src, flexlexer_h, bison_src,
include_directories : incdir, dependencies : boost_dep,
link_args : get_option('prefer_static') ? '-static' : '',
install : true)

14
windows-cross.ini Normal file
View File

@ -0,0 +1,14 @@
# Meson cross file for targeting Windows from Linux
# NB: The boost_root property must be set, possibly through a second cross file
[binaries]
cpp = 'x86_64-w64-mingw32-g++'
[host_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
#[properties]
#boost_root = '/home/sebastien/dynare/unstable/preprocessor/deps/mingw64/'