Skip to content

Commit

Permalink
(#17119) aws-checksums: add missing interface definition if shared + …
Browse files Browse the repository at this point in the history
…modernize more for conan v2

* add AWS_CHECKSUMS_USE_IMPORT_EXPORT interface definition if shared

* modernize more

* more elegant way to define target for legacy generators
  • Loading branch information
SpaceIm authored Apr 28, 2023
1 parent 98150fd commit 9491838
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
63 changes: 36 additions & 27 deletions recipes/aws-checksums/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, export_conandata_patches, copy, get, rmdir
from conan.tools.files import apply_conandata_patches, export_conandata_patches, copy, get, rmdir, save
import os
import textwrap

required_conan_version = ">=1.53.0"

required_conan_version = ">=1.52.0"

class AwsChecksums(ConanFile):
name = "aws-checksums"
description = (
"Cross-Platform HW accelerated CRC32c and CRC32 with fallback to efficient "
"SW implementations. C interface with language bindings for each of our SDKs."
)
license = "Apache-2.0",
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/awslabs/aws-checksums"
topics = ("aws", "checksum", )
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -34,18 +37,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 @@ -54,8 +48,7 @@ def requirements(self):
self.requires("aws-c-common/0.8.2")

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 @@ -76,18 +69,34 @@ def package(self):
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "aws-checksums"))

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

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-checksums")
self.cpp_info.set_property("cmake_target_name", "AWS::aws-checksums")
# TODO: back to global scope in conan v2 once cmake_find_package* generators removed
self.cpp_info.components["aws-checksums-lib"].libs = ["aws-checksums"]
self.cpp_info.libs = ["aws-checksums"]
if self.options.shared:
self.cpp_info.defines.append("AWS_CHECKSUMS_USE_IMPORT_EXPORT")

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.filenames["cmake_find_package"] = "aws-checksums"
self.cpp_info.filenames["cmake_find_package_multi"] = "aws-checksums"
self.cpp_info.names["cmake_find_package"] = "AWS"
self.cpp_info.names["cmake_find_package_multi"] = "AWS"
self.cpp_info.components["aws-checksums-lib"].names["cmake_find_package"] = "aws-checksums"
self.cpp_info.components["aws-checksums-lib"].names["cmake_find_package_multi"] = "aws-checksums"
self.cpp_info.components["aws-checksums-lib"].set_property("cmake_target_name", "AWS::aws-checksums")
self.cpp_info.components["aws-checksums-lib"].requires = ["aws-c-common::aws-c-common-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]
8 changes: 3 additions & 5 deletions recipes/aws-checksums/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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-checksums REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-checksums)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)

0 comments on commit 9491838

Please sign in to comment.