mirror of
https://github.com/avrdudes/avrdude.git
synced 2026-06-02 09:46:34 +03:00
CMakeLists.txt: allow disabling Python support (#2051)
* CMakeLists.txt: allow disabling Python support In some cases, even if Swig is found and Python3 is found, it may not be desirable to build Python support in avrdude, so this commit adds a FORCE_DISABLE_PYTHON_SUPPORTT option to be able to explicitly disable the Python support. To preserve existing behavior, this option defaults to disabled (OFF). Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Co-authored-by: Xiaofan Chen <xiaofanc@gmail.com>
This commit is contained in:
@@ -34,6 +34,7 @@ option(USE_EXTERNAL_LIBS "Use external libraries from AVRDUDE GitHub repositorie
|
||||
option(USE_LIBUSBWIN32 "Prefer libusb-win32 over libusb" OFF)
|
||||
option(DEBUG_CMAKE "Enable debugging output for this CMake project" OFF)
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
|
||||
option(FORCE_DISABLE_PYTHON_SUPPORT "Option to explicitly disable Python support" OFF)
|
||||
|
||||
if(WIN32)
|
||||
# Prefer static libraries over DLLs on Windows
|
||||
@@ -281,15 +282,31 @@ if(HAVE_LINUXGPIO)
|
||||
endif()
|
||||
|
||||
# -------------------------------------
|
||||
# Find SWIG
|
||||
find_package(SWIG 4.0 COMPONENTS python)
|
||||
if(SWIG_FOUND)
|
||||
find_package(Python3 COMPONENTS Interpreter Development)
|
||||
if(PYTHON3_FOUND)
|
||||
set(HAVE_SWIG 1)
|
||||
else()
|
||||
message(STATUS "Found SWIG but no Python3 header/library; cannot use SWIG")
|
||||
endif()
|
||||
# Find SWIG/Python3 if needed
|
||||
|
||||
if(NOT FORCE_DISABLE_PYTHON_SUPPORT)
|
||||
find_package(SWIG 4.0 COMPONENTS python)
|
||||
|
||||
if(SWIG_FOUND)
|
||||
set(Python3_FIND_STRATEGY LOCATION)
|
||||
set(Python3_FIND_UNVERSIONED_NAMES FIRST)
|
||||
find_package(Python3 COMPONENTS Interpreter Development)
|
||||
if(Python3_FOUND)
|
||||
set(HAVE_SWIG 1)
|
||||
message(STATUS "Python support enabled")
|
||||
execute_process(
|
||||
COMMAND ${Python3_EXECUTABLE} -c "import site; print(site.getsitepackages()[0])"
|
||||
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
else()
|
||||
message(STATUS "SWIG found, but Python3 headers/library missing; Python support disabled")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "SWIG not found; Python support disabled")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Python support explicitly disabled via FORCE_DISABLE_PYTHON_SUPPORT")
|
||||
endif()
|
||||
|
||||
# =====================================
|
||||
|
||||
Reference in New Issue
Block a user