Skip to content

Commit e0e72f9

Browse files
akallabethmfleisz
authored andcommitted
[cmake] use CMAKE_MSVC_RUNTIME_LIBRARY
* Increase required CMake version to 3.15 (windows only) * Use https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html#prop_tgt:MSVC_RUNTIME_LIBRARY to select windows runtime
1 parent bd2ac8b commit e0e72f9

File tree

12 files changed

+57
-82
lines changed

12 files changed

+57
-82
lines changed

CMakeCPack.cmake

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ set(CPACK_NSIS_MUI_UNICON "${PROJECT_SOURCE_DIR}/resource\\\\FreeRDP_Icon_96px.i
6161
set(CPACK_COMPONENTS_ALL client server libraries headers symbols tools)
6262

6363
if(MSVC)
64-
if(MSVC_RUNTIME STREQUAL "dynamic")
64+
string(FIND ${CMAKE_MSVC_RUNTIME_LIBRARY} "DLL" IS_SHARED)
65+
66+
if(NOT IS_SHARED STREQUAL "-1")
6567
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
6668
include(InstallRequiredSystemLibraries)
6769

CMakeLists.txt

+1-19
Original file line numberDiff line numberDiff line change
@@ -230,25 +230,7 @@ if(FREEBSD)
230230
endif()
231231

232232
# Configure MSVC Runtime
233-
if(MSVC)
234-
include(MSVCRuntime)
235-
if(NOT DEFINED MSVC_RUNTIME)
236-
set(MSVC_RUNTIME "dynamic" CACHE STRING "MSVC runtime type [dynamic|static]")
237-
endif()
238-
if(MSVC_RUNTIME STREQUAL "static")
239-
if(BUILD_SHARED_LIBS)
240-
message(FATAL_ERROR "Static CRT is only supported in a fully static build")
241-
endif()
242-
message(STATUS "Use the MSVC static runtime option carefully!")
243-
message(STATUS "OpenSSL uses /MD by default, and is very picky")
244-
message(STATUS "Random freeing errors are a common sign of runtime issues")
245-
endif()
246-
configure_msvc_runtime()
247-
248-
if(NOT DEFINED CMAKE_SUPPRESS_REGENERATION)
249-
set(CMAKE_SUPPRESS_REGENERATION ON)
250-
endif()
251-
endif()
233+
include(MSVCRuntime)
252234

253235
# Enable 64bit file support on linux and FreeBSD.
254236
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux" OR FREEBSD)

ci/cmake-preloads/config-windows.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
message("PRELOADING windows cache")
22
set (CMAKE_WINDOWS_VERSION "WIN7" CACHE STRING "windows build version")
3-
set (MSVC_RUNTIME "static" CACHE STRING "link MSVC runtime static")
43
set (BUILD_SHARED_LIBS OFF CACHE BOOL "build static linked executable")
54
set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded" CACHE STRING "MSVC runtime to use")
65
set (OPENSSL_USE_STATIC_LIBS ON CACHE BOOL "link OpenSSL static")

client/SDL/CMakeLists.txt

+1-19
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,7 @@ if(NOT CMAKE_BUILD_TYPE)
4444
endif()
4545

4646
# Configure MSVC Runtime
47-
if(MSVC)
48-
include(MSVCRuntime)
49-
if(NOT DEFINED MSVC_RUNTIME)
50-
set(MSVC_RUNTIME "dynamic" CACHE STRING "MSVC runtime type [dynamic|static]")
51-
endif()
52-
if(MSVC_RUNTIME STREQUAL "static")
53-
if(BUILD_SHARED_LIBS)
54-
message(FATAL_ERROR "Static CRT is only supported in a fully static build")
55-
endif()
56-
message(STATUS "Use the MSVC static runtime option carefully!")
57-
message(STATUS "OpenSSL uses /MD by default, and is very picky")
58-
message(STATUS "Random freeing errors are a common sign of runtime issues")
59-
endif()
60-
configure_msvc_runtime()
61-
62-
if(NOT DEFINED CMAKE_SUPPRESS_REGENERATION)
63-
set(CMAKE_SUPPRESS_REGENERATION ON)
64-
endif()
65-
endif()
47+
include(MSVCRuntime)
6648

6749
if(WITH_WIN_CONSOLE)
6850
set(WIN32_GUI_FLAG "")

client/Sample/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ option(CMAKE_VERBOSE_MAKEFILE "verbose CMake makefile" ON)
2727
option(CMAKE_POSITION_INDEPENDENT_CODE "build with position independent code (-fPIC or -fPIE)" ON)
2828
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/)
2929

30+
include(MSVCRuntime)
31+
3032
if(NOT CMAKE_BUILD_TYPE)
3133
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "project default" FORCE)
3234
endif()

cmake/MSVCRuntime.cmake

