chore(core): split flags into standard.meson.build

This commit is contained in:
Marc Durdin 2023-03-09 09:32:06 +07:00
parent 6a280804b8
commit 691dc8e618
12 changed files with 112 additions and 75 deletions

3
core/.gitignore vendored
View file

@ -1,6 +1,7 @@
.vs/
build/
configure/
resources/
# cross-compile for meson wasm, built from wasm.build.<platform>.in
wasm.build
@ -10,8 +11,6 @@ TIER.md
VERSION.md
shellHelperFunctions.sh
src/rust/keyman_keyboard_processor/target/
# The following files/subdirs are generated by autotools when building ibus-keyman.
# They can be removed after we convert ibus-keyman to use meson.
.deps/

View file

@ -54,7 +54,7 @@ builder_describe \
Libraries will be built in 'build/<target>/<configuration>/src'.
* <configuration>: 'debug' or 'release' (see --debug flag)
* All parameters after '--' are passed to meson or ninja
* All parameters after '--' are passed to meson or ninja \
" \
"@/common/tools/hextobin" \
"@/common/web/keyman-version" \
@ -112,6 +112,14 @@ else
TARGET_PATH="$KEYMAN_ROOT/core/build"
fi
# Import our standard compiler defines; this is copied from
# /resources/build/meson/standard.meson.build by build.sh, because meson doesn't
# allow us to reference a file outside its root
if builder_has_action configure; then
mkdir -p "$THIS_SCRIPT_PATH/resources"
cp "$KEYMAN_ROOT/resources/build/meson/standard.meson.build" "$THIS_SCRIPT_PATH/resources/meson.build"
fi
# Iterate through all possible targets; note that targets that cannot be built
# on the current platform have already been excluded through the archtargets
# settings above

View file

@ -14,27 +14,19 @@ project('keyboardprocessor', 'cpp', 'c',
'warning_level=2'],
meson_version: '>=0.53.0')
compiler = meson.get_compiler('cpp')
# Import our standard compiler defines; this is copied from
# /resources/build/standard.meson.build by build.sh, because
# meson doesn't allow us to reference a file outside its root
subdir('resources')
lib_version = '0.0.0'
py = import('python')
python = py.find_installation()
# Once we can assume meson 0.60 we can delete this
# (https://mesonbuild.com/Release-notes-for-0-60-0.html#msvc-compiler-now-assumes-utf8-source-code-by-default)
if compiler.get_id() == 'msvc'
add_global_arguments('/source-charset:utf-8', language: ['c', 'cpp'])
endif
message('host_machine.system(): ' + host_machine.system())
message('compiler.get_id(): ' + compiler.get_id())
cc = meson.get_compiler('c')
# TODO: Shared includes may use namespaces, etc which need future tidyup.
# For now, we use KMN_KBP to inject the km::kbp::kmx namespace
defns = ['-DKMN_KBP']
defns += ['-DKMN_KBP']
# #define DEBUG when we are on a debug build
if get_option('buildtype') == 'debug'

View file

