Skip to content

Commit a58c786

Browse files
KhalyutinAlexPeshkoff
authored andcommitted
relpace to libtommath 1.3 source tree
without dirs: /doc /logs /mtest /demo /.github and files makefile.shared libtommath_VS2008.sln libtommath_VS2008.vcproj add from fb libtommath_VSVC15.sln libtommath_VSVC15.vcproj with correct lists of *.c *.h makefile.shared with correct lists of *.o
1 parent 46c8026 commit a58c786

231 files changed

Lines changed: 14852 additions & 10055 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

extern/libtommath/CMakeLists.txt

Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
# SPDX-License-Identifier: Unlicense
2+
#
3+
# LibTomMath, a free open source portable number theoretic multiple-precision
4+
# integer (MPI) library written entirely in C.
5+
#
6+
7+
cmake_minimum_required(VERSION 3.10)
8+
9+
project(libtommath
10+
VERSION 1.3.0
11+
DESCRIPTION "A free open source portable number theoretic multiple-precision integer (MPI) library written entirely in C."
12+
HOMEPAGE_URL "https://www.libtom.net/LibTomMath"
13+
LANGUAGES C)
14+
15+
# package release version
16+
# bump if re-releasing the same VERSION + patches
17+
# set to 1 if releasing a new VERSION
18+
set(PACKAGE_RELEASE_VERSION 1)
19+
20+
#-----------------------------------------------------------------------------
21+
# Include cmake modules
22+
#-----------------------------------------------------------------------------
23+
include(GNUInstallDirs)
24+
include(CheckIPOSupported)
25+
include(CMakePackageConfigHelpers)
26+
# default is "No tests"
27+
option(BUILD_TESTING "" OFF)
28+
include(CTest)
29+
include(sources.cmake)
30+
31+
#-----------------------------------------------------------------------------
32+
# Options
33+
#-----------------------------------------------------------------------------
34+
option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"ON\", default is static" OFF)
35+
36+
#-----------------------------------------------------------------------------
37+
# Add support for ccache if desired
38+
#-----------------------------------------------------------------------------
39+
find_program(CCACHE ccache)
40+
41+
if(CCACHE)
42+
option(ENABLE_CCACHE "Enable ccache." ON)
43+
endif()
44+
45+
# use ccache if installed
46+
if(CCACHE AND ENABLE_CCACHE)
47+
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
48+
endif()
49+
50+
#-----------------------------------------------------------------------------
51+
# Compose CFLAGS
52+
#-----------------------------------------------------------------------------
53+
54+
# Some information ported from makefile_include.mk
55+
56+
57+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
58+
message(STATUS "Setting build type to 'Release' as none was specified.")
59+
set(CMAKE_BUILD_TYPE "Release")
60+
endif()
61+
62+
# We only differentiate between MSVC and GCC-compatible compilers
63+
if(MSVC)
64+
set(LTM_C_FLAGS -W3)
65+
elseif(WATCOM)
66+
set(LTM_C_FLAGS -fo=.obj -oaxt -3r -w3)
67+
else()
68+
set(LTM_C_FLAGS -Wall -Wsign-compare -Wextra -Wshadow
69+
-Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
70+
-Wstrict-prototypes -Wpointer-arith -Wsystem-headers)
71+
set(CMAKE_C_FLAGS_DEBUG "-g3")
72+
set(CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer")
73+
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O2")
74+
set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
75+
endif()
76+
77+
# What compiler do we have and what are their...uhm... peculiarities
78+
if(CMAKE_C_COMPILER_ID MATCHES "(C|c?)lang")
79+
list(APPEND LTM_C_FLAGS -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header)
80+
# Clang requires at least '-O1' for dead code elimination
81+
set(CMAKE_C_FLAGS_DEBUG "-O1 ${CMAKE_C_FLAGS_DEBUG}")
82+
endif()
83+
if(CMAKE_C_COMPILER MATCHES "mingw")
84+
list(APPEND LTM_C_FLAGS -Wno-shadow -Wno-expansion-to-defined -Wno-declaration-after-statement -Wno-bad-function-cast)
85+
endif()
86+
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
87+
list(APPEND LTM_C_FLAGS -Wno-nullability-completeness)
88+
endif()
89+
if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
90+
list(APPEND LTM_C_FLAGS -no-undefined)
91+
endif()
92+
93+
# TODO: coverage (lgcov)
94+
95+
# If the user set the environment variables at generate-time, append them
96+
# in order to allow overriding our defaults.
97+
# ${LTM_CFLAGS} means the user passed it via sth like:
98+
# $ cmake -DLTM_CFLAGS="foo"
99+
list(APPEND LTM_C_FLAGS ${LTM_CFLAGS})
100+
list(APPEND LTM_LD_FLAGS ${LTM_LDFLAGS})
101+
102+
#-----------------------------------------------------------------------------
103+
# library target
104+
#-----------------------------------------------------------------------------
105+
add_library(${PROJECT_NAME}
106+
${SOURCES}
107+
${HEADERS}
108+
)
109+
110+
target_include_directories(${PROJECT_NAME} PUBLIC
111+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
112+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
113+
)
114+
115+
target_compile_options(${PROJECT_NAME} BEFORE PRIVATE
116+
${LTM_C_FLAGS}
117+
)
118+
target_link_options(${PROJECT_NAME} BEFORE PRIVATE
119+
${LTM_LD_FLAGS}
120+
)
121+
122+
set(PUBLIC_HEADERS tommath.h)
123+
set(C89 False CACHE BOOL "(Usually maintained automatically) Enable when the library is in c89 mode to package the correct header files on install")
124+
if(C89)
125+
list(APPEND PUBLIC_HEADERS tommath_c89.h)
126+
endif()
127+
128+
set_target_properties(${PROJECT_NAME} PROPERTIES
129+
OUTPUT_NAME tommath
130+
VERSION ${PROJECT_VERSION}
131+
SOVERSION ${PROJECT_VERSION_MAJOR}
132+
PUBLIC_HEADER "${PUBLIC_HEADERS}"
133+
)
134+
135+
option(COMPILE_LTO "Build with LTO enabled")
136+
if(COMPILE_LTO)
137+
check_ipo_supported(RESULT COMPILER_SUPPORTS_LTO)
138+
if(COMPILER_SUPPORTS_LTO)
139+
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
140+
else()
141+
message(SEND_ERROR "This compiler does not support LTO. Reconfigure ${PROJECT_NAME} with -DCOMPILE_LTO=OFF.")
142+
endif()
143+
endif()
144+
145+
#-----------------------------------------------------------------------------
146+
# demo target
147+
#-----------------------------------------------------------------------------
148+
149+
if(BUILD_TESTING)
150+
enable_testing()
151+
add_subdirectory(demo)
152+
endif()
153+
154+
#-----------------------------------------------------------------------------
155+
# Install/export targets and files
156+
#-----------------------------------------------------------------------------
157+
set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
158+
set(PROJECT_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake")
159+
set(PROJECT_CONFIG_FILE "${PROJECT_NAME}-config.cmake")
160+
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
161+
162+
install(TARGETS ${PROJECT_NAME}
163+
EXPORT ${TARGETS_EXPORT_NAME}
164+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
165+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
166+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
167+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
168+
)
169+
170+
# Install libtommath.pc for pkg-config if we build a shared library
171+
if(BUILD_SHARED_LIBS)
172+
# Let the user override the default directory of the pkg-config file (usually this shouldn't be required to be changed)
173+
set(CMAKE_INSTALL_PKGCONFIGDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Folder where to install .pc files")
174+
175+
configure_file(
176+
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in
177+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
178+
@ONLY
179+
)
180+
181+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
182+
DESTINATION ${CMAKE_INSTALL_PKGCONFIGDIR}
183+
)
184+
endif()
185+
186+
# generate package version file
187+
write_basic_package_version_file(
188+
${PROJECT_VERSION_FILE}
189+
VERSION ${PROJECT_VERSION}
190+
COMPATIBILITY SameMajorVersion
191+
)
192+
193+
# install version file
194+
install(FILES ${PROJECT_VERSION_FILE}
195+
DESTINATION ${CONFIG_INSTALL_DIR}
196+
)
197+
198+
# build directory package config
199+
export(EXPORT ${TARGETS_EXPORT_NAME}
200+
FILE ${PROJECT_CONFIG_FILE}
201+
)
202+
203+
# installed package config
204+
install(EXPORT ${TARGETS_EXPORT_NAME}
205+
DESTINATION ${CONFIG_INSTALL_DIR}
206+
FILE ${PROJECT_CONFIG_FILE}
207+
)
208+
209+
# add to CMake registry
210+
export(PACKAGE ${PROJECT_NAME})
211+
212+
#---------------------------------------------------------------------------------------
213+
# Create release packages
214+
#---------------------------------------------------------------------------------------
215+
216+
# determine distribution and architecture
217+
find_program(LSB_RELEASE lsb_release)
218+
find_program(SYSCTL sysctl)
219+
find_program(UNAME uname)
220+
221+
if(UNAME)
222+
execute_process(COMMAND uname -m OUTPUT_VARIABLE MACHINE_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
223+
elseif(SYSCTL)
224+
execute_process(COMMAND sysctl -b hw.machine_arch OUTPUT_VARIABLE MACHINE_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
225+
else()
226+
string(TOLOWER ${CMAKE_SYSTEM_NAME} MACHINE_ARCH)
227+
endif()
228+
229+
if(LSB_RELEASE)
230+
execute_process(COMMAND lsb_release -si OUTPUT_VARIABLE LINUX_DISTRO OUTPUT_STRIP_TRAILING_WHITESPACE)
231+
execute_process(COMMAND lsb_release -sc OUTPUT_VARIABLE LINUX_DISTRO_CODENAME OUTPUT_STRIP_TRAILING_WHITESPACE)
232+
execute_process(COMMAND lsb_release -sr OUTPUT_VARIABLE LINUX_DISTRO_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
233+
234+
string(TOLOWER ${LINUX_DISTRO} LINUX_DISTRO)
235+
if(LINUX_DISTRO_CODENAME STREQUAL "n/a")
236+
set(DISTRO_PACK_PATH ${LINUX_DISTRO}/${LINUX_DISTRO_VERSION}/)
237+
else()
238+
set(DISTRO_PACK_PATH ${LINUX_DISTRO}/${LINUX_DISTRO_CODENAME}/)
239+
endif()
240+
else()
241+
set(DISTRO_PACK_PATH ${CMAKE_SYSTEM_NAME}/)
242+
endif()
243+
244+
# make sure untagged versions get a different package name
245+
execute_process(COMMAND git describe --exact-match --tags ERROR_QUIET RESULT_VARIABLE REPO_HAS_TAG)
246+
if(REPO_HAS_TAG EQUAL 0)
247+
set(PACKAGE_NAME_SUFFIX "")
248+
else()
249+
set(PACKAGE_NAME_SUFFIX "-git")
250+
message(STATUS "Use -git suffix")
251+
endif()
252+
253+
# default CPack generators
254+
set(CPACK_GENERATOR TGZ STGZ)
255+
256+
# extra CPack generators
257+
if(LINUX_DISTRO STREQUAL "debian" OR LINUX_DISTRO STREQUAL "ubuntu" OR LINUX_DISTRO STREQUAL "linuxmint")
258+
list(APPEND CPACK_GENERATOR DEB)
259+
elseif(LINUX_DISTRO STREQUAL "fedora" OR LINUX_DISTRO STREQUAL "opensuse" OR LINUX_DISTRO STREQUAL "centos")
260+
list(APPEND CPACK_GENERATOR RPM)
261+
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
262+
list(APPEND CPACK_GENERATOR FREEBSD)
263+
endif()
264+
265+
set(LTM_DEBIAN_SHARED_PACKAGE_NAME "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}${PROJECT_VERSION_MAJOR}")
266+
267+
# general CPack config
268+
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/${DISTRO_PACK_PATH})
269+
message(STATUS "CPack: packages will be generated under ${CPACK_PACKAGE_DIRECTORY}")
270+
if(BUILD_SHARED_LIBS)
271+
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${PROJECT_VERSION_MAJOR}")
272+
set(CPACK_DEBIAN_PACKAGE_NAME "${LTM_DEBIAN_SHARED_PACKAGE_NAME}")
273+
else()
274+
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}-devel")
275+
set(CPACK_DEBIAN_LIBRARIES_PACKAGE_NAME "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}-dev")
276+
endif()
277+
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
278+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LibTomMath")
279+
set(CPACK_PACKAGE_VENDOR "libtom projects")
280+
set(CPACK_PACKAGE_CONTACT "libtom@googlegroups.com")
281+
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
282+
set(PACKAGE_NAME_TRAILER ${CPACK_PACKAGE_VERSION}-${PACKAGE_RELEASE_VERSION}_${MACHINE_ARCH})
283+
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${PACKAGE_NAME_TRAILER})
284+
285+
# deb specific CPack config
286+
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
287+
set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON)
288+
set(CPACK_DEBIAN_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION})
289+
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
290+
if(BUILD_SHARED_LIBS)
291+
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
292+
else()
293+
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
294+
set(CPACK_DEBIAN_PACKAGE_DEPENDS ${LTM_DEBIAN_SHARED_PACKAGE_NAME})
295+
set(CPACK_DEB_COMPONENT_INSTALL ON)
296+
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
297+
set(CPACK_COMPONENTS_ALL Libraries)
298+
endif()
299+
300+
# rpm specific CPack config
301+
set(CPACK_RPM_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION})
302+
set(CPACK_RPM_PACKAGE_ARCHITECTURE ${MACHINE_ARCH})
303+
set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}")
304+
set(CPACK_RPM_PACKAGE_LICENSE "The Unlicense")
305+
306+
# FreeBSD specific CPack config
307+
set(CPACK_FREEBSD_PACKAGE_MAINTAINER "gahr@FreeBSD.org")
308+
set(CPACK_FREEBSD_PACKAGE_ORIGIN "math/libtommath")
309+
set(CPACK_FREEBSD_PACKAGE_CATEGORIES "math")
310+
311+
include(CPack)

