Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ jobs:
script: *script-cpp-unit
# GCC 7.3.0
- <<: *test-cpp-unit
name: gcc@7.3.0 -MPI -PY +H5 +ADIOS1
name: gcc@7.3.0 -MPI -PY +H5 +ADIOS1 -JSON
language: python
python: "2.7"
env:
- CXXSPEC="%gcc@7.3.0" USE_MPI=OFF USE_PYTHON=OFF USE_HDF5=ON USE_ADIOS1=ON USE_ADIOS2=OFF USE_SAMPLES=ON
- CXXSPEC="%gcc@7.3.0" USE_MPI=OFF USE_PYTHON=OFF USE_JSON=OFF USE_HDF5=ON USE_ADIOS1=ON USE_ADIOS2=OFF USE_SAMPLES=ON
compiler: gcc
addons:
apt:
Expand Down
52 changes: 51 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ function(openpmd_option name description default)
endfunction()

openpmd_option(MPI "Enable MPI support" AUTO)
openpmd_option(JSON "Enable JSON support" AUTO)
openpmd_option(HDF5 "Enable HDF5 support" AUTO)
openpmd_option(ADIOS1 "Enable ADIOS1 support" AUTO)
openpmd_option(ADIOS2 "Enable ADIOS2 support" OFF)
#openpmd_option(JSON "Enable JSON support" AUTO)
openpmd_option(PYTHON "Enable Python bindings" AUTO)

option(openPMD_USE_INTERNAL_VARIANT "Use internally shipped MPark.Variant" ON)
option(openPMD_USE_INTERNAL_CATCH "Use internally shipped Catch2" ON)
option(openPMD_USE_INTERNAL_PYBIND11 "Use internally shipped pybind11" ON)
option(openPMD_USE_INTERNAL_JSON "Use internally shipped nlohmann-json" ON)

option(openPMD_USE_INVASIVE_TESTS "Enable unit tests that modify source code" OFF)
option(openPMD_USE_VERIFY "Enable internal VERIFY (assert) macro independent of build type" ON)
Expand Down Expand Up @@ -88,6 +89,43 @@ else()
set(openPMD_HAVE_MPI FALSE)
endif()

# external library: nlohmann-json (optional)
if(openPMD_USE_JSON STREQUAL AUTO)
if(openPMD_USE_INTERNAL_JSON)
# see https://github.com/nlohmann/json/pull/1330
set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(
"${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/json"
EXCLUDE_FROM_ALL) # does not need to be publicly installed
set(openPMD_HAVE_JSON TRUE)
message(STATUS "nlohmann-json: Using INTERNAL version 3.4.0")
else()
find_package(nlohmann_json 3.4.0 CONFIG)
if(nlohmann_json_FOUND)
set(openPMD_HAVE_JSON TRUE)
message(STATUS "nlohmann-json: Found version ${nlohmann_json_VERSION}")
else()
set(openPMD_HAVE_JSON FALSE)
endif()
endif()
elseif(openPMD_USE_JSON)
if(openPMD_USE_INTERNAL_JSON)
# see https://github.com/nlohmann/json/pull/1330
set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(
"${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/json"
EXCLUDE_FROM_ALL) # does not need to be publicly installed
set(openPMD_HAVE_JSON TRUE)
message(STATUS "nlohmann-json: Using INTERNAL version 3.4.0")
else()
find_package(nlohmann_json 3.4.0 CONFIG REQUIRED)
set(openPMD_HAVE_JSON TRUE)
message(STATUS "nlohmann-json: Found version ${nlohmann_json_VERSION}")
endif()
else()
set(openPMD_HAVE_JSON FALSE)
endif()

# external library: HDF5 (optional)
if(openPMD_USE_HDF5 STREQUAL AUTO)
set(HDF5_PREFER_PARALLEL ${openPMD_HAVE_MPI})
Expand Down Expand Up @@ -326,6 +364,14 @@ else()
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_MPI=0")
endif()

