forked from microsoft/do-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
122 lines (104 loc) · 4.78 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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cmake_minimum_required(VERSION 3.7)
# The version command, to take effect, must be the first command to execute in the cmake generate step
project (do_project_root)
# Use the build/build.py script to choose and build a subproject.
# More cmake options are defined by individual subprojects.
# Only one subproject can be built with each invocation of cmake. This avoids confusion in specifying options
# exposed by an individual subproject.
option (DO_INCLUDE_AGENT "Build subproject client-lite" OFF)
option (DO_INCLUDE_PLUGINS "Build subproject plugins" OFF)
option (DO_INCLUDE_SDK "Build subproject sdk-cpp" OFF)
option (DO_BUILD_TESTS "Set DO_BUILD_TESTS to OFF to skip building tests." ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Get verbose output from cmake generation and build steps
set(CMAKE_VERBOSE_MAKEFILE ON)
# Set target OS platform
if (CMAKE_SYSTEM_NAME MATCHES Linux)
set(DO_PLATFORM_LINUX 1)
message (STATUS "DO Platform: Linux")
elseif (CMAKE_SYSTEM_NAME MATCHES Windows)
set(DO_PLATFORM_WINDOWS 1)
message (STATUS "DO Platform: Windows")
elseif (CMAKE_SYSTEM_NAME MATCHES Darwin) # Mac
set(DO_PLATFORM_MAC 1)
message (STATUS "DO Platform: Mac")
else()
message(FATAL_ERROR "Unknown platform")
endif()
# Set target lib<-->client interface
if (DO_PLATFORM_LINUX OR DO_PLATFORM_MAC)
set(DO_INTERFACE_REST 1)
message (STATUS "DO Interface: REST")
elseif (DO_PLATFORM_WINDOWS)
set(DO_INTERFACE_COM 1)
message (STATUS "DO Interface: COM")
else()
message(FATAL_ERROR "Unknown platform for interface")
endif()
# Set target client
# Note: In the future, may need to supply a variable to build.py which specifies which agent to build on linux.
# For now, linux support of the SDK is limited to only the open-sourced agent.
if (DO_PLATFORM_MAC OR DO_PLATFORM_WINDOWS)
set(DO_CLIENT_DOSVC 1)
message (STATUS "DO Client: DoSvc")
elseif (DO_PLATFORM_LINUX)
set(DO_CLIENT_AGENT 1)
message (STATUS "DO Client: Agent")
else()
message(FATAL_ERROR "Unknown platform for client")
endif()
# PIC (Position Independent Code) ensures .a files can be linked to executables that have PIE enabled
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# TODO: msvc and gcc support different compiler/linker flags, need to go through all flags and verify what's needed for each platform
# Certain flags cause build issues because the flag itself isn't supported on msvc
# Offending CMAKE_CXX_FLAGS: -Wformat
# Offending CMAKE_EXE_LINKER_FLAGS: relro
if (DO_PLATFORM_LINUX)
# PIE (Position Independent Executable) ensures exe/.so can run when ASLR is enabled in the target OS
set(COMPILER_HARDENING_FLAGS
"-fPIE -pie -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wformat -Werror=format-security")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${COMPILER_HARDENING_FLAGS} -fmerge-all-constants")
# relro+now thwarts some attack vectors by reordering some ELF data structures and also by making the GOT read-only
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -z relro -z now")
endif (DO_PLATFORM_LINUX)
# Define DEBUG macro in debug builds
string(TOLOWER ${CMAKE_BUILD_TYPE} DO_BUILD_TYPE)
if (DO_BUILD_TYPE MATCHES debug)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/common/cmake)
include (do-build-helpers)
include (do-packaging-helpers)
# For contributors, please modify builder name here if changes are made to project source
set(DO_BUILDER_IDENTIFIER "DU")
message(STATUS "Using builder name: ${DO_BUILDER_IDENTIFIER}")
message(STATUS "NOTE: Please modify builder name if modifying project source")
if (DO_BUILD_TIMESTAMP)
message(STATUS "Build timestamp found: ${DO_BUILD_TIMESTAMP}")
else ()
# Note: This is evaluated during generate phase only. Need to generate again to refresh it.
string(TIMESTAMP DO_BUILD_TIMESTAMP "%Y%m%d.%H%M%S" UTC)
message (STATUS "Build timestamp NOT found. Generated it via cmake: ${DO_BUILD_TIMESTAMP}.")
endif ()
if (DO_PLATFORM_LINUX)
set(DOSVC_BIN_NAME "deliveryoptimization-agent")
set(DO_PLUGIN_APT_BIN_NAME "deliveryoptimization-plugin-apt")
endif()
# Only one subproject can be built with each invocation of cmake. This avoids confusion in specifying options
# exposed by an individual subproject.
if (DO_INCLUDE_AGENT)
message (STATUS "Including subproject client-lite")
add_subdirectory(client-lite)
elseif (DO_INCLUDE_PLUGINS)
message (STATUS "Including subproject plugins")
add_subdirectory(plugins)
elseif (DO_INCLUDE_SDK)
message (STATUS "Including subproject sdk-cpp")
add_subdirectory(sdk-cpp)
else ()
message (WARNING "No subproject chosen. Nothing is configured to be built.")
endif ()