Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 736547 - dev-build/cmake: Gentoo patch breaks FindBLAS for development
Summary: dev-build/cmake: Gentoo patch breaks FindBLAS for development
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-09 17:11 UTC by Lucas Hosseini
Modified: 2025-02-22 22:51 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lucas Hosseini 2020-08-09 17:11:18 UTC
The `FindBLAS` CMake module supports options `BLA_VENDOR` (which enables one to specify a BLAS implementation), and `BLA_PREFER_PKGCONFIG` (which controls whether pkg-config should be used to do the lookup).

The Gentoo ebuild has a patch that overrides used input for `BLA_PREFER_PKGCONFIG`:
```
+# first, try PkgConfig
+set(BLA_PREFER_PKGCONFIG On)
```

This breaks CMake projects using `FindBLAS` with `BLA_VENDOR` set and `BLA_PREFER_PKGCONFIG=OFF`, since the `BLA_VENDOR` constraint will not be used as `BLA_PREFER_PKGCONFIG=OFF` gets overridden.

A simple fix would be to replace the above with:
```
if(NOT DEFINED BLA_PREFER_PKGCONFIG)
  set(BLA_PREFER_PKGCONFIG ON)
endif()
```

This would still override upstream CMake defaults, and would need any CMake project using `FindBLAS` to accomodate for Gentoo's customization, but at least it would give them a way to, unlike now.

A real fix would be to remove this tweak altogether, and patch each Gentoo CMake project that calls `FindBLAS` to `set(BLA_PREFER_PKGCONFIG ON)` before the `find_package(BLAS)` call.
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-08-11 07:06:40 UTC
It would help to see an example of the failure (inc. any relevant CMakeError/Info.txt files, but also the full build.log + emerge --info).
Comment 2 Lucas Hosseini 2020-08-14 20:39:30 UTC
I may have not been clear in my explanations: up to CMake 3.17, Gentoo patches the `FindBLAS` module in such a way (https://github.com/gentoo/gentoo/blob/master/dev-util/cmake/files/cmake-3.17.0_rc1-FindBLAS.patch) that the default behavior in Gentoo differs from the default behavior in upstream CMake.
More specifically, this materializes when the input variable `BLA_PREFER_PKGCONFIG` is set to `OFF`: outside of Gentoo pkg-config is then not used, while in Gentoo, it is used regardless as (`BLA_PREFER_PKGCONFIG` is overridden by the patch and set to `ON` despite the user explicitly setting it to `OFF`).
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-02-17 22:39:35 UTC
I was wondering why this is useful but it's because of e.g.:

[22:38:54]  <beauby> sam_: Yeah sorry I got distracted :D My use-case is not for Gentoo components, but using CMake to build third party projects (specifically one library that explicitly relies on mkl)
Comment 4 Lucas Hosseini 2022-02-17 22:44:57 UTC
Thanks Sam.

To expand on the above remark, the use-case would be using CMake to build third-party projects (not ebuilds) that explicitly depend on a specific BLAS implem (for instance MKL) without forcing the user to change their system-wide default BLAS implem.
Comment 5 William Throwe 2024-07-02 20:01:49 UTC
With Gentoo's new runtime-switchable blas system, it seems that the pkgconfig results are not affected by what provider is selected.  This seems to mean that it is now impossible to compile a CMake project against any provider except the reference implementation.
Comment 6 Alexey Korepanov 2025-02-10 11:34:49 UTC
Hi. I'm hitting this problem with llama.cpp. A simple example where the gentoo patch breaks cmake's detection of openblas is an empty project with CMakeLists.txt:

***
cmake_minimum_required(VERSION 3.10)
project(test)

set(BLA_VENDOR OpenBlas)
find_package(BLAS)

if (BLAS_FOUND)
    message(STATUS "BLAS found:")
    message(STATUS "    Libraries: ${BLAS_LIBRARIES}")
    message(STATUS "    Include dirs: ${BLAS_INCLUDE_DIRS}")
    message(STATUS "    Linker flags: ${BLAS_LINKER_FLAGS}")
endif()
***

The output has nothing to do with openblas:

-- BLAS found:
--     Libraries: /usr/lib64/libblas.so
--     Include dirs:
--     Linker flags:

The root problem seems to be with cmake: if BLA_PREFER_PKGCONFIG is set, then
cmake is ignoring BLA_VENDOR and isn't finding the right blas.

But anyway, the gentoo patch breaks FindBLAS in cmake
Comment 7 Alexey Korepanov 2025-02-10 11:38:02 UTC
I worked around this in guru with a (completely wrong but working) patch:
https://gitweb.gentoo.org/repo/proj/guru.git/tree/sci-misc/llama-cpp/files/blas-ld.diff
Comment 8 Alexey Korepanov 2025-02-10 13:40:29 UTC
This bug is nicely summarized by Michał Górny in
https://bugs.gentoo.org/835799#c6:

Gentoo shouldn't be patching CMake to override upstream behavior.  This is against the principle of least surprise.  This is especially harmful to software developers that are going to see inconsistent behavior between Gentoo and other distributions.
Comment 9 Alexey Korepanov 2025-02-22 22:51:27 UTC
I created a pull request https://github.com/gentoo/gentoo/pull/40709
It is ugly and does not really solve the problem, but it allows to restore the upstream behavior when needed