Skip to content

Commit

Permalink
[CMake] Use CMAKE_MSVC_RUNTIME_LIBRARY to select a CRT type instead o…
Browse files Browse the repository at this point in the history
…f regexp replacing

https://bugs.webkit.org/show_bug.cgi?id=248289

Reviewed by Don Olmstead.

Regexp replacing has been used to change a CRT type for Windows. CMake
3.15 introduced CMAKE_MSVC_RUNTIME_LIBRARY for it.
<https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html>

There was a code to remove _DEBUG macro definition from
CMAKE_{C,CXX}_FLAGS* variables. However, those variables don't include
it. _DEBUG macro is automatically defined by -MDd and -MTd switches.
Removed the code.

Bumped cmake_minimum_required version to 3.16 to use
target_precompile_headers (bug#248202).

* CMakeLists.txt: Source/JavaScriptCore/CMakeLists.txt:
* Source/WTF/CMakeLists.txt: Source/WebCore/CMakeLists.txt:
* Source/WebKitLegacy/CMakeLists.txt:
* Source/cmake/OptionsAppleWin.cmake: Source/cmake/OptionsMSVC.cmake:
* Source/cmake/OptionsWinCairo.cmake:

Canonical link: https://commits.webkit.org/257053@main
  • Loading branch information
fujii committed Nov 28, 2022
1 parent 2b1ab27 commit 121756d
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -10,7 +10,7 @@
# in support of the AppleWin internal build so this version should be kept in
# sync across those files.
#
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.16)
project(WebKit)

# Remove this cmake_policy() after upgrading cmake_minimum_required() to 3.20.
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/CMakeLists.txt
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.16)

include(WebKitCommon)
include(target/TargetWTF)
Expand Down
3 changes: 2 additions & 1 deletion Source/WTF/CMakeLists.txt
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.16)

include(WebKitCommon)
set_property(DIRECTORY . PROPERTY FOLDER "WTF")

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/CMakeLists.txt
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.16)

include(WebKitCommon)
include(target/TargetWTF)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKitLegacy/CMakeLists.txt
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.16)

include(WebKitCommon)
include(target/TargetWTF)
Expand Down
6 changes: 5 additions & 1 deletion Source/cmake/OptionsAppleWin.cmake
Expand Up @@ -3,7 +3,11 @@
# is no longer used, but we keep building with static runtime for backward
# compatibility. But if someone decides that it's OK to require existing
# projects to build with the runtime DLLs, that's now technically possible.
set(MSVC_STATIC_RUNTIME ON)
if (NOT DEBUG_SUFFIX)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
else ()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif ()

if (DEFINED ENV{AppleApplicationSupportSDK})
file(TO_CMAKE_PATH "$ENV{AppleApplicationSupportSDK}/AppleInternal" WEBKIT_LIBRARIES_DIR)
Expand Down
25 changes: 0 additions & 25 deletions Source/cmake/OptionsMSVC.cmake
Expand Up @@ -165,31 +165,6 @@ if (NOT ${CMAKE_CXX_FLAGS} STREQUAL "")
WEBKIT_PREPEND_GLOBAL_COMPILER_FLAGS(/W4)
endif ()

if (MSVC_STATIC_RUNTIME)
message(STATUS "Using multithreaded, static version of the run-time library")
set(MSVC_RUNTIME_COMPILE_FLAG "/MT")
set(MSVC_RUNTIME_LINKER_FLAGS "/NODEFAULTLIB:MSVCRT /NODEFAULTLIB:MSVCRTD")
else ()
message(STATUS "Using multithreaded, dynamic version of the run-time library")
set(MSVC_RUNTIME_COMPILE_FLAG "/MD")
# No linker flags are required
endif ()

foreach (flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
# Use the multithreaded static runtime library instead of the default DLL runtime.
string(REGEX REPLACE "/MD" "${MSVC_RUNTIME_COMPILE_FLAG}" ${flag_var} "${${flag_var}}")

# No debug runtime, even in debug builds.
if (NOT DEBUG_SUFFIX)
string(REGEX REPLACE "${MSVC_RUNTIME_COMPILE_FLAG}d" "${MSVC_RUNTIME_COMPILE_FLAG}" ${flag_var} "${${flag_var}}")
string(REGEX REPLACE "/D_DEBUG" "" ${flag_var} "${${flag_var}}")
endif ()
endforeach ()

# Make sure incremental linking is turned off, as it creates unacceptably long link times.
string(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replace_CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
set(CMAKE_SHARED_LINKER_FLAGS "${replace_CMAKE_SHARED_LINKER_FLAGS} /INCREMENTAL:NO")
Expand Down
3 changes: 3 additions & 0 deletions Source/cmake/OptionsWinCairo.cmake
@@ -1,3 +1,6 @@
# Use Release DLL CRT even for Debug build
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)

set(WTF_PLATFORM_WIN_CAIRO 1)

include(OptionsWin)
Expand Down

0 comments on commit 121756d

Please sign in to comment.