Imported target "libtommath" includes non-existent path "include/libtommath"
Hi,
I was trying to modernize the packaging of libtommath and libtomcrypt in Guix, but when attempting to build libtomcrypt with libtommath, the later having been built with CMake, I get:
-- CPack: packages will be generated under /tmp/guix-build-libtomcrypt-1.18.2-0.563f0fb.drv-0/build/packages/Linux/
-- Configuring done (0.1s)
CMake Error in CMakeLists.txt:
Imported target "libtommath" includes non-existent path
"/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/include/libtommath"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.
-- Generating done (0.0s)
CMake Generate step failed. Build files cannot be regenerated correctly.
error: in phase 'configure': uncaught exception:
%exception #<&invoke-error program: "cmake" arguments: ("../source" "-C /tmp/guix-build-libtomcrypt-1.18.2-0.563f0fb.drv-0/guix-file.OhalQL" "-GUnix Makefiles") exit-status: 1 term-signal: #f stop-signal: #f>
phase `configure' failed after 0.2 seconds
It looks like a bug in the CMake installed files of libtommath?
hmm, there are two flavors of libtommath, default is the "devel"/static library build (BUILD_SHARED_LIBS=Off), but there's also the "prod"/shared library build (BUILD_SHARED_LIBS=On). Maybe you only built&installed the former which doesn't include the header files?
$ cmake ..
[...]
$ cpack -G TAR
[...]
CPack: - package: /path/to/packages/Linux/libtommath-devel-1.3.0-1_x86_64-Libraries.tar generated.
$ tar -tf packages/Linux/libtommath-devel-1.3.0-1_x86_64-Libraries.tar
lib64/
lib64/libtommath.a
$ cmake -DBUILD_SHARED_LIBS=On ..
[...]
$ cpack -G TAR
[...]
CPack: - package: /path/to/packages/Linux/libtommath1-1.3.0-1_x86_64.tar generated.
$ tar -tf packages/Linux/libtommath1-1.3.0-1_x86_64.tar
libtommath1-1.3.0-1_x86_64/lib64/
libtommath1-1.3.0-1_x86_64/lib64/libtommath.so.1.3.0
libtommath1-1.3.0-1_x86_64/lib64/libtommath.so.1
libtommath1-1.3.0-1_x86_64/lib64/libtommath.so
libtommath1-1.3.0-1_x86_64/lib64/pkgconfig/
libtommath1-1.3.0-1_x86_64/lib64/pkgconfig/libtommath.pc
libtommath1-1.3.0-1_x86_64/lib64/cmake/
libtommath1-1.3.0-1_x86_64/lib64/cmake/libtommath/
libtommath1-1.3.0-1_x86_64/lib64/cmake/libtommath/libtommath-config-version.cmake
libtommath1-1.3.0-1_x86_64/lib64/cmake/libtommath/libtommath-config.cmake
libtommath1-1.3.0-1_x86_64/lib64/cmake/libtommath/libtommath-config-release.cmake
libtommath1-1.3.0-1_x86_64/include/
libtommath1-1.3.0-1_x86_64/include/libtommath/
libtommath1-1.3.0-1_x86_64/include/libtommath/tommath.h
libtommath1-1.3.0-1_x86_64/share/
libtommath1-1.3.0-1_x86_64/share/man/
libtommath1-1.3.0-1_x86_64/share/man/man3/
libtommath1-1.3.0-1_x86_64/share/man/man3/tommath.3
I have the same issue using vcpkg. I've set it to use static packages and libtommath fails.
In my case, I'm happy with shared libraries, so I added -DBUILD_SHARED_LIBS=ON to both libtommath and libtomcrypt, like so:
(define-public libtomcrypt
(let ((commit "563f0fb4f2a2c6a665ce9d091fac7956dbf7c40a")
(revision "0"))
(package
(name "libtomcrypt")
(version (git-version "1.18.2" revision commit))
(source
(origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/libtom/libtomcrypt")
(commit commit)))
(file-name (git-file-name name version))
(sha256
(base32
"0whmj47lhxv6jcbz8rwxg28709zj35sm46pfnj18q1a7sldarwvg"))))
(build-system cmake-build-system)
(arguments (list #:configure-flags #~(list "-DBUILD_SHARED_LIBS=ON")
#:phases #~(modify-phases %standard-phases
(add-after 'unpack 'avoid-git-describe
(lambda _
(substitute* "CMakeLists.txt"
(("COMMAND git describe.*")
"COMMAND true\n")))))))
(native-inputs (list pkg-config))
(inputs (list libtommath))
(home-page "https://www.libtom.net/LibTomCrypt/")
(synopsis "Cryptographic toolkit")
(description "LibTomCrypt is a fairly comprehensive, modular and portable
cryptographic toolkit that provides developers with a vast array of well known
published block ciphers, one-way hash functions, chaining modes, pseudo-random
number generators, public key cryptography and a plethora of other routines.")
(properties `((lint-hidden-cve . ("CVE-2019-17362"))))
(license unlicense))))
(define-public libtommath
(package
(name "libtommath")
(version "1.3.0")
(source
(origin
(method url-fetch)
(uri (string-append "https://github.com/libtom/libtommath/releases/"
"download/v" version "/ltm-" version ".tar.xz"))
(sha256
(base32
"024xzb66abhla7kjks07ga05id9lq007cq3kxc41769m6kcp4qi9"))))
(build-system cmake-build-system)
(arguments (list #:configure-flags #~(list "-DBUILD_SHARED_LIBS=ON")))
(home-page "https://www.libtom.net/LibTomMath/")
(synopsis "Portable number theoretic multiple-precision integer library")
(description "LibTomMath is a portable number theoretic multiple-precision
integer library written entirely in C. It's designed to provide an API that is
simple to work with that provides fairly efficient routines that build out of
the box without configuration.")
(properties `((upstream-name . "ltm")
(lint-hidden-cve . ("CVE-2023-36328"))))
(license unlicense)))
The content of libtommath now looks like:
$ find /gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/lib
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/lib/libtommath.so.1.3.0
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/lib/libtommath.so.1
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/lib/libtommath.so
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/lib/pkgconfig
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/lib/pkgconfig/libtommath.pc
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/lib/cmake
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/lib/cmake/libtommath
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/lib/cmake/libtommath/libtommath-config-version.cmake
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/lib/cmake/libtommath/libtommath-config.cmake
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/lib/cmake/libtommath/libtommath-config-relwithdebinfo.cmake
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/include
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/include/tommath.h
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/share
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/share/doc
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/share/doc/libtommath-1.3.0
/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/share/doc/libtommath-1.3.0/LICENSE
But libtomcrypt still fails to configure like:
starting phase `configure'
source directory: "/tmp/guix-build-libtomcrypt-1.18.2-0.563f0fb.drv-0/source" (relative from build: "../source")
build directory: "/tmp/guix-build-libtomcrypt-1.18.2-0.563f0fb.drv-0/build"
running 'cmake' with arguments ("../source" "-C /tmp/guix-build-libtomcrypt-1.18.2-0.563f0fb.drv-0/guix-file.4yPlrI" "-GUnix Makefiles" "-DBUILD_SHARED_LIBS=ON")
loading initial cache file /tmp/guix-build-libtomcrypt-1.18.2-0.563f0fb.drv-0/guix-file.4yPlrI
-- The C compiler identification is GNU 14.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /gnu/store/jb4szkjkmlqdc92nnhxvm9ypq6hvk9vw-gcc-14.3.0/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PkgConfig: /gnu/store/ij33h3fbal8v4c4m8w4j7vqcr35d5grf-pkg-config-0.29.2/bin/pkg-config (found version "0.29.2")
CMake Warning at CMakeLists.txt:310 (export):
Cannot create package registry file:
/homeless-shelter/.cmake/packages/libtomcrypt/fe9fe3a66d73e4e64162b835bff97dd2
No such file or directory
-- CPack: packages will be generated under /tmp/guix-build-libtomcrypt-1.18.2-0.563f0fb.drv-0/build/packages/Linux/
-- Configuring done (0.1s)
CMake Error in CMakeLists.txt:
Imported target "libtommath" includes non-existent path
"/gnu/store/jh2pdcflmd6v2qb1h4f0ls7smmk5yc80-libtommath-1.3.0/include/libtommath"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.
-- Generating done (0.0s)
CMake Generate step failed. Build files cannot be regenerated correctly.
error: in phase 'configure': uncaught exception:
%exception #<&invoke-error program: "cmake" arguments: ("../source" "-C /tmp/guix-build-libtomcrypt-1.18.2-0.563f0fb.drv-0/guix-file.4yPlrI" "-GUnix Makefiles" "-DBUILD_SHARED_LIBS=ON") exit-status: 1 term-signal: #f stop-signal: #f>
phase `configure' failed after 0.2 seconds
command "cmake" "../source" "-C /tmp/guix-build-libtomcrypt-1.18.2-0.563f0fb.drv-0/guix-file.4yPlrI" "-GUnix Makefiles" "-DBUILD_SHARED_LIBS=ON" failed with status 1
I guess this is because the libtomcrypt build system assumes libtommath includes are somewhere relative to CMAKE_INSTALL_PREFIX, which is not the case in Guix.
Since I'm using the x64-windows-static triplet in vcpkg, I had to switch over to using FetchContent to grab them manually:
# ----------------------------
# Dependency: libtommath
FetchContent_Declare(libtommath
GIT_REPOSITORY https://github.com/libtom/libtommath.git
GIT_TAG develop
EXCLUDE_FROM_ALL # install copies ${CMAKE_SOURCE_DIR}/doc/tommath.3, which is bad, so exclude from ALL
)
FetchContent_MakeAvailable(libtommath)
target_include_directories(${TARGET_NAME} PUBLIC "${libtommath_SOURCE_DIR}")
# ----------------------------
# Dependency: libtomcrypt
FetchContent_Declare(tomcrypt
GIT_REPOSITORY https://github.com/libtom/libtomcrypt.git
GIT_TAG develop
FIND_PACKAGE_ARGS CONFIG
)
FetchContent_MakeAvailable(tomcrypt)
set_target_properties(libtomcrypt PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
target_link_libraries(${TARGET_NAME} PUBLIC tomcrypt$<$<CONFIG:Debug>:${CMAKE_DEBUG_POSTFIX}>)
target_include_directories(${TARGET_NAME} PUBLIC "${libtomcrypt_SOURCE_DIR}/src/headers")
add_dependencies(libtomcrypt libtommath)
add_dependencies(${TARGET_NAME} libtomcrypt)
That worked for me so I'm not touching it anymore. 🤞