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

libtommath: migrate to Conan v2 #18852

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7834d28
Create a new package for libtommath that supports conan v2
jowr Mar 14, 2023
0985c39
Started all over with an example package
jowr Mar 14, 2023
d17ee2e
Revert "Started all over with an example package"
jowr Mar 14, 2023
3309639
Revert "Create a new package for libtommath that supports conan v2"
jowr Mar 14, 2023
ea14f8b
Use the upstream CMakeLists.txt to create a new package
jowr Mar 14, 2023
882db62
Included suggestions from the GitHub actions linter
jowr Mar 14, 2023
34bfa85
Added a new linked library for non-MSVC Windows biulds
jowr Mar 15, 2023
6189091
Added a package_type
jowr Mar 15, 2023
e6f0ec0
Updated the version information to "cci.20221028" as suggested by the…
jowr Apr 19, 2023
73a73c3
Apply suggestions from code review
prince-chrismc Apr 26, 2023
4a648a7
Apply suggestions from code review
prince-chrismc Apr 27, 2023
cd8225b
Apply suggestions from code review
prince-chrismc Apr 28, 2023
e288df7
generate target without namespace
uilianries Jun 28, 2023
0372dda
support conan v2 for 1.2.0
uilianries Jun 28, 2023
da55f6c
fix windows build
uilianries Jun 28, 2023
8557f77
inject tool requires environment
uilianries Jun 28, 2023
5e50a72
pass libtool as argument
uilianries Jun 29, 2023
aa23f7c
pass cross-compile flag for mac m1
uilianries Jun 30, 2023
fbf335d
libtommath: add package_type
valgur Nov 27, 2023
382bb8e
libtommath: add v1.2.1
valgur Nov 27, 2023
388c28e
libtommath: convert into a CMake project
valgur Nov 27, 2023
0424593
libtommath: fix BUILD_SHARED_LIBS not being set
valgur Nov 27, 2023
0f5be2c
libtommath: Debug build is broken on Windows
valgur Nov 28, 2023
7df1669
libtommath: merge 'all' and 'cmake' recipes
valgur Apr 9, 2024
37faf30
libtommath: fix MSVC Debug build
valgur Apr 11, 2024
330e9cb
libtommath: don't modify self.settings.build_type
valgur Jul 15, 2024
f42e0a2
libtommath: try to fix the MSVC build
valgur Aug 11, 2024
1828fa1
libtommath: brute-force a fix for the MSVC Debug dead-code eliminatio…
valgur Sep 3, 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
22 changes: 16 additions & 6 deletions recipes/libtommath/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
sources:
"1.3.0":
url: "https://github.com/libtom/libtommath/releases/download/v1.3.0/ltm-1.3.0.tar.xz"
sha256: "296272d93435991308eb73607600c034b558807a07e829e751142e65ccfa9d08"
"1.2.1":
source:
url: "https://github.com/libtom/libtommath/releases/download/v1.2.1/ltm-1.2.1.tar.xz"
sha256: "986025d7b374276fee2e30e99f3649e4ac0db8a02257a37ee10eae72abed0d1f"
cmakelists:
url: "https://raw.githubusercontent.com/libtom/libtommath/8314bde5e5c8e5d9331460130a9d1066e324f091/CMakeLists.txt"
sha256: "68f22dbed8d1fabab8819a7a482d1a74d0b1813b8527333fb767afcfc21c421f"
"1.2.0":
url: "https://github.com/libtom/libtommath/releases/download/v1.2.0/ltm-1.2.0.tar.xz"
sha256: "b7c75eecf680219484055fcedd686064409254ae44bc31a96c5032843c0e18b1"
patches:
"1.2.0":
- patch_file: "patches/0001-enable-building-dll-s-using-makefile-msvc.patch"
base_path: "source_subfolder"
source:
url: "https://github.com/libtom/libtommath/releases/download/v1.2.0/ltm-1.2.0.tar.xz"
sha256: "b7c75eecf680219484055fcedd686064409254ae44bc31a96c5032843c0e18b1"
cmakelists:
url: "https://raw.githubusercontent.com/libtom/libtommath/8314bde5e5c8e5d9331460130a9d1066e324f091/CMakeLists.txt"
sha256: "68f22dbed8d1fabab8819a7a482d1a74d0b1813b8527333fb767afcfc21c421f"
158 changes: 58 additions & 100 deletions recipes/libtommath/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
import os

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rm, rmdir, download, replace_in_file, save
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class LibTomMathConan(ConanFile):
name = "libtommath"
description = "LibTomMath is a free open source portable number theoretic multiple-precision integer library written entirely in C."
topics = "libtommath", "math", "multiple", "precision"
license = "Unlicense"
homepage = "https://www.libtom.net/"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.libtom.net/"
topics = ("math", "multi-precision")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -21,119 +28,70 @@ class LibTomMathConan(ConanFile):
"fPIC": True,
}

