Skip to content

Commit

Permalink
ENH: use the new CMake mechanism to specify MSVC's static or DLL CRT
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Dec 2, 2021
1 parent 6853d63 commit 4bf1ef0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CMake/ITKConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@")

Expand Down
10 changes: 10 additions & 0 deletions CMake/UseITK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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$<$<CONFIG:Debug>:Debug>")
else()
message(STATUS "ITK is setting ${PROJECT_NAME}'s MSVC_RUNTIME_LIBRARY to dynamic")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
endif()

# Add include directories needed to use ITK.
include_directories(BEFORE ${ITK_INCLUDE_DIRS})

Expand Down
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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$<$<CONFIG:Debug>:Debug>")
message(STATUS "Using MSVC's static CRT (/MT and /MTd)")
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
message(STATUS "Using MSVC's dynamic CRT (/MD and /MDd)")
endif()

include(ITKDownloadSetup)
include(PreventInSourceBuilds)
include(PreventInBuildInstalls)
Expand Down

0 comments on commit 4bf1ef0

Please sign in to comment.