From 7fdf58091d5c81be1f1c850ffa4ce7e3fbadaf0c Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 26 May 2024 20:38:51 +0300 Subject: [PATCH 1/4] sioclient: new recipe --- recipes/sioclient/all/conandata.yml | 4 + recipes/sioclient/all/conanfile.py | 113 ++++++++++++++++++ .../sioclient/all/test_package/CMakeLists.txt | 8 ++ .../sioclient/all/test_package/conanfile.py | 26 ++++ .../all/test_package/test_package.cpp | 6 + recipes/sioclient/config.yml | 3 + 6 files changed, 160 insertions(+) create mode 100644 recipes/sioclient/all/conandata.yml create mode 100644 recipes/sioclient/all/conanfile.py create mode 100644 recipes/sioclient/all/test_package/CMakeLists.txt create mode 100644 recipes/sioclient/all/test_package/conanfile.py create mode 100644 recipes/sioclient/all/test_package/test_package.cpp create mode 100644 recipes/sioclient/config.yml diff --git a/recipes/sioclient/all/conandata.yml b/recipes/sioclient/all/conandata.yml new file mode 100644 index 0000000000000..ae83b98849ee1 --- /dev/null +++ b/recipes/sioclient/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "cci.20240405": + url: "https://github.com/socketio/socket.io-client-cpp/archive/c6be96b226f0fe3853beaeaa99c06834342a78db.zip" + sha256: "7c68117185dbc49579bba09a3e877f2a716cc331c28b3d8b6d3f867c4346b639" diff --git a/recipes/sioclient/all/conanfile.py b/recipes/sioclient/all/conanfile.py new file mode 100644 index 0000000000000..3e3fc4124d561 --- /dev/null +++ b/recipes/sioclient/all/conanfile.py @@ -0,0 +1,113 @@ +import os + +from conan import ConanFile +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.env import VirtualBuildEnv +from conan.tools.files import copy, get, replace_in_file, rm, rmdir, save + +required_conan_version = ">=1.53.0" + + +class SioclientConan(ConanFile): + name = "sioclient" + description = "C++11 implementation of Socket.IO client" + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/socketio/socket.io-client-cpp" + topics = ("websocket", "client") + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_openssl": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "with_openssl": True, + } + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + self.requires("websocketpp/0.8.2") + self.requires("asio/1.30.2") + self.requires("rapidjson/cci.20230929") + if self.options.with_openssl: + self.requires("openssl/[>=1.1 <4]") + + def validate(self): + if self.settings.compiler.cppstd: + check_min_cppstd(self, 11) + + def build_requirements(self): + # 3.28+ is not supported + self.tool_requires("cmake/[>=3.12 <=3.27]") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["USE_SUBMODULES"] = False + tc.generate() + + deps = CMakeDeps(self) + deps.generate() + + VirtualBuildEnv(self).generate() + + def _patch_sources(self): + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), + "asio asio::asio", "asio::asio") + save(self, os.path.join(self.source_folder, "test", "CMakeLists.txt"), "") + + def build(self): + self._patch_sources() + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rm(self, "*.pdb", self.package_folder, recursive=True) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "sioclient") + + self.cpp_info.components["sioclient_"].set_property("cmake_target_name", "sioclient::sioclient") + self.cpp_info.components["sioclient_"].libs = ["sioclient"] + self.cpp_info.components["sioclient_"].requires = [ + "websocketpp::websocketpp", + "asio::asio", + "rapidjson::rapidjson", + ] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["sioclient_"].system_libs.extend(["m", "pthread"]) + + if self.options.with_openssl: + self.cpp_info.components["sioclient_tls"].set_property("cmake_target_name", "sioclient::sioclient_tls") + self.cpp_info.components["sioclient_tls"].libs = ["sioclient_tls"] + self.cpp_info.components["sioclient_tls"].requires = [ + "websocketpp::websocketpp", + "asio::asio", + "rapidjson::rapidjson", + "openssl::openssl", + ] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["sioclient_tls"].system_libs.extend(["m", "pthread"]) diff --git a/recipes/sioclient/all/test_package/CMakeLists.txt b/recipes/sioclient/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..4985d53cb13ca --- /dev/null +++ b/recipes/sioclient/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(sioclient REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE sioclient::sioclient) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/sioclient/all/test_package/conanfile.py b/recipes/sioclient/all/test_package/conanfile.py new file mode 100644 index 0000000000000..3a91c9439218e --- /dev/null +++ b/recipes/sioclient/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/sioclient/all/test_package/test_package.cpp b/recipes/sioclient/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..646e232b2bda0 --- /dev/null +++ b/recipes/sioclient/all/test_package/test_package.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + sio::client h; + h.socket(); +} diff --git a/recipes/sioclient/config.yml b/recipes/sioclient/config.yml new file mode 100644 index 0000000000000..f1cb71fea7cad --- /dev/null +++ b/recipes/sioclient/config.yml @@ -0,0 +1,3 @@ +versions: + "cci.20240405": + folder: all From c74b837639ed657c762618b2c205c67bc637bbad Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 26 May 2024 21:56:31 +0300 Subject: [PATCH 2/4] sioclient: Windows shared builds are not supported --- recipes/sioclient/all/conanfile.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/recipes/sioclient/all/conanfile.py b/recipes/sioclient/all/conanfile.py index 3e3fc4124d561..cf68a231f53f8 100644 --- a/recipes/sioclient/all/conanfile.py +++ b/recipes/sioclient/all/conanfile.py @@ -1,6 +1,7 @@ import os from conan import ConanFile +from conan.errors import ConanInvalidConfiguration from conan.tools.build import check_min_cppstd from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout from conan.tools.env import VirtualBuildEnv @@ -51,6 +52,8 @@ def requirements(self): def validate(self): if self.settings.compiler.cppstd: check_min_cppstd(self, 11) + if self.settings.os == "Windows": + raise ConanInvalidConfiguration("Shared builds on Windows are not supported") def build_requirements(self): # 3.28+ is not supported From 797ed84b64bf921751e3f6bc0a5e49770d7f01ff Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 27 May 2024 15:42:11 +0300 Subject: [PATCH 3/4] sioclient: require CMake 3.15+ --- recipes/sioclient/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/sioclient/all/conanfile.py b/recipes/sioclient/all/conanfile.py index cf68a231f53f8..81ad8ad067db7 100644 --- a/recipes/sioclient/all/conanfile.py +++ b/recipes/sioclient/all/conanfile.py @@ -57,7 +57,7 @@ def validate(self): def build_requirements(self): # 3.28+ is not supported - self.tool_requires("cmake/[>=3.12 <=3.27]") + self.tool_requires("cmake/[>=3.15 <=3.27]") def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) From 5ca57fc29af19dd64a1d74d1de2ce5b3e001503b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n=20Blanco?= Date: Tue, 28 May 2024 15:20:37 +0200 Subject: [PATCH 4/4] Update recipes/sioclient/all/conanfile.py --- recipes/sioclient/all/conanfile.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/recipes/sioclient/all/conanfile.py b/recipes/sioclient/all/conanfile.py index 81ad8ad067db7..4af93cba3d64c 100644 --- a/recipes/sioclient/all/conanfile.py +++ b/recipes/sioclient/all/conanfile.py @@ -55,10 +55,6 @@ def validate(self): if self.settings.os == "Windows": raise ConanInvalidConfiguration("Shared builds on Windows are not supported") - def build_requirements(self): - # 3.28+ is not supported - self.tool_requires("cmake/[>=3.15 <=3.27]") - def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True)