1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
|
From: Drew Parsons <dparsons@debian.org>
Date: Thu, 22 Feb 2024 18:43:49 +0100
Subject: enables build for multiple Python versions
to be specified via ADIOS2_Python_Version e.g. -DADIOS2_Python_Version="3.11;3.12"
Use ADIOS2_Python_Version to build python extensions for all supported
Python versions
Idea for using separate directories for each Python version is adapted
from https://gitlab.kitware.com/cmake/cmake/-/issues/21797
---
CMakeLists.txt | 7 +++
bindings/CMakeLists.txt | 15 +++++-
bindings/Python/CMakeLists.txt | 24 ++++++---
cmake/DetectOptions.cmake | 90 +++++++++++++++++-----------------
cmake/DetectPythonOptions.cmake | 89 +++++++++++++++++++++++++++++++++
testing/adios2/bindings/CMakeLists.txt | 4 +-
testing/adios2/engine/CMakeLists.txt | 4 +-
thirdparty/CMakeLists.txt | 2 +-
8 files changed, 177 insertions(+), 58 deletions(-)
create mode 100644 cmake/DetectPythonOptions.cmake
Index: adios2/CMakeLists.txt
===================================================================
--- adios2.orig/CMakeLists.txt 2025-12-06 11:13:24.157043074 +0100
+++ adios2/CMakeLists.txt 2025-12-06 11:13:24.149068730 +0100
@@ -208,6 +208,11 @@
mark_as_advanced(ADIOS2_USE_PIP)
include(${PROJECT_SOURCE_DIR}/cmake/DetectOptions.cmake)
+if(ADIOS2_Python_Version)
+ # use the last Python version in the list to run tests
+ list(GET ADIOS2_Python_Version -1 ADIOS2_Python_Default_Test)
+endif()
+
if(ADIOS2_HAVE_CUDA OR ADIOS2_HAVE_Kokkos_CUDA)
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
@@ -443,6 +448,8 @@
message(" cmake: ${CMAKE_INSTALL_CMAKEDIR}")
if(DEFINED CMAKE_INSTALL_PYTHONDIR)
message(" python: ${CMAKE_INSTALL_PYTHONDIR}")
+elseif(ADIOS2_Python_Version)
+ message(" python: ${ADIOS2_Python_Version}")
endif()
message("")
message(" Features:")
Index: adios2/bindings/CMakeLists.txt
===================================================================
--- adios2.orig/bindings/CMakeLists.txt 2025-12-06 11:13:24.157043074 +0100
+++ adios2/bindings/CMakeLists.txt 2025-12-06 11:13:24.149487110 +0100
@@ -3,8 +3,19 @@
# accompanying file Copyright.txt for details.
#------------------------------------------------------------------------------#
-if(ADIOS2_HAVE_Python)
- add_subdirectory(Python)
+if(ADIOS2_USE_Python)
+ if(ADIOS2_Python_Version)
+ # specific Python versions specified, e.g. -DADIOS2_Python_Version=3.12;3.11
+ foreach(pyver IN LISTS ADIOS2_Python_Version)
+ file(REMOVE_RECURSE Python${pyver})
+ file(COPY Python DESTINATION ${CMAKE_BINARY_DIR}/build_source/bindings/Python${pyver})
+ file(WRITE ${CMAKE_BINARY_DIR}/build_source/bindings/Python${pyver}/Python/ADIOS2_Python_Version.txt ${pyver})
+ add_subdirectory(${CMAKE_BINARY_DIR}/build_source/bindings/Python${pyver}/Python ${CMAKE_BINARY_DIR}/bindings/Python${pyver}/Python)
+ endforeach()
+ else()
+ # build for the default Python version only
+ add_subdirectory(Python)
+ endif()
endif()
if(ADIOS2_HAVE_Fortran)
Index: adios2/bindings/Python/CMakeLists.txt
===================================================================
--- adios2.orig/bindings/Python/CMakeLists.txt 2025-12-06 11:13:24.157043074 +0100
+++ adios2/bindings/Python/CMakeLists.txt 2025-12-06 11:17:18.646913561 +0100
@@ -1,4 +1,12 @@
-Python_add_library(adios2_py MODULE
+# If a specific Python version should be used, it will be defined in ADIOS2_Python_Version.txt
+if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/ADIOS2_Python_Version.txt)
+ file(READ ${CMAKE_CURRENT_LIST_DIR}/ADIOS2_Python_Version.txt PYVER)
+ include(${PROJECT_SOURCE_DIR}/cmake/DetectPythonOptions.cmake)
+endif()
+
+include(${PROJECT_SOURCE_DIR}/cmake/ADIOSFunctions.cmake)
+
+Python_add_library(adios2_py${PYVER} MODULE
WITH_SOABI
py11ADIOS.cpp
py11IO.cpp
@@ -10,9 +18,9 @@
py11Query.cpp
py11glue.cpp
)
-target_compile_definitions(adios2_py PRIVATE "ADIOS2_PYTHON_MODULE_NAME=adios2_bindings${ADIOS2_LIBRARY_SUFFIX}")
+target_compile_definitions(adios2_py${PYVER} PRIVATE "ADIOS2_PYTHON_MODULE_NAME=adios2_bindings${ADIOS2_LIBRARY_SUFFIX}")
if(ADIOS2_HAVE_MPI)
- target_sources(adios2_py PRIVATE
+ target_sources(adios2_py${PYVER} PRIVATE
py11ADIOSMPI.cpp
py11IOMPI.cpp
)
@@ -24,7 +32,7 @@
set(maybe_adios2_core_mpi)
set(maybe_mpi4py)
endif()
-target_link_libraries(adios2_py PRIVATE
+target_link_libraries(adios2_py${PYVER} PRIVATE
${maybe_adios2_cxx_mpi} adios2_cxx
${maybe_adios2_core_mpi} adios2_core
adios2::thirdparty::pybind11
@@ -47,7 +55,7 @@
)
# We need the $<0:> for the Windows python unittests to work
-set_target_properties(adios2_py PROPERTIES
+set_target_properties(adios2_py${PYVER} PROPERTIES
CXX_VISIBILITY_PRESET hidden
OUTPUT_NAME adios2_bindings${ADIOS2_LIBRARY_SUFFIX}
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/adios2/bindings$<0:>
@@ -64,23 +72,23 @@
string(REGEX REPLACE "[^/]+" ".." relative_base "${install_location}/bindings")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
- set_property(TARGET adios2_py APPEND PROPERTY
+ set_property(TARGET adios2_py${PYVER} APPEND PROPERTY
INSTALL_RPATH "$ORIGIN/${relative_base}/${CMAKE_INSTALL_LIBDIR}"
)
endif()
-install(TARGETS adios2_py
+install(TARGETS adios2_py${PYVER}
DESTINATION ${install_location}/bindings
- COMPONENT adios2_python-python
+ COMPONENT adios2_python-python${PYVER}
${ADIOS2_MAYBE_EXCLUDE_FROM_ALL}
)
install(FILES ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/adios2/bindings/__init__.py
DESTINATION ${install_location}/bindings
- COMPONENT adios2_python-python
+ COMPONENT adios2_python-python${PYVER}
${ADIOS2_MAYBE_EXCLUDE_FROM_ALL}
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
DESTINATION ${install_location}
- COMPONENT adios2_python-python
+ COMPONENT adios2_python-python${PYVER}
${ADIOS2_MAYBE_EXCLUDE_FROM_ALL}
)
Index: adios2/cmake/DetectOptions.cmake
===================================================================
--- adios2.orig/cmake/DetectOptions.cmake 2025-12-06 11:13:24.157043074 +0100
+++ adios2/cmake/DetectOptions.cmake 2025-12-06 11:13:24.150747606 +0100
@@ -407,53 +407,53 @@
endif()
endif()
-if(ADIOS2_USE_PIP)
- find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development.Module)
- set(ADIOS2_HAVE_PIP TRUE)
-elseif(ADIOS2_USE_Python STREQUAL AUTO)
- find_package(Python 3.8 COMPONENTS Interpreter Development)
- if(Python_FOUND AND ADIOS2_HAVE_MPI)
- find_package(PythonModule COMPONENTS mpi4py mpi4py/mpi4py.h)
- endif()
-elseif(ADIOS2_USE_Python)
- find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development)
- if(ADIOS2_HAVE_MPI)
- find_package(PythonModule REQUIRED COMPONENTS mpi4py mpi4py/mpi4py.h)
- endif()
-endif()
-if(Python_FOUND)
- if(ADIOS2_HAVE_MPI)
- if(PythonModule_mpi4py_FOUND)
- set(ADIOS2_HAVE_Python ON)
- endif()
- else()
- set(ADIOS2_HAVE_Python ON)
- endif()
-endif()
+#if(ADIOS2_USE_PIP)
+# find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development.Module)
+# set(ADIOS2_HAVE_PIP TRUE)
+#elseif(ADIOS2_USE_Python STREQUAL AUTO)
+# find_package(Python 3.8 COMPONENTS Interpreter Development)
+# if(Python_FOUND AND ADIOS2_HAVE_MPI)
+# find_package(PythonModule COMPONENTS mpi4py mpi4py/mpi4py.h)
+# endif()
+#elseif(ADIOS2_USE_Python)
+# find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development)
+# if(ADIOS2_HAVE_MPI)
+# find_package(PythonModule REQUIRED COMPONENTS mpi4py mpi4py/mpi4py.h)
+# endif()
+#endif()
+#if(Python_FOUND)
+# if(ADIOS2_HAVE_MPI)
+# if(PythonModule_mpi4py_FOUND)
+# set(ADIOS2_HAVE_Python ON)
+# endif()
+# else()
+# set(ADIOS2_HAVE_Python ON)
+# endif()
+#endif()
# Even if no python support, we still want the interpreter for tests
-if(BUILD_TESTING AND NOT Python_Interpreter_FOUND)
- find_package(Python REQUIRED COMPONENTS Interpreter)
-endif()
-
-if(Python_Interpreter_FOUND)
- # Setup output directories
- if(Python_Development_FOUND)
- lists_get_prefix("Python_INCLUDE_DIRS;Python_LIBRARIES;Python_SITEARCH" _Python_DEVPREFIX)
- else()
- lists_get_prefix("Python_EXECUTABLE;Python_SITEARCH" _Python_DEVPREFIX)
- endif()
- string_strip_prefix(
- "${_Python_DEVPREFIX}" "${Python_SITEARCH}" CMAKE_INSTALL_PYTHONDIR_DEFAULT
- )
- set(CMAKE_INSTALL_PYTHONDIR "${CMAKE_INSTALL_PYTHONDIR_DEFAULT}"
- CACHE PATH "Install directory for python modules"
- )
- mark_as_advanced(CMAKE_INSTALL_PYTHONDIR)
- set(CMAKE_PYTHON_OUTPUT_DIRECTORY
- ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}
- )
-endif()
+#if(BUILD_TESTING AND NOT Python_Interpreter_FOUND)
+# find_package(Python REQUIRED COMPONENTS Interpreter)
+#endif()
+#
+#if(Python_Interpreter_FOUND)
+# # Setup output directories
+# if(Python_Development_FOUND)
+# lists_get_prefix("Python_INCLUDE_DIRS;Python_LIBRARIES;Python_SITEARCH" _Python_DEVPREFIX)
+# else()
+# lists_get_prefix("Python_EXECUTABLE;Python_SITEARCH" _Python_DEVPREFIX)
+# endif()
+# string_strip_prefix(
+# "${_Python_DEVPREFIX}" "${Python_SITEARCH}" CMAKE_INSTALL_PYTHONDIR_DEFAULT
+# )
+# set(CMAKE_INSTALL_PYTHONDIR "${CMAKE_INSTALL_PYTHONDIR_DEFAULT}"
+# CACHE PATH "Install directory for python modules"
+# )
+# mark_as_advanced(CMAKE_INSTALL_PYTHONDIR)
+# set(CMAKE_PYTHON_OUTPUT_DIRECTORY
+# ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}
+# )
+#endif()
# Sst
if(ADIOS2_USE_SST AND NOT WIN32)
Index: adios2/cmake/DetectPythonOptions.cmake
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ adios2/cmake/DetectPythonOptions.cmake 2025-12-06 11:13:24.151173357 +0100
@@ -0,0 +1,89 @@
+#------------------------------------------------------------------------------#
+# Distributed under the OSI-approved Apache License, Version 2.0. See
+# accompanying file Copyright.txt for details.
+#------------------------------------------------------------------------------#
+
+# This file contains the option and dependency logic for Python support,
+# moved from DetectOptions.cmake to allow for multiple python versions.
+
+# Python
+
+if(PYVER)
+ set(PY3VER ${PYVER})
+else()
+ set(PY3VER 3)
+endif()
+
+# Not supported on PGI
+if(CMAKE_CXX_COMPILER_ID STREQUAL PGI)
+ if(ADIOS2_USE_Python STREQUAL ON)
+ message(FATAL_ERROR "Python bindings are not supported with the PGI compiler")
+ elseif(ADIOS2_USE_Python STREQUAL AUTO)
+ message(WARNING "Disabling python bindings as they are not supported with the PGI compiler")
+ set(ADIOS2_USE_Python OFF)
+ endif()
+endif()
+
+# Not supported without shared libs
+if(NOT SHARED_LIBS_SUPPORTED)
+ if(ADIOS2_USE_Python STREQUAL ON)
+ message(FATAL_ERROR "Python bindings are not supported without shared library support")
+ elseif(ADIOS2_USE_Python STREQUAL AUTO)
+ message(WARNING "Disabling python bindings since no shared library support was detected.")
+ set(ADIOS2_USE_Python OFF)
+ endif()
+endif()
+
+if(ADIOS2_USE_Python STREQUAL AUTO)
+ if(PYVER)
+ find_package(Python ${PYVER} EXACT COMPONENTS Interpreter Development NumPy)
+ else()
+ find_package(Python 3 COMPONENTS Interpreter Development NumPy)
+ endif()
+ if(Python_FOUND AND ADIOS2_HAVE_MPI)
+ find_package(PythonModule COMPONENTS mpi4py mpi4py/mpi4py.h)
+ endif()
+elseif(ADIOS2_USE_Python)
+ if(PYVER)
+ find_package(Python ${PYVER} EXACT REQUIRED COMPONENTS Interpreter Development NumPy)
+ else()
+ find_package(Python 3 REQUIRED COMPONENTS Interpreter Development NumPy)
+ endif()
+ if(ADIOS2_HAVE_MPI)
+ find_package(PythonModule REQUIRED COMPONENTS mpi4py mpi4py/mpi4py.h)
+ endif()
+endif()
+
+if(Python_FOUND)
+ if(ADIOS2_HAVE_MPI)
+ if(PythonModule_mpi4py_FOUND)
+ set(ADIOS2_HAVE_Python ON)
+ endif()
+ else()
+ set(ADIOS2_HAVE_Python ON)
+ endif()
+endif()
+
+# Even if no python support, we still want the interpreter for tests
+if(BUILD_TESTING AND NOT Python_Interpreter_FOUND)
+ find_package(Python REQUIRED COMPONENTS Interpreter)
+endif()
+
+if(Python_Interpreter_FOUND)
+ # Setup output directories
+ if(Python_Development_FOUND)
+ lists_get_prefix("Python_INCLUDE_DIRS;Python_LIBRARIES;Python_SITEARCH" _Python_DEVPREFIX)
+ else()
+ lists_get_prefix("Python_EXECUTABLE;Python_SITEARCH" _Python_DEVPREFIX)
+ endif()
+ string_strip_prefix(
+ "${_Python_DEVPREFIX}" "${Python_SITEARCH}" CMAKE_INSTALL_PYTHONDIR_DEFAULT
+ )
+ set(CMAKE_INSTALL_PYTHONDIR "${CMAKE_INSTALL_PYTHONDIR_DEFAULT}"
+ CACHE PATH "Install directory for python modules"
+ )
+ mark_as_advanced(CMAKE_INSTALL_PYTHONDIR)
+ set(CMAKE_PYTHON_OUTPUT_DIRECTORY
+ ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}
+ )
+endif()
Index: adios2/testing/adios2/bindings/CMakeLists.txt
===================================================================
--- adios2.orig/testing/adios2/bindings/CMakeLists.txt 2025-12-06 11:13:24.157043074 +0100
+++ adios2/testing/adios2/bindings/CMakeLists.txt 2025-12-06 11:13:24.151692120 +0100
@@ -3,7 +3,9 @@
# accompanying file Copyright.txt for details.
#------------------------------------------------------------------------------#
-if(ADIOS2_HAVE_Python)
+# Can only run python binding tests with a general Python build
+# not with versions specified by ADIOS2_Python_Version
+if(ADIOS2_HAVE_Python AND NOT ADIOS2_Python_Version)
add_subdirectory(python)
endif()
Index: adios2/testing/adios2/engine/CMakeLists.txt
===================================================================
--- adios2.orig/testing/adios2/engine/CMakeLists.txt 2025-12-06 11:13:24.157043074 +0100
+++ adios2/testing/adios2/engine/CMakeLists.txt 2025-12-06 11:13:24.151930863 +0100
@@ -14,7 +14,9 @@
add_subdirectory(hdf5)
endif()
-if(ADIOS2_HAVE_DataMan)
+# Can only run dataman with a general Python build
+# not with versions specified by ADIOS2_Python_Version
+if(ADIOS2_HAVE_DataMan AND NOT ADIOS2_Python_Version)
add_subdirectory(dataman)
endif()
Index: adios2/thirdparty/CMakeLists.txt
===================================================================
--- adios2.orig/thirdparty/CMakeLists.txt 2025-12-06 11:13:24.157043074 +0100
+++ adios2/thirdparty/CMakeLists.txt 2025-12-06 11:13:24.152195538 +0100
@@ -47,7 +47,7 @@
endif()
endif()
-if(ADIOS2_HAVE_Python)
+if(ADIOS2_USE_Python)
if(ADIOS2_USE_EXTERNAL_PYBIND11)
find_package(pybind11 REQUIRED)
adios2_add_thirdparty_target(pybind11 pybind11::pybind11)
|