Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake option to link MSVC runtime library statically #224

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ jobs:
echo "/Users/runner/Library/Python/${{ matrix.python-version }}/bin" >> $GITHUB_PATH
fi
if [ "${{ matrix.compiler }}" == "msvc" ]; then
cmake -S . -B build -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF
cmake -S . -B build -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -DMATIO_STATIC_LINK_MSVC_RT=ON --loglevel VERBOSE
elif [ "${{ matrix.compiler }}" == "mingw" ]; then
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -G "MinGW Makefiles"
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -G "MinGW Makefiles" --loglevel VERBOSE
else
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF --loglevel VERBOSE
fi
- name: Build with ${{ matrix.compiler }}
run: |
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
pkg_add cmake
run: |
set -e
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DMATIO_SHARED=OFF -DMATIO_MAT73=OFF
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DMATIO_SHARED=OFF -DMATIO_MAT73=OFF --loglevel VERBOSE
cmake --build build -- -j8
./build/test_snprintf
./build/test_mat -H
Expand Down Expand Up @@ -137,7 +137,7 @@ jobs:
run: |
set -e
mkdir build
cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=Release -DMATIO_SHARED=OFF -DMATIO_MAT73=OFF
cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=Release -DMATIO_SHARED=OFF -DMATIO_MAT73=OFF --loglevel VERBOSE
cmake --build build -- -j8
./build/test_snprintf
./build/test_mat -H
Expand Down
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_MSVC_RT: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_MSVC_RT: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
15 changes: 15 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ 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)

if(POLICY CMP0091)
tbeu marked this conversation as resolved.
Show resolved Hide resolved
# CMake >= 3.15 has CMAKE_MSVC_RUNTIME_LIBRARY to set the MSVCC runtime library
if(MSVC)
# Option to link the MSVC runtime library statically
option(MATIO_STATIC_LINK_MSVC_RT "Link the MSVC runtime library statically" OFF)
if(MATIO_STATIC_LINK_MSVC_RT)
message(VERBOSE "Configuring to link the MSVC runtime library statically")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
message(VERBOSE "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
Loading