Skip to content

Commit

Permalink
Add CMake option to link MSVC runtime library statically
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeu committed Feb 10, 2024
1 parent b0b3140 commit e333695
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ cmake_minimum_required(VERSION 3.7)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()

project(matio
VERSION 1.5.26
Expand Down
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ Table of Contents
* 'MATIO_SHARED:BOOL=ON'
This option builds the matio library as shared object
(i.e., a dynamic link library on Windows).
* 'MATIO_STATIC_LINK_CRT:BOOL=OFF'
This option links the MSVC runtime library statically.
* 'MATIO_WITH_HDF5:BOOL=ON'
This option enables CMake to check for availability of the
HDF5 library (see section 2.1.2 for information about HDF5).
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ This flag enables the support for version 7.3 MAT files.
This option enables position-independent code (PIC), i.e., compilation with the `-fPIC` flag. It is ignored for Visual Studio builds.
* `MATIO_SHARED:BOOL=ON`
This option builds the matio library as shared object (i.e., a dynamic link library on Windows).
* `MATIO_STATIC_LINK_CRT:BOOL=OFF`
This option links the MSVC runtime library statically.
* `MATIO_WITH_HDF5:BOOL=ON`
This option enables CMake to check for availability of the HDF5 library (see section [2.1.2](#212-hdf5) for information about HDF5).
* `MATIO_WITH_ZLIB:BOOL=ON`
Expand Down
16 changes: 16 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ option(MATIO_SHARED "Build shared matio library, disable for static library" ON)
# Option to enable position-independent code (PIC)
option(MATIO_PIC "Enable position-independent code (PIC), i.e., compilation with the -fPIC flag" ON)

# Option to link the MSVC runtime library statically
option(MATIO_STATIC_LINK_CRT "Link the MSVC runtime library statically" OFF)

if(POLICY CMP0091)
# CMake >= 3.15 has CMAKE_MSVC_RUNTIME_LIBRARY to set the MSVCC runtime library
if(WIN32 AND CMAKE_GENERATOR MATCHES "Visual Studio .*|NMake .*")
if(MATIO_STATIC_LINK_CRT)
message(STATUS "Configuring to link the MSVC runtime library statically")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
message(STATUS "Configuring to link the MSVC runtime library dynamically")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
endif()
endif()

# Build with hdf5 support
option(MATIO_WITH_HDF5 "Check for HDF5 library" ON)

Expand Down
2 changes: 2 additions & 0 deletions documentation/build.texi
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Visual Studio builds.
@item MATIO_SHARED:BOOL=ON
This option builds the matio library as shared object
(i.e., a dynamic link library on Windows).
@item MATIO_STATIC_LINK_CRT:BOOL=OFF
This option links the MSVC runtime library statically.
@item MATIO_WITH_HDF5:BOOL=ON
This option enables CMake to check for availability of the
HDF5 library (see section 2.1.2 for information about HDF5).
Expand Down

0 comments on commit e333695

Please sign in to comment.