Skip to content

Commit

Permalink
Merge pull request #514 from cppalliance/packages
Browse files Browse the repository at this point in the history
Add vcpkg and Conan packages
  • Loading branch information
mborland authored May 1, 2024
2 parents d2be0f4 + a068d52 commit 47cb147
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 1 deletion.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,31 @@ This library is not an official boost library, and is under active development.
# How To Use The Library

This library is header only, and contains no dependencies.
It can either be copied into the directory of your choice, or installed with CMake.

## CMake

````
git clone https://github.com/cppalliance/decimal
cd decimal
mkdir build && cd build
cmake .. OR cmake .. -DCMAKE_INSTALL_PREFIX=/your/custom/path
cmake --install .
````

## vcpkg

````
git clone https://github.com/cppalliance/decimal
cd decimal
vcpkg install decimal --overlay-ports=ports/decimal
````

## Conan

````
git clone https://github.com/cppalliance/decimal
conan create decimal/conan --build missing
````

# Supported Platforms

Expand Down
102 changes: 102 additions & 0 deletions conan/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from conan import ConanFile
from conan.errors import (
ConanException,
ConanInvalidConfiguration,
)
from conan.tools.files import copy
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import (
cmake_layout,
CMake,
CMakeDeps,
CMakeToolchain,
)
from conan.tools.scm import Version

import os

required_conan_version = ">=1.53.0"

class CharconvConan(ConanFile):
name = "boost_decimal"
version = "1.0.0"
description = "Boost provides free peer-reviewed portable C++ source libraries"
url = "https://github.com/cppalliance/decimal"
homepage = "https://github.com/cppalliance/decimal"
license = "BSL-1.0"
topics = ("decimal-binary", "conversion")

settings = "os", "arch", "compiler", "build_type"

options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

requires = "boost/[>=1.82.0]"

@property
def _min_compiler_version_default_cxx14(self):
return {
"apple-clang": 99,
"gcc": 6,
"clang": 6,
"Visual Studio": 14, # guess
"msvc": 192,
}.get(str(self.settings.compiler))

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 14)
else:
version_cxx14_standard_json = self._min_compiler_version_default_cxx14
if not version_cxx14_standard_json:
self.output.warning("Assuming the compiler supports c++14 by default")
elif Version(self.settings.compiler.version) < version_cxx14_standard_json:
raise ConanInvalidConfiguration("Boost.Decimal requires C++14")

def layout(self):
self.folders.root = ".."
cmake_layout(self, build_folder="bin")

def export_sources(self):
src = os.path.join(self.recipe_folder, "..")
copy(self, "CMakeLists.txt", src, self.export_sources_folder)
copy(self, "LICENSE", src, self.export_sources_folder)
copy(self, "include*", src, self.export_sources_folder)
copy(self, "conan/*.cmake", src, self.export_sources_folder)

def generate(self):
boost = self.dependencies["boost"]

tc = CMakeToolchain(self)
tc.variables["BOOST_SUPERPROJECT_VERSION"] = boost.ref.version
tc.variables["CMAKE_PROJECT_boost_decimal_INCLUDE"] = os.path.join(
self.source_folder, "conan", "targets.cmake")
tc.generate()

deps = CMakeDeps(self)
deps.generate()

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

def package(self):
libdir = os.path.join(self.package_folder, "lib")

copy(self, "include/*", self.source_folder, self.package_folder)

copy(self, "LICENSE", self.source_folder, self.package_folder)

def package_info(self):
self.cpp_info.libs = ["boost_decimal"]
1 change: 1 addition & 0 deletions conan/targets.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find_package(Boost)
7 changes: 7 additions & 0 deletions ports/decimal/b2-options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2024 Matt Borland
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt

if(APPLE)
list(APPEND B2_OPTIONS cxxstd=14)
endif()
16 changes: 16 additions & 0 deletions ports/decimal/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Matt Borland
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
#
# See: https://devblogs.microsoft.com/cppblog/registries-bring-your-own-libraries-to-vcpkg/

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO cppalliance/decimal
REF v1.0.0
SHA512 73043ea9514b747e519a5365ae57d9c1516d5f55784779d056d7db7266fd68328cd394e144db28125563c898b1d3acb6a4b47588ff319edefc84d35567a40b52
HEAD_REF master
)

file(COPY "${SOURCE_PATH}/include" DESTINATION "${CURRENT_PACKAGES_DIR}")
file(COPY "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
16 changes: 16 additions & 0 deletions ports/decimal/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "decimal",
"version": "1.0.0",
"description": "A C++14 implementation of IEEE 754 decimal floating point numbers",
"homepage": "https://github.com/cppalliance/decimal",
"dependencies": [
{
"name": "boost-vcpkg-helpers",
"version>=": "1.81.0"
},
{
"name": "vcpkg-cmake",
"host": true
}
]
}

0 comments on commit 47cb147

Please sign in to comment.