diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5aa80f57fe..9ee89b0c37 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,7 +19,10 @@ Features - ADIOS2: support added (v2.4.0+) #482 #513 #530 - support empty datasets via ``RecordComponent::makeEmpty`` #528 #529 -- CMake: Build a shared library by default #506 +- CMake: + + - build a shared library by default #506 + - generate pkg-config ``.pc`` file #532 - Python: - manylinux2010 wheels for PyPI #523 diff --git a/CMakeLists.txt b/CMakeLists.txt index 61c3ffeab3..b32cdbd8c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,7 @@ openpmd_option(ADIOS1 "ADIOS1 backend (.bp files)" AUTO) openpmd_option(ADIOS2 "ADIOS2 backend (.bp files)" OFF) openpmd_option(PYTHON "Enable Python bindings" AUTO) +option(openPMD_HAVE_PKGCONFIG "Generate a .pc file for pkg-config" ON) 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) @@ -373,6 +374,7 @@ endif() # own headers target_include_directories(openPMD PUBLIC $ + $ $ ) @@ -412,10 +414,6 @@ if(openPMD_HAVE_MPI) # MPI targets: CMake 3.9+ # note: often the PUBLIC dependency to CXX is missing in C targets... target_link_libraries(openPMD PUBLIC MPI::MPI_C MPI::MPI_CXX) - - target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_MPI=1") -else() - target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_MPI=0") endif() # JSON Backend @@ -423,9 +421,6 @@ if(openPMD_HAVE_JSON) #target_link_libraries(openPMD PRIVATE openPMD::thirdparty::nlohmann_json) target_include_directories(openPMD SYSTEM PRIVATE $) - target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_JSON=1") -else() - target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_JSON=0") endif() # HDF5 Backend @@ -433,9 +428,6 @@ if(openPMD_HAVE_HDF5) target_link_libraries(openPMD PRIVATE ${HDF5_LIBRARIES}) target_include_directories(openPMD SYSTEM PRIVATE ${HDF5_INCLUDE_DIRS}) target_compile_definitions(openPMD PRIVATE ${HDF5_DEFINITIONS}) - target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_HDF5=1") -else() - target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_HDF5=0") endif() # ADIOS1 Backend @@ -456,9 +448,9 @@ if(openPMD_HAVE_ADIOS1) target_link_libraries(openPMD.ADIOS1.Parallel PUBLIC openPMD::thirdparty::mpark_variant) target_include_directories(openPMD.ADIOS1.Serial SYSTEM PRIVATE - ${openPMD_SOURCE_DIR}/include) + ${openPMD_SOURCE_DIR}/include ${openPMD_BINARY_DIR}/include) target_include_directories(openPMD.ADIOS1.Parallel SYSTEM PRIVATE - ${openPMD_SOURCE_DIR}/include) + ${openPMD_SOURCE_DIR}/include ${openPMD_BINARY_DIR}/include) if(openPMD_HAVE_MPI) target_link_libraries(openPMD.ADIOS1.Parallel PUBLIC MPI::MPI_C MPI::MPI_CXX) @@ -529,19 +521,13 @@ if(openPMD_HAVE_ADIOS1) target_compile_definitions(openPMD.ADIOS1.Parallel PRIVATE "-DopenPMD_USE_VERIFY=0") endif() - target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_ADIOS1=1") target_link_libraries(openPMD PUBLIC openPMD.ADIOS1.Serial) target_link_libraries(openPMD PUBLIC openPMD.ADIOS1.Parallel) -else() - target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_ADIOS1=0") endif() # ADIOS2 Backend if(openPMD_HAVE_ADIOS2) target_link_libraries(openPMD PUBLIC adios2::adios2) - target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_ADIOS2=1") -else() - target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_ADIOS2=0") endif() # Runtime parameter and API status checks ("asserts") @@ -664,27 +650,7 @@ if(BUILD_TESTING) add_executable(${testname}Tests test/${testname}Test.cpp) if(openPMD_USE_INVASIVE_TESTS) - target_compile_definitions(${testname}Tests PUBLIC "-DopenPMD_USE_INVASIVE_TESTS=1") - endif() - - if(openPMD_HAVE_MPI) - 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() - - if(openPMD_HAVE_ADIOS1) - target_compile_definitions(${testname}Tests PUBLIC "-DopenPMD_HAVE_ADIOS1=1") - endif() - - if(openPMD_HAVE_ADIOS2) - target_compile_definitions(${testname}Tests PUBLIC "-DopenPMD_HAVE_ADIOS2=1") + target_compile_definitions(${testname}Tests PRIVATE "-DopenPMD_USE_INVASIVE_TESTS=1") endif() target_link_libraries(${testname}Tests PRIVATE openPMD) if(${testname} MATCHES "Parallel.+$") @@ -754,11 +720,24 @@ endif () # Generate Files with Configuration Options ################################### # # TODO configure a version.hpp +configure_file( + ${openPMD_SOURCE_DIR}/include/openPMD/config.hpp.in + ${openPMD_BINARY_DIR}/include/openPMD/config.hpp + @ONLY +) + configure_file( ${openPMD_SOURCE_DIR}/openPMDConfig.cmake.in ${openPMD_BINARY_DIR}/openPMDConfig.cmake @ONLY ) +if(openPMD_HAVE_PKGCONFIG) + CONFIGURE_FILE( + ${openPMD_SOURCE_DIR}/openPMD.pc.in + ${openPMD_BINARY_DIR}/openPMD.pc + @ONLY + ) +endif() include(CMakePackageConfigHelpers) write_basic_package_version_file("openPMDConfigVersion.cmake" @@ -791,6 +770,11 @@ if(openPMD_HAVE_PYTHON) endif() install(DIRECTORY "${openPMD_SOURCE_DIR}/include/openPMD" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING PATTERN "*.hpp" +) +install( + FILES ${openPMD_BINARY_DIR}/include/openPMD/config.hpp + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openPMD ) # install third-party libraries # TODO not needed with C++17 compiler @@ -817,6 +801,16 @@ install( ${openPMD_SOURCE_DIR}/share/openPMD/cmake/FindADIOS.cmake DESTINATION ${CMAKE_INSTALL_CMAKEDIR}/Modules ) +# pkg-config .pc file for depending legacy projects +# This is for projects that do not use a build file generator, e.g. +# because they compile manually on the command line or write their +# Makefiles by hand. +if(openPMD_HAVE_PKGCONFIG) + install( + FILES ${openPMD_BINARY_DIR}/openPMD.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig + ) +endif() # Tests ####################################################################### diff --git a/README.md b/README.md index 52a9503a6a..d96530d2e2 100644 --- a/README.md +++ b/README.md @@ -247,7 +247,7 @@ The install will contain header files and libraries in the path set with `-DCMAK ### CMake -If your project is using CMake for its build, one can conveniently use our provided `Config.cmake` package which is installed alongside the library. +If your project is using CMake for its build, one can conveniently use our provided `openPMDConfig.cmake` package which is installed alongside the library. First set the following environment hint if openPMD-api was *not* installed in a system path: @@ -272,3 +272,23 @@ add_subdirectory("path/to/source/of/openPMD-api") target_link_libraries(YourTarget PRIVATE openPMD::openPMD) ``` + +### Manually + +If your (Linux/OSX) project is build by calling the compiler directly or uses a manually written `Makefile`, consider using our `openPMD.pc` helper file for `pkg-config` which are installed alongside the library. + +First set the following environment hint if openPMD-api was *not* installed in a system path: + +```bash +# optional: only needed if installed outside of system paths +export PKG_CONFIG_PATH=$HOME/somepath/lib/pkgconfig:$PKG_CONFIG_PATH +``` + +Additional linker and compiler flags for your project are available via: +```bash +pkg-config --libs openPMD +# -L${HOME}/somepath/lib -lopenPMD + +pkg-config --cflags openPMD +# -I${HOME}/somepath/include +``` diff --git a/include/openPMD/IO/ADIOS/ADIOS1IOHandler.hpp b/include/openPMD/IO/ADIOS/ADIOS1IOHandler.hpp index 838156c509..63ab961b63 100644 --- a/include/openPMD/IO/ADIOS/ADIOS1IOHandler.hpp +++ b/include/openPMD/IO/ADIOS/ADIOS1IOHandler.hpp @@ -20,6 +20,7 @@ */ #pragma once +#include "openPMD/config.hpp" #include "openPMD/IO/AbstractIOHandler.hpp" #include diff --git a/include/openPMD/IO/ADIOS/ADIOS1IOHandlerImpl.hpp b/include/openPMD/IO/ADIOS/ADIOS1IOHandlerImpl.hpp index 28fe496987..46710c67f8 100644 --- a/include/openPMD/IO/ADIOS/ADIOS1IOHandlerImpl.hpp +++ b/include/openPMD/IO/ADIOS/ADIOS1IOHandlerImpl.hpp @@ -20,6 +20,7 @@ */ #pragma once +#include "openPMD/config.hpp" #include "openPMD/IO/AbstractIOHandler.hpp" #if openPMD_HAVE_ADIOS1 diff --git a/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp b/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp index 1e46ae31bc..696809ba03 100644 --- a/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp +++ b/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp @@ -20,6 +20,7 @@ */ #pragma once +#include "openPMD/config.hpp" #include "openPMD/IO/AbstractIOHandler.hpp" #include diff --git a/include/openPMD/IO/ADIOS/ParallelADIOS1IOHandler.hpp b/include/openPMD/IO/ADIOS/ParallelADIOS1IOHandler.hpp index aae8abfa51..17629a844a 100644 --- a/include/openPMD/IO/ADIOS/ParallelADIOS1IOHandler.hpp +++ b/include/openPMD/IO/ADIOS/ParallelADIOS1IOHandler.hpp @@ -20,6 +20,7 @@ */ #pragma once +#include "openPMD/config.hpp" #include "openPMD/IO/AbstractIOHandler.hpp" #include diff --git a/include/openPMD/IO/ADIOS/ParallelADIOS1IOHandlerImpl.hpp b/include/openPMD/IO/ADIOS/ParallelADIOS1IOHandlerImpl.hpp index c2d4656ff3..b153fa78d1 100644 --- a/include/openPMD/IO/ADIOS/ParallelADIOS1IOHandlerImpl.hpp +++ b/include/openPMD/IO/ADIOS/ParallelADIOS1IOHandlerImpl.hpp @@ -20,6 +20,7 @@ */ #pragma once +#include "openPMD/config.hpp" #include "openPMD/IO/AbstractIOHandler.hpp" #if openPMD_HAVE_ADIOS1 && openPMD_HAVE_MPI diff --git a/include/openPMD/IO/AbstractIOHandler.hpp b/include/openPMD/IO/AbstractIOHandler.hpp index 5d51fbaf7d..ff973a2a65 100644 --- a/include/openPMD/IO/AbstractIOHandler.hpp +++ b/include/openPMD/IO/AbstractIOHandler.hpp @@ -20,6 +20,7 @@ */ #pragma once +#include "openPMD/config.hpp" #include "openPMD/IO/AccessType.hpp" #include "openPMD/IO/Format.hpp" #include "openPMD/IO/IOTask.hpp" diff --git a/include/openPMD/IO/AbstractIOHandlerHelper.hpp b/include/openPMD/IO/AbstractIOHandlerHelper.hpp index 08b640e653..45d0d02737 100644 --- a/include/openPMD/IO/AbstractIOHandlerHelper.hpp +++ b/include/openPMD/IO/AbstractIOHandlerHelper.hpp @@ -19,7 +19,8 @@ * If not, see . */ #pragma once - + +#include "openPMD/config.hpp" #include "openPMD/IO/AbstractIOHandler.hpp" diff --git a/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp b/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp index 3ad22ff080..39af7e2d2f 100644 --- a/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp +++ b/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp @@ -20,6 +20,7 @@ */ #pragma once +#include "openPMD/config.hpp" #if openPMD_HAVE_HDF5 # include "openPMD/IO/AbstractIOHandlerImpl.hpp" # include diff --git a/include/openPMD/IO/HDF5/ParallelHDF5IOHandler.hpp b/include/openPMD/IO/HDF5/ParallelHDF5IOHandler.hpp index 9f16c647e8..495652e454 100644 --- a/include/openPMD/IO/HDF5/ParallelHDF5IOHandler.hpp +++ b/include/openPMD/IO/HDF5/ParallelHDF5IOHandler.hpp @@ -20,6 +20,7 @@ */ #pragma once +#include "openPMD/config.hpp" #include "openPMD/IO/AbstractIOHandler.hpp" #include diff --git a/include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp b/include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp index 8ae6259ed9..1c4021656f 100644 --- a/include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp +++ b/include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp @@ -20,6 +20,7 @@ */ #pragma once +#include "openPMD/config.hpp" #include "openPMD/IO/AbstractIOHandlerImpl.hpp" #if openPMD_HAVE_MPI diff --git a/include/openPMD/IO/JSON/JSONFilePosition.hpp b/include/openPMD/IO/JSON/JSONFilePosition.hpp index 3d622c0008..70748b094a 100644 --- a/include/openPMD/IO/JSON/JSONFilePosition.hpp +++ b/include/openPMD/IO/JSON/JSONFilePosition.hpp @@ -21,7 +21,7 @@ #pragma once - +#include "openPMD/config.hpp" #include "openPMD/IO/AbstractFilePosition.hpp" diff --git a/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp b/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp index 468fbdf629..9038ccd0d8 100644 --- a/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp +++ b/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp @@ -21,7 +21,7 @@ #pragma once - +#include "openPMD/config.hpp" #include "openPMD/auxiliary/Filesystem.hpp" #include "openPMD/IO/AbstractIOHandler.hpp" #include "openPMD/IO/AbstractIOHandlerImpl.hpp" diff --git a/include/openPMD/Series.hpp b/include/openPMD/Series.hpp index 97b93902cf..3e0e592f59 100644 --- a/include/openPMD/Series.hpp +++ b/include/openPMD/Series.hpp @@ -20,6 +20,7 @@ */ #pragma once +#include "openPMD/config.hpp" #include "openPMD/backend/Attributable.hpp" #include "openPMD/backend/Container.hpp" #include "openPMD/IO/AbstractIOHandler.hpp" diff --git a/include/openPMD/benchmark/mpi/MPIBenchmark.hpp b/include/openPMD/benchmark/mpi/MPIBenchmark.hpp index b1cea6239d..d9d517346d 100644 --- a/include/openPMD/benchmark/mpi/MPIBenchmark.hpp +++ b/include/openPMD/benchmark/mpi/MPIBenchmark.hpp @@ -21,6 +21,7 @@ #pragma once +#include "openPMD/config.hpp" #if openPMD_HAVE_MPI diff --git a/include/openPMD/benchmark/mpi/MPIBenchmarkReport.hpp b/include/openPMD/benchmark/mpi/MPIBenchmarkReport.hpp index c8736bea0e..cea79f16f7 100644 --- a/include/openPMD/benchmark/mpi/MPIBenchmarkReport.hpp +++ b/include/openPMD/benchmark/mpi/MPIBenchmarkReport.hpp @@ -21,16 +21,17 @@ #pragma once +#include "openPMD/config.hpp" #if openPMD_HAVE_MPI +#include "openPMD/Datatype.hpp" +#include "openPMD/Series.hpp" #include #include #include #include #include "string.h" -#include "openPMD/Datatype.hpp" -#include "openPMD/Series.hpp" namespace openPMD diff --git a/include/openPMD/config.hpp.in b/include/openPMD/config.hpp.in new file mode 100644 index 0000000000..d4c83b06d9 --- /dev/null +++ b/include/openPMD/config.hpp.in @@ -0,0 +1,41 @@ +/* Copyright 2019 Axel Huebl + * + * This file is part of openPMD-api. + * + * openPMD-api is free software: you can redistribute it and/or modify + * it under the terms of of either the GNU General Public License or + * the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * openPMD-api is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with openPMD-api. + * If not, see . + */ +#pragma once + +#ifndef openPMD_HAVE_MPI +# cmakedefine01 openPMD_HAVE_MPI +#endif + +#ifndef openPMD_HAVE_JSON +# cmakedefine01 openPMD_HAVE_JSON +#endif + +#ifndef openPMD_HAVE_HDF5 +# cmakedefine01 openPMD_HAVE_HDF5 +#endif + +#ifndef openPMD_HAVE_ADIOS1 +# cmakedefine01 openPMD_HAVE_ADIOS1 +#endif + +#ifndef openPMD_HAVE_ADIOS2 +# cmakedefine01 openPMD_HAVE_ADIOS2 +#endif diff --git a/include/openPMD/openPMD.hpp b/include/openPMD/openPMD.hpp index 9a3f625a85..b2d62fa665 100644 --- a/include/openPMD/openPMD.hpp +++ b/include/openPMD/openPMD.hpp @@ -48,5 +48,6 @@ #include "openPMD/auxiliary/ShareRaw.hpp" #include "openPMD/auxiliary/Variant.hpp" +#include "openPMD/config.hpp" #include "openPMD/version.hpp" // IWYU pragma: end_exports diff --git a/openPMD.pc.in b/openPMD.pc.in new file mode 100644 index 0000000000..b78174be36 --- /dev/null +++ b/openPMD.pc.in @@ -0,0 +1,13 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix}/@CMAKE_INSTALL_BINDIR@ +libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: openPMD +Description: C++ & Python API for Scientific I/O with openPMD. +Version: @openPMD_VERSION@ +URL: https://openpmd-api.readthedocs.io + +Libs: -L${libdir} -lopenPMD @openPMD_PC_PUBLIC_LIBS@ +Libs.private: -L${libdir} @openPMD_PC_PRIVATE_LIBS@ +Cflags: -I${includedir} @openPMD_PC_PUBLIC_DEFINES@ diff --git a/src/IO/ADIOS/ParallelADIOS1IOHandler.cpp b/src/IO/ADIOS/ParallelADIOS1IOHandler.cpp index 849bc94868..56983806f3 100644 --- a/src/IO/ADIOS/ParallelADIOS1IOHandler.cpp +++ b/src/IO/ADIOS/ParallelADIOS1IOHandler.cpp @@ -351,5 +351,10 @@ ParallelADIOS1IOHandler::flush() { return std::future< void >(); } + +void +ParallelADIOS1IOHandler::enqueue(IOTask const&) +{ +} #endif } // openPMD diff --git a/src/binding/python/Series.cpp b/src/binding/python/Series.cpp index 161e003f56..31e9505b3a 100644 --- a/src/binding/python/Series.cpp +++ b/src/binding/python/Series.cpp @@ -18,15 +18,19 @@ * and the GNU Lesser General Public License along with openPMD-api. * If not, see . */ + #include #include + +#include "openPMD/config.hpp" +#include "openPMD/Series.hpp" + #if openPMD_HAVE_MPI // re-implemented signatures: // include # include #endif -#include "openPMD/Series.hpp" #include namespace py = pybind11; diff --git a/src/binding/python/openPMD.cpp b/src/binding/python/openPMD.cpp index e68e5f64b2..64820379ba 100644 --- a/src/binding/python/openPMD.cpp +++ b/src/binding/python/openPMD.cpp @@ -21,6 +21,7 @@ #include #include +#include "openPMD/config.hpp" #include "openPMD/version.hpp" #include diff --git a/test/AuxiliaryTest.cpp b/test/AuxiliaryTest.cpp index dfaa63398a..29f03d4218 100644 --- a/test/AuxiliaryTest.cpp +++ b/test/AuxiliaryTest.cpp @@ -3,6 +3,7 @@ # define OPENPMD_private public # define OPENPMD_protected public #endif +#include "openPMD/config.hpp" #include "openPMD/backend/Writable.hpp" #include "openPMD/backend/Attributable.hpp" #include "openPMD/backend/Container.hpp"