Skip to content

Commit 87d671c

Browse files
authored
Merge pull request #100 from thewtex/pass-itk-options
Superbuild: Pass additional ITK CMake configuration options
2 parents f6afc12 + 2e91988 commit 87d671c

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

CMakeLists.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ if(ITKPythonPackage_SUPERBUILD)
153153
message(STATUS "SuperBuild - Searching for python[OK]")
154154
message(STATUS "SuperBuild - DOXYGEN_EXECUTABLE: ${DOXYGEN_EXECUTABLE}")
155155

156+
# CMake configuration variables to pass to ITK's build
157+
set(ep_itk_cmake_cache_args "")
158+
foreach(var
159+
BUILD_SHARED_LIBS
160+
ITK_BUILD_DEFAULT_MODULES
161+
)
162+
if(DEFINED ${var})
163+
list(APPEND ep_itk_cmake_cache_args "-D${var}=${${var}}")
164+
endif()
165+
endforeach()
166+
function(cached_variables RESULTVAR PATTERN)
167+
get_cmake_property(variables CACHE_VARIABLES)
168+
set(result)
169+
foreach(variable ${variables})
170+
if(${variable} AND variable MATCHES "${PATTERN}")
171+
list(APPEND result "-D${variable}=${${variable}}")
172+
endif()
173+
endforeach()
174+
set(${RESULTVAR} ${result} PARENT_SCOPE)
175+
endfunction()
176+
cached_variables(itk_pattern_cached_vars "^(ITK_WRAP_)|(ITKGroup_)|(Module_)")
177+
list(APPEND ep_itk_cmake_cache_args ${itk_pattern_cached_vars})
178+
# Todo, also pass all Module_* variables
179+
message(STATUS "ITK CMake Cache Args - ${ep_itk_cmake_cache_args}")
156180
#-----------------------------------------------------------------------------
157181
# ITK: This project builds ITK and associated Python modules
158182

@@ -182,7 +206,7 @@ if(ITKPythonPackage_SUPERBUILD)
182206
SOURCE_DIR ${ITK_SOURCE_DIR}
183207
BINARY_DIR ${ITK_BINARY_DIR}
184208
PREFIX "ITKp"
185-
CMAKE_CACHE_ARGS
209+
CMAKE_ARGS
186210
-DBUILD_TESTING:BOOL=OFF
187211
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
188212
-DPY_SITE_PACKAGES_PATH:PATH=${CMAKE_INSTALL_PREFIX}
@@ -198,6 +222,7 @@ if(ITKPythonPackage_SUPERBUILD)
198222
-DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
199223
-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE}
200224
${ep_common_cmake_cache_args}
225+
${ep_itk_cmake_cache_args}
201226
USES_TERMINAL_DOWNLOAD 1
202227
USES_TERMINAL_UPDATE 1
203228
USES_TERMINAL_CONFIGURE 1

scripts/windows_build_wheels.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def build_wrapped_itk(
106106

107107

108108
def build_wheel(python_version, single_wheel=False,
109-
cleanup=False, wheel_names=None):
109+
cleanup=False, wheel_names=None,
110+
cmake_options=[]):
110111

111112
python_executable, \
112113
python_include_dir, \
@@ -152,7 +153,7 @@ def build_wheel(python_version, single_wheel=False,
152153
"-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir,
153154
"-DPYTHON_LIBRARY:FILEPATH=%s" % python_library,
154155
"-DDOXYGEN_EXECUTABLE:FILEPATH=C:/P/doxygen/doxygen.exe",
155-
])
156+
] + cmake_options)
156157
# Cleanup
157158
check_call([python_executable, "setup.py", "clean"])
158159

@@ -192,7 +193,7 @@ def build_wheel(python_version, single_wheel=False,
192193
"-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable,
193194
"-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir,
194195
"-DPYTHON_LIBRARY:FILEPATH=%s" % python_library
195-
])
196+
] + cmake_options)
196197

197198
# Cleanup
198199
if cleanup:
@@ -226,7 +227,7 @@ def test_wheels(single_wheel=False):
226227

227228

228229
def build_wheels(py_envs=DEFAULT_PY_ENVS, single_wheel=False,
229-
cleanup=False, wheel_names=None):
230+
cleanup=False, wheel_names=None, cmake_options=[]):
230231

231232
for py_env in py_envs:
232233
prepare_build_env(py_env)
@@ -252,7 +253,8 @@ def build_wheels(py_envs=DEFAULT_PY_ENVS, single_wheel=False,
252253
# Compile wheels re-using standalone project and archive cache
253254
for py_env in py_envs:
254255
build_wheel(py_env, single_wheel=single_wheel,
255-
cleanup=cleanup, wheel_names=wheel_names)
256+
cleanup=cleanup, wheel_names=wheel_names,
257+
cmake_options=cmake_options)
256258

257259

258260
def main(wheel_names=None):
@@ -261,10 +263,12 @@ def main(wheel_names=None):
261263
parser.add_argument('--py-envs', nargs='+', default=DEFAULT_PY_ENVS,
262264
help='Target Python environment versions, e.g. "37-x64".')
263265
parser.add_argument('--no-cleanup', dest='cleanup', action='store_false', help='Do not clean up temporary build files.')
266+
parser.add_argument('cmake_options', nargs='*', help='Extra options to pass to CMake, e.g. -DBUILD_SHARED_LIBS:BOOL=OFF')
264267
args = parser.parse_args()
265268

266269
build_wheels(single_wheel=args.single_wheel, cleanup=args.cleanup,
267-
py_envs=args.py_envs, wheel_names=wheel_names)
270+
py_envs=args.py_envs, wheel_names=wheel_names,
271+
cmake_options=args.cmake_options)
268272
fixup_wheels()
269273
test_wheels(single_wheel=args.single_wheel)
270274

0 commit comments

Comments
 (0)