Skip to content
Open
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
27 changes: 20 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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$<$<CONFIG:Debug>:Debug>")
endif()
add_compile_options(/MT$<$<CONFIG:Debug>: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()
Expand Down Expand Up @@ -257,7 +270,7 @@ if(ONIGMO_SHARED_LIB)
PROPERTIES PDB_NAME onigmo.dll)
target_link_options(onigmo-shared
PUBLIC /pdb:$<TARGET_PDB_FILE:onigmo-shared>
PRIVATE /LTCG)
PRIVATE $<$<NOT:$<CONFIG:Debug>>:/LTCG>)
endif()

# Library install routines
Expand Down