diff --git a/recipes/amqp-cpp/all/CMakeLists.txt b/recipes/amqp-cpp/all/CMakeLists.txt deleted file mode 100644 index dddebcc68cdb4c..00000000000000 --- a/recipes/amqp-cpp/all/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 3.4) -project(cmake_wrapper) - -if(WIN32 AND BUILD_SHARED_LIBS) - set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) -endif() - -include(conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -add_subdirectory(source_subfolder) diff --git a/recipes/amqp-cpp/all/conandata.yml b/recipes/amqp-cpp/all/conandata.yml index 2543d0dc3e3ba0..063e7eada33390 100644 --- a/recipes/amqp-cpp/all/conandata.yml +++ b/recipes/amqp-cpp/all/conandata.yml @@ -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" diff --git a/recipes/amqp-cpp/all/conanfile.py b/recipes/amqp-cpp/all/conanfile.py index 6b5d9c2631df00..efcd52d23c58ea 100644 --- a/recipes/amqp-cpp/all/conanfile.py +++ b/recipes/amqp-cpp/all/conanfile.py @@ -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): @@ -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": @@ -48,41 +37,40 @@ 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( @@ -90,21 +78,20 @@ def package(self): {"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") @@ -112,7 +99,9 @@ def package_info(self): 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" diff --git a/recipes/amqp-cpp/all/patches/0001-cmake-openssl-install-directories.patch b/recipes/amqp-cpp/all/patches/0001-cmake-openssl-install-directories.patch index 31d848a28a7716..f47d6bd4b19df0 100644 --- a/recipes/amqp-cpp/all/patches/0001-cmake-openssl-install-directories.patch +++ b/recipes/amqp-cpp/all/patches/0001-cmake-openssl-install-directories.patch @@ -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 # ------------------------------------------------------------------------------------------------------ diff --git a/recipes/amqp-cpp/all/test_package/CMakeLists.txt b/recipes/amqp-cpp/all/test_package/CMakeLists.txt index 0fcd0b264d0277..bbc10e2424b6bd 100644 --- a/recipes/amqp-cpp/all/test_package/CMakeLists.txt +++ b/recipes/amqp-cpp/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/amqp-cpp/all/test_package/conanfile.py b/recipes/amqp-cpp/all/test_package/conanfile.py index a500b98343c743..0a6bc68712d901 100644 --- a/recipes/amqp-cpp/all/test_package/conanfile.py +++ b/recipes/amqp-cpp/all/test_package/conanfile.py @@ -1,9 +1,19 @@ -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) @@ -11,6 +21,6 @@ def build(self): 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") diff --git a/recipes/amqp-cpp/all/test_v1_package/CMakeLists.txt b/recipes/amqp-cpp/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..0d20897301b68b --- /dev/null +++ b/recipes/amqp-cpp/all/test_v1_package/CMakeLists.txt @@ -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) diff --git a/recipes/amqp-cpp/all/test_v1_package/conanfile.py b/recipes/amqp-cpp/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..38f4483872d47f --- /dev/null +++ b/recipes/amqp-cpp/all/test_v1_package/conanfile.py @@ -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)