@ -4,58 +4,17 @@
# Authors: Tim Eves (TSE)
#
defns += ['-DKMN_KBP_EXPORTING']
version_res = []
defns += ['-DKMN_KBP_EXPORTING']
if compiler.get_id() == 'gcc' or compiler.get_id() == 'clang'
warns = [
'-Wctor-dtor-privacy',
'-Wdouble-promotion',
'-Wendif-labels',
'-Wno-unknown-pragmas',
'-Wno-missing-field-initializers',
'-Wnon-virtual-dtor',
'-Wshadow'
]
flags = [
'-fvisibility=hidden',
'-fvisibility-inlines-hidden'
]
links = []
if compiler.get_id() == 'clang'
warns += [
'-Wimplicit-fallthrough',
'-Wno-double-promotion',
'-Wshorten-64-to-32'
]
endif
if host_machine.system() == 'darwin'
warns += ['-Wno-ctor-dtor-privacy', '-Wno-non-virtual-dtor']
endif
endif
if compiler.get_id() == 'msvc'
warns = []
flags = []
defns += [
'-D_SCL_SECURE_NO_WARNINGS',
'-D_CRT_SECURE_NO_WARNINGS',
'-DUNICODE'
]
links = []
if cpp_compiler.get_id() == 'msvc'
# /n = append null
# /c65001 = utf-8 file format
version_res += import('windows').compile_resources('version.rc', args:['/n','/c65001'])
endif
if compiler.get_id() == 'emscripten'
warns = []
flags = []
defns = ['-DKMN_KBP']
links = []
if cpp_compiler.get_id() == 'emscripten'
defns += ['-DKMN_KBP']
endif
kmx_files = files(

View file

@ -1,4 +1,6 @@
if compiler.get_id() == 'gcc' or compiler.get_id() == 'clang' or compiler.get_id() == 'emscripten'
# TODO -- why are these differing from the standard.meson.build flags?
if cpp_compiler.get_id() == 'gcc' or cpp_compiler.get_id() == 'clang' or cpp_compiler.get_id() == 'emscripten'
warns = [
'-Wno-missing-field-initializers',
'-Wno-unused-parameter'

View file

@ -22,7 +22,7 @@ if get_option('keyman_core_tests')
if get_option('default_library') != 'static'
ctypes_void_p_size = ['-c', 'import ctypes; print(ctypes.sizeof(ctypes.c_void_p))']
r = run_command(python, ctypes_void_p_size)
python_ctypes_compatible = r.stdout().to_int() == compiler.sizeof('void *')
python_ctypes_compatible = r.stdout().to_int() == cpp_compiler.sizeof('void *')
if not python_ctypes_compatible
message('Python ctypes is incompatible with built shared object. Disabling some tests.')
endif

View file

@ -4,7 +4,7 @@
# Authors: Tim Eves (TSE)
#
if compiler.get_id() == 'emscripten'
if cpp_compiler.get_id() == 'emscripten'
tests_flags = ['-lnodefs.js']
else
tests_flags = []

View file

@ -4,7 +4,8 @@
# Authors: Tim Eves (TSE)
#
if compiler.get_id() == 'gcc' or compiler.get_id() == 'clang' or compiler.get_id() == 'emscripten'
# TODO -- why are these differing from the standard.meson.build flags?
if cpp_compiler.get_id() == 'gcc' or cpp_compiler.get_id() == 'clang' or cpp_compiler.get_id() == 'emscripten'
warns = [
'-Wno-missing-field-initializers',
'-Wno-unused-parameter'
@ -13,7 +14,7 @@ else
warns = []
endif
defns+=['-DKMN_KBP_STATIC']
local_defns = ['-DKMN_KBP_STATIC']
tests = [
['context-api', 'context_api.cpp'],
['keyboard-api', 'keyboard_api.cpp'],
@ -24,7 +25,7 @@ tests = [
['kmx_context', 'test_kmx_context.cpp'],
]
if compiler.get_id() == 'emscripten'
if cpp_compiler.get_id() == 'emscripten'
tests_flags = ['--embed-file', join_paths(meson.current_source_dir(),'..','kmx','@/')]
source_path = '/'
test_path = '/'
@ -36,7 +37,7 @@ endif
foreach t : tests
bin = executable(t[0], t[1],
cpp_args: defns + warns,
cpp_args: local_defns + defns + warns,
include_directories: [inc, libsrc],
link_args: links + tests_flags,
objects: lib.extract_all_objects(recursive: false))

View file

@ -9,7 +9,7 @@
# Build all binary test keyboards
if compiler.get_id() == 'emscripten'
if cpp_compiler.get_id() == 'emscripten'
binary_test_path = '/'
else
binary_test_path = meson.current_build_dir()

View file

@ -5,7 +5,8 @@
# History: 19 Oct 2018 - TSE - Added test for context API functions.
#
if compiler.get_id() == 'gcc' or compiler.get_id() == 'clang' or compiler.get_id() == 'emscripten'
# TODO -- why are these differing from the standard.meson.build flags?
if cpp_compiler.get_id() == 'gcc' or cpp_compiler.get_id() == 'clang' or cpp_compiler.get_id() == 'emscripten'
warns = [
'-Wno-missing-field-initializers',
'-Wno-unused-parameter'
@ -15,7 +16,7 @@ else
endif
if compiler.get_id() == 'emscripten'
if cpp_compiler.get_id() == 'emscripten'
tests_flags = ['--embed-file', join_paths(meson.current_source_dir(),'@/')]
# we have to link in files from the binary folder also as the binary tests
# use the kmx test runner.
@ -108,7 +109,7 @@ else
cat_cmd = [find_program('cat', required: true)]
endif
if compiler.get_id() == 'emscripten'
if cpp_compiler.get_id() == 'emscripten'
# The .kmx files are linked in to the unit test,
# so kmcomp is too late here
kmcomp = disabler()
@ -206,7 +207,7 @@ if kmcomp.found()
endforeach
else
foreach kbd : tests
if compiler.get_id() == 'emscripten'
if cpp_compiler.get_id() == 'emscripten'
kbd_basename = kbd
else
kbd_basename = 'k_' + kbd.underscorify().to_lower()

View file

@ -4,7 +4,8 @@
# Authors: Marc Durdin
#
if compiler.get_id() == 'gcc' or compiler.get_id() == 'clang' or compiler.get_id() == 'emscripten'
# TODO -- why are these differing from the standard.meson.build flags?
if cpp_compiler.get_id() == 'gcc' or cpp_compiler.get_id() == 'clang' or cpp_compiler.get_id() == 'emscripten'
warns = [
'-Wno-missing-field-initializers',
'-Wno-unused-parameter'
@ -37,7 +38,7 @@ endif
# Build ldml test executable
if compiler.get_id() == 'emscripten'
if cpp_compiler.get_id() == 'emscripten'
tests_flags = ['--embed-file', join_paths(meson.current_build_dir(),'keyboards','@')]
tests_flags += ['--embed-file', join_paths(meson.current_build_dir(),'invalid-keyboards','@')]
test_path = '/'

View file

@ -0,0 +1,74 @@
#
# Shared configuration for all meson-based builds
#
# This file has the master location /resources/build/meson/standard.meson.build,
# and is copied into each project's <project>/resources/meson.build in the
# configure step, so that it can be referenced by meson directly.
#
# Where possible, we want to use these flags everywhere
#
cpp_compiler = meson.get_compiler('cpp')
c_compiler = meson.get_compiler('c')
# Once we can assume meson 0.60 we can delete this
# (https://mesonbuild.com/Release-notes-for-0-60-0.html#msvc-compiler-now-assumes-utf8-source-code-by-default)
if cpp_compiler.get_id() == 'msvc'
add_global_arguments('/source-charset:utf-8', language: ['c', 'cpp'])
endif
#
# Standard informational messages for our builds
#
message('host_machine.system(): ' + host_machine.system())
message('compiler.get_id(): ' + cpp_compiler.get_id())
#
# Standard compiler flags for all platforms
#
warns = []
flags = []
links = []
defns = []
if cpp_compiler.get_id() == 'gcc' or cpp_compiler.get_id() == 'clang'
warns += [
'-Wctor-dtor-privacy',
'-Wdouble-promotion',
'-Wendif-labels',
'-Wno-unknown-pragmas',
'-Wno-missing-field-initializers',
'-Wnon-virtual-dtor',
'-Wshadow'
]
flags += [
'-fvisibility=hidden',
'-fvisibility-inlines-hidden'
]
if cpp_compiler.get_id() == 'clang'
warns += [
'-Wimplicit-fallthrough',
'-Wno-double-promotion',
'-Wshorten-64-to-32'
]
endif
if host_machine.system() == 'darwin'
warns += ['-Wno-ctor-dtor-privacy', '-Wno-non-virtual-dtor']
endif
endif
if cpp_compiler.get_id() == 'msvc'
defns += [
'-D_SCL_SECURE_NO_WARNINGS',
'-D_CRT_SECURE_NO_WARNINGS',
'-DUNICODE'
]
endif
if cpp_compiler.get_id() == 'emscripten'
#
endif