-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
75 lines (66 loc) · 3.05 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Main CMakeLists
cmake_minimum_required(VERSION 3.13)
project(console LANGUAGES CXX VERSION 0.1.0)
option(CONSOLE_INSTALL "Install console" ON)
function (target_set_options TGT)
# Set C++20
target_compile_features(${TGT} PRIVATE cxx_std_20)
set_target_properties(${TGT} PROPERTIES
CXX_EXTENSIONS OFF
INTERPROCEDURAL_OPTIMIZATION ON)
# MSVC settings
if (MSVC)
# Force MSVC to use utf-8 encoding regardless of whether the BOM exists
target_compile_options(${TGT} PRIVATE "/utf-8")
# /Zc:__cplusplus is needed for MSVC to produce correct value for the __cplusplus macro
# If this option is not on, __cplusplus will always expands to 199711L
if (MSVC_VERSION GREATER_EQUAL 1914)
target_compile_options(${TGT} PUBLIC
"/Zc:__cplusplus"
"/Zc:externConstexpr")
endif ()
endif ()
# Asio requires _WIN32_WINNT to be set
if (WIN32)
if (${CMAKE_SYSTEM_VERSION} EQUAL 10) # Windows 10
set(WIN32_WINNT 0x0A00)
elseif (${CMAKE_SYSTEM_VERSION} EQUAL 6.3) # Windows 8.1
set(WIN32_WINNT 0x0603)
elseif (${CMAKE_SYSTEM_VERSION} EQUAL 6.2) # Windows 8
set(WIN32_WINNT 0x0602)
elseif (${CMAKE_SYSTEM_VERSION} EQUAL 6.1) # Windows 7
set(WIN32_WINNT 0x0601)
elseif (${CMAKE_SYSTEM_VERSION} EQUAL 6.0) # Windows Vista
set(WIN32_WINNT 0x0600)
else () # Windows XP (5.1)
set(WIN32_WINNT 0x0501)
endif ()
target_compile_definitions(${TGT} PRIVATE _WIN32_WINNT=${WIN32_WINNT})
endif ()
# Warnings and errors settings
# Use highest reasonable warning level, and treat warnings as errors
if (MSVC) # Visual Studio
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") # If default /W3 presents
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # Change /W3 to /W4
else ()
target_compile_options(${TGT} PRIVATE /W4) # Add /W4 directly
endif ()
target_compile_options(${TGT} PRIVATE /WX) # Treat warnings as errors
# Treat all header files specified by angle brackets to be system headers, and ignore all those warnings
target_compile_options(${TGT} PRIVATE
/experimental:external /external:W0 /external:anglebrackets)
else () # Not Visual Studio, assuming gcc or clang
target_compile_options(${TGT} PRIVATE
-Wall -Wextra -pedantic -Wundef -Werror
-Wno-missing-field-initializers # Aggregate init with base class would be impossible with this warning
# TODO: gcc trunk currently confuses itself in coroutine code, remove this later when gcc behaves well
-Wno-unused-value)
endif ()
endfunction ()
function (target_set_output_dir TGT)
set_target_properties(${TGT} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/out"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/out"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/out")
endfunction ()
add_subdirectory(lib)