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

s2n: remove component workaround for legacy generators #17122

Merged
merged 3 commits into from
Apr 28, 2023
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
42 changes: 29 additions & 13 deletions recipes/s2n/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, save
import os
import textwrap

required_conan_version = ">=1.53.0"

Expand Down Expand Up @@ -39,7 +40,7 @@ def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("openssl/3.1.0")
self.requires("openssl/[>=1.1 <4]")

def validate(self):
if self.settings.os == "Windows":
Expand Down Expand Up @@ -69,20 +70,35 @@ def package(self):
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "s2n"))

# 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::s2n": "s2n::s2n"}
)

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", "s2n")
self.cpp_info.set_property("cmake_target_name", "AWS::s2n")
# TODO: back to global scope in conan v2 once cmake_find_package* generators removed
self.cpp_info.components["s2n-lib"].libs = ["s2n"]
self.cpp_info.components["s2n-lib"].requires = ["openssl::crypto"]
self.cpp_info.libs = ["s2n"]
self.cpp_info.requires = ["openssl::crypto"]
if self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.components["s2n-lib"].system_libs = ["m", "pthread"]
self.cpp_info.system_libs = ["m", "pthread"]

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.filenames["cmake_find_package"] = "s2n"
self.cpp_info.filenames["cmake_find_package_multi"] = "s2n"
self.cpp_info.names["cmake_find_package"] = "AWS"
self.cpp_info.names["cmake_find_package_multi"] = "AWS"
self.cpp_info.components["s2n-lib"].names["cmake_find_package"] = "s2n"
self.cpp_info.components["s2n-lib"].names["cmake_find_package_multi"] = "s2n"
self.cpp_info.components["s2n-lib"].set_property("cmake_target_name", "AWS::s2n")
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]