Skip to content

Commit

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

* add AWS_COMPRESSION_USE_IMPORT_EXPORT interface definition if shared

* modernize more for conan v2

* more elegant way to define target for legacy generators

* aws-c-common is public
  • Loading branch information
SpaceIm authored and pezy committed Jun 1, 2023
1 parent 15a1afb commit 2fe80b7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
63 changes: 35 additions & 28 deletions recipes/aws-c-compression/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rmdir
from conan.tools.files import copy, get, rmdir, save
import os
import textwrap

required_conan_version = ">=1.47.0"
required_conan_version = ">=1.53.0"


class AwsCCompression(ConanFile):
Expand All @@ -13,7 +14,7 @@ class AwsCCompression(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/awslabs/aws-c-compression"
license = "Apache-2.0",

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -30,28 +31,18 @@ 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)

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

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

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

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

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

0 comments on commit 2fe80b7

Please sign in to comment.