CMake test suite failing on Alpine Linux

There are 3 tests failing in the CMake test suite when building from sources on Alpine Linux.
I tried to crawl the CMake bug tracker & Google search to check if something was reported but did not find anything thus asking help here to check if I’m doing something wrong or if a bug shall be opened.

The minimal repro I have for this is:

docker run -it --rm alpine:3.15
apk add binutils gcc g++ gfortran curl util-linux ca-certificates gnupg openssl-dev cmake make musl-dev
apk add bzip2-dev curl-dev expat-dev libarchive-dev linux-headers libuv-dev ncurses-dev rhash-dev xz-dev zlib-dev py3-sphinx file musl-utils
curl -fsSLO https://github.com/Kitware/CMake/releases/download/v3.22.2/cmake-3.22.2.tar.gz
tar -xf cmake-3.22.2.tar.gz
cmake -S cmake-3.22.2 -B cmake-build -DCMAKE_USE_OPENSSL:BOOL=ON -DBUILD_TESTING:BOOL=ON
cd cmake-build
make -j4
./bin/ctest --output-on-failure -j4

Summary:

The following tests FAILED:
	 62 - ExportImport (Failed)
	532 - RunCMake.install (Failed)
	533 - RunCMake.file-GET_RUNTIME_DEPENDENCIES (Failed)

Error log extract:

CMake Error at /root/cmake-3.22.2/Tests/RunCMake/RunCMake.cmake:201 (message):
  TARGETS-RUNTIME_DEPENDENCIES-nodep-all - FAILED:

  Result is [1], not [0].

  stderr does not match that expected.

  Command was:

   command> "/root/cmake-build/bin/cmake" "-DCMAKE_INSTALL_PREFIX=/root/cmake-build/Tests/RunCMake/install/TARGETS-RUNTIME_DEPENDENCIES-nodep-build/root-all" "-DBUILD_TYPE=Debug" "-P" "cmake_install.cmake"

  Actual stdout:

   actual-out> -- Install configuration: "Debug"
   actual-out> -- Installing: /root/cmake-build/Tests/RunCMake/install/TARGETS-RUNTIME_DEPENDENCIES-nodep-build/root-all/bin/exe

  Expected stderr to match:

   expect-err> ^$

  Actual stderr:

   actual-err> CMake Error at cmake_install.cmake:62 (file):
   actual-err>   file Failed to run ldconfig

Call Stack (most recent call first):
  /root/cmake-3.22.2/Tests/RunCMake/RunCMake.cmake:215 (run_cmake)
  /root/cmake-3.22.2/Tests/RunCMake/install/RunCMakeTest.cmake:15 (run_cmake_command)
  /root/cmake-3.22.2/Tests/RunCMake/install/RunCMakeTest.cmake:183 (run_install_test)

All errors seem to have to do with file Failed to run ldconfig.

On a side note, it seems the test suite is never run on Alpine Linux official package:

  • added 2017-09-20: alpinelinux/aports/commit/09e4dd994fe45731bb5d2d11a333e2d17c9d8a05
  • removed/skipped 2017-09-22: alpinelinux/aports/commit/6e01dd13be82b9a24218d9983f59e3aed35556e9

Related to investigation of https://gitlab.kitware.com/cmake/cmake/-/issues/23187 / https://github.com/scikit-build/cmake-python-distributions/issues/221

It seems that musl-based platforms are not all that well-considered in the file(GET_RUNTIME_DEPENDENCIES) code. How should CMake discover the default library paths in such cases?

Cc: @kyle.edwards

I don’t think this is necessarily musl-specific but more Alpine-specific. We haven’t been having issues passing the test suite on Adélie Linux, which is also using musl. However, we use a vastly different ldconfig to Alpine.

Ninja edit: from a trybuild on a big-endian IBM Power node with CMake 3.22.2: 553/583 Test #517: RunCMake.file-GET_RUNTIME_DEPENDENCIES ............ Passed 11.23 sec

Hi,
I’m also seeing this while building srecord-1.65.0 (which is CMake-based) on latest Alpine Linux.

During cmake --install .:

CMake Error at srec_cat/cmake_install.cmake:66 (file):
  file Failed to run ldconfig
Call Stack (most recent call first):
  cmake_install.cmake:52 (include)

I can’t attach the srec_cat/cmake_install.cmake file because I’m a new user, but the relevant part is:

if(CMAKE_INSTALL_COMPONENT STREQUAL "srec_cat" OR NOT CMAKE_INSTALL_COMPONENT)
  file(GET_RUNTIME_DEPENDENCIES
    RESOLVED_DEPENDENCIES_VAR _CMAKE_DEPS
    EXECUTABLES
      "/srecord-1.65.0-Source/build/srec_cat/srec_cat"
      "/srecord-1.65.0-Source/build/srec_cmp/srec_cmp"
      "/srecord-1.65.0-Source/build/srec_info/srec_info"
    DIRECTORIES
      "/usr/bin/"
    PRE_EXCLUDE_REGEXES
      "api-ms-"
      "ext-ms-"
    POST_EXCLUDE_REGEXES
      ".*system32/.*\\.dll"
    )
endif()

CMake version is 3.24.3.

This is currently breaking install of this package for me. Is there a workaround available?

Some additional info: straceing cmake --install . I found out that it calls ldconfig as:

[pid  6642] execve("/sbin/ldconfig", ["/sbin/ldconfig", "-v", "-N", "-X"], 0x7ffd180a39d8 /* 7 vars */ <unfinished ...>
...
[pid  6642] +++ exited with 1 +++

So I’m guessing Alpine’s ldconfig does not cope well with those flags.