diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f29ecd0..db3bef9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,22 +4,25 @@ # integer (MPI) library written entirely in C. # +# CMakeLitst.tx formated by cmake-format (https://github.com/cheshirekow/cmake_format) with default config + cmake_minimum_required(VERSION 3.10) -project(libtommath - VERSION 1.3.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) +project( + libtommath + VERSION 1.3.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 +# 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) @@ -27,37 +30,39 @@ include(CMakePackageConfigHelpers) option(BUILD_TESTING "" OFF) include(CTest) include(sources.cmake) - -#----------------------------------------------------------------------------- +include(CMakePrintHelpers) +# ----------------------------------------------------------------------------- # Options -#----------------------------------------------------------------------------- -option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"ON\", default is static" OFF) -option(BUILD_TUNING "Run a tuning program for the fast multiplication/squaring algorithms if \"ON\"" OFF) -option(BUILD_GRAPHS "Run a benchmark of the fast multiplication/squaring algorithms and make graphics if \"ON\"" OFF) - -option(BUILD_PROFILE "Run a profiler (branch optimization) if \"ON\"" OFF) -option(BUILD_PROFILE_TUNED "Run a profiler (branch optimization) after tuning fast multiplication if \"ON\"" OFF) -option(BUILD_PROFILE_TUNED_TUNED "Run a profiler (branch optimization) after tuning fast multiplication and again at the end if \"ON\"" OFF) - -option(BUILD_PROF_CMP "Run benchmarks before and after profiling and generate plots and images\ - in \"logs/\" if \"ON\" Works on the amalgamated version" OFF) -option(BUILD_PROF_CMP_TUNED "Run benchmarks before and after tuning and profiling and generate\ - plots and images in \"logs/\" if \"ON\" Works on the amalgamated version" OFF) -option(BUILD_PROF_CMP_TUNED_TUNED "Run benchmarks before and after tuning, profiling, tuning in that order\ - and generate\ plots and images in \"logs/\" if \"ON\" Works on the amalgamated version" OFF) - -# Set a common control variable for profiling -if(BUILD_PROFILE OR BUILD_PROFILE_TUNED OR BUILD_PROFILE_TUNED_TUNED OR BUILD_PROF_CMP OR BUILD_PROF_CMP_TUNED OR BUILD_PROF_CMP_TUNED_TUNED) -set(PREPARE_PROFILING 1) -endif() - -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- +option( + BUILD_SHARED_LIBS + "Build shared library and only the shared library if \"ON\", default is static" + OFF) +option( + BUILD_TUNING + "Run a tuning program for the fast multiplication/squaring algorithms if \"ON\"" + OFF) +option( + BUILD_GRAPHS + "Run a benchmark of the fast multiplication/squaring algorithms after tuning and make graphics if \"ON\"" + OFF) + +option( + BUILD_PROFILE + "Run benchmarks before and after profiling (branch optimization) and generate plots and images\ + in \"logs/\" if \"ON\"" + OFF) +# option(BUILD_PROFILE_TUNED "Run a profiler (branch optimization) after tuning +# fast multiplication if \"ON\"" OFF) option(BUILD_PROFILE_TUNED_TUNED "Run a +# profiler (branch optimization) after tuning and tune again at the end if +# \"ON\"" 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") @@ -65,192 +70,229 @@ endif() # We only differentiate between MSVC and GCC-compatible compilers if(MSVC) - set(LTM_C_FLAGS -W3) + set(LTM_C_FLAGS -W3) elseif(WATCOM) - set(LTM_C_FLAGS -fo=.obj -oaxt -3r -w3) + set(LTM_C_FLAGS -fo=.obj -oaxt -3r -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") + 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 elimination - set(CMAKE_C_FLAGS_DEBUG "-O1 ${CMAKE_C_FLAGS_DEBUG}") + list(APPEND LTM_C_FLAGS -Wno-typedef-redefinition -Wno-tautological-compare + -Wno-builtin-requires-header) + # Clang requires at least '-O1' for dead code elimination + 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) + 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) + list(APPEND LTM_C_FLAGS -Wno-nullability-completeness) endif() if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN") - list(APPEND LTM_C_FLAGS -no-undefined) + 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" +# 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}) - -#----------------------------------------------------------------------------- +if(BUILD_PROFILE) + list(APPEND LTM_C_FLAGS -fprofile-arcs) +endif() +# ----------------------------------------------------------------------------- # library target -#----------------------------------------------------------------------------- -add_library(${PROJECT_NAME} - ${SOURCES} - ${HEADERS} -) - -target_include_directories(${PROJECT_NAME} PUBLIC - $ - $ -) - -target_compile_options(${PROJECT_NAME} BEFORE PRIVATE - ${LTM_C_FLAGS} -) -target_link_options(${PROJECT_NAME} BEFORE PRIVATE - ${LTM_LD_FLAGS} -) - +# ----------------------------------------------------------------------------- +add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) + +target_include_directories( + ${PROJECT_NAME} + PUBLIC $ + $) + +target_compile_options(${PROJECT_NAME} BEFORE PRIVATE ${LTM_C_FLAGS}) +target_link_options(${PROJECT_NAME} BEFORE PRIVATE ${LTM_LD_FLAGS}) +if(BUILD_PROFILE) + target_link_libraries(${PROJECT_NAME} PRIVATE gcov) +endif() set(PUBLIC_HEADERS tommath.h) -set(C89 False CACHE BOOL "(Usually maintained automatically) Enable when the library is in c89 mode to package the correct header files on install") +set(C89 + False + CACHE + BOOL + "(Usually maintained automatically) Enable when the library is in c89 mode to package the correct header files on install" +) if(C89) - list(APPEND PUBLIC_HEADERS tommath_c89.h) + list(APPEND PUBLIC_HEADERS tommath_c89.h) endif() -set_target_properties(${PROJECT_NAME} PROPERTIES - OUTPUT_NAME tommath - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR} - PUBLIC_HEADER "${PUBLIC_HEADERS}" -) +set_target_properties( + ${PROJECT_NAME} + PROPERTIES OUTPUT_NAME tommath + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} + PUBLIC_HEADER "${PUBLIC_HEADERS}") 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(FATAL_ERROR "This compiler does not support LTO. Reconfigure ${PROJECT_NAME} with -DCOMPILE_LTO=OFF.") - endif() + check_ipo_supported(RESULT COMPILER_SUPPORTS_LTO) + if(COMPILER_SUPPORTS_LTO) + set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION + TRUE) + else() + message( + FATAL_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) + enable_testing() + add_subdirectory(demo) endif() -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # tuning and benchmark targets -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- -# build dependencies, run etc/tune_it.sh and additionally run benchmarks if so advised +# build dependencies, run etc/tune_it.sh and additionally run benchmarks if so +# advised if(BUILD_TUNING OR BUILD_GRAPHS) - add_subdirectory(etc ${CMAKE_CURRENT_SOURCE_DIR}/etc) + add_subdirectory(etc ${CMAKE_CURRENT_SOURCE_DIR}/etc) endif() -# Profiling (branch optimizing) -if(PREPARE_PROFILING) - -## "Normal" version make->profile->make - -### Tuned "normal" version make->tune->profile->make - -### Double tuned Tuned "normal" version make->tune->profile->tune->make - -## Amalgamated version (all *c files concatenated into one large file) otherwise same as above - -### Tuned "amalgamated" version make->tune->profile->make - -### Double tuned "amalgamated" version make->tune->profile->tune->make - +if(BUILD_PROFILE) + # build "timing" from "demo/timing.c" + add_executable(timing demo/timing.c) + target_compile_options(timing BEFORE PRIVATE -DMP_VERSION=\"before\") + target_link_libraries(timing PRIVATE ${PROJECT_NAME}) + add_custom_command( + TARGET timing + POST_BUILD + COMMAND timing + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + # rebuild libtommath with -fprofile-arcs + add_custom_command( + TARGET timing + POST_BUILD + COMMAND make clean && cmake .. -DBUILD_PROFILE_SECOND_RUN=ON + -DBUILD_PROFILE=OFF && make) + # rebuild libtommath with -fbranch-probabilities +elseif(BUILD_PROFILE_SECOND_RUN) + list(APPEND LTM_C_FLAGS -fbranch-probabilities) + add_custom_command( + TARGET ${PROJECT_NAME} + POST_BUILD + COMMAND cmake .. -DBUILD_PROFILE_SECOND_RUN=OFF -DBUILD_PROFILE=OFF + -DBUILD_PROF_CMP=ON && make) + # Run timings over profiled library and run gnuplot over the logs +elseif(BUILD_PROF_CMP) + find_program(GNUPLOT gnuplot) + # Rebuild "timing" from "demo/timing.c" against the profiled library + add_executable(timing demo/timing.c) + target_compile_options(timing BEFORE PRIVATE -DMP_VERSION=\"after\") + target_link_libraries(timing PRIVATE ${PROJECT_NAME}) + # TODO: write the CMakeLists.txt in logs and do it properly + add_custom_command( + TARGET timing + POST_BUILD + COMMAND timing + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + # ("timing" writes its tables in the "log" directory) Plot pictures with + # version + COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/logs && ${GNUPLOT} -c + before_after.dem ${PROJECT_VERSION} + # back to build directory + COMMAND cd ${CMAKE_BINARY_DIR}) 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_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} COMPONENT Libraries - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} -) +install( + TARGETS ${PROJECT_NAME} + EXPORT ${TARGETS_EXPORT_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries + 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") + # 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 - ) + 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} - ) + 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 -) + ${PROJECT_VERSION_FILE} + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion) # Windows uses a different help sytem. if((NOT WIN32) AND (NOT CMAKE_HOST_WIN32)) -# install manpage (not gzipped, some BSD's do not want it compressed?) -install(FILES ${CMAKE_SOURCE_DIR}/doc/tommath.3 - DESTINATION ${CMAKE_INSTALL_MANDIR}/man3/ -) + # install manpage (not gzipped, some BSD's do not want it compressed?) + install(FILES ${CMAKE_SOURCE_DIR}/doc/tommath.3 + DESTINATION ${CMAKE_INSTALL_MANDIR}/man3/) endif() # install version file -install(FILES ${PROJECT_VERSION_FILE} - DESTINATION ${CONFIG_INSTALL_DIR} -) +install(FILES ${PROJECT_VERSION_FILE} DESTINATION ${CONFIG_INSTALL_DIR}) # build directory package config -export(EXPORT ${TARGETS_EXPORT_NAME} - FILE ${PROJECT_CONFIG_FILE} -) +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} -) +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) @@ -258,67 +300,94 @@ find_program(SYSCTL sysctl) find_program(UNAME uname) if(UNAME) - execute_process(COMMAND uname -m OUTPUT_VARIABLE MACHINE_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE) + 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) + execute_process( + COMMAND sysctl -b hw.machine_arch + OUTPUT_VARIABLE MACHINE_ARCH + OUTPUT_STRIP_TRAILING_WHITESPACE) else() - string(TOLOWER ${CMAKE_SYSTEM_NAME} MACHINE_ARCH) + 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() + 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}/) + set(DISTRO_PACK_PATH ${CMAKE_SYSTEM_NAME}/) endif() # make sure untagged versions get a different package name -execute_process(COMMAND git describe --exact-match --tags ERROR_QUIET RESULT_VARIABLE REPO_HAS_TAG) +execute_process( + COMMAND git describe --exact-match --tags + ERROR_QUIET + RESULT_VARIABLE REPO_HAS_TAG) if(REPO_HAS_TAG EQUAL 0) - set(PACKAGE_NAME_SUFFIX "") + set(PACKAGE_NAME_SUFFIX "") else() - set(PACKAGE_NAME_SUFFIX "-git") - message(STATUS "Use -git suffix") + set(PACKAGE_NAME_SUFFIX "-git") + message(STATUS "Use -git suffix") 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) +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) + list(APPEND CPACK_GENERATOR FREEBSD) endif() -set(LTM_DEBIAN_SHARED_PACKAGE_NAME "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}${PROJECT_VERSION_MAJOR}") +set(LTM_DEBIAN_SHARED_PACKAGE_NAME + "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}${PROJECT_VERSION_MAJOR}") # 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}") +message( + STATUS "CPack: packages will be generated under ${CPACK_PACKAGE_DIRECTORY}") if(BUILD_SHARED_LIBS) - set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${PROJECT_VERSION_MAJOR}") - set(CPACK_DEBIAN_PACKAGE_NAME "${LTM_DEBIAN_SHARED_PACKAGE_NAME}") + set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${PROJECT_VERSION_MAJOR}") + set(CPACK_DEBIAN_PACKAGE_NAME "${LTM_DEBIAN_SHARED_PACKAGE_NAME}") else() - set(CPACK_PACKAGE_NAME "${PROJECT_NAME}-devel") - set(CPACK_DEBIAN_LIBRARIES_PACKAGE_NAME "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}-dev") + set(CPACK_PACKAGE_NAME "${PROJECT_NAME}-devel") + set(CPACK_DEBIAN_LIBRARIES_PACKAGE_NAME + "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}-dev") 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(PACKAGE_NAME_TRAILER + ${CPACK_PACKAGE_VERSION}-${PACKAGE_RELEASE_VERSION}_${MACHINE_ARCH}) set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${PACKAGE_NAME_TRAILER}) # deb specific CPack config @@ -327,13 +396,13 @@ set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON) set(CPACK_DEBIAN_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION}) set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) if(BUILD_SHARED_LIBS) - set(CPACK_DEBIAN_PACKAGE_SECTION "libs") + set(CPACK_DEBIAN_PACKAGE_SECTION "libs") else() - set(CPACK_DEBIAN_PACKAGE_SECTION "devel") - set(CPACK_DEBIAN_PACKAGE_DEPENDS ${LTM_DEBIAN_SHARED_PACKAGE_NAME}) - set(CPACK_DEB_COMPONENT_INSTALL ON) - set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) - set(CPACK_COMPONENTS_ALL Libraries) + set(CPACK_DEBIAN_PACKAGE_SECTION "devel") + set(CPACK_DEBIAN_PACKAGE_DEPENDS ${LTM_DEBIAN_SHARED_PACKAGE_NAME}) + set(CPACK_DEB_COMPONENT_INSTALL ON) + set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) + set(CPACK_COMPONENTS_ALL Libraries) endif() # rpm specific CPack config diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index e4050bf5..0d6bc1c2 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -43,6 +43,8 @@ target_link_options(tune BEFORE PUBLIC ) if(BUILD_GRAPHS) + # used in tune_it.sh + find_program(GNUPLOT gnuplot) add_custom_command(TARGET tune POST_BUILD COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tune_it.sh 1000 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM) else() add_custom_command(TARGET tune POST_BUILD COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tune_it.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM) diff --git a/logs/Makefile b/logs/Makefile index 59987e51..0d73db98 100644 --- a/logs/Makefile +++ b/logs/Makefile @@ -6,4 +6,4 @@ cmp: gnuplot before_after.dem clean: - rm -f *-*.log *.png graphs-*.dem + rm -f *.log *.png graphs-*.dem diff --git a/logs/before_after.dem b/logs/before_after.dem index 33721ad2..3d7b9ede 100644 --- a/logs/before_after.dem +++ b/logs/before_after.dem @@ -1,26 +1,34 @@ set terminal png +# Good for most colorblinds +set colorsequence podo +set key top left; + set ylabel "Cycles per Operation" set xlabel "Operand size (bits)" -set output "addsub-ba.png" +set output "addsub-ba-".ARG1.".png" +set title "Addition/subtraction before and after profiling. Version: ".ARG1 plot 'add-before.log' smooth bezier title "Addition (before)", \ 'add-after.log' smooth bezier title "Addition (after)", \ 'sub-before.log' smooth bezier title "Subtraction (before)", \ 'sub-after.log' smooth bezier title "Subtraction (after)" -set output "mult-ba.png" +set output "mult-ba-".ARG1.".png" +set title "Multiplication before and after profiling. Version: ".ARG1 plot 'mult-before.log' smooth bezier title "Multiplication (without Karatsuba) (before)", \ 'mult-after.log' smooth bezier title "Multiplication (without Karatsuba) (after)", \ 'mult_kara-before.log' smooth bezier title "Multiplication (Karatsuba) (before)", \ 'mult_kara-after.log' smooth bezier title "Multiplication (Karatsuba) (after)" -set output "sqr-ba.png" +set output "sqr-ba-".ARG1.".png" +set title "Squaring before and after profiling. Version: ".ARG1 plot 'sqr-before.log' smooth bezier title "Squaring (without Karatsuba) (before)", \ 'sqr-after.log' smooth bezier title "Squaring (without Karatsuba) (after)", \ 'sqr_kara-before.log' smooth bezier title "Squaring (Karatsuba) (before)", \ 'sqr_kara-after.log' smooth bezier title "Squaring (Karatsuba) (after)" -set output "expt-ba.png" +set output "expt-ba-".ARG1.".png" +set title "Exponentiation algorithms before and after profiling. Version: ".ARG1 plot 'expt-before.log' smooth bezier title "Exptmod (Montgomery) (before)", \ 'expt-after.log' smooth bezier title "Exptmod (Montgomery) (after)", \ 'expt_dr-before.log' smooth bezier title "Exptmod (Diminished Radix) (before)", \ @@ -30,7 +38,8 @@ plot 'expt-before.log' smooth bezier title "Exptmod (Montgomery) (before)", \ 'expt_2kl-before.log' smooth bezier title "Exptmod (2k-l Reduction) (before)", \ 'expt_2kl-after.log' smooth bezier title "Exptmod (2k-l Reduction) (after)" -set output "invmod-ba.png" +set output "invmod-ba-".ARG1.".png" +set title "Invmod algorithms before and after profiling. Version: ".ARG1 plot 'invmod-before.log' smooth bezier title "Modular Inverse (before)", \ 'invmod-after.log' smooth bezier title "Modular Inverse (after)" diff --git a/makefile_include.mk b/makefile_include.mk index 7bca5cad..4aadc770 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -191,9 +191,9 @@ cleancov: cleancov-clean clean clean: rm -f *.gcda *.gcno *.gcov *.bat *.o *.a *.obj *.lib *.exe *.dll etclib/*.o \ demo/*.o test timing mtest_opponent mtest/mtest mtest/mtest.exe tuning_list \ - *.s tommath_amalgam.c pre_gen/tommath_amalgam.c *.da *.dyn *.dpi tommath.tex \ + *.s tommath_amalgam.c *.da *.dyn *.dpi tommath.tex \ cmake_install.cmake Makefile \ `find . -type f | grep [~] | xargs` *.lo *.la - rm -rf .libs/ demo/.libs CMakeFiles + rm -rf .libs/ demo/.libs CMakeFiles pre_gen ${MAKE} -C etc/ clean MAKE=${MAKE} ${MAKE} -C doc/ clean MAKE=${MAKE}