From 3cc0cfc48cb1c66612b69d9c6b07126412d2a069 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 9 Jan 2019 19:34:57 +0100 Subject: [PATCH] CMake: try harder to find the right Python version The FindPythonInterp module does not verify that a discovered 'python' program is actually Python 3. Replace this deprecated module by a modern version that was introduced with CMake 3.12. Remove PYTHON_EXECUTABLE from WSDG now that it is much more likely that CMake discovers the right version. Change-Id: I1f8438baced3d5bf9e1e2732980ad177d3257ca3 Reviewed-on: https://code.wireshark.org/review/31468 Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs Reviewed-by: Anders Broman --- CMakeLists.txt | 16 ++++++++++++++-- cmake/modules/LocatePythonModule.cmake | 4 +++- docbook/wsdg_src/WSDG_chapter_tools.asciidoc | 3 --- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9ba598e6f..a6b3b2029e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -913,7 +913,7 @@ endif() # - set HAVE_XXX # The minimum package list -set(PACKAGELIST Git GLIB2 GMODULE2 GTHREAD2 GCRYPT LEX YACC Perl PythonInterp) +set(PACKAGELIST Git GLIB2 GMODULE2 GTHREAD2 GCRYPT LEX YACC Perl) set(LEX_OPTIONS REQUIRED) set(GLIB2_OPTIONS REQUIRED) set(GLIB2_FIND_OPTIONS REQUIRED) @@ -921,9 +921,21 @@ set(GLIB2_MIN_VERSION 2.32.0) set(GTHREAD2_OPTIONS REQUIRED) set(GCRYPT_OPTIONS "1.4.2" REQUIRED) set(Perl_OPTIONS REQUIRED) -set(PythonInterp_OPTIONS "3.4" REQUIRED) set(YACC_OPTIONS REQUIRED) +if(CMAKE_VERSION VERSION_LESS "3.12") + # Locate the Python interpreter. Finds the wrong (Python 2) version if: + # - PATH contains python3.6, but not python3 (3.4). Affects RHEL7+EPEL. + # - Path contains C:\Python27 but not C:\Python37 (which is installed, + # but not present in PATH). + find_package(PythonInterp 3.4 REQUIRED) +else() + find_package(Python3 3.4 REQUIRED) + # Several files (including LocatePythonModule) still use the old name + # from FindPythonInterp, let's stick to it for now. + set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE}) +endif() + if (NOT WIN32) set(PACKAGELIST ${PACKAGELIST} Gettext M) set(M_OPTIONS REQUIRED) diff --git a/cmake/modules/LocatePythonModule.cmake b/cmake/modules/LocatePythonModule.cmake index efc6c3ff2e..3fbe0c793d 100644 --- a/cmake/modules/LocatePythonModule.cmake +++ b/cmake/modules/LocatePythonModule.cmake @@ -6,7 +6,9 @@ # After PATHS additional paths for python to search can be provided. # When REQUIRED is set, the function will abort the cmake execution is the module is not found function(LOCATE_PYTHON_MODULE module) - find_package(PythonInterp) + if(NOT PYTHON_EXECUTABLE) + find_package(PythonInterp) + endif() # Parse (additional) arguments set(options REQUIRED) diff --git a/docbook/wsdg_src/WSDG_chapter_tools.asciidoc b/docbook/wsdg_src/WSDG_chapter_tools.asciidoc index 5a21265a21..998f5d10f9 100644 --- a/docbook/wsdg_src/WSDG_chapter_tools.asciidoc +++ b/docbook/wsdg_src/WSDG_chapter_tools.asciidoc @@ -117,9 +117,6 @@ Let you set the path to a locally-compiled version of c-ares. Most optional libraries have xxx_INCLUDE_DIR and xxx_LIB flags that let you control their discovery. - --DPYTHON_EXECUTABLE=c:/Python36/python:: Force the Python path. - -DENABLE_APPLICATION_BUNDLE=OFF:: Disable building an application bundle (Wireshark.app) on macOS You can list all build variables (with help) by running `cmake -LH [options]