-
Notifications
You must be signed in to change notification settings - Fork 51
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
Replace internal dependencies by FetchContent #1583
Changes from 20 commits
b05ad8f
8f7e3e8
620d861
6136a97
41a4658
dc57e24
74fe22c
78448ea
803c359
0ba14dc
d8cda47
7d90228
1402795
2557842
8d7dbd6
0e624d4
73189c5
1c71d9a
0084e9b
a4ab2b5
acc6e07
5c8f968
5976cc9
cbdcc1c
ea5b8db
16a9928
0f280e2
63f239a
7b8c6ed
a87abab
fc87c50
c04fe38
4d77402
cce18a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Preamble #################################################################### | ||
# | ||
cmake_minimum_required(VERSION 3.15.0) | ||
cmake_minimum_required(VERSION 3.24.0) | ||
|
||
project(openPMD VERSION 0.16.0) # LANGUAGES CXX | ||
|
||
|
@@ -9,23 +9,6 @@ set(openPMD_STANDARD_VERSION 1.1.0) | |
|
||
include(${openPMD_SOURCE_DIR}/cmake/openPMDFunctions.cmake) | ||
|
||
|
||
# CMake policies ############################################################## | ||
# | ||
# Search in <PackageName>_ROOT: | ||
# https://cmake.org/cmake/help/v3.12/policy/CMP0074.html | ||
if(POLICY CMP0074) | ||
cmake_policy(SET CMP0074 NEW) | ||
endif() | ||
|
||
# We use simple syntax in cmake_dependent_option, so we are compatible with the | ||
# extended syntax in CMake 3.22+ | ||
# https://cmake.org/cmake/help/v3.22/policy/CMP0127.html | ||
if(POLICY CMP0127) | ||
cmake_policy(SET CMP0127 NEW) | ||
endif() | ||
|
||
|
||
# No in-Source builds ######################################################### | ||
# | ||
# In-source builds clutter up the source directory and lead to mistakes with | ||
|
@@ -148,10 +131,6 @@ openpmd_option(PYTHON "Enable Python bindings" AUTO) | |
option(openPMD_INSTALL "Add installation targets" ON) | ||
option(openPMD_INSTALL_RPATH "Add RPATHs to installed binaries" ON) | ||
option(openPMD_HAVE_PKGCONFIG "Generate a .pc file for pkg-config" 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_INTERNAL_TOML11 "Use internally shipped toml11" 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) | ||
|
@@ -233,6 +212,7 @@ endfunction() | |
# Clang+MPI: Potentially needed MPI::MPI_C targets in the past | ||
# (exact MPI flavor & Clang version lost) | ||
# BullMPI: PUBLIC dependency to MPI::MPI_CXX is missing in MPI::MPI_C target | ||
include(FetchContent) | ||
set(openPMD_MPI_LINK_C_DEFAULT OFF) | ||
option(openPMD_MPI_LINK_C "Also link the MPI C targets" ${openPMD_MPI_LINK_C_DEFAULT}) | ||
mark_as_advanced(openPMD_MPI_LINK_C) | ||
|
@@ -259,27 +239,39 @@ endif() | |
|
||
|
||
# external library: nlohmann-json (required) | ||
if(openPMD_USE_INTERNAL_JSON) | ||
set(JSON_BuildTests OFF CACHE INTERNAL "") | ||
set(JSON_Install OFF CACHE INTERNAL "") # only used PRIVATE | ||
add_subdirectory("${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/json") | ||
message(STATUS "nlohmann-json: Using INTERNAL version '3.9.1'") | ||
else() | ||
find_package(nlohmann_json 3.9.1 CONFIG REQUIRED) | ||
message(STATUS "nlohmann-json: Found version '${nlohmann_json_VERSION}'") | ||
find_package(nlohmann_json CONFIG) | ||
if(NOT nlohmann_json_FOUND) | ||
message(STATUS "Fetching nlohmann-json from https://github.com/nlohmann/json") | ||
FetchContent_Declare( | ||
nlohmann_json | ||
GIT_REPOSITORY https://github.com/nlohmann/json.git | ||
GIT_TAG v3.11.3 | ||
SOURCE_DIR "${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/json/" | ||
OVERRIDE_FIND_PACKAGE | ||
) | ||
set(JSON_BuildTests OFF CACHE INTERNAL "NLohmann JSON option defiend internally by OpenPMD") | ||
set(JSON_Install OFF CACHE INTERNAL "NLohmann JSON option defiend internally by OpenPMD") # only used PRIVATE | ||
FetchContent_MakeAvailable(nlohmann_json) | ||
endif() | ||
add_library(openPMD::thirdparty::nlohmann_json INTERFACE IMPORTED) | ||
target_link_libraries(openPMD::thirdparty::nlohmann_json | ||
INTERFACE nlohmann_json::nlohmann_json) | ||
|
||
# external library: toml11 | ||
if(openPMD_USE_INTERNAL_TOML11) | ||
set(toml11_INSTALL OFF CACHE INTERNAL "") | ||
add_subdirectory("${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/toml11") | ||
message(STATUS "toml11: Using INTERNAL version '3.7.1'") | ||
else() | ||
find_package(toml11 3.7.1 CONFIG REQUIRED) | ||
message(STATUS "toml11: Found version '${toml11_VERSION}'") | ||
find_package(toml11 CONFIG) | ||
if(NOT toml11_FOUND) | ||
message(STATUS "Fetching toml11 from https://github.com/ToruNiina/toml11") | ||
FetchContent_Declare( | ||
toml11 | ||
GIT_REPOSITORY https://github.com/ToruNiina/toml11 | ||
# Migrate to the latest commit to remove CMake Warning which is not yet | ||
# available in any official release. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean the warning below? Do I understand correctly that this has been fixed on toml11 dev and we are waiting for the next release?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's probably an issue unrelated to this PR which we should better solve separately? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, after finishing this PR I would try to Update catch2 and toml11 with separate issues as described above |
||
GIT_TAG v3.7.1 | ||
SOURCE_DIR "${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/toml11/" | ||
OVERRIDE_FIND_PACKAGE | ||
) | ||
set(toml11_INSTALL OFF CACHE INTERNAL "toml11 option defiend internally by OpenPMD") | ||
FetchContent_MakeAvailable(toml11) | ||
endif() | ||
add_library(openPMD::thirdparty::toml11 INTERFACE IMPORTED) | ||
target_link_libraries(openPMD::thirdparty::toml11 | ||
|
@@ -396,47 +388,31 @@ endif() | |
|
||
# external library: pybind11 (optional) | ||
set(_PY_DEV_MODULE Development.Module) | ||
if(CMAKE_VERSION VERSION_LESS 3.18.0) | ||
# over-specification needed for CMake<3.18 | ||
# https://pybind11.readthedocs.io/en/latest/compiling.html#findpython-mode | ||
# https://cmake.org/cmake/help/v3.18/module/FindPython.html | ||
set(_PY_DEV_MODULE Development) | ||
endif() | ||
if(openPMD_USE_PYTHON STREQUAL AUTO) | ||
find_package(Python 3.8.0 COMPONENTS Interpreter ${_PY_DEV_MODULE}) | ||
if(Python_FOUND) | ||
if(openPMD_USE_INTERNAL_PYBIND11) | ||
add_subdirectory("${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/pybind11") | ||
set(openPMD_HAVE_PYTHON TRUE) | ||
message(STATUS "pybind11: Using INTERNAL version 2.11.1") | ||
else() | ||
find_package(pybind11 2.11.1 CONFIG) | ||
if(pybind11_FOUND) | ||
set(openPMD_HAVE_PYTHON TRUE) | ||
message(STATUS "pybind11: Found version '${pybind11_VERSION}'") | ||
else() | ||
set(openPMD_HAVE_PYTHON FALSE) | ||
endif() | ||
endif() | ||
else() | ||
set(openPMD_HAVE_PYTHON FALSE) | ||
endif() | ||
elseif(openPMD_USE_PYTHON) | ||
find_package(Python COMPONENTS Interpreter ${_PY_DEV_MODULE} REQUIRED) | ||
if(openPMD_USE_INTERNAL_PYBIND11) | ||
add_subdirectory("${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/pybind11") | ||
set(openPMD_HAVE_PYTHON TRUE) | ||
message(STATUS "pybind11: Using INTERNAL version 2.11.1") | ||
else() | ||
find_package(pybind11 2.11.1 REQUIRED CONFIG) | ||
set(openPMD_HAVE_PYTHON TRUE) | ||
message(STATUS "pybind11: Found version '${pybind11_VERSION}'") | ||
else() | ||
set(openPMD_HAVE_PYTHON FALSE) | ||
endif() | ||
if(Python_FOUND) | ||
find_package(pybind11 CONFIG) | ||
if(NOT pybind11_FOUND) | ||
message(STATUS "Fetching PyBind11 from https://github.com/pybind/pybind11") | ||
FetchContent_Declare( | ||
pybind11 | ||
GIT_REPOSITORY https://github.com/pybind/pybind11.git | ||
GIT_TAG v2.11.1 | ||
SOURCE_DIR "${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/pybind11/" | ||
OVERRIDE_FIND_PACKAGE | ||
) | ||
FetchContent_MakeAvailable(pybind11) | ||
endif() | ||
set(openPMD_HAVE_PYTHON TRUE) | ||
else() | ||
set(openPMD_HAVE_PYTHON FALSE) | ||
endif() | ||
|
||
|
||
# Targets ##################################################################### | ||
# | ||
set(CORE_SOURCE | ||
|
@@ -550,18 +526,22 @@ target_include_directories(openPMD PUBLIC | |
|
||
# Catch2 for unit tests | ||
if(openPMD_BUILD_TESTING) | ||
add_library(openPMD::thirdparty::Catch2 INTERFACE IMPORTED) | ||
if(openPMD_USE_INTERNAL_CATCH) | ||
target_include_directories(openPMD::thirdparty::Catch2 SYSTEM INTERFACE | ||
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/catch2/include> | ||
find_package(Catch2 CONFIG) | ||
if(NOT Catch2_FOUND) | ||
message(STATUS "Fetching toml11 from https://github.com/catchorg/Catch2") | ||
DerNils-git marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FetchContent_Declare( | ||
Catch2 | ||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git | ||
# ToDo Migrate to v3 and latest release | ||
GIT_TAG v2.13.10 | ||
SOURCE_DIR "${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/catch2/" | ||
OVERRIDE_FIND_PACKAGE | ||
) | ||
message(STATUS "Catch2: Using INTERNAL version '2.13.10'") | ||
else() | ||
find_package(Catch2 2.13.10 REQUIRED CONFIG) | ||
target_link_libraries(openPMD::thirdparty::Catch2 | ||
INTERFACE Catch2::Catch2) | ||
message(STATUS "Catch2: Found version '${Catch2_VERSION}'") | ||
FetchContent_MakeAvailable(Catch2) | ||
endif() | ||
add_library(openPMD::thirdparty::Catch2 INTERFACE IMPORTED) | ||
target_link_libraries(openPMD::thirdparty::Catch2 | ||
INTERFACE Catch2::Catch2) | ||
endif() | ||
|
||
if(openPMD_HAVE_MPI) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be aware that with this, the build folder will modify the source tree.
What does the workflow look like switching between different openPMD versions that specify different dependency versions. Will FetchContent notice and update the dependencies' versions upon configuring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true and might be a problem. I don't have experience with this.
Moving from lower to higher versions of OpenPMD should not be a problem. These directories have been deleted using
git rm
and should therefore be deleted when moving forward. FetchContent can then download into these directories w/o problem.A problem might arise if one moves from a higher to a lower version. If the directories have been populated by FetchContent and git tries to add the old libraries again in the same directories I can not predict the behavior.
It would be possible to use a different directory with FetchContent until we are sure that it works as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since @ax3l uses FetchContent in WarpX, let's wait until he is back to see what their approach looks like (relevant bits in their CMake config: https://github.com/ECP-WarpX/WarpX/blob/11e2a1722aac8929db0ed677f634673d235c1396/cmake/dependencies/openPMD.cmake#L29)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll move this to the build directory, as we do in other project.