Skip to content

CMake: Install toml11 and nlohmann_json for inclusion in downstream code #1757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
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
)
")
endif()
if(TARGET fetchedtoml11-install)
install(CODE "
execute_process(
COMMAND ${CMAKE_COMMAND} \
--build \"${CMAKE_BINARY_DIR}\" \
--target fetchedtoml11-install
)
")
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