You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
4.3 KiB

  1. # CMake script for finding wxPython/Phoenix library
  2. # Copyright (C) 2018 CERN
  3. # Author: Maciej Suminski <maciej.suminski@cern.ch>
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, you may find one here:
  17. # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  18. # or you may search the http://www.gnu.org website for the version 2 license,
  19. # or you may write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  21. # Exported variables:
  22. # WXPYTHON_VERSION: wxPython/Phoenix version,
  23. # normally 3.x.x for wxPython, 4.x.x for Phoenix
  24. # WXPYTHON_FLAVOR: 'Phoenix' or 'wxPython'
  25. # WXPYTHON_TOOLKIT: base library toolkit (e.g. gtk2, gtk3, msw, osx_cocoa)
  26. # WXPYTHON_WXVERSION: wxWidgets version used by wxPython/Phoenix
  27. # Create a CMake list containing wxPython version
  28. set( _py_cmd "import wx;print(wx.version())" )
  29. # Add user specified Python site package path
  30. if( PYTHON_SITE_PACKAGE_PATH )
  31. set( _py_site_path
  32. "import sys;sys.path.insert(0, \"${PYTHON_SITE_PACKAGE_PATH}\");" )
  33. endif()
  34. if( VCPKG_TOOLCHAIN )
  35. # python 3.8+ requires us to use python to add additional load directories (PATH no longer supported)
  36. # vcpkg does not copy all the dlls into the python folder so we need this for development
  37. # as the wxpython modules need the wxwidgets library DLLs to load
  38. 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\");" )
  39. else()
  40. set( _py_dll "" )
  41. endif()
  42. execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "${_py_dll}${_py_site_path}${_py_cmd}"
  43. RESULT_VARIABLE _WXPYTHON_VERSION_RESULT
  44. OUTPUT_VARIABLE _WXPYTHON_VERSION_FOUND
  45. OUTPUT_STRIP_TRAILING_WHITESPACE
  46. )
  47. # Check to see if any version of wxPython is installed on the system.
  48. if( _WXPYTHON_VERSION_RESULT GREATER 0 )
  49. message( FATAL_ERROR "wxPython/Phoenix does not appear to be installed on the system" )
  50. endif()
  51. # Turn the version string to a list for easier processing
  52. set( _WXPYTHON_VERSION_LIST ${_WXPYTHON_VERSION_FOUND})
  53. separate_arguments( _WXPYTHON_VERSION_LIST )
  54. list( LENGTH _WXPYTHON_VERSION_LIST _VERSION_LIST_LEN )
  55. if( _VERSION_LIST_LEN LESS 3 )
  56. message( FATAL_ERROR "Unknown wxPython/Phoenix version string: ${_WXPYTHON_VERSION_FOUND}" )
  57. endif()
  58. # wxPython style, e.g. '3.0.2.0;gtk3;(classic) or Pheonix style: e.g. 4.0.1;gtk3;(phoenix)
  59. list( GET _WXPYTHON_VERSION_LIST 0 WXPYTHON_VERSION )
  60. list( GET _WXPYTHON_VERSION_LIST 1 WXPYTHON_TOOLKIT )
  61. list( GET _WXPYTHON_VERSION_LIST 2 WXPYTHON_FLAVOR )
  62. # Determine wxWidgets version used by wxPython/Phoenix
  63. if( WXPYTHON_FLAVOR MATCHES "phoenix" )
  64. # 4.0.1;gtk3;(phoenix) does not contain wxWidgets version, request it explicitly
  65. set( _py_cmd "import wx;print(wx.wxWidgets_version.split(' ')[1])")
  66. execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "${_py_dll}${_py_site_path}${_py_cmd}"
  67. RESULT_VARIABLE WXPYTHON_WXVERSION_RESULT
  68. OUTPUT_VARIABLE WXPYTHON_WXVERSION
  69. OUTPUT_STRIP_TRAILING_WHITESPACE
  70. )
  71. if( NOT WXPYTHON_WXVERSION_RESULT EQUAL 0 )
  72. set( WXPYTHON_WXVERSION "3.0.2" )
  73. message( WARNING "Could not determine wxWidgets version used by Phoenix, "
  74. "requesting ${WXPYTHON_WXVERSION}" )
  75. endif()
  76. set( WXPYTHON_FLAVOR "Phoenix" )
  77. elseif( WXPYTHON_FLAVOR MATCHES "classic" )
  78. # 3.0.2.0;gtk3;(classic) has the wxWidgets version in the first part
  79. set( WXPYTHON_WXVERSION ${WXPYTHON_VERSION} )
  80. set( WXPYTHON_FLAVOR "wxPython" )
  81. else()
  82. message( FATAL_ERROR "Unknown wxPython/Phoenix type: ${WXPYTHON_FLAVOR}")
  83. endif()
  84. # Fix an incosistency between the toolkit names reported by wx.version() and wx-config for cocoa
  85. if( WXPYTHON_TOOLKIT STREQUAL "osx-cocoa" )
  86. set( WXPYTHON_TOOLKIT "osx_cocoa" )
  87. endif()