Skip to content

Commit db0fcf2

Browse files
committed
COMP: Build in-scope DCMTK alongside MINC and GDCM on MSVC
Building DCMTK in ITK's shared CMake scope (FetchContent + add_subdirectory) runs DCMTK's configure in that scope, with two side effects on sibling third-party modules: - Leftover CMAKE_REQUIRED_* state from DCMTK's probes. Snapshot and restore it around FetchContent_MakeAvailable(dcmtk). - DCMTK's GenerateDCMTKConfigure.cmake globally redefines standard CMake check commands (CHECK_FUNCTION_EXISTS on Windows, CHECK_CXX_SYMBOL_EXISTS). CMake commands are global, so those overrides leak into ITK modules configured afterward: their CHECK_FUNCTION_EXISTS calls run DCMTK's header-less check_symbol_exists, report the function missing, and the module trips a #error -- MINC on tmpnam, GDCM on _strnicmp, depending on configure order. Restore the real implementations after DCMTK by including a copy of each module under a fresh path (include_guard(GLOBAL) blocks a plain re-include), fixing every dependent module regardless of order. The ExternalProject build never hit either because DCMTK configures in a separate CMake process.
1 parent 5003c3e commit db0fcf2

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Modules/ThirdParty/DCMTK/CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,48 @@ else(ITK_USE_SYSTEM_DCMTK)
267267
GIT_REPOSITORY ${DCMTK_GIT_REPOSITORY}
268268
GIT_TAG ${DCMTK_GIT_TAG}
269269
)
270+
271+
# DCMTK's configure runs many CHECK_*_EXISTS probes that mutate the shared
272+
# CMAKE_REQUIRED_* state; in ITK's in-scope build that would leak into
273+
# sibling third-party feature probes, so snapshot and restore it.
274+
set(
275+
_dcmtk_required_vars
276+
CMAKE_REQUIRED_FLAGS
277+
CMAKE_REQUIRED_DEFINITIONS
278+
CMAKE_REQUIRED_INCLUDES
279+
CMAKE_REQUIRED_LIBRARIES
280+
CMAKE_REQUIRED_QUIET
281+
)
282+
foreach(_v ${_dcmtk_required_vars})
283+
set(_dcmtk_saved_${_v} "${${_v}}")
284+
endforeach()
285+
270286
FetchContent_MakeAvailable(dcmtk)
271287

288+
foreach(_v ${_dcmtk_required_vars})
289+
set(${_v} "${_dcmtk_saved_${_v}}")
290+
unset(_dcmtk_saved_${_v})
291+
endforeach()
292+
unset(_dcmtk_required_vars)
293+
294+
# DCMTK's GenerateDCMTKConfigure.cmake globally redefines standard CMake check
295+
# commands (CHECK_FUNCTION_EXISTS on Windows, CHECK_CXX_SYMBOL_EXISTS). CMake
296+
# commands are global, so those overrides leak into ITK modules configured
297+
# afterward: MINC's and GDCM's CHECK_FUNCTION_EXISTS(tmpnam/_strnicmp ...) then
298+
# run DCMTK's header-less check_symbol_exists, report the function missing, and
299+
# those modules trip a #error. Whether a given module is affected depends on
300+
# configure order, so restore the real implementations here, unconditionally,
301+
# by including a copy of each module under a fresh path (include_guard(GLOBAL)
302+
# blocks a plain re-include).
303+
foreach(_check_mod CheckFunctionExists CheckCXXSymbolExists)
304+
configure_file(
305+
"${CMAKE_ROOT}/Modules/${_check_mod}.cmake"
306+
"${CMAKE_CURRENT_BINARY_DIR}/RestoreChecks/${_check_mod}.cmake"
307+
COPYONLY
308+
)
309+
include("${CMAKE_CURRENT_BINARY_DIR}/RestoreChecks/${_check_mod}.cmake")
310+
endforeach()
311+
272312
# Expose DCMTK's now-in-scope targets to the rest of ITK.
273313
set(ITKDCMTK_LIBRARIES ${_ITKDCMTK_LIB_NAMES})
274314
foreach(lib ${_ITKDCMTK_LIB_NAMES})

0 commit comments

Comments
 (0)