Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring Meson build definition more in line with CMake #4452

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

dcbaker
Copy link
Contributor

@dcbaker dcbaker commented Sep 9, 2024

Update the Meson build definition to use Meson best practices, and bring into alignment with the CMake build files.

Particularly, This changes the meson build to only expose a single target, like the CMake does, controlled by an option with the same name. It additionally exposes the GlobalUDLs and ImplicitConversions options, which have behavioral implementations a consumer may wish to control. I have not exposed other options as they don't seem to be important for behavior.

The options names do not have the JSON_ prefix, and Meson already has (sub)project option namespaces, so adding JSON_ would worse (-Dnlohmann_json:ImplicitConversions vs -Dnlohmann_json:JSON_ImplicitConversions).

Pull request checklist

Read the Contribution Guidelines for detailed information.

  • Changes are described in the pull request, or an existing issue is referenced.
  • The test suite compiles and runs without error.
  • Code coverage is 100%. Test cases can be added by editing the test suite.
  • The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header files single_include/nlohmann/json.hpp and single_include/nlohmann/json_fwd.hpp. The whole process is described here.

meson.build Outdated Show resolved Hide resolved
@dcbaker dcbaker force-pushed the submit/meson-updates branch 2 times, most recently from 5b5adfe to b65e362 Compare September 9, 2024 20:20
@nlohmann
Copy link
Owner

Is meson_options.txt really needed? If so, can it be moved into a subdirectory?

@dcbaker
Copy link
Contributor Author

dcbaker commented Sep 13, 2024

Meson options must be specified in a meson_options.txt (or for fairly new versions of Meson in a meson.options file), and that file has to be in the same directory as the root meson.build file. Meson options are read-only from the meson.build files, and are read in before the parsing of the meson.build file starts.

Copy link

This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!

@github-actions github-actions bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Jan 19, 2025
@dcbaker
Copy link
Contributor Author

dcbaker commented Jan 19, 2025

I know that the meson_options.txt seems to be a blocker here, if I opened a new PR with the patches up until meson_options.txt is added, would that allow those changes to move faster?

@nlohmann
Copy link
Owner

How is this related to #3885?

@dcbaker
Copy link
Contributor Author

dcbaker commented Jan 19, 2025

It's not at all. I can comment there.

@nlohmann
Copy link
Owner

Please do - I don't know Meson and will not be able to solve any of these issues.

@github-actions github-actions bot removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Jan 20, 2025
@heitbaum
Copy link

This PR improves the meson build significantly. All the headers are now being installed. It doesn’t address the .cmake files (but that is a seperate issue.)

it would be good to see this merged.

#3885 (comment)

./usr/lib/pkgconfig/nlohmann_json.pc
./usr/include/nlohmann/detail/string_concat.hpp
./usr/include/nlohmann/detail/string_escape.hpp
./usr/include/nlohmann/detail/value_t.hpp
./usr/include/nlohmann/detail/macro_scope.hpp
./usr/include/nlohmann/detail/abi_macros.hpp
./usr/include/nlohmann/detail/iterators/iter_impl.hpp
./usr/include/nlohmann/detail/iterators/primitive_iterator.hpp
./usr/include/nlohmann/detail/iterators/json_reverse_iterator.hpp
./usr/include/nlohmann/detail/iterators/iteration_proxy.hpp
./usr/include/nlohmann/detail/iterators/iterator_traits.hpp
./usr/include/nlohmann/detail/iterators/internal_iterator.hpp
./usr/include/nlohmann/detail/hash.hpp
./usr/include/nlohmann/detail/input/lexer.hpp
./usr/include/nlohmann/detail/input/json_sax.hpp
./usr/include/nlohmann/detail/input/input_adapters.hpp
./usr/include/nlohmann/detail/input/position_t.hpp
./usr/include/nlohmann/detail/input/binary_reader.hpp
./usr/include/nlohmann/detail/input/parser.hpp
./usr/include/nlohmann/detail/exceptions.hpp
./usr/include/nlohmann/detail/json_custom_base_class.hpp
./usr/include/nlohmann/detail/conversions/to_json.hpp
./usr/include/nlohmann/detail/conversions/from_json.hpp
./usr/include/nlohmann/detail/conversions/to_chars.hpp
./usr/include/nlohmann/detail/json_ref.hpp
./usr/include/nlohmann/detail/output/serializer.hpp
./usr/include/nlohmann/detail/output/binary_writer.hpp
./usr/include/nlohmann/detail/output/output_adapters.hpp
./usr/include/nlohmann/detail/json_pointer.hpp
./usr/include/nlohmann/detail/meta/is_sax.hpp
./usr/include/nlohmann/detail/meta/type_traits.hpp
./usr/include/nlohmann/detail/meta/identity_tag.hpp
./usr/include/nlohmann/detail/meta/detected.hpp
./usr/include/nlohmann/detail/meta/cpp_future.hpp
./usr/include/nlohmann/detail/meta/void_t.hpp
./usr/include/nlohmann/detail/meta/call_std/end.hpp
./usr/include/nlohmann/detail/meta/call_std/begin.hpp
./usr/include/nlohmann/detail/meta/std_fs.hpp
./usr/include/nlohmann/detail/macro_unscope.hpp
./usr/include/nlohmann/adl_serializer.hpp
./usr/include/nlohmann/json_fwd.hpp
./usr/include/nlohmann/thirdparty/hedley/hedley_undef.hpp
./usr/include/nlohmann/thirdparty/hedley/hedley.hpp
./usr/include/nlohmann/ordered_map.hpp
./usr/include/nlohmann/json.hpp
./usr/include/nlohmann/byte_container_with_subtype.hpp

