diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index a3ec48cf..e7264ddc 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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: | @@ -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 @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 745f549e..40ba4858 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/README b/README index c658d64b..5af2ddee 100644 --- a/README +++ b/README @@ -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). diff --git a/README.md b/README.md index 90224c0d..30cae574 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/cmake/options.cmake b/cmake/options.cmake index f2e36459..17c56405 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -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) + # 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$<$:Debug>") + else() + message(VERBOSE "Configuring to link the MSVC runtime library dynamically") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + endif() + endif() +endif() + # Build with hdf5 support option(MATIO_WITH_HDF5 "Check for HDF5 library" ON) diff --git a/documentation/build.texi b/documentation/build.texi index 1306bc62..63ec6565 100644 --- a/documentation/build.texi +++ b/documentation/build.texi @@ -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).