Skip to content
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

python: install to a proper libdir prefix #599

Merged
merged 11 commits into from
Jun 4, 2024
32 changes: 3 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,42 +105,16 @@ if(NOT ROOT_CXX_STANDARD VERSION_EQUAL CMAKE_CXX_STANDARD)
message(WARNING "You are trying to build podio with a different c++ standard than ROOT. C++${CMAKE_CXX_STANDARD} was required but ROOT was built with C++${ROOT_CXX_STANDARD}")
endif()

#Check if Python version detected matches the version used to build ROOT
SET(Python_FIND_FRAMEWORK LAST)
IF((TARGET ROOT::PyROOT OR TARGET ROOT::ROOTTPython) AND ${ROOT_VERSION} VERSION_GREATER_EQUAL 6.19)
# some cmake versions don't include python patch level in PYTHON_VERSION
IF(CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0 AND CMAKE_VERSION VERSION_LESS_EQUAL 3.17.2)
string(REGEX MATCH [23]\.[0-9]+ REQUIRE_PYTHON_VERSION ${ROOT_PYTHON_VERSION})
ELSE()
SET(REQUIRE_PYTHON_VERSION ${ROOT_PYTHON_VERSION})
ENDIF()
message( STATUS "Python version used for building ROOT ${ROOT_PYTHON_VERSION}" )
message( STATUS "Required python version ${REQUIRE_PYTHON_VERSION}")

if(NOT PODIO_RELAX_PYVER)
find_package(Python ${REQUIRE_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Development Interpreter)
else()
find_package(Python ${REQUIRE_PYTHON_VERSION} REQUIRED COMPONENTS Development Interpreter)
string(REPLACE "." ";" _root_pyver_tuple ${REQUIRE_PYTHON_VERSION})
list(GET _root_pyver_tuple 0 _root_pyver_major)
list(GET _root_pyver_tuple 1 _root_pyver_minor)
if(NOT "${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}" VERSION_EQUAL "${_root_pyver_major}.${_root_pyver_minor}")
message(FATAL_ERROR "There is a mismatch between the major and minor versions in Python"
" (found ${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) and ROOT, compiled with "
"Python ${_root_pyver_major}.${_root_pyver_minor}")
endif()
endif()
else()
find_package(Python COMPONENTS Development Interpreter)
endif()

# ROOT only sets usage requirements from 6.14, so for
# earlier versions need to hack in INTERFACE_INCLUDE_DIRECTORIES
if(ROOT_VERSION VERSION_LESS 6.14)
set_property(TARGET ROOT::Core APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}")
endif()
list(APPEND PODIO_IO_HANDLERS ROOT)

# python setup (including python package discovery and install dir)
podio_python_setup()

#--- enable podio macros--------------------------------------------------------
include(cmake/podioMacros.cmake)

Expand Down
56 changes: 56 additions & 0 deletions cmake/podioBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,59 @@ macro(ADD_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE})
endif(CLANG_TIDY)
endmacro(ADD_CLANG_TIDY)

# --- Macro to find a python version that is compatible with ROOT and to setup
# --- the python install directory for the podio python sources
#
# The python install directory is exposed via the podio_PYTHON_INSTALLDIR cmake
# variable. It defaults to
# CMAKE_INSTALL_PREFIX/lib[64]/pythonX.YY/site-packages/, where pythonX.YY is
# the major.minor version of python and lib or lib64 is decided from checking
# Python3_SITEARCH
#
# NOTE: This macro needs to be called **AFTER** find_package(ROOT) since that is
# necessary to expose
macro(podio_python_setup)
#Check if Python version detected matches the version used to build ROOT
SET(Python_FIND_FRAMEWORK LAST)
IF((TARGET ROOT::PyROOT OR TARGET ROOT::ROOTTPython) AND ${ROOT_VERSION} VERSION_GREATER_EQUAL 6.19)
# some cmake versions don't include python patch level in PYTHON_VERSION
IF(CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0 AND CMAKE_VERSION VERSION_LESS_EQUAL 3.17.2)
string(REGEX MATCH [23]\.[0-9]+ REQUIRE_PYTHON_VERSION ${ROOT_PYTHON_VERSION})
ELSE()
SET(REQUIRE_PYTHON_VERSION ${ROOT_PYTHON_VERSION})
ENDIF()
message( STATUS "Python version used for building ROOT ${ROOT_PYTHON_VERSION}" )
message( STATUS "Required python version ${REQUIRE_PYTHON_VERSION}")

if(NOT PODIO_RELAX_PYVER)
find_package(Python3 ${REQUIRE_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Development Interpreter)
else()
find_package(Python3 ${REQUIRE_PYTHON_VERSION} REQUIRED COMPONENTS Development Interpreter)
string(REPLACE "." ";" _root_pyver_tuple ${REQUIRE_PYTHON_VERSION})
list(GET _root_pyver_tuple 0 _root_pyver_major)
list(GET _root_pyver_tuple 1 _root_pyver_minor)
if(NOT "${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}" VERSION_EQUAL "${_root_pyver_major}.${_root_pyver_minor}")
message(FATAL_ERROR "There is a mismatch between the major and minor versions in Python"
" (found ${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) and ROOT, compiled with "
"Python ${_root_pyver_major}.${_root_pyver_minor}")
endif()
endif()
else()
find_package(Python3 COMPONENTS Development Interpreter)
endif()

# Setup the python install dir. See the discussion in
# https://github.com/AIDASoft/podio/pull/599 for more details on why this is
# done the way it is
set(podio_python_lib_dir lib)
if("${Python3_SITEARCH}" MATCHES "/lib64/")
set(podio_python_lib_dir lib64)
endif()

set(podio_PYTHON_INSTALLDIR
"${CMAKE_INSTALL_PREFIX}/${podio_python_lib_dir}/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages"
CACHE STRING
"The install prefix for the python bindings and the generator and templates"
)
endmacro(podio_python_setup)
3 changes: 0 additions & 3 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
SET(podio_PYTHON_INSTALLDIR python)
SET(podio_PYTHON_INSTALLDIR ${podio_PYTHON_INSTALLDIR} PARENT_SCOPE)

set(to_install
podio_class_generator.py
podio_schema_evolution.py
Expand Down