Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
(conan-io#17120) aws-crt-cpp: add missing interface definition if shared
Browse files Browse the repository at this point in the history
* add AWS_CRT_CPP_USE_IMPORT_EXPORT interface definition if shared

* more elegant way to define target for legacy generators

* add missing transitive headers

* aws-c-common is a public dependency

* fix traits
  • Loading branch information
SpaceIm authored and ericLemanissier committed Sep 15, 2023
1 parent fc586ce commit d396952
Showing 1 changed file with 40 additions and 30 deletions.
70 changes: 40 additions & 30 deletions recipes/aws-crt-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from conan import ConanFile
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir, save
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout

import os
import textwrap

required_conan_version = ">=1.53.0"

Expand Down Expand Up @@ -46,22 +47,23 @@ def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("aws-c-common/0.8.2")
self.requires("aws-c-cal/0.5.13", transitive_headers=True)
self.requires("aws-c-common/0.8.2", transitive_headers=True)
self.requires("aws-checksums/0.1.13")
if Version(self.version) < "0.17.29":
self.requires("aws-c-io/0.10.20")
self.requires("aws-c-http/0.6.13")
self.requires("aws-c-auth/0.6.11")
self.requires("aws-c-s3/0.1.37")
self.requires("aws-c-mqtt/0.7.10")
self.requires("aws-c-auth/0.6.11", transitive_headers=True)
self.requires("aws-c-event-stream/0.2.7")
self.requires("aws-c-http/0.6.13", transitive_headers=True)
self.requires("aws-c-io/0.10.20", transitive_headers=True)
self.requires("aws-c-mqtt/0.7.10", transitive_headers=True)
self.requires("aws-c-s3/0.1.37")
else:
self.requires("aws-c-io/0.13.4")
self.requires("aws-c-http/0.6.22")
self.requires("aws-c-auth/0.6.17")
self.requires("aws-c-s3/0.1.49")
self.requires("aws-c-mqtt/0.7.12")
self.requires("aws-c-auth/0.6.17", transitive_headers=True)
self.requires("aws-c-event-stream/0.2.15")
self.requires("aws-c-http/0.6.22", transitive_headers=True)
self.requires("aws-c-io/0.13.4", transitive_headers=True)
self.requires("aws-c-mqtt/0.7.12", transitive_headers=True)
self.requires("aws-c-s3/0.1.49")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
Expand Down Expand Up @@ -91,26 +93,34 @@ def package(self):
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "aws-crt-cpp"))

# 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-crt-cpp": "aws-crt-cpp::aws-crt-cpp"}
)

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-crt-cpp")
self.cpp_info.set_property("cmake_target_name", "AWS::aws-crt-cpp")

self.cpp_info.components["aws-crt-cpp-lib"].names["cmake_find_package"] = "aws-crt-cpp"
self.cpp_info.components["aws-crt-cpp-lib"].names["cmake_find_package_multi"] = "aws-crt-cpp"
self.cpp_info.components["aws-crt-cpp-lib"].libs = ["aws-crt-cpp"]
self.cpp_info.components["aws-crt-cpp-lib"].requires = [
"aws-c-event-stream::aws-c-event-stream-lib",
"aws-c-common::aws-c-common-lib",
"aws-c-io::aws-c-io-lib",
"aws-c-http::aws-c-http-lib",
"aws-c-auth::aws-c-auth-lib",
"aws-c-mqtt::aws-c-mqtt-lib",
"aws-c-s3::aws-c-s3-lib",
"aws-checksums::aws-checksums-lib"
]
self.cpp_info.libs = ["aws-crt-cpp"]
if self.options.shared:
self.cpp_info.defines.append("AWS_CRT_CPP_USE_IMPORT_EXPORT")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "aws-crt-cpp"
self.cpp_info.filenames["cmake_find_package_multi"] = "aws-crt-cpp"
self.cpp_info.names["cmake_find_package"] = "AWS"
self.cpp_info.names["cmake_find_package_multi"] = "AWS"
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]

0 comments on commit d396952

Please sign in to comment.