Merge pull request #528 from libtom/add-cmake-support Add cmake support
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 9e4cee0..06eb58a 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -25,7 +25,7 @@ on:
- /^ci\/.*$/
jobs:
- Build:
+ Testme:
runs-on: ${{ matrix.os }}
strategy:
matrix:
@@ -146,3 +146,41 @@ jobs:
cat test_*.log || true
cat valgrind_test.log || true
cat gcc_errors_*.log || true
+
+ CMake:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ ubuntu-18.04, ubuntu-20.04 ]
+ build_type: [ '', -DCMAKE_BUILD_TYPE=Debug, -DCMAKE_BUILD_TYPE=Release, -DCMAKE_BUILD_TYPE=RelWithDebInfo, -DCMAKE_BUILD_TYPE=MinSizeRel ]
+ cc: [ clang, gcc ]
+ config:
+ # Static library build
+ - { CMAKEOPTIONS: '-DBUILD_SHARED_LIBS=Off' }
+ # Shared library build
+ - { CMAKEOPTIONS: '-DBUILD_SHARED_LIBS=On' }
+ steps:
+ - uses: actions/checkout@v2
+ - name: install dependencies
+ run: |
+ sudo apt-get update -qq
+ sudo apt-get install -y cmake gcc clang llvm
+ - name: build
+ run: |
+ mkdir build
+ cd build
+ CC=${{ matrix.cc }} cmake ${{ matrix.config.CMAKEOPTIONS }} ${{ matrix.build_type }} ..
+ make -j$(nproc)
+ - name: test
+ run: |
+ cd build
+ CC=${{ matrix.cc }} cmake ${{ matrix.config.CMAKEOPTIONS }} ${{ matrix.build_type }} -DBUILD_TESTING=On ..
+ make -j$(nproc)
+ ctest
+ - name: test (in demo folder)
+ run: |
+ mkdir -p demo/build
+ cd demo/build
+ CC=${{ matrix.cc }} cmake ${{ matrix.config.CMAKEOPTIONS }} ${{ matrix.build_type }} ..
+ make -j$(nproc)
+ ctest
diff --git a/.gitignore b/.gitignore
index 696e0ec..36fd9dd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -104,3 +104,10 @@ logs/*.png
logs/*-*.dem
callgraph.txt
+
+# cmake build directories
+build*/
+
+# kdevelop section
+.kdev4/
+*.kdev4
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..bca46ea
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,271 @@
+# SPDX-License-Identifier: Unlicense
+#
+# LibTomMath, a free open source portable number theoretic multiple-precision
+# integer (MPI) library written entirely in C.
+#
+
+cmake_minimum_required(VERSION 3.10)
+
+project(libtommath
+ VERSION 1.2.0
+ DESCRIPTION "A free open source portable number theoretic multiple-precision integer (MPI) library written entirely in C."
+ HOMEPAGE_URL "https://www.libtom.net/LibTomMath"
+ LANGUAGES C)
+
+# package release version
+# bump if re-releasing the same VERSION + patches
+# set to 1 if releasing a new VERSION
+set(PACKAGE_RELEASE_VERSION 1)
+
+#-----------------------------------------------------------------------------
+# Include cmake modules
+#-----------------------------------------------------------------------------
+include(GNUInstallDirs)
+include(CheckIPOSupported)
+include(CMakePackageConfigHelpers)
+# default is "No tests"
+option(BUILD_TESTING "" OFF)
+include(CTest)
+include(sources.cmake)
+
+# The only direct cmake argument for now
+option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"ON\", default is static" OFF)
+
+#-----------------------------------------------------------------------------
+# Compose CFLAGS
+#-----------------------------------------------------------------------------
+
+# Some information ported from makefile_include.mk
+
+
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+ message(STATUS "Setting build type to 'Release' as none was specified.")
+ set(CMAKE_BUILD_TYPE "Release")
+endif()
+
+# We only differentiate between MSVC and GCC-compatible compilers
+if(MSVC)
+ set(LTM_C_FLAGS -W3)
+else()
+ set(LTM_C_FLAGS -Wall -Wsign-compare -Wextra -Wshadow
+ -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
+ -Wstrict-prototypes -Wpointer-arith -Wsystem-headers)
+ set(CMAKE_C_FLAGS_DEBUG "-g3")
+ set(CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer")
+ set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O2")
+ set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
+endif()
+
+# What compiler do we have and what are their...uhm... peculiarities
+if(CMAKE_C_COMPILER_ID MATCHES "(C|c?)lang")
+ list(APPEND LTM_C_FLAGS -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header)
+ # Clang requires at least '-O1' for dead code eliminiation
+ set(CMAKE_C_FLAGS_DEBUG "-O1 ${CMAKE_C_FLAGS_DEBUG}")
+endif()
+if(CMAKE_C_COMPILER MATCHES "mingw")
+ list(APPEND LTM_C_FLAGS -Wno-shadow -Wno-expansion-to-defined -Wno-declaration-after-statement -Wno-bad-function-cast)
+endif()
+if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ list(APPEND LTM_C_FLAGS -Wno-nullability-completeness)
+endif()
+if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
+ list(APPEND LTM_C_FLAGS -no-undefined)
+endif()
+
+# TODO: coverage (lgcov)
+
+# If the user set the environment variables at generate-time, append them
+# in order to allow overriding our defaults.
+# ${LTM_CFLAGS} means the user passed it via sth like:
+# $ cmake -DLTM_CFLAGS="foo"
+list(APPEND LTM_C_FLAGS ${LTM_CFLAGS})
+list(APPEND LTM_LD_FLAGS ${LTM_LDFLAGS})
+
+#-----------------------------------------------------------------------------
+# library target
+#-----------------------------------------------------------------------------
+add_library(${PROJECT_NAME}
+ ${SOURCES}
+ ${HEADERS}
+)
+
+target_include_directories(${PROJECT_NAME} PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
+)
+
+target_compile_options(${PROJECT_NAME} BEFORE PRIVATE
+ ${LTM_C_FLAGS}
+)
+target_link_options(${PROJECT_NAME} BEFORE PRIVATE
+ ${LTM_LD_FLAGS}
+)
+
+set_target_properties(${PROJECT_NAME} PROPERTIES
+ OUTPUT_NAME tommath
+ VERSION ${PROJECT_VERSION}
+ SOVERSION ${PROJECT_VERSION_MAJOR}
+ PUBLIC_HEADER tommath.h
+)
+
+option(COMPILE_LTO "Build with LTO enabled")
+if(COMPILE_LTO)
+ check_ipo_supported(RESULT COMPILER_SUPPORTS_LTO)
+ if(COMPILER_SUPPORTS_LTO)
+ set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
+ else()
+ message(SEND_ERROR "This compiler does not support LTO. Reconfigure ${PROJECT_NAME} with -DCOMPILE_LTO=OFF.")
+ endif()
+endif()
+
+#-----------------------------------------------------------------------------
+# demo target
+#-----------------------------------------------------------------------------
+
+if(BUILD_TESTING)
+ enable_testing()
+ add_subdirectory(demo)
+endif()
+
+#-----------------------------------------------------------------------------
+# Install/export targets and files
+#-----------------------------------------------------------------------------
+set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
+set(PROJECT_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake")
+set(PROJECT_CONFIG_FILE "${PROJECT_NAME}-config.cmake")
+set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
+
+install(TARGETS ${PROJECT_NAME}
+ EXPORT ${TARGETS_EXPORT_NAME}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
+)
+
+# Install libtommath.pc for pkg-config if we build a shared library
+if(BUILD_SHARED_LIBS)
+ # Let the user override the default directory of the pkg-config file (usually this shouldn't be required to be changed)
+ set(CMAKE_INSTALL_PKGCONFIGDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Folder where to install .pc files")
+
+ configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
+ @ONLY
+ )
+
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
+ DESTINATION ${CMAKE_INSTALL_PKGCONFIGDIR}
+ )
+endif()
+
+# generate package version file
+write_basic_package_version_file(
+ ${PROJECT_VERSION_FILE}
+ VERSION ${PROJECT_VERSION}
+ COMPATIBILITY SameMajorVersion
+)
+
+# install version file
+install(FILES ${PROJECT_VERSION_FILE}
+ DESTINATION ${CONFIG_INSTALL_DIR}
+)
+
+# build directory package config
+export(EXPORT ${TARGETS_EXPORT_NAME}
+ FILE ${PROJECT_CONFIG_FILE}
+)
+
+# installed package config
+install(EXPORT ${TARGETS_EXPORT_NAME}
+ DESTINATION ${CONFIG_INSTALL_DIR}
+ FILE ${PROJECT_CONFIG_FILE}
+)
+
+# add to CMake registry
+export(PACKAGE ${PROJECT_NAME})
+
+#---------------------------------------------------------------------------------------
+# Create release packages
+#---------------------------------------------------------------------------------------
+
+# determine distribution and architecture
+find_program(LSB_RELEASE lsb_release)
+find_program(SYSCTL sysctl)
+find_program(UNAME uname)
+
+if(UNAME)
+ execute_process(COMMAND uname -m OUTPUT_VARIABLE MACHINE_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
+elseif(SYSCTL)
+ execute_process(COMMAND sysctl -b hw.machine_arch OUTPUT_VARIABLE MACHINE_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
+else()
+ string(TOLOWER ${CMAKE_SYSTEM_NAME} MACHINE_ARCH)
+endif()
+
+if(LSB_RELEASE)
+ execute_process(COMMAND lsb_release -si OUTPUT_VARIABLE LINUX_DISTRO OUTPUT_STRIP_TRAILING_WHITESPACE)
+ execute_process(COMMAND lsb_release -sc OUTPUT_VARIABLE LINUX_DISTRO_CODENAME OUTPUT_STRIP_TRAILING_WHITESPACE)
+ execute_process(COMMAND lsb_release -sr OUTPUT_VARIABLE LINUX_DISTRO_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ string(TOLOWER ${LINUX_DISTRO} LINUX_DISTRO)
+ if(LINUX_DISTRO_CODENAME STREQUAL "n/a")
+ set(DISTRO_PACK_PATH ${LINUX_DISTRO}/${LINUX_DISTRO_VERSION}/)
+ else()
+ set(DISTRO_PACK_PATH ${LINUX_DISTRO}/${LINUX_DISTRO_CODENAME}/)
+ endif()
+else()
+ set(DISTRO_PACK_PATH ${CMAKE_SYSTEM_NAME}/)
+endif()
+
+# default CPack generators
+set(CPACK_GENERATOR TGZ STGZ)
+
+# extra CPack generators
+if(LINUX_DISTRO STREQUAL "debian" OR LINUX_DISTRO STREQUAL "ubuntu" OR LINUX_DISTRO STREQUAL "linuxmint")
+ list(APPEND CPACK_GENERATOR DEB)
+elseif(LINUX_DISTRO STREQUAL "fedora" OR LINUX_DISTRO STREQUAL "opensuse" OR LINUX_DISTRO STREQUAL "centos")
+ list(APPEND CPACK_GENERATOR RPM)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+ list(APPEND CPACK_GENERATOR FREEBSD)
+endif()
+
+# general CPack config
+set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/${DISTRO_PACK_PATH})
+message(STATUS "CPack: packages will be generated under ${CPACK_PACKAGE_DIRECTORY}")
+if(BUILD_SHARED_LIBS)
+ set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${PROJECT_VERSION_MAJOR}")
+else()
+ set(CPACK_PACKAGE_NAME "${PROJECT_NAME}-devel")
+endif()
+set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LibTomMath")
+set(CPACK_PACKAGE_VENDOR "libtom projects")
+set(CPACK_PACKAGE_CONTACT "libtom@googlegroups.com")
+set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
+set(PACKAGE_NAME_TRAILER ${CPACK_PACKAGE_VERSION}-${PACKAGE_RELEASE_VERSION}_${MACHINE_ARCH})
+set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${PACKAGE_NAME_TRAILER})
+set(CPACK_STRIP_FILES ON)
+
+# deb specific CPack config
+set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
+set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
+set(CPACK_DEBIAN_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION})
+if(BUILD_SHARED_LIBS)
+ set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
+else()
+ set(CPACK_DEBIAN_PACKAGE_NAME "${PROJECT_NAME}-dev")
+ set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
+endif()
+
+# rpm specific CPack config
+set(CPACK_RPM_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION})
+set(CPACK_RPM_PACKAGE_ARCHITECTURE ${MACHINE_ARCH})
+set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}")
+set(CPACK_RPM_PACKAGE_LICENSE "The Unlicense")
+
+# FreeBSD specific CPack config
+set(CPACK_FREEBSD_PACKAGE_MAINTAINER "gahr@FreeBSD.org")
+set(CPACK_FREEBSD_PACKAGE_ORIGIN "math/libtommath")
+set(CPACK_FREEBSD_PACKAGE_CATEGORIES "math")
+
+include(CPack)
diff --git a/README.md b/README.md
index be5b207..7ee58bb 100644
--- a/README.md
+++ b/README.md
@@ -6,9 +6,9 @@ This is the git repository for [LibTomMath](http://www.libtom.net/LibTomMath/),
### Travis CI
-master: [![Build Status](https://api.travis-ci.org/libtom/libtommath.png?branch=master)](https://travis-ci.org/libtom/libtommath)
+master: [![Build Status](https://github.com/libtom/libtommath/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/libtom/libtommath/actions/workflows/main.yml?query=branch%3Amaster+++)
-develop: [![Build Status](https://api.travis-ci.org/libtom/libtommath.png?branch=develop)](https://travis-ci.org/libtom/libtommath)
+develop: [![Build Status](https://github.com/libtom/libtommath/actions/workflows/main.yml/badge.svg?branch=develop)](https://github.com/libtom/libtommath/actions/workflows/main.yml?query=branch%3Adevelop+++)
### AppVeyor
@@ -42,3 +42,17 @@ Tests are located in `demo/` and can be built in two flavors.
## Building and Installing
Building is straightforward for GNU Linux only, the section "Building LibTomMath" in the documentation in `doc/bn.pdf` has the details.
+
+### CMake support
+
+The project provides support for the CMake build system.
+
+```
+git clone https://github.com/libtom/libtommath.git
+mkdir -p libtommath/build
+cd libtommath/build
+cmake ..
+make -j$(nproc)
+```
+
+A shared library build can be done by setting `-DBUILD_SHARED_LIBS=On` when invoking the `cmake` command.
diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt
new file mode 100644
index 0000000..06ff898
--- /dev/null
+++ b/demo/CMakeLists.txt
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: Unlicense
+#
+# LibTomMath, a free open source portable number theoretic multiple-precision
+# integer (MPI) library written entirely in C.
+#
+
+cmake_minimum_required(VERSION 3.10)
+
+set(LTM_TEST test-ltm)
+
+# This file can be included from the top level or used stand-alone
+if(PROJECT_NAME)
+ set(LIBRARY_NAME ${PROJECT_NAME})
+else()
+ # Define an independent project and all the necessary stuff around
+ project(${LTM_TEST}
+ LANGUAGES C)
+ set(LIBRARY_NAME libtommath)
+ find_package(${LIBRARY_NAME})
+ include(CTest)
+ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+ set(CMAKE_BUILD_TYPE "Release")
+ endif()
+endif()
+
+#-----------------------------------------------------------------------------
+# Compose CFLAGS etc.
+#-----------------------------------------------------------------------------
+
+if(NOT MSVC)
+ set(CMAKE_C_FLAGS_DEBUG "-g3 -O1")
+endif()
+
+#-----------------------------------------------------------------------------
+# demo target
+#-----------------------------------------------------------------------------
+
+add_executable(${LTM_TEST}
+ ${CMAKE_CURRENT_SOURCE_DIR}/shared.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/test.c
+)
+
+target_include_directories(${LTM_TEST} PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ $<$<STREQUAL:${PROJECT_NAME},${LTM_TEST}>:${CMAKE_CURRENT_SOURCE_DIR}/..>
+)
+
+target_link_libraries(${LTM_TEST} PRIVATE
+ ${LIBRARY_NAME}
+)
+
+target_compile_options(${LTM_TEST} PRIVATE
+ $<$<STREQUAL:$<TARGET_PROPERTY:${LIBRARY_NAME},TYPE>,SHARED_LIBRARY>:-DLTM_TEST_DYNAMIC>
+ ${LTM_C_FLAGS}
+)
+target_link_options(${LTM_TEST} BEFORE PUBLIC
+ ${LTM_LD_FLAGS}
+)
+
+#-----------------------------------------------------------------------------
+# CTest
+#-----------------------------------------------------------------------------
+add_test(NAME ${LTM_TEST} COMMAND ${LTM_TEST})
diff --git a/helper.pl b/helper.pl
index 20b0dc9..e5ad27a 100755
--- a/helper.pl
+++ b/helper.pl
@@ -221,11 +221,32 @@ sub patch_file {
return $content;
}
+sub make_sources_cmake {
+ my ($src_ref, $hdr_ref) = @_;
+ my @sources = @{ $src_ref };
+ my @headers = @{ $hdr_ref };
+ my $output = "# SPDX-License-Identifier: Unlicense
+# Autogenerated File! Do not edit.
+
+set(SOURCES\n";
+ foreach my $sobj (sort @sources) {
+ $output .= $sobj . "\n";
+ }
+ $output .= ")\n\nset(HEADERS\n";
+ foreach my $hobj (sort @headers) {
+ $output .= $hobj . "\n";
+ }
+ $output .= ")\n";
+ return $output;
+}
+
sub process_makefiles {
my $write = shift;
my $changed_count = 0;
- my @o = map { my $x = $_; $x =~ s/\.c$/.o/; $x } bsd_glob("*.c");
- my @all = bsd_glob("*.{c,h}");
+ my @headers = bsd_glob("*.h");
+ my @sources = bsd_glob("*.c");
+ my @o = map { my $x = $_; $x =~ s/\.c$/.o/; $x } @sources;
+ my @all = sort(@sources, @headers);
my $var_o = prepare_variable("OBJECTS", @o);
(my $var_obj = $var_o) =~ s/\.o\b/.obj/sg;
@@ -244,10 +265,12 @@ sub process_makefiles {
}
# update OBJECTS + HEADERS in makefile*
- for my $m (qw/ makefile makefile.shared makefile_include.mk makefile.msvc makefile.unix makefile.mingw /) {
+ for my $m (qw/ makefile makefile.shared makefile_include.mk makefile.msvc makefile.unix makefile.mingw sources.cmake /) {
my $old = read_file($m);
my $new = $m eq 'makefile.msvc' ? patch_file($old, $var_obj)
- : patch_file($old, $var_o);
+ : $m eq 'sources.cmake' ? make_sources_cmake(\@sources, \@headers)
+ : patch_file($old, $var_o);
+
if ($old ne $new) {
write_file($m, $new) if $write;
warn "changed: $m\n";
diff --git a/libtommath.pc.in b/libtommath.pc.in
index 099b1cd..ad8f5c3 100644
--- a/libtommath.pc.in
+++ b/libtommath.pc.in
@@ -1,10 +1,9 @@
-prefix=@to-be-replaced@
-exec_prefix=${prefix}
-libdir=${exec_prefix}/lib
-includedir=${prefix}/include
+prefix=@CMAKE_INSTALL_PREFIX@
+libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@
Name: LibTomMath
Description: public domain library for manipulating large integer numbers
-Version: @to-be-replaced@
+Version: @PROJECT_VERSION@
Libs: -L${libdir} -ltommath
Cflags: -I${includedir}
diff --git a/makefile.shared b/makefile.shared
index 41a0cd2..4938da8 100644
--- a/makefile.shared
+++ b/makefile.shared
@@ -65,7 +65,8 @@ install: $(LIBNAME)
install -d $(DESTDIR)$(INCPATH)
$(LIBTOOL) --mode=install install -m 644 $(LIBNAME) $(DESTDIR)$(LIBPATH)/$(LIBNAME)
install -m 644 $(HEADERS_PUB) $(DESTDIR)$(INCPATH)
- sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' libtommath.pc.in > libtommath.pc
+ sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' -e 's,@CMAKE_INSTALL_LIBDIR@,lib,' \
+ -e 's,@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@,include/tommath,' libtommath.pc.in > libtommath.pc
install -d $(DESTDIR)$(LIBPATH)/pkgconfig
install -m 644 libtommath.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
diff --git a/sources.cmake b/sources.cmake
new file mode 100644
index 0000000..797d461
--- /dev/null
+++ b/sources.cmake
@@ -0,0 +1,169 @@
+# SPDX-License-Identifier: Unlicense
+# Autogenerated File! Do not edit.
+
+set(SOURCES
+mp_2expt.c
+mp_abs.c
+mp_add.c
+mp_add_d.c
+mp_addmod.c
+mp_and.c
+mp_clamp.c
+mp_clear.c
+mp_clear_multi.c
+mp_cmp.c
+mp_cmp_d.c
+mp_cmp_mag.c
+mp_cnt_lsb.c
+mp_complement.c
+mp_copy.c
+mp_count_bits.c
+mp_cutoffs.c
+mp_div.c
+mp_div_2.c
+mp_div_2d.c
+mp_div_d.c
+mp_dr_is_modulus.c
+mp_dr_reduce.c
+mp_dr_setup.c
+mp_error_to_string.c
+mp_exch.c
+mp_expt_n.c
+mp_exptmod.c
+mp_exteuclid.c
+mp_fread.c
+mp_from_sbin.c
+mp_from_ubin.c
+mp_fwrite.c
+mp_gcd.c
+mp_get_double.c
+mp_get_i32.c
+mp_get_i64.c
+mp_get_l.c
+mp_get_mag_u32.c
+mp_get_mag_u64.c
+mp_get_mag_ul.c
+mp_grow.c
+mp_hash.c
+mp_init.c
+mp_init_copy.c
+mp_init_i32.c
+mp_init_i64.c
+mp_init_l.c
+mp_init_multi.c
+mp_init_set.c
+mp_init_size.c
+mp_init_u32.c
+mp_init_u64.c
+mp_init_ul.c
+mp_invmod.c
+mp_is_square.c
+mp_kronecker.c
+mp_lcm.c
+mp_log_n.c
+mp_lshd.c
+mp_mod.c
+mp_mod_2d.c
+mp_montgomery_calc_normalization.c
+mp_montgomery_reduce.c
+mp_montgomery_setup.c
+mp_mul.c
+mp_mul_2.c
+mp_mul_2d.c
+mp_mul_d.c
+mp_mulmod.c
+mp_neg.c
+mp_or.c
+mp_pack.c
+mp_pack_count.c
+mp_prime_fermat.c
+mp_prime_frobenius_underwood.c
+mp_prime_is_prime.c
+mp_prime_miller_rabin.c
+mp_prime_next_prime.c
+mp_prime_rabin_miller_trials.c
+mp_prime_rand.c
+mp_prime_strong_lucas_selfridge.c
+mp_radix_size.c
+mp_radix_size_overestimate.c
+mp_rand.c
+mp_rand_source.c
+mp_read_radix.c
+mp_reduce.c
+mp_reduce_2k.c
+mp_reduce_2k_l.c
+mp_reduce_2k_setup.c
+mp_reduce_2k_setup_l.c
+mp_reduce_is_2k.c
+mp_reduce_is_2k_l.c
+mp_reduce_setup.c
+mp_root_n.c
+mp_rshd.c
+mp_sbin_size.c
+mp_set.c
+mp_set_double.c
+mp_set_i32.c
+mp_set_i64.c
+mp_set_l.c
+mp_set_u32.c
+mp_set_u64.c
+mp_set_ul.c
+mp_shrink.c
+mp_signed_rsh.c
+mp_sqrmod.c
+mp_sqrt.c
+mp_sqrtmod_prime.c
+mp_sub.c
+mp_sub_d.c
+mp_submod.c
+mp_to_radix.c
+mp_to_sbin.c
+mp_to_ubin.c
+mp_ubin_size.c
+mp_unpack.c
+mp_xor.c
+mp_zero.c
+s_mp_add.c
+s_mp_copy_digs.c
+s_mp_div_3.c
+s_mp_div_recursive.c
+s_mp_div_school.c
+s_mp_div_small.c
+s_mp_exptmod.c
+s_mp_exptmod_fast.c
+s_mp_get_bit.c
+s_mp_invmod.c
+s_mp_invmod_odd.c
+s_mp_log.c
+s_mp_log_2expt.c
+s_mp_log_d.c
+s_mp_montgomery_reduce_comba.c
+s_mp_mul.c
+s_mp_mul_balance.c
+s_mp_mul_comba.c
+s_mp_mul_high.c
+s_mp_mul_high_comba.c
+s_mp_mul_karatsuba.c
+s_mp_mul_toom.c
+s_mp_prime_is_divisible.c
+s_mp_prime_tab.c
+s_mp_radix_map.c
+s_mp_radix_size_overestimate.c
+s_mp_rand_platform.c
+s_mp_sqr.c
+s_mp_sqr_comba.c
+s_mp_sqr_karatsuba.c
+s_mp_sqr_toom.c
+s_mp_sub.c
+s_mp_zero_buf.c
+s_mp_zero_digs.c
+)
+
+set(HEADERS
+tommath.h
+tommath_c89.h
+tommath_class.h
+tommath_cutoffs.h
+tommath_private.h
+tommath_superclass.h
+)