FindBlas.cmake: (CMake 3.11) pkg-config variant populates BLAS_LIBRARIES with magic target string instead of actual libraries
Commit a9c42e3e introduces a call to pkg-conf and populates, if successful the BLAS_LIBRARIES
variable with PkgConfig::PKGC_BLAS
. While this works fine for usage with target_link_libraries
, or similar, this has a number of severe issues:
- Projects might expect that
BLAS_LIBRARIES
is actually a semicolon separated list of actual libraries (for example for creating non-cmake configuration, or similar). It is not advisable to change the behavior of a bundled find module that drastically. - This breaks the target export mechanism.
Minimal example for the export problem:
cmake_minimum_required(VERSION 3.11)
find_package(BLAS)
add_library(foo SHARED foo.cc)
target_link_libraries(foo ${BLAS_LIBRARIES})
export(TARGETS foo FILE ${CMAKE_BINARY_DIR}/ExportTargets.cmake)
Now, simply importing said ExportTargets.cmake
fails:
cmake_minimum_required(VERSION 3.11)
include(.../ExportTargets.cmake)
add_library(bar SHARED bar.cc)
target_link_libraries(bar foo)
$ cmake .
CMake Error at CMakeLists.txt:4 (ADD_LIBRARY):
Target "bar" links to target "PkgConfig::PKGC_BLAS" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
$ make
ld: cannot find -lPkgConfig::PKGC_BLAS
Edited by Matthias Maier