• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 11)
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)
34
35target_link_libraries(example perfetto
36                      ${CMAKE_THREAD_LIBS_INIT})
37target_link_libraries(example_system_wide perfetto
38                      ${CMAKE_THREAD_LIBS_INIT})
39target_link_libraries(example_custom_data_source perfetto
40                      ${CMAKE_THREAD_LIBS_INIT})
41target_link_libraries(example_console perfetto
42                      ${CMAKE_THREAD_LIBS_INIT})
43
44# On Android we also need the logging library.
45if (ANDROID)
46  target_link_libraries(example log)
47  target_link_libraries(example_system_wide log)
48  target_link_libraries(example_custom_data_source log)
49  target_link_libraries(example_console log)
50endif (ANDROID)
51
52if (WIN32)
53  # The perfetto library contains many symbols, so it needs the big object
54  # format.
55  target_compile_options(perfetto PRIVATE "/bigobj")
56  # Disable legacy features in windows.h.
57  add_definitions(-DWIN32_LEAN_AND_MEAN -DNOMINMAX)
58  # On Windows we should link to WinSock2.
59  target_link_libraries(example ws2_32)
60  target_link_libraries(example_system_wide ws2_32)
61  target_link_libraries(example_custom_data_source ws2_32)
62  target_link_libraries(example_console ws2_32)
63endif (WIN32)
64
65# Enable standards-compliant mode when using the Visual Studio compiler.
66if (MSVC)
67  target_compile_options(example PRIVATE "/permissive-")
68  target_compile_options(example_system_wide PRIVATE "/permissive-")
69  target_compile_options(example_custom_data_source PRIVATE "/permissive-")
70  target_compile_options(example_console PRIVATE "/permissive-")
71endif (MSVC)