Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conan v2 support for LibTomMath #16558

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
db8cc58
Create a new package for libtommath that supports conan v2
jowr Mar 14, 2023
8f3aee6
Started all over with an example package
jowr Mar 14, 2023
93684ae
Revert "Started all over with an example package"
jowr Mar 14, 2023
0c70cba
Revert "Create a new package for libtommath that supports conan v2"
jowr Mar 14, 2023
d2645b3
Use the upstream CMakeLists.txt to create a new package
jowr Mar 14, 2023
76cf054
Merge branch 'master' into package/libtommath
jowr Mar 14, 2023
66dbfbb
Included suggestions from the GitHub actions linter
jowr Mar 14, 2023
8cc99f3
Added a new linked library for non-MSVC Windows biulds
jowr Mar 15, 2023
e0d1758
Merge remote-tracking branch 'upstream/master' into package/libtommath
jowr Mar 15, 2023
a83fba6
Added a package_type
jowr Mar 15, 2023
8181502
Merge branch 'master' into package/libtommath
jowr Mar 16, 2023
e833b8e
Merge branch 'master' into package/libtommath
jowr Mar 20, 2023
a8668f0
Merge branch 'master' into package/libtommath
jowr Mar 27, 2023
b275915
Merge branch 'master' into package/libtommath
jowr Mar 29, 2023
cd1e0b6
Merge branch 'master' into package/libtommath
jowr Apr 11, 2023
9f17e88
Updated the version information to "cci.20221028" as suggested by the…
jowr Apr 19, 2023
dac84a7
Merge branch 'master' into package/libtommath
jowr Apr 19, 2023
9be2a62
Apply suggestions from code review
prince-chrismc Apr 26, 2023
a6a4195
Apply suggestions from code review
prince-chrismc Apr 27, 2023
79fae61
Apply suggestions from code review
prince-chrismc Apr 28, 2023
e94187c
generate target without namespace
uilianries Jun 28, 2023
6ea9333
support conan v2 for 1.2.0
uilianries Jun 28, 2023
3a8712e
fix windows build
uilianries Jun 28, 2023
50319e6
inject tool requires environment
uilianries Jun 28, 2023
14eb573
pass libtool as argument
uilianries Jun 29, 2023
66b656c
pass cross-compile flag for mac m1
uilianries Jun 30, 2023
e92cb09
Merge branch 'master' into package/libtommath
jcar87 Feb 12, 2024
a63d1ee
Merge branch 'master' into package/libtommath
uilianries Apr 2, 2024
7ced202
replace temporary version by official 1.3.0
uilianries Apr 2, 2024
40adbd4
Merge branch 'package/libtommath' of github.com:jowr/conan-center-ind…
uilianries Apr 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions recipes/libtommath/cmake/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sources:
# Newer versions at the top
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
"1.2.1-dev":
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
url: "https://github.com/libtom/libtommath/archive/03de03dee753442d4b23166982514639c4ccbc39.tar.gz"
sha256: "ab65fcfc88f7bd457b13a615228298935f05af17a0a8554ad0e3fba9812b03c2"
patches:
# Newer versions at the top
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
"1.2.1-dev":
- patch_file: "patches/0002-enable-building-dlls.patch"
patch_description: "add support for windows dlls"
patch_type: "portability"
123 changes: 123 additions & 0 deletions recipes/libtommath/cmake/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
from conan import ConanFile
from conan.tools.microsoft import is_msvc_static_runtime, is_msvc
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
from conan.tools.env import VirtualBuildEnv
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
import os


required_conan_version = ">=1.53.0"
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved


class LibTomMathConan(ConanFile):
name = "libtommath"
description = "LibTomMath is a free open source portable number theoretic multiple-precision integer library written entirely in C."
license = "Unlicense"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.libtom.net/"
topics = ("math", "mpi", "multi-precision")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _min_cppstd(self):
return None

# These are the oldest versions I could find in the docs
@property
def _compilers_minimum_version(self):
return {
"gcc": "4.1",
"Visual Studio": "8",
"clang": "3.3",
"apple-clang": "5.0",
}

def export_sources(self):
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
export_conandata_patches(self)

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

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
# for plain C projects only
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def layout(self):
cmake_layout(self, src_folder="src")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
# BUILD_SHARED_LIBS and POSITION_INDEPENDENT_CODE are automatically parsed when self.options.shared or self.options.fPIC exist
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
tc = CMakeToolchain(self)
# Boolean values are preferred instead of "ON"/"OFF"
tc.variables["PACKAGE_CUSTOM_DEFINITION"] = True
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
if is_msvc(self):
# don't use self.settings.compiler.runtime
tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self)
# # deps_cpp_info, deps_env_info and deps_user_info are no longer used
# if self.dependencies["dependency"].options.foobar:
# tc.variables["DEPENDENCY_LIBPATH"] = self.dependencies["dependency"].cpp_info.libdirs
# cache_variables should be used sparingly, example setting cmake policies
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
tc.generate()
# In case there are dependencies listed on requirements, CMakeDeps should be used
tc = CMakeDeps(self)
tc.generate()
# In case there are dependencies listed on build_requirements, VirtualBuildEnv should be used
tc = VirtualBuildEnv(self)
tc.generate(scope="build")
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved

