-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCMakeLists.txt
164 lines (138 loc) · 4.24 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
cmake_minimum_required(VERSION 3.25)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(vcpkg)
set(VCPKG_SUBMODULE_ROOT ${CMAKE_CURRENT_LIST_DIR}/vcpkg)
vcpkg_configure(SUBMODULE_ROOT ${VCPKG_SUBMODULE_ROOT})
project(netremote
LANGUAGES CXX
VERSION 0.0.1
)
# Conditional inclusion of OS-dependent source trees.
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(BUILD_FOR_LINUX TRUE)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(BUILD_FOR_WINDOWS TRUE)
else ()
MESSAGE(FATAL_ERROR "No supported target OS detected, SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")
endif()
MESSAGE(STATUS "Target OS ${CMAKE_SYSTEM_NAME} detected")
# Set language configutation options. The C++ standard used must be the lowest
# common denominator for all the OS-dependent projects. In practice, since this
# project must build under the Windows build system (build.exe), its toolchain
# is typically the limiting factor.
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Don't add CTest targets
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
include(CheckPIESupported)
include(CTest)
include(ExternalProject)
include(GNUInstallDirs)
include(grpc)
include(protoc)
# Enable verbose output until project is bootstrapped.
set(CMAKE_VERBOSE_MAKEFILE ON)
# Pull in external dependencies.
# Look for protobuf-config.cmake.
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(gRPC CONFIG REQUIRED)
find_package(Protobuf CONFIG REQUIRED)
find_package(Threads REQUIRED)
find_package(magic_enum CONFIG REQUIRED)
# Enable POSITION_INDEPENDENT_CODE variable to control passing PIE flags to the linker.
if (POLICY CMP0083)
cmake_policy(SET CMP0083 NEW)
endif()
# Enable position independent executables.
check_pie_supported(LANGUAGES CXX)
if (CMAKE_CXX_LINK_PIE_SUPPORTED)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
if (WERROR)
add_compile_options(-Werror)
endif()
# Set compiler specific options
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Common options for both gcc and clang
add_compile_options(
-fstack-protector-all
-fvisibility=hidden
-fcf-protection
-fpermissive
-mshstk
-Wall
-Wshadow
-Wformat-security
-Wextra
-Wpedantic
-Wconversion
-Walloca
-Wvla
)
# gcc specific options
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(
-fstack-clash-protection
-Wtrampolines
-Wl,-z,noexecstack
-Wl,-z,now
-Wl,-z,relro
-z noexecstack
)
if (NOF_CODE_COVERAGE)
add_compile_options(
-fprofile-arcs
-ftest-coverage
)
endif()
# clang specific options
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (NOF_CODE_COVERAGE)
add_compile_options(
-fprofile-instr-generate
-fcoverage-mapping
)
endif()
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# TODO
endif()
if (CMAKE_BUILD_TYPE MATCHES "(Release|RelWithDebInfo|MinSizeRel)")
add_compile_definitions(_FORTIFY_SOURCE=2)
endif()
# Common source directories
set(NETREMOTE_DIR_SRC ${CMAKE_CURRENT_LIST_DIR}/src)
set(NETREMOTE_DIR_LINUX ${CMAKE_CURRENT_LIST_DIR}/linux)
set(NETREMOTE_DIR_WINDOWS ${CMAKE_CURRENT_LIST_DIR}/windows)
# Add common, global compile definitions.
add_compile_definitions(
MAGIC_ENUM_RANGE_MIN=0
MAGIC_ENUM_RANGE_MAX=255
)
# Conditional inclusion of OS-dependent source trees.
if (BUILD_FOR_LINUX)
include(hostap)
add_subdirectory(linux)
elseif (BUILD_FOR_WINDOWS)
# Make public version of wil available.
set(WIL_BUILD_TESTS OFF CACHE INTERNAL "Turn off wil tests")
set(WIL_BUILD_PACKAGING OFF CACHE INTERNAL "Turn off wil packaging")
find_package(wil CONFIG REQUIRED)
# Add Windows-specific global compile definitions.
add_compile_definitions(
_UNICODE
UNICODE
NOMINMAX
WIN32_LEAN_AND_MEAN
)
# Allow more than default number of sections in object files.
add_compile_options(
/bigobj
)
add_subdirectory(windows)
endif()
add_subdirectory(protocol)
add_subdirectory(src)
add_subdirectory(tests)