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

ixwebsocket: conan v2 support #15511

Merged
merged 2 commits into from
Feb 1, 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
9 changes: 0 additions & 9 deletions recipes/ixwebsocket/all/CMakeLists.txt

This file was deleted.

48 changes: 24 additions & 24 deletions recipes/ixwebsocket/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
sources:
"7.9.2":
url: "https://github.com/machinezone/IXWebSocket/archive/v7.9.2.zip"
sha256: "B5224C1DEC64E25933F2DC547C278265A1B335C4516F1B11FAC81F0AC99B747E"
"9.1.9":
url: "https://github.com/machinezone/IXWebSocket/archive/v9.1.9.zip"
sha256: "dd83b4855882b538ca9782b42e80be4ebf96f978974e2615def673fb9d58c33b"
"9.6.4":
url: "https://github.com/machinezone/IXWebSocket/archive/v9.6.4.zip"
sha256: "b249b3bd0323f5b9aa4808852266f17073afd9f1f3a89815205a39604230f0ea"
"10.2.5":
url: "https://github.com/machinezone/IXWebSocket/archive/v10.2.5.tar.gz"
sha256: "5db57c7327dc0764151038dc71d9ae7d9859fe3f1c182f35b4e2dfec43a5224e"
"10.4.0":
url: "https://github.com/machinezone/IXWebSocket/archive/v10.4.0.tar.gz"
sha256: "5bdeef08a66d3c143e7fd8b02820ed5ee5c7848e4fa043132cbeef4ea18cd326"
"11.0.4":
url: "https://github.com/machinezone/IXWebSocket/archive/v11.0.4.tar.gz"
sha256: "deebfa04bd6bd930b2f7c0daba8674c8e8bc273a3d735b1877b1f4bb2c0e8596"
"11.0.9":
url: "https://github.com/machinezone/IXWebSocket/archive/v11.0.9.tar.gz"
sha256: "bb355b54add3de14fa645ac9c16c49d1cd8324fdeea959a64071ca9aec64da7e"
"11.2.4":
url: "https://github.com/machinezone/IXWebSocket/archive/refs/tags/v11.2.4.tar.gz"
sha256: "e9d4bfc6192c5390f43a9e0534ef7e3a2821bc062a1ff8c94f80884df3b412a9"
"11.4.3":
url: "https://github.com/machinezone/IXWebSocket/archive/refs/tags/v11.4.3.tar.gz"
sha256: "aa2d02c9c71339943cc61eb4efeb2ffc3a5a0011128a67027b9251b7d8a6e0ac"
"11.2.4":
url: "https://github.com/machinezone/IXWebSocket/archive/refs/tags/v11.2.4.tar.gz"
sha256: "e9d4bfc6192c5390f43a9e0534ef7e3a2821bc062a1ff8c94f80884df3b412a9"
"11.0.9":
url: "https://github.com/machinezone/IXWebSocket/archive/v11.0.9.tar.gz"
sha256: "bb355b54add3de14fa645ac9c16c49d1cd8324fdeea959a64071ca9aec64da7e"
"11.0.4":
url: "https://github.com/machinezone/IXWebSocket/archive/v11.0.4.tar.gz"
sha256: "deebfa04bd6bd930b2f7c0daba8674c8e8bc273a3d735b1877b1f4bb2c0e8596"
"10.4.0":
url: "https://github.com/machinezone/IXWebSocket/archive/v10.4.0.tar.gz"
sha256: "5bdeef08a66d3c143e7fd8b02820ed5ee5c7848e4fa043132cbeef4ea18cd326"
"10.2.5":
url: "https://github.com/machinezone/IXWebSocket/archive/v10.2.5.tar.gz"
sha256: "5db57c7327dc0764151038dc71d9ae7d9859fe3f1c182f35b4e2dfec43a5224e"
"9.6.4":
url: "https://github.com/machinezone/IXWebSocket/archive/v9.6.4.zip"
sha256: "b249b3bd0323f5b9aa4808852266f17073afd9f1f3a89815205a39604230f0ea"
"9.1.9":
url: "https://github.com/machinezone/IXWebSocket/archive/v9.1.9.zip"
sha256: "dd83b4855882b538ca9782b42e80be4ebf96f978974e2615def673fb9d58c33b"
"7.9.2":
url: "https://github.com/machinezone/IXWebSocket/archive/v7.9.2.zip"
sha256: "b5224c1dec64e25933f2dc547c278265a1b335c4516f1b11fac81f0ac99b747e"
132 changes: 67 additions & 65 deletions recipes/ixwebsocket/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,145 +1,147 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import collect_libs, copy, get, replace_in_file, rmdir
from conan.tools.scm import Version
import os

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.54.0"


