From 1129232d506897bc2f58a13a15213c4fdfc16d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Thu, 18 Nov 2021 17:41:59 -0500 Subject: [PATCH] ENH: use the new CMake mechanism to specify MSVC's static or DLL CRT --- CMake/ITKConfig.cmake.in | 3 +++ CMake/UseITK.cmake | 10 ++++++++++ CMakeLists.txt | 14 +++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CMake/ITKConfig.cmake.in b/CMake/ITKConfig.cmake.in index f50fdd72450b..de76e4aef97b 100644 --- a/CMake/ITKConfig.cmake.in +++ b/CMake/ITKConfig.cmake.in @@ -50,6 +50,9 @@ set(ITK_BUILD_SHARED "@ITK_BUILD_SHARED_LIBS@") # Export the library build type (SHARED or STATIC) for external builds set(ITK_LIBRARY_BUILD_TYPE "@ITK_LIBRARY_BUILD_TYPE@") +# Whether ITK links to MSVC's static CRT (/MT and /MTd). +set(ITK_MSVC_STATIC_CRT "@ITK_MSVC_STATIC_RUNTIME_LIBRARY_value@") + # Whether ITK examples were built. set(ITK_BUILD_EXAMPLES "@BUILD_EXAMPLES@") diff --git a/CMake/UseITK.cmake b/CMake/UseITK.cmake index 89decdb4f312..3a6586a462da 100644 --- a/CMake/UseITK.cmake +++ b/CMake/UseITK.cmake @@ -24,6 +24,16 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ITK_REQUIRED_LINK_ set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${ITK_REQUIRED_LINK_FLAGS}") include(${ITK_CMAKE_DIR}/ITKInitializeCXXStandard.cmake) +if(MSVC) + if(ITK_MSVC_STATIC_CRT) + message(STATUS "ITK is setting ${PROJECT_NAME}'s MSVC_RUNTIME_LIBRARY to static") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + else() + message(STATUS "ITK is setting ${PROJECT_NAME}'s MSVC_RUNTIME_LIBRARY to dynamic") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + endif() +endif() + # Add include directories needed to use ITK. include_directories(BEFORE ${ITK_INCLUDE_DIRS}) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c8b85c0129f..b72d82f00ba5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ foreach(pnew "CMP0120") cmake_policy(SET ${pnew} NEW) endif() endforeach() -foreach(pold "CMP0091") +foreach(pold "") if(POLICY ${pold}) cmake_policy(SET ${pold} OLD) endif() @@ -125,6 +125,18 @@ endif() include(CTest) mark_as_advanced(CLEAR BUILD_TESTING) +option(ITK_MSVC_STATIC_RUNTIME_LIBRARY "Link to MSVC's static CRT (/MT and /MTd). +OFF (default) means link to regular, dynamic CRT (/MD and /MDd)." OFF) +mark_as_advanced(ITK_MSVC_STATIC_RUNTIME_LIBRARY) +set(ITK_MSVC_STATIC_RUNTIME_LIBRARY_value ${ITK_MSVC_STATIC_RUNTIME_LIBRARY}) +if(ITK_MSVC_STATIC_RUNTIME_LIBRARY) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + message(STATUS "Using MSVC's static CRT (/MT and /MTd)") +else() + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + message(STATUS "Using MSVC's dynamic CRT (/MD and /MDd)") +endif() + include(ITKDownloadSetup) include(PreventInSourceBuilds) include(PreventInBuildInstalls)