Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build argument: --static-crt #5148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ set(ENABLE_LTO ON CACHE BOOL "Enable LTO build?")
set(ENABLE_STRIP ON CACHE BOOL "Enable stripping all symbols from release binary?")
set(ENABLE_COMPILE_COMMANDS ON CACHE BOOL "Enable generating compile_commands.json?")

if(USING_MSVC)
set(ENABLE_STATIC_CRT OFF CACHE BOOL "Enable MSVC static CRT?")
endif()

# Option overrides
if(NOT USING_CLANG)
set(JERRY_LIBFUZZER OFF)
Expand Down Expand Up @@ -132,6 +136,7 @@ message(STATUS "BUILD_SHARED_LIBS " ${BUILD_SHARED_LIBS})
message(STATUS "ENABLE_AMALGAM " ${ENABLE_AMALGAM} ${ENABLE_AMALGAM_MESSAGE})
message(STATUS "ENABLE_LTO " ${ENABLE_LTO} ${ENABLE_LTO_MESSAGE})
message(STATUS "ENABLE_STRIP " ${ENABLE_STRIP} ${ENABLE_STRIP_MESSAGE})
message(STATUS "ENABLE_STATIC_CRT " ${ENABLE_STATIC_CRT})
message(STATUS "ENABLE_COMPILE_COMMANDS " ${ENABLE_COMPILE_COMMANDS})
message(STATUS "JERRY_VERSION " ${JERRY_VERSION})
message(STATUS "JERRY_CMDLINE " ${JERRY_CMDLINE} ${JERRY_CMDLINE_MESSAGE})
Expand Down Expand Up @@ -241,6 +246,22 @@ if(USING_MSVC)
jerry_add_link_flags(/OPT:NOREF)
# Disable MSVC warning 4996 globally because it stops us from using standard C functions.
jerry_add_compile_flags(/wd4996)

if(ENABLE_STATIC_CRT)
# Replace the existing /MD and /MDd values with /MT and /MTd.
set(COMPILER_FLAGS
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)

foreach(_flag ${COMPILER_FLAGS})
string(REPLACE "/MD" "/MT" ${_flag} "${${_flag}}")
endforeach()
endif()
endif()

if(JERRY_LIBFUZZER)
Expand Down
3 changes: 3 additions & 0 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def devhelp(helpstring):
help='enable amalgamated build (%(choices)s)')
buildgrp.add_argument('--lto', metavar='X', choices=['ON', 'OFF'], type=str.upper,
help='enable link-time optimizations (%(choices)s)')
buildgrp.add_argument('--static-crt', metavar='X', choices=['ON', 'OFF'], type=str.upper,
help='enable msvc static CRT (%(choices)s)')
buildgrp.add_argument('--shared-libs', metavar='X', choices=['ON', 'OFF'], type=str.upper,
help='enable building of shared libraries (%(choices)s)')
buildgrp.add_argument('--strip', metavar='X', choices=['ON', 'OFF'], type=str.upper,
Expand Down Expand Up @@ -187,6 +189,7 @@ def build_options_append(cmakeopt, cliarg):
build_options_append('ENABLE_AMALGAM', arguments.amalgam)
build_options_append('ENABLE_LTO', arguments.lto)
build_options_append('BUILD_SHARED_LIBS', arguments.shared_libs)
build_options_append('ENABLE_STATIC_CRT', arguments.static_crt)
build_options_append('ENABLE_STRIP', arguments.strip)
build_options_append('CMAKE_TOOLCHAIN_FILE', arguments.toolchain)
build_options_append('CMAKE_VERBOSE_MAKEFILE', arguments.verbose)
Expand Down