File: FindPercetto.cmake

package info (click to toggle)
freespace2 25.0.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 47,232 kB
  • sloc: cpp: 657,500; ansic: 22,305; sh: 293; python: 200; makefile: 198; xml: 181
file content (126 lines) | stat: -rw-r--r-- 3,819 bytes parent folder | download | duplicates (3)
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
# Copyright 2021-2022, Collabora, Ltd.
#
# SPDX-License-Identifier: BSL-1.0
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# Original Author:
# 2021-2022 Rylie Pavlik <rylie.pavlik@collabora.com> <rylie@ryliepavlik.com>

#[[.rst:
FindPercetto
---------------

Find the Percetto C wrapper around the Perfetto tracing API.

Targets
^^^^^^^

If successful, the following imported targets are created.

* ``percetto::percetto``

Cache variables
^^^^^^^^^^^^^^^

The following cache variable may also be set to assist/control the operation of this module:

``Percetto_ROOT_DIR``
 The root to search for Percetto.
#]]

set(Percetto_ROOT_DIR
    "${Percetto_ROOT_DIR}"
    CACHE PATH "Root to search for Percetto")

include(FeatureSummary)
set_package_properties(
    Percetto PROPERTIES
    URL "https://github.com/olvaffe/percetto/"
    DESCRIPTION "A C wrapper around the C++ Perfetto tracing SDK.")

include(FindPackageHandleStandardArgs)

# See if it's being built in a current project.
if(NOT Percetto_FOUND)
    if(TARGET percetto::percetto)
        # OK, good - this is what we wanted
    elseif(TARGET Percetto::percetto)
        # we now prefer lowercase
        add_library(percetto::percetto INTERFACE IMPORTED)
        set_target_properties(
            percetto::percetto PROPERTIES INTERFACE_LINK_LIBRARIES
                                          Percetto::percetto)
    endif()

    if(TARGET percetto::percetto)
        set(Percetto_LIBRARY percetto::percetto)
        find_package_handle_standard_args(Percetto
                                          REQUIRED_VARS Percetto_LIBRARY)
        return()
    endif()
endif()

# See if we can find something made by android prefab (gradle), or exported by CMake
find_package(Percetto QUIET CONFIG NAMES percetto Percetto)
if(Percetto_FOUND)
    find_package_handle_standard_args(Percetto CONFIG_MODE)
    if(TARGET percetto::percetto)
        # OK, good - this is what we wanted
    elseif(TARGET Percetto::percetto)
        # we now prefer lowercase
        add_library(percetto::percetto INTERFACE IMPORTED)
        set_target_properties(
            percetto::percetto PROPERTIES INTERFACE_LINK_LIBRARIES
                                          Percetto::percetto)
    else()
        message(FATAL_ERROR "assumptions failed")
    endif()
    return()
endif()

if(NOT ANDROID)
    find_package(PkgConfig QUIET)
    if(PKG_CONFIG_FOUND)
        set(_old_prefix_path "${CMAKE_PREFIX_PATH}")
        # So pkg-config uses Percetto_ROOT_DIR too.
        if(Percetto_ROOT_DIR)
            list(APPEND CMAKE_PREFIX_PATH ${Percetto_ROOT_DIR})
        endif()
        pkg_check_modules(PC_percetto QUIET percetto)
        # Restore
        set(CMAKE_PREFIX_PATH "${_old_prefix_path}")
    endif()
endif()

find_path(
    Percetto_INCLUDE_DIR
    NAMES percetto.h
    PATHS ${Percetto_ROOT_DIR}
    HINTS ${PC_percetto_INCLUDE_DIRS}
    PATH_SUFFIXES include)

find_library(
    Percetto_LIBRARY
    NAMES percetto
    PATHS ${Percetto_ROOT_DIR}
    HINTS ${PC_percetto_LIBRARY_DIRS}
    PATH_SUFFIXES lib)

find_package_handle_standard_args(Percetto REQUIRED_VARS Percetto_INCLUDE_DIR
                                                         Percetto_LIBRARY)
if(Percetto_FOUND)
    if(NOT TARGET percetto::percetto)
        add_library(percetto::percetto UNKNOWN IMPORTED)

        set_target_properties(
            percetto::percetto
            PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Percetto_INCLUDE_DIR}"
                       IMPORTED_LINK_INTERFACE_LANGUAGES "C"
                       IMPORTED_LOCATION ${Percetto_LIBRARY})
    endif()
    mark_as_advanced(Percetto_LIBRARY Percetto_INCLUDE_DIR)
endif()
mark_as_advanced(Percetto_ROOT_DIR)