Skip to content

Commit

Permalink
Update CMake Windows/MSVC configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
carstene1ns committed Apr 26, 2024
1 parent d2a2a2f commit c84e5ea
Showing 1 changed file with 9 additions and 33 deletions.
42 changes: 9 additions & 33 deletions Modules/ConfigureWindows.cmake
@@ -1,50 +1,26 @@
if(WIN32)
# Target Unicode API
add_definitions(-D_UNICODE)
add_definitions(-DUNICODE)
add_compile_definitions(_UNICODE UNICODE)

# Disable API deprecation warnings
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)

# Prevent some Windows.h global namespace pollution
add_definitions(-DNOMINMAX)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN)

# Make math constants available
add_compile_definitions(_USE_MATH_DEFINES)
endif()

if(MSVC)
option(SHARED_RUNTIME "Windows: Build using the shared runtime library (/MD), disable for static runtime (/MT)" ON)

# Set compiler options.
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(SHARED_RUNTIME)
message(STATUS "Windows: Using dynamic runtime library (/MD)")
foreach(variable ${variables})
if(${variable} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
endif()
endforeach()
else()
message(STATUS "Windows: Using static runtime library (/MT)")
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
endif()
# Depends on vcpkg but we don't support anything else
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<STREQUAL:${VCPKG_CRT_LINKAGE},dynamic>:DLL>" CACHE STRING "")

option(MSVC_MULTICORE "MSVC: Build using multiple cores (/MP)" ON)
if (MSVC_MULTICORE)
add_compile_options("/MP")
endif()

# Interpret character literals as UTF-8
add_compile_options("/utf-8")
endif()

0 comments on commit c84e5ea

Please sign in to comment.