From b81c500ce22a23eb39a8369c12ce3e2730a8b5e7 Mon Sep 17 00:00:00 2001 From: Christian Ewald Date: Mon, 8 Aug 2016 08:31:08 +0200 Subject: [PATCH] Fixed finding python libraries on windows in venv When run on windows in a venv, PYTHON_LIBRARY pointet to a non-existant location in the virtual environment directory. This has been fixed by testing if the path exists and, if not, trying an alternative path, relative to the PYTHON_INCLUDE_DIR. If the alternative path doesn't exit as well, an error will be raised. --- tools/FindPythonLibsNew.cmake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/FindPythonLibsNew.cmake b/tools/FindPythonLibsNew.cmake index bfc865c8f..76e18b390 100644 --- a/tools/FindPythonLibsNew.cmake +++ b/tools/FindPythonLibsNew.cmake @@ -142,6 +142,20 @@ endif() if(CMAKE_HOST_WIN32) set(PYTHON_LIBRARY "${PYTHON_PREFIX}/libs/Python${PYTHON_LIBRARY_SUFFIX}.lib") + + # when run in a venv, PYTHON_PREFIX points to it. But the libraries remain in the + # original python installation. They may be found relative to PYTHON_INCLUDE_DIR. + if(NOT EXISTS "${PYTHON_LIBRARY}") + get_filename_component(_PYTHON_ROOT ${PYTHON_INCLUDE_DIR} DIRECTORY) + set(PYTHON_LIBRARY + "${_PYTHON_ROOT}/libs/Python${PYTHON_LIBRARY_SUFFIX}.lib") + endif() + + # raise an error if the python libs are still not found. + if(NOT EXISTS "${PYTHON_LIBRARY}") + message(FATAL_ERROR "Python libraries not found") + endif() + elseif(APPLE) set(PYTHON_LIBRARY "${PYTHON_PREFIX}/lib/libpython${PYTHON_LIBRARY_SUFFIX}.dylib")