Add contrib/libtomcrypt.cmake, and write about it in doc/crypt.tex

contrib/libtomcrypt.cmake is a snippet that can be used by any CMake
based project that wants to link with libtomcrypt, no matter if it
was installed with libtomcrypt-config.cmake or libtomcrypt.pc.

Fixes #681
This commit is contained in:
Richard Levitte 2025-02-18 21:25:32 +01:00
parent cda7d42647
commit 894f33b81c
2 changed files with 42 additions and 0 deletions

14
contrib/libtomcrypt.cmake Normal file
View file

@ -0,0 +1,14 @@
# To find libtomcrypt no matter what the installation look like, start with
# looking for the CMake specific configuration, and failing that, try the
# pkg-config package instead. The resulting target is different in each
# case, but is recorded in the variable ${LIBTOMCRYPT}, so please use that
# for all targets that depend on libtomcrypt.
find_package(libtomcrypt QUIET)
if (libtomcrypt_FOUND)
set(LIBTOMCRYPT libtomcrypt)
else()
find_package(PkgConfig)
pkg_check_modules(libtomcrypt REQUIRED IMPORTED_TARGET libtomcrypt)
set(LIBTOMCRYPT PkgConfig::libtomcrypt)
endif()

View file

@ -8868,6 +8868,34 @@ Per default a static library in \textbf{Release} configuration is built, without
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{Building a libtomcrypt app with CMake}
Depending on if libtomcrypt was built and installed using the
available makefiles, or using CMake, different package files are
provided.
With the available makefiles, the pkg-config file
\texttt{libtomcrypt.pc} is produced, while with CMake, the CMake
config file \texttt{libtomcrypt-config.cmake} is produced.
The result is that different installations have different package
config files.
This has proven problematic for other CMake-based projects. That is,
however, fairly easy to solve with this little CMake snippet (also
found in \texttt{contrib/libtomcrypt.cmake}:
\begin{verbatim}
find_package(libtomcrypt QUIET)
if (libtomcrypt_FOUND)
set(LIBTOMCRYPT libtomcrypt)
else()
find_package(PkgConfig)
pkg_check_modules(libtomcrypt REQUIRED IMPORTED_TARGET libtomcrypt)
set(LIBTOMCRYPT PkgConfig::libtomcrypt)
endif()
\end{verbatim}
\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.