From e1afb533c052e6b092a6876153c3241d297bb6a5 Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Thu, 26 Feb 2026 21:54:18 +0000 Subject: [PATCH 1/3] BUG: Use module's interface include in wrapping's castxml Use generator expression to convert target property into properly formatted string for include file. Change to file with GENERATE option to support generator expressions. There were redundant calls to configure the inc file for each wrapping file. An additional prefix is added to the inc file to create multiple. --- Wrapping/TypedefMacros.cmake | 1 - .../itk_auto_load_submodules.cmake | 30 +++++++++++++++---- .../macro_files/itk_end_wrap_module.cmake | 14 +-------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Wrapping/TypedefMacros.cmake b/Wrapping/TypedefMacros.cmake index 1fcfb69fa5d..4d034eab42d 100644 --- a/Wrapping/TypedefMacros.cmake +++ b/Wrapping/TypedefMacros.cmake @@ -148,7 +148,6 @@ macro(itk_wrap_module library_name) # be linked to the wrapper library. set( WRAPPER_LIBRARY_LINK_LIBRARIES - ${ITK_LIBRARIES} ${ITK_LIBRARY_NAMESPACE}::${library_name}Module ) diff --git a/Wrapping/macro_files/itk_auto_load_submodules.cmake b/Wrapping/macro_files/itk_auto_load_submodules.cmake index 30008b0f24b..42eb4b5a968 100644 --- a/Wrapping/macro_files/itk_auto_load_submodules.cmake +++ b/Wrapping/macro_files/itk_auto_load_submodules.cmake @@ -106,7 +106,7 @@ function(generate_castxml_commandline_flags) list(APPEND include_dir_list ${ITK_INCLUDE_DIRS}) list(REMOVE_DUPLICATES include_dir_list) - # CONFIG_CASTXML_INC_CONTENTS - variable used for building contents to write with configure_file() + # CONFIG_CASTXML_INC_CONTENTS - variable used for building contents to write with file(GENERATE) unset(CONFIG_CASTXML_INC_CONTENTS) foreach(dir ${include_dir_list}) set( @@ -116,6 +116,23 @@ function(generate_castxml_commandline_flags) endforeach() unset(include_dir_list) + foreach(_depend IN LISTS WRAPPER_LIBRARY_LINK_LIBRARIES) + if(TARGET ${_depend}) + set( + CONFIG_CASTXML_INC_CONTENTS + "${CONFIG_CASTXML_INC_CONTENTS}$,REPLACE,^(.+)$,\"-I\\1\">,\n>\n" + ) + set( + CONFIG_CASTXML_INC_CONTENTS + "${CONFIG_CASTXML_INC_CONTENTS}$,REPLACE,^(.+)$,\"-isystem\" \"\\1\">,\n>\n" + ) + set( + CONFIG_CASTXML_INC_CONTENTS + "${CONFIG_CASTXML_INC_CONTENTS}$,REPLACE,^(.+)$,\"-D\\1\">,\n>\n" + ) + endif() + endforeach() + unset(_module_depends) set( CONFIG_CASTXML_INC_CONTENTS "${CONFIG_CASTXML_INC_CONTENTS}-Qunused-arguments\n" @@ -160,15 +177,16 @@ function(generate_castxml_commandline_flags) endif() endforeach() - #Write compile definitions and include paths to file. @CONFIG_CASTXML_INC_CONTENTS@ expanded in configure_file + #Write compile definitions and include paths to file. Generator expressions evaluated at generation time. set( castxml_inc_file - "${WRAPPER_LIBRARY_OUTPUT_DIR}/castxml_inputs/${WRAPPER_LIBRARY_NAME}.castxml.inc" + "${WRAPPER_LIBRARY_OUTPUT_DIR}/castxml_inputs/${_each_submodule_this_module}.castxml.inc" ) - configure_file( - "${ITK_WRAP_CASTXML_SOURCE_DIR}/cast_xml.inc.in" + file( + GENERATE + OUTPUT "${castxml_inc_file}" - @ONLY + CONTENT "${CONFIG_CASTXML_INC_CONTENTS}" ) unset(CONFIG_CASTXML_INC_CONTENTS) diff --git a/Wrapping/macro_files/itk_end_wrap_module.cmake b/Wrapping/macro_files/itk_end_wrap_module.cmake index 83a24fc3a7b..bb7288d3760 100644 --- a/Wrapping/macro_files/itk_end_wrap_module.cmake +++ b/Wrapping/macro_files/itk_end_wrap_module.cmake @@ -392,19 +392,7 @@ PyModule_AddObject(m, \"_C_API\", cAPIObject); ${DO_NOT_WAIT_FOR_THREADS_CALLS} " ) - elseif( - "ITKCommon" - IN_LIST - WRAPPER_LIBRARY_LINK_LIBRARIES - OR - "${ITK_LIBRARY_NAMESPACE}::ITKCommon" - IN_LIST - WRAPPER_LIBRARY_LINK_LIBRARIES - OR - "${ITK_LIBRARY_NAMESPACE}::ITKCommonModule" - IN_LIST - WRAPPER_LIBRARY_LINK_LIBRARIES - ) + elseif(NOT WRAPPER_LIBRARY_NAME STREQUAL "ITKPyBase") set( ITK_WRAP_PYTHON_GLOBAL_TIMESTAMP_DECLS " From fe30c3b69e26ad0acc21d99497ff4446a9bc40c7 Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Fri, 27 Feb 2026 20:51:13 +0000 Subject: [PATCH 2/3] ENH: Disable cast_xml usage of directory level properties Compile definitions and include directories are no longer obtained from the directory. This is replaced by usage of target level properties. Retain support for WRAPPER_LIBRARY_INCLUDE_DIRECTORIES and WRAPPER_LIBRARY_LINK_LIBRARIES to control behavior. --- .../itk_auto_load_submodules.cmake | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/Wrapping/macro_files/itk_auto_load_submodules.cmake b/Wrapping/macro_files/itk_auto_load_submodules.cmake index 42eb4b5a968..7eaad7d35a8 100644 --- a/Wrapping/macro_files/itk_auto_load_submodules.cmake +++ b/Wrapping/macro_files/itk_auto_load_submodules.cmake @@ -102,8 +102,7 @@ function(generate_castxml_commandline_flags) ## ============================ # create the files used to pass the file to include to castxml - get_directory_property(include_dir_list INCLUDE_DIRECTORIES) - list(APPEND include_dir_list ${ITK_INCLUDE_DIRS}) + set(include_dir_list ${WRAPPER_LIBRARY_INCLUDE_DIRECTORIES}) list(REMOVE_DUPLICATES include_dir_list) # CONFIG_CASTXML_INC_CONTENTS - variable used for building contents to write with file(GENERATE) @@ -132,7 +131,6 @@ function(generate_castxml_commandline_flags) ) endif() endforeach() - unset(_module_depends) set( CONFIG_CASTXML_INC_CONTENTS "${CONFIG_CASTXML_INC_CONTENTS}-Qunused-arguments\n" @@ -146,29 +144,6 @@ function(generate_castxml_commandline_flags) "${CONFIG_CASTXML_INC_CONTENTS}-DITK_MANUAL_INSTANTIATION\n" ) - # Get the compile_definitions of the module added with add_compile_definitions - # From the wrapping folder (current) - get_directory_property(compile_definition_list COMPILE_DEFINITIONS) - # And from the top module folder - set(module_folder "${WRAPPER_LIBRARY_SOURCE_DIR}/..") - get_directory_property( - compile_definition_list_at_module - DIRECTORY "${module_folder}" - COMPILE_DEFINITIONS - ) - unset(module_folder) - # Merge and remove duplicates - list(APPEND compile_definition_list ${compile_definition_list_at_module}) - unset(compile_definition_list_at_module) - list(REMOVE_DUPLICATES compile_definition_list) - - foreach(def ${compile_definition_list}) - set( - CONFIG_CASTXML_INC_CONTENTS - "${CONFIG_CASTXML_INC_CONTENTS}\"-D${def}\"\n" - ) - endforeach() - unset(compile_definition_list) foreach(include_file ${WRAPPER_INCLUDE_FILES}) if("${include_file}" MATCHES "<.*>") string(APPEND CASTXML_INCLUDES "#include ${include_file}\n") From d63f5df00279728fedc809145f3dfc500f9eb834 Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Tue, 3 Mar 2026 16:32:37 -0500 Subject: [PATCH 3/3] BUG: Include python paths some wrapped modules For modules that use Python.h, explicitly include Python's path for cast xml. --- Modules/Bridge/NumPy/wrapping/CMakeLists.txt | 1 + Modules/Core/Common/wrapping/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/Bridge/NumPy/wrapping/CMakeLists.txt b/Modules/Bridge/NumPy/wrapping/CMakeLists.txt index b9fedf2fc6c..ea10db3cab1 100644 --- a/Modules/Bridge/NumPy/wrapping/CMakeLists.txt +++ b/Modules/Bridge/NumPy/wrapping/CMakeLists.txt @@ -1,5 +1,6 @@ if(ITK_WRAP_PYTHON) itk_wrap_module(ITKBridgeNumPy) + list(APPEND WRAPPER_LIBRARY_INCLUDE_DIRECTORIES ${Python3_INCLUDE_DIRS}) set( WRAPPER_SUBMODULE_ORDER itkPyBuffer diff --git a/Modules/Core/Common/wrapping/CMakeLists.txt b/Modules/Core/Common/wrapping/CMakeLists.txt index 59a95e1e5ae..b72c818c322 100644 --- a/Modules/Core/Common/wrapping/CMakeLists.txt +++ b/Modules/Core/Common/wrapping/CMakeLists.txt @@ -1,5 +1,5 @@ itk_wrap_module(ITKCommon) - +list(APPEND WRAPPER_LIBRARY_INCLUDE_DIRECTORIES ${Python3_INCLUDE_DIRS}) set( WRAPPER_SUBMODULE_ORDER itkFixedArray