forked from chromium/content_analysis_sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
182 lines (167 loc) · 5.65 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Copyright 2022 The Chromium Authors.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
cmake_minimum_required(VERSION 3.22)
project(chrome_enterprise_connector_local_analysis)
# Ensure a C++14 compiler is used.
set(CMAKE_CXX_STANDARD 14)
# Determine the operating system being targeted.
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(WIN TRUE)
set(MAC FALSE)
set(LINUX FALSE)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(WIN FALSE)
set(MAC TRUE)
set(LINUX FALSE)
else()
set(WIN FALSE)
set(MAC FALSE)
set(LINUX TRUE)
endif()
# Set the path to the protoc protobuf compiler.
if(WIN)
set(PROTOC ${PROJECT_BINARY_DIR}/vcpkg/installed/x64-windows/tools/protobuf/protoc.exe)
elseif(MAC)
set(PROTOC ${PROJECT_BINARY_DIR}/vcpkg/installed/x64-osx/tools/protobuf/protoc)
elseif(LINUX)
set(PROTOC ${PROJECT_BINARY_DIR}/vcpkg/installed/x64-linux/tools/protobuf/protoc)
endif()
# Calls the protoc compiler using the arguments specific to this project.
# protobuf_generate_cpp is not flexible enough for our needs.
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/gen/content_analysis/sdk/analysis.pb.cc
COMMAND
${PROTOC}
--cpp_out=${PROJECT_BINARY_DIR}/gen
--proto_path=${PROJECT_SOURCE_DIR}/proto
${PROJECT_SOURCE_DIR}/proto/content_analysis/sdk/analysis.proto
DEPENDS ./proto/content_analysis/sdk/analysis.proto
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
# Define proto target. Compile this target exclusively by calling:
# `cmake --build <build_dir> --target proto`
add_custom_target(proto ALL DEPENDS ${PROJECT_BINARY_DIR}/gen/content_analysis/sdk/analysis.pb.cc)
# The include directory contains the header files needed by the demo code.
# The gen directory contains generated protobuf headers describing the request
# and response objects used to communicate with Google Chrome.
set(AGENT_INCLUDES
./agent/include
.
${PROJECT_BINARY_DIR}/gen
)
set(BROWSER_INCLUDES
./browser/include
.
${PROJECT_BINARY_DIR}/gen
)
# The SDK contains platform specific code for each of the supported platforms.
# ${PLATFORM_AGENT_CODE} holds the list of source files needed for the current
# platform being built.
if(WIN)
set(PLATFORM_AGENT_CODE
./agent/src/agent_win.cc
./agent/src/agent_win.h
./agent/src/session_win.cc
./agent/src/session_win.h
./common/utils_win.cc
./common/utils_win.h
)
set(PLATFORM_QUEUED_AGENT_DEMO_CODE
./demo/queued_agent_win.cc
)
elseif(MAC)
set(PLATFORM_AGENT_CODE
./agent/src/agent_mac.cc
./agent/src/agent_mac.h
./agent/src/session_mac.cc
./agent/src/session_mac.h
)
elseif(LINUX)
set(PLATFORM_AGENT_CODE
./agent/src/agent_posix.cc
./agent/src/agent_posix.h
./agent/src/session_posix.cc
./agent/src/session_posix.h
)
set(PLATFORM_QUEUED_AGENT_DEMO_CODE
./demo/queued_agent_posix.cc
)
endif()
# The SDK contains platform specific code for each of the supported platforms.
# ${PLATFORM_BROWSER_CODE} holds the list of source files needed for the current
# platform being built.
if(WIN)
set(PLATFORM_BROWSER_CODE
./browser/src/client_win.cc
./browser/src/client_win.h
./common/utils_win.cc
./common/utils_win.h
)
elseif(MAC)
set(PLATFORM_BROWSER_CODE
./browser/src/client_mac.cc
./browser/src/client_mac.h
)
elseif(LINUX)
set(PLATFORM_BROWSER_CODE
./browser/src/client_posix.cc
./browser/src/client_posix.h
)
endif()
# Makes available the package definitions in vcpkg.
include("${PROJECT_BINARY_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
find_package(Protobuf CONFIG REQUIRED)
# Unit tests
enable_testing()
find_package(GTest CONFIG REQUIRED)
include(GoogleTest)
add_executable(
agent_test_shell
../agent/src/agent_test_shell.cc
)
target_link_libraries(
agent_test_shell
PUBLIC
GTest::gtest GTest::gtest_main
)
gtest_discover_tests(agent_test_shell)
# Builds the content analysis connector agent linker library. This library is linked
# into the agent in order to listen for and process content analysis requests
# from Google Chrome.
add_library(cac_agent
./agent/include/content_analysis/sdk/analysis_agent.h
./agent/src/agent_base.cc
./agent/src/agent_base.h
./agent/src/session_base.cc
./agent/src/session_base.h
${PLATFORM_AGENT_CODE}
${PROJECT_BINARY_DIR}/gen/content_analysis/sdk/analysis.pb.cc
)
target_link_libraries(cac_agent PUBLIC protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
target_include_directories(cac_agent PRIVATE ${AGENT_INCLUDES})
# Builds the content analysis connector browser linker library. This library is linked
# into the client in order to send content analysis requests to the agent.
add_library(cac_browser
./browser/include/content_analysis/sdk/analysis_client.h
./browser/src/client_base.cc
./browser/src/client_base.h
${PLATFORM_BROWSER_CODE}
${PROJECT_BINARY_DIR}/gen/content_analysis/sdk/analysis.pb.cc
)
target_include_directories(cac_browser PRIVATE ${BROWSER_INCLUDES})
target_link_libraries(cac_browser PUBLIC protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
# The demo agent executable.
add_executable(agent ./demo/agent.cc)
target_include_directories(agent PRIVATE ${AGENT_INCLUDES})
target_link_libraries(agent PRIVATE cac_agent)
# A demo agent that queues up requests for a background thread.
if (WIN OR LINUX)
add_executable(queued_agent ${PLATFORM_QUEUED_AGENT_DEMO_CODE})
target_include_directories(queued_agent PRIVATE ${AGENT_INCLUDES})
target_link_libraries(queued_agent PRIVATE cac_agent)
endif()
# The demo client executable.
add_executable(browser ./demo/client.cc)
target_include_directories(browser PRIVATE ${BROWSER_INCLUDES})
target_link_libraries(browser PRIVATE cac_browser)