xref: /aosp_15_r20/external/perfetto/examples/sdk/CMakeLists.txt (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1# Copyright (C) 2020 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15cmake_minimum_required(VERSION 3.13)
16project(perfetto-sdk-example)
17
18set(CMAKE_CXX_STANDARD 17)
19set(CMAKE_CXX_STANDARD_REQUIRED ON)
20
21find_package(Threads)
22
23# Define a static library for Perfetto. In this example, we expect the SDK
24# (perfetto.cc and perfetto.h) to live in the top level sdk/ directory.
25include_directories(../../sdk)
26add_library(perfetto STATIC ../../sdk/perfetto.cc)
27
28# Link the library to the main executables.
29add_executable(example example.cc trace_categories.cc)
30add_executable(example_system_wide example_system_wide.cc
31               trace_categories.cc)
32add_executable(example_custom_data_source example_custom_data_source.cc)
33add_executable(example_console example_console.cc trace_categories.cc)
34add_executable(example_startup_trace example_startup_trace.cc)
35
36target_link_libraries(example perfetto
37                      ${CMAKE_THREAD_LIBS_INIT})
38target_link_libraries(example_system_wide perfetto
39                      ${CMAKE_THREAD_LIBS_INIT})
40target_link_libraries(example_custom_data_source perfetto
41                      ${CMAKE_THREAD_LIBS_INIT})
42target_link_libraries(example_console perfetto
43                      ${CMAKE_THREAD_LIBS_INIT})
44target_link_libraries(example_startup_trace perfetto
45                      ${CMAKE_THREAD_LIBS_INIT})
46
47# On Android we also need the logging library.
48if (ANDROID)
49  target_link_libraries(example log)
50  target_link_libraries(example_system_wide log)
51  target_link_libraries(example_custom_data_source log)
52  target_link_libraries(example_console log)
53  target_link_libraries(example_startup_trace log)
54endif (ANDROID)
55
56if (WIN32)
57  # The perfetto library contains many symbols, so it needs the big object
58  # format.
59  target_compile_options(perfetto PRIVATE "/bigobj")
60  # Disable legacy features in windows.h.
61  add_definitions(-DWIN32_LEAN_AND_MEAN -DNOMINMAX)
62  # On Windows we should link to WinSock2.
63  target_link_libraries(example ws2_32)
64  target_link_libraries(example_system_wide ws2_32)
65  target_link_libraries(example_custom_data_source ws2_32)
66  target_link_libraries(example_console ws2_32)
67  target_link_libraries(example_startup_trace ws2_32)
68endif (WIN32)
69
70# Enable standards-compliant mode when using the Visual Studio compiler.
71if (MSVC)
72  target_compile_options(example PRIVATE "/permissive-")
73  target_compile_options(example_system_wide PRIVATE "/permissive-")
74  target_compile_options(example_custom_data_source PRIVATE "/permissive-")
75  target_compile_options(example_console PRIVATE "/permissive-")
76  target_compile_options(example_startup_trace PRIVATE "/permissive-")
77endif (MSVC)
78