Skip to content

Commit f5d3d90

Browse files
author
winsoft666
authored
Add build argument: --static-crt (#5148)
Signed-off-by: winsoft666 <[email protected]>
1 parent de51531 commit f5d3d90

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ set(ENABLE_LTO ON CACHE BOOL "Enable LTO build?")
6767
set(ENABLE_STRIP ON CACHE BOOL "Enable stripping all symbols from release binary?")
6868
set(ENABLE_COMPILE_COMMANDS ON CACHE BOOL "Enable generating compile_commands.json?")
6969

70+
if(USING_MSVC)
71+
set(ENABLE_STATIC_CRT OFF CACHE BOOL "Enable MSVC static CRT?")
72+
endif()
73+
7074
# Option overrides
7175
if(NOT USING_CLANG)
7276
set(JERRY_LIBFUZZER OFF)
@@ -132,6 +136,7 @@ message(STATUS "BUILD_SHARED_LIBS " ${BUILD_SHARED_LIBS})
132136
message(STATUS "ENABLE_AMALGAM " ${ENABLE_AMALGAM} ${ENABLE_AMALGAM_MESSAGE})
133137
message(STATUS "ENABLE_LTO " ${ENABLE_LTO} ${ENABLE_LTO_MESSAGE})
134138
message(STATUS "ENABLE_STRIP " ${ENABLE_STRIP} ${ENABLE_STRIP_MESSAGE})
139+
message(STATUS "ENABLE_STATIC_CRT " ${ENABLE_STATIC_CRT})
135140
message(STATUS "ENABLE_COMPILE_COMMANDS " ${ENABLE_COMPILE_COMMANDS})
136141
message(STATUS "JERRY_VERSION " ${JERRY_VERSION})
137142
message(STATUS "JERRY_CMDLINE " ${JERRY_CMDLINE} ${JERRY_CMDLINE_MESSAGE})
@@ -241,6 +246,22 @@ if(USING_MSVC)
241246
jerry_add_link_flags(/OPT:NOREF)
242247
# Disable MSVC warning 4996 globally because it stops us from using standard C functions.
243248
jerry_add_compile_flags(/wd4996)
249+
250+
if(ENABLE_STATIC_CRT)
251+
# Replace the existing /MD and /MDd values with /MT and /MTd.
252+
set(COMPILER_FLAGS
253+
CMAKE_CXX_FLAGS
254+
CMAKE_CXX_FLAGS_DEBUG
255+
CMAKE_CXX_FLAGS_RELEASE
256+
CMAKE_C_FLAGS
257+
CMAKE_C_FLAGS_DEBUG
258+
CMAKE_C_FLAGS_RELEASE
259+
)
260+
261+
foreach(_flag ${COMPILER_FLAGS})
262+
string(REPLACE "/MD" "/MT" ${_flag} "${${_flag}}")
263+
endforeach()
264+
endif()
244265
endif()
245266

246267
if(JERRY_LIBFUZZER)

tools/build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def devhelp(helpstring):
7878
help='enable amalgamated build (%(choices)s)')
7979
buildgrp.add_argument('--lto', metavar='X', choices=['ON', 'OFF'], type=str.upper,
8080
help='enable link-time optimizations (%(choices)s)')
81+
buildgrp.add_argument('--static-crt', metavar='X', choices=['ON', 'OFF'], type=str.upper,
82+
help='enable msvc static CRT (%(choices)s)')
8183
buildgrp.add_argument('--shared-libs', metavar='X', choices=['ON', 'OFF'], type=str.upper,
8284
help='enable building of shared libraries (%(choices)s)')
8385
buildgrp.add_argument('--strip', metavar='X', choices=['ON', 'OFF'], type=str.upper,
@@ -187,6 +189,7 @@ def build_options_append(cmakeopt, cliarg):
187189
build_options_append('ENABLE_AMALGAM', arguments.amalgam)
188190
build_options_append('ENABLE_LTO', arguments.lto)
189191
build_options_append('BUILD_SHARED_LIBS', arguments.shared_libs)
192+
build_options_append('ENABLE_STATIC_CRT', arguments.static_crt)
190193
build_options_append('ENABLE_STRIP', arguments.strip)
191194
build_options_append('CMAKE_TOOLCHAIN_FILE', arguments.toolchain)
192195
build_options_append('CMAKE_VERBOSE_MAKEFILE', arguments.verbose)

0 commit comments

Comments
 (0)