Moved wxPython/Phoenix detection to a separate CMake module

This commit is contained in:
Maciej Suminski 2018-11-02 09:42:04 +01:00
parent 23e574fbcd
commit b7b9cccffc
2 changed files with 105 additions and 71 deletions

View File

@ -729,79 +729,12 @@ if( KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES )
endif()
if( KICAD_SCRIPTING_WXPYTHON )
# Create a CMake list containing wxPython version
set( _py_cmd "import wx;print(wx.version())" )
# Add user specified Python site package path.
if( PYTHON_SITE_PACKAGE_PATH )
set( _py_site_path
"import sys;sys.path.insert(0, \"${PYTHON_SITE_PACKAGE_PATH}\");" )
if( APPLE ) # extra path for macOS, so that 'wx' module is accessible
set( _py_site_path
"${_py_site_path}sys.path.insert(0, \"${PYTHON_SITE_PACKAGE_PATH}/wx-3.0-osx_cocoa\");" )
endif()
endif()
execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "${_py_site_path}${_py_cmd}"
RESULT_VARIABLE WXPYTHON_VERSION_RESULT
OUTPUT_VARIABLE WXPYTHON_VERSION_FOUND
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Check to see if any version of wxPython is installed on the system.
if( WXPYTHON_VERSION_RESULT GREATER 0 )
message( FATAL_ERROR "wxPython/Phoenix does not appear to be installed on the system." )
endif()
# Turn the version string to a list for easier processing
set( WXPYTHON_VERSION_LIST ${WXPYTHON_VERSION_FOUND})
separate_arguments( WXPYTHON_VERSION_LIST )
list( LENGTH WXPYTHON_VERSION_LIST VERSION_LIST_LEN )
if( VERSION_LIST_LEN EQUAL 3 )
# wxPython style, e.g. '3.0.2.0;gtk3;(classic) or Pheonix style: e.g. 4.0.1;gtk3;(phoenix)
list( GET WXPYTHON_VERSION_LIST 0 WXPYTHON_VERSION )
list( GET WXPYTHON_VERSION_LIST 1 WXPYTHON_TOOLKIT )
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}"
RESULT_VARIABLE WXPYTHON_WXVERSION
OUTPUT_VARIABLE WXPYTHON_WXVERSION_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if( NOT WXPYTHON_WXVERSION_RESULT EQUAL 0 )
set( WXPYTHON_WXVERSION "3.0.2" )
message( WARNING "Could not determine wxWidgets version used by Phoenix, requesting ${WXPYTHON_WXVERSION}" )
endif()
else()
# 3.0.2.0;gtk3;(classic) has the wxWidgets version in the first part
set( WXPYTHON_WXVERSION ${WXPYTHON_VERSION} )
endif()
elseif( VERSION_LIST_LEN EQUAL 5 )
# Phoenix style, e.g. '4.0.3;gtk3;(phoenix);wxWidgets;3.0.4'
list( GET WXPYTHON_VERSION_LIST 0 WXPYTHON_VERSION )
list( GET WXPYTHON_VERSION_LIST 1 WXPYTHON_TOOLKIT )
list( GET WXPYTHON_VERSION_LIST 4 WXPYTHON_WXVERSION )
else()
message( FATAL_ERROR "Unknown wxPython/Phoenix version string: ${WXPYTHON_VERSION_FOUND}" )
endif()
find_package( wxPython REQUIRED )
message( STATUS "Found ${WXPYTHON_FLAVOR} "
"${WXPYTHON_VERSION}/${WXPYTHON_TOOLKIT} "
"(wxWidgets ${WXPYTHON_WXVERSION})" )
endif()
# Fix an incosistency between the toolkit names reported by wx.version() and wx-config for cocoa
if( WXPYTHON_TOOLKIT STREQUAL "osx-cocoa" )
set( WXPYTHON_TOOLKIT "osx_cocoa" )
endif()
message( STATUS "wxPython/Phoenix version ${WXPYTHON_VERSION}/${WXPYTHON_TOOLKIT} found." )
# Infrequently needed headers go at end of search paths, append to INC_AFTER which
# although is used for all components, should be a harmless hit for something like eeschema
# so long as unused search paths are at the end like this.

