pboettch / json-schema-validator

JSON schema validator for JSON for Modern C++
Other
466 stars 134 forks source link

Cmake FetchContent not working with new tagged version #250

Closed HenriqueCA closed 1 year ago

HenriqueCA commented 1 year ago

I tried to use Cmake FetchContent to download nlohmann_json and this repository. When i tried using the new tagged version (2.2.0) from the validator, it presented this error:

CMake Error: install(EXPORT "nlohmann_json_schema_validatorTargets" ...) includes target "nlohmann_json_schema_validator" which requires target "nlohmann_json" that is not in any export set.

Below is the code used to download both repositories:

include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
FetchContent_MakeAvailable(json)

FetchContent_Declare(nlohmann_json_schema_validator URL https://github.com/pboettch/json-schema-validator/archive/refs/tags/2.2.0.tar.gz)
FetchContent_MakeAvailable(nlohmann_json_schema_validator)

Workaround: Change the version of json-schema-validator to 2.1.0. It will find nlohman_json and link with it.

Kuxe commented 1 year ago

I get this exact error with 2.2.0 as well, using FetchContent_Declare and FetchContent_Populate (instead of FetchContent_MakeAvailable). I can confirm that downgrading to 2.1.0 works.

HenriqueCA commented 1 year ago

If you set the Cmake Variable "JSON_Install" to ON, it will work with version 2.2.0, using FetchContent_MakeAvailable set(JSON_Install ON)

LecrisUT commented 1 year ago

Try out #262. It should fix it at least if you are not trying to further install nlohmann_json_schema_validator after you have FetchContent it.


This is a design problem that I am trying to get some clarification. On one hand json-schema-validator needs nlohmann_json because it is used as an #include in the exported header. On the other hand it is bad practice to install something that is not the project that you are declaring. So for the moment the installation of nlohmann_json_schema_validator I have it set to JSON_Install=ON to make it installable, but it should be fixed as soon as possible.