Skip to content

Commit

Permalink
(#14155) tracy: add 0.9 + conan v2 support + fix cmake names
Browse files Browse the repository at this point in the history
* fix cmake names

* conan v2 support

* add tracy/0.9
  • Loading branch information
SpaceIm authored Nov 26, 2022
1 parent e7232c0 commit 62f515b
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 57 deletions.
7 changes: 0 additions & 7 deletions recipes/tracy/all/CMakeLists.txt

This file was deleted.

3 changes: 3 additions & 0 deletions recipes/tracy/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"0.9":
url: "https://github.com/wolfpld/tracy/archive/refs/tags/v0.9.tar.gz"
sha256: "93a91544e3d88f3bc4c405bad3dbc916ba951cdaadd5fcec1139af6fa56e6bfc"
"0.8.2.1":
url: "https://github.com/wolfpld/tracy/archive/v0.8.2.1.tar.gz"
sha256: "97f478579efa1f5ce4c8619014a20327010fea122c21248701fe2bbb46ec1c1f"
Expand Down
78 changes: 42 additions & 36 deletions recipes/tracy/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rmdir
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.53.0"


class TracyConan(ConanFile):
Expand All @@ -11,7 +14,7 @@ class TracyConan(ConanFile):
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"
settings = "os", "arch", "compiler", "build_type"

# Existing CMake tracy options with default value
_tracy_options = {
Expand All @@ -38,58 +41,61 @@ class TracyConan(ConanFile):
**{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
self.options.rm_safe("fPIC")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
def layout(self):
cmake_layout(self, src_folder="src")

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
def validate(self):
if self.info.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)

def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(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
opt = f"TRACY_{opt.upper()}"
tc.variables[opt] = switch
tc.generate()

def build(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
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"))
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.libs = ["TracyClient"]
self.cpp_info.set_property("cmake_file_name", "Tracy")
self.cpp_info.set_property("cmake_target_name", "Tracy::TracyClient")
# TODO: back to global scope in conan v2
self.cpp_info.components["tracyclient"].libs = ["TracyClient"]
if self.options.shared:
self.cpp_info.components["tracyclient"].defines.append("TRACY_IMPORTS")
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("pthread")
self.cpp_info.components["tracyclient"].system_libs.append("pthread")
if self.settings.os == "Linux":
self.cpp_info.system_libs.append("dl")
self.cpp_info.components["tracyclient"].system_libs.append("dl")

# TODO: to remove in conan v2
self.cpp_info.names["cmake_find_package"] = "Tracy"
self.cpp_info.names["cmake_find_package_multi"] = "Tracy"
self.cpp_info.components["tracyclient"].names["cmake_find_package"] = "TracyClient"
self.cpp_info.components["tracyclient"].names["cmake_find_package_multi"] = "TracyClient"
self.cpp_info.components["tracyclient"].set_property("cmake_target_name", "Tracy::TracyClient")
17 changes: 9 additions & 8 deletions recipes/tracy/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
find_package(Tracy REQUIRED CONFIG)

find_package(tracy REQUIRED)

add_executable(test_package example.cpp)
target_link_libraries(test_package tracy::tracy)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE Tracy::TracyClient)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
if(Tracy_VERSION VERSION_GREATER_EQUAL "0.9")
target_compile_definitions(${PROJECT_NAME} PRIVATE TRACY_GE_0_9)
endif()
21 changes: 15 additions & 6 deletions recipes/tracy/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

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)
if not cross_building(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef TRACY_GE_0_9
#include <tracy/Tracy.hpp>
#else
#include <Tracy.hpp>
#endif

int main(int argc, char **argv) {
ZoneScopedN("main")
Expand Down
8 changes: 8 additions & 0 deletions recipes/tracy/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
17 changes: 17 additions & 0 deletions recipes/tracy/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


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)
2 changes: 2 additions & 0 deletions recipes/tracy/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"0.9":
folder: all
"0.8.2.1":
folder: all
"0.8.1":
Expand Down

0 comments on commit 62f515b

Please sign in to comment.