FS#68076 - [check]: invalid CMake config installed

Attached to Project: Arch Linux
Opened by Matwey V. Kornilov (matwey) - Friday, 02 October 2020, 14:29 GMT
Last edited by Jan Alexander Steffens (heftig) - Saturday, 03 October 2020, 10:19 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Jan Alexander Steffens (heftig)
Architecture All
Severity Very Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:


/usr/lib/cmake/check/check-targets.cmake module fails due to missed libcheck.a file.
The issue is that the module always checks for the file presence, even if this target is not used.


Additional info:
* check-0.15.2-1

Steps to reproduce:

1. Create sample CMakeLists.txt with the following content:

cmake_minimum_required (VERSION 3.0)
project(test LANGUAGES C)

find_package(Check CONFIG NAMES Check check)

2. Create ./build dir and try to run cmake

mkdir build
cd build
cmake ..

3. See the following error:

-- The C compiler identification is GNU 10.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/sbin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at /usr/lib64/cmake/check/check-targets.cmake:96 (message):
The imported target "Check::check" references the file

"/usr/lib/libcheck.a"

but this file does not exist. Possible reasons include:

* The file was deleted, renamed, or moved to another location.

* An install or uninstall procedure did not complete successfully.

* The installation package was faulty and contained

"/usr/lib64/cmake/check/check-targets.cmake"

but not all the files it references.

Call Stack (most recent call first):
/usr/lib64/cmake/check/check-config.cmake:36 (include)
CMakeLists.txt:4 (find_package)


-- Configuring incomplete, errors occurred!
See also "/root/t/build/CMakeFiles/CMakeOutput.log".


Possible solution:

Patch check CMakeLists.txt during installation in order not to export Check::check static target.
This task depends upon

Closed by  Jan Alexander Steffens (heftig)
Saturday, 03 October 2020, 10:19 GMT
Reason for closing:  Fixed
Additional comments about closing:  check 0.15.2-2
Comment by Eli Schwartz (eschwartz) - Friday, 02 October 2020, 14:51 GMT
It provides a superior pkg-config file, try using find_package(PkgConfig) followed by pkg_check_modules(CHECK check IMPORTED_TARGET GLOBAL) and link to PkgConfig::CHECK.

I'm not sure why this package builds with both cmake and autotools if the cmake files are broken anyway. Can we just drop that?

Alternatively is there a way to tell cmake to drop that broken check *without* patching unstable generated outputs, which I really do not think is remotely advisable.
Comment by Jan Alexander Steffens (heftig) - Friday, 02 October 2020, 15:16 GMT
We could add the static lib.
Comment by Eli Schwartz (eschwartz) - Friday, 02 October 2020, 15:37 GMT
I don't see why we should violate a highly sensible packaging rule in order to add files people won't use just to work around a cmake bug in a *-config.cmake that was apparently always broken but the OP is the first person to notice due to being the first person who ever used libcheck with cmake.

Cmake config files are not even advised for use on linux since they are usually wrong and often not available for good or ill. Using pkg_check_modules is the "good practice" advice.
Comment by Matwey V. Kornilov (matwey) - Friday, 02 October 2020, 19:54 GMT
Eli,

Please note that cmake doesn't say that it didn't found Check, it breaks inside find_package() function, so there is no way to check anything else as you suggested, because no further instruction are executed after find_package() line.

What I initially suggested, is to patch the sources (not generated output) as following to prevent generating libcheck.a related staff:

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4a02dbe..4d731c9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -188,7 +188,7 @@ target_include_directories(checkShared
)

if(NOT THIS_IS_SUBPROJECT)
- install(TARGETS check checkShared
+ install(TARGETS checkShared
EXPORT check-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

However, if you consider using cmake as a bad practice then you just shouldn't distribute /usr/lib/cmake/check at all.
Comment by Eli Schwartz (eschwartz) - Friday, 02 October 2020, 20:42 GMT
My suggestion was to use pkg_check_modules() instead of, not as a fallback for, find_package() as the latter cannot break if it isn't used.

Edit: note that it's still useful to check it as a fallback -- people might want to use your software but their system install of libcheck was built with autotools only.

Thank you for correcting me about the patch you suggested. I agree that if you can patch the source CMakeLists.txt to not try to generate broken static library checks, this is the best solution to the bug report.

Ideally we could get upstream to properly select for shared only, and also for cmake to stop breaking on unused files that are deleted in packaging. But if we can robustly work around it so that the cmake config files which are installed, are functional, we should do so.

...

Cmake config files still suck, but that's not a reason to refuse to install them. Merely a reason to warn people that they might not behave as expected...
Comment by Matwey V. Kornilov (matwey) - Friday, 02 October 2020, 20:52 GMT
pkg_check_modules() is not fully portable, for instance, it won't work with Visual Studio targets, so it cannot fully replace other techniques.

Comment by Jan Alexander Steffens (heftig) - Friday, 02 October 2020, 21:22 GMT
Thanks. I've applied your suggested fix to check 0.15.2-2. Can you test again, please?
Comment by Matwey V. Kornilov (matwey) - Saturday, 03 October 2020, 06:57 GMT
0.15.2-2 works good for me. thank you!

Loading...