Skip to content

Commit a322c2d

Browse files
authored
Merge pull request InsightSoftwareConsortium#5842 from blowekamp/fix_wrap_external
Refactor wrapping to use target properties and address bug building remote modules against an ITK build directory
2 parents 45dfb4a + d63f5df commit a322c2d

5 files changed

Lines changed: 27 additions & 46 deletions

File tree

Modules/Bridge/NumPy/wrapping/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
if(ITK_WRAP_PYTHON)
22
itk_wrap_module(ITKBridgeNumPy)
3+
list(APPEND WRAPPER_LIBRARY_INCLUDE_DIRECTORIES ${Python3_INCLUDE_DIRS})
34
set(
45
WRAPPER_SUBMODULE_ORDER
56
itkPyBuffer

Modules/Core/Common/wrapping/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
itk_wrap_module(ITKCommon)
2-
2+
list(APPEND WRAPPER_LIBRARY_INCLUDE_DIRECTORIES ${Python3_INCLUDE_DIRS})
33
set(
44
WRAPPER_SUBMODULE_ORDER
55
itkFixedArray

Wrapping/TypedefMacros.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ macro(itk_wrap_module library_name)
148148
# be linked to the wrapper library.
149149
set(
150150
WRAPPER_LIBRARY_LINK_LIBRARIES
151-
${ITK_LIBRARIES}
152151
${ITK_LIBRARY_NAMESPACE}::${library_name}Module
153152
)
154153

Wrapping/macro_files/itk_auto_load_submodules.cmake

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,10 @@ function(generate_castxml_commandline_flags)
102102
## ============================
103103

104104
# create the files used to pass the file to include to castxml
105-
get_directory_property(include_dir_list INCLUDE_DIRECTORIES)
106-
list(APPEND include_dir_list ${ITK_INCLUDE_DIRS})
105+
set(include_dir_list ${WRAPPER_LIBRARY_INCLUDE_DIRECTORIES})
107106
list(REMOVE_DUPLICATES include_dir_list)
108107

109-
# CONFIG_CASTXML_INC_CONTENTS - variable used for building contents to write with configure_file()
108+
# CONFIG_CASTXML_INC_CONTENTS - variable used for building contents to write with file(GENERATE)
110109
unset(CONFIG_CASTXML_INC_CONTENTS)
111110
foreach(dir ${include_dir_list})
112111
set(
@@ -116,6 +115,22 @@ function(generate_castxml_commandline_flags)
116115
endforeach()
117116
unset(include_dir_list)
118117

118+
foreach(_depend IN LISTS WRAPPER_LIBRARY_LINK_LIBRARIES)
119+
if(TARGET ${_depend})
120+
set(
121+
CONFIG_CASTXML_INC_CONTENTS
122+
"${CONFIG_CASTXML_INC_CONTENTS}$<LIST:JOIN,$<LIST:TRANSFORM,$<TARGET_PROPERTY:${_depend},INTERFACE_INCLUDE_DIRECTORIES>,REPLACE,^(.+)$,\"-I\\1\">,\n>\n"
123+
)
124+
set(
125+
CONFIG_CASTXML_INC_CONTENTS
126+
"${CONFIG_CASTXML_INC_CONTENTS}$<LIST:JOIN,$<LIST:TRANSFORM,$<TARGET_PROPERTY:${_depend},INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>,REPLACE,^(.+)$,\"-isystem\" \"\\1\">,\n>\n"
127+
)
128+
set(
129+
CONFIG_CASTXML_INC_CONTENTS
130+
"${CONFIG_CASTXML_INC_CONTENTS}$<LIST:JOIN,$<LIST:TRANSFORM,$<TARGET_PROPERTY:${_depend},INTERFACE_COMPILE_DEFINITIONS>,REPLACE,^(.+)$,\"-D\\1\">,\n>\n"
131+
)
132+
endif()
133+
endforeach()
119134
set(
120135
CONFIG_CASTXML_INC_CONTENTS
121136
"${CONFIG_CASTXML_INC_CONTENTS}-Qunused-arguments\n"
@@ -129,29 +144,6 @@ function(generate_castxml_commandline_flags)
129144
"${CONFIG_CASTXML_INC_CONTENTS}-DITK_MANUAL_INSTANTIATION\n"
130145
)
131146

132-
# Get the compile_definitions of the module added with add_compile_definitions
133-
# From the wrapping folder (current)
134-
get_directory_property(compile_definition_list COMPILE_DEFINITIONS)
135-
# And from the top module folder
136-
set(module_folder "${WRAPPER_LIBRARY_SOURCE_DIR}/..")
137-
get_directory_property(
138-
compile_definition_list_at_module
139-
DIRECTORY "${module_folder}"
140-
COMPILE_DEFINITIONS
141-
)
142-
unset(module_folder)
143-
# Merge and remove duplicates
144-
list(APPEND compile_definition_list ${compile_definition_list_at_module})
145-
unset(compile_definition_list_at_module)
146-
list(REMOVE_DUPLICATES compile_definition_list)
147-
148-
foreach(def ${compile_definition_list})
149-
set(
150-
CONFIG_CASTXML_INC_CONTENTS
151-
"${CONFIG_CASTXML_INC_CONTENTS}\"-D${def}\"\n"
152-
)
153-
endforeach()
154-
unset(compile_definition_list)
155147
foreach(include_file ${WRAPPER_INCLUDE_FILES})
156148
if("${include_file}" MATCHES "<.*>")
157149
string(APPEND CASTXML_INCLUDES "#include ${include_file}\n")
@@ -160,15 +152,16 @@ function(generate_castxml_commandline_flags)
160152
endif()
161153
endforeach()
162154

163-
#Write compile definitions and include paths to file. @CONFIG_CASTXML_INC_CONTENTS@ expanded in configure_file
155+
#Write compile definitions and include paths to file. Generator expressions evaluated at generation time.
164156
set(
165157
castxml_inc_file
166-
"${WRAPPER_LIBRARY_OUTPUT_DIR}/castxml_inputs/${WRAPPER_LIBRARY_NAME}.castxml.inc"
158+
"${WRAPPER_LIBRARY_OUTPUT_DIR}/castxml_inputs/${_each_submodule_this_module}.castxml.inc"
167159
)
168-
configure_file(
169-
"${ITK_WRAP_CASTXML_SOURCE_DIR}/cast_xml.inc.in"
160+
file(
161+
GENERATE
162+
OUTPUT
170163
"${castxml_inc_file}"
171-
@ONLY
164+
CONTENT "${CONFIG_CASTXML_INC_CONTENTS}"
172165
)
173166
unset(CONFIG_CASTXML_INC_CONTENTS)
174167

Wrapping/macro_files/itk_end_wrap_module.cmake

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,7 @@ PyModule_AddObject(m, \"_C_API\", cAPIObject);
392392
${DO_NOT_WAIT_FOR_THREADS_CALLS}
393393
"
394394
)
395-
elseif(
396-
"ITKCommon"
397-
IN_LIST
398-
WRAPPER_LIBRARY_LINK_LIBRARIES
399-
OR
400-
"${ITK_LIBRARY_NAMESPACE}::ITKCommon"
401-
IN_LIST
402-
WRAPPER_LIBRARY_LINK_LIBRARIES
403-
OR
404-
"${ITK_LIBRARY_NAMESPACE}::ITKCommonModule"
405-
IN_LIST
406-
WRAPPER_LIBRARY_LINK_LIBRARIES
407-
)
395+
elseif(NOT WRAPPER_LIBRARY_NAME STREQUAL "ITKPyBase")
408396
set(
409397
ITK_WRAP_PYTHON_GLOBAL_TIMESTAMP_DECLS
410398
"

0 commit comments

Comments
 (0)