From db8cc583739ef27e08e837b0d82c259aae1d46cb Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 14 Mar 2023 15:02:54 +0100 Subject: [PATCH 01/19] Create a new package for libtommath that supports conan v2 --- recipes/libtommath/config.yml | 4 +- recipes/libtommath/development/conanfile.py | 54 +++++++++++++++++++ .../development/test_package/CMakeLists.txt | 9 ++++ .../test_package/CMakeUserPresets.json | 9 ++++ .../development/test_package/conanfile.py | 29 ++++++++++ .../test_package/src/test_package.c | 34 ++++++++++++ .../libtommath/{all => release}/conandata.yml | 0 .../libtommath/{all => release}/conanfile.py | 0 ...e-building-dll-s-using-makefile-msvc.patch | 0 .../test_package/CMakeLists.txt | 0 .../test_package/conanfile.py | 0 .../test_package/test_package.c | 0 12 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 recipes/libtommath/development/conanfile.py create mode 100644 recipes/libtommath/development/test_package/CMakeLists.txt create mode 100644 recipes/libtommath/development/test_package/CMakeUserPresets.json create mode 100644 recipes/libtommath/development/test_package/conanfile.py create mode 100644 recipes/libtommath/development/test_package/src/test_package.c rename recipes/libtommath/{all => release}/conandata.yml (100%) rename recipes/libtommath/{all => release}/conanfile.py (100%) rename recipes/libtommath/{all => release}/patches/0001-enable-building-dll-s-using-makefile-msvc.patch (100%) rename recipes/libtommath/{all => release}/test_package/CMakeLists.txt (100%) rename recipes/libtommath/{all => release}/test_package/conanfile.py (100%) rename recipes/libtommath/{all => release}/test_package/test_package.c (100%) diff --git a/recipes/libtommath/config.yml b/recipes/libtommath/config.yml index b8ea8afb5a353..fcd34a2eefcbe 100644 --- a/recipes/libtommath/config.yml +++ b/recipes/libtommath/config.yml @@ -1,3 +1,5 @@ versions: + "1.2.0-dev": + folder: "development" "1.2.0": - folder: "all" + folder: "release" diff --git a/recipes/libtommath/development/conanfile.py b/recipes/libtommath/development/conanfile.py new file mode 100644 index 0000000000000..992f586f3a8dc --- /dev/null +++ b/recipes/libtommath/development/conanfile.py @@ -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"] + + diff --git a/recipes/libtommath/development/test_package/CMakeLists.txt b/recipes/libtommath/development/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..02c3b0c6591f8 --- /dev/null +++ b/recipes/libtommath/development/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/libtommath/development/test_package/CMakeUserPresets.json b/recipes/libtommath/development/test_package/CMakeUserPresets.json new file mode 100644 index 0000000000000..382419e65135f --- /dev/null +++ b/recipes/libtommath/development/test_package/CMakeUserPresets.json @@ -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" + ] +} \ No newline at end of file diff --git a/recipes/libtommath/development/test_package/conanfile.py b/recipes/libtommath/development/test_package/conanfile.py new file mode 100644 index 0000000000000..b9749b3bb19d3 --- /dev/null +++ b/recipes/libtommath/development/test_package/conanfile.py @@ -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") diff --git a/recipes/libtommath/development/test_package/src/test_package.c b/recipes/libtommath/development/test_package/src/test_package.c new file mode 100644 index 0000000000000..4deb4ecefcb4b --- /dev/null +++ b/recipes/libtommath/development/test_package/src/test_package.c @@ -0,0 +1,34 @@ +#include "libtommath/tommath.h" + +#include +#include + +#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; +} diff --git a/recipes/libtommath/all/conandata.yml b/recipes/libtommath/release/conandata.yml similarity index 100% rename from recipes/libtommath/all/conandata.yml rename to recipes/libtommath/release/conandata.yml diff --git a/recipes/libtommath/all/conanfile.py b/recipes/libtommath/release/conanfile.py similarity index 100% rename from recipes/libtommath/all/conanfile.py rename to recipes/libtommath/release/conanfile.py diff --git a/recipes/libtommath/all/patches/0001-enable-building-dll-s-using-makefile-msvc.patch b/recipes/libtommath/release/patches/0001-enable-building-dll-s-using-makefile-msvc.patch similarity index 100% rename from recipes/libtommath/all/patches/0001-enable-building-dll-s-using-makefile-msvc.patch rename to recipes/libtommath/release/patches/0001-enable-building-dll-s-using-makefile-msvc.patch diff --git a/recipes/libtommath/all/test_package/CMakeLists.txt b/recipes/libtommath/release/test_package/CMakeLists.txt similarity index 100% rename from recipes/libtommath/all/test_package/CMakeLists.txt rename to recipes/libtommath/release/test_package/CMakeLists.txt diff --git a/recipes/libtommath/all/test_package/conanfile.py b/recipes/libtommath/release/test_package/conanfile.py similarity index 100% rename from recipes/libtommath/all/test_package/conanfile.py rename to recipes/libtommath/release/test_package/conanfile.py diff --git a/recipes/libtommath/all/test_package/test_package.c b/recipes/libtommath/release/test_package/test_package.c similarity index 100% rename from recipes/libtommath/all/test_package/test_package.c rename to recipes/libtommath/release/test_package/test_package.c From 8f3aee678d740fa97489ef84b1484a6ad04f16df Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 14 Mar 2023 22:50:42 +0100 Subject: [PATCH 02/19] Started all over with an example package --- recipes/libtommath/all/conandata.yml | 16 ++ recipes/libtommath/all/conanfile.py | 162 ++++++++++++++++++ ...e-building-dll-s-using-makefile-msvc.patch | 146 ++++++++++++++++ .../patches/0002-enable-building-dlls.patch | 83 +++++++++ .../all/test_package/CMakeLists.txt | 12 ++ .../libtommath/all/test_package/conanfile.py | 27 +++ .../all/test_package/test_package.c | 34 ++++ .../all/test_v1_package/CMakeLists.txt | 8 + .../all/test_v1_package/conanfile.py | 19 ++ recipes/libtommath/config.yml | 5 +- 10 files changed, 510 insertions(+), 2 deletions(-) create mode 100644 recipes/libtommath/all/conandata.yml create mode 100644 recipes/libtommath/all/conanfile.py create mode 100644 recipes/libtommath/all/patches/0001-enable-building-dll-s-using-makefile-msvc.patch create mode 100644 recipes/libtommath/all/patches/0002-enable-building-dlls.patch create mode 100644 recipes/libtommath/all/test_package/CMakeLists.txt create mode 100644 recipes/libtommath/all/test_package/conanfile.py create mode 100644 recipes/libtommath/all/test_package/test_package.c create mode 100644 recipes/libtommath/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/libtommath/all/test_v1_package/conanfile.py diff --git a/recipes/libtommath/all/conandata.yml b/recipes/libtommath/all/conandata.yml new file mode 100644 index 0000000000000..d6d98021186be --- /dev/null +++ b/recipes/libtommath/all/conandata.yml @@ -0,0 +1,16 @@ +sources: + # Newer versions at the top + "1.2.0-dev": + url: "https://github.com/libtom/libtommath/archive/03de03dee753442d4b23166982514639c4ccbc39.tar.gz" + sha256: "ab65fcfc88f7bd457b13a615228298935f05af17a0a8554ad0e3fba9812b03c2" + "1.2.0": + url: "https://github.com/libtom/libtommath/releases/download/v1.2.0/ltm-1.2.0.tar.xz" + sha256: "b7c75eecf680219484055fcedd686064409254ae44bc31a96c5032843c0e18b1" +patches: + # Newer versions at the top + "1.2.0-dev": + - patch_file: "patches/0002-enable-building-dlls.patch" + patch_description: "add support for windows dlls" + "1.2.0": + - patch_file: "patches/0001-enable-building-dll-s-using-makefile-msvc.patch" + patch_description: "add support for windows dlls" diff --git a/recipes/libtommath/all/conanfile.py b/recipes/libtommath/all/conanfile.py new file mode 100644 index 0000000000000..d7454fd01a9ef --- /dev/null +++ b/recipes/libtommath/all/conanfile.py @@ -0,0 +1,162 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.microsoft import check_min_vs, is_msvc_static_runtime, is_msvc +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.env import VirtualBuildEnv +import os + + +required_conan_version = ">=1.53.0" + +# +# INFO: Please, remove all comments before pushing your PR! +# + + +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") + 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", + } + + # no exports_sources attribute, but export_sources(self) method instead + # this allows finer grain exportation of patches per version + def export_sources(self): + 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 + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + + def layout(self): + # src_folder must use the same source folder name the project + cmake_layout(self, src_folder="src") + + # def requirements(self): + # # prefer self.requires method instead of requires attribute + # self.requires("dependency/0.8.1") + + # def validate(self): + # # validate the minimum cpp standard supported. For C++ projects only + # if self.settings.compiler.cppstd: + # check_min_cppstd(self, self._min_cppstd) + # check_min_vs(self, 191) + # if not is_msvc(self): + # minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + # if minimum_version and Version(self.settings.compiler.version) < minimum_version: + # raise ConanInvalidConfiguration( + # f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." + # ) + # # in case it does not work in another configuration, it should validated here too + # if is_msvc(self) and self.options.shared: + # raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Visual Studio and msvc.") + + # if another tool than the compiler or CMake is required to build the project (pkgconf, bison, flex etc) + # def build_requirements(self): + # self.tool_requires("tool/x.y.z") + + 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 + tc = CMakeToolchain(self) + # Boolean values are preferred instead of "ON"/"OFF" + tc.variables["PACKAGE_CUSTOM_DEFINITION"] = True + 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" + 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") + + 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 + 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. + 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, "*.la", os.path.join(self.package_folder, "lib")) + 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.libs = ["tommath"] + + # # if package has an official FindPACKAGE.cmake listed in https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html#find-modules + # # examples: bzip2, freetype, gdal, icu, libcurl, libjpeg, libpng, libtiff, openssl, sqlite3, zlib... + # self.cpp_info.set_property("cmake_module_file_name", "PACKAGE") + # self.cpp_info.set_property("cmake_module_target_name", "PACKAGE::PACKAGE") + # if package provides a CMake config file (package-config.cmake or packageConfig.cmake, with package::package target, usually installed in /lib/cmake//) + self.cpp_info.set_property("cmake_file_name", "libtommath") + self.cpp_info.set_property("cmake_target_name", "libtommath::libtommath") + # if package provides a pkgconfig file (package.pc, usually installed in /lib/pkgconfig/) + self.cpp_info.set_property("pkg_config_name", "libtommath") + + # 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" + self.cpp_info.filenames["cmake_find_package_multi"] = "libtommath" + self.cpp_info.names["cmake_find_package"] = "LIBTOMMATH" + self.cpp_info.names["cmake_find_package_multi"] = "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 new file mode 100644 index 0000000000000..8a24dc18457e4 --- /dev/null +++ b/recipes/libtommath/all/patches/0001-enable-building-dll-s-using-makefile-msvc.patch @@ -0,0 +1,146 @@ +--- 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/patches/0002-enable-building-dlls.patch b/recipes/libtommath/all/patches/0002-enable-building-dlls.patch new file mode 100644 index 0000000000000..416188f2b94e6 --- /dev/null +++ b/recipes/libtommath/all/patches/0002-enable-building-dlls.patch @@ -0,0 +1,83 @@ +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -91,6 +91,10 @@ add_library(${PROJECT_NAME} + ${HEADERS} + ) + ++if(BUILD_SHARED_LIBS AND MSVC) ++ target_sources(${PROJECT_NAME} PRIVATE "tommath.def") ++endif() ++ + target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ +--- s_mp_rand_platform.c ++++ s_mp_rand_platform.c +@@ -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); diff --git a/recipes/libtommath/all/test_package/CMakeLists.txt b/recipes/libtommath/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..6cb8ec7927cd2 --- /dev/null +++ b/recipes/libtommath/all/test_package/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.8) + +project(test_package C) # if the project is pure C +# project(test_package CXX) # if the project uses c++ + +find_package(libtommath REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +# don't link to ${CONAN_LIBS} or CONAN_PKG::package +target_link_libraries(${PROJECT_NAME} PRIVATE libtommath::libtommath) +# In case the target project need a specific C++ standard +# target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/libtommath/all/test_package/conanfile.py b/recipes/libtommath/all/test_package/conanfile.py new file mode 100644 index 0000000000000..52b7eea658fee --- /dev/null +++ b/recipes/libtommath/all/test_package/conanfile.py @@ -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 +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") diff --git a/recipes/libtommath/all/test_package/test_package.c b/recipes/libtommath/all/test_package/test_package.c new file mode 100644 index 0000000000000..4deb4ecefcb4b --- /dev/null +++ b/recipes/libtommath/all/test_package/test_package.c @@ -0,0 +1,34 @@ +#include "libtommath/tommath.h" + +#include +#include + +#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; +} diff --git a/recipes/libtommath/all/test_v1_package/CMakeLists.txt b/recipes/libtommath/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..925ecbe19e448 --- /dev/null +++ b/recipes/libtommath/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/libtommath/all/test_v1_package/conanfile.py b/recipes/libtommath/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..78453e0085f23 --- /dev/null +++ b/recipes/libtommath/all/test_v1_package/conanfile.py @@ -0,0 +1,19 @@ +from conans import ConanFile, CMake +from conan.tools.build import cross_building +import os + + +# legacy validation with Conan 1.x +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) diff --git a/recipes/libtommath/config.yml b/recipes/libtommath/config.yml index fcd34a2eefcbe..270bcbfbc2901 100644 --- a/recipes/libtommath/config.yml +++ b/recipes/libtommath/config.yml @@ -1,5 +1,6 @@ versions: + # Newer versions at the top "1.2.0-dev": - folder: "development" + folder: all "1.2.0": - folder: "release" + folder: all From 93684ae2fb9bba2929da6e412fe88fbf94695b81 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 14 Mar 2023 23:03:50 +0100 Subject: [PATCH 03/19] Revert "Started all over with an example package" This reverts commit 8f3aee678d740fa97489ef84b1484a6ad04f16df. --- recipes/libtommath/all/conandata.yml | 16 -- recipes/libtommath/all/conanfile.py | 162 ------------------ ...e-building-dll-s-using-makefile-msvc.patch | 146 ---------------- .../patches/0002-enable-building-dlls.patch | 83 --------- .../all/test_package/CMakeLists.txt | 12 -- .../libtommath/all/test_package/conanfile.py | 27 --- .../all/test_package/test_package.c | 34 ---- .../all/test_v1_package/CMakeLists.txt | 8 - .../all/test_v1_package/conanfile.py | 19 -- recipes/libtommath/config.yml | 5 +- 10 files changed, 2 insertions(+), 510 deletions(-) delete mode 100644 recipes/libtommath/all/conandata.yml delete mode 100644 recipes/libtommath/all/conanfile.py delete mode 100644 recipes/libtommath/all/patches/0001-enable-building-dll-s-using-makefile-msvc.patch delete mode 100644 recipes/libtommath/all/patches/0002-enable-building-dlls.patch delete mode 100644 recipes/libtommath/all/test_package/CMakeLists.txt delete mode 100644 recipes/libtommath/all/test_package/conanfile.py delete mode 100644 recipes/libtommath/all/test_package/test_package.c delete mode 100644 recipes/libtommath/all/test_v1_package/CMakeLists.txt delete mode 100644 recipes/libtommath/all/test_v1_package/conanfile.py diff --git a/recipes/libtommath/all/conandata.yml b/recipes/libtommath/all/conandata.yml deleted file mode 100644 index d6d98021186be..0000000000000 --- a/recipes/libtommath/all/conandata.yml +++ /dev/null @@ -1,16 +0,0 @@ -sources: - # Newer versions at the top - "1.2.0-dev": - url: "https://github.com/libtom/libtommath/archive/03de03dee753442d4b23166982514639c4ccbc39.tar.gz" - sha256: "ab65fcfc88f7bd457b13a615228298935f05af17a0a8554ad0e3fba9812b03c2" - "1.2.0": - url: "https://github.com/libtom/libtommath/releases/download/v1.2.0/ltm-1.2.0.tar.xz" - sha256: "b7c75eecf680219484055fcedd686064409254ae44bc31a96c5032843c0e18b1" -patches: - # Newer versions at the top - "1.2.0-dev": - - patch_file: "patches/0002-enable-building-dlls.patch" - patch_description: "add support for windows dlls" - "1.2.0": - - patch_file: "patches/0001-enable-building-dll-s-using-makefile-msvc.patch" - patch_description: "add support for windows dlls" diff --git a/recipes/libtommath/all/conanfile.py b/recipes/libtommath/all/conanfile.py deleted file mode 100644 index d7454fd01a9ef..0000000000000 --- a/recipes/libtommath/all/conanfile.py +++ /dev/null @@ -1,162 +0,0 @@ -from conan import ConanFile -from conan.errors import ConanInvalidConfiguration -from conan.tools.microsoft import check_min_vs, is_msvc_static_runtime, is_msvc -from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file -from conan.tools.build import check_min_cppstd -from conan.tools.scm import Version -from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout -from conan.tools.env import VirtualBuildEnv -import os - - -required_conan_version = ">=1.53.0" - -# -# INFO: Please, remove all comments before pushing your PR! -# - - -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") - 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", - } - - # no exports_sources attribute, but export_sources(self) method instead - # this allows finer grain exportation of patches per version - def export_sources(self): - 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 - self.settings.rm_safe("compiler.libcxx") - self.settings.rm_safe("compiler.cppstd") - - def layout(self): - # src_folder must use the same source folder name the project - cmake_layout(self, src_folder="src") - - # def requirements(self): - # # prefer self.requires method instead of requires attribute - # self.requires("dependency/0.8.1") - - # def validate(self): - # # validate the minimum cpp standard supported. For C++ projects only - # if self.settings.compiler.cppstd: - # check_min_cppstd(self, self._min_cppstd) - # check_min_vs(self, 191) - # if not is_msvc(self): - # minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) - # if minimum_version and Version(self.settings.compiler.version) < minimum_version: - # raise ConanInvalidConfiguration( - # f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." - # ) - # # in case it does not work in another configuration, it should validated here too - # if is_msvc(self) and self.options.shared: - # raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Visual Studio and msvc.") - - # if another tool than the compiler or CMake is required to build the project (pkgconf, bison, flex etc) - # def build_requirements(self): - # self.tool_requires("tool/x.y.z") - - 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 - tc = CMakeToolchain(self) - # Boolean values are preferred instead of "ON"/"OFF" - tc.variables["PACKAGE_CUSTOM_DEFINITION"] = True - 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" - 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") - - 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 - 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. - 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, "*.la", os.path.join(self.package_folder, "lib")) - 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.libs = ["tommath"] - - # # if package has an official FindPACKAGE.cmake listed in https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html#find-modules - # # examples: bzip2, freetype, gdal, icu, libcurl, libjpeg, libpng, libtiff, openssl, sqlite3, zlib... - # self.cpp_info.set_property("cmake_module_file_name", "PACKAGE") - # self.cpp_info.set_property("cmake_module_target_name", "PACKAGE::PACKAGE") - # if package provides a CMake config file (package-config.cmake or packageConfig.cmake, with package::package target, usually installed in /lib/cmake//) - self.cpp_info.set_property("cmake_file_name", "libtommath") - self.cpp_info.set_property("cmake_target_name", "libtommath::libtommath") - # if package provides a pkgconfig file (package.pc, usually installed in /lib/pkgconfig/) - self.cpp_info.set_property("pkg_config_name", "libtommath") - - # 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" - self.cpp_info.filenames["cmake_find_package_multi"] = "libtommath" - self.cpp_info.names["cmake_find_package"] = "LIBTOMMATH" - self.cpp_info.names["cmake_find_package_multi"] = "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/patches/0002-enable-building-dlls.patch b/recipes/libtommath/all/patches/0002-enable-building-dlls.patch deleted file mode 100644 index 416188f2b94e6..0000000000000 --- a/recipes/libtommath/all/patches/0002-enable-building-dlls.patch +++ /dev/null @@ -1,83 +0,0 @@ ---- CMakeLists.txt -+++ CMakeLists.txt -@@ -91,6 +91,10 @@ add_library(${PROJECT_NAME} - ${HEADERS} - ) - -+if(BUILD_SHARED_LIBS AND MSVC) -+ target_sources(${PROJECT_NAME} PRIVATE "tommath.def") -+endif() -+ - target_include_directories(${PROJECT_NAME} PUBLIC - $ - $ ---- s_mp_rand_platform.c -+++ s_mp_rand_platform.c -@@ -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); diff --git a/recipes/libtommath/all/test_package/CMakeLists.txt b/recipes/libtommath/all/test_package/CMakeLists.txt deleted file mode 100644 index 6cb8ec7927cd2..0000000000000 --- a/recipes/libtommath/all/test_package/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -cmake_minimum_required(VERSION 3.8) - -project(test_package C) # if the project is pure C -# project(test_package CXX) # if the project uses c++ - -find_package(libtommath REQUIRED CONFIG) - -add_executable(${PROJECT_NAME} test_package.c) -# don't link to ${CONAN_LIBS} or CONAN_PKG::package -target_link_libraries(${PROJECT_NAME} PRIVATE libtommath::libtommath) -# In case the target project need a specific C++ standard -# target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/libtommath/all/test_package/conanfile.py b/recipes/libtommath/all/test_package/conanfile.py deleted file mode 100644 index 52b7eea658fee..0000000000000 --- a/recipes/libtommath/all/test_package/conanfile.py +++ /dev/null @@ -1,27 +0,0 @@ -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 -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") diff --git a/recipes/libtommath/all/test_package/test_package.c b/recipes/libtommath/all/test_package/test_package.c deleted file mode 100644 index 4deb4ecefcb4b..0000000000000 --- a/recipes/libtommath/all/test_package/test_package.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "libtommath/tommath.h" - -#include -#include - -#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; -} diff --git a/recipes/libtommath/all/test_v1_package/CMakeLists.txt b/recipes/libtommath/all/test_v1_package/CMakeLists.txt deleted file mode 100644 index 925ecbe19e448..0000000000000 --- a/recipes/libtommath/all/test_v1_package/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -project(test_package) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ - ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/libtommath/all/test_v1_package/conanfile.py b/recipes/libtommath/all/test_v1_package/conanfile.py deleted file mode 100644 index 78453e0085f23..0000000000000 --- a/recipes/libtommath/all/test_v1_package/conanfile.py +++ /dev/null @@ -1,19 +0,0 @@ -from conans import ConanFile, CMake -from conan.tools.build import cross_building -import os - - -# legacy validation with Conan 1.x -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) diff --git a/recipes/libtommath/config.yml b/recipes/libtommath/config.yml index 270bcbfbc2901..fcd34a2eefcbe 100644 --- a/recipes/libtommath/config.yml +++ b/recipes/libtommath/config.yml @@ -1,6 +1,5 @@ versions: - # Newer versions at the top "1.2.0-dev": - folder: all + folder: "development" "1.2.0": - folder: all + folder: "release" From 0c70cba3a96824bfb049228994c665c588f8a92a Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 14 Mar 2023 23:03:56 +0100 Subject: [PATCH 04/19] Revert "Create a new package for libtommath that supports conan v2" This reverts commit db8cc583739ef27e08e837b0d82c259aae1d46cb. --- .../libtommath/{release => all}/conandata.yml | 0 .../libtommath/{release => all}/conanfile.py | 0 ...e-building-dll-s-using-makefile-msvc.patch | 0 .../test_package/CMakeLists.txt | 0 .../test_package/conanfile.py | 0 .../test_package/test_package.c | 0 recipes/libtommath/config.yml | 4 +- recipes/libtommath/development/conanfile.py | 54 ------------------- .../development/test_package/CMakeLists.txt | 9 ---- .../test_package/CMakeUserPresets.json | 9 ---- .../development/test_package/conanfile.py | 29 ---------- .../test_package/src/test_package.c | 34 ------------ 12 files changed, 1 insertion(+), 138 deletions(-) rename recipes/libtommath/{release => all}/conandata.yml (100%) rename recipes/libtommath/{release => all}/conanfile.py (100%) rename recipes/libtommath/{release => all}/patches/0001-enable-building-dll-s-using-makefile-msvc.patch (100%) rename recipes/libtommath/{release => all}/test_package/CMakeLists.txt (100%) rename recipes/libtommath/{release => all}/test_package/conanfile.py (100%) rename recipes/libtommath/{release => all}/test_package/test_package.c (100%) delete mode 100644 recipes/libtommath/development/conanfile.py delete mode 100644 recipes/libtommath/development/test_package/CMakeLists.txt delete mode 100644 recipes/libtommath/development/test_package/CMakeUserPresets.json delete mode 100644 recipes/libtommath/development/test_package/conanfile.py delete mode 100644 recipes/libtommath/development/test_package/src/test_package.c diff --git a/recipes/libtommath/release/conandata.yml b/recipes/libtommath/all/conandata.yml similarity index 100% rename from recipes/libtommath/release/conandata.yml rename to recipes/libtommath/all/conandata.yml diff --git a/recipes/libtommath/release/conanfile.py b/recipes/libtommath/all/conanfile.py similarity index 100% rename from recipes/libtommath/release/conanfile.py rename to recipes/libtommath/all/conanfile.py diff --git a/recipes/libtommath/release/patches/0001-enable-building-dll-s-using-makefile-msvc.patch b/recipes/libtommath/all/patches/0001-enable-building-dll-s-using-makefile-msvc.patch similarity index 100% rename from recipes/libtommath/release/patches/0001-enable-building-dll-s-using-makefile-msvc.patch rename to recipes/libtommath/all/patches/0001-enable-building-dll-s-using-makefile-msvc.patch diff --git a/recipes/libtommath/release/test_package/CMakeLists.txt b/recipes/libtommath/all/test_package/CMakeLists.txt similarity index 100% rename from recipes/libtommath/release/test_package/CMakeLists.txt rename to recipes/libtommath/all/test_package/CMakeLists.txt diff --git a/recipes/libtommath/release/test_package/conanfile.py b/recipes/libtommath/all/test_package/conanfile.py similarity index 100% rename from recipes/libtommath/release/test_package/conanfile.py rename to recipes/libtommath/all/test_package/conanfile.py diff --git a/recipes/libtommath/release/test_package/test_package.c b/recipes/libtommath/all/test_package/test_package.c similarity index 100% rename from recipes/libtommath/release/test_package/test_package.c rename to recipes/libtommath/all/test_package/test_package.c diff --git a/recipes/libtommath/config.yml b/recipes/libtommath/config.yml index fcd34a2eefcbe..b8ea8afb5a353 100644 --- a/recipes/libtommath/config.yml +++ b/recipes/libtommath/config.yml @@ -1,5 +1,3 @@ versions: - "1.2.0-dev": - folder: "development" "1.2.0": - folder: "release" + folder: "all" diff --git a/recipes/libtommath/development/conanfile.py b/recipes/libtommath/development/conanfile.py deleted file mode 100644 index 992f586f3a8dc..0000000000000 --- a/recipes/libtommath/development/conanfile.py +++ /dev/null @@ -1,54 +0,0 @@ -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"] - - diff --git a/recipes/libtommath/development/test_package/CMakeLists.txt b/recipes/libtommath/development/test_package/CMakeLists.txt deleted file mode 100644 index 02c3b0c6591f8..0000000000000 --- a/recipes/libtommath/development/test_package/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -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) diff --git a/recipes/libtommath/development/test_package/CMakeUserPresets.json b/recipes/libtommath/development/test_package/CMakeUserPresets.json deleted file mode 100644 index 382419e65135f..0000000000000 --- a/recipes/libtommath/development/test_package/CMakeUserPresets.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "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" - ] -} \ No newline at end of file diff --git a/recipes/libtommath/development/test_package/conanfile.py b/recipes/libtommath/development/test_package/conanfile.py deleted file mode 100644 index b9749b3bb19d3..0000000000000 --- a/recipes/libtommath/development/test_package/conanfile.py +++ /dev/null @@ -1,29 +0,0 @@ -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") diff --git a/recipes/libtommath/development/test_package/src/test_package.c b/recipes/libtommath/development/test_package/src/test_package.c deleted file mode 100644 index 4deb4ecefcb4b..0000000000000 --- a/recipes/libtommath/development/test_package/src/test_package.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "libtommath/tommath.h" - -#include -#include - -#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; -} From d2645b3bb6aa7e907af1128d6f45433a8170d77e Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 14 Mar 2023 23:09:25 +0100 Subject: [PATCH 05/19] Use the upstream CMakeLists.txt to create a new package --- recipes/libtommath/cmake/conandata.yml | 10 ++ recipes/libtommath/cmake/conanfile.py | 125 ++++++++++++++++++ .../patches/0002-enable-building-dlls.patch | 83 ++++++++++++ .../cmake/test_package/CMakeLists.txt | 12 ++ .../cmake/test_package/conanfile.py | 27 ++++ .../cmake/test_package/test_package.c | 34 +++++ .../cmake/test_v1_package/CMakeLists.txt | 8 ++ .../cmake/test_v1_package/conanfile.py | 19 +++ recipes/libtommath/config.yml | 2 + 9 files changed, 320 insertions(+) create mode 100644 recipes/libtommath/cmake/conandata.yml create mode 100644 recipes/libtommath/cmake/conanfile.py create mode 100644 recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch create mode 100644 recipes/libtommath/cmake/test_package/CMakeLists.txt create mode 100644 recipes/libtommath/cmake/test_package/conanfile.py create mode 100644 recipes/libtommath/cmake/test_package/test_package.c create mode 100644 recipes/libtommath/cmake/test_v1_package/CMakeLists.txt create mode 100644 recipes/libtommath/cmake/test_v1_package/conanfile.py diff --git a/recipes/libtommath/cmake/conandata.yml b/recipes/libtommath/cmake/conandata.yml new file mode 100644 index 0000000000000..7007dd66c5bb0 --- /dev/null +++ b/recipes/libtommath/cmake/conandata.yml @@ -0,0 +1,10 @@ +sources: + # Newer versions at the top + "1.2.1-dev": + url: "https://github.com/libtom/libtommath/archive/03de03dee753442d4b23166982514639c4ccbc39.tar.gz" + sha256: "ab65fcfc88f7bd457b13a615228298935f05af17a0a8554ad0e3fba9812b03c2" +patches: + # Newer versions at the top + "1.2.1-dev": + - patch_file: "patches/0002-enable-building-dlls.patch" + patch_description: "add support for windows dlls" diff --git a/recipes/libtommath/cmake/conanfile.py b/recipes/libtommath/cmake/conanfile.py new file mode 100644 index 0000000000000..0483ed68ff405 --- /dev/null +++ b/recipes/libtommath/cmake/conanfile.py @@ -0,0 +1,125 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.microsoft import check_min_vs, is_msvc_static_runtime, is_msvc +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.env import VirtualBuildEnv +import os + + +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." + license = "Unlicense" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://www.libtom.net/" + topics = ("math", "mpi", "multi-precision") + 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): + 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 + 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 + tc = CMakeToolchain(self) + # Boolean values are preferred instead of "ON"/"OFF" + tc.variables["PACKAGE_CUSTOM_DEFINITION"] = True + 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" + 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") + + 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 + 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. + 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, "*.la", os.path.join(self.package_folder, "lib")) + 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.libs = ["tommath"] + self.cpp_info.set_property("cmake_file_name", "libtommath") + self.cpp_info.set_property("cmake_target_name", "libtommath::libtommath") + self.cpp_info.set_property("pkg_config_name", "libtommath") + + # 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" + self.cpp_info.filenames["cmake_find_package_multi"] = "libtommath" + self.cpp_info.names["cmake_find_package"] = "LIBTOMMATH" + self.cpp_info.names["cmake_find_package_multi"] = "libtommath" diff --git a/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch b/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch new file mode 100644 index 0000000000000..416188f2b94e6 --- /dev/null +++ b/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch @@ -0,0 +1,83 @@ +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -91,6 +91,10 @@ add_library(${PROJECT_NAME} + ${HEADERS} + ) + ++if(BUILD_SHARED_LIBS AND MSVC) ++ target_sources(${PROJECT_NAME} PRIVATE "tommath.def") ++endif() ++ + target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ +--- s_mp_rand_platform.c ++++ s_mp_rand_platform.c +@@ -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); diff --git a/recipes/libtommath/cmake/test_package/CMakeLists.txt b/recipes/libtommath/cmake/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..6cb8ec7927cd2 --- /dev/null +++ b/recipes/libtommath/cmake/test_package/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.8) + +project(test_package C) # if the project is pure C +# project(test_package CXX) # if the project uses c++ + +find_package(libtommath REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +# don't link to ${CONAN_LIBS} or CONAN_PKG::package +target_link_libraries(${PROJECT_NAME} PRIVATE libtommath::libtommath) +# In case the target project need a specific C++ standard +# target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/libtommath/cmake/test_package/conanfile.py b/recipes/libtommath/cmake/test_package/conanfile.py new file mode 100644 index 0000000000000..52b7eea658fee --- /dev/null +++ b/recipes/libtommath/cmake/test_package/conanfile.py @@ -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 +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") diff --git a/recipes/libtommath/cmake/test_package/test_package.c b/recipes/libtommath/cmake/test_package/test_package.c new file mode 100644 index 0000000000000..4deb4ecefcb4b --- /dev/null +++ b/recipes/libtommath/cmake/test_package/test_package.c @@ -0,0 +1,34 @@ +#include "libtommath/tommath.h" + +#include +#include + +#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; +} diff --git a/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt b/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..925ecbe19e448 --- /dev/null +++ b/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/libtommath/cmake/test_v1_package/conanfile.py b/recipes/libtommath/cmake/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..78453e0085f23 --- /dev/null +++ b/recipes/libtommath/cmake/test_v1_package/conanfile.py @@ -0,0 +1,19 @@ +from conans import ConanFile, CMake +from conan.tools.build import cross_building +import os + + +# legacy validation with Conan 1.x +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) diff --git a/recipes/libtommath/config.yml b/recipes/libtommath/config.yml index b8ea8afb5a353..dbc622ce6c93c 100644 --- a/recipes/libtommath/config.yml +++ b/recipes/libtommath/config.yml @@ -1,3 +1,5 @@ versions: + "1.2.1-dev": + folder: "cmake" "1.2.0": folder: "all" From 66dbfbbd5d9b1a46f9d3308c5beaf32e273384db Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 14 Mar 2023 23:19:58 +0100 Subject: [PATCH 06/19] Included suggestions from the GitHub actions linter --- recipes/libtommath/cmake/conandata.yml | 1 + recipes/libtommath/cmake/conanfile.py | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/recipes/libtommath/cmake/conandata.yml b/recipes/libtommath/cmake/conandata.yml index 7007dd66c5bb0..bcfdbfaede95b 100644 --- a/recipes/libtommath/cmake/conandata.yml +++ b/recipes/libtommath/cmake/conandata.yml @@ -8,3 +8,4 @@ patches: "1.2.1-dev": - patch_file: "patches/0002-enable-building-dlls.patch" patch_description: "add support for windows dlls" + patch_type: "portability" diff --git a/recipes/libtommath/cmake/conanfile.py b/recipes/libtommath/cmake/conanfile.py index 0483ed68ff405..fe5ef92914ba7 100644 --- a/recipes/libtommath/cmake/conanfile.py +++ b/recipes/libtommath/cmake/conanfile.py @@ -1,9 +1,6 @@ from conan import ConanFile -from conan.errors import ConanInvalidConfiguration -from conan.tools.microsoft import check_min_vs, is_msvc_static_runtime, is_msvc -from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file -from conan.tools.build import check_min_cppstd -from conan.tools.scm import Version +from conan.tools.microsoft import is_msvc_static_runtime, is_msvc +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout from conan.tools.env import VirtualBuildEnv import os From 8cc99f3f3e563f67ac00eed6fcf5353f48207430 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Wed, 15 Mar 2023 09:24:18 +0100 Subject: [PATCH 07/19] Added a new linked library for non-MSVC Windows biulds --- .../cmake/patches/0002-enable-building-dlls.patch | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch b/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch index 416188f2b94e6..162dc86e20416 100644 --- a/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch +++ b/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch @@ -1,12 +1,16 @@ --- CMakeLists.txt +++ CMakeLists.txt -@@ -91,6 +91,10 @@ add_library(${PROJECT_NAME} +@@ -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 $ From a83fba626ba814526b75df27b114785b5b3f8b6e Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Wed, 15 Mar 2023 19:06:18 +0100 Subject: [PATCH 08/19] Added a package_type --- recipes/libtommath/cmake/conanfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes/libtommath/cmake/conanfile.py b/recipes/libtommath/cmake/conanfile.py index fe5ef92914ba7..d4100ced8f794 100644 --- a/recipes/libtommath/cmake/conanfile.py +++ b/recipes/libtommath/cmake/conanfile.py @@ -16,6 +16,7 @@ class LibTomMathConan(ConanFile): 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], From 9f17e88d15055e56db5a74c6ab2636e19398ed22 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Wed, 19 Apr 2023 15:27:35 +0200 Subject: [PATCH 09/19] Updated the version information to "cci.20221028" as suggested by the reviewer --- recipes/libtommath/cmake/conandata.yml | 4 ++-- recipes/libtommath/config.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/recipes/libtommath/cmake/conandata.yml b/recipes/libtommath/cmake/conandata.yml index bcfdbfaede95b..ed741eb822fd6 100644 --- a/recipes/libtommath/cmake/conandata.yml +++ b/recipes/libtommath/cmake/conandata.yml @@ -1,11 +1,11 @@ sources: # Newer versions at the top - "1.2.1-dev": + "cci.20221028": url: "https://github.com/libtom/libtommath/archive/03de03dee753442d4b23166982514639c4ccbc39.tar.gz" sha256: "ab65fcfc88f7bd457b13a615228298935f05af17a0a8554ad0e3fba9812b03c2" patches: # Newer versions at the top - "1.2.1-dev": + "cci.20221028": - patch_file: "patches/0002-enable-building-dlls.patch" patch_description: "add support for windows dlls" patch_type: "portability" diff --git a/recipes/libtommath/config.yml b/recipes/libtommath/config.yml index dbc622ce6c93c..0c26ae5f72951 100644 --- a/recipes/libtommath/config.yml +++ b/recipes/libtommath/config.yml @@ -1,5 +1,5 @@ versions: - "1.2.1-dev": + "cci.20221028": folder: "cmake" "1.2.0": folder: "all" From 9be2a620ffbef3d637d32a096afbc7fd270b5dce Mon Sep 17 00:00:00 2001 From: Chris Mc Date: Wed, 26 Apr 2023 12:01:47 -0700 Subject: [PATCH 10/19] Apply suggestions from code review --- recipes/libtommath/cmake/conandata.yml | 2 -- recipes/libtommath/cmake/conanfile.py | 37 +------------------------- 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/recipes/libtommath/cmake/conandata.yml b/recipes/libtommath/cmake/conandata.yml index ed741eb822fd6..e358b71b98af2 100644 --- a/recipes/libtommath/cmake/conandata.yml +++ b/recipes/libtommath/cmake/conandata.yml @@ -1,10 +1,8 @@ sources: - # Newer versions at the top "cci.20221028": url: "https://github.com/libtom/libtommath/archive/03de03dee753442d4b23166982514639c4ccbc39.tar.gz" sha256: "ab65fcfc88f7bd457b13a615228298935f05af17a0a8554ad0e3fba9812b03c2" patches: - # Newer versions at the top "cci.20221028": - patch_file: "patches/0002-enable-building-dlls.patch" patch_description: "add support for windows dlls" diff --git a/recipes/libtommath/cmake/conanfile.py b/recipes/libtommath/cmake/conanfile.py index d4100ced8f794..7231e963040fe 100644 --- a/recipes/libtommath/cmake/conanfile.py +++ b/recipes/libtommath/cmake/conanfile.py @@ -27,20 +27,6 @@ class LibTomMathConan(ConanFile): "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): export_conandata_patches(self) @@ -51,7 +37,6 @@ def config_options(self): def configure(self): if self.options.shared: self.options.rm_safe("fPIC") - # for plain C projects only self.settings.rm_safe("compiler.libcxx") self.settings.rm_safe("compiler.cppstd") @@ -62,31 +47,11 @@ 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 tc = CMakeToolchain(self) - # Boolean values are preferred instead of "ON"/"OFF" - tc.variables["PACKAGE_CUSTOM_DEFINITION"] = True - 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" - 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") - - 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 + apply_conandata_patches(self) cmake = CMake(self) cmake.configure() cmake.build() From a6a41956bcbc58976c06740190d71e0fa6bab17b Mon Sep 17 00:00:00 2001 From: Chris Mc Date: Thu, 27 Apr 2023 08:12:06 -0700 Subject: [PATCH 11/19] Apply suggestions from code review --- recipes/libtommath/cmake/conanfile.py | 19 ++++--------------- .../cmake/test_package/CMakeLists.txt | 8 ++------ .../cmake/test_package/conanfile.py | 1 - .../cmake/test_v1_package/CMakeLists.txt | 4 ++++ .../cmake/test_v1_package/conanfile.py | 1 - 5 files changed, 10 insertions(+), 23 deletions(-) diff --git a/recipes/libtommath/cmake/conanfile.py b/recipes/libtommath/cmake/conanfile.py index 7231e963040fe..d4d15a757d72c 100644 --- a/recipes/libtommath/cmake/conanfile.py +++ b/recipes/libtommath/cmake/conanfile.py @@ -1,12 +1,10 @@ from conan import ConanFile -from conan.tools.microsoft import is_msvc_static_runtime, is_msvc from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir -from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout -from conan.tools.env import VirtualBuildEnv +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout import os -required_conan_version = ">=1.53.0" +required_conan_version = ">=1.54.0" class LibTomMathConan(ConanFile): @@ -61,19 +59,12 @@ def package(self): cmake = CMake(self) cmake.install() - # some files extensions and folders are not allowed. Please, read the FAQs to get informed. - 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, "*.la", os.path.join(self.package_folder, "lib")) - 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.libs = ["tommath"] self.cpp_info.set_property("cmake_file_name", "libtommath") - self.cpp_info.set_property("cmake_target_name", "libtommath::libtommath") - self.cpp_info.set_property("pkg_config_name", "libtommath") + self.cpp_info.set_property("cmake_target_name", "libtommath") # If they are needed on Linux, m, pthread and dl are usually needed on FreeBSD too if self.settings.os in ["Linux", "FreeBSD"]: @@ -82,7 +73,5 @@ def package_info(self): 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" - self.cpp_info.filenames["cmake_find_package_multi"] = "libtommath" - self.cpp_info.names["cmake_find_package"] = "LIBTOMMATH" + self.cpp_info.names["cmake_find_package"] = "libtommath" self.cpp_info.names["cmake_find_package_multi"] = "libtommath" diff --git a/recipes/libtommath/cmake/test_package/CMakeLists.txt b/recipes/libtommath/cmake/test_package/CMakeLists.txt index 6cb8ec7927cd2..3b58e6e9fc16a 100644 --- a/recipes/libtommath/cmake/test_package/CMakeLists.txt +++ b/recipes/libtommath/cmake/test_package/CMakeLists.txt @@ -1,12 +1,8 @@ cmake_minimum_required(VERSION 3.8) -project(test_package C) # if the project is pure C -# project(test_package CXX) # if the project uses c++ +project(test_package C) find_package(libtommath REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) -# don't link to ${CONAN_LIBS} or CONAN_PKG::package -target_link_libraries(${PROJECT_NAME} PRIVATE libtommath::libtommath) -# In case the target project need a specific C++ standard -# target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) +target_link_libraries(${PROJECT_NAME} PRIVATE libtommath) diff --git a/recipes/libtommath/cmake/test_package/conanfile.py b/recipes/libtommath/cmake/test_package/conanfile.py index 52b7eea658fee..faf72798061c5 100644 --- a/recipes/libtommath/cmake/test_package/conanfile.py +++ b/recipes/libtommath/cmake/test_package/conanfile.py @@ -4,7 +4,6 @@ import os -# It will become the standard on Conan 2.x class TestLibTomMathConan(ConanFile): settings = "os", "arch", "compiler", "build_type" generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" diff --git a/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt b/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt index 925ecbe19e448..9a608511cc7c9 100644 --- a/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt +++ b/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt @@ -4,5 +4,9 @@ project(test_package) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup(TARGETS) +# workaround v1 legacy generators always haveing namespaces +add_library(libtommath) +target_link_libraries(libtommath libtommath::libtommath) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/libtommath/cmake/test_v1_package/conanfile.py b/recipes/libtommath/cmake/test_v1_package/conanfile.py index 78453e0085f23..32e56135f6429 100644 --- a/recipes/libtommath/cmake/test_v1_package/conanfile.py +++ b/recipes/libtommath/cmake/test_v1_package/conanfile.py @@ -3,7 +3,6 @@ import os -# legacy validation with Conan 1.x class TestLibTomMathV1Conan(ConanFile): settings = "os", "arch", "compiler", "build_type" generators = "cmake", "cmake_find_package_multi" From 79fae61590a03dd005465806c53345ed62d80a25 Mon Sep 17 00:00:00 2001 From: Chris Mc Date: Fri, 28 Apr 2023 11:23:59 -0700 Subject: [PATCH 12/19] Apply suggestions from code review --- recipes/libtommath/cmake/conanfile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipes/libtommath/cmake/conanfile.py b/recipes/libtommath/cmake/conanfile.py index d4d15a757d72c..9955d5e35078a 100644 --- a/recipes/libtommath/cmake/conanfile.py +++ b/recipes/libtommath/cmake/conanfile.py @@ -1,5 +1,5 @@ from conan import ConanFile -from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout import os @@ -60,6 +60,7 @@ def package(self): cmake.install() rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) def package_info(self): self.cpp_info.libs = ["tommath"] From e94187c009d6928b5297a0ba744b625d8b43dd89 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Wed, 28 Jun 2023 09:40:58 +0200 Subject: [PATCH 13/19] generate target without namespace Signed-off-by: Uilian Ries --- recipes/libtommath/cmake/conanfile.py | 34 +++++++-- .../patches/0002-enable-building-dlls.patch | 72 +------------------ .../cmake/test_v1_package/CMakeLists.txt | 6 +- 3 files changed, 29 insertions(+), 83 deletions(-) diff --git a/recipes/libtommath/cmake/conanfile.py b/recipes/libtommath/cmake/conanfile.py index 9955d5e35078a..3327a2df2dc2d 100644 --- a/recipes/libtommath/cmake/conanfile.py +++ b/recipes/libtommath/cmake/conanfile.py @@ -1,7 +1,8 @@ from conan import ConanFile -from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir, save from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout import os +import textwrap required_conan_version = ">=1.54.0" @@ -62,17 +63,36 @@ def package(self): rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + # INFO: Generate cmake target without namespace + self._create_cmake_module_alias_targets( + os.path.join(self.package_folder, self._module_file_rel_path), + {self.name: f"{self.name}::{self.name}"} + ) + + def _create_cmake_module_alias_targets(self, module_file, targets): + content = "" + for alias, aliased in targets.items(): + content += textwrap.dedent("""\ + if(TARGET {aliased} AND NOT TARGET {alias}) + add_library({alias} INTERFACE IMPORTED) + set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased}) + endif() + """.format(alias=alias, aliased=aliased)) + save(self, module_file, content) + + + @property + def _module_file_rel_path(self): + return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake") + 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") - # 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") + self.cpp_info.system_libs.extend(["m", "pthread", "dl"]) # TODO: to remove in conan v2 once cmake_find_package_* generators removed - self.cpp_info.names["cmake_find_package"] = "libtommath" - self.cpp_info.names["cmake_find_package_multi"] = "libtommath" + self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path] + self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path] diff --git a/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch b/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch index 162dc86e20416..fbb4465abdbba 100644 --- a/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch +++ b/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch @@ -3,7 +3,7 @@ @@ -91,6 +91,14 @@ add_library(${PROJECT_NAME} ${HEADERS} ) - + +if(BUILD_SHARED_LIBS AND MSVC) + target_sources(${PROJECT_NAME} PRIVATE "tommath.def") +endif() @@ -15,73 +15,3 @@ target_include_directories(${PROJECT_NAME} PUBLIC $ $ ---- s_mp_rand_platform.c -+++ s_mp_rand_platform.c -@@ -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); diff --git a/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt b/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt index 9a608511cc7c9..2f6b1a2f7ec79 100644 --- a/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt +++ b/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt @@ -1,12 +1,8 @@ cmake_minimum_required(VERSION 3.1) -project(test_package) +project(test_package C) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup(TARGETS) -# workaround v1 legacy generators always haveing namespaces -add_library(libtommath) -target_link_libraries(libtommath libtommath::libtommath) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ ${CMAKE_CURRENT_BINARY_DIR}/test_package/) From 6ea9333d6c026996fe623b1f593019b349dd327a Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Wed, 28 Jun 2023 10:35:30 +0200 Subject: [PATCH 14/19] support conan v2 for 1.2.0 Signed-off-by: Uilian Ries --- recipes/libtommath/all/conandata.yml | 1 - recipes/libtommath/all/conanfile.py | 175 +++++++++--------- .../all/test_package/CMakeLists.txt | 11 +- .../libtommath/all/test_package/conanfile.py | 24 ++- recipes/libtommath/cmake/conanfile.py | 1 + 5 files changed, 106 insertions(+), 106 deletions(-) diff --git a/recipes/libtommath/all/conandata.yml b/recipes/libtommath/all/conandata.yml index ecbf1c3cd0078..7fc908c6e48fd 100644 --- a/recipes/libtommath/all/conandata.yml +++ b/recipes/libtommath/all/conandata.yml @@ -5,4 +5,3 @@ sources: patches: "1.2.0": - patch_file: "patches/0001-enable-building-dll-s-using-makefile-msvc.patch" - base_path: "source_subfolder" diff --git a/recipes/libtommath/all/conanfile.py b/recipes/libtommath/all/conanfile.py index 6bdf6dd129d98..d2a6f691c058c 100644 --- a/recipes/libtommath/all/conanfile.py +++ b/recipes/libtommath/all/conanfile.py @@ -1,7 +1,12 @@ -from conans import AutoToolsBuildEnvironment, ConanFile, tools +from conan import ConanFile +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir, rename, chdir +from conan.tools.gnu import Autotools, AutotoolsToolchain +from conan.tools.layout import basic_layout +from conan.tools.microsoft import is_msvc, NMakeToolchain import os -required_conan_version = ">=1.33.0" + +required_conan_version = ">=1.53.0" class LibTomMathConan(ConanFile): @@ -21,11 +26,8 @@ class LibTomMathConan(ConanFile): "fPIC": True, } - exports_sources = "patches/*" - - @property - def _source_subfolder(self): - return "source_subfolder" + def export_sources(self): + export_conandata_patches(self) @property def _settings_build(self): @@ -37,98 +39,91 @@ def config_options(self): 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): + basic_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) + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def build_requirements(self): + if self._settings_build.os == "Windows": + self.win_bash = True + if not self.conf.get("tools.microsoft.bash:path", check_type=str): + self.tool_requires("msys2/cci.latest") + if not self.conf.get("tools.gnu:pkg_config", check_type=str): + self.tool_requires("pkgconf/1.9.3") + if not is_msvc(self) and self.settings.os != "Windows" and self.options.shared: + self.tool_requires("libtool/2.4.7") + + def generate(self): + if is_msvc(self): + tc = NMakeToolchain(self) + tc.extra_ldflags = ["-lcrypt32"] + tc.generate() + else: + tc = AutotoolsToolchain(self) + if self.settings.os == "Macos" and self.settings.arch == "armv8": + tc.extra_ldflags.append("-arch arm64") + tc.make_args = [f"PREFIX={self.package_folder}"] + tc.generate() + + @property + def _makefile_filename(self): + if is_msvc(self): + if self.options.shared: + return "makefile.msvc" + elif self.settings.os == "Windows" and not is_msvc(self): + return "makefile.mingw" + elif self.options.shared: + return "makefile.shared" + else: + return "makefile.unix" + + @property + def _makefile_target(self): + if is_msvc(self): + return "tommath.dll" if self.options.shared else "tommath.lib" + elif self.settings.os == "Windows" and not is_msvc(self): + return "libtommath.dll" if self.options.shared else "libtommath.a" + return None def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - self._run_makefile() + apply_conandata_patches(self) + with chdir(self, self.source_folder): + if is_msvc(self): + self.run(f"nmake -f {self._makefile_filename} {self._makefile_target}") + else: + autotools = Autotools(self) + autotools.make(target=self._makefile_target, args=["-f", self._makefile_filename]) def package(self): - self.copy("LICENSE", src=self._source_subfolder, dst="licenses") + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "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") + # INFO: The mingw makefile uses `cmd`, which is only available on Windows + copy(self, "*.a", src=self.source_folder, dst=os.path.join(self.package_folder, "lib")) + copy(self, "*.lib", src=self.source_folder, dst=os.path.join(self.package_folder, "lib")) + copy(self, "*.dll", src=self.source_folder, dst=os.path.join(self.package_folder, "bin")) + copy(self, "tommath.h", src=self.source_folder, dst=os.path.join(self.package_folder, "include")) else: - self._run_makefile("install") + with chdir(self, self.source_folder): + if is_msvc(self): + self.run(f"nmake -f {self._makefile_filename} install") + else: + autotools = Autotools(self) + autotools.install(args=["DESTDIR=", "-f", self._makefile_filename]) - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") - tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) + rm(self, "*.la", os.path.join(self.package_folder, "lib")) + if self.options.shared: + rm(self, "*.a", os.path.join(self.package_folder, "lib")) + rmdir(self, 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")) + if is_msvc(self) and self.options.shared: + rename(os.path.join(self.package_folder, "lib", "tommath.dll.lib"), + os.path.join(self.package_folder, "lib", "tommath.lib")) def package_info(self): self.cpp_info.libs = ["tommath"] @@ -136,4 +131,6 @@ def package_info(self): if self.settings.os == "Windows": self.cpp_info.system_libs = ["advapi32", "crypt32"] - self.cpp_info.names["pkg_config"] = "libtommath" + 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") diff --git a/recipes/libtommath/all/test_package/CMakeLists.txt b/recipes/libtommath/all/test_package/CMakeLists.txt index 90762dc612cbd..3b58e6e9fc16a 100644 --- a/recipes/libtommath/all/test_package/CMakeLists.txt +++ b/recipes/libtommath/all/test_package/CMakeLists.txt @@ -1,11 +1,8 @@ -cmake_minimum_required(VERSION 3.1) -project(test_package C) +cmake_minimum_required(VERSION 3.8) -include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") -conan_basic_setup(TARGETS) +project(test_package C) -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/cmake/conanfile.py b/recipes/libtommath/cmake/conanfile.py index 3327a2df2dc2d..df659f9cf0685 100644 --- a/recipes/libtommath/cmake/conanfile.py +++ b/recipes/libtommath/cmake/conanfile.py @@ -89,6 +89,7 @@ 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") + self.cpp_info.set_property("pkg_config_name", "libtommath") if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs.extend(["m", "pthread", "dl"]) From 3a8712ea062e8bb49c5e5dd7775498f4e19294af Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Wed, 28 Jun 2023 10:46:18 +0200 Subject: [PATCH 15/19] fix windows build Signed-off-by: Uilian Ries --- recipes/libtommath/all/conanfile.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/recipes/libtommath/all/conanfile.py b/recipes/libtommath/all/conanfile.py index d2a6f691c058c..3e371ff0b634c 100644 --- a/recipes/libtommath/all/conanfile.py +++ b/recipes/libtommath/all/conanfile.py @@ -74,10 +74,9 @@ def generate(self): @property def _makefile_filename(self): if is_msvc(self): - if self.options.shared: - return "makefile.msvc" + return "makefile.msvc" elif self.settings.os == "Windows" and not is_msvc(self): - return "makefile.mingw" + return "makefile.mingw" elif self.options.shared: return "makefile.shared" else: @@ -122,7 +121,7 @@ def package(self): rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) if is_msvc(self) and self.options.shared: - rename(os.path.join(self.package_folder, "lib", "tommath.dll.lib"), + rename(self, os.path.join(self.package_folder, "lib", "tommath.dll.lib"), os.path.join(self.package_folder, "lib", "tommath.lib")) def package_info(self): From 50319e639a86cdbb1694692c3476648776faaffb Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Wed, 28 Jun 2023 11:57:45 +0200 Subject: [PATCH 16/19] inject tool requires environment Signed-off-by: Uilian Ries --- recipes/libtommath/all/conanfile.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/recipes/libtommath/all/conanfile.py b/recipes/libtommath/all/conanfile.py index 3e371ff0b634c..ea643a94cfc17 100644 --- a/recipes/libtommath/all/conanfile.py +++ b/recipes/libtommath/all/conanfile.py @@ -1,6 +1,7 @@ from conan import ConanFile from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir, rename, chdir from conan.tools.gnu import Autotools, AutotoolsToolchain +from conan.tools.env import VirtualBuildEnv from conan.tools.layout import basic_layout from conan.tools.microsoft import is_msvc, NMakeToolchain import os @@ -60,6 +61,8 @@ def build_requirements(self): self.tool_requires("libtool/2.4.7") def generate(self): + env = VirtualBuildEnv(self) + env.generate() if is_msvc(self): tc = NMakeToolchain(self) tc.extra_ldflags = ["-lcrypt32"] From 14eb573c8f5b6e1c0745f552c3d0f408ac9139b8 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Thu, 29 Jun 2023 15:56:19 +0200 Subject: [PATCH 17/19] pass libtool as argument Signed-off-by: Uilian Ries --- recipes/libtommath/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/libtommath/all/conanfile.py b/recipes/libtommath/all/conanfile.py index ea643a94cfc17..235065f5b6944 100644 --- a/recipes/libtommath/all/conanfile.py +++ b/recipes/libtommath/all/conanfile.py @@ -71,7 +71,7 @@ def generate(self): tc = AutotoolsToolchain(self) if self.settings.os == "Macos" and self.settings.arch == "armv8": tc.extra_ldflags.append("-arch arm64") - tc.make_args = [f"PREFIX={self.package_folder}"] + tc.make_args = [f"PREFIX={self.package_folder}", "LIBTOOL=libtool"] tc.generate() @property From 66b656ce6f784dcbc5734d8056baf93c4c78ed32 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Fri, 30 Jun 2023 10:04:13 +0200 Subject: [PATCH 18/19] pass cross-compile flag for mac m1 Signed-off-by: Uilian Ries --- recipes/libtommath/all/conanfile.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/recipes/libtommath/all/conanfile.py b/recipes/libtommath/all/conanfile.py index 235065f5b6944..ba1b027f1bbd9 100644 --- a/recipes/libtommath/all/conanfile.py +++ b/recipes/libtommath/all/conanfile.py @@ -3,6 +3,7 @@ from conan.tools.gnu import Autotools, AutotoolsToolchain from conan.tools.env import VirtualBuildEnv from conan.tools.layout import basic_layout +from conan.tools.build import cross_building from conan.tools.microsoft import is_msvc, NMakeToolchain import os @@ -71,7 +72,9 @@ def generate(self): tc = AutotoolsToolchain(self) if self.settings.os == "Macos" and self.settings.arch == "armv8": tc.extra_ldflags.append("-arch arm64") - tc.make_args = [f"PREFIX={self.package_folder}", "LIBTOOL=libtool"] + if cross_building(self): + tc.make_args.append("CROSS_COMPILE=arm64-apple-m1-") + tc.make_args.extend([f"PREFIX={self.package_folder}", "LIBTOOL=libtool"]) tc.generate() @property From 7ced202faffbfb6bd0f9326d713e97b4968a16a3 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Tue, 2 Apr 2024 17:38:11 +0200 Subject: [PATCH 19/19] replace temporary version by official 1.3.0 Signed-off-by: Uilian Ries --- recipes/libtommath/cmake/conandata.yml | 12 ++++++------ recipes/libtommath/cmake/conanfile.py | 4 ---- ...s.patch => 0001-enable-building-dlls.patch} | 10 ++++++---- .../cmake/test_package/test_package.c | 2 +- .../cmake/test_v1_package/CMakeLists.txt | 8 -------- .../cmake/test_v1_package/conanfile.py | 18 ------------------ recipes/libtommath/config.yml | 2 +- 7 files changed, 14 insertions(+), 42 deletions(-) rename recipes/libtommath/cmake/patches/{0002-enable-building-dlls.patch => 0001-enable-building-dlls.patch} (69%) delete mode 100644 recipes/libtommath/cmake/test_v1_package/CMakeLists.txt delete mode 100644 recipes/libtommath/cmake/test_v1_package/conanfile.py diff --git a/recipes/libtommath/cmake/conandata.yml b/recipes/libtommath/cmake/conandata.yml index e358b71b98af2..7cef6c70944d1 100644 --- a/recipes/libtommath/cmake/conandata.yml +++ b/recipes/libtommath/cmake/conandata.yml @@ -1,9 +1,9 @@ sources: - "cci.20221028": - url: "https://github.com/libtom/libtommath/archive/03de03dee753442d4b23166982514639c4ccbc39.tar.gz" - sha256: "ab65fcfc88f7bd457b13a615228298935f05af17a0a8554ad0e3fba9812b03c2" + "1.3.0": + url: "https://github.com/libtom/libtommath/releases/download/v1.3.0/ltm-1.3.0.tar.xz" + sha256: "296272d93435991308eb73607600c034b558807a07e829e751142e65ccfa9d08" patches: - "cci.20221028": - - patch_file: "patches/0002-enable-building-dlls.patch" - patch_description: "add support for windows dlls" + "1.3.0": + - patch_file: "patches/0001-enable-building-dlls.patch" + patch_description: "Enable building DLLs using tommath.def" patch_type: "portability" diff --git a/recipes/libtommath/cmake/conanfile.py b/recipes/libtommath/cmake/conanfile.py index df659f9cf0685..04506fb8536dd 100644 --- a/recipes/libtommath/cmake/conanfile.py +++ b/recipes/libtommath/cmake/conanfile.py @@ -93,7 +93,3 @@ def package_info(self): if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs.extend(["m", "pthread", "dl"]) - - # TODO: to remove in conan v2 once cmake_find_package_* generators removed - self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path] - self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path] diff --git a/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch b/recipes/libtommath/cmake/patches/0001-enable-building-dlls.patch similarity index 69% rename from recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch rename to recipes/libtommath/cmake/patches/0001-enable-building-dlls.patch index fbb4465abdbba..c0faef97cb7f7 100644 --- a/recipes/libtommath/cmake/patches/0002-enable-building-dlls.patch +++ b/recipes/libtommath/cmake/patches/0001-enable-building-dlls.patch @@ -1,9 +1,11 @@ ---- CMakeLists.txt -+++ CMakeLists.txt -@@ -91,6 +91,14 @@ add_library(${PROJECT_NAME} +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0b84e79..04dea2e 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -107,6 +107,14 @@ add_library(${PROJECT_NAME} ${HEADERS} ) - + +if(BUILD_SHARED_LIBS AND MSVC) + target_sources(${PROJECT_NAME} PRIVATE "tommath.def") +endif() diff --git a/recipes/libtommath/cmake/test_package/test_package.c b/recipes/libtommath/cmake/test_package/test_package.c index 4deb4ecefcb4b..cad90cb5780b2 100644 --- a/recipes/libtommath/cmake/test_package/test_package.c +++ b/recipes/libtommath/cmake/test_package/test_package.c @@ -1,4 +1,4 @@ -#include "libtommath/tommath.h" +#include "tommath.h" #include #include diff --git a/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt b/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt deleted file mode 100644 index 2f6b1a2f7ec79..0000000000000 --- a/recipes/libtommath/cmake/test_v1_package/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -project(test_package C) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ - ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/libtommath/cmake/test_v1_package/conanfile.py b/recipes/libtommath/cmake/test_v1_package/conanfile.py deleted file mode 100644 index 32e56135f6429..0000000000000 --- a/recipes/libtommath/cmake/test_v1_package/conanfile.py +++ /dev/null @@ -1,18 +0,0 @@ -from conans import ConanFile, CMake -from conan.tools.build import cross_building -import os - - -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) diff --git a/recipes/libtommath/config.yml b/recipes/libtommath/config.yml index 0c26ae5f72951..1dca1b456361e 100644 --- a/recipes/libtommath/config.yml +++ b/recipes/libtommath/config.yml @@ -1,5 +1,5 @@ versions: - "cci.20221028": + "1.3.0": folder: "cmake" "1.2.0": folder: "all"