← Back to team overview

kicad-developers team mailing list archive

[Patch] Cleanup of cmake python flag dependency handling

 

Based on the previous discussion on the list about the cmake handling for
the python flags, I have made the attached patch for master. In it I have
cleaned up how all the KICAD_SCRIPTING_* flags are handled in the main
cmake file so that now the flag KICAD_SCRIPTING acts as a global off switch
for all python support (it will set all other flags to OFF when it is set
to OFF by the user). I have also added version checking to the wxPython
detection portion, so that it now verifies that Phoenix was actually found
when it was requested, and that the classic interface was found if it was
requested. A mismatch in the wxPython requested flavor and found flavor is
a fatal error for the process so the user has to sort out what is happening
with their versioning.

I do not believe these changes will break existing build processes, since
they should already have the flags in the valid combinations and the
defaults for the flags remain the same.

-Ian
From 3e5f5db353bb1581b808e0e1bb720ed65c2c93fe Mon Sep 17 00:00:00 2001
From: Ian McInerney <Ian.S.McInerney@xxxxxxxx>
Date: Thu, 20 Jun 2019 17:23:57 +0100
Subject: [PATCH] Cleanup cmake python dependency handling to catch errors

* Changed the KICAD_SCRIPTING flag to be a global disable, so it
  will disable all other scripting flags when set to OFF
* Added version testing with the wxPython flags to ensure the
  proper version is found for the flags provided
---
 CMakeLists.txt                         | 69 ++++++++++++++++++--------
 Documentation/development/compiling.md | 31 +++++++-----
 2 files changed, 67 insertions(+), 33 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d6e18c2f9..ee43d9eb9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -100,28 +100,39 @@ option( KICAD_BUILD_QA_TESTS
     "Build software Quality assurance unit tests (default ON)"
     ON )
 
+option( BUILD_GITHUB_PLUGIN
+    "Build the GITHUB_PLUGIN for pcbnew."
+    ON )
+
+option( KICAD_SPICE
+    "Build KiCad with internal Spice simulator."
+    ON )
+
 # when option KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES is enabled:
 # PYTHON_EXECUTABLE can be defined when invoking cmake
 # ( use -DPYTHON_EXECUTABLE=<python path>/python.exe or python2 )
 # when not defined by user, the default is python.exe under Windows and python2 for others
 # python binary file should be in exec path.
 
-# KICAD_SCRIPTING_MODULES requires KICAD_SCRIPTING enable it here if KICAD_SCRIPTING_MODULES is ON
-if ( KICAD_SCRIPTING_MODULES AND NOT KICAD_SCRIPTING )
-    message(STATUS "Changing KICAD_SCRIPTING to ON as needed by KICAD_SCRIPTING_MODULES")
-    set ( KICAD_SCRIPTING ON )
+# KICAD_SCRIPTING controls the entire python scripting system. If it is off, no other scripting
+# functions are available.
+if ( NOT KICAD_SCRIPTING )
+    message( STATUS "KICAD_SCRIPTING is OFF: Disabling all python scripting support" )
+    set( KICAD_SCRIPTING_MODULES OFF )
+    set( KICAD_SCRIPTING_ACTION_MENU OFF )
+    set( KICAD_SCRIPTING_PYTHON3 OFF )
+    set( KICAD_SCRIPTING_WXPYTHON OFF )
+    set( KICAD_SCRIPTING_WXPYTHON_PHOENIX OFF)
 endif()
 
-# same with KICAD_SCRIPTING_ACTION_MENUS
-if ( KICAD_SCRIPTING_ACTION_MENU AND NOT KICAD_SCRIPTING )
-    message(STATUS "Changing KICAD_SCRIPTING to ON as needed by KICAD_SCRIPTING_ACTION_MENU")
-    set ( KICAD_SCRIPTING ON )
+# KICAD_SCRIPTING_WXPYTHON_PHOENIX requires enabling the KICAD_SCRIPTING_WXPYTHON flag
+# so that the wxWidgets library is properly versioned
+if ( KICAD_SCRIPTING AND NOT KICAD_SCRIPTING_WXPYTHON AND KICAD_SCRIPTING_WXPYTHON_PHOENIX )
+    message( STATUS
+        "KICAD_SCRIPTING_WXPYTHON_PHOENIX has been requested, setting KICAD_SCRIPTING_WXPYTHON to ON")
+    set( KICAD_SCRIPTING_WXPYTHON ON)
 endif()
 
-option( BUILD_GITHUB_PLUGIN "Build the GITHUB_PLUGIN for pcbnew." ON )
-
-option( KICAD_SPICE "Build KiCad with internal Spice simulator." ON )
-
 # Global setting: exports are explicit
 set( CMAKE_CXX_VISIBILITY_PRESET "hidden" )
 set( CMAKE_VISIBILITY_INLINES_HIDDEN ON )
@@ -627,8 +638,9 @@ set( INC_AFTER
     ${CMAKE_BINARY_DIR}
     )
 
-
+#
 # Find Python and other scripting resources
+#
 if( KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES )
 
     # SWIG 3.0 or later require for C++11 support.
