Repository: conan-io/conan-center-index

Issue:
Perfetto/20.1
### Package Details
  * Package Name/Version: **perfetto/20.1**
  * Website: **https://perfetto.dev/**
  * Source code: **https://android.googlesource.com/platform/external/perfetto**


### Description Of The Library / Tool
Perfetto - System profiling, app tracing and trace analysis

Perfetto is a production-grade open-source stack for performance instrumentation and trace analysis. It offers services and libraries and for recording system-level and app-level traces, native + java heap profiling, a library for analyzing traces using SQL and a web-based UI to visualize and explore multi-GB traces.


Discussion:

Resolving patch:
diff --git a/recipes/perfetto/all/conanfile.py b/recipes/perfetto/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/perfetto/all/conanfile.py
@@ -0,0 +1,76 @@
+from conans import ConanFile, CMake, tools
+from conans.errors import ConanInvalidConfiguration
+
+import os
+
+required_conan_version = ">=1.33.0"
+
+
+class PerfettoConan(ConanFile):
+    name = "perfetto"
+    license = "Apache-2.0"
+    homepage = "https://perfetto.dev"
+    url = "https://github.com/conan-io/conan-center-index"
+    description = "Performance instrumentation and tracing for Android, Linux and Chrome"
+    topics = ("linux", "profiling", "tracing")
+    settings = "os", "compiler", "build_type", "arch"
+    options = {
+            "shared": [True, False],
+            "fPIC": [True, False]
+    }
+    default_options = {
+            "shared": False,
+            "fPIC": True
+    }
+
+    exports_sources = ["CMakeLists.txt"]
+    generators = "cmake"
+
+    _cmake = None
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        if self.options.shared:
+            del self.options.fPIC
+
+    def validate(self):
+        if self.settings.compiler == "gcc" and tools.Version(self.settings.compiler.version) < 7:
+            raise ConanInvalidConfiguration ("perfetto requires gcc >= 7")
+        if self.settings.compiler.cppstd:
+            tools.check_min_cppstd(self, 11)
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version],
+               strip_root=True, destination=self._source_subfolder)
+
+    def _configure_cmake(self):
+        if self._cmake:
+            return self._cmake
+        self._cmake = CMake(self)
+        self._cmake.configure()
+        return self._cmake
+
+    def build(self):
+        cmake = self._configure_cmake()
+        cmake.build()
+
+    def package(self):
+        self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
+        cmake = self._configure_cmake()
+        cmake.install()
+
+    def package_info(self):
+        self.cpp_info.libs = ["perfetto"]
+        self.cpp_info.names["pkgconfig"] = "perfetto"
+        if self.settings.os == "Linux":
+            self.cpp_info.system_libs.append("pthread")
+        if self.settings.os == "Windows":
+            self.cpp_info.system_libs.append("ws2_32")
+


Test patch:
diff --git a/recipes/perfetto/all/test_package/CMakeLists.txt b/recipes/perfetto/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/perfetto/all/test_package/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required(VERSION 3.4)
+project(test_package CXX)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup(TARGETS)
+
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+find_package(perfetto REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test_package.cpp)
+target_link_libraries(${PROJECT_NAME} perfetto::perfetto)
diff --git a/recipes/perfetto/all/test_package/conanfile.py b/recipes/perfetto/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/perfetto/all/test_package/conanfile.py
@@ -0,0 +1,18 @@
+import os
+
+from conans import ConanFile, CMake, tools
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "arch", "compiler", "build_type"
+    generators = "cmake", "cmake_find_package_multi"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not tools.cross_building(self):
+            bin_path = os.path.join("bin", "test_package")
+            self.run(bin_path, run_environment=True)
diff --git a/recipes/perfetto/all/test_package/test_package.cpp b/recipes/perfetto/all/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/perfetto/all/test_package/test_package.cpp
@@ -0,0 +1,19 @@
+#include <perfetto.h>
+
+int main(int argv, char** argc) {
+  perfetto::TracingInitArgs args;
+
+  // The backends determine where trace events are recorded. You may select one
+  // or more of:
+
+  // 1) The in-process backend only records within the app itself.
+  args.backends |= perfetto::kInProcessBackend;
+
+  // 2) The system backend writes events into a system Perfetto daemon,
+  //    allowing merging app and system events (e.g., ftrace) on the same
+  //    timeline. Requires the Perfetto `traced` daemon to be running (e.g.,
+  //    on Android Pie and newer).
+  args.backends |= perfetto::kSystemBackend;
+
+  perfetto::Tracing::Initialize(args);
+}