mirror of
https://github.com/nlohmann/json.git
synced 2026-10-03 21:20:30 +00:00
Fix the Meson CMake target for includedir or datadir outside the prefix
nlohmann_jsonTargets.cmake always prepended the prefix computed from the file's location to includedir. With an absolute includedir outside the prefix (as Nix passes for packages with a separate dev output), this gave "<prefix>//abs/include"; with an absolute datadir outside the prefix, the number of ".." was derived from the absolute path and the prefix resolved to "/". In both cases find_package(nlohmann_json) failed with "Imported target includes non-existent path". Use the absolute include directory in these cases, as CMake's install(EXPORT) does, and check it in CI. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
# do that, but as the library is header-only, the target only needs an include
|
||||
# directory, the C++ standard, and the compile definitions of the options that
|
||||
# differ from their defaults. Paths are computed relative to this file so that
|
||||
# the installation can be relocated (e.g., into a sysroot).
|
||||
# the installation can be relocated (e.g., into a sysroot), unless includedir or
|
||||
# datadir is outside the prefix.
|
||||
|
||||
if(TARGET @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@)
|
||||
return()
|
||||
@@ -14,7 +15,7 @@ get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}/@NLOHMANN_JSON_
|
||||
|
||||
add_library(@PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@ INTERFACE IMPORTED)
|
||||
set_target_properties(@PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@ PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/@NLOHMANN_JSON_INCLUDE_INSTALL_DIR@"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "@NLOHMANN_JSON_INCLUDE_DIR@"
|
||||
)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.8)
|
||||
set_target_properties(@PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@ PROPERTIES
|
||||
|
||||
Reference in New Issue
Block a user