Skip to content

Commit 91a2c83

Browse files
fundawangcary-ilm
authored andcommitted
Set PYTHON_INSTALL_DIR based on Python3_SITEARCH
Python3_SIETARCH is relative, but PYTHON_INSTALL_DIR is absolute. So strip the Python3_PREFIS from Python3_SITEARCH to form a relative path. This is preferable to the current hardcoded path, but is also preferable to using an absolute path, as suggested in AcademySoftwareFoundation#523. Signed-off-by: Cary Phillips <cary@ilm.com>
1 parent 95f1a89 commit 91a2c83

3 files changed

Lines changed: 49 additions & 10 deletions

File tree

src/pybind11/PyBindImath/CMakeLists.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,21 @@ 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+
file(RELATIVE_PATH PYTHON_INSTALL_DIR
142+
"${Python3_PREFIX}"
143+
"${Python3_SITEARCH}")
144+
132145
message(STATUS "installing ${PYBINDIMATH_MODULE_NAME} to ${PYTHON_INSTALL_DIR}")
133146

134147
else()

src/python/PyImath/CMakeLists.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,21 @@ if (IMATH_INSTALL)
212212
# Set the PYTHON_INSTALL_DIR but only if it's not already set,
213213
# which allows an externally-set value to take effect.
214214
#
215-
216-
set(PYTHON_INSTALL_DIR "lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages")
215+
# PYTHON_INSTALL_DIR should be a relative path underneath the
216+
# INSTALL_DIR. Set it to Python3_SITEARCH, relative to the python
217+
# system installation.
218+
#
219+
220+
if (NOT Python3_PREFIX)
221+
# if Python3_PREFIX is not set, use the location of the python executable
222+
get_filename_component(Python3_PREFIX "${Python3_EXECUTABLE}" DIRECTORY)
223+
get_filename_component(Python3_PREFIX "${Python3_PREFIX}" DIRECTORY)
224+
endif()
225+
226+
file(RELATIVE_PATH PYTHON_INSTALL_DIR
227+
"${Python3_PREFIX}"
228+
"${Python3_SITEARCH}")
229+
217230
message(STATUS "installing ${PYIMATH_MODULE_NAME} module to ${PYTHON_INSTALL_DIR}")
218231

219232
else()

src/python/PyImathNumpy/CMakeLists.txt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,27 @@ target_link_libraries(${PYIMATHNUMPY_MODULE}
5050

5151
if (IMATH_INSTALL)
5252

53-
#
54-
# Set the PYTHON_INSTALL_DIR but only if it's not already set,
55-
# which allows an externally-set value to take effect.
56-
#
57-
5853
if (NOT DEFINED PYTHON_INSTALL_DIR)
5954

60-
set(PYTHON_INSTALL_DIR "lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages")
55+
#
56+
# Set the PYTHON_INSTALL_DIR but only if it's not already set,
57+
# which allows an externally-set value to take effect.
58+
#
59+
# PYTHON_INSTALL_DIR should be a relative path underneath the
60+
# INSTALL_DIR. Set it to Python3_SITEARCH, relative to the python
61+
# system installation.
62+
#
63+
64+
if (NOT Python3_PREFIX)
65+
# if Python3_PREFIX is not set, use the location of the python executable
66+
get_filename_component(Python3_PREFIX "${Python3_EXECUTABLE}" DIRECTORY)
67+
get_filename_component(Python3_PREFIX "${Python3_PREFIX}" DIRECTORY)
68+
endif()
69+
70+
file(RELATIVE_PATH PYTHON_INSTALL_DIR
71+
"${Python3_PREFIX}"
72+
"${Python3_SITEARCH}")
73+
6174
message(STATUS "installing ${PYIMATHNUMPY_MODULE} module to ${PYTHON_INSTALL_DIR}")
6275

6376
else()

0 commit comments

Comments
 (0)