class IXWebSocketConan(ConanFile):
name = "ixwebsocket"
description = "IXWebSocket is a C++ library for WebSocket client and server development"
topics = ("conan", "IXWebSocket", "socket", "websocket")
topics = ("socket", "websocket")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/machinezone/IXWebSocket"
license = "BSD-3-Clause"
exports_sources = ["CMakeLists.txt"]
settings = "os", "compiler", "build_type", "arch"
short_paths = True
generators = "cmake", "cmake_find_package"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"tls": ["mbedtls", "openssl", "applessl", False],
"with_zlib": [True, False]
"with_zlib": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"tls": "mbedtls",
"with_zlib": True
"with_zlib": True,
}

_cmake = None
short_paths = True

@property
def _source_subfolder(self):
return "source_subfolder"
def _min_cppstd(self):
# After version 11.0.8, IXWebSocket is fully compatible with C++ 11.
# https://github.com/machinezone/IXWebSocket/commit/ee5a2eb46ee0e109415dc02b0db85a9c76256090
return "14" if Version(self.version) < "11.0.8" else "11"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if tools.Version(self.version) < "10.1.5":
if Version(self.version) < "10.1.5":
# zlib is always required before 10.1.5
del self.options.with_zlib

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):
if self.options.get_safe("with_zlib", True):
self.requires("zlib/1.2.12")
self.requires("zlib/1.2.13")
if self.options.tls == "openssl":
self.requires("openssl/1.1.1q")
self.requires("openssl/1.1.1s")
elif self.options.tls == "mbedtls":
self.requires("mbedtls/2.25.0")

