Skip to content

Commit d43d75a

Browse files
committed
Add conan package
1 parent d2be0f4 commit d43d75a

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

conan/conanfile.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
from conan import ConanFile
2+
from conan.errors import (
3+
ConanException,
4+
ConanInvalidConfiguration,
5+
)
6+
from conan.tools.files import copy
7+
from conan.tools.build import check_min_cppstd
8+
from conan.tools.cmake import (
9+
cmake_layout,
10+
CMake,
11+
CMakeDeps,
12+
CMakeToolchain,
13+
)
14+
from conan.tools.scm import Version
15+
16+
import os
17+
18+
required_conan_version = ">=1.53.0"
19+
20+
class CharconvConan(ConanFile):
21+
name = "boost_decimal"
22+
version = "1.0.0"
23+
description = "Boost provides free peer-reviewed portable C++ source libraries"
24+
url = "https://github.com/cppalliance/decimal"
25+
homepage = "https://github.com/cppalliance/decimal"
26+
license = "BSL-1.0"
27+
topics = ("decimal-binary", "conversion")
28+
29+
settings = "os", "arch", "compiler", "build_type"
30+
31+
options = {
32+
"shared": [True, False],
33+
"fPIC": [True, False],
34+
}
35+
default_options = {
36+
"shared": False,
37+
"fPIC": True,
38+
}
39+
40+
requires = "boost/[>=1.82.0]"
41+
42+
@property
43+
def _min_compiler_version_default_cxx14(self):
44+
return {
45+
"apple-clang": 99,
46+
"gcc": 6,
47+
"clang": 6,
48+
"Visual Studio": 14, # guess
49+
"msvc": 192,
50+
}.get(str(self.settings.compiler))
51+
52+
def config_options(self):
53+
if self.settings.os == "Windows":
54+
del self.options.fPIC
55+
56+
def validate(self):
57+
if self.settings.compiler.get_safe("cppstd"):
58+
check_min_cppstd(self, 14)
59+
else:
60+
version_cxx14_standard_json = self._min_compiler_version_default_cxx14
61+
if not version_cxx14_standard_json:
62+
self.output.warning("Assuming the compiler supports c++14 by default")
63+
elif Version(self.settings.compiler.version) < version_cxx14_standard_json:
64+
raise ConanInvalidConfiguration("Boost.Decimal requires C++14")
65+
66+
def layout(self):
67+
self.folders.root = ".."
68+
cmake_layout(self, build_folder="bin")
69+
70+
def export_sources(self):
71+
src = os.path.join(self.recipe_folder, "..")
72+
copy(self, "CMakeLists.txt", src, self.export_sources_folder)
73+
copy(self, "LICENSE", src, self.export_sources_folder)
74+
copy(self, "include*", src, self.export_sources_folder)
75+
copy(self, "conan/*.cmake", src, self.export_sources_folder)
76+
77+
def generate(self):
78+
boost = self.dependencies["boost"]
79+
80+
tc = CMakeToolchain(self)
81+
tc.variables["BOOST_SUPERPROJECT_VERSION"] = boost.ref.version
82+
tc.variables["CMAKE_PROJECT_boost_decimal_INCLUDE"] = os.path.join(
83+
self.source_folder, "conan", "targets.cmake")
84+
tc.generate()
85+
86+
deps = CMakeDeps(self)
87+
deps.generate()
88+
89+
def build(self):
90+
cmake = CMake(self)
91+
cmake.configure()
92+
cmake.build()
93+
94+
def package(self):
95+
libdir = os.path.join(self.package_folder, "lib")
96+
97+
copy(self, "include/*", self.source_folder, self.package_folder)
98+
99+
copy(self, "LICENSE", self.source_folder, self.package_folder)
100+
101+
def package_info(self):
102+
self.cpp_info.libs = ["boost_decimal"]

conan/targets.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
find_package(Boost)

0 commit comments

Comments
 (0)