forked from microsoft/do-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
150 lines (130 loc) · 6.42 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
# 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)
option (DO_BUILD_FOR_SNAP "Enable DO Snap build option" OFF)
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 -Wreturn-local-addr")
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")
# Depending on the ordering in PATH environment variable (observed on Ubuntu2004), cmake might search
# /lib instead of /usr/lib which causes Boost::headers to get the non-existent "/include" path.
# (Enable --trace-expand in cmake and look at lines from boost_headers-config.cmake and its callers.)
# Workaround: force cmake to look in "/usr" since the /lib and /bin paths are either
# not relevant for our usage or they are symlinks to /usr/lib and /usr/bin.
if (NOT CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH "/usr")
endif ()
endif (DO_PLATFORM_LINUX)
if (DO_PLATFORM_WINDOWS AND DO_INCLUDE_SDK)
# Replicate some of MSEdge build config to catch issues before integration.
# Use Visual Studio 2019 and the x64-Clang-Debug-SDK cmake config to enable these configs.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(DISABLE_WARNINGS "-Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-reserved-id-macro -Wno-global-constructors -Wno-exit-time-destructors -Wno-extra-semi-stmt")
# Note: Many warnings to fix before we can turn on -Werror
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wreturn-stack-address -Wno-string-conversion ${DISABLE_WARNINGS}")
endif ()
if (NOT DO_BUILD_TESTS)
# Disable C++ exceptions
string(REGEX REPLACE "/EH[a-z]+" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_HAS_EXCEPTIONS=0")
# Disable RTTI
string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
endif ()
endif ()
# 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 ()