Skip to content

Commit

Permalink
New option for building with static CRT in Windows (HDFGroup#4062)
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnHDF authored and lrknox committed Mar 21, 2024
1 parent 6e95abb commit 58ef5fd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 43 deletions.
8 changes: 0 additions & 8 deletions config/cmake/HDFUseFortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
#-----------------------------------------------------------------------------
Expand Down
34 changes: 5 additions & 29 deletions config/cmake/UserMacros/Windows_MT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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$<$<CONFIG:Debug>:Debug>")
endif ()
9 changes: 3 additions & 6 deletions release_docs/INSTALL_CMake.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.


========================================================================
Expand Down
9 changes: 9 additions & 0 deletions release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 58ef5fd

Please sign in to comment.