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

sioclient: new recipe #24112

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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/sioclient/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"cci.20240405":
url: "https://github.com/socketio/socket.io-client-cpp/archive/c6be96b226f0fe3853beaeaa99c06834342a78db.zip"
sha256: "7c68117185dbc49579bba09a3e877f2a716cc331c28b3d8b6d3f867c4346b639"
116 changes: 116 additions & 0 deletions recipes/sioclient/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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
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)
uilianries marked this conversation as resolved.
Show resolved Hide resolved
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.12 <=3.27]")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to check with the team what to do to set a min cmake version like this. (Also, this probably should be set to something >= 3.15)


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"])
8 changes: 8 additions & 0 deletions recipes/sioclient/all/test_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 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)
26 changes: 26 additions & 0 deletions recipes/sioclient/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
6 changes: 6 additions & 0 deletions recipes/sioclient/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <sio_client.h>

int main() {
sio::client h;
h.socket();
}
3 changes: 3 additions & 0 deletions recipes/sioclient/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20240405":
folder: all
Loading