diff --git a/recipes/aws-c-cal/all/conanfile.py b/recipes/aws-c-cal/all/conanfile.py index 3ed5c70f492e6..bb8fb82e75aab 100644 --- a/recipes/aws-c-cal/all/conanfile.py +++ b/recipes/aws-c-cal/all/conanfile.py @@ -1,11 +1,12 @@ from conan import ConanFile from conan.tools.apple import is_apple_os from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout -from conan.tools.files import apply_conandata_patches, copy, get, rmdir +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, save from conan.tools.scm import Version import os +import textwrap -required_conan_version = ">=1.51.3" +required_conan_version = ">=1.53.0" class AwsCCal(ConanFile): @@ -14,7 +15,8 @@ class AwsCCal(ConanFile): topics = ("aws", "amazon", "cloud", "cal", "crypt", ) url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/awslabs/aws-c-cal" - license = "Apache-2.0", + license = "Apache-2.0" + package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -27,11 +29,10 @@ class AwsCCal(ConanFile): @property def _needs_openssl(self): - return self.settings.os != "Windows" and not is_apple_os(self) + return not (self.settings.os == "Windows" or is_apple_os(self)) def export_sources(self): - for p in self.conan_data.get("patches", {}).get(self.version, []): - copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder) + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -39,30 +40,26 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC - 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") def requirements(self): if Version(self.version) <= "0.5.11": - self.requires("aws-c-common/0.6.11") + # transitive_libs probably not strictly required, but it's impossible to write a robust test package + # without it for conan v2 (we would have to required aws-c-common in test package, but we can't know + # which version to require in test package) + self.requires("aws-c-common/0.6.11", transitive_headers=True, transitive_libs=True) else: - self.requires("aws-c-common/0.8.2") + self.requires("aws-c-common/0.8.2", transitive_headers=True, transitive_libs=True) if self._needs_openssl: - self.requires("openssl/1.1.1s") + self.requires("openssl/[>=1.1 <4]") 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) @@ -84,30 +81,43 @@ def package(self): cmake.install() rmdir(self, os.path.join(self.package_folder, "lib", "aws-c-cal")) + # 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-cal": "aws-c-cal::aws-c-cal"} + ) + + 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-cal") self.cpp_info.set_property("cmake_target_name", "AWS::aws-c-cal") - - self.cpp_info.filenames["cmake_find_package"] = "aws-c-cal" - self.cpp_info.filenames["cmake_find_package_multi"] = "aws-c-cal" - self.cpp_info.names["cmake_find_package"] = "AWS" - self.cpp_info.names["cmake_find_package_multi"] = "AWS" - self.cpp_info.components["aws-c-cal-lib"].names["cmake_find_package"] = "aws-c-cal" - self.cpp_info.components["aws-c-cal-lib"].names["cmake_find_package_multi"] = "aws-c-cal" - self.cpp_info.components["aws-c-cal-lib"].set_property("cmake_target_name", "AWS::aws-c-cal") - - self.cpp_info.components["aws-c-cal-lib"].libs = ["aws-c-cal"] - self.cpp_info.components["aws-c-cal-lib"].requires = ["aws-c-common::aws-c-common-lib"] + self.cpp_info.libs = ["aws-c-cal"] + self.cpp_info.requires = ["aws-c-common::aws-c-common"] + if self.options.shared: + self.cpp_info.defines.append("AWS_CAL_USE_IMPORT_EXPORT") if self.settings.os == "Windows": - self.cpp_info.components["aws-c-cal-lib"].system_libs.append("ncrypt") + self.cpp_info.system_libs.append("ncrypt") elif is_apple_os(self): - self.cpp_info.components["aws-c-cal-lib"].frameworks.extend(["CoreFoundation", "Security"]) + self.cpp_info.frameworks.extend(["CoreFoundation", "Security"]) elif self.settings.os in ("FreeBSD", "Linux"): - self.cpp_info.components["aws-c-cal-lib"].system_libs.append("dl") + self.cpp_info.system_libs.append("dl") - self.user_info.with_openssl = self._needs_openssl if self._needs_openssl: - self.cpp_info.components["aws-c-cal-lib"].requires.append("openssl::crypto") + self.cpp_info.requires.append("openssl::crypto") if not self.dependencies["openssl"].options.shared: # aws-c-cal does not statically link to openssl and searches dynamically for openssl symbols . # Mark these as undefined so the linker will include them. @@ -124,5 +134,9 @@ def package_info(self): "HMAC_CTX_init", "HMAC_CTX_cleanup", "HMAC_CTX_reset", ]) crypto_link_flags = "-Wl," + ",".join(f"-u{symbol}" for symbol in crypto_symbols) - self.cpp_info.components["aws-c-cal-lib"].exelinkflags.append(crypto_link_flags) - self.cpp_info.components["aws-c-cal-lib"].sharedlinkflags.append(crypto_link_flags) + self.cpp_info.exelinkflags.append(crypto_link_flags) + self.cpp_info.sharedlinkflags.append(crypto_link_flags) + + # TODO: to remove in conan v2 once cmake_find_package* 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] diff --git a/recipes/aws-c-cal/all/test_package/CMakeLists.txt b/recipes/aws-c-cal/all/test_package/CMakeLists.txt index 7ed07f4d9b8e6..a98182dc5ef67 100644 --- a/recipes/aws-c-cal/all/test_package/CMakeLists.txt +++ b/recipes/aws-c-cal/all/test_package/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.1) project(test_package LANGUAGES C) find_package(aws-c-cal REQUIRED CONFIG) +find_package(aws-c-common REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) -target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-c-cal) +target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-c-cal AWS::aws-c-common) diff --git a/recipes/aws-c-cal/all/test_package/conanfile.py b/recipes/aws-c-cal/all/test_package/conanfile.py index 1b3c18ef08ac1..fb5c5c0c1d8f0 100644 --- a/recipes/aws-c-cal/all/test_package/conanfile.py +++ b/recipes/aws-c-cal/all/test_package/conanfile.py @@ -1,4 +1,5 @@ from conan import ConanFile +from conan.tools.apple import is_apple_os from conan.tools.build import can_run from conan.tools.cmake import CMake, cmake_layout import os @@ -10,6 +11,10 @@ class TestPackageConan(ConanFile): generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" test_type = "explicit" + @property + def _needs_openssl(self): + return not (self.settings.os == "Windows" or is_apple_os(self)) + def layout(self): cmake_layout(self) @@ -25,7 +30,7 @@ def test(self): if can_run(self): stream = io.StringIO() bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") - self.run(bin_path, env="conanrun", output=stream) + self.run(bin_path, stream, env="conanrun") self.output.info(stream.getvalue()) - if self.deps_user_info["aws-c-cal"].with_openssl == "True": + if self._needs_openssl: assert "found static libcrypto" in stream.getvalue() diff --git a/recipes/aws-c-cal/all/test_v1_package/CMakeLists.txt b/recipes/aws-c-cal/all/test_v1_package/CMakeLists.txt index 8a88842ed46e6..0d20897301b68 100644 --- a/recipes/aws-c-cal/all/test_v1_package/CMakeLists.txt +++ b/recipes/aws-c-cal/all/test_v1_package/CMakeLists.txt @@ -1,10 +1,8 @@ cmake_minimum_required(VERSION 3.1) -project(test_package LANGUAGES C) +project(test_package) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup(TARGETS) -find_package(aws-c-cal REQUIRED CONFIG) - -add_executable(${PROJECT_NAME} ../test_package/test_package.c) -target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-c-cal) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package + ${CMAKE_CURRENT_BINARY_DIR}/test_package) diff --git a/recipes/aws-c-cal/all/test_v1_package/conanfile.py b/recipes/aws-c-cal/all/test_v1_package/conanfile.py index ff0f4e1acbd6f..e27da49632915 100644 --- a/recipes/aws-c-cal/all/test_v1_package/conanfile.py +++ b/recipes/aws-c-cal/all/test_v1_package/conanfile.py @@ -1,4 +1,5 @@ from conans import ConanFile, CMake, tools +from conan.tools.apple import is_apple_os import os import io @@ -7,6 +8,10 @@ class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" generators = "cmake", "cmake_find_package_multi" + @property + def _needs_openssl(self): + return not (self.settings.os == "Windows" or is_apple_os(self)) + def build(self): cmake = CMake(self) cmake.configure() @@ -16,7 +21,7 @@ def test(self): if not tools.cross_building(self): stream = io.StringIO() bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True, output=stream) + self.run(bin_path, stream, run_environment=True) self.output.info(stream.getvalue()) - if self.deps_user_info["aws-c-cal"].with_openssl == "True": + if self._needs_openssl: assert "found static libcrypto" in stream.getvalue()