@@ -30,27 +30,40 @@ endif()
3030
3131# Update CFLAGS
3232if (MSVC )
33+ # Use static C runtime
34+ if (NOT (CMAKE_VERSION VERSION_LESS "3.15" ))
35+ set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG :Debug >:Debug >" )
36+ endif ()
37+ add_compile_options (/MT$<$<CONFIG:Debug>:d> )
38+ # Replace (/|-)MD(d?) with (/|-)MT(d?) to avoid D9025 warning
39+ foreach (config_type ${CMAKE_CONFIGURATION_TYPES } ${CMAKE_BUILD_TYPE } Debug Release RelWithDebInfo MinSizeRel)
40+ string (TOUPPER ${config_type} upper_config_type)
41+ set (flag_var "CMAKE_C_FLAGS_${upper_config_type} " )
42+ string (REGEX REPLACE "(^| |\\ t|\\ r|\\ n)(-|/)(MD)(d?)($| |\\ t|\\ r|\\ n)" "\\ 1\\ 2MT\\ 4\\ 5" ${flag_var} "${${flag_var} }" )
43+ endforeach ()
44+ set (flag_var)
45+ set (upper_config_type)
46+ set (config_type)
47+
48+ # Make compiler aware of source code using UTF-8 encoding
49+ add_compile_options (/utf-8 )
50+
3351 add_definitions (-D_CRT_SECURE_NO_WARNINGS )
3452 add_definitions (-D_CRT_NONSTDC_NO_WARNINGS )
3553
3654 # Use custom CFLAGS for MSVC
3755 #
3856 # /Zi ...... Generate pdb files.
39- # /MT ...... Static link C runtimes.
4057 # /wd4711 .. C4711 (function selected for inline expansion)
4158 # /wd4100 .. C4100 (unreferenced formal parameter)
4259 # /wd5045 .. C5045 (Spectre mitigation)
4360 #
44- set (CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /DNDEBUG /O2 / Zi /wd4100 /wd4711 /wd5045" )
61+ set (CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /Zi /wd4100 /wd4711 /wd5045" )
4562 set (CMAKE_EXE_LINKER_FLAGS "/Debug /INCREMENTAL:NO" )
46- set (CMAKE_BUILD_TYPE None)
4763
4864 # We need this line in order to link libonigmo.lib statically.
4965 # Read onigmo/README for details.
5066 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS } -DEXPORT -DHAVE_CONFIG_H" )
51- # Use add_compile_options() to set /MT since Visual Studio
52- # Generator does not notice /MT in CMAKE_C_FLAGS.
53- add_compile_options (/MT )
5467else ()
5568 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS } -Wall" )
5669endif ()
0 commit comments