From cdbe29df0c5dacbe710969ebf0ddb7a7b13bb79b Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Fri, 27 Feb 2026 14:28:04 +0300 Subject: [PATCH 1/2] build: MSVC: debug C runtime for debug build configuration Signed-off-by: Marat Abrarov --- CMakeLists.txt | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a5f1244..1f2374b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,27 +30,40 @@ endif() # Update CFLAGS if (MSVC) + # Use static C runtime + if (NOT (CMAKE_VERSION VERSION_LESS "3.15")) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + endif() + add_compile_options(/MT$<$:d>) + # Replace (/|-)MD(d?) with (/|-)MT(d?) to avoid D9025 warning + foreach(config_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug Release RelWithDebInfo MinSizeRel) + string(TOUPPER ${config_type} upper_config_type) + set(flag_var "CMAKE_C_FLAGS_${upper_config_type}") + string(REGEX REPLACE "(^| |\\t|\\r|\\n)(-|/)(MD)(d?)($| |\\t|\\r|\\n)" "\\1\\2MT\\4\\5" ${flag_var} "${${flag_var}}") + endforeach() + set(flag_var) + set(upper_config_type) + set(config_type) + + # Make compiler aware of source code using UTF-8 encoding + add_compile_options(/utf-8) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_NONSTDC_NO_WARNINGS) # Use custom CFLAGS for MSVC # # /Zi ...... Generate pdb files. - # /MT ...... Static link C runtimes. # /wd4711 .. C4711 (function selected for inline expansion) # /wd4100 .. C4100 (unreferenced formal parameter) # /wd5045 .. C5045 (Spectre mitigation) # - set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /DNDEBUG /O2 /Zi /wd4100 /wd4711 /wd5045") + set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /Zi /wd4100 /wd4711 /wd5045") set(CMAKE_EXE_LINKER_FLAGS "/Debug /INCREMENTAL:NO") - set(CMAKE_BUILD_TYPE None) # We need this line in order to link libonigmo.lib statically. # Read onigmo/README for details. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPORT -DHAVE_CONFIG_H") - # Use add_compile_options() to set /MT since Visual Studio - # Generator does not notice /MT in CMAKE_C_FLAGS. - add_compile_options(/MT) else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") endif() From 732e052e23e0d8f86a06f3d646846b3807ceece6 Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Fri, 27 Feb 2026 14:28:18 +0300 Subject: [PATCH 2/2] build: MSVC: no link-time code generation for debug build configuration to speedup building Signed-off-by: Marat Abrarov --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f2374b..5f0ee4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,7 +270,7 @@ if(ONIGMO_SHARED_LIB) PROPERTIES PDB_NAME onigmo.dll) target_link_options(onigmo-shared PUBLIC /pdb:$ - PRIVATE /LTCG) + PRIVATE $<$>:/LTCG>) endif() # Library install routines