From 82ecb0f77b8d205e617818555992b7bb1a04e56f Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Wed, 20 Jan 2021 21:05:14 -0500 Subject: [PATCH] Fix vcpkg python build compatibility --- CMakeModules/FindPythonInterp.cmake | 2 +- CMakeModules/FindwxPython.cmake | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CMakeModules/FindPythonInterp.cmake b/CMakeModules/FindPythonInterp.cmake index 67b6eb0a45..f2b57c6398 100644 --- a/CMakeModules/FindPythonInterp.cmake +++ b/CMakeModules/FindPythonInterp.cmake @@ -108,7 +108,7 @@ if(NOT PYTHON_EXECUTABLE) list( APPEND _Python_PPATHS "C:/python/${_CURRENT_VERSION}.1" ) list( APPEND _Python_PPATHS "C:/python/${_CURRENT_VERSION}.0" ) elseif(VCPKG_TOOLCHAIN) - list( APPEND _Python_PPATHS ${PYTHON_ROOT_DIR} ) + list( APPEND _Python_PPATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools/python3" ) else() list( APPEND _Python_PPATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath] ) endif() diff --git a/CMakeModules/FindwxPython.cmake b/CMakeModules/FindwxPython.cmake index 257f83c60c..8d5ae3858b 100644 --- a/CMakeModules/FindwxPython.cmake +++ b/CMakeModules/FindwxPython.cmake @@ -41,7 +41,16 @@ if( PYTHON_SITE_PACKAGE_PATH ) endif() endif() -execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "${_py_site_path}${_py_cmd}" +if( VCPKG_TOOLCHAIN ) +# python 3.8+ requires us to use python to add additiona load directories (PATH no longer supported) +# vcpkg does not copy all the dlls into the python folder so we need this for development +# as the wxpython modules need the wxwidgets library DLLs to load + set( _py_dll "import os;os.add_dll_directory(\"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin\");os.add_dll_directory(\"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/bin\");" ) +else() + set( _py_dll "" ) +endif() + +execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "${_py_dll}${_py_site_path}${_py_cmd}" RESULT_VARIABLE _WXPYTHON_VERSION_RESULT OUTPUT_VARIABLE _WXPYTHON_VERSION_FOUND OUTPUT_STRIP_TRAILING_WHITESPACE @@ -70,8 +79,9 @@ list( GET _WXPYTHON_VERSION_LIST 2 WXPYTHON_FLAVOR ) # Determine wxWidgets version used by wxPython/Phoenix if( WXPYTHON_FLAVOR MATCHES "phoenix" ) # 4.0.1;gtk3;(phoenix) does not contain wxWidgets version, request it explicitly + set( _py_cmd "import wx;print(wx.wxWidgets_version.split(' ')[1])") - execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "${_py_site_path}${_py_cmd}" + execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "${_py_dll}${_py_site_path}${_py_cmd}" RESULT_VARIABLE WXPYTHON_WXVERSION_RESULT OUTPUT_VARIABLE WXPYTHON_WXVERSION OUTPUT_STRIP_TRAILING_WHITESPACE