Skip to content

Commit b37b578

Browse files
hageboeckdpiparo
authored andcommitted
[cppyy] Move libcppyy.so to <LIBDIR>/cppyy/libcppyy.so
When compiling ROOT in Gentoo, the following warning was issued: * Verifying compiled files for python3.13 * * QA Notice: The following unexpected files/directories were found * top-level in the site-packages directory: * * /usr/lib/python3.13/site-packages/libcppyy.so.6.37.01 * * This is most likely a bug in the build system. More information * can be found in the Python Guide: * https://projects.gentoo.org/python/guide/qawarn.html#stray-top-level-files-in-site-packages Similarly to #14917, this can be solved by moving it to <LIBDIR>/cppyy. Therefore: - Move the libray - Update the library's RUNPATHs for it to find ROOT libraries. - Use relative import paths to simplify finding libcppyy - Don't touch the install location in Windows for now Fix #20015.
1 parent fbd5a4e commit b37b578

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

bindings/pyroot/cppyy/CPyCppyy/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ endif()
7373
add_library(cppyy SHARED src/CPyCppyyPyModule.cxx)
7474

7575
# Set the suffix to '.so' and the prefix to 'lib'
76-
set_target_properties(cppyy PROPERTIES ${ROOT_LIBRARY_PROPERTIES})
76+
set_target_properties(cppyy PROPERTIES ${ROOT_LIBRARY_PROPERTIES}
77+
LIBRARY_OUTPUT_DIRECTORY ${localruntimedir}/cppyy)
7778
if(MSVC)
7879
target_link_libraries(cppyy PRIVATE CPyCppyy)
7980
set_target_properties(cppyy PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
@@ -108,7 +109,7 @@ set_property(GLOBAL APPEND PROPERTY ROOT_EXPORTED_TARGETS cppyy)
108109

109110
if(NOT MSVC)
110111
# Make sure that relative RUNPATH to main ROOT libraries is always correct.
111-
ROOT_APPEND_LIBDIR_TO_INSTALL_RPATH(cppyy ${CMAKE_INSTALL_PYTHONDIR})
112+
ROOT_APPEND_LIBDIR_TO_INSTALL_RPATH(cppyy ${CMAKE_INSTALL_PYTHONDIR}/cppyy)
112113
ROOT_APPEND_LIBDIR_TO_INSTALL_RPATH(CPyCppyy ${CMAKE_INSTALL_LIBDIR})
113114
endif()
114115

@@ -119,9 +120,9 @@ install(TARGETS CPyCppyy EXPORT ${CMAKE_PROJECT_NAME}Exports
119120
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
120121

121122
install(TARGETS cppyy EXPORT ${CMAKE_PROJECT_NAME}Exports
122-
RUNTIME DESTINATION ${CMAKE_INSTALL_PYTHONDIR} COMPONENT libraries
123-
LIBRARY DESTINATION ${CMAKE_INSTALL_PYTHONDIR} COMPONENT libraries
124-
ARCHIVE DESTINATION ${CMAKE_INSTALL_PYTHONDIR} COMPONENT libraries)
123+
RUNTIME DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/cppyy COMPONENT libraries # Windows
124+
LIBRARY DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/cppyy COMPONENT libraries
125+
ARCHIVE DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/cppyy COMPONENT libraries)
125126

126127
file(COPY ${headers} DESTINATION ${CMAKE_BINARY_DIR}/include/CPyCppyy)
127128

bindings/pyroot/cppyy/cppyy/python/cppyy/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,20 @@ def add_library_path(path):
339339

340340
apipath_extra = os.path.join(os.path.dirname(apipath), 'site', 'python'+ldversion)
341341
if not os.path.exists(os.path.join(apipath_extra, 'CPyCppyy')):
342-
import glob, libcppyy
343-
ape = os.path.dirname(libcppyy.__file__)
344-
# a "normal" structure finds the include directory up to 3 levels up,
345-
# ie. dropping lib/pythonx.y[md]/site-packages
342+
import glob
343+
import platform
344+
345+
if platform.system() == "Windows":
346+
# Install locations are handled differently on Windows
347+
import libcppyy
348+
349+
ape = os.path.dirname(libcppyy.__file__)
350+
else:
351+
import cppyy.libcppyy as libcppyy
352+
353+
ape = os.path.dirname(libcppyy.__file__)
354+
# a "normal" structure finds the include directory up to 3 levels up,
355+
# ie. dropping lib/pythonx.y[md]/site-packages
346356
for i in range(3):
347357
if os.path.exists(os.path.join(ape, 'include')):
348358
break

bindings/pyroot/cppyy/cppyy/python/cppyy/_cpython_cppyy.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33

44
import ctypes
5+
import platform
56
import sys
67

78
from . import _stdcpp_fix
@@ -27,7 +28,11 @@
2728
except ImportError:
2829
c = None
2930

30-
import libcppyy as _backend
31+
if platform.system() == "Windows":
32+
# On Windows, the library has to be searched without prefix
33+
import libcppyy as _backend
34+
else:
35+
import cppyy.libcppyy as _backend
3136

3237
if c is not None:
3338
_backend._cpp_backend = c

0 commit comments

Comments
 (0)