extern/libtommath/LICENSE

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
1-
LibTomMath is hereby released into the Public Domain.
1+
The LibTom license
22

3-
-- Tom St Denis
3+
This is free and unencumbered software released into the public domain.
44

5+
Anyone is free to copy, modify, publish, use, compile, sell, or
6+
distribute this software, either in source code form or as a compiled
7+
binary, for any purpose, commercial or non-commercial, and by any
8+
means.
9+
10+
In jurisdictions that recognize copyright laws, the author or authors
11+
of this software dedicate any and all copyright interest in the
12+
software to the public domain. We make this dedication for the benefit
13+
of the public at large and to the detriment of our heirs and
14+
successors. We intend this dedication to be an overt act of
15+
relinquishment in perpetuity of all present and future rights to this
16+
software under copyright law.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24+
OTHER DEALINGS IN THE SOFTWARE.
25+
26+
For more information, please refer to <http://unlicense.org/>

extern/libtommath/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# libtommath
2+
3+
This is the git repository for [LibTomMath](http://www.libtom.net/LibTomMath/), a free open source portable number theoretic multiple-precision integer (MPI) library written entirely in C.
4+
5+
## Build Status
6+
7+
### Travis CI
8+
9+
master: [![Build Status](https://api.travis-ci.org/libtom/libtommath.png?branch=master)](https://travis-ci.org/libtom/libtommath)
10+
11+
develop: [![Build Status](https://api.travis-ci.org/libtom/libtommath.png?branch=develop)](https://travis-ci.org/libtom/libtommath)
12+
13+
### AppVeyor
14+
15+
master: [![Build status](https://ci.appveyor.com/api/projects/status/b80lpolw3i8m6hsh/branch/master?svg=true)](https://ci.appveyor.com/project/libtom/libtommath/branch/master)
16+
17+
develop: [![Build status](https://ci.appveyor.com/api/projects/status/b80lpolw3i8m6hsh/branch/develop?svg=true)](https://ci.appveyor.com/project/libtom/libtommath/branch/develop)
18+
19+
### ABI Laboratory
20+
21+
API/ABI changes: [check here](https://abi-laboratory.pro/tracker/timeline/libtommath/)
22+
23+
## Summary
24+
25+
The `develop` branch contains the in-development version. Stable releases are tagged.
26+
27+
Documentation is built from the LaTeX file `bn.tex`. There is also limited documentation in `tommath.h`.
28+
There is also a document, `tommath.pdf`, which describes the goals of the project and many of the algorithms used.
29+
30+
The project can be build by using `make`. Along with the usual `make`, `make clean` and `make install`,
31+
there are several other build targets, see the makefile for details.
32+
There are also makefiles for certain specific platforms.
33+
34+
## Testing
35+
36+
Tests are located in `demo/` and can be built in two flavors.
37+
* `make test` creates a stand-alone test binary that executes several test routines.
38+
* `make mtest_opponent` creates a test binary that is intended to be run against `mtest`.
39+
`mtest` can be built with `make mtest` and test execution is done like `./mtest/mtest | ./mtest_opponent`.
40+
`mtest` is creating test vectors using an alternative MPI library and `test` is consuming these vectors to verify correct behavior of ltm
41+
42+
## Building and Installing
43+
44+
Building is straightforward for GNU Linux only, the section "Building LibTomMath" in the documentation in `doc/bn.pdf` has the details.

0 commit comments

Comments
 (0)