Skip to content

Commit

Permalink
Feature/meson support (#522)
Browse files Browse the repository at this point in the history
* set remote branch

* add subprojects

* give up compiling unit tests in Meson because no user-defined function feature

* add support for installing m4 macros

* add comments in root meson.build

* add pkg-config generator

* remove gtest subproject because removed unit tests earlier

* add python support

* add lua support

* remove 'bin' install directories because meson defaults to standard conforming directory i.e. bin

* add basic java support

* reset options

* change meson.options to meson_options.txt for backward compatibility

* make doxygen not required

* remove compiler warnings to match cmake

* remove -Wno-unused-result c_arg

* add option to disable compilation of lcmgen

* mark java as WIP in meson.build

* create meson ci tests

* edit windows build dependencies and linking in meson

* make full lcm_export.h

* try not compiling static libs for windows

* try verbose output in ci for windows

* add compiler arg for windows in meson

* build static liblcm again

* add basic test to meson build ci

* install shared library lcm

* use grep to create test for lcm windows

* remove verbose output from cmake windows build

* remove verbose output from meson windows build

* install lcm lib headers

* install man pages

* clean up commented code and unused code

* fix lcm header install subdir into lcm subdir

* add build files for c example

* add ci test for building c example

* install lcm before using in Windows ci test

* fix directories

* fix fedora docker command and don't build c example for windows

* add build files for cpp example and lcm_log_writer

* add ci tests for building c++ and lcm log writer example

* comment placeholder code for java pkg-config generation

* address documentation support not implemented yet

* add generated file from examples to gitignore

* shorten code and remove unused exe variable declarations

* remove jchart2d meson files until further development

* shorten library building code using Meson's

* add generated c example code to gitignore

* add back variable for static lcm lib

fix python library installation and remove comment

* build all modules with met dependencies by default

* remove building java because broken

* check for optional module dependencies and don't build optional modules if not found

* add options summary

* remove generated java targets from main meson build

* remove name_suffix from windows python build

* remove python support for Windows and describe WIP status for python and java

* remove mysterious meson/ directory from gitignore

* shorten lcm lib building code

* rename lcm-python module to lcm

* add detailed summary

* add build instructions for Meson

* use meson built in default_library switch for building shared/static instead of unused option

* fix lcm-lua install_dir and name

* mark all optional modules as not working

* add spaces

* fix python installation for linux and macos

* move pure keyword from find_installation() to install_sources() and bring back hacky platlib dir for compatibility with ubuntu 22.04's ancient meson version

* fix macos lua install oserror

* update lua install_dir to match cmake

* replace unsupported message with disabled message when unsupported features are disabled

* fix if statement

* fix python/lua typo

* remove python, lua, and java support

* use threads dependency

* remove threads dep for windows

* include stdbool.h for windows

* format code

* add rationale for nested broken modules

---------

Co-authored-by: jason <[email protected]>
  • Loading branch information
Zinput and jason authored Dec 23, 2024
1 parent a234e3a commit 4b1f438
Show file tree
Hide file tree
Showing 24 changed files with 646 additions and 15 deletions.
175 changes: 175 additions & 0 deletions .github/workflows/test_meson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
name: test_meson

on: [push, pull_request]

jobs:

ubuntu:
strategy:
matrix:
os: [ubuntu-24.04, ubuntu-22.04]
build_type: [Debug, Release]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- name: Install Dependencies
run: |
sudo apt install liblua5.3-dev lua5.3 libjchart2d-java libglib2.0-dev meson
- name: Setup Meson
run: meson setup ${{github.workspace}}/build

- name: Build
run: ninja -C ${{github.workspace}}/build

- name: Test
run : '${{github.workspace}}/build/liblcm-test/lcm-tester | grep "LCM: OK!"'

- name: Install
run : sudo ninja -C ${{github.workspace}}/build install

- name : Build C Example
working-directory: ${{github.workspace}}/examples/c
run: |
meson setup build
ninja -C build
- name: Build C++ Example
working-directory: ${{github.workspace}}/examples/cpp
run: |
meson setup build
ninja -C build
- name: Build and Run C++ Log Writer Example
working-directory: ${{github.workspace}}/examples/cpp/lcm_log_writer
run: |
meson setup build
ninja -C build
LD_LIBRARY_PATH=/usr/local/lib/ build/lcm_log_writer build/example.log
fedora:
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v3

- name: Build and Start Container
run: |
docker build -f docker/Dockerfile.fedora -t lcm-fedora docker
docker run -v $(pwd):/work -d --rm -it --name lcm-fedora lcm-fedora /bin/bash
- name: Setup Meson
run: docker exec lcm-fedora meson setup ${{github.workspace}}/build

- name: Build
run: docker exec lcm-fedora ninja -C ${{github.workspace}}/build

- name: Test
run : 'docker exec lcm-fedora ${{github.workspace}}/build/liblcm-test/lcm-tester | grep "LCM: OK!"'

- name: Install
run : docker exec lcm-fedora ninja -C ${{github.workspace}}/build install

- name : Build C Example
run: |
docker exec --workdir /work/examples/c lcm-fedora meson setup build
docker exec --workdir /work/examples/c lcm-fedora ninja -C build
- name: Build C++ Example
run: |
docker exec --workdir /work/examples/cpp lcm-fedora meson setup build
docker exec --workdir /work/examples/cpp lcm-fedora ninja -C build
- name: Build and Run C++ Log Writer Example
working-directory: ${{github.workspace}}/examples/cpp/lcm_log_writer
run: |
docker exec --workdir /work/examples/cpp/lcm_log_writer lcm-fedora meson setup build
docker exec --workdir /work/examples/cpp/lcm_log_writer lcm-fedora ninja -C build
docker exec --workdir /work/examples/cpp/lcm_log_writer -e LD_LIBRARY_PATH=/usr/local/lib64/ lcm-fedora build/lcm_log_writer build/example.log
macos:
strategy:
matrix:
os: [macos-13, macos-14]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- name: Install Dependencies
run: |
brew install lua meson
- name: Setup Meson
run: meson setup ${{github.workspace}}/build

- name: Build
run: ninja -C ${{github.workspace}}/build

- name: Test
run : '${{github.workspace}}/build/liblcm-test/lcm-tester | grep "LCM: OK!"'

- name: Install
run : sudo ninja -C ${{github.workspace}}/build install

- name : Build C Example
working-directory: ${{github.workspace}}/examples/c
run: |
meson setup build
ninja -C build
- name: Build C++ Example
working-directory: ${{github.workspace}}/examples/cpp
run: |
meson setup build
ninja -C build
- name: Build and Run C++ Log Writer Example
working-directory: ${{github.workspace}}/examples/cpp/lcm_log_writer
run: |
meson setup build
ninja -C build
build/lcm_log_writer build/example.log
windows:
strategy:
matrix:
os: [windows-2019, windows-2022]

runs-on: ${{ matrix.os }}

defaults:
run:
shell: msys2 {0}

steps:
- uses: actions/checkout@v3
- uses: msys2/setup-msys2@v2
with:
msystem: mingw64
update: false
install: >-
git
make
pacboy: >-
toolchain:p
cmake:p
glib2:p
gtest:p
meson:p
- name: Setup Meson
run: meson setup build --prefix /mingw64/

- name: Build
run: ninja -C build

- name: Install
run: ninja -C build install

- name: Test
run : 'lcm-tester | grep "LCM: OK"'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ docs/_build/
.project
.classpath
.venv
.DS_Store
.DS_Store
.cache/
3 changes: 2 additions & 1 deletion docker/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN dnf install -y \
clang \
glib2-devel \
java-17-openjdk-devel \
python3-devel
python3-devel \
meson

WORKDIR /work
53 changes: 40 additions & 13 deletions docs/content/build-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,43 @@ To build the Python module from source and install it, run:
pip3 install -v .
```

## CMake Overview
## CMake and Meson overview

These instructions assume that you will build in a directory named `build` as
a direct subdirectory of the source directory, and that you will use the
default generator. CMake permits the build directory to be almost anywhere
(although in-source builds are strongly discouraged), and supports multiple
generators. To users familiar with CMake, we recommend using
[Ninja](https://ninja-build.org/).
default generator. CMake and Meson support multiple generators and permit the
build directory to be almost anywhere (although in-source builds are strongly
discouraged for both and are prohibited in Meson). To users familiar with
CMake, we recommend using [Ninja](https://ninja-build.org/).

A detailed description of how to use CMake is not specific to LCM and is beyond
the scope of these instructions.
A detailed description of how to use CMake or Meson is not specific to LCM and
is beyond the scope of these instructions.

By default CMake is configured to produce a release build. To build with debug symbols instead, use:
By default CMake and Meson are configured to produce a release build. To build with debug symbols instead, use:

```shell
cmake .. -DCMAKE_BUILD_TYPE=Debug
```

when configuring a build directory in the following sections.
for CMake, and use:

```shell
meson setup build -Dbuildtype=debug
```

for Meson when configuring a build directory in the following sections.

## Ubuntu and Debian

Required packages:
- build-essential
- cmake
- cmake # note: if using CMake
- meson # note: if using Meson
- libglib2.0-dev

Optional packages (e.g., for language-specific support or building documentation):
- default-jdk
- libjchart2d-java # note: if not installed, jchart2d will be built from source
- libjchart2d-java # note: if not installed, jchart2d will be built from source in CMake
- doxygen
- liblua5.3-dev
- lua5.3
Expand All @@ -69,7 +76,7 @@ Python packages needed for building documentation:
- myst-parser
- sphinx-rtd-theme

From a terminal, run the following commands.
From a terminal, run the following commands for CMake:

```shell
mkdir build
Expand All @@ -79,14 +86,23 @@ make
sudo make install
```

or run the following commands for Meson:

```shell
meson setup build
cd build
meson compile
sudo meson install
```

## OS X

There are several ways to build LCM on OS X, none of which are necessarily
better than the others.

### Homebrew

Install Homebrew packages
Install Homebrew packages (swap `cmake` for `meson` if building with Meson)

```shell
brew install glib pkg-config cmake
Expand All @@ -96,6 +112,8 @@ Install Java. Type `javac` in a terminal, then follow the instructions.

Download and build LCM.

For CMake, run:

```shell
mkdir build
cd build
Expand All @@ -104,6 +122,15 @@ make
make install
```

For Meson, run:

```shell
meson setup build
cd build
meson compile
meson install
```

## Windows

LCM is officially supported on MSYS2. There is some residual support for Visual Studio that is
Expand Down
5 changes: 5 additions & 0 deletions docs/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Placeholder code until documentation support is implemented
# doxygen = find_program('doxygen', required : false)
# if not doxygen.found()
# warning('Doxygen was not found; documentation generation will be incomplete')
# endif
9 changes: 9 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,14 @@
/c/exlcm_example_t.c
/c/exlcm_example_t.h
/c/listener-async
/c/exlcm_example_list_t.c
/c/exlcm_example_list_t.h
/c/exlcm_exampleconst_t.c
/c/exlcm_exampleconst_t.h
/c/exlcm_muldim_array_t.c
/c/exlcm_muldim_array_t.h
/c/exlcm_node_t.c
/c/exlcm_node_t.h
/cpp/lcm_log_writer/pronto/
/java/temperature_demo_java/lcmtypes/
!/go/listener/
3 changes: 3 additions & 0 deletions examples/c/generate_example_messages_c.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

lcm-gen -c ../types/*
31 changes: 31 additions & 0 deletions examples/c/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
project('lcm_c_example', 'c')

lcm_dep = dependency('lcm')
glib_dep = dependency('glib-2.0')

generate_example_messages_c_exe = find_program('generate_example_messages_c.sh')
run_command(generate_example_messages_c_exe, check: true)

example_messages_source = ['exlcm_exampleconst_t.c', 'exlcm_example_list_t.c', 'exlcm_example_t.c', 'exlcm_muldim_array_t.c', 'exlcm_node_t.c']
example_messages_c_lib = library('example_messages-c',
example_messages_source,
dependencies : lcm_dep)

example_messages_c_dep = declare_dependency(link_with : example_messages_c_lib,
dependencies : lcm_dep)

executable('listener',
'listener.c',
dependencies : example_messages_c_dep)
executable('listener-async',
'listener-async.c',
dependencies : example_messages_c_dep)
executable('listener-glib',
'listener-glib.c',
dependencies : [example_messages_c_dep, glib_dep])
executable('send_message',
'send_message.c',
dependencies : example_messages_c_dep)
executable('read_log',
'read_log.c',
dependencies : example_messages_c_dep)
3 changes: 3 additions & 0 deletions examples/cpp/generate_example_messages_cpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

lcm-gen -x ../types/*
11 changes: 11 additions & 0 deletions examples/cpp/lcm_log_writer/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
project('lcm_log_writer', 'cpp')

lcm_dep = dependency('lcm')
glib_dep = dependency('glib-2.0')

run_command('lcm-gen', '-x', 'pronto_joint_state_t.lcm', check: true)

lcm_log_writer_exe = executable('lcm_log_writer',
'main.cpp',
include_directories : include_directories('pronto'),
dependencies : [lcm_dep, glib_dep])
Loading

0 comments on commit 4b1f438

Please sign in to comment.