Build/Win: Eliminate MSVC run-time DLL dependency

(regression introduced by 1644bdb7d2)

Setting a maximum version in cmake_minimum_required() effectively sets
the behavior to NEW for all policies introduced in all CMake versions up
to and including that maximum version.  The NEW behavior for CMP0091,
introduced in CMake 3.15, uses CMake variables to specify the MSVC
runtime library against which to link, rather than placing the relevant
flags in CMAKE_C_FLAGS*.  Thus, replacing /MD with /MT in CMAKE_C_FLAGS*
no longer has any effect when using CMake 3.15+.
This commit is contained in:
DRC
2024-01-25 13:52:58 -05:00
parent 289df647c0
commit 17df25f92c
3 changed files with 42 additions and 13 deletions

View File

@@ -10,7 +10,7 @@ if(CMAKE_EXECUTABLE_SUFFIX)
endif()
project(libjpeg-turbo C)
set(VERSION 3.0.2)
set(VERSION 3.0.3)
set(COPYRIGHT_YEAR "1991-2024")
string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
list(GET VERSION_TRIPLET 0 VERSION_MAJOR)
@@ -379,12 +379,22 @@ set(TURBOJPEG_SO_VERSION 0.${TURBOJPEG_SO_AGE}.0)
# COMPILER SETTINGS
###############################################################################
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
if(MSVC)
option(WITH_CRT_DLL
"Link all ${CMAKE_PROJECT_NAME} libraries and executables with the C run-time DLL (msvcr*.dll) instead of the static C run-time library (libcmt*.lib.) The default is to use the C run-time DLL only with the libraries and executables that need it."
FALSE)
if(NOT WITH_CRT_DLL)
# Use the static C library for all build types
if(CMAKE_VERSION VERSION_EQUAL "3.15" OR
CMAKE_VERSION VERSION_GREATER "3.15")
if(CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG")
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
endif()
else()
foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${var} MATCHES "/MD")
@@ -392,6 +402,7 @@ if(MSVC)
endif()
endforeach()
endif()
endif()
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
endif()
@@ -418,8 +429,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
endif()
endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
set(EFFECTIVE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
message(STATUS "Compiler flags = ${EFFECTIVE_C_FLAGS}")

View File

@@ -1,3 +1,14 @@
3.0.3
=====
### Significant changes relative to 3.0.2:
1. Fixed an issue in the build system, introduced in 3.0.2, that caused all
libjpeg-turbo components to depend on the Visual C++ run-time DLL when built
with Visual C++ and CMake 3.15 or later, regardless of value of the
`WITH_CRT_DLL` CMake variable.
3.0.2
=====

View File

@@ -11,6 +11,14 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
if(MSVC)
# Build all configurations against shared C library
if(CMAKE_VERSION VERSION_EQUAL "3.15" OR
CMAKE_VERSION VERSION_GREATER "3.15")
if(CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG")
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
endif()
else()
foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${var} MATCHES "/MT")
@@ -18,6 +26,7 @@ if(MSVC)
endif()
endforeach()
endif()
endif()
foreach(src ${JPEG_SOURCES})
set(JPEG_SRCS ${JPEG_SRCS} ../${src})