Skip to content

Commit 0454866

Browse files
committed
getting rid of json complexity
1 parent 1a2d412 commit 0454866

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

CMakeLists.txt

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,54 @@ endif()
2424

2525
# Handle nlohmann_json dependency
2626
if(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()
2940
else()
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)
5654
endif()
5755

5856
# Create the library (header-only)
5957
add_library(devdat INTERFACE)
6058

61-
# Set target properties (note: header-only libraries use INTERFACE)
59+
# Set target properties
6260
target_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
7168
target_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
7875
add_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
9196
install(
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
)
102107
endif()
@@ -111,8 +116,6 @@ install(
111116

112117
# Create config files
113118
include(CMakePackageConfigHelpers)
114-
115-
# Create a config file that handles dependencies
116119
configure_file(
117120
${CMAKE_CURRENT_SOURCE_DIR}/cmake/devdatConfig.cmake.in
118121
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake

cmake/devdatConfig.cmake.in

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ include(CMakeFindDependencyMacro)
55
# Find or load CUDA toolkit (required for Thrust)
66
find_dependency(CUDAToolkit REQUIRED)
77

8-
# Handle nlohmann_json dependency if using system version
8+
# Handle nlohmann_json dependency
99
if(@DEVDAT_USE_SYSTEM_JSON@)
10-
find_dependency(nlohmann_json REQUIRED)
10+
# Check if we used a custom include path provided by superbuild
11+
if(NOT TARGET json_interface)
12+
# We used the system package during build
13+
find_dependency(nlohmann_json REQUIRED)
14+
endif()
15+
# Otherwise, json_interface target is already defined in the Targets file
1116
endif()
1217

1318
# Include the exported targets
1419
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
1520

21+
# Provide compatibility with older FindPackage behavior
22+
set(devdat_FOUND TRUE)
23+
set(devdat_VERSION @PROJECT_VERSION@)
24+
set(devdat_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../../include")
25+
1626
message(STATUS "Found @PROJECT_NAME@ @PROJECT_VERSION@")

0 commit comments

Comments
 (0)