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

aws-c-io: fix interface definition for shared lib on windows + bump s2n + add package_type #17104

Merged
Merged
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
77 changes: 42 additions & 35 deletions recipes/aws-c-io/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from conan import ConanFile
from conan.tools.files import get, copy, rmdir
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import get, copy, rmdir, save
from conan.tools.scm import Version
import os
import textwrap

required_conan_version = ">=1.53.0"

required_conan_version = ">=1.52.0"

class AwsCIO(ConanFile):
name = "aws-c-io"
description = "IO and TLS for application protocols"
license = "Apache-2.0",
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/awslabs/aws-c-io"
topics = ("aws", "amazon", "cloud", "io", "tls",)
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -29,18 +32,9 @@ def config_options(self):

def configure(self):
if self.options.shared:
try:
del self.options.fPIC
except Exception:
pass
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def layout(self):
cmake_layout(self, src_folder="src")
Expand All @@ -49,18 +43,17 @@ def requirements(self):
# the versions of aws-c-common and aws-c-io are tied since aws-c-common/0.6.12 and aws-c-io/0.10.10
# Please refer https://github.com/conan-io/conan-center-index/issues/7763
if Version(self.version) <= "0.10.9":
self.requires("aws-c-common/0.6.11")
self.requires("aws-c-common/0.6.11", transitive_headers=True, transitive_libs=True)
self.requires("aws-c-cal/0.5.11")
else:
self.requires("aws-c-common/0.8.2")
self.requires("aws-c-common/0.8.2", transitive_headers=True, transitive_libs=True)
self.requires("aws-c-cal/0.5.13")

if self.settings.os in ["Linux", "FreeBSD", "Android"]:
self.requires("s2n/1.3.15")
self.requires("s2n/1.3.31")

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

def generate(self):
tc = CMakeToolchain(self)
Expand All @@ -81,24 +74,38 @@ def package(self):
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "aws-c-io"))

# TODO: to remove in conan v2 once legacy generators removed
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{"AWS::aws-c-io": "aws-c-io::aws-c-io"}
)

def _create_cmake_module_alias_targets(self, module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent(f"""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""")
save(self, module_file, content)

@property
def _module_file_rel_path(self):
return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake")

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "aws-c-io")
self.cpp_info.set_property("cmake_target_name", "AWS::aws-c-io")
# TODO: back to global scope in conan v2 once cmake_find_package* generators removed
self.cpp_info.components["aws-c-io-lib"].libs = ["aws-c-io"]
self.cpp_info.libs = ["aws-c-io"]
if self.options.shared:
self.cpp_info.defines.append("AWS_IO_USE_IMPORT_EXPORT")
if self.settings.os == "Macos":
self.cpp_info.components["aws-c-io-lib"].frameworks.append("Security")
self.cpp_info.frameworks.append("Security")
if self.settings.os == "Windows":
self.cpp_info.components["aws-c-io-lib"].system_libs = ["crypt32", "secur32", "shlwapi"]
self.cpp_info.system_libs = ["crypt32", "secur32", "shlwapi"]

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.filenames["cmake_find_package"] = "aws-c-io"
self.cpp_info.filenames["cmake_find_package_multi"] = "aws-c-io"
self.cpp_info.names["cmake_find_package"] = "AWS"
self.cpp_info.names["cmake_find_package_multi"] = "AWS"
self.cpp_info.components["aws-c-io-lib"].names["cmake_find_package"] = "aws-c-io"
self.cpp_info.components["aws-c-io-lib"].names["cmake_find_package_multi"] = "aws-c-io"
self.cpp_info.components["aws-c-io-lib"].set_property("cmake_target_name", "AWS::aws-c-io")
self.cpp_info.components["aws-c-io-lib"].requires = ["aws-c-cal::aws-c-cal-lib", "aws-c-common::aws-c-common-lib"]
if self.settings.os in ["Linux", "FreeBSD", "Android"]:
self.cpp_info.components["aws-c-io-lib"].requires.append("s2n::s2n-lib")
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]