port cmake integration changes from libtommath
... also enable building of tests. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
parent
d07a66f9b2
commit
97d0f61491
279
CMakeLists.txt
279
CMakeLists.txt
@ -1,68 +1,196 @@
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
#
|
||||
# LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(tomcrypt VERSION 1.18.2)
|
||||
project(libtomcrypt
|
||||
VERSION 1.18.2
|
||||
DESCRIPTION "A modular cryptographic library."
|
||||
HOMEPAGE_URL "https://www.libtom.net/LibTomCrypt"
|
||||
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 required CMake modules
|
||||
# Include CMake modules
|
||||
#-----------------------------------------------------------------------------
|
||||
include(GNUInstallDirs)
|
||||
include(CheckIPOSupported)
|
||||
include(CMakePackageConfigHelpers)
|
||||
# for potential builds against gnump
|
||||
include(FindPkgConfig)
|
||||
# default is "No tests"
|
||||
option(BUILD_TESTING "" OFF)
|
||||
include(CTest)
|
||||
include(sources.cmake)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Options
|
||||
#-----------------------------------------------------------------------------
|
||||
option(USE_LTM "Build with libtommath" TRUE)
|
||||
option(BUILD_SHARED_LIBS "Build shared library" FALSE)
|
||||
option(WITH_LTM "Build with support for libtommath" TRUE)
|
||||
option(WITH_GMP "Build with support for GNU Multi Precision Arithmetic Library" FALSE)
|
||||
set(MPI_PROVIDER "LTM" CACHE STRING "Build tests and demos against 'LTM', 'TFM' or 'GMP', default is LTM")
|
||||
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 differentiate between MSVC, WATCOM and GCC-compatible compilers
|
||||
if(MSVC)
|
||||
set(LTC_C_FLAGS -W3)
|
||||
elseif(WATCOM)
|
||||
set(LTC_C_FLAGS -fo=.obj -oaxt -3r -w3)
|
||||
else()
|
||||
set(LTC_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 LTC_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 LTC_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 LTC_C_FLAGS -Wno-nullability-completeness)
|
||||
endif()
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
|
||||
list(APPEND LTC_C_FLAGS -no-undefined)
|
||||
endif()
|
||||
|
||||
# If the user set the environment variables at generate-time, append them
|
||||
# in order to allow overriding our defaults.
|
||||
# ${LTC_CFLAGS} means the user passed it via sth like:
|
||||
# $ cmake -DLTC_CFLAGS="foo"
|
||||
list(APPEND LTC_C_FLAGS ${LTC_CFLAGS})
|
||||
list(APPEND LTC_LD_FLAGS ${LTC_LDFLAGS})
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Library targets
|
||||
#-----------------------------------------------------------------------------
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/sources.cmake)
|
||||
add_library(${PROJECT_NAME} ${SOURCES})
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Definitions
|
||||
#-----------------------------------------------------------------------------
|
||||
if(USE_LTM)
|
||||
find_package(tommath 1.2.0 REQUIRED)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LTM LTM_DESC)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Add subdirectories
|
||||
#-----------------------------------------------------------------------------
|
||||
add_subdirectory(demos)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Public headers
|
||||
#-----------------------------------------------------------------------------
|
||||
get_property(${PROJECT_NAME}-public-headers GLOBAL PROPERTY PUBLIC_HEADERS)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Library target properties
|
||||
#-----------------------------------------------------------------------------
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${${PROJECT_NAME}-public-headers}")
|
||||
add_library(${PROJECT_NAME}
|
||||
${SOURCES}
|
||||
${PUBLIC_HEADERS}
|
||||
${PRIVATE_HEADERS}
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/headers>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/lib${PROJECT_NAME}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
|
||||
)
|
||||
|
||||
# libtommath dependent
|
||||
if(USE_LTM)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC tommath)
|
||||
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 tomcrypt
|
||||
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(SEND_ERROR "This compiler does not support LTO. Reconfigure ${PROJECT_NAME} with -DCOMPILE_LTO=OFF.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# MPI provider
|
||||
#-----------------------------------------------------------------------------
|
||||
# libtommath
|
||||
if(WITH_LTM)
|
||||
find_package(libtommath 1.2.0 REQUIRED)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC LTM_DESC)
|
||||
if(MPI_PROVIDER MATCHES "LTM")
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LTM)
|
||||
endif()
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC libtommath)
|
||||
endif()
|
||||
# GNU MP
|
||||
if(WITH_GMP)
|
||||
pkg_check_modules(GMP REQUIRED gmp>=6.1.2)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC GMP_DESC)
|
||||
if(MPI_PROVIDER MATCHES "GMP")
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_GMP)
|
||||
endif()
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${GMP_LIBRARIES})
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# demos&test targets
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
add_subdirectory(demos)
|
||||
if(BUILD_TESTING)
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Install/export targets and files
|
||||
#---------------------------------------------------------------------------------------
|
||||
set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/lib${PROJECT_NAME}")
|
||||
set(PROJECT_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/lib${PROJECT_NAME}-config-version.cmake")
|
||||
set(PROJECT_CONFIG_FILE "lib${PROJECT_NAME}-config.cmake")
|
||||
set(TARGETS_EXPORT_NAME "lib${PROJECT_NAME}Targets")
|
||||
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
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${TARGETS_EXPORT_NAME}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
# Install libtomcrypt.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(
|
||||
@ -71,33 +199,20 @@ write_basic_package_version_file(
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
|
||||
# install targets
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
COMPONENT "runtime"
|
||||
EXPORT ${TARGETS_EXPORT_NAME}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lib${PROJECT_NAME}
|
||||
)
|
||||
|
||||
# install version file
|
||||
install(FILES ${PROJECT_VERSION_FILE}
|
||||
COMPONENT "development"
|
||||
DESTINATION ${CONFIG_INSTALL_DIR}
|
||||
)
|
||||
|
||||
# build directory package config
|
||||
export(EXPORT ${TARGETS_EXPORT_NAME}
|
||||
FILE ${PROJECT_CONFIG_FILE}
|
||||
NAMESPACE "LTC::"
|
||||
)
|
||||
|
||||
# installed package config
|
||||
install(EXPORT ${TARGETS_EXPORT_NAME}
|
||||
COMPONENT "development"
|
||||
DESTINATION ${CONFIG_INSTALL_DIR}
|
||||
FILE ${PROJECT_CONFIG_FILE}
|
||||
NAMESPACE "LTC::"
|
||||
)
|
||||
|
||||
# add to CMake registry
|
||||
@ -106,19 +221,33 @@ export(PACKAGE ${PROJECT_NAME})
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Create release packages
|
||||
#---------------------------------------------------------------------------------------
|
||||
# package release version
|
||||
set(PACKAGE_RELEASE_VERSION 1)
|
||||
|
||||
# determine distribution and architecture
|
||||
find_program(LSB_RELEASE lsb_release)
|
||||
find_program(SYSCTL sysctl)
|
||||
find_program(UNAME uname)
|
||||
|
||||
execute_process(COMMAND uname -m OUTPUT_VARIABLE MACHINE_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
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 -sr OUTPUT_VARIABLE LINUX_DISTRO_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
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
|
||||
@ -129,33 +258,47 @@ if(LINUX_DISTRO STREQUAL "debian" OR LINUX_DISTRO STREQUAL "ubuntu" OR LINUX_DIS
|
||||
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)
|
||||
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/${DISTRO_PACK_PATH})
|
||||
message(STATUS "CPack: packages will be generated under ${CPACK_PACKAGE_DIRECTORY}")
|
||||
set(CPACK_PACKAGE_NAME "lib${PROJECT_NAME}")
|
||||
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 "LibTomCrypt")
|
||||
set(CPACK_PACKAGE_VENDOR "LibTomCrypt")
|
||||
set(CPACK_PACKAGE_VENDOR "libtom projects")
|
||||
set(CPACK_PACKAGE_CONTACT "libtom@googlegroups.com")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
||||
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${PACKAGE_RELEASE_VERSION}_${LINUX_DISTRO}-${LINUX_DISTRO_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})
|
||||
set(CPACK_STRIP_FILES ON)
|
||||
|
||||
# deb specific CPack config
|
||||
set(CPACK_DEBIAN_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION})
|
||||
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
|
||||
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
|
||||
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://www.libtom.net/LibTomCrypt")
|
||||
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
|
||||
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_URL "https://www.libtom.net/LibTomCrypt")
|
||||
set(CPACK_RPM_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION})
|
||||
set(CPACK_RPM_PACKAGE_ARCHITECTURE ${MACHINE_ARCH})
|
||||
set(CPACK_RPM_PACKAGE_NAME "lib${PROJECT_NAME}-${PROJECT_VERSION}")
|
||||
set(CPACK_RPM_FILE_NAME "lib${PROJECT_NAME}_${PROJECT_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}_${LINUX_DISTRO}-${LINUX_DISTRO_VERSION}_${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
|
||||
set(CPACK_RPM_PACKAGE_LICENSE "WTFPL")
|
||||
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 "security/libtomcrypt")
|
||||
set(CPACK_FREEBSD_PACKAGE_CATEGORIES "security")
|
||||
|
||||
include(CPack)
|
||||
|
15
README.md
15
README.md
@ -180,6 +180,21 @@ You want to install the shared library to a special path and use it from this pa
|
||||
|
||||
Have a look at the developer documentation, [[GNU]] or [[FreeBSD]] to get a detailed explanation of all the variables.
|
||||
|
||||
## CMake support
|
||||
|
||||
The project provides support for the CMake build system.
|
||||
|
||||
```
|
||||
git clone https://github.com/libtom/libtomcrypt.git
|
||||
mkdir -p libtomcrypt/build
|
||||
cd libtomcrypt/build
|
||||
cmake ..
|
||||
make -j$(nproc)
|
||||
```
|
||||
|
||||
More details around building with CMake can be found in the developer documentation.
|
||||
|
||||
|
||||
[GNU]: https://www.gnu.org/prep/standards/html_node/DESTDIR.html
|
||||
|
||||
[FreeBSD]: https://www.freebsd.org/doc/en/books/porters-handbook/porting-prefix.html
|
||||
|
@ -8110,6 +8110,23 @@ make -f makefile.shared install CFLAGS="-DTFM_DESC" EXTRALIBS=-ltfm
|
||||
This will build and install the library and link the shared object against the TomsFastMath library (which must be installed as a shared object as well). The
|
||||
shared build process requires libtool to be installed.
|
||||
|
||||
\mysection{Building with CMake}
|
||||
|
||||
LibTomCrypt can also be built via CMake.
|
||||
|
||||
\begin{verbatim}
|
||||
git clone https://github.com/libtom/libtomcrypt.git
|
||||
mkdir -p libtomcrypt/build
|
||||
cd libtomcrypt/build
|
||||
cmake ..
|
||||
make -j$(nproc)
|
||||
\end{verbatim}
|
||||
|
||||
Per default a static library in \textbf{Release} configuration is built, without tests and building against the LibTomMath library.
|
||||
|
||||
A shared library build can be done by setting \textbf{-DBUILD\_SHARED\_LIBS=On} when invoking the \textbf{cmake} command.
|
||||
Tests can be enabled by setting \textbf{-DBUILD\_TESTING=On} when invoking the \textbf{cmake} command.
|
||||
|
||||
\mysection{Header Configuration}
|
||||
The file \textit{tomcrypt\_cfg.h} is what lets you control various high level macros which control the behaviour of the library. Build options are also
|
||||
stored in \textit{tomcrypt\_custom.h} which allow the enabling and disabling of various algorithms.
|
||||
|
13
helper.pl
13
helper.pl
@ -286,14 +286,19 @@ sub make_sources_cmake {
|
||||
foreach my $obj (sort @$list) {
|
||||
$output .= $obj . "\n";
|
||||
}
|
||||
$output .= ")\n\n";
|
||||
|
||||
$output .= ")\n\nset(PUBLIC_HEADERS\n";
|
||||
if ($pub_headers eq "") {
|
||||
return $output;
|
||||
}
|
||||
|
||||
$output .= "set(PUBLIC_HEADERS\n";
|
||||
|
||||
foreach my $obj (sort @$pub_headers) {
|
||||
$output .= $obj . "\n";
|
||||
}
|
||||
|
||||
$output .= ")\n\n";
|
||||
$output .= ")\n\nset(PRIVATE_HEADERS src/headers/tomcrypt_private.h)\n";
|
||||
$output .= "set_property(GLOBAL PROPERTY PUBLIC_HEADERS \$\{PUBLIC_HEADERS\}\)\n\n";
|
||||
|
||||
return $output;
|
||||
@ -316,6 +321,7 @@ sub process_makefiles {
|
||||
my $var_h = prepare_variable("HEADERS_PUB", (sort @h));
|
||||
(my $var_obj = $var_o) =~ s/\.o\b/.obj/sg;
|
||||
|
||||
my @t_srcs = sort (map { my $x = $_; $x =~ s/^tests\///; $x } @t);
|
||||
my $var_to = prepare_variable("TOBJECTS", sort map { my $x = $_; $x =~ s/\.c$/.o/; $x } @t);
|
||||
(my $var_tobj = $var_to) =~ s/\.o\b/.obj/sg;
|
||||
|
||||
@ -335,10 +341,11 @@ sub process_makefiles {
|
||||
}
|
||||
|
||||
# update OBJECTS + HEADERS in makefile*
|
||||
for my $m (qw/ makefile makefile.shared makefile.unix makefile.mingw makefile.msvc makefile_include.mk doc\/Doxyfile sources.cmake /) {
|
||||
for my $m (qw/ makefile makefile.shared makefile.unix makefile.mingw makefile.msvc makefile_include.mk doc\/Doxyfile sources.cmake tests\/sources.cmake /) {
|
||||
my $old = read_file($m);
|
||||
my $new = $m eq 'makefile.msvc' ? patch_file($old, $var_obj, $var_h, $var_tobj, @ver_version)
|
||||
: $m eq 'sources.cmake' ? make_sources_cmake(\@all, \@h)
|
||||
: $m eq 'tests/sources.cmake' ? make_sources_cmake(\@t_srcs, "")
|
||||
: patch_file($old, $var_o, $var_h, $var_to, @ver_version);
|
||||
|
||||
if ($old ne $new) {
|
||||
|
@ -1,10 +1,10 @@
|
||||
prefix=@to-be-replaced@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
libdir=${exec_prefix}/lib
|
||||
includedir=${prefix}/include
|
||||
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@
|
||||
|
||||
Name: LibTomCrypt
|
||||
Description: public domain open source cryptographic toolkit
|
||||
Version: @to-be-replaced@
|
||||
Version: @PROJECT_VERSION@
|
||||
Libs: -L${libdir} -ltomcrypt
|
||||
Cflags: -I${includedir}
|
||||
|
@ -79,7 +79,8 @@ endef
|
||||
$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
|
||||
|
||||
install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install
|
||||
sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' libtomcrypt.pc.in > libtomcrypt.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/tomcrypt,' libtomcrypt.pc.in > libtomcrypt.pc
|
||||
install -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
|
||||
install -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
|
||||
|
||||
|
@ -384,6 +384,7 @@ src/pk/dsa/dsa_shared_secret.c
|
||||
src/pk/dsa/dsa_sign_hash.c
|
||||
src/pk/dsa/dsa_verify_hash.c
|
||||
src/pk/dsa/dsa_verify_key.c
|
||||
src/pk/ec25519/ec25519_crypto_ctx.c
|
||||
src/pk/ec25519/ec25519_export.c
|
||||
src/pk/ec25519/ec25519_import_pkcs8.c
|
||||
src/pk/ec25519/tweetnacl.c
|
||||
@ -519,5 +520,6 @@ src/headers/tomcrypt_pkcs.h
|
||||
src/headers/tomcrypt_prng.h
|
||||
)
|
||||
|
||||
set(PRIVATE_HEADERS src/headers/tomcrypt_private.h)
|
||||
set_property(GLOBAL PROPERTY PUBLIC_HEADERS ${PUBLIC_HEADERS})
|
||||
|
||||
|
71
tests/CMakeLists.txt
Normal file
71
tests/CMakeLists.txt
Normal file
@ -0,0 +1,71 @@
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
#
|
||||
# LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
set(LTC_TEST test-ltc)
|
||||
|
||||
# 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(${LTC_TEST}
|
||||
LANGUAGES C)
|
||||
set(LIBRARY_NAME libtomcrypt)
|
||||
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
|
||||
#-----------------------------------------------------------------------------
|
||||
include(sources.cmake)
|
||||
set(PRIVATE_HEADERS
|
||||
common.h
|
||||
tomcrypt_test.h
|
||||
)
|
||||
|
||||
add_executable(${LTC_TEST}
|
||||
${SOURCES}
|
||||
${PRIVATE_HEADERS}
|
||||
)
|
||||
|
||||
target_include_directories(${LTC_TEST} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
$<$<STREQUAL:${PROJECT_NAME},${LTC_TEST}>:${CMAKE_CURRENT_SOURCE_DIR}/..>
|
||||
)
|
||||
|
||||
target_link_libraries(${LTC_TEST} PRIVATE
|
||||
${LIBRARY_NAME}
|
||||
)
|
||||
|
||||
target_compile_options(${LTC_TEST} PRIVATE
|
||||
$<$<STREQUAL:$<TARGET_PROPERTY:${LIBRARY_NAME},TYPE>,SHARED_LIBRARY>:-DLTC_TEST_DYNAMIC>
|
||||
-DCMAKE_SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"
|
||||
${LTC_C_FLAGS}
|
||||
)
|
||||
target_link_options(${LTC_TEST} BEFORE PUBLIC
|
||||
${LTC_LD_FLAGS}
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# CTest
|
||||
#-----------------------------------------------------------------------------
|
||||
add_test(NAME ${LTC_TEST} COMMAND ${LTC_TEST})
|
||||
|
||||
find_program(MEMORYCHECK_COMMAND valgrind)
|
||||
set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full")
|
@ -79,10 +79,26 @@ static off_t fsize(const char *filename)
|
||||
|
||||
return -1;
|
||||
}
|
||||
static DIR *s_opendir(const char *path, char *mypath, unsigned long l)
|
||||
{
|
||||
#ifdef CMAKE_SOURCE_DIR
|
||||
#define SOURCE_PREFIX CMAKE_SOURCE_DIR "/"
|
||||
#else
|
||||
#define SOURCE_PREFIX ""
|
||||
#endif
|
||||
DIR *d = NULL;
|
||||
int r = snprintf(mypath, l, "%s%s", SOURCE_PREFIX, path);
|
||||
if (r > 0 && (unsigned int)r < l) {
|
||||
d = opendir(mypath);
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
int test_process_dir(const char *path, void *ctx, dir_iter_cb process, dir_cleanup_cb cleanup, const char *test)
|
||||
{
|
||||
DIR *d = opendir(path);
|
||||
char mypath[PATH_MAX];
|
||||
DIR *d = s_opendir(path, mypath, sizeof(mypath));
|
||||
struct dirent *de;
|
||||
char fname[PATH_MAX];
|
||||
void* buf = NULL;
|
||||
@ -96,7 +112,7 @@ int test_process_dir(const char *path, void *ctx, dir_iter_cb process, dir_clean
|
||||
fname[0] = '\0';
|
||||
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0 || strcmp(de->d_name, "README.txt") == 0)
|
||||
continue;
|
||||
strcat(fname, path);
|
||||
strcat(fname, mypath);
|
||||
strcat(fname, "/");
|
||||
strcat(fname, de->d_name);
|
||||
fsz = fsize(fname);
|
||||
|
@ -13,7 +13,12 @@ int file_test(void)
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };
|
||||
unsigned char buf[200];
|
||||
unsigned long len;
|
||||
const char *fname = "tests/test.key";
|
||||
#ifdef CMAKE_SOURCE_DIR
|
||||
#define FILE_IN_SOURCE_DIR(f) CMAKE_SOURCE_DIR "/" f
|
||||
#else
|
||||
#define FILE_IN_SOURCE_DIR(f) f
|
||||
#endif
|
||||
const char *fname = FILE_IN_SOURCE_DIR("tests/test.key");
|
||||
FILE *in;
|
||||
int err, isha256, iaes;
|
||||
|
||||
|
35
tests/sources.cmake
Normal file
35
tests/sources.cmake
Normal file
@ -0,0 +1,35 @@
|
||||
set(SOURCES
|
||||
base16_test.c
|
||||
base32_test.c
|
||||
base64_test.c
|
||||
bcrypt_test.c
|
||||
cipher_hash_test.c
|
||||
common.c
|
||||
der_test.c
|
||||
dh_test.c
|
||||
dsa_test.c
|
||||
ecc_test.c
|
||||
ed25519_test.c
|
||||
file_test.c
|
||||
mac_test.c
|
||||
misc_test.c
|
||||
modes_test.c
|
||||
mpi_test.c
|
||||
multi_test.c
|
||||
no_null_termination_check_test.c
|
||||
no_prng.c
|
||||
padding_test.c
|
||||
pkcs_1_eme_test.c
|
||||
pkcs_1_emsa_test.c
|
||||
pkcs_1_oaep_test.c
|
||||
pkcs_1_pss_test.c
|
||||
pkcs_1_test.c
|
||||
prng_test.c
|
||||
rotate_test.c
|
||||
rsa_test.c
|
||||
ssh_test.c
|
||||
store_test.c
|
||||
test.c
|
||||
x25519_test.c
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user