Skip to content
Closed
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,24 @@ if(openPMD_INSTALL)
RUNTIME DESTINATION ${openPMD_INSTALL_BINDIR}
INCLUDES DESTINATION ${openPMD_INSTALL_INCLUDEDIR}
)
if(TARGET fetchednlohmann_json-install)
install(CODE "
execute_process(
COMMAND ${CMAKE_COMMAND} \
--build \"${CMAKE_BINARY_DIR}\" \
--target fetchednlohmann_json-install
)
")
Comment on lines +1080 to +1086

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far, I have intentionally turned the install of sub-projects off. Instead of this code, we could set JSON_Install ON:

https://github.com/nlohmann/json/blob/v3.12.0/CMakeLists.txt#L48

Comment on lines +1080 to +1086

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different question: Why would you hack together a manual installation here? Isn't it conceptually closer to what you want to express to link to json/toml11 publicly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See Axel's comment above; this did not work because I was not aware about CMake options in nlohmann-json/toml11 which we set to suppress installations.
I'm only leaving this PR open rn because we might in future add nlohmann-json/toml11 functionality to our public API, in which case we would need to install these libraries somehow along with the main library. There is at the moment no concrete plan to work on this further.

endif()
if(TARGET fetchedtoml11-install)
install(CODE "
execute_process(
COMMAND ${CMAKE_COMMAND} \
--build \"${CMAKE_BINARY_DIR}\" \
--target fetchedtoml11-install
Comment on lines +1089 to +1093

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TOML11_INSTALL is the equivalent option there:
https://github.com/ToruNiina/toml11/blob/v4.4.0/CMakeLists.txt#L27-L28

)
")
endif()
if(openPMD_HAVE_PYTHON)
install(
DIRECTORY ${openPMD_SOURCE_DIR}/src/binding/python/openpmd_api
Expand Down
23 changes: 23 additions & 0 deletions cmake/dependencies/json.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ function(find_json)
if(NOT IS_DIRECTORY ${openPMD_json_src})
message(FATAL_ERROR "Specified directory openPMD_json_src='${openPMD_json_src}' does not exist!")
endif()
set(openPMD_used_json_src "${openPMD_json_src}")
elseif(openPMD_json_tar)
message(STATUS "Downloading nlohmann_json ...")
message(STATUS "nlohmann_json source: ${openPMD_json_tar}")
set(openPMD_used_json_src "_deps/fetchednlohmann_json-src/")
elseif(openPMD_json_branch)
message(STATUS "Downloading nlohmann_json ...")
message(STATUS "nlohmann_json repository: ${openPMD_json_repo} (${openPMD_json_branch})")
set(openPMD_used_json_src "_deps/fetchednlohmann_json-src/")
endif()
endif()
if(TARGET nlohmann_json::nlohmann_json)
Expand Down Expand Up @@ -48,6 +51,26 @@ function(find_json)
find_package(nlohmann_json 3.9.1 CONFIG REQUIRED)
message(STATUS "nlohmann_json: Found version '${nlohmann_json_VERSION}'")
endif()

if(DEFINED openPMD_used_json_src)
include(ExternalProject)
set(cmake_args -DJSON_BuildTests=OFF)
if(NOT DEFINED CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
OR NOT ${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
cmake_path(
ABSOLUTE_PATH openPMD_INSTALL_PREFIX
BASE_DIRECTORY "${openPMD_BINARY_DIR}"
OUTPUT_VARIABLE openPMD_resolved_install_prefix)
list(APPEND cmake_args -DCMAKE_INSTALL_PREFIX=${openPMD_resolved_install_prefix})
endif()
ExternalProject_Add(fetchednlohmann_json
SOURCE_DIR ${openPMD_used_json_src}
BUILD_IN_SOURCE OFF
EXCLUDE_FROM_ALL TRUE
CMAKE_ARGS ${cmake_args}
STEP_TARGETS install
)
endif()
endfunction()

# local source-tree
Expand Down
22 changes: 22 additions & 0 deletions cmake/dependencies/toml11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ function(find_toml11)
if(NOT IS_DIRECTORY ${openPMD_toml11_src})
message(FATAL_ERROR "Specified directory openPMD_toml11_src='${openPMD_toml11_src}' does not exist!")
endif()
set(openPMD_used_toml11_src "${openPMD_toml11_src}")
elseif(openPMD_toml11_tar)
message(STATUS "Downloading toml11 ...")
message(STATUS "toml11 source: ${openPMD_toml11_tar}")
set(openPMD_used_toml11_src "_deps/fetchedtoml11-src/")
elseif(openPMD_toml11_branch)
message(STATUS "Downloading toml11 ...")
message(STATUS "toml11 repository: ${openPMD_toml11_repo} (${openPMD_toml11_branch})")
set(openPMD_used_toml11_src "_deps/fetchedtoml11-src/")
endif()
endif()
if(TARGET toml11::toml11)
Expand Down Expand Up @@ -56,6 +59,25 @@ function(find_toml11)
endif()
message(STATUS "toml11: Found version '${toml11_VERSION}'")
endif()

if(DEFINED openPMD_used_toml11_src)
include(ExternalProject)
set(cmake_args "")
if(NOT DEFINED CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR NOT ${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
cmake_path(
ABSOLUTE_PATH openPMD_INSTALL_PREFIX
BASE_DIRECTORY "${openPMD_BINARY_DIR}"
OUTPUT_VARIABLE openPMD_resolved_install_prefix)
list(APPEND cmake_args -DCMAKE_INSTALL_PREFIX=${openPMD_resolved_install_prefix})
endif()
ExternalProject_Add(fetchedtoml11
SOURCE_DIR ${openPMD_used_toml11_src}
BUILD_IN_SOURCE OFF
EXCLUDE_FROM_ALL TRUE
CMAKE_ARGS ${cmake_args}
STEP_TARGETS install
)
endif()
endfunction()

# local source-tree
Expand Down
Loading