@property
def _can_use_openssl(self):
if self.settings.os == "Windows":
# Future: support for OpenSSL on Windows was introduced in 7.9.3. Earlier versions force MbedTLS
return tools.Version(self.version) >= "7.9.3"
return Version(self.version) >= "7.9.3"
# The others do, by default, support OpenSSL and MbedTLS. Non-standard operating systems might
# be a challenge.
# Older versions doesn't support OpenSSL on Mac, but those are unlikely to be built now.
return True

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
# After version 11.0.8, IXWebSocket is fully compatible with C++ 11. https://github.com/machinezone/IXWebSocket/commit/ee5a2eb46ee0e109415dc02b0db85a9c76256090
tools.check_min_cppstd(self, 14 if tools.Version(self.version) < "11.0.8" else 11)
if self.options.tls == "applessl" and not tools.is_apple_os(self.settings.os):
check_min_cppstd(self, self._min_cppstd)
if self.options.tls == "applessl" and not is_apple_os(self):
raise ConanInvalidConfiguration("Can only use Apple SSL on Apple.")
elif not self._can_use_openssl and self.options.tls == "openssl":
raise ConanInvalidConfiguration("This version doesn't support OpenSSL with Windows; use v7.9.3 or newer for this to be valid")
raise ConanInvalidConfiguration(f"{self.ref} doesn't support OpenSSL with Windows; use v7.9.3 or newer for this to be valid")

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["USE_TLS"] = bool(self.options.tls)
tc.variables["USE_MBED_TLS"] = self.options.tls == "mbedtls"
tc.variables["USE_OPEN_SSL"] = self.options.tls == "openssl"
# Apple configures itself if USE_TLS True, and USE_MBED_TLS + USE_OPEN_SSL False
if Version(self.version) >= "10.1.5":
tc.variables["USE_ZLIB"] = self.options.with_zlib
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt")
# Use Find modules generated by conan
tools.replace_in_file(cmakelists,
"set(CMAKE_MODULE_PATH \"${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}\")",
"list(APPEND CMAKE_MODULE_PATH \"${CMAKE_CURRENT_SOURCE_DIR}/CMake\")")
# Use CMake variables from FindMbedTLS.cmake generated by conan
tools.replace_in_file(cmakelists, "MBEDTLS_INCLUDE_DIRS", "MbedTLS_INCLUDE_DIRS")
tools.replace_in_file(cmakelists, "MBEDTLS_LIBRARIES", "MbedTLS_LIBRARIES")
cmakelists = os.path.join(self.source_folder, "CMakeLists.txt")
# Use CMake variables from MbedTLSConfig.cmake generated by conan
replace_in_file(self, cmakelists, "${MBEDTLS_INCLUDE_DIRS}", "${MbedTLS_INCLUDE_DIRS}")
replace_in_file(self, cmakelists, "${MBEDTLS_LIBRARIES}", "MbedTLS::mbedtls")
# Do not force PIC
if tools.Version(self.version) >= "9.5.7":
tools.replace_in_file(cmakelists, "set(CMAKE_POSITION_INDEPENDENT_CODE ON)", "")
if Version(self.version) >= "9.5.7":
replace_in_file(self, cmakelists, "set(CMAKE_POSITION_INDEPENDENT_CODE ON)", "")
# Allow shared
if tools.Version(self.version) < "11.1.4":
tools.replace_in_file(cmakelists, "add_library( ixwebsocket STATIC", "add_library( ixwebsocket")
if tools.Version(self.version) < "9.8.5":
tools.replace_in_file(cmakelists,
if Version(self.version) < "11.1.4":
replace_in_file(self, cmakelists, "add_library( ixwebsocket STATIC", "add_library( ixwebsocket")
if Version(self.version) < "9.8.5":
replace_in_file(self, cmakelists,
"ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib",
"ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin")
elif tools.Version(self.version) < "11.4.3":
tools.replace_in_file(cmakelists,
elif Version(self.version) < "11.4.3":
replace_in_file(self, cmakelists,
"ARCHIVE DESTINATION lib",
"ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin")
else:
tools.replace_in_file(cmakelists,
replace_in_file(self, cmakelists,
"ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}",
"ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION bin")

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["USE_TLS"] = bool(self.options.tls)
self._cmake.definitions["USE_MBED_TLS"] = self.options.tls == "mbedtls"
self._cmake.definitions["USE_OPEN_SSL"] = self.options.tls == "openssl"
# Apple configures itself if USE_TLS True, and USE_MBED_TLS + USE_OPEN_SSL False
if tools.Version(self.version) >= "10.1.5":
self._cmake.definitions["USE_ZLIB"] = self.options.with_zlib

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):
self.copy(pattern="LICENSE*", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE*", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "ixwebsocket"
self.cpp_info.names["cmake_find_package_multi"] = "ixwebsocket"
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.set_property("cmake_file_name", "ixwebsocket")
self.cpp_info.set_property("cmake_target_name", "ixwebsocket::ixwebsocket")
self.cpp_info.libs = collect_libs(self)
if self.settings.os == "Windows":
self.cpp_info.system_libs.extend(["wsock32", "ws2_32", "shlwapi"])
if bool(self.options.tls):
self.cpp_info.system_libs.append("Crypt32")
elif self.settings.os == "Linux":
self.cpp_info.system_libs.append("pthread")
self.cpp_info.system_libs.append("crypt32")
elif self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["m", "pthread"])
if self.options.get_safe("with_zlib", False):
self.cpp_info.defines.append("IXWEBSOCKET_USE_ZLIB")
if self.options.tls == "mbedtls":
Expand Down
11 changes: 4 additions & 7 deletions recipes/ixwebsocket/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(ixwebsocket REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ixwebsocket::ixwebsocket)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED ON)
target_link_libraries(${PROJECT_NAME} PRIVATE ixwebsocket::ixwebsocket)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
23 changes: 15 additions & 8 deletions recipes/ixwebsocket/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os

from conans import ConanFile, CMake, tools


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"
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 not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
7 changes: 3 additions & 4 deletions recipes/ixwebsocket/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
int main() {
std::string url = "https://github.com";
std::string protocol, host, path, query;
int port;
int port;

bool res = ix::UrlParser::parse(url, protocol, host, path, query, port);

std::cout
std::cout
<< "URL parse result: \n"
<< "Protocol: " << protocol
<< "\nHost: " << host
<< "\nHost: " << host
<< "\nPath: " << path
<< "\nQuery: " << query
<< "\nPort: " << port << std::endl;

}
8 changes: 8 additions & 0 deletions recipes/ixwebsocket/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/ixwebsocket/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)
Loading