Skip to content

Conversation

@dcbaker
Copy link
Contributor

@dcbaker dcbaker commented Mar 14, 2024

Meson, Like CMake and Bazel, is a modern build system supporting C++ with the ability to configure and build dependencies from source. To do this effectively, it needs native Meson build definitions for the project to be built. This PR adds those definitions with as much parity to the C++ build system as possible, with the exception of the generation of the CMake configuration files (Meson cannot generate sophisticated ones using targets), and without some of the tests, since one is for CMake files it doesn't generate, and the other is for fuzzing, which is still a painful experience in Meson.

I've provided CI jobs, but much more minimal ones than what CMake runs.


This change is Reviewable

@jarro2783
Copy link
Owner

Thanks, I know nothing about Meson so if it builds then it looks good to me. I just don't see the main unit tests being built and run.

@dcbaker
Copy link
Contributor Author

dcbaker commented Mar 18, 2024

You're right! I'm not sure how I missed adding that. the latest version has that tested added.

@dcbaker dcbaker force-pushed the submit/meson branch 2 times, most recently from 966e1e7 to 8dd0b2e Compare March 18, 2024 17:40
@jarro2783
Copy link
Owner

Does this run the tests?

@jarro2783
Copy link
Owner

It looks like it builds the tests but doesn't run them. I think it would be good to run them as well.

@dcbaker
Copy link
Contributor Author

dcbaker commented Apr 13, 2024

Yeah, i think it should be running them, but it doesn't. I'm not sure if it's a GitHub configuration issue or something in the Meson. I haven't had time to look this week, but I'm hoping to on Monday

@lazysegtree
Copy link
Contributor

@dcbaker Are you still working on this?

This is primarily intended to be useful for projects using Meson wishing
to consume cxxopts as a subproject. By hosting the files upstream users
get the benefit of automatic parity with the CMake based install
provided by an OS vendor or distribution.

The implementation attempts to mirror the CMake build as much as
possible, with the exception of generating the cmake-config files, which
Meson doesn't currently support. It uses a small python script to parse
the cxxopts.hpp header to extract the version, due to a concious design
decision of Meson to leave such complex logic to external scripting
languages like Python.
@dcbaker dcbaker force-pushed the submit/meson branch 5 times, most recently from f2e8f2b to d4ddc8c Compare January 6, 2026 18:12
@dcbaker
Copy link
Contributor Author

dcbaker commented Jan 6, 2026

@lazysegtree I had completely forgotten about it TBH, thanks for remding me :)

The tests are now running, and I think that covers all of the requested changes

Comment on lines +21 to +41
option(
'examples',
type : 'feature',
description : 'Whether to build examples. Defaults to enabled when not built as a subproject, otherwise disabled.',
)
option(
'tests',
type : 'feature',
description : 'Whether to build tests. Defaults to enabled when not built as a subproject, otherwise disabled.',
)
option(
'warnings',
type : 'feature',
description : 'Whether to add additional warnings. Defaults to enabled when not built as a subproject, otherwise disabled.',
)
option(
'icu',
type : 'feature',
value : 'disabled',
description : 'use ICU Unicode library.',
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all options like examples, and warning aren't covered in build workflows, it would be nice that you could provide logs from your system that they can successfully execute now. Something like results of meson run --option=example.

This will provide a proof that all the meson build instructions you have written, works as expected.
And will act as a proof that the options worked in the past at one place, if build breaks at some point in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcbaker It looks to me that we are not running the tests find-package-test and add-subdirectory-test that targets the src/example.cpp . Is that not a problem? Are those tests on for something cmake specific? Or it would benefit to add them later ( don't have to be this PR, we can track that in a different PR)

cmake output from github workflow -

Run ctest -C $BUILD_TYPE --output-on-failure
Test project /home/runner/work/cxxopts/cxxopts/build/test
    Start 1: options
1/3 Test #1: options ..........................   Passed    0.00 sec
    Start 2: find-package-test
2/3 Test #2: find-package-test ................   Passed    6.45 sec
    Start 3: add-subdirectory-test
3/3 Test #3: add-subdirectory-test ............   Passed    6.26 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =  12.73 sec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The find-package test relies on having the cmake config files. Meson can generate very simple cmake files, but not using targets like cxxopts does, but we haven't put effort into generating more complex ones because CMake itself is migrating away from that toward CPS, and we are also working on CPS support, so there isn't really a good way for me to implement it.

The add-subdirectory test doesn't make a lot of sense for Meson either, as Meson has always had a feature more like CMake's ExternalProject, and doesn't allow external projects to be added as a subdirectory. I could potentially add a test to use cxxopts via a subproject call (roughly equivalent to ExternalProject), if you'd like.

@dcbaker dcbaker force-pushed the submit/meson branch 8 times, most recently from 6033252 to 3436819 Compare January 7, 2026 18:07
I've tried to be a bit more minimal here than the CMake tests are, since
there's already a good cross section of testing there. For Meson, I just
want to touch test each of the major platforms to ensure that it works
@dcbaker
Copy link
Contributor Author

dcbaker commented Jan 7, 2026

Latest version includes building with ICU support on and off on Ubuntu, as well as running the example on Ubuntu.

I can add tests to toggle examples on and off, as well as turning the warnings off, they're both currently turned on by default

Copy link
Contributor

@lazysegtree lazysegtree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants