Skip to content

Commit bccf288

Browse files
committed
ENH: Add Windows TBB support
1 parent 374c744 commit bccf288

File tree

2 files changed

+45
-27
lines changed

2 files changed

+45
-27
lines changed

CMakeLists.txt

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ message(STATUS "SuperBuild - ITKPythonPackage_WHEEL_NAME:${ITKPythonPackage_WHEE
1616

1717
option(ITKPythonPackage_USE_TBB "Build and use oneTBB in the ITK python package" ON)
1818

19+
set(libpath "lib")
20+
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
21+
set(libpath "lib64")
22+
endif()
23+
if(ITK_SOURCE_DIR)
24+
set(TBB_DIR "${ITK_SOURCE_DIR}/../oneTBB-prefix/${libpath}/cmake/TBB")
25+
else()
26+
set(TBB_DIR "${CMAKE_BINARY_DIR}/../oneTBB-prefix/${libpath}/cmake/TBB")
27+
endif()
28+
set(tbb_args )
29+
if(ITKPythonPackage_USE_TBB)
30+
set(tbb_args
31+
-DModule_ITKTBB:BOOL=ON
32+
-DTBB_DIR:PATH=${TBB_DIR}
33+
)
34+
endif()
35+
1936
if(ITKPythonPackage_SUPERBUILD)
2037

2138
#-----------------------------------------------------------------------------
@@ -29,7 +46,7 @@ if(ITKPythonPackage_SUPERBUILD)
2946
# Avoid "Manually-specified variables were not used by the project" warnings.
3047
ipp_unused_vars(${PYTHON_VERSION_STRING} ${SKBUILD})
3148

32-
set(ep_common_cmake_cache_args)
49+
set(ep_common_cmake_cache_args )
3350
if(NOT CMAKE_CONFIGURATION_TYPES)
3451
list(APPEND ep_common_cmake_cache_args
3552
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
@@ -91,34 +108,22 @@ if(ITKPythonPackage_SUPERBUILD)
91108
message(FATAL_ERROR "ITK_SOURCE_DIR variable is defined but corresponds to nonexistent directory")
92109
endif()
93110

94-
set(tbb_args )
95111
if(ITKPythonPackage_USE_TBB)
96112
ExternalProject_add(oneTBB
97-
GIT_REPOSITORY "https://github.com/oneapi-src/oneTBB.git"
98-
GIT_TAG "v2021.3.0"
113+
URL https://github.com/oneapi-src/oneTBB/archive/refs/tags/v2021.3.0.tar.gz
114+
URL_HASH SHA256=8f616561603695bbb83871875d2c6051ea28f8187dbe59299961369904d1d49e
99115
CMAKE_ARGS
100116
-DTBB_TEST:BOOL=OFF
101117
-DCMAKE_BUILD_TYPE:STRING=Release
102118
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/../oneTBB-prefix
103119
${ep_common_cmake_cache_args}
120+
-DCMAKE_BUILD_TYPE:STRING=Release
121+
BUILD_BYPRODUCTS "${TBB_DIR}/TBBConfig.cmake"
104122
USES_TERMINAL_DOWNLOAD 1
105123
USES_TERMINAL_UPDATE 1
106124
USES_TERMINAL_CONFIGURE 1
107125
USES_TERMINAL_BUILD 1
108126
)
109-
set(libpath "lib")
110-
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
111-
set(libpath "lib64")
112-
endif()
113-
if(ITK_SOURCE_DIR)
114-
set(TBB_DIR "${ITK_SOURCE_DIR}/../oneTBB-prefix/${libpath}/cmake/TBB")
115-
else()
116-
set(TBB_DIR "${CMAKE_BINARY_DIR}/../oneTBB-prefix/${libpath}/cmake/TBB")
117-
endif()
118-
set(tbb_args
119-
-DModule_ITKTBB:BOOL=ON
120-
-DTBB_DIR:PATH=${TBB_DIR}
121-
)
122127
message(STATUS "SuperBuild - TBB: Enabled")
123128
message(STATUS "SuperBuild - TBB_DIR: ${TBB_DIR}")
124129
endif()
@@ -140,7 +145,7 @@ if(ITKPythonPackage_SUPERBUILD)
140145
CONFIGURE_COMMAND ""
141146
BUILD_COMMAND ""
142147
INSTALL_COMMAND ""
143-
DEPENDS ${tbb_depends}
148+
DEPENDS "${tbb_depends}"
144149
)
145150
set(proj_status "")
146151

@@ -273,8 +278,8 @@ if(ITKPythonPackage_SUPERBUILD)
273278
-DPython3_LIBRARY:FILEPATH=${Python3_LIBRARY}
274279
-DPython3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE}
275280
${ep_common_cmake_cache_args}
276-
${ep_itk_cmake_cache_args}
277281
${tbb_args}
282+
${ep_itk_cmake_cache_args}
278283
USES_TERMINAL_DOWNLOAD 1
279284
USES_TERMINAL_UPDATE 1
280285
USES_TERMINAL_CONFIGURE 1
@@ -319,6 +324,7 @@ if(ITKPythonPackage_SUPERBUILD)
319324
-DITK_SOURCE_DIR:PATH=${ITK_SOURCE_DIR}
320325
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
321326
-DITKPythonPackage_WHEEL_NAME:STRING=${ITKPythonPackage_WHEEL_NAME}
327+
-DITKPythonPackage_USE_TBB:BOOL=${ITKPythonPackage_USE_TBB}
322328
${ep_common_cmake_cache_args}
323329
USES_TERMINAL_CONFIGURE 1
324330
INSTALL_COMMAND ""
@@ -548,7 +554,7 @@ else()
548554
unset(CMAKE_INSTALL_COMPONENT)
549555
set(COMPONENT \"${component}\")
550556
set(CMAKE_INSTALL_DO_STRIP 1)
551-
include\(\"${ITK_BINARY_DIR}/cmake_install.cmake\")
557+
include(\"${ITK_BINARY_DIR}/cmake_install.cmake\")
552558
unset(CMAKE_INSTALL_COMPONENT)
553559
")
554560
endforeach()

scripts/windows_build_wheels.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def prepare_build_env(python_version):
4747
if not os.path.exists(venv_dir):
4848
check_call([venv, venv_dir])
4949
pip_install(venv_dir, "scikit-build")
50+
pip_install(venv_dir, "delvewheel")
5051

5152

5253
def build_wrapped_itk(
@@ -76,6 +77,8 @@ def build_wrapped_itk(
7677
script_file.close()
7778
os.remove(script_file.name)
7879

80+
tbb_dir = os.path.join(ROOT_DIR, 'oneTBB-prefix', 'lib', 'cmake', 'TBB')
81+
7982
# Build ITK python
8083
with push_dir(directory=build_path, make_directory=True), \
8184
push_env(**build_env):
@@ -102,6 +105,8 @@ def build_wrapped_itk(
102105
"-DITK_WRAP_PYTHON:BOOL=ON",
103106
"-DITK_WRAP_DOC:BOOL=ON",
104107
"-DDOXYGEN_EXECUTABLE:FILEPATH=C:/P/doxygen/doxygen.exe",
108+
"-DModule_ITKTBB:BOOL=ON",
109+
"-DTBB_DIR:PATH=%s" % tbb_dir,
105110
"-G", "Ninja",
106111
source_path
107112
])
@@ -214,14 +219,21 @@ def build_wheel(python_version, single_wheel=False,
214219
shutil.rmtree(
215220
os.path.join(build_path, "Wrapping", "Generators", "CastXML"))
216221

217-
218-
def fixup_wheel(filepath):
219-
pass
222+
def fixup_wheel(py_envs, filepath):
223+
py_env = py_envs[0]
224+
delve_wheel = os.path.join(ROOT_DIR, "venv-" + py_env, "Scripts", "delvewheel.exe")
225+
check_call([delve_wheel, "repair", "--no-mangle-all", "--add-path",
226+
"C:/P/IPP/oneTBB-prefix/bin", "--ignore-in-wheel", "-w",
227+
os.path.join(ROOT_DIR, "dist"), filepath])
220228

221229

222-
def fixup_wheels():
223-
for wheel in glob.glob(os.path.join(ROOT_DIR, "dist", "*.whl")):
224-
fixup_wheel(wheel)
230+
def fixup_wheels(single_wheel, py_envs):
231+
# TBB library fix-up
232+
tbb_wheel = "itk_core"
233+
if single_wheel:
234+
tbb_wheel = "itk"
235+
for wheel in glob.glob(os.path.join(ROOT_DIR, "dist", tbb_wheel + "*.whl")):
236+
fixup_wheel(py_envs, wheel)
225237

226238

227239
def test_wheels(python_env):
@@ -293,7 +305,7 @@ def main(wheel_names=None):
293305
build_wheels(single_wheel=args.single_wheel, cleanup=args.cleanup,
294306
py_envs=args.py_envs, wheel_names=wheel_names,
295307
cmake_options=args.cmake_options)
296-
fixup_wheels()
308+
fixup_wheels(args.single_wheel, args.py_envs)
297309
for py_env in args.py_envs:
298310
test_wheels(py_env)
299311

0 commit comments

Comments
 (0)