From e4f216cb20fe65b54422d18b1aa7831d9bf106e5 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 8 Nov 2023 21:13:45 +0200 Subject: [PATCH] (#18722) libsolace: migrate to Conan v2 * libsolace: migrate to Conan v2 * libsolace: drop old versions that would require patching * libsolace: add v0.4.1 --- recipes/libsolace/all/conandata.yml | 14 +-- recipes/libsolace/all/conanfile.py | 102 ++++++++++++------ .../libsolace/all/test_package/CMakeLists.txt | 7 +- .../libsolace/all/test_package/conanfile.py | 25 +++-- .../all/test_v1_package/CMakeLists.txt | 8 ++ .../all/test_v1_package/conanfile.py | 19 ++++ recipes/libsolace/config.yml | 4 +- 7 files changed, 119 insertions(+), 60 deletions(-) create mode 100644 recipes/libsolace/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/libsolace/all/test_v1_package/conanfile.py diff --git a/recipes/libsolace/all/conandata.yml b/recipes/libsolace/all/conandata.yml index f0faad0897234..4f59b4c769d25 100644 --- a/recipes/libsolace/all/conandata.yml +++ b/recipes/libsolace/all/conandata.yml @@ -1,11 +1,7 @@ sources: - "0.3.6": - sha256: ea9847005d0a680264986ddab5b1c077b04b80f02a2529cc38e8191b64ea97c7 - url: https://github.com/abbyssoul/libsolace/archive/v0.3.6.zip - "0.3.7": - sha256: 7f9790f850a0d7209f95be03e1c58e67f91faeec2e12709893cf32e5f09aa6d0 - url: https://github.com/abbyssoul/libsolace/archive/v0.3.7.zip + "0.4.1": + url: "https://github.com/abbyssoul/libsolace/archive/v0.4.1.zip" + sha256: "56d91ff180223322e0a93d62eb9f3974555f085d8e4e6e8435708d2bed0dfa0e" "0.3.9": - sha256: 5a91cc000d0ef5c51fb58197a8e3ef003fa191926f4f2511b7e8940648f007ce - url: https://github.com/abbyssoul/libsolace/archive/v0.3.9.zip - + url: "https://github.com/abbyssoul/libsolace/archive/v0.3.9.zip" + sha256: "5a91cc000d0ef5c51fb58197a8e3ef003fa191926f4f2511b7e8940648f007ce" diff --git a/recipes/libsolace/all/conanfile.py b/recipes/libsolace/all/conanfile.py index ba37d1a345156..e1bc3a637dd18 100644 --- a/recipes/libsolace/all/conanfile.py +++ b/recipes/libsolace/all/conanfile.py @@ -1,66 +1,98 @@ import os -from conans import CMake, ConanFile, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import copy, get, replace_in_file +from conan.tools.scm import Version + +required_conan_version = ">=1.53.0" + class LibsolaceConan(ConanFile): name = "libsolace" - description = "High performance components for mission critical applications" - topics = ("HPC", "High reliability", "P10", "solace", "performance", "c++", "conan") + description = "High-performance components for mission-critical applications" + license = "Apache-2.0" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/abbyssoul/libsolace" - license = "Apache-2.0" - settings = "os", "compiler", "build_type", "arch" + topics = ("HPC", "High reliability", "P10", "solace", "performance", "c++") + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], - "fPIC": [True, False] + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, } - default_options = {"shared": False, "fPIC": True} - generators = "cmake" @property - def _source_subfolder(self): - return "source_subfolder" + def _min_cppstd(self): + return 17 @property - def _supported_cppstd(self): - return ["17", "gnu17", "20", "gnu20"] + def _compilers_minimum_version(self): + return { + "gcc": "7", + "clang": "5", + "apple-clang": "9", + } + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC def configure(self): - compiler_version = tools.Version(str(self.settings.compiler.version)) + if self.options.shared: + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") + def validate(self): if self.settings.os == "Windows": - raise ConanInvalidConfiguration("This library is not yet compatible with Windows") - # Exclude compilers that claims to support C++17 but do not in practice - if (self.settings.compiler == "gcc" and compiler_version < "7") or \ - (self.settings.compiler == "clang" and compiler_version < "5") or \ - (self.settings.compiler == "apple-clang" and compiler_version < "9"): - raise ConanInvalidConfiguration("This library requires C++17 or higher support standard. {} {} is not supported".format(self.settings.compiler, self.settings.compiler.version)) - if self.settings.compiler.cppstd and not self.settings.compiler.cppstd in self._supported_cppstd: - raise ConanInvalidConfiguration("This library requires c++17 standard or higher. {} required".format(self.settings.compiler.cppstd)) + raise ConanInvalidConfiguration("This library is not yet compatible with Windows") + + if self.settings.compiler.cppstd: + check_min_cppstd(self, self._min_cppstd) + + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and Version(self.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." + ) def source(self): - tools.get(**self.conan_data["sources"][self.version]) - extracted_dir = self.name + "-" + self.version - os.rename(extracted_dir, self._source_subfolder) + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.cache_variables["PKG_CONFIG"] = False + tc.cache_variables["SOLACE_GTEST_SUPPORT"] = False + tc.generate() - def _configure_cmake(self): - cmake = CMake(self, parallel=True) - cmake.definitions["PKG_CONFIG"] = "OFF" - cmake.definitions["SOLACE_GTEST_SUPPORT"] = "OFF" - cmake.configure(source_folder=self._source_subfolder) - return cmake + def _patch_sources(self): + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), + "include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)\nconan_basic_setup()", + "") def build(self): - cmake = self._configure_cmake() + self._patch_sources() + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - cmake = self._configure_cmake() + cmake = CMake(self) cmake.install() - self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder) + copy(self, "LICENSE", + dst=os.path.join(self.package_folder, "licenses"), + src=self.source_folder) def package_info(self): self.cpp_info.libs = ["solace"] - if self.settings.os == "Linux": + if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs.append("m") diff --git a/recipes/libsolace/all/test_package/CMakeLists.txt b/recipes/libsolace/all/test_package/CMakeLists.txt index a4b980e0e807c..8301614166c20 100644 --- a/recipes/libsolace/all/test_package/CMakeLists.txt +++ b/recipes/libsolace/all/test_package/CMakeLists.txt @@ -1,8 +1,7 @@ -cmake_minimum_required(VERSION 3.3) +cmake_minimum_required(VERSION 3.15) project(PackageTest CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() +find_package(libsolace REQUIRED CONFIG) set(CMAKE_CXX_STANDARD_REQUIRED on) @@ -10,4 +9,4 @@ add_executable(example example.cpp) # libsolace requires at least C++17 set_target_properties(example PROPERTIES CXX_STANDARD 17) -target_link_libraries(example ${CONAN_LIBS}) +target_link_libraries(example libsolace::libsolace) diff --git a/recipes/libsolace/all/test_package/conanfile.py b/recipes/libsolace/all/test_package/conanfile.py index ce9505669ad4f..8d52b7021efe1 100644 --- a/recipes/libsolace/all/test_package/conanfile.py +++ b/recipes/libsolace/all/test_package/conanfile.py @@ -1,19 +1,26 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os -from conans import ConanFile, CMake, tools -class SolaceTestConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake" +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) - # Current dir is "test_package/build/" and CMakeLists.txt is - # in "test_package" cmake.configure() cmake.build() def test(self): - if not tools.cross_building(self.settings): - with tools.chdir("bin"): - self.run(".%sexample" % os.sep, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "example") + self.run(bin_path, env="conanrun") diff --git a/recipes/libsolace/all/test_v1_package/CMakeLists.txt b/recipes/libsolace/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/libsolace/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +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/libsolace/all/test_v1_package/conanfile.py b/recipes/libsolace/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..890f8e01b2489 --- /dev/null +++ b/recipes/libsolace/all/test_v1_package/conanfile.py @@ -0,0 +1,19 @@ +import os +from conans import ConanFile, CMake, tools + + +class SolaceTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + # Current dir is "test_package/build/" and CMakeLists.txt is + # in "test_package" + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + with tools.chdir("bin"): + self.run(".%sexample" % os.sep, run_environment=True) diff --git a/recipes/libsolace/config.yml b/recipes/libsolace/config.yml index e3af7d3426c10..c9e2a428688a9 100644 --- a/recipes/libsolace/config.yml +++ b/recipes/libsolace/config.yml @@ -1,7 +1,5 @@ versions: - 0.3.6: - folder: all - 0.3.7: + 0.4.1: folder: all 0.3.9: folder: all