Skip to content

Commit

Permalink
Cxx: Initial version of the DFP with the Conan Package Manager support.
Browse files Browse the repository at this point in the history
  • Loading branch information
agdavydov81 committed Nov 2, 2023
1 parent ab71ecd commit d383933
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 36 deletions.
2 changes: 0 additions & 2 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,3 @@ if (JAVA_MATH_PREFIX)
set_target_properties(dfpmath PROPERTIES OUTPUT_NAME "ddfpmath${VERSION_SUFFIX}")
install(TARGETS dfpmath)
endif()

include(CPack)
50 changes: 26 additions & 24 deletions native/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from conan import ConanFile
from conan.tools.files import copy
#from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
import os
import re

Expand All @@ -22,42 +22,44 @@ def load_version(properties_filename):
class DfpConan(ConanFile):
name = "dfp"
package_type = "library"

# Optional metadata
description = "Decimal Floating Point Arithmetic Library"
homepage = "https://github.com/epam/DFP/"
url = "https://github.com/epam/DFP.git"
license = ("Apache-2.0", "Intel")
topics = ("decimal", "dfp", "ieee-754", "deltix")
author = "Andrei Davydov (agdavydov81@gmail.com)"

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = {"shared": False}

options = {
"shared": [True, False],
"c_runtime": [None, "glibc", "musl", "libc"],
"c_runtime_shared": [None, True, False],
"libPath": [None, "ANY"],
"libMask": [None, "ANY"]
}
default_options = {
"shared": True,
"c_runtime": None,
"c_runtime_shared": None,
"libMask": None
}
# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "src/*", "include/*"

def set_version(self):
# Command line ``--version=xxxx`` will be assigned first to self.version and have priority
self.version = self.version or load_version(os.path.join(self.recipe_folder, "..", "gradle.properties"))

def configure(self):
# it's a C library
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")
def layout(self):
cmake_layout(self)

self.libPath = f"{self.options.get_safe('libPath')}"
self.libMask = f"{self.options.get_safe('libMask')}"
self.options.rm_safe("libPath")
self.options.rm_safe("libMask")
def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()

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

def package(self):
copy(self, pattern="DecimalNative.h*", src=self.recipe_folder, dst=os.path.join(self.package_folder, "include"))
copy(self, pattern=self.libMask, src=self.libPath, dst=os.path.join(self.package_folder, "lib"))
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["ddfp"]
20 changes: 13 additions & 7 deletions native/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run


class TestExampleConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"
generators = "CMakeDeps", "CMakeToolchain"

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

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

def build_requirements(self):
self.tool_requires("dfp/[>=1.0.2]")
def layout(self):
cmake_layout(self)

def test(self):
if not cross_building(self):
self.run("./test_package_example")
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "demo")
self.run(cmd, env="conanrun")
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <iostream>
#include <sstream>
#include "DecimalNative.hpp"
#include <DecimalNative.hpp>

using namespace epam::deltix::dfp;

int main(int argc, char *argv[]) {
if(argc!=4) {
std::cerr << "Usage: <A> <op> <B>" << std::endl;
return -1;
std::cout << "Usage: <A> <op> <B>" << std::endl;
return 0;
}

const Decimal64 x(argv[1]); // Parsing call example - can throw std::invalid_argument
Expand Down

0 comments on commit d383933

Please sign in to comment.