When configuring DCMTK project CHECK_TYPE_SIZE
function started to fail when switched to CMake-3.25.0, on Windows, using VS 2022, x64. It works well when using CMake-3.24.3.
Multiple other people have reported the same issue with CMake-3.25.0 on other projects - see for example OpenCV: Cmake Compile Error for Opencv 4.5.5 · Issue #22784 · opencv/opencv · GitHub
How to reproduce:
- Get DCMTK from
github.com/DCMTK/dcmtk
- Configure using VS2022
Problematic CMake command:
include (CheckTypeSize)
CHECK_TYPE_SIZE("char" SIZEOF_CHAR)
For convenience, I’ve also uploaded the source code, build tree, and trace log as a zip file.
Result:
The exact same source code is configured exactly the same way.
Result when using CMake-3.24.3:
Check size of char
Check size of char - done
Trace obtained with 3.24.3
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(139): foreach(h ${CMAKE_EXTRA_INCLUDE_FILES} )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(144): set(bin ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.bin )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(145): configure_file(${__check_type_size_dir}/CheckTypeSize.c.in ${src} @ONLY )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(146): try_compile(HAVE_${var} ${CMAKE_BINARY_DIR} ${src} COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS} LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS} -DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES} OUTPUT_VARIABLE output COPY_FILE ${bin} )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(157): if(HAVE_${var} )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(159): file(STRINGS ${bin} strings LIMIT_COUNT 10 REGEX INFO:size )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(162): set(regex_size .*INFO:size\\[0*([^]]*)\\].* )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(163): set(regex_key key\\[([^]]*)\\] )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(164): set(keys )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(165): set(code )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(166): set(mismatch )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(167): set(first 1 )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(168): foreach(info ${strings} )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(169): if(${info} MATCHES ${regex_size} )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(171): set(size ${CMAKE_MATCH_1} )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(172): if(first )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(173): set(${var} ${size} )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(177): set(first 0 )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(180): string(REGEX MATCH ${regex_key} key ${info} )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(181): string(REGEX REPLACE ${regex_key} \\1 key ${key} )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(182): if(key )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(190): if(mismatch AND keys )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(193): else()
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(194): file(REMOVE ${map} )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(197): if(mismatch AND NOT keys )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(201): if(NOT CMAKE_REQUIRED_QUIET )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(202): message(CHECK_PASS done )
-- Check size of char - done
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(204): file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log Determining size of ${type} passed with the following output:\n${output}\n\n )
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake(206): set(${var} ${${var}} CACHE INTERNAL CHECK_TYPE_SIZE: sizeof(${type}) )
CMake Warning (dev) at C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake:206 (set):
Policy CMP0126 is not set: set(CACHE) does not remove a normal variable of
the same name. Run "cmake --help-policy CMP0126" for policy details. Use
the cmake_policy command to set the policy and suppress this warning.
For compatibility with older versions of CMake, normal variable
"SIZEOF_CHAR" will be removed from the current scope.
Call Stack (most recent call first):
C:/Program Files/CMake-3.24.3/share/cmake-3.24/Modules/CheckTypeSize.cmake:277 (__check_type_size_impl)
Result when using CMake-3.25.0:
Check size of char
CMake Error at C:/Program Files/CMake-3.25.0/share/cmake-3.25/Modules/CheckTypeSize.cmake:147 (try_compile):
Cannot copy output executable
''
to destination specified by COPY_FILE:
'C:/D/DCMTK-build325/CMakeFiles/CheckTypeSize/SIZEOF_CHAR.bin'
Recorded try_compile output location doesn't exist:
C:/D/DCMTK-build325/CMakeFiles/CMakeScratch/TryCompile-wd3ff3/Debug/cmTC_45f0b.exe
Call Stack (most recent call first):
C:/Program Files/CMake-3.25.0/share/cmake-3.25/Modules/CheckTypeSize.cmake:277 (__check_type_size_impl)
CMake/GenerateDCMTKConfigure.cmake:175 (CHECK_TYPE_SIZE)
CMake/dcmtkPrepare.cmake:481 (include)
CMakeLists.txt:44 (include)
Trace obtained with 3.25.0
C:/Program Files/CMake-3.25.0/share/cmake-3.25/Modules/CheckTypeSize.cmake(139): foreach(h ${CMAKE_EXTRA_INCLUDE_FILES} )
C:/Program Files/CMake-3.25.0/share/cmake-3.25/Modules/CheckTypeSize.cmake(144): set(bin ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.bin )
C:/Program Files/CMake-3.25.0/share/cmake-3.25/Modules/CheckTypeSize.cmake(145): file(READ ${__check_type_size_dir}/CheckTypeSize.c.in src_content )
C:/Program Files/CMake-3.25.0/share/cmake-3.25/Modules/CheckTypeSize.cmake(146): string(CONFIGURE ${src_content} src_content @ONLY )
C:/Program Files/CMake-3.25.0/share/cmake-3.25/Modules/CheckTypeSize.cmake(147): try_compile(HAVE_${var} SOURCE_FROM_VAR ${src} src_content COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS} LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS} -DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES} OUTPUT_VARIABLE output COPY_FILE ${bin} )
CMake Error at C:/Program Files/CMake-3.25.0/share/cmake-3.25/Modules/CheckTypeSize.cmake:147 (try_compile):
Cannot copy output executable
''
to destination specified by COPY_FILE:
'C:/D/DCMTK-build325/CMakeFiles/CheckTypeSize/SIZEOF_CHAR.bin'
Recorded try_compile output location doesn't exist:
C:/D/DCMTK-build325/CMakeFiles/CMakeScratch/TryCompile-fn88sh/Debug/cmTC_b1ee1.exe
Call Stack (most recent call first):
C:/Program Files/CMake-3.25.0/share/cmake-3.25/Modules/CheckTypeSize.cmake:277 (__check_type_size_impl)
There are 2-3 recent commits that probably caused the issue: https://gitlab.kitware.com/cmake/cmake/-/commits/master/Modules/CheckTypeSize.cmake