Skip to content

Commit

Permalink
(conan-io#8840) wslay: modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored and miklelappo committed Feb 9, 2022
1 parent 3da3534 commit 30dbd00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
36 changes: 19 additions & 17 deletions recipes/wslay/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
import os
import textwrap

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.43.0"


class WslayConan(ConanFile):
name = "wslay"
description = "The WebSocket library in C"
topics = ("conan", "websockets", "rfc6455", "communication", "tcp")
topics = ("websockets", "rfc6455", "communication", "tcp")
homepage = "https://tatsuhiro-t.github.io/wslay"
url = "https://github.com/conan-io/conan-center-index"
license = "MIT"

settings = "os", "compiler", "build_type", "arch"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -23,15 +23,18 @@ class WslayConan(ConanFile):
"fPIC": True,
}

exports_sources = ["CMakeLists.txt", "patches/*"]
generators = "cmake"

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand Down Expand Up @@ -66,6 +69,8 @@ def package(self):
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))

# TODO: to remove in conan v2 once cmake_find_package* & pkg_config generators removed
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{self._wslay_lib_target: "wslay::wslay"}
Expand All @@ -83,26 +88,23 @@ def _create_cmake_module_alias_targets(module_file, targets):
""".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))
return os.path.join("lib", "cmake", "conan-official-{}-targets.cmake".format(self.name))

@property
def _wslay_lib_target(self):
return "wslay_shared" if self.options.shared else "wslay"

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "wslay"
self.cpp_info.names["cmake_find_package_multi"] = "wslay"
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.names["pkg_config"] = "libwslay"
self.cpp_info.set_property("cmake_file_name", "wslay")
self.cpp_info.set_property("cmake_target_name", self._wslay_lib_target)
self.cpp_info.set_property("pkg_config_name", "libwslay")
self.cpp_info.libs = [self._wslay_lib_target]
if self.settings.os == "Windows":
self.cpp_info.system_libs = ["ws2_32"]

# TODO: to remove in conan v2 once cmake_find_package* & pkg_config generators removed
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.names["pkg_config"] = "libwslay"
4 changes: 2 additions & 2 deletions recipes/wslay/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"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
Expand All @@ -12,6 +12,6 @@ def build(self):
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit 30dbd00

Please sign in to comment.