CMake: try harder to find the right Python version
authorPeter Wu <peter@lekensteyn.nl>
Wed, 9 Jan 2019 18:34:57 +0000 (19:34 +0100)
committerAnders Broman <a.broman58@gmail.com>
Thu, 10 Jan 2019 06:42:08 +0000 (06:42 +0000)
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 <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
CMakeLists.txt
cmake/modules/LocatePythonModule.cmake
docbook/wsdg_src/WSDG_chapter_tools.asciidoc

index b9ba598e6f2a649bd5f250228d888bce840d61c5..a6b3b2029e9f45ec142ccdc0bd52808c3a1bd0f4 100644 (file)
@@ -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)
index efc6c3ff2eb763440fdffa321e63b41e540404ab..3fbe0c793de4e64834f5a3d257fc880b70b8d396 100644 (file)
@@ -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)
index 5a21265a21d20546f6666bc6dd95a442afda3981..998f5d10f95b354ca73e94181222d8f0b07b41ca 100644 (file)
@@ -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]