From 0997c6b19c6b3aaa491fca8c20cdd3f15f97df96 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sun, 30 Sep 2018 15:42:58 -0600 Subject: [PATCH] CMake: Don't depend on Python interpreter This allows building against the Python libraries even when the Python interpreter/executable is missing. The correct extensions for the binary modules will be guessed, the tests will fail, and the bytecode for any pure-Python modules will not be precompiled. --- cmake/macros/Python.cmake | 4 +++- dtool/Package.cmake | 35 ++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/cmake/macros/Python.cmake b/cmake/macros/Python.cmake index 524caae38e..a04679f5d3 100644 --- a/cmake/macros/Python.cmake +++ b/cmake/macros/Python.cmake @@ -39,7 +39,9 @@ function(add_python_target target) PREFIX "" SUFFIX "${PYTHON_EXTENSION_SUFFIX}") - install(TARGETS ${target} DESTINATION "${PYTHON_ARCH_INSTALL_DIR}/${slash_namespace}") + if(PYTHON_ARCH_INSTALL_DIR) + install(TARGETS ${target} DESTINATION "${PYTHON_ARCH_INSTALL_DIR}/${slash_namespace}") + endif() else() set_target_properties(${target} PROPERTIES OUTPUT_NAME "${basename}" diff --git a/dtool/Package.cmake b/dtool/Package.cmake index b1b0780040..71a9795d35 100644 --- a/dtool/Package.cmake +++ b/dtool/Package.cmake @@ -7,10 +7,9 @@ set(WANT_PYTHON_VERSION "" find_package(PythonInterp ${WANT_PYTHON_VERSION} QUIET) find_package(PythonLibs ${PYTHON_VERSION_STRING} QUIET) -if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND) + +if(PYTHONLIBS_FOUND) set(PYTHON_FOUND ON) -else() - set(PYTHON_FOUND OFF) endif() package_option(PYTHON DEFAULT ON @@ -19,16 +18,26 @@ is also enabled, Python bindings will be generated.") # Also detect the optimal install paths: if(HAVE_PYTHON) - execute_process( - COMMAND ${PYTHON_EXECUTABLE} - -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(False))" - OUTPUT_VARIABLE _LIB_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process( - COMMAND ${PYTHON_EXECUTABLE} - -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(True))" - OUTPUT_VARIABLE _ARCH_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) + if(WIN32 AND NOT CYGWIN) + set(_LIB_DIR ".") + set(_ARCH_DIR ".") + elseif(PYTHON_EXECUTABLE) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} + -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(False))" + OUTPUT_VARIABLE _LIB_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} + -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(True))" + OUTPUT_VARIABLE _ARCH_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + else() + set(_LIB_DIR "") + set(_ARCH_DIR "") + endif() + + execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "from sysconfig import get_config_var as g; print((g('EXT_SUFFIX') or g('SO'))[:])"