From c872acae63feb8b391f6919b94c2d2d06deb1a19 Mon Sep 17 00:00:00 2001 From: Allen Byrne <50328838+byrnHDF@users.noreply.github.com> Date: Thu, 7 Mar 2024 11:27:56 -0600 Subject: New option for building with static CRT in Windows (#4062) --- config/cmake/HDFUseFortran.cmake | 8 -------- config/cmake/UserMacros/Windows_MT.cmake | 34 +++++--------------------------- release_docs/INSTALL_CMake.txt | 9 +++------ release_docs/RELEASE.txt | 9 +++++++++ 4 files changed, 17 insertions(+), 43 deletions(-) diff --git a/config/cmake/HDFUseFortran.cmake b/config/cmake/HDFUseFortran.cmake index 392ea30..2d53a50 100644 --- a/config/cmake/HDFUseFortran.cmake +++ b/config/cmake/HDFUseFortran.cmake @@ -19,14 +19,6 @@ set (HDF_PREFIX "H5") include (CheckFortranSourceRuns) include (CheckFortranSourceCompiles) -#------------------------------------------------------------------------------- -# Fix Fortran flags if we are compiling statically on Windows using -# Windows_MT.cmake from config/cmake/UserMacros -#------------------------------------------------------------------------------- -if (BUILD_STATIC_CRT_LIBS) - TARGET_STATIC_CRT_FLAGS () -endif () - #----------------------------------------------------------------------------- # Detect name mangling convention used between Fortran and C #----------------------------------------------------------------------------- diff --git a/config/cmake/UserMacros/Windows_MT.cmake b/config/cmake/UserMacros/Windows_MT.cmake index c8edbe4..351c991 100644 --- a/config/cmake/UserMacros/Windows_MT.cmake +++ b/config/cmake/UserMacros/Windows_MT.cmake @@ -20,34 +20,10 @@ # INCLUDE(path_to_file/WINDOWS_MT.cmake) #----------------------------------------------------------------------------- -# Option to Build with Static CRT libraries on Windows -#------------------------------------------------------------------------------- -macro (TARGET_STATIC_CRT_FLAGS) - if (MSVC AND NOT BUILD_SHARED_LIBS) - foreach (flag_var - CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) - if (${flag_var} MATCHES "/MD") - string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - endif () - endforeach () - foreach (flag_var - CMAKE_Fortran_FLAGS CMAKE_Fortran_FLAGS_DEBUG CMAKE_Fortran_FLAGS_RELEASE - CMAKE_Fortran_FLAGS_MINSIZEREL CMAKE_Fortran_FLAGS_RELWITHDEBINFO) - if (${flag_var} MATCHES "/libs:dll") - string (REGEX REPLACE "/libs:dll" "/libs:static" ${flag_var} "${${flag_var}}") - endif () - endforeach () - set (WIN_COMPILE_FLAGS "") - set (WIN_LINK_FLAGS "/NODEFAULTLIB:MSVCRT") - endif () -endmacro () - +# Option to Build with Static CRT libraries on Windows (USE WITH CAUTION!!!) #----------------------------------------------------------------------------- -option (BUILD_STATIC_CRT_LIBS "Build With Static CRT Libraries" OFF) -mark_as_advanced (BUILD_STATIC_CRT_LIBS) -if (BUILD_STATIC_CRT_LIBS) - TARGET_STATIC_CRT_FLAGS () +option (HDF5_BUILD_STATIC_CRT_LIBS "Build With Static Windows CRT Libraries" OFF) +mark_as_advanced (HDF5_BUILD_STATIC_CRT_LIBS) +if (HDF5_BUILD_STATIC_CRT_LIBS) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif () diff --git a/release_docs/INSTALL_CMake.txt b/release_docs/INSTALL_CMake.txt index 392abf3..4d4af24 100644 --- a/release_docs/INSTALL_CMake.txt +++ b/release_docs/INSTALL_CMake.txt @@ -968,13 +968,10 @@ VII. User Defined Options for HDF5 Libraries with CMake ======================================================================== Support for User Defined macros and options has been added. The file -UserMacros.cmake has an example of the technique. In the folder, -config/cmake/UserMacros, is an implementation for Windows Visual Studio -users for linking libraries to the static CRT - Windows_MT.cmake. +UserMacros.cmake has an example of the technique. -Copy the contents of the file, both macro and option, into the -UserMacros.cmake file. Then enable the option to the CMake configuration, -build and test process. +Replace the template code with your macro in the UserMacros.cmake file. +Then enable the option to the CMake configuration, build and test process. ======================================================================== diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 9ef3f45..25bcbbf 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -47,6 +47,15 @@ New Features Configuration: ------------- + - New option for building with static CRT in Windows + + The following option has been added: + HDF5_BUILD_STATIC_CRT_LIBS "Build With Static Windows CRT Libraries" OFF + Because our minimum CMake is 3.18, the macro to change runtime flags no longer + works as CMake changed the default behavior in CMake 3.15. + + Fixes GitHub issue #3984 + - Added support for the new MSVC preprocessor Microsoft added support for a new, standards-conformant preprocessor -- cgit v0.12