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

tgbot: migrate to Conan v2 #18792

Merged
merged 7 commits into from
Nov 14, 2023
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
7 changes: 0 additions & 7 deletions recipes/tgbot/all/CMakeLists.txt

This file was deleted.

6 changes: 0 additions & 6 deletions recipes/tgbot/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,3 @@ sources:
"1.3":
url: "https://github.com/reo7sp/tgbot-cpp/archive/v1.3.tar.gz"
sha256: "85b9aef49c595d39fc9dc330b1b83625bea9509966dc623f7b4c1ee7309679c9"
"1.2.1":
url: "https://github.com/reo7sp/tgbot-cpp/archive/v1.2.1.tar.gz"
sha256: "bcc82cc8c421e96098ba6ef350acc0c1ce9fbbc21a11b91eb8643324757d09f2"
"1.2":
url: "https://github.com/reo7sp/tgbot-cpp/archive/v1.2.tar.gz"
sha256: "6d5158db38fb092e12060080a611ccdccde35cfb85f030996daee9619bebc513"
92 changes: 51 additions & 41 deletions recipes/tgbot/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, replace_in_file

required_conan_version = ">=1.53.0"


class TgbotConan(ConanFile):
name = "tgbot"

url = "https://github.com/conan-io/conan-center-index"
homepage = "http://reo7sp.github.io/tgbot-cpp"
description = "C++ library for Telegram bot API"
topics = ("tgbot", "telegram", "telegram-api", "telegram-bot", "bot")
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://reo7sp.github.io/tgbot-cpp"
topics = ("telegram", "telegram-api", "telegram-bot", "bot")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -24,69 +29,74 @@ class TgbotConan(ConanFile):
"fPIC": True,
}

generators = "cmake", "cmake_find_package"
exports_sources = ["CMakeLists.txt"]

_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
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("boost/1.79.0")
self.requires("libcurl/7.84.0")
self.requires("openssl/1.1.1q")
# tgbot/Api.h:#include <boost/property_tree/ptree.hpp>
self.requires("boost/1.83.0", transitive_headers=True, transitive_libs=True)
valgur marked this conversation as resolved.
Show resolved Hide resolved
# tgbot/net/CurlHttpClient.h:#include <curl/curl.h>
self.requires("libcurl/[>=7.78 <9]", transitive_headers=True, transitive_libs=True)
valgur marked this conversation as resolved.
Show resolved Hide resolved
self.requires("openssl/[>=1.1 <4]")

@property
def _required_boost_components(self):
return ["system"]

def validate(self):
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)
miss_boost_required_comp = any(getattr(self.options["boost"], "without_{}".format(boost_comp), True) for boost_comp in self._required_boost_components)
if self.options["boost"].header_only or miss_boost_required_comp:
raise ConanInvalidConfiguration("{0} requires non header-only boost with these components: {1}".format(self.name, ", ".join(self._required_boost_components)))
check_min_cppstd(self, 11)
miss_boost_required_comp = any(
self.dependencies["boost"].options.get_safe(f"without_{boost_comp}", True)
for boost_comp in self._required_boost_components
)
if self.dependencies["boost"].options.header_only or miss_boost_required_comp:
raise ConanInvalidConfiguration(
f"{self.name} requires non header-only boost with these components: "
+ ", ".join(self._required_boost_components)
)

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ENABLE_TESTS"] = False
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def _patch_sources(self):
# Don't force PIC
tools.replace_in_file(
os.path.join(self._source_subfolder, "CMakeLists.txt"),
replace_in_file(
self,
os.path.join(self.source_folder, "CMakeLists.txt"),
"set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)",
""
"",
)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["ENABLE_TESTS"] = False
self._cmake.configure()
return self._cmake

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.install()
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
copy(self, "LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder)
fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.libs = ["TgBot"]
valgur marked this conversation as resolved.
Show resolved Hide resolved
self.cpp_info.requires = ["boost::headers", "boost::system", "libcurl::libcurl", "openssl::openssl"]
self.cpp_info.defines = ["HAVE_CURL=1"]
7 changes: 2 additions & 5 deletions recipes/tgbot/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

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

find_package(tgbot REQUIRED)
find_package(tgbot REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
Expand Down
20 changes: 15 additions & 5 deletions recipes/tgbot/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os
from conans import ConanFile, CMake, tools


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

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):
self.run(os.path.join("bin", "test_package"), run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/tgbot/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.15)
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/)
16 changes: 16 additions & 0 deletions recipes/tgbot/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
from conans import ConanFile, CMake, tools


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

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
self.run(os.path.join("bin", "test_package"), run_environment=True)
4 changes: 0 additions & 4 deletions recipes/tgbot/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ versions:
folder: all
"1.3":
folder: all
"1.2.1":
folder: all
"1.2":
folder: all