+40-41
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
1-
2-
macro(configure_msvc_runtime)
3-
if(MSVC)
4-
# Default to statically-linked runtime.
5-
if("${MSVC_RUNTIME}" STREQUAL "")
6-
set(MSVC_RUNTIME "dynamic")
1+
if (WIN32)
2+
if (CMAKE_VERSION VERSION_LESS 3.15.0)
3+
message(FATAL_ERROR "windows builds require CMake >= 3.15")
4+
endif()
5+
if(NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
6+
if (MSVC_RUNTIME STREQUAL "dynamic")
7+
set(MSVC_DEFAULT_RUNTIME "MultiThreadedDLL")
8+
elseif(MSVC_RUNTIME STREQUAL "static")
9+
set(MSVC_DEFAULT_RUNTIME "MultiThreaded")
10+
else()
11+
message(WARNING "invalid MSVC_RUNTIME (deprecated) value '${MSVC_RUNTIME}', ignoring")
712
endif()
813

9-
# Set compiler options.
10-
set(variables
11-
CMAKE_C_FLAGS
12-
CMAKE_C_FLAGS_DEBUG
13-
CMAKE_C_FLAGS_MINSIZEREL
14-
CMAKE_C_FLAGS_RELEASE
15-
CMAKE_C_FLAGS_RELWITHDEBINFO
16-
CMAKE_CXX_FLAGS
17-
CMAKE_CXX_FLAGS_DEBUG
18-
CMAKE_CXX_FLAGS_MINSIZEREL
19-
CMAKE_CXX_FLAGS_RELEASE
20-
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
21-
22-
if(${MSVC_RUNTIME} STREQUAL "static")
23-
message(STATUS "MSVC: using statically-linked runtime (/MT and /MTd).")
24-
foreach(variable ${variables})
25-
if(${variable} MATCHES "/MD")
26-
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
27-
endif()
28-
endforeach()
14+
if(MSVC_DEFAULT_RUNTIME)
15+
message("Using CMAKE_MSVC_RUNTIME_LIBRARY=${MSVC_DEFAULT_RUNTIME} (derived from MSVC_RUNTIME (deprecated) value '${MSVC_RUNTIME}')" )
2916
else()
30-
message(STATUS "MSVC: using dynamically-linked runtime (/MD and /MDd).")
31-
foreach(variable ${variables})
32-
if(${variable} MATCHES "/MT")
33-
string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
34-
endif()
35-
endforeach()
36-
endif()
17+
set(MSVC_DEFAULT_RUNTIME "MultiThreaded")
18+
19+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
20+
string(APPEND MSVC_DEFAULT_RUNTIME "Debug")
21+
endif()
3722

38-
foreach(variable ${variables})
39-
if(${variable} MATCHES "/Ob0")
40-
string(REGEX REPLACE "/Ob0" "/Ob2" ${variable} "${${variable}}")
23+
if (BUILD_SHARED_LIBS)
24+
string(APPEND MSVC_DEFAULT_RUNTIME "DLL")
4125
endif()
42-
endforeach()
26+
message("Using CMAKE_MSVC_RUNTIME_LIBRARY=${MSVC_DEFAULT_RUNTIME}" )
27+
endif()
28+
29+
set(CMAKE_MSVC_RUNTIME_LIBRARY ${MSVC_DEFAULT_RUNTIME} CACHE STRING "MSVC runtime")
30+
endif()
31+
32+
message("build is using MSVC runtime ${CMAKE_MSVC_RUNTIME_LIBRARY}")
33+
34+
string(FIND ${CMAKE_MSVC_RUNTIME_LIBRARY} "DLL" IS_SHARED)
35+
if(IS_SHARED STREQUAL "-1")
36+
if(BUILD_SHARED_LIBS)
37+
message(FATAL_ERROR "Static CRT is only supported in a fully static build")
38+
endif()
39+
message(STATUS "Use the MSVC static runtime option carefully!")
40+
message(STATUS "OpenSSL uses /MD by default, and is very picky")
41+
message(STATUS "Random freeing errors are a common sign of runtime issues")
42+
endif()
4343

44-
foreach(variable ${variables})
45-
set(${variable} "${${variable}}" CACHE STRING "MSVC_${variable}" FORCE)
46-
endforeach()
44+
if(NOT DEFINED CMAKE_SUPPRESS_REGENERATION)
45+
set(CMAKE_SUPPRESS_REGENERATION ON)
4746
endif()
48-
endmacro(configure_msvc_runtime)
47+
endif()

packaging/windows/preload.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
message("PRELOADING windows cache")
22
set (CMAKE_WINDOWS_VERSION "WIN7" CACHE STRING "windows build version")
33
set (BUILD_SHARED_LIBS OFF CACHE BOOL "build static linked executable")
4-
set (MSVC_RUNTIME "static" CACHE STRING "link MSVC runtime static")
54
set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded" CACHE STRING "MSVC runtime to use")
65
set (OPENSSL_USE_STATIC_LIBS ON CACHE BOOL "link OpenSSL static")
76
set (CHANNEL_URBDRC OFF CACHE BOOL "we do not build libusb support")

server/proxy/modules/bitmap-filter/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ endif()
3232
set(CMAKE_CXX_STANDARD 11)
3333
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3434

35+
include(MSVCRuntime)
36+
3537
add_library(${PROJECT_NAME} MODULE
3638
bitmap-filter.cpp
3739
)

server/proxy/modules/capture/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ if (supported)
3333
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
3434
endif()
3535

36+
include(MSVCRuntime)
37+
3638
add_library(${PROJECT_NAME} MODULE
3739
cap_main.c
3840
cap_config.c

server/proxy/modules/demo/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ endif()
3232
set(CMAKE_CXX_STANDARD 11)
3333
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3434

35+
include(MSVCRuntime)
36+
3537
add_library(${PROJECT_NAME} MODULE
3638
demo.cpp
3739
)

server/proxy/modules/dyn-channel-dump/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ endif()
3131
set(CMAKE_CXX_STANDARD 17)
3232
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3333

34+
include(MSVCRuntime)
35+
3436
add_library(${PROJECT_NAME} MODULE
3537
dyn-channel-dump.cpp
3638
)

winpr/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ if (NOT FREERDP_UNIFIED_BUILD)
4949
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
5050
endif()
5151
endif()
52+
53+
include(MSVCRuntime)
5254
endif()
5355

5456
set(DEFAULT_DEBUG_OPTION OFF)

0 commit comments

Comments
 (0)