def _patch_sources(self):
apply_conandata_patches(self)

def build(self):
self._patch_sources() # It can be apply_conandata_patches(self) only in case no more patches are needed
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

# some files extensions and folders are not allowed. Please, read the FAQs to get informed.
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
rmdir(self, os.path.join(self.package_folder, "share"))
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved

def package_info(self):
self.cpp_info.libs = ["tommath"]
self.cpp_info.set_property("cmake_file_name", "libtommath")
self.cpp_info.set_property("cmake_target_name", "libtommath::libtommath")
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
self.cpp_info.set_property("pkg_config_name", "libtommath")
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved

# If they are needed on Linux, m, pthread and dl are usually needed on FreeBSD too
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
self.cpp_info.system_libs.append("pthread")
self.cpp_info.system_libs.append("dl")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "LIBTOMMATH"
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
self.cpp_info.filenames["cmake_find_package_multi"] = "libtommath"
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
self.cpp_info.names["cmake_find_package"] = "LIBTOMMATH"
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
self.cpp_info.names["cmake_find_package_multi"] = "libtommath"
87 changes: 87 additions & 0 deletions recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -91,6 +91,14 @@ add_library(${PROJECT_NAME}
${HEADERS}
)

+if(BUILD_SHARED_LIBS AND MSVC)
+ target_sources(${PROJECT_NAME} PRIVATE "tommath.def")
+endif()
+
+if(WIN32 AND NOT MSVC)
+ target_link_libraries(${PROJECT_NAME} PRIVATE crypt32)
+endif()
+
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
--- s_mp_rand_platform.c
+++ s_mp_rand_platform.c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the patch is not related to generating DLLs. I would not include if possible, instead, I recommend you sending it as a patch to the upstream.

@@ -16,6 +16,16 @@ static mp_err s_read_arc4random(void *p, size_t n)
}
#endif

+/* Add a dummy function for s_read_arc4random
+ */
+#if !defined(S_READ_ARC4RANDOM_C)
+static mp_err s_read_arc4random(void *p, size_t n)
+{
+ (void)p; (void)n;
+ return MP_ERR;
+}
+#endif
+
#if defined(_WIN32)
#define S_READ_WINCSP_C

@@ -47,6 +57,16 @@ static mp_err s_read_wincsp(void *p, size_t n)
}
#endif /* WIN32 */

+/* Add a dummy function for s_read_wincsp
+ */
+#if !defined(S_READ_WINCSP_C)
+static mp_err s_read_wincsp(void *p, size_t n)
+{
+ (void)p; (void)n;
+ return MP_ERR;
+}
+#endif
+
#if !defined(S_READ_WINCSP_C) && defined(__linux__) && defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2, 25)
#define S_READ_GETRANDOM_C
@@ -72,6 +92,16 @@ static mp_err s_read_getrandom(void *p, size_t n)
#endif
#endif

+/* Add a dummy function for s_read_getrandom
+ */
+#if !defined(S_READ_GETRANDOM_C)
+static mp_err s_read_getrandom(void *p, size_t n)
+{
+ (void)p; (void)n;
+ return MP_ERR;
+}
+#endif
+
/* We assume all platforms besides windows provide "/dev/urandom".
* In case yours doesn't, define MP_NO_DEV_URANDOM at compile-time.
*/
@@ -112,6 +142,16 @@ static mp_err s_read_urandom(void *p, size_t n)
}
#endif

+/* Add a dummy function for s_read_urandom
+ */
+#if !defined(S_READ_URANDOM_C)
+static mp_err s_read_urandom(void *p, size_t n)
+{
+ (void)p; (void)n;
+ return MP_ERR;
+}
+#endif
+
mp_err s_read_arc4random(void *p, size_t n);
mp_err s_read_wincsp(void *p, size_t n);
mp_err s_read_getrandom(void *p, size_t n);
12 changes: 12 additions & 0 deletions recipes/libtommath/cmake/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.8)

project(test_package C) # if the project is pure C
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
# project(test_package CXX) # if the project uses c++
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved

find_package(libtommath REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
# don't link to ${CONAN_LIBS} or CONAN_PKG::package
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
target_link_libraries(${PROJECT_NAME} PRIVATE libtommath::libtommath)
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
# In case the target project need a specific C++ standard
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
# target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 27 additions & 0 deletions recipes/libtommath/cmake/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


# It will become the standard on Conan 2.x
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
class TestLibTomMathConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

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

def layout(self):
cmake_layout(self)

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

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
34 changes: 34 additions & 0 deletions recipes/libtommath/cmake/test_package/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;
}
8 changes: 8 additions & 0 deletions recipes/libtommath/cmake/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
19 changes: 19 additions & 0 deletions recipes/libtommath/cmake/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


# legacy validation with Conan 1.x
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
class TestLibTomMathV1Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

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

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
2 changes: 2 additions & 0 deletions recipes/libtommath/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"1.2.1-dev":
folder: "cmake"
"1.2.0":
folder: "all"