View File

@ -0,0 +1,101 @@
# CMake script for finding wxPython/Phoenix library
# Copyright (C) 2018 CERN
# Author: Maciej Suminski <maciej.suminski@cern.ch>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you may find one here:
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# or you may search the http://www.gnu.org website for the version 2 license,
# or you may write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# Exported variables:
# WXPYTHON_VERSION: wxPython/Phoenix version,
# normally 3.x.x for wxPython, 4.x.x for Phoenix
# WXPYTHON_FLAVOR: 'Phoenix' or 'wxPython'
# WXPYTHON_TOOLKIT: base library toolkit (e.g. gtk2, gtk3, msw, osx_cocoa)
# WXPYTHON_WXVERSION: wxWidgets version used by wxPython/Phoenix
# Create a CMake list containing wxPython version
set( _py_cmd "import wx;print(wx.version())" )
# Add user specified Python site package path
if( PYTHON_SITE_PACKAGE_PATH )
set( _py_site_path
"import sys;sys.path.insert(0, \"${PYTHON_SITE_PACKAGE_PATH}\");" )
if( APPLE ) # extra path for macOS, so that 'wx' module is accessible
set( _py_site_path
"${_py_site_path}sys.path.insert(0, \"${PYTHON_SITE_PACKAGE_PATH}/wx-3.0-osx_cocoa\");" )
endif()
endif()
execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "${_py_site_path}${_py_cmd}"
RESULT_VARIABLE _WXPYTHON_VERSION_RESULT
OUTPUT_VARIABLE _WXPYTHON_VERSION_FOUND
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Check to see if any version of wxPython is installed on the system.
if( _WXPYTHON_VERSION_RESULT GREATER 0 )
message( FATAL_ERROR "wxPython/Phoenix does not appear to be installed on the system" )
endif()
# Turn the version string to a list for easier processing
set( _WXPYTHON_VERSION_LIST ${_WXPYTHON_VERSION_FOUND})
separate_arguments( _WXPYTHON_VERSION_LIST )
list( LENGTH _WXPYTHON_VERSION_LIST _VERSION_LIST_LEN )
if( _VERSION_LIST_LEN LESS 3 )
message( FATAL_ERROR "Unknown wxPython/Phoenix version string: ${_WXPYTHON_VERSION_FOUND}" )
endif()
# wxPython style, e.g. '3.0.2.0;gtk3;(classic) or Pheonix style: e.g. 4.0.1;gtk3;(phoenix)
list( GET _WXPYTHON_VERSION_LIST 0 WXPYTHON_VERSION )
list( GET _WXPYTHON_VERSION_LIST 1 WXPYTHON_TOOLKIT )
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}"
RESULT_VARIABLE WXPYTHON_WXVERSION_RESULT
OUTPUT_VARIABLE WXPYTHON_WXVERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if( NOT WXPYTHON_WXVERSION_RESULT EQUAL 0 )
set( WXPYTHON_WXVERSION "3.0.2" )
message( WARNING "Could not determine wxWidgets version used by Phoenix, "
"requesting ${WXPYTHON_WXVERSION}" )
endif()
set( WXPYTHON_FLAVOR "Phoenix" )
elseif( WXPYTHON_FLAVOR MATCHES "classic" )
# 3.0.2.0;gtk3;(classic) has the wxWidgets version in the first part
set( WXPYTHON_WXVERSION ${WXPYTHON_VERSION} )
set( WXPYTHON_FLAVOR "wxPython" )
else()
message( FATAL_ERROR "Unknown wxPython/Phoenix type: ${WXPYTHON_FLAVOR}")
endif()
# Fix an incosistency between the toolkit names reported by wx.version() and wx-config for cocoa
if( WXPYTHON_TOOLKIT STREQUAL "osx-cocoa" )
set( WXPYTHON_TOOLKIT "osx_cocoa" )
endif()