marzer / tomlplusplus

Header-only TOML config file parser and serializer for C++17.
https://marzer.github.io/tomlplusplus/
MIT License
1.58k stars 152 forks source link

Installation and use with Meson doesn't seem to work #217

Closed HealthyPear closed 9 months ago

HealthyPear commented 10 months ago

Environment

toml++ version and/or commit hash:

3.3.0 from meson subproject

Compiler:

Apple Clang 13

C++ standard mode:

not sure, the default one

Target arch:

x86_64

Library configuration overrides:

Relevant compilation flags:

Describe the bug

../main.cxx:2:10: fatal error: 'toml++/toml.hpp' file not found
#include <toml++/toml.hpp>

wheremain.cxx is this example

Steps to reproduce (or a small repro code sample)

Follow the instructions and use the following build configuration

meson.build

project('test_tomlplusplus', 'cpp')

tomlplusplus = dependency('tomlplusplus')

executable('main', 'main.cxx', dependencies : tomlplusplus)

then compile with meson compile -C build

Additional information

This is my meson setup output

The Meson build system
Version: 1.3.1
Source dir: /Users/michele/Documents/Programming/test_tomlplusplus
Build dir: /Users/michele/Documents/Programming/test_tomlplusplus/build_meson
Build type: native build
Project name: test_tomlplusplus
Project version: undefined
C++ compiler for the host machine: c++ (clang 13.0.0 "Apple clang version 13.0.0 (clang-1300.0.29.30)")
C++ linker for the host machine: c++ ld64 711
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: YES (/usr/local/bin/pkg-config) 0.29.2
Found CMake: /usr/local/bin/cmake (3.28.1)
Run-time dependency tomlplusplus found: NO (tried pkgconfig, framework and cmake)
Looking for a fallback subproject for the dependency tomlplusplus

Executing subproject tomlplusplus

tomlplusplus| Project name: tomlplusplus
tomlplusplus| Project version: 3.3.0
tomlplusplus| C++ compiler for the host machine: c++ (clang 13.0.0 "Apple clang version 13.0.0 (clang-1300.0.29.30)")
tomlplusplus| C++ linker for the host machine: c++ ld64 711
tomlplusplus| Message: target cpu_family: x86_64
tomlplusplus| Message: target cpu: x86_64
tomlplusplus| Message: target system: darwin
tomlplusplus| Message: target endian: little
tomlplusplus| Compiler for C++ supports arguments -ferror-limit=5: YES
tomlplusplus| Compiler for C++ supports arguments -fmax-errors=5: NO
tomlplusplus| Compiler for C++ supports arguments -Wno-unused-command-line-argument: YES
tomlplusplus| Compiler for C++ supports arguments -Wno-reserved-macro-identifier: NO
tomlplusplus| Compiler for C++ supports arguments -Wno-init-list-lifetime: NO
tomlplusplus| Compiler for C++ supports arguments -fchar8_t: YES
tomlplusplus| Compiler for C++ supports arguments /bigobj: NO
tomlplusplus| Compiler for C++ supports arguments /Gy: NO
tomlplusplus| Compiler for C++ supports arguments /GF: NO
tomlplusplus| Compiler for C++ supports arguments /openmp-: NO
tomlplusplus| Compiler for C++ supports arguments /permissive-: NO
tomlplusplus| Compiler for C++ supports arguments /utf-8: NO
tomlplusplus| Compiler for C++ supports arguments /volatile:iso: NO
tomlplusplus| Compiler for C++ supports arguments /Zc:__cplusplus: NO
tomlplusplus| Compiler for C++ supports arguments /Zc:inline: NO
tomlplusplus| Compiler for C++ supports arguments /Zc:externConstexpr: NO
tomlplusplus| Compiler for C++ supports arguments /Zc:preprocessor: NO
tomlplusplus| Compiler for C++ supports arguments /Zc:throwingNew: NO
tomlplusplus| Compiler for C++ supports arguments -D_HAS_EXCEPTIONS=1: YES
tomlplusplus| Compiler for C++ supports arguments -Wno-c++98-compat: YES
tomlplusplus| Compiler for C++ supports arguments -Wno-c++98-compat-pedantic: YES
tomlplusplus| Compiler for C++ supports arguments -Wno-documentation: YES
tomlplusplus| Compiler for C++ supports arguments -Wno-documentation-unknown-command: YES
tomlplusplus| Compiler for C++ supports arguments -Wno-switch-enum: YES
tomlplusplus| Compiler for C++ supports arguments -Wno-covered-switch-default: YES
tomlplusplus| Compiler for C++ supports arguments -Wno-padded: YES
tomlplusplus| Compiler for C++ supports arguments -Wno-float-equal: YES
tomlplusplus| Compiler for C++ supports arguments -DTOML_HEADER_ONLY=0: YES
tomlplusplus| Compiler for C++ supports arguments -DTOML_SHARED_LIB=1: YES
tomlplusplus| Build targets in project: 1
tomlplusplus| Subproject tomlplusplus finished.

