Skip to content

Commit

Permalink
Ensure FIND_PACKGE PythonInterp called before PythonLibs
Browse files Browse the repository at this point in the history
Upstream Cmake docs specify that PythonInterp should be called before
PythonLibs[1].  In some environments, inconsistency is possible when called
out of order.

[1] https://cmake.org/cmake/help/latest/module/FindPythonInterp.html
  • Loading branch information
markmcclain committed Oct 28, 2021
1 parent ff88787 commit 35677c1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ IF (ENABLE_PYTHON3 AND NOT DEFINED PythonLibs_FIND_VERSION)
SET (PythonLibs_FIND_VERSION_MAJOR 2)
ENDIF (ENABLE_PYTHON3 AND NOT DEFINED PythonLibs_FIND_VERSION)

FIND_PACKAGE (PythonLibs REQUIRED)
IF(PYTHONLIBS_VERSION_STRING MATCHES "^([0-9.]+)")
FIND_PACKAGE (PythonInterp ${python_version} REQUIRED)
IF(PYTHON_VERSION_STRING MATCHES "^([0-9.]+)")
SET(python_version "${CMAKE_MATCH_1}")
ELSE()
MESSAGE(FATAL_ERROR "PythonLibs version format unknown '${PYTHONLIBS_VERSION_STRING}'")
MESSAGE(FATAL_ERROR "PythonInterp version format unknown '${PYTHONINTERP_VERSION_STRING}'")
ENDIF()
FIND_PACKAGE (PythonInterp ${python_version} REQUIRED)
FIND_PACKAGE (PythonLibs ${python_version} REQUIRED)

EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_lib(True))" OUTPUT_VARIABLE PYTHON_INSTALL_DIR)

Expand Down

0 comments on commit 35677c1

Please # to comment.