diff --git a/CMake/ITKSetPython3Vars.cmake b/CMake/ITKSetPython3Vars.cmake index 4a396cc07a6..061fde1476e 100644 --- a/CMake/ITKSetPython3Vars.cmake +++ b/CMake/ITKSetPython3Vars.cmake @@ -109,6 +109,7 @@ else() set( _python_find_components Interpreter + Development.Module Development.SABIModule ) else() @@ -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 diff --git a/Modules/Core/Common/src/CMakeLists.txt b/Modules/Core/Common/src/CMakeLists.txt index 59f4d0a2c9f..22573b3ea70 100644 --- a/Modules/Core/Common/src/CMakeLists.txt +++ b/Modules/Core/Common/src/CMakeLists.txt @@ -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 - "$" + "$" ) endif() @@ -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}) + if(MSVC) + target_link_directories(ITKCommon PRIVATE ${Python3_LIBRARY_DIRS}) + endif() endif() if(ITK_USE_TBB) diff --git a/Wrapping/macro_files/itk_end_wrap_module.cmake b/Wrapping/macro_files/itk_end_wrap_module.cmake index bb7288d3760..bfb53dd9796 100644 --- a/Wrapping/macro_files/itk_end_wrap_module.cmake +++ b/Wrapping/macro_files/itk_end_wrap_module.cmake @@ -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}) endif() # Link the modules together