@@ -24,57 +24,54 @@ endif()
2424
2525# Handle nlohmann_json dependency
2626if (DEVDAT_USE_SYSTEM_JSON)
27- find_package (nlohmann_json REQUIRED)
28- set (JSON_TARGET nlohmann_json::nlohmann_json)
27+ # Check if JSON_INCLUDE_DIR is provided by the superbuild
28+ if (DEFINED JSON_INCLUDE_DIR)
29+ message (STATUS "Using JSON include directory provided by superbuild: ${JSON_INCLUDE_DIR} " )
30+ # Simple interface library to handle the include directory
31+ add_library (json_interface INTERFACE )
32+ target_include_directories (json_interface INTERFACE ${JSON_INCLUDE_DIR} )
33+ set (JSON_TARGET json_interface)
34+ else ()
35+ # Find system package
36+ message (STATUS "Finding system nlohmann_json package" )
37+ find_package (nlohmann_json REQUIRED)
38+ set (JSON_TARGET nlohmann_json::nlohmann_json)
39+ endif ()
2940else ()
30- # Download nlohmann_json at configure time
41+ # Fetch our own copy
42+ message (STATUS "Fetching nlohmann_json" )
3143 include (FetchContent)
3244 FetchContent_Declare(
3345 nlohmann_json
3446 GIT_REPOSITORY https://github.com/nlohmann/json.git
3547 GIT_TAG v3.11.2
3648 )
3749 FetchContent_MakeAvailable(nlohmann_json)
50+ set (JSON_TARGET nlohmann_json::nlohmann_json)
3851
39- # Create our own interface that doesn't need to be exported
40- add_library (devdat_json_dep INTERFACE )
41- target_include_directories (devdat_json_dep
42- INTERFACE
43- $<BUILD_INTERFACE:${nlohmann_json_SOURCE_DIR} /include >
44- # Important: This is how consumers will find the headers
45- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
46- )
47-
48- # Install the nlohmann_json headers directly to include directory
49- # This ensures they're found alongside our own headers
50- install (
51- DIRECTORY ${nlohmann_json_SOURCE_DIR} /include /
52- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
53- )
54-
55- set (JSON_TARGET devdat_json_dep)
52+ # Note: When not using system JSON, we'll need to ensure the headers are installed
53+ set (INSTALL_JSON_HEADERS TRUE )
5654endif ()
5755
5856# Create the library (header-only)
5957add_library (devdat INTERFACE )
6058
61- # Set target properties (note: header-only libraries use INTERFACE)
59+ # Set target properties
6260target_include_directories (devdat
6361 INTERFACE
6462 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >
6563 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
66- $<BUILD_INTERFACE:${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} >
67- $<INSTALL_INTERFACE:${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} >
64+ ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
6865)
6966
70- # Link dependencies (using our local target and CUDA)
67+ # Link dependencies
7168target_link_libraries (devdat
7269 INTERFACE
7370 ${JSON_TARGET}
7471 CUDA::toolkit
7572)
7673
77- # Add an alias target for use within the build tree
74+ # Add an alias target
7875add_library (${PROJECT_NAME} ::devdat ALIAS devdat)
7976
8077# Installation
@@ -87,16 +84,24 @@ install(
8784 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
8885)
8986
90- # Install the target (note: header-only libraries have special install syntax)
87+ # If we fetched JSON and need to install the headers
88+ if (DEFINED INSTALL_JSON_HEADERS)
89+ install (
90+ DIRECTORY ${nlohmann_json_SOURCE_DIR} /include /
91+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
92+ )
93+ endif ()
94+
95+ # Install the target
9196install (
9297 TARGETS devdat
9398 EXPORT ${PROJECT_NAME} Targets
9499)
95100
96- if ( NOT DEVDAT_USE_SYSTEM_JSON)
97- # Add our bundled dependency to the exported targets
101+ # If using a custom JSON interface target, install it too
102+ if (DEVDAT_USE_SYSTEM_JSON AND DEFINED JSON_INCLUDE_DIR)
98103 install (
99- TARGETS devdat_json_dep
104+ TARGETS json_interface
100105 EXPORT ${PROJECT_NAME} Targets
101106 )
102107endif ()
@@ -111,8 +116,6 @@ install(
111116
112117# Create config files
113118include (CMakePackageConfigHelpers)
114-
115- # Create a config file that handles dependencies
116119configure_file (
117120 ${CMAKE_CURRENT_SOURCE_DIR} /cmake/devdatConfig.cmake.in
118121 ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} Config.cmake
0 commit comments