Skip to content

Commit

Permalink
ENH: Python wrapping fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Jan 18, 2021
1 parent 1e0755c commit dd6f608
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions CMake/ITKSetPython3Vars.cmake
@@ -1,6 +1,5 @@
# This file provides a work-around to provide consistent
# python3 cmake variables for cmake versions pre/post 3.12.0
# NOTE: Only python 3 versions 3.6 and above are searched for.

# If the cmake variable "PYTHON_DEVELOPMENT_REQUIRED" is set to ON
# then the development environments are found.
Expand Down Expand Up @@ -29,8 +28,8 @@ if("${CMAKE_VERSION}" VERSION_LESS_EQUAL "3.15.0")
message(FATAL_ERROR "Python executable (\"${PYTHON_VERSION_STRING}\") and library (\"${PYTHONLIBS_VERSION_STRING}\") version mismatch.")
endif()
endif()
if(PYTHON_VERSION_STRING VERSION_LESS 3.5)
# if python version is less than 3.5, unset so that it appears that no python version is found.
if(PYTHON_VERSION_STRING VERSION_LESS 3.6)
# if python version is less than 3.6, unset so that it appears that no python version is found.
# to emulate the same behavior as find(Python3 ..) from cmake 3.12.0+
unset(PYTHON_EXECUTABLE)
unset(PYTHONINTERP_FOUND)
Expand All @@ -52,6 +51,7 @@ else()
if(DEFINED Python3_EXECUTABLE) # if already specified
set(_specified_Python3_EXECUTABLE ${Python3_EXECUTABLE})
endif()
# set(Python3_FIND_REGISTRY LAST) # default is FIRST. Do we need/want this?
find_package(Python3 COMPONENTS Interpreter Development)
if(DEFINED _specified_Python3_EXECUTABLE)
set(Python3_EXECUTABLE ${_specified_Python3_EXECUTABLE} CACHE INTERNAL
Expand Down
10 changes: 7 additions & 3 deletions CMakeLists.txt
Expand Up @@ -600,14 +600,18 @@ if(BUILD_TESTING OR ITK_BUILD_DOCUMENTATION OR ITK_WRAP_PYTHON)
set(PYTHON_DEVELOPMENT_REQUIRED ${ITK_WRAP_PYTHON})
include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/ITKSetPython3Vars.cmake)

if(ITK_WRAP_PYTHON AND Python3_VERSION VERSION_LESS 3.5)
message(FATAL_ERROR "Python versions less than 3.5 are not supported for wrapping. Python version: \"${Python3_VERSION}\".")
endif()
if(ITK_WRAP_PYTHON AND NOT Python3_INCLUDE_DIRS)
message(FATAL_ERROR "Python version ${Python3_VERSION} development environment not found for wrapping.")
endif()
if(NOT Python3_ROOT_DIR)
get_filename_component(Python3_ROOT_DIR ${Python3_EXECUTABLE} DIRECTORY)
endif()
endif()

# Add user-visible cache entry
set(Python3_ROOT_DIR ${Python3_ROOT_DIR} CACHE PATH
"Which installation or virtual environment of Python to use" FORCE)

if(BUILD_TESTING)
# If building the testing, write the test costs (i.e. time to run)
# analysis to disk to more easily review long-running test times
Expand Down

0 comments on commit dd6f608

Please sign in to comment.