Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update CMake Windows/MSVC configuration
- Loading branch information
1 parent
d2a2a2f
commit c84e5ea
Showing
1 changed file
with
9 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |