From 7341a169c5c6adb90f020018d5ec8942967d5417 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Tue, 20 Jun 2023 09:44:53 +0200 Subject: [PATCH] (#17107) aws-c-http: add missing interface definition if shared + modernize more for conan v2 * add AWS_HTTP_USE_IMPORT_EXPORT interface definition if shared * modernize more * more elegant way to define target for legacy generators * aws-c-common & aws-c-io are public dependencies --- recipes/aws-c-http/all/conanfile.py | 76 ++++++++++--------- .../all/test_v1_package/CMakeLists.txt | 9 +-- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/recipes/aws-c-http/all/conanfile.py b/recipes/aws-c-http/all/conanfile.py index 5f4b5242c4dbed..2d95021a30464c 100644 --- a/recipes/aws-c-http/all/conanfile.py +++ b/recipes/aws-c-http/all/conanfile.py @@ -1,18 +1,21 @@ from conan import ConanFile -from conan.tools.scm import Version -from conan.tools.files import get, copy, rmdir 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.47.0" class AwsCHttp(ConanFile): name = "aws-c-http" description = "C99 implementation of the HTTP/1.1 and HTTP/2 specifications" - license = "Apache-2.0", + license = "Apache-2.0" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/awslabs/aws-c-http" topics = ("aws", "amazon", "cloud", "http", "http2", ) + package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -29,33 +32,23 @@ 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") def requirements(self): - 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-compression/0.2.15") if Version(self.version) < "0.6.22": - self.requires("aws-c-io/0.10.20") + self.requires("aws-c-io/0.10.20", transitive_headers=True) else: - self.requires("aws-c-io/0.13.4") + self.requires("aws-c-io/0.13.4", transitive_headers=True) 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) @@ -76,21 +69,34 @@ def package(self): cmake.install() rmdir(self, os.path.join(self.package_folder, "lib", "aws-c-http")) + # 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-http": "aws-c-http::aws-c-http"} + ) + + 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-http") self.cpp_info.set_property("cmake_target_name", "AWS::aws-c-http") + self.cpp_info.libs = ["aws-c-http"] + if self.options.shared: + self.cpp_info.defines.append("AWS_HTTP_USE_IMPORT_EXPORT") - self.cpp_info.filenames["cmake_find_package"] = "aws-c-http" - self.cpp_info.filenames["cmake_find_package_multi"] = "aws-c-http" - self.cpp_info.names["cmake_find_package"] = "AWS" - self.cpp_info.names["cmake_find_package_multi"] = "AWS" - - self.cpp_info.components["aws-c-http-lib"].set_property("cmake_target_name", "AWS::aws-c-http") - self.cpp_info.components["aws-c-http-lib"].names["cmake_find_package"] = "aws-c-http" - self.cpp_info.components["aws-c-http-lib"].names["cmake_find_package_multi"] = "aws-c-http" - self.cpp_info.components["aws-c-http-lib"].libs = ["aws-c-http"] - self.cpp_info.components["aws-c-http-lib"].requires = [ - "aws-c-common::aws-c-common-lib", - "aws-c-compression::aws-c-compression-lib", - "aws-c-io::aws-c-io-lib" - ] + # 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-http/all/test_v1_package/CMakeLists.txt b/recipes/aws-c-http/all/test_v1_package/CMakeLists.txt index b3195e120b0b22..0d20897301b68b 100644 --- a/recipes/aws-c-http/all/test_v1_package/CMakeLists.txt +++ b/recipes/aws-c-http/all/test_v1_package/CMakeLists.txt @@ -1,11 +1,8 @@ cmake_minimum_required(VERSION 3.1) - -project(test_package C) +project(test_package) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup(TARGETS) -find_package(aws-c-http REQUIRED CONFIG) - -add_executable(${PROJECT_NAME} ../test_package/test_package.c) -target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-c-http) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package + ${CMAKE_CURRENT_BINARY_DIR}/test_package)