Dependency tomlplusplus found: YES 3.3.0 (overridden)
Build targets in project: 2

test_tomlplusplus undefined

  Subprojects
    tomlplusplus: YES

Found ninja-1.11.1 at /usr/local/bin/ninja

while the following is the (working) CMake configuration

cmake_minimum_required(VERSION 3.27)

project(test_tomlplusplus)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

include(FetchContent)
FetchContent_Declare(
    tomlplusplus
    GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
    GIT_TAG v3.4.0
)
FetchContent_MakeAvailable(tomlplusplus)

add_executable(main main.cxx)

# target_link_libraries(main PUBLIC tomlplusplus)
target_include_directories(main PUBLIC
    ${tomlplusplus_SOURCE_DIR}/include
)
marzer commented 10 months ago

Just to be clear, are you trying to use it after installing it system-wide, or as a meson subproject? You mention both "installation" and "subproject" above, so I'm not sure.

If you're using it as a subproject it should work (that's how I use it myself in a few other projects), though it could be that the example snippet is incorrect. Try this instead:

tomlplusplus = subproject('tomlplusplus').get_variable('tomlplusplus_dep')

alternatively this might also work:

tomlplusplus = dependency('tomlplusplus_dep')
HealthyPear commented 10 months ago

I just followed the instructions here https://marzer.github.io/tomlplusplus/#mainpage-adding-lib-meson

so I have the wrap file and all seems to be in place under the subprojects folder

Unfortunately your updated snippet gives me the same error - it cannot find your library headers

HealthyPear commented 10 months ago
[1/2] Compiling C++ object main.p/main.cxx.o
FAILED: main.p/main.cxx.o
c++ -Imain.p -I. -I.. -Isubprojects/tomlplusplus-3.3.0/include -I../subprojects/tomlplusplus-3.3.0/include -fdiagnostics-color=always -Wall -Winvalid-pch -O0 -g -DTOML_HEADER_ONLY=0 -DTOML_SHARED_LIB=1 -MD -MQ main.p/main.cxx.o -MF main.p/main.cxx.o.d -o main.p/main.cxx.o -c ../main.cxx
../main.cxx:2:10: fatal error: 'toml++/toml.hpp' file not found
#include <toml++/toml.hpp>
         ^~~~~~~~~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.
HealthyPear commented 10 months ago

I am using meson 1.3.1 always from Homebrew if it can be of any help

unfortunately I am quite ignorant about C++/CMake/Meson...

marzer commented 10 months ago

I am quite ignorant about C++/CMake/Meson...

Yeah, me too 😅

Unfortunately your updated snippet gives me the same error

Hmmmn. Let me look into it.

marzer commented 10 months ago

So I just did this:

shell:

meson wrap install tomlplusplus

meson.build:

project('test_tomlplusplus', 'cpp')

tomlplusplus = dependency('tomlplusplus')

