diff --git a/core/.gitignore b/core/.gitignore index e71a856da3..b02aacc473 100644 --- a/core/.gitignore +++ b/core/.gitignore @@ -1,6 +1,7 @@ .vs/ build/ configure/ +resources/ # cross-compile for meson wasm, built from wasm.build..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/ diff --git a/core/build.sh b/core/build.sh index b746065b48..90e56733f3 100755 --- a/core/build.sh +++ b/core/build.sh @@ -54,7 +54,7 @@ builder_describe \ Libraries will be built in 'build///src'. * : '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 diff --git a/core/meson.build b/core/meson.build index 47b8860389..81d994124c 100644 --- a/core/meson.build +++ b/core/meson.build @@ -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' diff --git a/core/src/meson.build b/core/src/meson.build index 8259d0e22a..b117b06f9d 100644 --- a/core/src/meson.build +++ b/core/src/meson.build @@ -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( diff --git a/core/tests/kmx_test_source/meson.build b/core/tests/kmx_test_source/meson.build index 4cfdd5661d..691839047f 100644 --- a/core/tests/kmx_test_source/meson.build +++ b/core/tests/kmx_test_source/meson.build @@ -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' diff --git a/core/tests/meson.build b/core/tests/meson.build index 1d37806947..e2e2997582 100644 --- a/core/tests/meson.build +++ b/core/tests/meson.build @@ -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 diff --git a/core/tests/unit/json/meson.build b/core/tests/unit/json/meson.build index 42106976cd..6289d7db0c 100644 --- a/core/tests/unit/json/meson.build +++ b/core/tests/unit/json/meson.build @@ -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 = [] diff --git a/core/tests/unit/kmnkbd/meson.build b/core/tests/unit/kmnkbd/meson.build index 16884298e5..9cf3cdb240 100644 --- a/core/tests/unit/kmnkbd/meson.build +++ b/core/tests/unit/kmnkbd/meson.build @@ -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)) diff --git a/core/tests/unit/kmx/fixtures/binary/meson.build b/core/tests/unit/kmx/fixtures/binary/meson.build index 5998a3b1e9..da509ff619 100644 --- a/core/tests/unit/kmx/fixtures/binary/meson.build +++ b/core/tests/unit/kmx/fixtures/binary/meson.build @@ -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() diff --git a/core/tests/unit/kmx/meson.build b/core/tests/unit/kmx/meson.build index 048b888011..f4ededbf95 100644 --- a/core/tests/unit/kmx/meson.build +++ b/core/tests/unit/kmx/meson.build @@ -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() diff --git a/core/tests/unit/ldml/meson.build b/core/tests/unit/ldml/meson.build index 7dc3d81805..596099246a 100644 --- a/core/tests/unit/ldml/meson.build +++ b/core/tests/unit/ldml/meson.build @@ -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 = '/' diff --git a/resources/build/meson/standard.meson.build b/resources/build/meson/standard.meson.build new file mode 100644 index 0000000000..32eef47c8a --- /dev/null +++ b/resources/build/meson/standard.meson.build @@ -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 /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