@nlohmann nlohmann added the please rebase Please rebase your branch to origin/develop label Jan 20, 2025
@dcbaker dcbaker force-pushed the submit/meson-updates branch from b65e362 to 7f44940 Compare January 20, 2025 19:50
@github-actions github-actions bot removed the CMake label Jan 20, 2025
for better readability

Signed-off-by: Dylan Baker <[email protected]>
Without a version set meson will give no developer warnings, including
deprecations. 0.64 was selected as it's quite old, it's the newest
version supported by muon (a pure C Meson implementation), and there's
nothing complicated going on here.

Signed-off-by: Dylan Baker <[email protected]>
This simplifies the use of json as a subproject.

Signed-off-by: Dylan Baker <[email protected]>
This makes a single call to install the entire directory, and doesn't
need an update if any new headers are added. It also will simplify
bringing the Meson and CMake builds into allignment on how they handle
the multi-header vs single-header setups.

Signed-off-by: Dylan Baker <[email protected]>
Matching the CMake as closely as possible, as Meson doesn't have C++11
feature checks like CMAke does.

Signed-off-by: Dylan Baker <[email protected]>
This uses a meson option (set in `meson_options.txt`) to control whether
multi-header or single-header setup is wanted.

Signed-off-by: Dylan Baker <[email protected]>
@dcbaker dcbaker force-pushed the submit/meson-updates branch from 7f44940 to e40b32d Compare January 20, 2025 19:52
@dcbaker
Copy link
Contributor Author

dcbaker commented Jan 20, 2025

I've rebased on the current develop branch to fix conflicts and added my signed-off-by

@coveralls
Copy link

Coverage Status

coverage: 99.186%. remained the same
when pulling e40b32d on dcbaker:submit/meson-updates
into 8c7dcd3 on nlohmann:develop.

@nlohmann nlohmann removed the please rebase Please rebase your branch to origin/develop label Jan 20, 2025
Copy link
Owner

@nlohmann nlohmann left a comment

Choose a reason for hiding this comment

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

Please also document meson.build and meson_options.txt in FILES.md.

'MultipleHeaders',
type: 'boolean',
value: true,
description: 'Use non-amalgomated version of the library',
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
description: 'Use non-amalgomated version of the library',
description: 'Use non-amalgamated version of the library',

type: 'boolean',
value: true,
description: 'Enable implicit conversions',
)
Copy link
Owner

Choose a reason for hiding this comment

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

There are more flags, see https://json.nlohmann.me/integration/cmake/#cmake-options for example. Though not are equally interesting, I wonder why here only theres three have been selected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's been a while, I remember for sure that the MultipleHeaders option is essential to get the same behavior out of Meson and CMake, especially when using the Meson definitions in an embedded project. I don't remember why I added the other two.

Copy link
Contributor Author

@dcbaker dcbaker Jan 27, 2025

Choose a reason for hiding this comment

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

@nlohmann: I looked more, and I'm pretty sure that the reason that I added those two options in particular is that the related defines are exposed publicly in the pkg-config file. So for Meson and CMake to generate equivalent .pc files we'd need that.

Now that I'm looking at the generated CMake Target, it looks like JSON_DISABLE_ENUM_SERIALIZATION, JSON_DIAGNOSTICS, JSON_DIAGNOSTIC_POSITIONS, and JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON are exposed in CMake, so maybe we should update the pkg-config CMake generates to expose those as well?

Copy link
Owner

Choose a reason for hiding this comment

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

Sounds plausible, but I would not know how :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants