|
| 1 | +# This Meson script is experimental and potentially incomplete. It is not part |
| 2 | +# of the supported build system for Micro-Manager or mmCoreAndDevices. |
| 3 | + |
| 4 | +# IMPORTANT: This build script uses mmcore and mmdevice from the mirror |
| 5 | +# repositories, not the MMCore/ and MMDevice/ in mmCoreAndDevices. This is |
| 6 | +# because this build script is expected to be put in use when MMCoreJ is moved |
| 7 | +# out of mmCoreAndDevices. |
| 8 | +# The versions used are defined in mmdevice.wrap and mmcore.wrap. |
| 9 | + |
| 10 | +project( |
| 11 | + 'mmcorej', |
| 12 | + 'cpp', 'java', |
| 13 | + # TODO version (set here and generate pom.xml) |
| 14 | + meson_version: '>=1.3.0', |
| 15 | + default_options: [ |
| 16 | + 'cpp_std=c++14', |
| 17 | + 'warning_level=3', |
| 18 | + ], |
| 19 | +) |
| 20 | + |
| 21 | +cxx = meson.get_compiler('cpp') |
| 22 | + |
| 23 | +if cxx.get_id() in ['gcc', 'clang'] |
| 24 | + # SWIG Java typemaps call for -fno-strict-aliasing when compiling the |
| 25 | + # SWIG-generated code (see SWIG docs). |
| 26 | + add_project_arguments('-fno-strict-aliasing', language: 'cpp') |
| 27 | +endif |
| 28 | + |
| 29 | +if cxx.get_id() in ['msvc', 'clang-cl'] |
| 30 | + add_project_arguments('-DNOMINMAX', language: 'cpp') |
| 31 | +endif |
| 32 | + |
| 33 | +fs = import('fs') |
| 34 | + |
| 35 | +swig = find_program('swig', native: true) |
| 36 | + |
| 37 | +mmcore_proj = subproject( |
| 38 | + 'mmcore', |
| 39 | + default_options: { |
| 40 | + 'default_library': 'static', |
| 41 | + 'tests': 'disabled', |
| 42 | + }, |
| 43 | +) |
| 44 | +mmcore_dep = mmcore_proj.get_variable('mmcore') |
| 45 | + |
| 46 | +jni_dep = dependency('jni', version: '>= 1.8.0') |
| 47 | + |
| 48 | +threads_dep = dependency('threads') |
| 49 | + |
| 50 | +swig_include_dirs = mmcore_proj.get_variable('swig_include_dirs') |
| 51 | +swig_incdir_args = [] |
| 52 | +foreach abspath : swig_include_dirs |
| 53 | + swig_incdir_args += '-I' + fs.relative_to( |
| 54 | + abspath, |
| 55 | + meson.project_build_root(), |
| 56 | + ) |
| 57 | +endforeach |
| 58 | + |
| 59 | +subdir('src/main/java') # Get java_sources |
| 60 | + |
| 61 | +# TODO Add check to ensure we don't miss any |
| 62 | +swig_gen_java_source_names = [ |
| 63 | + 'ActionType.java', |
| 64 | + 'BooleanVector.java', |
| 65 | + 'CharVector.java', |
| 66 | + 'CMMCore.java', |
| 67 | + 'Configuration.java', |
| 68 | + 'DeviceDetectionStatus.java', |
| 69 | + 'DeviceInitializationState.java', |
| 70 | + 'DeviceNotification.java', |
| 71 | + 'DeviceType.java', |
| 72 | + 'DoubleVector.java', |
| 73 | + 'FocusDirection.java', |
| 74 | + 'LongVector.java', |
| 75 | + 'Metadata.java', |
| 76 | + 'MetadataArrayTag.java', |
| 77 | + 'MetadataError.java', |
| 78 | + 'MetadataSingleTag.java', |
| 79 | + 'MetadataTag.java', |
| 80 | + 'MMCoreJ.java', |
| 81 | + 'MMCoreJConstants.java', |
| 82 | + 'MMCoreJJNI.java', |
| 83 | + 'MMEventCallback.java', |
| 84 | + 'pair_ss.java', |
| 85 | + 'PortType.java', |
| 86 | + 'PropertySetting.java', |
| 87 | + 'PropertyType.java', |
| 88 | + 'StrMap.java', |
| 89 | + 'StrVector.java', |
| 90 | + 'SWIGTYPE_p_std__istringstream.java', |
| 91 | + 'UnsignedVector.java', |
| 92 | +] |
| 93 | + |
| 94 | +swig_gen = custom_target( |
| 95 | + 'swig-mmcorej', |
| 96 | + input: 'MMCoreJ.i', |
| 97 | + output: [ |
| 98 | + 'MMCoreJ_swig_wrap.cpp', # @OUTPUT0@, swig_gen[0] |
| 99 | + 'MMCoreJ_swig_wrap.h', # @OUTPUT1@, swig_gen[1] |
| 100 | + swig_gen_java_source_names, |
| 101 | + ], |
| 102 | + depfile: 'MMCoreJ_swig_wrap.d', |
| 103 | + command: [ |
| 104 | + swig, |
| 105 | + '-c++', |
| 106 | + '-java', |
| 107 | + '-package', 'mmcorej', |
| 108 | + '-module', 'MMCoreJ', |
| 109 | + swig_incdir_args, |
| 110 | + '-MD', '-MF', '@DEPFILE@', |
| 111 | + '-o', '@OUTPUT0@', |
| 112 | + '-oh', '@OUTPUT1@', |
| 113 | + '-outdir', '@OUTDIR@', |
| 114 | + '@INPUT@', |
| 115 | + ], |
| 116 | +) |
| 117 | + |
| 118 | +swig_gen_cpp_sources = [swig_gen[0], swig_gen[1]] |
| 119 | + |
| 120 | +swig_gen_java_sources = [] |
| 121 | +foreach src : swig_gen.to_list() |
| 122 | + if src.full_path().endswith('.h') or src.full_path().endswith('.cpp') |
| 123 | + continue |
| 124 | + endif |
| 125 | + swig_gen_java_sources += src |
| 126 | +endforeach |
| 127 | + |
| 128 | +# Note that JNI libraries are supposed to be dylibs, not Mach-O bundles, on |
| 129 | +# macOS, even though they are loaded by dlopen() (other platforms don't have |
| 130 | +# this distinction). So we use shared_library(), not shared_module(). |
| 131 | +shared_library( |
| 132 | + 'MMCoreJ_wrap', |
| 133 | + swig_gen_cpp_sources, |
| 134 | + dependencies: [ |
| 135 | + jni_dep, |
| 136 | + mmcore_dep, |
| 137 | + threads_dep, |
| 138 | + ], |
| 139 | + gnu_symbol_visibility: 'hidden', |
| 140 | + install: true, |
| 141 | +) |
| 142 | + |
| 143 | +jar( |
| 144 | + 'MMCoreJ', |
| 145 | + java_sources, |
| 146 | + swig_gen_java_sources, |
| 147 | + java_resources: structured_sources([ |
| 148 | + # TODO pom.xml |
| 149 | + ]), |
| 150 | + override_options: [ |
| 151 | + 'warning_level=1', # Disable -Xdoclint:all, keep -Xlint:all |
| 152 | + ], |
| 153 | + install: true, |
| 154 | +) |
| 155 | + |
| 156 | +# TODO Javadoc jar (needs parsing of Doxygen XML; see old generator) |
| 157 | +# TODO Source jar (create externally from source dist?) |
0 commit comments