Skip to content

Commit c2d84ce

Browse files
committed
fix(json): avoid exporting nlohmann_json target and use header-only fallback safely for install/export
2 parents 9aacd4c + 8d8b092 commit c2d84ce

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ target_include_directories(vix_json INTERFACE
4646
)
4747

4848
set(_VIX_JSON_PROVIDER "none")
49+
set(_VIX_JSON_INSTALL_FALLBACK OFF)
4950

5051
find_package(nlohmann_json QUIET CONFIG)
5152
if (nlohmann_json_FOUND)
@@ -67,15 +68,14 @@ else()
6768
)
6869
FetchContent_MakeAvailable(nlohmann_json_fallback)
6970

70-
if (NOT TARGET nlohmann_json::nlohmann_json)
71-
add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
72-
target_include_directories(nlohmann_json::nlohmann_json INTERFACE
73-
$<BUILD_INTERFACE:${nlohmann_json_fallback_SOURCE_DIR}/single_include>
74-
)
75-
endif()
71+
# Do NOT link fetched nlohmann target into exported install interface.
72+
# Just expose its headers during the build.
73+
target_include_directories(vix_json INTERFACE
74+
$<BUILD_INTERFACE:${nlohmann_json_fallback_SOURCE_DIR}/single_include>
75+
)
7676

77-
target_link_libraries(vix_json INTERFACE nlohmann_json::nlohmann_json)
7877
set(_VIX_JSON_PROVIDER "nlohmann_json (fetched header-only)")
78+
set(_VIX_JSON_INSTALL_FALLBACK ON)
7979
endif()
8080
endif()
8181

@@ -107,8 +107,17 @@ install(DIRECTORY include/
107107
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h"
108108
)
109109

110+
# If using fetched fallback, install nlohmann headers too.
111+
if (_VIX_JSON_INSTALL_FALLBACK)
112+
install(
113+
DIRECTORY "${nlohmann_json_fallback_SOURCE_DIR}/single_include/nlohmann"
114+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
115+
FILES_MATCHING PATTERN "*.hpp"
116+
)
117+
endif()
118+
110119
install(TARGETS vix_json
111-
EXPORT VixTargets # <- join umbrella export-set
120+
EXPORT VixTargets
112121
)
113122

114123
# Status

0 commit comments

Comments
 (0)