Skip to content

Commit

Permalink
COMP: ITK_WRAP_PYTHON_VERSION is used for remote modules
Browse files Browse the repository at this point in the history
The remote modules need ITK_WRAP_PYTHON_VERSION defined in the ITKConfig.cmake and
also for embedded ITK builds.  The variable must be set before the
remote modules are processed.
  • Loading branch information
hjmjohnson authored and dzenanz committed Aug 21, 2022
1 parent 73ddcf5 commit 278129b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CMake/ITKConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ set(ITK_WRAP_complex_double @ITK_WRAP_complex_double@)
set(ITK_WRAP_IMAGE_DIMS "@ITK_WRAP_IMAGE_DIMS@")
set(ITK_WRAP_VECTOR_COMPONENTS "@ITK_WRAP_VECTOR_COMPONENTS@")

set(ITK_WRAP_PYTHON_VERSION "@Python3_VERSION@")
set(ITK_WRAP_PYTHON_VERSION "@ITK_WRAP_PYTHON_VERSION@")
5 changes: 5 additions & 0 deletions CMake/ITKSetPython3Vars.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ if(PYTHON_DEVELOPMENT_REQUIRED)
else() # if not PYTHON_DEVELOPMENT_REQUIRED, just find some version of Python (don't need to be as specific)
find_package(Python3 COMPONENTS Interpreter)
endif()
if(ITK_WRAP_PYTHON)
set(ITK_WRAP_PYTHON_VERSION "${Python3_VERSION}")
else()
set(ITK_WRAP_PYTHON_VERSION "ITK_WRAP_PYTHON=OFF")
endif()
if(NOT Python3_EXECUTABLE AND _specified_Python3_EXECUTABLE) # workaround for cases where FindPython3 fails to set correctly
set(Python3_EXECUTABLE ${_specified_Python3_EXECUTABLE} CACHE INTERNAL
"Path to the Python interpreter" FORCE)
Expand Down
30 changes: 14 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,20 @@ mark_as_advanced(ITK_USE_FLOAT_SPACE_PRECISION)
option(DISABLE_MODULE_TESTS "Disable all ITK module tests in `test` folder" OFF)
mark_as_advanced(DISABLE_MODULE_TESTS)

#-----------------------------------------------------------------------------
# Need to set python variables before remote modules are included.
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 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()

#-----------------------------------------------------------------------------
# Configure Eigen3 before ITKModuleEnablement
# No download or build is performed. Generates Targets and Config.cmake files for Eigen
Expand Down Expand Up @@ -568,22 +582,6 @@ endif()

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

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 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 278129b

Please sign in to comment.