Skip to content

Commit

Permalink
Create a new package for libtommath that supports conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jowr committed Mar 14, 2023
1 parent 19d45a5 commit db8cc58
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 1 deletion.
4 changes: 3 additions & 1 deletion recipes/libtommath/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"1.2.0-dev":
folder: "development"
"1.2.0":
folder: "all"
folder: "release"
54 changes: 54 additions & 0 deletions recipes/libtommath/development/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.scm import Git

class LibTomMathRecipe(ConanFile):
name = "libtommath"
version = "1.2.0-dev"

# Optional metadata
license = "Unlicense"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.libtom.net/"
topics = ("libtommath", "math", "multiple", "precision")

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

def source(self):
git = Git(self)
git.clone(url="https://github.com/libtom/libtommath.git", target=".")
git.checkout("03de03dee753442d4b23166982514639c4ccbc39")

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

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self)

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):
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["tommath"]


9 changes: 9 additions & 0 deletions recipes/libtommath/development/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest C)

find_package(libtommath CONFIG REQUIRED)



add_executable(example src/test_package.c)
target_link_libraries(example libtommath::libtommath)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 4,
"vendor": {
"conan": {}
},
"include": [
"C:\\Users\\jowr\\Repos\\TMP\\conan-center-index.win.git\\recipes\\libtommath\\development\\test_package\\build\\msvc-193-x86_64-14-release\\generators\\CMakePresets.json"
]
}
29 changes: 29 additions & 0 deletions recipes/libtommath/development/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os

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


class LibTomMathTestConan(ConanFile):
name = "libtommathtest"
version = "1.2.0-dev"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"

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

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

def layout(self):
self.folders.source = "src"
cmake_layout(self)

def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "example")
self.run(cmd, env="conanrun")
34 changes: 34 additions & 0 deletions recipes/libtommath/development/test_package/src/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "libtommath/tommath.h"

#include <stdio.h>
#include <stdlib.h>

#define check(V) \
if ((V) != MP_OKAY) { \
fprintf(stderr, #V " FAILURE\n"); \
return 1; \
}

int main() {
mp_int a, b, c;

check(mp_init(&a));
check(mp_init(&b));
check(mp_init(&c));

check(mp_rand(&a, 30));
check(mp_rand(&b, 30));

check(mp_add(&a, &b, &c));

printf("a = ");
check(mp_fwrite(&a, 10, stdout));
printf("\nb = ");
check(mp_fwrite(&b, 10, stdout));
printf("\na + b = ");
check(mp_fwrite(&c, 10, stdout));
printf("\n");

mp_clear_multi(&a, &b, &c, NULL);
return 0;
}
File renamed without changes.
File renamed without changes.

0 comments on commit db8cc58

Please sign in to comment.