executable('main', 'main.cxx', dependencies : tomlplusplus)

locally in a test project and it worked fine? I don't know where else to go from here.

marzer commented 10 months ago

what is the output of meson wrap status? e.g.

> meson wrap status
Subproject status
 tomlplusplus up to date. Branch 3.3.0, revision 1.
HealthyPear commented 10 months ago

Subproject status tomlplusplus up to date. Branch 3.3.0, revision 1.

seems to be exactly the same

could you zip and share here your test project? maybe I made a mistake elsewhere?

marzer commented 10 months ago

Ohhhh wait, I know what's happening. That's 3.3.0, which didn't have toml.hpp - I added that in 3.4.0. change your include to this:

#include <toml++/toml.h>

Totally my fault :) ideally the wrap should have been updated, but I haven't gotten around to it.

marzer commented 10 months ago

(there's no difference between the two headers - one just includes the other. I added the .hpp version in v3.4.0 to be more idiomatic C++.)

HealthyPear commented 10 months ago

Thanks that was indeed the issue here!

I suggest adding a note about this to the docs then.

Also, if it can be of any help, in my case (arch+compiler) I had to explicitly use 'cpp_std=c++17' as a default option otherwise a ton of other error pop out (but that might be only my setup)

HealthyPear commented 10 months ago

To be fair, I now went into the subproject source and I see the .hpp file, it's just not in the include directory but rather the top-level, together with the README

marzer commented 10 months ago

I suggest adding a note about this to the docs then.

Yep. I should flag this as a <= 3.3.0, >= 3.4.0 thing.

Also, if it can be of any help, in my case (arch+compiler) I had to explicitly use 'cpp_std=c++17' as a default option otherwise a ton of other error pop out (but that might be only my setup)

Well yeah, it's a C++17 project. Meson doesn't propagate the minimum C++ version up from dependencies (that I'm aware of, anyway) - it expects you to be explicit here. If you don't provide a value for cpp_std it'll just be whatever your compiler's default is (often C++14 these days). See Meson: Compiler options for detail.

To be fair, I now went into the subproject source and I see the .hpp file, it's just not in the include directory but rather the top-level, together with the README

Yeah, that's the single-include version, with the entire library in one file. That's always been there. In v3.4.0 I added a 'normal' version of toml.hpp in the same directory as toml.h. (having different file extensions for the two different ways of including the library was a dumb historical mistake on my part, so I fixed it in v3.4.0.)

HealthyPear commented 10 months ago

Would you say it's safer to include the .h also for 3.4.0 until the wrap is updated?

marzer commented 10 months ago

Yep, the .h version isn't going anywhere :)

eli-schwartz commented 10 months ago

Just to be clear, are you trying to use it after installing it system-wide, or as a meson subproject? You mention both "installation" and "subproject" above, so I'm not sure.

If you're using it as a subproject it should work (that's how I use it myself in a few other projects), though it could be that the example snippet is incorrect. Try this instead:

tomlplusplus = subproject('tomlplusplus').get_variable('tomlplusplus_dep')

This is the old style, for when your wrap file doesn't support [provide].

alternatively this might also work:

tomlplusplus = dependency('tomlplusplus_dep')

This doesn't work at all, since tomlplusplus_dep is a meson.build script variable, not the name of a registered dependency.

...

The documentation suggests this:

tomlplusplus_dep = dependency('tomlplusplus')

which works fine, but could be improved a bit:

tomlplusplus_dep = dependency('tomlplusplus', version: '>=3.4.0')

since that will guarantee having "at least version 3.4.0", and that's something you want in order to provide consistency and reliability e.g. in terms of header include name. Plus, many of the examples for adding it to your project include minimum requirements like this.

marzer commented 10 months ago

Thanks for the clarifications @eli-schwartz 😃

marzer commented 9 months ago

The header include has been fixed in the documentation, as now there's a version selector - it'll be the correct value if you switch it to v3.3.0 :)