diff --git a/recipes/libtommath/all/conandata.yml b/recipes/libtommath/all/conandata.yml index ecbf1c3cd0078..cdc64416010c8 100644 --- a/recipes/libtommath/all/conandata.yml +++ b/recipes/libtommath/all/conandata.yml @@ -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" diff --git a/recipes/libtommath/all/conanfile.py b/recipes/libtommath/all/conanfile.py index 6bdf6dd129d98..f9ebd1474071a 100644 --- a/recipes/libtommath/all/conanfile.py +++ b/recipes/libtommath/all/conanfile.py @@ -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], @@ -21,119 +28,76 @@ 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) + tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW" + 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") + if is_msvc(self): + # libtommath requires /O1 on MSVC Debug builds for dead code elimination. + # I could not find a way short of forcing settings.build_type=RelWithDebInfo to get that to work, though. + # Disabling the missing symbols directly instead. + # https://github.com/libtom/libtommath/blob/42b3fb07e7d504f61a04c7fca12e996d76a25251/s_mp_rand_platform.c#L120-L138 + file = "bn_s_mp_rand_platform.c" if Version(self.version) <= "1.3.0" else "s_mp_rand_platform.c" + for symbol in ["s_read_getrandom", "s_read_ltm_rng", "s_read_arc4random", "s_read_urandom"]: + replace_in_file(self, os.path.join(self.source_folder, file), + f"if ((err != MP_OKAY) && MP_HAS({symbol.upper()})", + f"// if ((err != MP_OKAY) && MP_HAS({symbol.upper()})") 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" diff --git a/recipes/libtommath/all/patches/0001-enable-building-dll-s-using-makefile-msvc.patch b/recipes/libtommath/all/patches/0001-enable-building-dll-s-using-makefile-msvc.patch deleted file mode 100644 index 8a24dc18457e4..0000000000000 --- a/recipes/libtommath/all/patches/0001-enable-building-dll-s-using-makefile-msvc.patch +++ /dev/null @@ -1,146 +0,0 @@ ---- makefile.msvc -+++ makefile.msvc -@@ -12,13 +12,16 @@ - #The following can be overridden from command line e.g. make -f makefile.msvc CC=gcc ARFLAGS=rcs - PREFIX = c:\devel - CFLAGS = /Ox -+LDFLAGS = - - #Compilation flags - LTM_CFLAGS = /nologo /I./ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /D__STDC_WANT_SECURE_LIB__=1 /D_CRT_HAS_CXX17=0 /Wall /wd4146 /wd4127 /wd4668 /wd4710 /wd4711 /wd4820 /wd5045 /WX $(CFLAGS) --LTM_LDFLAGS = advapi32.lib -+LTM_LDFLAGS = $(LDFLAGS) advapi32.lib - --#Libraries to be created (this makefile builds only static libraries) --LIBMAIN_S =tommath.lib -+#Libraries to be created -+LIBMAIN_S = tommath.lib -+LIBMAIN_I = tommath.dll.lib -+LIBMAIN_D = tommath.dll - - #List of objects to compile (all goes to tommath.lib) - OBJECTS=bn_cutoffs.obj bn_deprecated.obj bn_mp_2expt.obj bn_mp_abs.obj bn_mp_add.obj bn_mp_add_d.obj bn_mp_addmod.obj \ -@@ -67,15 +70,19 @@ - $(LIBMAIN_S): $(OBJECTS) - lib /out:$(LIBMAIN_S) $(OBJECTS) - -+#Create DLL + import library tommath.dll.lib -+$(LIBMAIN_D) $(LIBMAIN_I): $(OBJECTS) tommath.def -+ link /dll /out:$(LIBMAIN_D) /implib:$(LIBMAIN_I) /def:tommath.def $(LTM_LDFLAGS) $(OBJECTS) -+ - #Build test suite - test.exe: $(LIBMAIN_S) demo/shared.obj demo/test.obj - cl $(LTM_CFLAGS) $(TOBJECTS) $(LIBMAIN_S) $(LTM_LDFLAGS) demo/shared.c demo/test.c /Fe$@ - @echo NOTICE: start the tests by launching test.exe - - test_standalone: test.exe - @echo test_standalone is deprecated, please use make-target 'test.exe' - --all: $(LIBMAIN_S) test.exe -+all: $(LIBMAIN_S) test.exe $(LIBMAIN_D) - - tune: $(LIBMAIN_S) - $(MAKE) -C etc tune -@@ -85,9 +92,11 @@ clean: - @-cmd /c del /Q /S *.OBJ *.LIB *.EXE *.DLL 2>nul - - #Install the library + headers --install: $(LIBMAIN_S) -+install: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D) - cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin" - cmd /c if not exist "$(PREFIX)\lib" mkdir "$(PREFIX)\lib" - cmd /c if not exist "$(PREFIX)\include" mkdir "$(PREFIX)\include" - copy /Y $(LIBMAIN_S) "$(PREFIX)\lib" -+ copy /Y $(LIBMAIN_I) "$(PREFIX)\lib" -+ copy /Y $(LIBMAIN_D) "$(PREFIX)\bin" - copy /Y tommath*.h "$(PREFIX)\include" ---- bn_s_mp_rand_platform.c -+++ bn_s_mp_rand_platform.c -@@ -14,6 +14,12 @@ - arc4random_buf(p, n); - return MP_OKAY; - } -+#else -+static mp_err s_read_arc4random(void *p, size_t n) -+{ -+ (void)p; (void)n; -+ return MP_ERR; -+} - #endif - - #if defined(_WIN32) || defined(_WIN32_WCE) -@@ -46,6 +46,12 @@ - } - return CryptGenRandom(hProv, (DWORD)n, (BYTE *)p) == TRUE ? MP_OKAY : MP_ERR; - } -+#else -+static mp_err s_read_wincsp(void *p, size_t n) -+{ -+ (void)p; (void)n; -+ return MP_ERR; -+} - #endif /* WIN32 */ - - #if !defined(BN_S_READ_WINCSP_C) && defined(__linux__) && defined(__GLIBC_PREREQ) -@@ -73,6 +85,14 @@ - #endif - #endif - -+#ifndef BN_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. - */ -@@ -111,6 +131,12 @@ - close(fd); - return MP_OKAY; - } -+#else -+static mp_err s_read_urandom(void *p, size_t n) -+{ -+ (void)p; (void)n; -+ return MP_ERR; -+} - #endif - - #if defined(MP_PRNG_ENABLE_LTM_RNG) -@@ -126,6 +132,12 @@ - if (res != n) return MP_ERR; - return MP_OKAY; - } -+#else -+static mp_err s_read_ltm_rng(void *p, size_t n) -+{ -+ (void)p; (void)n; -+ return MP_ERR; -+} - #endif - - mp_err s_read_arc4random(void *p, size_t n); ---- tommath.def -+++ tommath.def -@@ -102,6 +102,7 @@ - mp_prime_strong_lucas_selfridge - mp_radix_size - mp_rand -+ mp_rand_source - mp_read_radix - mp_reduce - mp_reduce_2k ---- bn_mp_set_double.c -+++ bn_mp_set_double.c -@@ -3,7 +3,7 @@ - /* LibTomMath, multiple-precision integer library -- Tom St Denis */ - /* SPDX-License-Identifier: Unlicense */ - --#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559) -+#if 1 - mp_err mp_set_double(mp_int *a, double b) - { - uint64_t frac; diff --git a/recipes/libtommath/all/test_package/CMakeLists.txt b/recipes/libtommath/all/test_package/CMakeLists.txt index 90762dc612cbd..47004d99c9835 100644 --- a/recipes/libtommath/all/test_package/CMakeLists.txt +++ b/recipes/libtommath/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/libtommath/all/test_package/conanfile.py b/recipes/libtommath/all/test_package/conanfile.py index 9e09e219fdcb3..faf72798061c5 100644 --- a/recipes/libtommath/all/test_package/conanfile.py +++ b/recipes/libtommath/all/test_package/conanfile.py @@ -1,13 +1,19 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os -class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "pkg_config" +class TestLibTomMathConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" - def build_requirements(self): - self.build_requires("pkgconf/1.7.4") + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -15,6 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/libtommath/config.yml b/recipes/libtommath/config.yml index b8ea8afb5a353..8e76a74067f93 100644 --- a/recipes/libtommath/config.yml +++ b/recipes/libtommath/config.yml @@ -1,3 +1,7 @@ versions: + "1.3.0": + folder: "all" + "1.2.1": + folder: "all" "1.2.0": folder: "all"