CMake: Deprecate ENABLE_STATIC_RUNTIME for CMake >=3.15

Closes #546.
This commit is contained in:
evpobr 2020-08-23 13:57:21 +05:00
parent 4f6f65752b
commit 26e473796c
4 changed files with 44 additions and 33 deletions

View File

@ -64,14 +64,14 @@ jobs:
triplet: 'x64-windows-static'
build-system: cmake
cmake-generator: 'Visual Studio 16 2019'
cmake-options: '-DENABLE_STATIC_RUNTIME=ON -DCMAKE_GENERATOR_PLATFORM=x64 -DCMAKE_BUILD_TYPE=Release -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake'
cmake-options: '-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug> -DCMAKE_BUILD_TYPE=Release -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake'
- name: windows-latest-vs2019-Win32
os: windows-latest
triplet: 'x86-windows-static'
build-system: cmake
cmake-generator: 'Visual Studio 16 2019'
cmake-options: '-DENABLE_STATIC_RUNTIME=ON -DCMAKE_GENERATOR_PLATFORM=Win32 -DCMAKE_BUILD_TYPE=Release -DVCPKG_TARGET_TRIPLET=x86-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake'
cmake-options: '-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug> -DCMAKE_GENERATOR_PLATFORM=Win32 -DCMAKE_BUILD_TYPE=Release -DVCPKG_TARGET_TRIPLET=x86-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake'
runs-on: ${{ matrix.os }}
steps:

View File

@ -1,5 +1,9 @@
cmake_minimum_required (VERSION 3.1..3.18)
# MSVC runtime library flags are selected by an abstraction, CMake >= 3.15
# This policy still need to be set even with cmake_minimum_required() command above.
cmake_policy (SET CMP0091 NEW)
project(sndfile VERSION 1.0.29)
#
@ -45,7 +49,7 @@ option (BUILD_EXAMPLES "Build examples" ON)
option (ENABLE_CPACK "Enable CPack support" ON)
option (ENABLE_EXPERIMENTAL "Enable experimental code" OFF)
option (ENABLE_BOW_DOCS "Enable black-on-white html docs" OFF)
if (MSVC)
if (MSVC AND (CMAKE_VERSION VERSION_LESS 3.15))
option (ENABLE_STATIC_RUNTIME "Enable static runtime" OFF)
endif ()
option (ENABLE_PACKAGE_CONFIG "Generate and install package config file" ON)
@ -92,7 +96,7 @@ if (WIN32 AND (NOT MINGW) AND BUILD_SHARED_LIBS)
add_feature_info (ENABLE_COMPATIBLE_LIBSNDFILE_NAME ENABLE_COMPATIBLE_LIBSNDFILE_NAME "Set DLL name to libsndfile-1.dll (canonical name), sndfile.dll otherwise")
endif ()
if (MSVC)
if (MSVC AND (CMAKE_VERSION VERSION_LESS 3.15))
add_feature_info (ENABLE_STATIC_RUNTIME ENABLE_STATIC_RUNTIME "Enable static runtime")
endif ()

View File

@ -136,10 +136,11 @@ You can pass additional options with `/D<parameter>=<value>` when you run
* `INSTALL_PKGCONFIG_MODULE` - generate and install [pkg-config module](https://people.freedesktop.org/~dbn/pkg-config-guide.html).
This option is `ON` by default.
* `ENABLE_STATIC_RUNTIME` - enable static runtime on Windows platform, `OFF` by
default.
default (CMake < 3.15).
**Note**: For MSVC compiler this option is depecated. Use `CMAKE_MSVC_RUNTIME_LIBRARY`
option instead (CMake >= 3.15).
**Note**: For MSVC compiler this option is deprecated and disabled for CMake >= 3.15, see
policy [CMP0091](https://cmake.org/cmake/help/latest/policy/CMP0091.html).
Use `CMAKE_MSVC_RUNTIME_LIBRARY` option instead.
* `ENABLE_COMPATIBLE_LIBSNDFILE_NAME` - set DLL name to `libsndfile-1.dll`
(canonical name) on Windows platform, `sndfile.dll` otherwise, `OFF` by
default. Library name can be different depending on platform. The well known

View File

@ -220,33 +220,39 @@ if (MINGW)
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static-libgcc -static-libstdc++ -s")
endif ()
if (ENABLE_STATIC_RUNTIME)
if (MSVC)
foreach (flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
)
if (${flag_var} MATCHES "/MD")
string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif ()
endforeach (flag_var)
endif (MSVC)
elseif (NOT ENABLE_STATIC_RUNTIME)
if (MSVC)
foreach (flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
)
if (${flag_var} MATCHES "/MT")
string (REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}")
endif (${flag_var} MATCHES "/MT")
endforeach (flag_var)
if (MSVC)
if (DEFINED ENABLE_STATIC_RUNTIME)
if (CMAKE_VERSION VERSION_LESS 3.15)
if (ENABLE_STATIC_RUNTIME)
foreach (flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
)
if (${flag_var} MATCHES "/MD")
string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif ()
endforeach (flag_var)
else ()
foreach (flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
)
if (${flag_var} MATCHES "/MT")
string (REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}")
endif (${flag_var} MATCHES "/MT")
endforeach (flag_var)
endif ( )
else ()
message (FATAL_ERROR "ENABLE_STATIC_RUNTIME option is for CMake < 3.15, use CMAKE_MSVC_RUNTIME_LIBRARY standard option instead.")
endif ()
endif ()
endif ( )
else ()
message(AUTHOR_WARNING "ENABLE_STATIC_RUNTIME option is for MSVC compiler only.")
endif ()
if (BUILD_SHARED_LIBS)
find_package (PythonInterp REQUIRED)