# JSON Backend
if(openPMD_HAVE_JSON)
target_link_libraries(openPMD PRIVATE nlohmann_json::nlohmann_json)
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_JSON=1")
else()
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_JSON=0")
endif()

# HDF5 Backend
if(openPMD_HAVE_HDF5)
target_link_libraries(openPMD PUBLIC ${HDF5_LIBRARIES})
Expand Down Expand Up @@ -551,6 +597,10 @@ if(BUILD_TESTING)
target_compile_definitions(${testname}Tests PUBLIC "-DopenPMD_HAVE_MPI=1")
endif()

if(openPMD_HAVE_JSON)
target_compile_definitions(${testname}Tests PUBLIC "-DopenPMD_HAVE_JSON=1")
endif()

if(openPMD_HAVE_HDF5)
target_compile_definitions(${testname}Tests PUBLIC "-DopenPMD_HAVE_HDF5=1")
endif()
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ Shipped internally in `share/openPMD/thirdParty/`:
* [MPark.Variant](https://github.com/mpark/variant) 1.3.0+ ([BSL-1.0](https://github.com/mpark/variant/blob/master/LICENSE.md))
* [Catch2](https://github.com/catchorg/Catch2) 2.3.0+ ([BSL-1.0](https://github.com/catchorg/Catch2/blob/master/LICENSE.txt))
* [pybind11](https://github.com/pybind/pybind11) 2.2.3+ ([new BSD](https://github.com/pybind/pybind11/blob/master/LICENSE))
* [NLohmann-JSON](https://github.com/nlohmann/json) 3.4.0+ ([MIT](https://github.com/nlohmann/json/blob/develop/LICENSE.MIT))

Optional I/O backends:
* [JSON](https://en.wikipedia.org/wiki/JSON) (*not yet implemented*)
* [HDF5](https://support.hdfgroup.org/HDF5) 1.8.13+
* [ADIOS1](https://www.olcf.ornl.gov/center-projects/adios) 1.13.1+
* [ADIOS2](https://github.com/ornladios/ADIOS2) 2.1+ (*not yet implemented*)
Expand Down Expand Up @@ -173,6 +175,7 @@ CMake controls options with prefixed `-D`, e.g. `-DopenPMD_USE_MPI=OFF`:
| CMake Option | Values | Description |
|------------------------------|------------------|------------------------------------------------------------------------------|
| `openPMD_USE_MPI` | **AUTO**/ON/OFF | Enable MPI support |
| `openPMD_USE_JSON` | **AUTO**/ON/OFF | Enable support for JSON <sup>1</sup> |
| `openPMD_USE_HDF5` | **AUTO**/ON/OFF | Enable support for HDF5 |
| `openPMD_USE_ADIOS1` | **AUTO**/ON/OFF | Enable support for ADIOS1 |
| `openPMD_USE_ADIOS2` | AUTO/ON/**OFF** | Enable support for ADIOS2 <sup>1</sup> |
Expand All @@ -193,6 +196,7 @@ The following options allow to switch to external installs:
| `openPMD_USE_INTERNAL_VARIANT` | **ON**/OFF | MPark.Variant | 1.3.0+ |
| `openPMD_USE_INTERNAL_CATCH` | **ON**/OFF | Catch2 | 2.3.0+ |
| `openPMD_USE_INTERNAL_PYBIND11` | **ON**/OFF | pybind11 | 2.2.3+ |
| `openPMD_USE_INTERNAL_JSON` | **ON**/OFF | NLohmann-JSON | 3.4.0+ |

By default, this will build as a static library (`libopenPMD.a`) and installs also its headers.
In order to build a static library, append `-DBUILD_SHARED_LIBS=ON` to the `cmake` command.
Expand Down
2 changes: 2 additions & 0 deletions docs/source/dev/buildoptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CMake controls options with prefixed ``-D``, e.g. ``-DopenPMD_USE_MPI=OFF``:
CMake Option Values Description
============================== =============== ========================================================================
``openPMD_USE_MPI`` **AUTO**/ON/OFF Enable MPI support
``openPMD_USE_JSON`` **AUTO**/ON/OFF Enable support for JSON :sup:`1`
``openPMD_USE_HDF5`` **AUTO**/ON/OFF Enable support for HDF5
``openPMD_USE_ADIOS1`` **AUTO**/ON/OFF Enable support for ADIOS1
``openPMD_USE_ADIOS2`` AUTO/ON/**OFF** Enable support for ADIOS2 :sup:`1`
Expand Down Expand Up @@ -73,6 +74,7 @@ CMake Option Values Installs Library Version
``openPMD_USE_INTERNAL_VARIANT`` **ON**/OFF Yes MPark.Variant 1.3.0+
``openPMD_USE_INTERNAL_CATCH`` **ON**/OFF No Catch2 2.3.0+
``openPMD_USE_INTERNAL_PYBIND11`` **ON**/OFF No pybind11 2.2.3+
``openPMD_USE_INTERNAL_JSON`` **ON**/OFF No NLohmann-JSON 3.4.0+
================================= =========== ======== ============= ========


Expand Down
2 changes: 2 additions & 0 deletions docs/source/dev/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ The following libraries are shipped internally in ``share/openPMD/thirdParty/``
* `MPark.Variant <https://github.com/mpark/variant>`_ 1.3.0+ (`BSL-1.0 <https://github.com/mpark/variant/blob/master/LICENSE.md>`_)
* `Catch2 <https://github.com/catchorg/Catch2>`_ 2.3.0+ (`BSL-1.0 <https://github.com/catchorg/Catch2/blob/master/LICENSE.txt>`_)
* `pybind11 <https://github.com/pybind/pybind11>`_ 2.2.3+ (`new BSD <https://github.com/pybind/pybind11/blob/master/LICENSE>`_)
* `NLohmann-JSON <https://github.com/nlohmann/json> 3.4.0+ (`MIT <https://github.com/nlohmann/json/blob/develop/LICENSE.MIT>`_)

Optional: I/O backends
----------------------

* `JSON <https://en.wikipedia.org/wiki/JSON>`_
* `HDF5 <https://support.hdfgroup.org/HDF5>`_ 1.8.13+
* `ADIOS1 <https://www.olcf.ornl.gov/center-projects/adios>`_ 1.13.1+
* `ADIOS2 <https://github.com/ornladios/ADIOS2>`_ 2.1+ (*not yet implemented*)
Expand Down
3 changes: 3 additions & 0 deletions openPMDConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ else()
endif()
set(openPMD_MPI_FOUND ${openPMD_HAVE_MPI})

set(openPMD_HAVE_JSON @openPMD_HAVE_JSON@)
set(openPMD_JSON_FOUND ${openPMD_HAVE_JSON})

set(openPMD_HAVE_HDF5 @openPMD_HAVE_HDF5@)
if(openPMD_HAVE_HDF5)
find_dependency(HDF5)
Expand Down
124 changes: 124 additions & 0 deletions share/openPMD/thirdParty/json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
cmake_minimum_required(VERSION 3.8)

##
## PROJECT
## name and version
##
project(nlohmann_json VERSION 3.4.0 LANGUAGES CXX)

##
## INCLUDE
##
##
include(ExternalProject)

##
## OPTIONS
##
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ON)
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OFF)

##
## CONFIGURATION
##
set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME})
set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}"
CACHE INTERNAL "")
set(NLOHMANN_JSON_INCLUDE_INSTALL_DIR "include")
set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
set(NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")

if (JSON_MultipleHeaders)
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
message(STATUS "Using the multi-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
else()
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/single_include/")
message(STATUS "Using the single-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
endif()

##
## TARGET
## create target and add include path
##
add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${NLOHMANN_JSON_TARGET_NAME} ALIAS ${NLOHMANN_JSON_TARGET_NAME})
target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_std_11)

target_include_directories(
${NLOHMANN_JSON_TARGET_NAME}
INTERFACE
$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_BUILD_DIR}>
$<INSTALL_INTERFACE:include>
)

## add debug view definition file for msvc (natvis)
if (MSVC)
set(NLOHMANN_ADD_NATVIS TRUE)
set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis")
target_sources(
${NLOHMANN_JSON_TARGET_NAME}
INTERFACE
$<INSTALL_INTERFACE:${NLOHMANN_NATVIS_FILE}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${NLOHMANN_NATVIS_FILE}>
)
endif()

##
## TESTS
## create and configure the unit test target
##
include(CTest) #adds option BUILD_TESTING (default ON)

if(BUILD_TESTING AND JSON_BuildTests)
enable_testing()
add_subdirectory(test)
endif()

##
## INSTALL
## install header files, generate and install cmake config files for find_package()
##
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE} COMPATIBILITY SameMajorVersion
)
configure_file(
${NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE}
${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE}
@ONLY
)

