Skip to content

Commit 894f33b

Browse files
committed
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
1 parent cda7d42 commit 894f33b

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

contrib/libtomcrypt.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# To find libtomcrypt no matter what the installation look like, start with
2+
# looking for the CMake specific configuration, and failing that, try the
3+
# pkg-config package instead. The resulting target is different in each
4+
# case, but is recorded in the variable ${LIBTOMCRYPT}, so please use that
5+
# for all targets that depend on libtomcrypt.
6+
7+
find_package(libtomcrypt QUIET)
8+
if (libtomcrypt_FOUND)
9+
set(LIBTOMCRYPT libtomcrypt)
10+
else()
11+
find_package(PkgConfig)
12+
pkg_check_modules(libtomcrypt REQUIRED IMPORTED_TARGET libtomcrypt)
13+
set(LIBTOMCRYPT PkgConfig::libtomcrypt)
14+
endif()

doc/crypt.tex

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8868,6 +8868,34 @@ \subsection{Installation Directories}
88688868
A shared library build can be done by setting \textbf{-DBUILD\_SHARED\_LIBS=On} when invoking the \textbf{cmake} command.
88698869
Tests can be enabled by setting \textbf{-DBUILD\_TESTING=On} when invoking the \textbf{cmake} command.
88708870

8871+
\mysection{Building a libtomcrypt app with CMake}
8872+
8873+
Depending on if libtomcrypt was built and installed using the
8874+
available makefiles, or using CMake, different package files are
8875+
provided.
8876+
8877+
With the available makefiles, the pkg-config file
8878+
\texttt{libtomcrypt.pc} is produced, while with CMake, the CMake
8879+
config file \texttt{libtomcrypt-config.cmake} is produced.
8880+
8881+
The result is that different installations have different package
8882+
config files.
8883+
8884+
This has proven problematic for other CMake-based projects. That is,
8885+
however, fairly easy to solve with this little CMake snippet (also
8886+
found in \texttt{contrib/libtomcrypt.cmake}:
8887+
8888+
\begin{verbatim}
8889+
find_package(libtomcrypt QUIET)
8890+
if (libtomcrypt_FOUND)
8891+
set(LIBTOMCRYPT libtomcrypt)
8892+
else()
8893+
find_package(PkgConfig)
8894+
pkg_check_modules(libtomcrypt REQUIRED IMPORTED_TARGET libtomcrypt)
8895+
set(LIBTOMCRYPT PkgConfig::libtomcrypt)
8896+
endif()
8897+
\end{verbatim}
8898+
88718899
\mysection{Header Configuration}
88728900
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
88738901
stored in \textit{tomcrypt\_custom.h} which allow the enabling and disabling of various algorithms.

0 commit comments

Comments
 (0)