Skip to content

Commit 6317164

Browse files
committed
cmake: Add essential platform-specific definitions and options
1 parent 16b6c2f commit 6317164

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,41 @@ else()
6060
endif()
6161
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
6262

63+
if(WIN32)
64+
#[=[
65+
This build system supports two ways to build binaries for Windows.
66+
67+
1. Building on Windows using MSVC.
68+
Implementation notes:
69+
- /DWIN32 and /D_WINDOWS definitions are included into the CMAKE_CXX_FLAGS_INIT
70+
and CMAKE_CXX_FLAGS_INIT variables by default.
71+
- A run-time library is selected using the CMAKE_MSVC_RUNTIME_LIBRARY variable.
72+
- MSVC-specific options, for example, /Zc:__cplusplus, are additionally required.
73+
74+
2. Cross-compiling using MinGW.
75+
Implementation notes:
76+
- WIN32 and _WINDOWS definitions must be provided explicitly.
77+
- A run-time library must be specified explicitly using _MT definition.
78+
]=]
79+
80+
add_compile_definitions(_WIN32_WINNT=0x0601 _WIN32_IE=0x0501 WIN32_LEAN_AND_MEAN NOMINMAX)
81+
82+
if(MSVC)
83+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
84+
add_compile_options(/utf-8 /Zc:__cplusplus)
85+
endif()
86+
87+
if(MINGW)
88+
add_compile_definitions(WIN32 _WINDOWS _MT)
89+
# We require Windows 7 (NT 6.1) or later.
90+
add_link_options(-Wl,--major-subsystem-version,6 -Wl,--minor-subsystem-version,1)
91+
endif()
92+
endif()
93+
94+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
95+
add_compile_definitions(MAC_OSX)
96+
endif()
97+
6398
include(CheckSourceCompilesAndLinks)
6499
include(cmake/introspection.cmake)
65100

0 commit comments

Comments
 (0)