Bug#1073480: llvm-17-dev: shipped Findzstd.cmake conflicts with cmake module provided by libzstd-dev

Pino Toscano pino at debian.org
Tue Jul 16 20:34:23 BST 2024


Source: qt6-base
Followup-For: Bug #1073480
X-Debbugs-Cc: pkg-llvm-team at lists.alioth.debian.org
Control: reassign -1 llvm-17-dev
Control: severity -1 important

Hi,

after a big of debugging, I think I got to the actual reason for this
failure.

In particular, starting from LLVM 16, there is a shipped cmake find
module to find libzstd:

$ dpkg -L llvm-17-dev | grep -i zstd
/usr/lib/llvm-17/lib/cmake/llvm/Findzstd.cmake

The problem here is that it defines cmake targets with the same name as
those defined by the libzstd own cmake config modules:

$ dpkg -L libzstd-dev | grep -i cmake
/usr/lib/x86_64-linux-gnu/cmake
/usr/lib/x86_64-linux-gnu/cmake/zstd
/usr/lib/x86_64-linux-gnu/cmake/zstd/zstdConfig.cmake
/usr/lib/x86_64-linux-gnu/cmake/zstd/zstdConfigVersion.cmake
/usr/lib/x86_64-linux-gnu/cmake/zstd/zstdTargets-none.cmake
/usr/lib/x86_64-linux-gnu/cmake/zstd/zstdTargets.cmake

This can be easily reproduced on a clean system with only LLVM and
libzstd development files, and a very simple CMakeLists.txt file:

$ podman run -ti --rm --pull=newer debian:unstable
root at 514df0e64d7b:/# apt-get update
root at 514df0e64d7b:/# apt-get -y dist-upgrade
root at 514df0e64d7b:/# apt-get --no-install-recommends install gcc g++ make cmake libzstd-dev llvm-17-dev
root at 514df0e64d7b:/# cd /tmp/
root at 514df0e64d7b:/tmp# cat >CMakeLists.txt <<EOF
> cmake_minimum_required(VERSION 3.20)
> project(test)
> find_package(LLVM CONFIG)
> find_package(zstd CONFIG)
> EOF
root at 514df0e64d7b:/tmp# mkdir build
root at 514df0e64d7b:/tmp# cd build/
root at 514df0e64d7b:/tmp/build# cmake ..
-- The C compiler identification is GNU 13.3.0
-- The CXX compiler identification is GNU 13.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test HAVE_FFI_CALL
-- Performing Test HAVE_FFI_CALL - Success
-- Found FFI: /usr/lib/x86_64-linux-gnu/libffi.so
-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) 
-- Performing Test Terminfo_LINKABLE
-- Performing Test Terminfo_LINKABLE - Success
-- Found Terminfo: /usr/lib/x86_64-linux-gnu/libtinfo.so
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.3.1")
-- Found zstd: /usr/lib/x86_64-linux-gnu/libzstd.so
-- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.12.7")
-- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR) 
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/zstd/zstdTargets.cmake:42 (message):
  Some (but not all) targets in this export set were already defined.

  Targets Defined: zstd::libzstd_shared, zstd::libzstd_static

  Targets not yet defined: zstd::libzstd

Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/zstd/zstdConfig.cmake:42 (include)
  CMakeLists.txt:4 (find_package)


-- Configuring incomplete, errors occurred!


The order of the bits in the CMakeLists.txt is the key:
- the cmake find module shipped by LLVM defines two targets,
  zstd::libzstd_shared and zstd::libzstd_static
- the libzstd cmake config module defines three targets, i.e.
  zstd::libzstd_shared, zstd::libzstd_static, and zstd::libzstd
- the libzstd cmake config module expects a "all or nothing situation",
  as it assumes that if one is defined, then all the others are too
  (AFAIK this is done so that multiple calls to find_package(zstd) will
  not redefine things)

This is exactly the situation in qt6-tools: first Clang is searched
(which in turns requires LLVM), and then zstd.

Hence:
- I'm reassigning this to llvm, as it is clearly a bug there; IMHO
  either the module needs to be taught about the zstd::libzstd target,
  or it needs to try to use the libzstd config module
- I'm lowering the severity of this to important, since it is a not so
  common situation
- I will add a workaround in qt6-tools

-- 
Pino



More information about the Pkg-llvm-team mailing list