Skip to content

Commit

Permalink
(#11516) erikzenker-hsm: Modernize to Conan v2
Browse files Browse the repository at this point in the history
* erikzenker-hsm: Conan-v2: Replace imports conans->conan

* erikzenker-hsm: Conan-V2: Fix all imports

* erikzenker-hsm: Conan-V2: Replace source_subfolder to layout

* erikzenker-hsm: Conan-V2: Fix tools.files.rmdir() call

* erikzenker-hsm: Conan-V2: Force convert all compiler versions to str()

For mititating conan-io/conan#11105 in Conan
1.47-

* erikzenker-hsm: Conan-V2: Fix tools.get() usage

* erikzenker-hsm: Conan-V2: Drop cmake generator

* erikzenker-hsm/test_package: Drop cppstd setting

* erikzenker-hsm/test_package: Modernize imports

* erikzenker-hsm/conanfile.py: Add package_info for CMakeDeps

* erikzenker-hsm/test_package: Modernize to Conan V2 CMakeDeps

* erikzenker-hsm/conanfile.py: Fix linter warnings
  • Loading branch information
leha-bot authored Jul 19, 2022
1 parent 0335c9f commit 543a833
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
30 changes: 16 additions & 14 deletions recipes/erikzenker-hsm/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conans.tools import Version
from conan import ConanFile, tools
from conan.tools.cmake import CMake, cmake_layout
from conan.errors import ConanInvalidConfiguration
from conan.tools.scm import Version
import os

required_conan_version = ">=1.43.0"
Expand All @@ -14,36 +15,37 @@ class HsmConan(ConanFile):
topics = ("state-machine", "template-meta-programming")
requires = "boost/1.79.0"
no_copy_source = True
generators = "cmake"
settings = "os", "arch", "build_type", "compiler"
generators = "CMakeDeps", "CMakeToolchain"

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

def validate(self):
# https://github.com/erikzenker/hsm#dependencies
if self.settings.compiler == "clang" and Version(self.settings.compiler.version) < 8:
if self.settings.compiler == "clang" and Version(str(self.settings.compiler.version)) < '8':
raise ConanInvalidConfiguration("clang 8+ is required")
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < 8:
if self.settings.compiler == "gcc" and Version(str(self.settings.compiler.version)) < '8':
raise ConanInvalidConfiguration("GCC 8+ is required")

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

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

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

def package_id(self):
self.info.header_only()

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "hsm"
self.cpp_info.names["cmake_find_package_multi"] = "hsm"
self.cpp_info.set_property("cmake_file_name", "hsm")
self.cpp_info.set_property("cmake_target_name", "hsm::hsm")
3 changes: 0 additions & 3 deletions recipes/erikzenker-hsm/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)

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

find_package(hsm CONFIG REQUIRED)

set(CMAKE_CXX_STANDARD 17)
Expand Down
20 changes: 14 additions & 6 deletions recipes/erikzenker-hsm/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import os

from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import cross_building


class HsmTestConan(ConanFile):
settings = "cppstd", "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"

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

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
Expand All @@ -14,6 +22,6 @@ def build(self):


def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)
if not cross_building(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "example")
self.run(bin_path, env="conanrun")

0 comments on commit 543a833

Please sign in to comment.