Skip to content

Commit

Permalink
COMP: Allow building basic ITK on computer without python3.5
Browse files Browse the repository at this point in the history
This patch consolidates the searching for python components
into the main CMakeLists.txt file.
  • Loading branch information
hjmjohnson committed Jan 9, 2020
1 parent e5cbf1e commit 764737d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 88 deletions.
21 changes: 0 additions & 21 deletions CMake/ITKModuleDoxygen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,6 @@
# ${_name}.dot file which defines the local dependency as graph
# which will be then processed by dot

# python is needed to verify the presence of the module name in the doxygen header
# Don't require it to not force the developers to install python to be able to build
# ITK. The tests will simply not be run if python is not available.
# Prefer to use more robust FindPython3 module if greater than cmake 3.12.0
if("${CMAKE_VERSION}" VERSION_LESS_EQUAL "3.12.0")
# Use of PythonInterp and PythonLibs is dprecated since cmake version 3.12.0

# configure python (find PythonInterp first, as of cmake 3.1)
find_package(PythonInterp)
# Check for supported python versions
if(PYTHON_VERSION_STRING VERSION_LESS 3.5)
message(FATAL_ERROR "Python versions less than 3.5 are not supported. Python version: \"${PYTHON_VERSION_STRING}\".")
endif()

## For forward compatibility with cmake 3.12.0 or greater
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
else()
find_package(Python3 COMPONENTS Interpreter REQUIRED)
endif()


macro( itk_module_doxygen _name )

# _content defines the content of the ${_name}.dox file
Expand Down
19 changes: 0 additions & 19 deletions CMake/ITKModuleHeaderTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,6 @@
# primary purpose of this test is to make sure there are not missing module
# dependencies.

# This does not force the developer to install python to be able to build ITK.
# The tests will simply not be run if python is unavailable.
# Prefer to use more robust FindPython3 module if greater than cmake 3.12.0
if("${CMAKE_VERSION}" VERSION_LESS_EQUAL "3.12.0")
# Use of PythonInterp and PythonLibs is dprecated since cmake version 3.12.0

# configure python (find PythonInterp first, as of cmake 3.1)
find_package(PythonInterp)
# Check for supported python versions
if(PYTHON_VERSION_STRING VERSION_LESS 3.5)
message(FATAL_ERROR "Python versions less than 3.5 are not supported. Python version: \"${PYTHON_VERSION_STRING}\".")
endif()

## For forward compatibility with cmake 3.12.0 or greater
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
else()
find_package(Python3 COMPONENTS Interpreter REQUIRED)
endif()

# Improve performance of MSVC GUI, by reducing number of header tests.
set( MAXIMUM_NUMBER_OF_HEADERS_default 35 )
if( MSVC )
Expand Down
62 changes: 32 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -512,52 +512,54 @@ endif()

install(FILES "LICENSE" "NOTICE" "README.md" DESTINATION ${ITK_INSTALL_DOC_DIR} COMPONENT Runtime)

if(BUILD_TESTNG OR ITK_WRAP_PYTHON)
# Python3 is required if testing (for google tests) or wrapping for python is requested.
# Because GoogleTest uses deprecated FindPythonInterp
if(BUILD_TESTING OR ITK_BUILD_DOCUMENTATION OR ITK_WRAP_PYTHON)
# Prefer to use more robust FindPython3 module if greater than cmake 3.12.0
if("${CMAKE_VERSION}" VERSION_LESS_EQUAL "3.12.0")
# Use of PythonInterp and PythonLibs is dprecated since cmake version 3.12.0

# Because GoogleTest uses deprecated FindPythonInterp, attempt finding Python3 versions first
# Use of PythonInterp and PythonLibs is deprecated since cmake version 3.12.0
# Only use deprecated mechanisms for older versions of cmake
set(Python_ADDITIONAL_VERSIONS 3.9 3.8 3.7 3.6 3.5)
# configure python (find PythonInterp first, as of cmake 3.1)
find_package(PythonInterp REQUIRED)
# Check for supported python versions
if(PYTHON_VERSION_STRING VERSION_LESS 3.5)
message(WARNING "Python versions less than 3.5 are not supported. Python version: \"${PYTHON_VERSION_STRING}\".")
endif()