install(
DIRECTORY ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}
DESTINATION ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}
)
install(
FILES ${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE} ${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
)
if (NLOHMANN_ADD_NATVIS)
install(
FILES ${NLOHMANN_NATVIS_FILE}
DESTINATION .
)
endif()
export(
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE ${NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE}
)
install(
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
EXPORT ${NLOHMANN_JSON_TARGETS_EXPORT_NAME}
INCLUDES DESTINATION ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}
)
install(
EXPORT ${NLOHMANN_JSON_TARGETS_EXPORT_NAME}
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
)

16 changes: 16 additions & 0 deletions share/openPMD/thirdParty/json/cmake/config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include(FindPackageHandleStandardArgs)
set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE})
find_package_handle_standard_args(@PROJECT_NAME@ CONFIG_MODE)

if(NOT TARGET @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@NLOHMANN_JSON_TARGETS_EXPORT_NAME@.cmake")
if((NOT TARGET @NLOHMANN_JSON_TARGET_NAME@) AND
(NOT @PROJECT_NAME@_FIND_VERSION OR
@PROJECT_NAME@_FIND_VERSION VERSION_LESS 3.2.0))
add_library(@NLOHMANN_JSON_TARGET_NAME@ INTERFACE IMPORTED)
set_target_properties(@NLOHMANN_JSON_TARGET_NAME@ PROPERTIES
INTERFACE_LINK_LIBRARIES @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@
)
endif()
endif()

32 changes: 32 additions & 0 deletions share/openPMD/thirdParty/json/nlohmann_json.natvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="nlohmann::basic_json&lt;*&gt;">
<DisplayString Condition="m_type == nlohmann::detail::value_t::null">null</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::object">{*(m_value.object)}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::array">{*(m_value.array)}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::string">{*(m_value.string)}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::boolean">{m_value.boolean}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::number_integer">{m_value.number_integer}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::number_unsigned">{m_value.number_unsigned}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::number_float">{m_value.number_float}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::discarded">discarded</DisplayString>
<Expand>
<ExpandedItem Condition="m_type == nlohmann::detail::value_t::object">
*(m_value.object),view(simple)
</ExpandedItem>
<ExpandedItem Condition="m_type == nlohmann::detail::value_t::array">
*(m_value.array),view(simple)
</ExpandedItem>
</Expand>
</Type>

<!-- skip the pair first/second members in the treeview while traversing a map.
Only works in VS 2015 Update 2 and beyond using the new visualization -->
<Type Name="std::pair&lt;*, nlohmann::basic_json&lt;*&gt;&gt;" IncludeView="MapHelper">
<DisplayString>{second}</DisplayString>
<Expand>
<ExpandedItem>second</ExpandedItem>
</Expand>
</Type>

</AutoVisualizer>
Loading