Repository: conan-io/conan-center-index

Issue:
[request] tracy/0.6.3
### Package Details
  * Package Name/Version: **tracy/v0.6.3**
  * Website: **https://github.com/wolfpld/tracy**
  * Source code: **https://github.com/wolfpld/tracy**


### Description Of The Library / Tool

A real time, nanosecond resolution, remote telemetry frame profiler for games and other applications






Discussion:
Note tracy includes multiple tools, mainly the client libraries and the profiler server gui.

In my Tracy fork I already have a working cmake and Conan recipes for the client libraries, but I would like to package the exec tools as well. This requires some deps (the client libs have no deps iirc). From the top of my head, the Linux deps needed to build the gui are:

 - opengl (mesa, x11, etc)
 - glfw 3.3
 - gtk 2.0
 - capstone
 - freetype 6

Another option would be to package them separately (to avoid dep issues in target toolchains that just need the client libs). This is what I did with my recipe.
BTW we technically do not need to add cmake support to be able to package Tracy, it already includes build scripts for the profiler server (makefiles for linux/mac, and a vs solution for windows) so what we could do is to just generate build scripts on the fly for the client, and use the existing scripts for the server.
Are you still interested in this ?

I definitely am, but the build system of Tracy being what it is, I'm not confident enough to package it myself.
It would be very nice to be able to depend on Tracy via conan, providing the lib to integrate inside client code and the viewer program already built.

Resolving patch:
diff --git a/recipes/tracy/all/conanfile.py b/recipes/tracy/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/tracy/all/conanfile.py
@@ -0,0 +1,95 @@
+from conans import ConanFile, CMake, tools
+import os
+
+required_conan_version = ">=1.43.0"
+
+
+class TracyConan(ConanFile):
+    name = "tracy"
+    description = "C++ frame profiler"
+    topics = ("profiler", "performance", "gamedev")
+    homepage = "https://github.com/wolfpld/tracy"
+    url = "https://github.com/conan-io/conan-center-index"
+    license = ["BSD-3-Clause"]
+    settings = "os", "compiler", "build_type", "arch"
+
+    # Existing CMake tracy options with default value
+    _tracy_options = {
+        "enable": ([True, False], True),
+        "callstack": ([True, False], False),
+        "only_localhost": ([True, False], False),
+        "no_broadcast": ([True, False], False),
+        "no_code_transfer": ([True, False], False),
+        "no_context_switch": ([True, False], False),
+        "no_exit": ([True, False], False),
+        "no_frame_image": ([True, False], False),
+        "no_sampling": ([True, False], False),
+        "no_verify": ([True, False], False),
+        "no_vsync_capture": ([True, False], False),
+    }
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+        **{k: v[0] for k, v in _tracy_options.items()},
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+        **{k: v[1] for k, v in _tracy_options.items()},
+    }
+
+    exports_sources = ["CMakeLists.txt"]
+    generators = "cmake"
+    _cmake = None
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    def validate(self):
+        if self.settings.compiler.get_safe("cppstd"):
+            tools.check_min_cppstd(self, 11)
+
+    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 source(self):
+        tools.get(**self.conan_data["sources"][self.version],
+                  destination=self._source_subfolder, strip_root=True)
+
+    def _configure_cmake(self):
+        if self._cmake:
+            return self._cmake
+        self._cmake = CMake(self)
+
+        # Set all tracy options in the correct form
+        # For example, TRACY_NO_EXIT
+        for opt in self._tracy_options.keys():
+            switch = getattr(self.options, opt)
+            opt = 'TRACY_' + opt.upper()
+            self._cmake.definitions[opt] = switch
+
+        self._cmake.configure()
+        return self._cmake
+
+    def build(self):
+        cmake = self._configure_cmake()
+        cmake.build()
+
+    def package(self):
+        self.copy(pattern="LICENSE", dst="licenses",
+                  src=self._source_subfolder)
+        self._cmake.install()
+        tools.rmdir(os.path.join(self.package_folder, "share"))
+
+    def package_info(self):
+        self.cpp_info.libs = ["TracyClient"]
+        if self.settings.os in ["Linux", "FreeBSD"]:
+            self.cpp_info.system_libs.append("pthread")
+        if self.settings.os == "Linux":
+            self.cpp_info.system_libs.append("dl")


Test patch:
diff --git a/recipes/tracy/all/test_package/CMakeLists.txt b/recipes/tracy/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/tracy/all/test_package/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup(TARGETS)
+
+find_package(tracy REQUIRED)
+
+add_executable(test_package example.cpp)
+target_link_libraries(test_package tracy::tracy)
diff --git a/recipes/tracy/all/test_package/conanfile.py b/recipes/tracy/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/tracy/all/test_package/conanfile.py
@@ -0,0 +1,16 @@
+from conans import ConanFile, CMake, tools
+import os
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    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/tracy/all/test_package/example.cpp b/recipes/tracy/all/test_package/example.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/tracy/all/test_package/example.cpp
@@ -0,0 +1,7 @@
+#include <Tracy.hpp>
+
+int main(int argc, char **argv) {
+  ZoneScopedN("main")
+
+  return 0;
+}