from conan import ConanFile from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout from conan.tools.files import copy import os class SimpleAmqpClientConan(ConanFile): name = "simpleamqpclient" version = "2.5.1" description = "Simple C++ Wrapper around rabbitmq-c" url = "https://github.com/alanxz/SimpleAmqpClient" license = "MIT" author = "Alan Antonuk" topics = ("rabbitmq", "amqp", "client", "message-queue", "cpp") settings = "os", "compiler", "build_type", "arch" package_type = "library" options = { "shared": [True, False], "fPIC": [True, False], "with_test": [True, False] } default_options = { "shared": False, "fPIC": True, "with_test": True } exports_sources = "CMakeLists.txt", "Modules/*", "src/*", "testing/*", "third-party/*", "Doxyfile.in", "libSimpleAmqpClient.pc.in" def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: self.options.rm_safe("fPIC") def layout(self): cmake_layout(self) def requirements(self): self.requires("rabbitmq-c/[>=0.11.0]", transitive_headers=True, transitive_libs=True) def build_requirements(self): if self.options.with_test: self.test_requires("xgoogletest/1.17.1") def generate(self): tc = CMakeToolchain(self) tc.variables["BUILD_SHARED_LIBS"] = self.options.shared tc.variables["ENABLE_TESTING"] = self.options.with_test tc.variables["BUILD_API_DOCS"] = False tc.generate() deps = CMakeDeps(self) deps.set_property("rabbitmq-c", "cmake_target_name", "rabbitmq::rabbitmq" if self.options.shared else "rabbitmq::rabbitmq-static") deps.generate() def build(self): cmake = CMake(self) cmake.configure() cmake.build() if self.options.with_test: cmake.test() def package(self): cmake = CMake(self) cmake.install() copy(self, "LICENSE-MIT", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) def package_info(self): self.cpp_info.set_property("cmake_file_name", "simpleamqpclient") self.cpp_info.set_property("cmake_target_name", "simpleamqpclient::simpleamqpclient") # When simpleamqpclient builds as static on windows, we need SimpleAmqpClient_STATIC if not self.options.shared and self.settings.os == "Windows": self.cpp_info.defines.append("SimpleAmqpClient_STATIC") libs_name = "SimpleAmqpClient" # In the CMakeLists.txt: # set_target_properties(SimpleAmqpClient PROPERTIES VERSION ${SAC_VERSION} OUTPUT_NAME SimpleAmqpClient.${SAC_SOVERSION}) # Note on Windows it sets SimpleAmqpClient.7, but conan usually links `SimpleAmqpClient.7.lib` or similar. We'll simplify and use SimpleAmqpClient.7 if we really need to, but often CMake finds it via exported targets. Let's provide the base name here. # Actually in Windows if shared, CMake generates SimpleAmqpClient.lib or SimpleAmqpClient.7.lib. Let's just use "SimpleAmqpClient". self.cpp_info.libs = ["SimpleAmqpClient"] if self.settings.os == "Windows": self.cpp_info.system_libs.append("ws2_32") self.cpp_info.requires = ["rabbitmq-c::rabbitmq-c"]