After some digging I found that the problem occurs in dcmtk\config\tests\cxx11.cc. The code checks for the macro __cplusplus:
Code: Select all
#elif __cplusplus < 201103L
#error "This is not a C++11 compiler"
Unfortunately, MSVC doesn't set this macro correctly. From
https://learn.microsoft.com/en-us/cpp/b ... w=msvc-170:
... Because a lot of existing code appears to depend on the value of this macro matching 199711L, the compiler doesn't change the value of the macro unless you explicitly opt in by using the /Zc:__cplusplus compiler option.
I changed line 1453 in the function DCMTK_CHECK_CXX_STANDARD in dcmtk\CMake\GenerateDCMTKConfigure.cmake to
Code: Select all
try_compile(COMPILE_RESULT "${CMAKE_BINARY_DIR}" "${DCMTK_SOURCE_DIR}/config/tests/cxx${STANDARD}.cc" COMPILE_DEFINITIONS "/Zc:__cplusplus")
CMake now enables the C++ features:
Code: Select all
Info: C++11 features enabled
Info: C++14 features enabled
Info: C++17 features enabled
I also added the following to dcmtk\CMakeLists.txt
Code: Select all
set(CMAKE_CXX_STANDARD 17)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
endif()
However, the resulting VS solution is configured to use the C++14 standard, and I had to add /Zc:__cplusplus to the compiler flags for each project.
Is there a way to tell CMake to generate the solution with this compiler flag?