@@ -686,19 +698,36 @@ if( KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES )
         find_package( PythonLibs 2.6 REQUIRED )
     endif()
 
-    if( KICAD_SCRIPTING_WXPYTHON )
-        find_package( wxPython REQUIRED )
-        message( STATUS "Found ${WXPYTHON_FLAVOR} "
-            "${WXPYTHON_VERSION}/${WXPYTHON_TOOLKIT} "
-            "(wxWidgets ${WXPYTHON_WXVERSION})" )
-    endif()
-
     # 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.
     set( INC_AFTER ${INC_AFTER} ${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/scripting )
 endif()
 
+# Find the wxPython installation if requested
+if( KICAD_SCRIPTING_WXPYTHON )
+    find_package( wxPython REQUIRED )
+
+    if( KICAD_SCRIPTING_WXPYTHON_PHOENIX AND WXPYTHON_VERSION VERSION_LESS 4.0.0 )
+        message( FATAL_ERROR
+            "Unable to find wxPython Phoenix,"
+            " instead found wxPython Classic ${WXPYTHON_VERSION}" )
+    endif()
+
+    # The test VERSION_GREATER_EQUAL is only available in cmake >3.7, so use the max possible
+    # version for the 3.0 line as the basis of the comparison
+    if( NOT KICAD_SCRIPTING_WXPYTHON_PHOENIX AND WXPYTHON_VERSION VERSION_GREATER 3.9.999 )
+        message( FATAL_ERROR
+            "Unable to find wxPython Classic,"
+            " instead found wxPython Phoenix ${WXPYTHON_VERSION}" )
+    endif()
+
+    message( STATUS "Found ${WXPYTHON_FLAVOR} "
+        "${WXPYTHON_VERSION}/${WXPYTHON_TOOLKIT} "
+        "(wxWidgets ${WXPYTHON_WXVERSION})" )
+endif()
+
+
 #
 # Find wxWidgets library, required
 #
diff --git a/Documentation/development/compiling.md b/Documentation/development/compiling.md
index 574683e1f..3b16725f6 100644
--- a/Documentation/development/compiling.md
+++ b/Documentation/development/compiling.md
@@ -138,35 +138,40 @@ these options and their default values.
 ## Scripting Support ## {#scripting_opt}
 
 The KICAD_SCRIPTING option is used to enable building the Python scripting support into Pcbnew.
-This options is enabled by default.
+This options is enabled by default, and will disable all other KICAD_SCRIPTING_* options when
+it is disabled.
 
-## Scripting Module Support ## {#scripting_mod_opt}
+## Python 3 Scripting Support ## {#python3}
 
-The KICAD_SCRIPTING_MODULES option is used to enable building and installing the Python modules
-supplied by KiCad.  This option is enabled by default and it will enable
-[KICAD_SCRIPTING](#scripting_opt) if disabled.
+The KICAD_SCRIPTING_PYTHON3 option is used to enable using Python 3 for the scripting support
+instead of Python 2.  This option is disabled by default and only is relevant if
+[KICAD_SCRIPTING](#scripting_opt) is enabled.
 
-## Python 3 Scripting Support ## {#python3}
+## Scripting Module Support ## {#scripting_mod_opt}
 
-The KICAD_SCRIPTING_PYTHON3 option is used to enable building of the Python 3 interface instead
-of Python 2.  This option is disabled by default.
+The KICAD_SCRIPTING_MODULES option is used to enable building and installing the Python modules
+supplied by KiCad.  This option is enabled by default, but will be disabled if
+[KICAD_SCRIPTING](#scripting_opt) is disabled.
 
 ## wxPython Scripting Support ## {#wxpython_opt}
 
 The KICAD_SCRIPTING_WXPYTHON option is used to enable building the wxPython interface into
-Pcbnew including the wxPython console.  This option is enabled by default.
+Pcbnew including the wxPython console.  This option is enabled by default, but will be disabled if
+[KICAD_SCRIPTING](#scripting_opt) is disabled.
 
 ## wxPython Phoenix Scripting Support ## {#wxpython_phoenix}
 
 The KICAD_SCRIPTING_WXPYTHON_PHOENIX option is used to enable building the wxPython interface with
-the new Phoenix binding instead of the legacy one.  This option is disabled by default.
+the new Phoenix binding instead of the legacy one.  This option is disabled by default, and
+enabling it requires [KICAD_SCRIPTING](#scripting_opt) to be enabled.
 
 ## Python Scripting Action Menu Support ## {#python_action_menu_opt}
 
 The KICAD_SCRIPTING_ACTION_MENU option allows Python scripts to be added directly to the Pcbnew
-menu.  This option is enabled by default and will enable [KICAD_SCRIPTING](#scripting_opt) if
-disabled.  Please note that this option is highly experimental and can cause Pcbnew to crash
-if Python scripts create an invalid object state within Pcbnew.
+menu.  This option is enabled by default, but will be disabled if
+[KICAD_SCRIPTING](#scripting_opt) is disabled.  Please note that this option is highly
+experimental and can cause Pcbnew to crash if Python scripts create an invalid object state
+within Pcbnew.
 
 ## GitHub Plugin ## {#github_opt}
 
-- 
2.17.2


Follow ups