Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions CMake/ITKSetPython3Vars.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ else()
set(
_python_find_components
Interpreter
Development.Module
Development.SABIModule
)
else()
Expand Down Expand Up @@ -195,26 +196,11 @@ else()
endif()

# If a specific Python3_EXECUTABLE is provided by the user, try to infer
# the corresponding Python3_ROOT_DIR for Unix/macOS/Linux so CMake's
# FindPython3 locates the matching installation or virtual environment.
# This is especially important for virtualenv/venv/conda environments.
if(
DEFINED
Python3_EXECUTABLE
AND
NOT
DEFINED
Python3_ROOT_DIR
AND
(
UNIX
OR
APPLE
)
AND
NOT
WIN32
)
# the corresponding Python3_ROOT_DIR so CMake's FindPython3 locates the
# matching installation or virtual environment.
# This is especially important for virtualenv/venv/conda environments
# and on Windows where FindPython3 may otherwise pick the wrong installation.
if(DEFINED Python3_EXECUTABLE AND NOT DEFINED Python3_ROOT_DIR)
# First, try sys.prefix from the provided interpreter (works for venv/conda)
execute_process(
COMMAND
Expand Down
12 changes: 10 additions & 2 deletions Modules/Core/Common/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,17 @@ set(
)

if(ITK_WRAP_PYTHON)
if(ITK_USE_PYTHON_LIMITED_API AND TARGET Python3::SABIModule)
set(_itk_python_target Python3::SABIModule)
else()
set(_itk_python_target Python3::Module)
endif()
list(APPEND ITKCommon_SRCS itkPyCommand.cxx)
set_source_files_properties(
itkPyCommand.cxx
PROPERTIES
INCLUDE_DIRECTORIES
"$<TARGET_PROPERTY:Python3::Module,INTERFACE_INCLUDE_DIRECTORIES>"
"$<TARGET_PROPERTY:${_itk_python_target},INTERFACE_INCLUDE_DIRECTORIES>"
)
endif()

Expand Down Expand Up @@ -255,7 +260,10 @@ if(UNIX)
endif()
endif()
if(ITK_WRAP_PYTHON)
target_link_libraries(ITKCommon PRIVATE Python3::Module)
target_link_libraries(ITKCommon PRIVATE ${_itk_python_target})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the correct interface seems right here.

For PR #5842, we are having issues related to this. Since itkPy*.h and hxx file include Python.h in there public interface, then cast_xml need the include path. So technically this should be public linkage, but this would cause every module to link again Python which is not needed. I have been debating an about a few solution, which include linking to "Python::Module" in a couple different places.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we just need to manually plug in the dependencies into the castxml call?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest update add this to wrapping/CMakeLists.txt: list(APPEND WRAPPER_LIBRARY_LINK_LIBRARIES Python3::Module) which I think is pretty close to that.

if(MSVC)
target_link_directories(ITKCommon PRIVATE ${Python3_LIBRARY_DIRS})
endif()
endif()

if(ITK_USE_TBB)
Expand Down
6 changes: 4 additions & 2 deletions Wrapping/macro_files/itk_end_wrap_module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -527,14 +527,16 @@ ${DO_NOT_WAIT_FOR_THREADS_CALLS}
)
else()
if(MSVC)
# Disables 'conversion from 'type1' to 'type2', possible loss of data warnings
# /wd4244: Disables 'conversion from 'type1' to 'type2', possible loss of data warnings
# /wd4996: Disables deprecated declaration warnings in generated wrapper code
set_target_properties(
${lib}
PROPERTIES
COMPILE_FLAGS
"/wd4244"
"/wd4244 /wd4996"
)
endif()
target_link_directories(${lib} PUBLIC ${Python3_LIBRARY_DIRS})
Comment thread
thewtex marked this conversation as resolved.
endif()

# Link the modules together
Expand Down
Loading