Skip to content

Commit

Permalink
(#18722) libsolace: migrate to Conan v2
Browse files Browse the repository at this point in the history
* libsolace: migrate to Conan v2

* libsolace: drop old versions that would require patching

* libsolace: add v0.4.1
  • Loading branch information
valgur authored Nov 8, 2023
1 parent 0395560 commit e4f216c
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 60 deletions.
14 changes: 5 additions & 9 deletions recipes/libsolace/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
102 changes: 67 additions & 35 deletions recipes/libsolace/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
7 changes: 3 additions & 4 deletions recipes/libsolace/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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)

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)
25 changes: 16 additions & 9 deletions recipes/libsolace/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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/<build_id>" 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")
8 changes: 8 additions & 0 deletions recipes/libsolace/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.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/)
19 changes: 19 additions & 0 deletions recipes/libsolace/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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/<build_id>" 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)
4 changes: 1 addition & 3 deletions recipes/libsolace/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
versions:
0.3.6:
folder: all
0.3.7:
0.4.1:
folder: all
0.3.9:
folder: all

0 comments on commit e4f216c

Please sign in to comment.