Skip to content

Commit 38dde57

Browse files
committed
Add Meson build system
JNI include path detection and JAR custom resource support both require Meson 0.62, which isn't available in all supported OSes yet, so we'll keep Autotools+Ant build support for now. Drop Cygwin support in Meson builds. WSL essentially obsoletes it, and openslide-winbuild has already dropped Cygwin support. Signed-off-by: Benjamin Gilbert <[email protected]>
1 parent c5dea49 commit 38dde57

File tree

7 files changed

+220
-14
lines changed

7 files changed

+220
-14
lines changed

.github/ISSUE_TEMPLATE/release.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# OpenSlide Java release process
22

33
- [ ] Run test build and `make distcheck`
4-
- [ ] Update `CHANGELOG.md` and version in `configure.ac`
4+
- [ ] Update `CHANGELOG.md` and versions in `configure.ac` and `meson.build`
55
- [ ] Create and push signed tag
6-
- [ ] `git clean -dxf && autoreconf -i && ./configure && make distcheck`
7-
- [ ] Attach release notes to [GitHub release](https://github.com/openslide/openslide-java/releases/new), set pre-release flag, and upload tarballs
6+
- [ ] `git clean -dxf && meson setup builddir && meson dist -C builddir`
7+
- [ ] Attach release notes to [GitHub release](https://github.com/openslide/openslide-java/releases/new), set pre-release flag, and upload tarball
88
- [ ] [Update openslide-winbuild](https://github.com/openslide/openslide-winbuild/issues/new?labels=release&template=release.md)
99
- [ ] Update website: `_data/releases.yaml`, `_includes/news.md`
1010
- [ ] Send mail to -announce and -users

.github/workflows/java.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ jobs:
2222
uses: actions/checkout@v3
2323
- name: Install dependencies (Linux)
2424
if: ${{ matrix.os == 'ubuntu-latest' }}
25-
run: sudo apt-get install libopenslide0-dev
25+
run: |
26+
sudo apt-get install libopenslide0-dev ninja-build
27+
# Ubuntu 22.04 packages Meson 0.61
28+
pip install --user meson
2629
- name: Install dependencies (macOS)
2730
if: ${{ matrix.os == 'macos-latest' }}
28-
run: brew install automake openslide
31+
run: brew install meson openslide
2932
- name: Build
3033
run: |
31-
autoreconf -i
32-
./configure --prefix=$HOME
33-
make
34-
make install
34+
meson setup builddir --prefix=$HOME
35+
meson compile -C builddir
36+
meson install -C builddir
3537
- name: Smoke test
36-
run: java -cp openslide.jar org.openslide.TestCLI fixtures/small.svs
38+
run: java -cp builddir/openslide.jar org.openslide.TestCLI fixtures/small.svs

README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,41 @@
33
This is a Java binding to [OpenSlide](https://openslide.org/).
44

55

6-
## Build requirements
6+
## Building with Meson
7+
8+
This is the new method.
9+
10+
### Build requirements
11+
12+
- JDK
13+
- Meson &ge; 0.62
14+
- OpenSlide &ge; 3.4.0
15+
- pkg-config
16+
17+
18+
### Building
19+
20+
```
21+
meson setup builddir
22+
meson compile -C builddir
23+
meson install -C builddir
24+
```
25+
26+
27+
## Building with Autotools and Ant
28+
29+
This is the old method, and will eventually be removed.
30+
31+
32+
### Build requirements
733

834
- JDK
935
- Apache Ant
1036
- OpenSlide &ge; 3.4.0
37+
- pkg-config
1138

1239

13-
## Building on Linux or Mac OS X
40+
### Building on Linux or Mac OS X
1441

1542
```
1643
./configure
@@ -22,7 +49,7 @@ make install
2249
autoconf, automake, libtool, and pkg-config and run `autoreconf -i`.)
2350

2451

25-
## Cross-compiling for Windows with MinGW-w64
52+
### Cross-compiling for Windows with MinGW-w64
2653

2754
```
2855
PKG_CONFIG=pkg-config \
@@ -35,7 +62,7 @@ make install
3562
For a 64-bit JRE, substitute `--host=x86_64-w64-mingw32`.
3663

3764

38-
## Building on Windows
65+
### Building on Windows
3966

4067
Ensure that the path to the openslide-java source tree does not contain
4168
whitespace.

meson.build

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
project(
2+
'openslide-java',
3+
'c', 'java',
4+
default_options : [
5+
'buildtype=debugoptimized',
6+
],
7+
license : 'LGPL-2.1-only',
8+
meson_version : '>=0.62',
9+
version : '0.12.2',
10+
)
11+
meson.add_dist_script(
12+
'scripts/dist.py'
13+
)
14+
java_ver = '1.8'
15+
16+
# options
17+
# must be absolute path for openslide_jni_path
18+
install_dir = get_option('prefix') / get_option('libdir') / 'openslide-java'
19+
20+
# Java setup
21+
jni = dependency(
22+
'jni',
23+
version : '>=' + java_ver,
24+
)
25+
if meson.is_cross_build()
26+
# probably no native JNI headers available; use bundled generic ones
27+
jni = declare_dependency(
28+
dependencies : [jni],
29+
include_directories : ['cross'],
30+
)
31+
elif host_machine.system() == 'darwin'
32+
if not meson.get_compiler('c').has_header('jni.h', dependencies : [jni])
33+
# Meson < 1.0 doesn't know to check /usr/libexec/java_home
34+
darwin_java_home = run_command(
35+
'/usr/libexec/java_home',
36+
check : true,
37+
).stdout().strip()
38+
message('Using JNI headers from ' + darwin_java_home)
39+
jni = declare_dependency(
40+
dependencies : [jni],
41+
include_directories : [
42+
darwin_java_home / 'include',
43+
darwin_java_home / 'include/darwin'
44+
],
45+
)
46+
endif
47+
endif
48+
native_java_home = meson.get_external_property(
49+
'java_home',
50+
'',
51+
native : true
52+
)
53+
jar = find_program(
54+
'jar',
55+
dirs : native_java_home != '' ? [native_java_home / 'bin'] : [],
56+
native : true,
57+
)
58+
59+
# compiler options
60+
add_project_arguments(
61+
'-Wno-pointer-to-int-cast',
62+
'-Wno-int-to-pointer-cast',
63+
language : 'c',
64+
)
65+
add_project_arguments(
66+
'-source', java_ver,
67+
'-target', java_ver,
68+
'-Xlint:-options',
69+
language : 'java',
70+
)
71+
72+
# library dependencies
73+
openslide = dependency(
74+
'openslide',
75+
version : '>=3.4.0',
76+
)
77+
78+
# JNI
79+
jni_link_args = []
80+
jni_prefix = []
81+
jni_suffix = []
82+
if host_machine.system() == 'windows'
83+
# JNI uses stdcall without @
84+
jni_link_args += '-Wl,--kill-at'
85+
# skip "lib" prefix, even when built with MinGW
86+
jni_prefix = ''
87+
elif host_machine.system() == 'darwin'
88+
# special file extension for JNI libraries
89+
jni_suffix = 'jnilib'
90+
endif
91+
openslide_jni = shared_module(
92+
'openslide-jni',
93+
'openslide-jni.c',
94+
dependencies : [jni, openslide],
95+
install : true,
96+
install_dir : install_dir,
97+
link_args : jni_link_args,
98+
name_prefix : jni_prefix,
99+
name_suffix : jni_suffix,
100+
)
101+
fs = import('fs')
102+
openslide_jni_path = install_dir / fs.name(openslide_jni.full_path())
103+
104+
# jar
105+
jar_props = configure_file(
106+
input : 'meta/openslide.properties.in',
107+
output : 'openslide.properties',
108+
configuration : {
109+
# don't embed JNI library path in jar on Windows
110+
'jni_path': host_machine.system() == 'windows' ? '' : openslide_jni_path,
111+
}
112+
)
113+
manifest_extra = configure_file(
114+
input : 'meta/MANIFEST.MF.in',
115+
output : 'MANIFEST.MF',
116+
configuration : {
117+
'version': meson.project_version(),
118+
}
119+
)
120+
built_jar = jar(
121+
'built',
122+
[
123+
'org/openslide/gui/Annotation.java',
124+
'org/openslide/gui/DefaultAnnotation.java',
125+
'org/openslide/gui/DefaultSelectionListModel.java',
126+
'org/openslide/gui/Demo.java',
127+
'org/openslide/gui/OpenSlideView.java',
128+
'org/openslide/gui/SelectionListModel.java',
129+
'org/openslide/AssociatedImage.java',
130+
'org/openslide/OpenSlideDisposedException.java',
131+
'org/openslide/OpenSlide.java',
132+
'org/openslide/OpenSlideJNI.java',
133+
'org/openslide/TestCLI.java',
134+
],
135+
java_resources : structured_sources(
136+
[],
137+
{
138+
'resources': jar_props,
139+
},
140+
),
141+
main_class : 'org.openslide.gui.Demo',
142+
)
143+
# https://github.com/mesonbuild/meson/issues/3070
144+
openslide_jar = custom_target(
145+
capture : true,
146+
command : [jar, '-um', manifest_extra],
147+
feed : true,
148+
input : built_jar,
149+
install : true,
150+
install_dir : install_dir,
151+
install_tag : 'runtime',
152+
output : 'openslide.jar',
153+
)

meta/MANIFEST.MF.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Implementation-Title: OpenSlide Java
2+
Implementation-Vendor: OpenSlide project
3+
Implementation-Version: @version@
4+

meta/openslide.properties.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openslide.jni.path=@jni_path@

scripts/dist.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/python3
2+
3+
import os
4+
from pathlib import Path
5+
import shutil
6+
import subprocess
7+
8+
base = Path(os.getenv('MESON_DIST_ROOT'))
9+
10+
base.joinpath('.gitattributes').unlink()
11+
base.joinpath('.gitignore').unlink()
12+
base.joinpath('m4', '.gitignore').unlink()
13+
shutil.rmtree(base / '.github')
14+
15+
# fixtures are currently only used by GitHub Actions
16+
shutil.rmtree(base / 'fixtures')
17+
18+
subprocess.run(['autoreconf', '-i'], cwd=base, check=True)
19+
shutil.rmtree(base / 'autom4te.cache')

0 commit comments

Comments
 (0)