exports_sources = "patches/*"

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

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

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def build_requirements(self):
if self._settings_build.os == "Windows" and self.settings.compiler != "Visual Studio":
self.build_requires("make/4.3")
if self.settings.compiler != "Visual Studio" and self.settings.os != "Windows" and self.options.shared:
self.build_requires("libtool/2.4.6")
def layout(self):
cmake_layout(self, src_folder="src")

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

def _run_makefile(self, target=None):
target = target or ""
autotools = AutoToolsBuildEnvironment(self)
autotools.libs = []
if self.settings.os == "Windows" and self.settings.compiler != "Visual Studio":
autotools.link_flags.append("-lcrypt32")
if self.settings.os == "Macos" and self.settings.arch == "armv8":
# FIXME: should be handled by helper
autotools.link_flags.append("-arch arm64")
args = autotools.vars
args.update({
"PREFIX": self.package_folder,
})
if self.settings.compiler != "Visual Studio":
if tools.get_env("CC"):
args["CC"] = tools.get_env("CC")
if tools.get_env("LD"):
args["LD"] = tools.get_env("LD")
if tools.get_env("AR"):
args["AR"] = tools.get_env("AR")

args["LIBTOOL"] = "libtool"
arg_str = " ".join("{}=\"{}\"".format(k, v) for k, v in args.items())

with tools.environment_append(args):
with tools.chdir(self._source_subfolder):
if self.settings.compiler == "Visual Studio":
if self.options.shared:
target = "tommath.dll"
else:
target = "tommath.lib"
with tools.vcvars(self):
self.run("nmake -f makefile.msvc {} {}".format(
target,
arg_str,
), run_environment=True)
else:
if self.settings.os == "Windows":
makefile = "makefile.mingw"
if self.options.shared:
target = "libtommath.dll"
else:
target = "libtommath.a"
else:
if self.options.shared:
makefile = "makefile.shared"
else:
makefile = "makefile.unix"
self.run("{} -f {} {} {} -j{}".format(
tools.get_env("CONAN_MAKE_PROGRAM", "make"),
makefile,
target,
arg_str,
tools.cpu_count(),
), run_environment=True)
if Version(self.version) >= "1.3":
get(self, **self.conan_data["sources"][self.version], strip_root=True)
else:
get(self, **self.conan_data["sources"][self.version]["source"], strip_root=True)
download(self, **self.conan_data["sources"][self.version]["cmakelists"], filename="CMakeLists.txt")

def generate(self):
tc = CMakeToolchain(self)
if is_msvc(self) and self.settings.build_type == "Debug":
# libtommath requires at least /O1 on MSVC for dead code elimination
# https://github.com/libtom/libtommath/blob/42b3fb07e7d504f61a04c7fca12e996d76a25251/s_mp_rand_platform.c#L120-L138
tc.cache_variables["CMAKE_CXX_FLAGS_DEBUG_INIT"] = "/O1"
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
tc.generate()

def _patch_sources(self):
if Version(self.version) < "1.3":
save(self, os.path.join(self.source_folder, "sources.cmake"),
"file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c)\n"
"file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)\n")
# Disable installation of docs, which is not valid for < 1.3
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"# Windows uses a different help sytem.\nif(", "if(0 AND")

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
self._run_makefile()
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
if self.settings.os == "Windows":
# The mingw makefile uses `cmd`, which is only available on Windows
self.copy("*.a", src=self._source_subfolder, dst="lib")
self.copy("*.lib", src=self._source_subfolder, dst="lib")
self.copy("*.dll", src=self._source_subfolder, dst="bin")
self.copy("tommath.h", src=self._source_subfolder, dst="include")
else:
self._run_makefile("install")
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

if self.settings.compiler == "Visual Studio" and self.options.shared:
os.rename(os.path.join(self.package_folder, "lib", "tommath.dll.lib"),
os.path.join(self.package_folder, "lib", "tommath.lib"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "libtommath")
self.cpp_info.set_property("cmake_target_name", "libtommath")
self.cpp_info.set_property("pkg_config_name", "libtommath")

self.cpp_info.libs = ["tommath"]
if Version(self.version) < "1.3":
self.cpp_info.includedirs.append(os.path.join("include", "libtommath"))
if not self.options.shared:
if self.settings.os == "Windows":
self.cpp_info.system_libs = ["advapi32", "crypt32"]

self.cpp_info.names["pkg_config"] = "libtommath"

This file was deleted.

10 changes: 3 additions & 7 deletions recipes/libtommath/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package C)

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

include(FindPkgConfig)
pkg_check_modules(LibTomMath REQUIRED IMPORTED_TARGET libtommath)
find_package(libtommath REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::LibTomMath)
target_link_libraries(${PROJECT_NAME} PRIVATE libtommath)
Loading
Loading