1 # Copyright 2022 The Chromium Authors.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 cmake_minimum_required(VERSION 3.22)
6 project(chrome_enterprise_connector_local_analysis)
8 # Ensure a C++14 compiler is used.
9 set(CMAKE_CXX_STANDARD 14)
11 # Determine the operating system being targeted.
12 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
16 elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
26 # Set the path to the protoc protobuf compiler.
28 set(PROTOC ${PROJECT_BINARY_DIR}/vcpkg/installed/x64-windows/tools/protobuf/protoc.exe)
30 set(PROTOC ${PROJECT_BINARY_DIR}/vcpkg/installed/x64-osx/tools/protobuf/protoc)
32 set(PROTOC ${PROJECT_BINARY_DIR}/vcpkg/installed/x64-linux/tools/protobuf/protoc)
35 # Calls the protoc compiler using the arguments specific to this project.
36 # protobuf_generate_cpp is not flexible enough for our needs.
38 OUTPUT ${PROJECT_BINARY_DIR}/gen/content_analysis/sdk/analysis.pb.cc
41 --cpp_out=${PROJECT_BINARY_DIR}/gen
42 --proto_path=${PROJECT_SOURCE_DIR}/proto
43 ${PROJECT_SOURCE_DIR}/proto/content_analysis/sdk/analysis.proto
44 DEPENDS ./proto/content_analysis/sdk/analysis.proto
45 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
47 # Define proto target. Compile this target exclusively by calling:
48 # `cmake --build <build_dir> --target proto`
49 add_custom_target(proto
52 ${PROJECT_BINARY_DIR}/gen/content_analysis/sdk/analysis.pb.cc
55 # The include directory contains the header files needed by the demo code.
56 # The gen directory contains generated protobuf headers describing the request
57 # and response objects used to communicate with Google Chrome.
61 ${PROJECT_BINARY_DIR}/gen
66 ${PROJECT_BINARY_DIR}/gen
69 # The SDK contains platform specific code for each of the supported platforms.
70 # ${PLATFORM_AGENT_CODE} holds the list of source files needed for the current
71 # platform being built.
73 set(PLATFORM_AGENT_CODE
74 ./agent/src/agent_utils_win.cc
75 ./agent/src/agent_utils_win.h
76 ./agent/src/agent_win.cc
77 ./agent/src/agent_win.h
78 ./agent/src/event_win.cc
79 ./agent/src/event_win.h
80 ./agent/src/scoped_print_handle_win.cc
81 ./agent/src/scoped_print_handle_win.h
85 set(PLATFORM_TEST_CODE
86 ./agent/src/agent_win_unittest.cc
87 ./agent/src/event_win_unittest.cc
90 set(PLATFORM_AGENT_CODE
91 ./agent/src/agent_mac.cc
92 ./agent/src/agent_mac.h
93 ./agent/src/event_mac.cc
94 ./agent/src/event_mac.h
95 ./agent/src/scoped_print_handle_mac.cc
96 ./agent/src/scoped_print_handle_mac.h
98 set(PLATFORM_TEST_CODE
99 ./agent/src/event_mac_unittest.cc
102 set(PLATFORM_AGENT_CODE
103 ./agent/src/agent_posix.cc
104 ./agent/src/agent_posix.h
105 ./agent/src/event_posix.cc
106 ./agent/src/event_posix.h
107 ./agent/src/scoped_print_handle_posix.cc
108 ./agent/src/scoped_print_handle_posix.h
110 set(PLATFORM_TEST_CODE
111 ./agent/src/event_posix_unittest.cc
115 # The SDK contains platform specific code for each of the supported platforms.
116 # ${PLATFORM_BROWSER_CODE} holds the list of source files needed for the current
117 # platform being built.
119 set(PLATFORM_BROWSER_CODE
120 ./browser/src/client_win.cc
121 ./browser/src/client_win.h
122 ./common/utils_win.cc
126 set(PLATFORM_BROWSER_CODE
127 ./browser/src/client_mac.cc
128 ./browser/src/client_mac.h
131 set(PLATFORM_BROWSER_CODE
132 ./browser/src/client_posix.cc
133 ./browser/src/client_posix.h
137 # Makes available the package definitions in vcpkg.
138 include("${PROJECT_BINARY_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
139 find_package(Protobuf CONFIG REQUIRED)
142 find_package(GTest CONFIG REQUIRED)
145 add_executable(unit_tests
146 ${PLATFORM_TEST_CODE}
148 set_property(TARGET unit_tests PROPERTY CXX_STANDARD 20)
149 target_include_directories(unit_tests
154 target_link_libraries(unit_tests
158 GTest::gtest GTest::gtest_main
161 gtest_discover_tests(unit_tests)
163 # Builds the content analysis connector agent linker library. This library
164 # is linked into the agent in order to listen for and process content analysis
165 # requests from Google Chrome.
166 add_library(cac_agent
167 ./agent/include/content_analysis/sdk/analysis_agent.h
168 ./agent/include/content_analysis/sdk/result_codes.h
169 ./agent/src/agent_base.cc
170 ./agent/src/agent_base.h
171 ./agent/src/event_base.cc
172 ./agent/src/event_base.h
173 ./agent/src/scoped_print_handle_base.cc
174 ./agent/src/scoped_print_handle_base.h
175 ${PLATFORM_AGENT_CODE}
176 ${PROJECT_BINARY_DIR}/gen/content_analysis/sdk/analysis.pb.cc
178 target_link_libraries(cac_agent
181 protobuf::libprotobuf
182 protobuf::libprotobuf-lite)
183 target_include_directories(cac_agent PRIVATE ${AGENT_INCLUDES})
184 # Builds the content analysis connector browser linker library. This library
185 # is linked into the client in order to send content analysis requests to the
187 add_library(cac_browser
188 ./browser/include/content_analysis/sdk/analysis_client.h
189 ./browser/src/client_base.cc
190 ./browser/src/client_base.h
191 ${PLATFORM_BROWSER_CODE}
192 ${PROJECT_BINARY_DIR}/gen/content_analysis/sdk/analysis.pb.cc
194 target_include_directories(cac_browser PRIVATE ${BROWSER_INCLUDES})
195 target_link_libraries(cac_browser
198 protobuf::libprotobuf
199 protobuf::libprotobuf-lite)
201 # The demo agent executable.
206 target_compile_features(agent PRIVATE cxx_std_17)
207 target_include_directories(agent PRIVATE ${AGENT_INCLUDES})
208 target_link_libraries(agent PRIVATE cac_agent)
210 # The demo client executable.
211 add_executable(browser ./demo/client.cc)
212 target_include_directories(browser PRIVATE ${BROWSER_INCLUDES})
213 target_link_libraries(browser PRIVATE cac_browser)