Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

easy_profiler: fix cross-build to iOS + fix CMake imported target + modernize #6244

Merged
merged 9 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/easy_profiler/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ sources:
"2.1.0":
url: "https://github.com/yse/easy_profiler/archive/v2.1.0.tar.gz"
sha256: "fabf95d59ede9da4873aebd52ef8a762fa8578dcdbcc6d7cdd811b5a7c3367ad"
patches:
"2.1.0":
- patch_file: "patches/0001-fix-cmake-bundle-install.patch"
base_path: "source_subfolder"
67 changes: 55 additions & 12 deletions recipes/easy_profiler/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from conans import ConanFile, tools, CMake
from conans.errors import ConanInvalidConfiguration
import os
import glob
import textwrap

required_conan_version = ">=1.33.0"


class EasyProfilerConan(ConanFile):
Expand All @@ -21,7 +24,6 @@ class EasyProfilerConan(ConanFile):
"shared": False,
"fPIC": True
}
short_paths = True

_cmake = None

Expand All @@ -41,13 +43,21 @@ def configure(self):
if self.options.shared:
del self.options.fPIC

def validate(self):
if self.settings.compiler == "Visual Studio" and self.settings.compiler.runtime == "MTd" and \
self.options.shared and tools.Version(self.settings.compiler.version) >= "15":
raise ConanInvalidConfiguration(
"{} {} with MTd runtime not supported".format(self.settings.compiler,
self.settings.compiler.version)
)

def source(self):
tools.get(**self.conan_data["sources"][self.version])
url = self.conan_data["sources"][self.version]["url"]
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

Expand All @@ -57,6 +67,7 @@ def _configure_cmake(self):
self._cmake = CMake(self)
# Don't build the GUI because it is dependent on Qt
self._cmake.definitions["EASY_PROFILER_NO_GUI"] = True
self._cmake.definitions["EASY_PROFILER_NO_SAMPLES"] = True
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

Expand All @@ -70,17 +81,49 @@ def package(self):
os.remove(os.path.join(self.package_folder, "LICENSE.MIT"))
os.remove(os.path.join(self.package_folder, "LICENSE.APACHE"))
if self.settings.os == "Windows":
for dll_file in \
glob.glob(os.path.join(self.package_folder, "bin", "*.dll")):
if os.path.basename(dll_file).startswith(("concrt", "msvcp",
"vcruntime")):
os.remove(dll_file)
for dll_prefix in ["concrt", "msvcp", "vcruntime"]:
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"),
"{}*.dll".format(dll_prefix))
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{"easy_profiler": "easy_profiler::easy_profiler"}
)

@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
tools.save(module_file, content)

@property
def _module_subfolder(self):
return os.path.join("lib", "cmake")

@property
def _module_file_rel_path(self):
return os.path.join(self._module_subfolder,
"conan-official-{}-targets.cmake".format(self.name))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "easy_profiler"
self.cpp_info.names["cmake_find_package_multi"] = "easy_profiler"
self.cpp_info.builddirs.append(self._module_subfolder)
self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.libs = ["easy_profiler"]
if self.settings.os == "Linux":
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m", "pthread"]
elif self.settings.os == "Windows":
self.cpp_info.system_libs = ["psapi", "ws2_32"]
if not self.options.shared:
self.cpp_info.defines.append("EASY_PROFILER_STATIC")

bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/easy_profiler_converter/CMakeLists.txt
+++ b/easy_profiler_converter/CMakeLists.txt
@@ -15,7 +15,6 @@ target_link_libraries(profiler_converter easy_profiler)
install(
TARGETS
profiler_converter
- RUNTIME
DESTINATION
bin
)
6 changes: 4 additions & 2 deletions recipes/easy_profiler/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 3.1)
project(test_package)

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

find_package(easy_profiler REQUIRED CONFIG)

add_executable(${PROJECT_NAME} example.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} easy_profiler)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
2 changes: 1 addition & 1 deletion recipes/easy_profiler/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

def build(self):
cmake = CMake(self)
Expand Down