set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})

find_package(PythonInterp)
if(ITK_WRAP_PYTHON)
find_package(PythonLibs REQUIRED)
# check for version mismatch.
if(PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND
AND NOT(PYTHON_VERSION_STRING VERSION_EQUAL PYTHONLIBS_VERSION_STRING))
message(WARNING "Python executable (\"${PYTHON_VERSION_STRING}\") and library (\"${PYTHONLIBS_VERSION_STRING}\") version mismatch.")
message(FATAL_ERROR "Python executable (\"${PYTHON_VERSION_STRING}\") and library (\"${PYTHONLIBS_VERSION_STRING}\") version mismatch.")
endif()
## For forward compatibility with cmake 3.12.0 or greater
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.
# to emulate the same behavior as find(Python3 ..) from cmake 3.12.0+
unset(PYTHON_EXECUTABLE)
unset(PYTHONINTERP_FOUND)
unset(PYTHON_VERSION_STRING)
unset(PYTHON_INCLUDE_DIRS)
else()
## For forward compatibility with cmake 3.12.0 or greater, emulate variable names from FindPython3.cmake
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
set(Python3_Interpreter_FOUND ${PYTHONINTERP_FOUND})
set(Python3_VERSION ${PYTHON_VERSION_STRING})

set(Python3_Development_FOUND ${PYTHONLIBS_FOUND})
set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})
set(Python3_LIBRARIES ${PYTHON_LIBRARIES})
endif()
else()
if(ITK_WRAP_PYTHON)
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
else()
find_package(Python3 COMPONENTS Interpreter REQUIRED)
find_package(Python3 COMPONENTS Interpreter)
endif()
# Check for supported python versions
if(Python3_VERSION VERSION_LESS 3.5)
message(WARNING "Python versions less than 3.5 are not supported. Python version: \"${Python3_VERSION}\".")
endif()
# For GoogleTest to force use of same python interpreter as found by the Python3 package
# as is looked for by the FindPythonInterp from the incluced GoogleTest package.
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
set(PYTHONINTERP_FOUND ${Python3_Interpreter_FOUND})
set(PYTHON_VERSION ${Python3_VERSION})
set(PYTHON_VERSION_MAJOR ${Python3_VERSION_MAJOR})
set(PYTHON_VERSION_MINOR ${Python3_VERSION_MINOR})
set(PYTHON_VERSION_PATCH ${Python3_VERSION_PATCH})
endif()

if(ITK_WRAP_PYTHON AND NOT Python3_Interpreter_FOUND)
message(FATAL_ERROR "Python version >=3.5 not found for wrapping.")
endif()
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()
endif()

Expand Down
18 changes: 0 additions & 18 deletions Wrapping/Generators/SwigInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@ if("${CMAKE_BINARY_DIR}" MATCHES "^.* .*$")
message(FATAL_ERROR "Swig and PCRE do not support paths with space characters. Please change build directory name.")
endif()

# Prefer to use more robust FindPython3 module if greater than cmake 3.12.0
if("${CMAKE_VERSION}" VERSION_LESS_EQUAL "3.12.0")
# Use of PythonInterp and PythonLibs is dprecated since cmake version 3.12.0

# configure python (find PythonInterp first, as of cmake 3.1)
find_package(PythonInterp)
# Check for supported python versions
if(PYTHON_VERSION_STRING VERSION_LESS 3.5)
message(FATAL_ERROR "Python versions less than 3.5 are not supported. Python version: \"${PYTHON_VERSION_STRING}\".")
endif()

## For forward compatibility with cmake 3.12.0 or greater
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
else()
find_package(Python3 COMPONENTS Interpreter REQUIRED)
endif()


###############################################################################
# Build swig

Expand Down

0 comments on commit 764737d

Please sign in to comment.