Skip to content

Commit

Permalink
(conan-io#15445) amqp-cpp: conan v2 support
Browse files Browse the repository at this point in the history
* conan v2 support

* add missing system libs
  • Loading branch information
SpaceIm authored and StellaSmith committed Feb 2, 2023
1 parent 960b1e7 commit 2719a26
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 81 deletions.
11 changes: 0 additions & 11 deletions recipes/amqp-cpp/all/CMakeLists.txt

This file was deleted.

8 changes: 0 additions & 8 deletions recipes/amqp-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,17 @@ sources:
patches:
"4.3.18":
- patch_file: "patches/0001-cmake-openssl-install-directories.patch"
base_path: "source_subfolder"
"4.3.16":
- patch_file: "patches/0001-cmake-openssl-install-directories.patch"
base_path: "source_subfolder"
"4.3.11":
- patch_file: "patches/0001-cmake-openssl-install-directories.patch"
base_path: "source_subfolder"
"4.3.10":
- patch_file: "patches/0001-cmake-openssl-install-directories.patch"
base_path: "source_subfolder"
"4.2.1":
- patch_file: "patches/0001-cmake-openssl-install-directories.patch"
base_path: "source_subfolder"
"4.1.7":
- patch_file: "patches/0001-cmake-openssl-install-directories.patch"
base_path: "source_subfolder"
"4.1.6":
- patch_file: "patches/0001-cmake-openssl-install-directories.patch"
base_path: "source_subfolder"
"4.1.5":
- patch_file: "patches/0001-cmake-openssl-install-directories.patch"
base_path: "source_subfolder"
85 changes: 37 additions & 48 deletions recipes/amqp-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, save
import os
import textwrap

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.53.0"


class AmqpcppConan(ConanFile):
Expand All @@ -25,21 +27,8 @@ class AmqpcppConan(ConanFile):
"linux_tcp_module": True,
}

generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -48,71 +37,71 @@ def config_options(self):

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if self.options.get_safe("linux_tcp_module"):
self.requires("openssl/1.1.1q")
self.requires("openssl/1.1.1s")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["AMQP-CPP_BUILD_SHARED"] = self.options.shared
self._cmake.definitions["AMQP-CPP_BUILD_EXAMPLES"] = False
self._cmake.definitions["AMQP-CPP_LINUX_TCP"] = self.options.get_safe("linux_tcp_module") or False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["AMQP-CPP_BUILD_SHARED"] = self.options.shared
tc.variables["AMQP-CPP_BUILD_EXAMPLES"] = False
tc.variables["AMQP-CPP_LINUX_TCP"] = self.options.get_safe("linux_tcp_module", False)
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.install()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = self._configure_cmake()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
self.copy("LICENSE", src=self._source_subfolder, dst="licenses", keep_path=False)
tools.rmdir(os.path.join(self.package_folder, "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{"amqpcpp": "amqpcpp::amqpcpp"}
)

@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
def _create_cmake_module_alias_targets(self, module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
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()
""".format(alias=alias, aliased=aliased))
tools.save(module_file, content)
""")
save(self, module_file, content)

@property
def _module_file_rel_path(self):
return os.path.join("lib", "cmake", "conan-official-{}-targets.cmake".format(self.name))
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", "amqpcpp")
self.cpp_info.set_property("cmake_target_name", "amqpcpp")
self.cpp_info.set_property("pkg_config_name", "amqpcpp")
self.cpp_info.libs = ["amqpcpp"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["dl", "pthread"]
self.cpp_info.system_libs = ["dl", "m", "pthread"]
elif self.settings.os == "Windows":
self.cpp_info.system_libs = ["ws2_32"]

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.names["pkg_config"] = "amqpcpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -88,7 +88,9 @@
@@ -88,7 +88,10 @@
#add_library(${PROJECT_NAME} STATIC ${SRCS})
add_library(${PROJECT_NAME} STATIC ${src_MAIN} ${src_LINUX_TCP})
endif()
-
+if(AMQP-CPP_LINUX_TCP)
+target_link_libraries(${PROJECT_NAME} CONAN_PKG::openssl)
+find_package(OpenSSL REQUIRED)
+target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)
+endif()
# install rules
# ------------------------------------------------------------------------------------------------------
Expand Down
11 changes: 4 additions & 7 deletions recipes/amqp-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(amqpcpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} amqpcpp)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_link_libraries(${PROJECT_NAME} PRIVATE amqpcpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
20 changes: 15 additions & 5 deletions recipes/amqp-cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/amqp-cpp/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
17 changes: 17 additions & 0 deletions recipes/amqp-cpp/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit 2719a26

Please sign in to comment.