Skip to content

Commit f08a836

Browse files
committed
COMP: Build in-scope DCMTK alongside MINC on MSVC
Building DCMTK in ITK's shared CMake scope (FetchContent + add_subdirectory) runs DCMTK's CHECK_*_EXISTS probes in that scope, with two effects on sibling third-party modules: - Leftover CMAKE_REQUIRED_* state from DCMTK's probes. Snapshot and restore it around FetchContent_MakeAvailable(dcmtk). - DCMTK caches HAVE_TMPNAM=0 on MSVC (its tmpnam probe, like MINC's, uses CHECK_FUNCTION_EXISTS, which cannot detect MSVC CRT functions). MINC then inherits the cached 0 and its config.h selects none of mkstemp/tempnam/ tmpnam, tripping the "System defines neither ..." #error. tmpnam() does exist in the MSVC CRT, so assert HAVE_TMPNAM directly for MSVC (matching MINC's own config.h.msvc-win32); the local set() also overrides any value left in the shared cache.
1 parent 33f964d commit f08a836

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

Modules/ThirdParty/DCMTK/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,30 @@ 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+
272294
# Expose DCMTK's now-in-scope targets to the rest of ITK.
273295
set(ITKDCMTK_LIBRARIES ${_ITKDCMTK_LIB_NAMES})
274296
foreach(lib ${_ITKDCMTK_LIB_NAMES})

Modules/ThirdParty/MINC/src/libminc/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
142142
CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
143143
CHECK_FUNCTION_EXISTS(system HAVE_SYSTEM)
144144

145+
# tmpnam() is in the MSVC CRT but CHECK_FUNCTION_EXISTS cannot detect it (its
146+
# self-declared prototype fails to link); assert it directly so config.h picks
147+
# the tmpnam path rather than tripping the no-temp-file #error. A local set()
148+
# also overrides any HAVE_TMPNAM left in the shared cache by a sibling build.
149+
if(MSVC)
150+
set(HAVE_TMPNAM 1)
151+
endif()
152+
145153
if(NOT MSVC)
146154
set(CMAKE_REQUIRED_LIBRARIES m)
147155
endif()

0 commit comments

Comments
 (0)