Skip to content

Commit 9f0507c

Browse files
authored
Merge branch 'main' into dependabot/github_actions/actions/upload-artifact-5.0.0
2 parents e0ece85 + 9830065 commit 9f0507c

File tree

4 files changed

+46
-32
lines changed

4 files changed

+46
-32
lines changed

src/pybind11/PyBindImath/CMakeLists.txt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,24 @@ if (IMATH_INSTALL)
127127
# Set the PYTHON_INSTALL_DIR but only if it's not already set,
128128
# which allows an externally-set value to take effect.
129129
#
130-
131-
set(PYTHON_INSTALL_DIR "lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages")
130+
# PYTHON_INSTALL_DIR should be a relative path underneath the
131+
# INSTALL_DIR. Set it to Python3_SITEARCH, relative to the python
132+
# system installation.
133+
#
134+
135+
if (NOT Python3_PREFIX)
136+
# if Python3_PREFIX is not set, use the location of the python executable
137+
get_filename_component(Python3_PREFIX "${Python3_EXECUTABLE}" DIRECTORY)
138+
get_filename_component(Python3_PREFIX "${Python3_PREFIX}" DIRECTORY)
139+
endif()
140+
141+
# Ensure Python3_SITEARCH is absolute before computing relative path
142+
file(REAL_PATH "${Python3_SITEARCH}" Python3_SITEARCH_ABS)
143+
144+
file(RELATIVE_PATH PYTHON_INSTALL_DIR
145+
"${Python3_PREFIX}"
146+
"${Python3_SITEARCH_ABS}")
147+
132148
message(STATUS "installing ${PYBINDIMATH_MODULE_NAME} to ${PYTHON_INSTALL_DIR}")
133149

134150
else()

src/python/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@ if(NOT Boost_FOUND)
1919
message(FATAL_ERROR "Could not find Boost")
2020
endif()
2121

22+
if (NOT DEFINED PYTHON_INSTALL_DIR)
23+
24+
#
25+
# Set the PYTHON_INSTALL_DIR but only if it's not already set,
26+
# which allows an externally-set value to take effect.
27+
#
28+
# PYTHON_INSTALL_DIR should be a relative path underneath the
29+
# INSTALL_DIR. Set it to Python3_SITEARCH, relative to the python
30+
# system installation.
31+
#
32+
33+
if (NOT Python3_PREFIX)
34+
# if Python3_PREFIX is not set, use the location of the python executable
35+
get_filename_component(Python3_PREFIX "${Python3_EXECUTABLE}" DIRECTORY)
36+
get_filename_component(Python3_PREFIX "${Python3_PREFIX}" DIRECTORY)
37+
endif()
38+
39+
# Ensure Python3_SITEARCH is an absolute path
40+
get_filename_component(Python3_SITEARCH_ABS "${Python3_SITEARCH}" REALPATH)
41+
42+
file(RELATIVE_PATH PYTHON_INSTALL_DIR
43+
"${Python3_PREFIX}"
44+
"${Python3_SITEARCH_ABS}")
45+
46+
endif()
47+
2248
#
2349
# Python library suffix string. By default, it includes the python
2450
# version and Imath release number, e.g. "_Python3_12-3_4"

src/python/PyImath/CMakeLists.txt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,22 +202,8 @@ add_library(PyImath::Config ALIAS PyImathConfig)
202202

203203
if (IMATH_INSTALL)
204204

205-
if (NOT DEFINED PYTHON_INSTALL_DIR)
205+
message(STATUS "installing ${PYIMATH_MODULE_NAME} module to ${PYTHON_INSTALL_DIR}")
206206

207-
#
208-
# Set the PYTHON_INSTALL_DIR but only if it's not already set,
209-
# which allows an externally-set value to take effect.
210-
#
211-
212-
set(PYTHON_INSTALL_DIR "lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages")
213-
message(STATUS "installing ${PYIMATH_MODULE_NAME} module to ${PYTHON_INSTALL_DIR}")
214-
215-
else()
216-
217-
message(STATUS "installing ${PYIMATH_MODULE_NAME} module to ${PYTHON_INSTALL_DIR} (set externally)")
218-
219-
endif()
220-
221207
#
222208
# Install the python module
223209
#

src/python/PyImathNumpy/CMakeLists.txt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,7 @@ target_link_libraries(${PYIMATHNUMPY_MODULE}
4646

4747
if (IMATH_INSTALL)
4848

49-
#
50-
# Set the PYTHON_INSTALL_DIR but only if it's not already set,
51-
# which allows an externally-set value to take effect.
52-
#
53-
54-
if (NOT DEFINED PYTHON_INSTALL_DIR)
55-
56-
set(PYTHON_INSTALL_DIR "lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages")
57-
message(STATUS "installing ${PYIMATHNUMPY_MODULE} module to ${PYTHON_INSTALL_DIR}")
58-
59-
else()
60-
61-
message(STATUS "installing ${PYIMATHNUMPY_MODULE} module to ${PYTHON_INSTALL_DIR} (set externally)")
62-
63-
endif()
49+
message(STATUS "installing ${PYIMATHNUMPY_MODULE} module to ${PYTHON_INSTALL_DIR}")
6450

6551
install(TARGETS ${PYIMATHNUMPY_MODULE} LIBRARY DESTINATION ${PYTHON_INSTALL_DIR})
6652

0 commit comments

Comments
 (0)