Skip to content

Is it expected that FetchContent_Declare and find_package do not produce targets or libraries? #1114

Open
@dograt

Description

@dograt

Hi all, I am trying to fetch this repository in my CMake project. I'm on WSL, running GCC 11.4.0 and CMake 3.20. I am calling the following in my CMakeLists.txt:

 FetchContent_Declare(
         LAPACK_PKG
         GIT_REPOSITORY ${LAPACK_URL}
         GIT_TAG       "v3.12.0"
         SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/package
         OVERRIDE_FIND_PACKAGE
         EXCLUDE_FROM_ALL
 )
 find_package(LAPACK_PKG REQUIRED)

This runs without error, but it doesn't seem that my project is actually populated by any targets. Or at least, I don't think it is. I tried querying for any output, and didn't see anything:

 message(STATUS "LAPACK_LIBRARIES: ${LAPACK_LIBRARIES}")
 message(STATUS "LAPACK_LIBRARIES: ${LAPACK_PKG_LIBRARIES}")

So, I tried printing ALL CMake variables containing the text "LAPACK/lapack", and still didn't see a LAPACK_PKG_LIBRARIES variable, or an equivalent:

-- FETCHCONTENT_SOURCE_DIR_LAPACK_PKG: 
-- FETCHCONTENT_UPDATES_DISCONNECTED_LAPACK_PKG: OFF
-- LAPACK++: OFF
-- LAPACKE: OFF
-- LAPACKE_WITH_TMG: OFF
-- LAPACK_BINARY_DIR: <path>
-- LAPACK_CONTENT_SOURCE_DIR: <path>
-- LAPACK_IS_TOP_LEVEL: OFF
-- LAPACK_PKG_CONFIG: <path>
-- LAPACK_PKG_CONSIDERED_CONFIGS: <path>/CMakeFiles/pkgRedirects/lapack_pkg-config.cmake
-- LAPACK_PKG_CONSIDERED_VERSIONS: unknown
-- LAPACK_PKG_DIR:<path>/build/CMakeFiles/pkgRedirects
-- LAPACK_PKG_FOUND: 1
-- LAPACK_PKG_VERSION_COUNT: 4294967295
-- LAPACK_PKG_VERSION_MAJOR: 0
-- LAPACK_PKG_VERSION_MINOR: 0
-- LAPACK_PKG_VERSION_PATCH: 0
-- LAPACK_PKG_VERSION_TWEAK: 0
-- LAPACK_SOURCE_DIR:<path>/lapack/package
-- LAPACK_TESTING_USE_PYTHON: ON
-- LAPACK_URL: <url>
-- USE_OPTIMIZED_LAPACK: OFF
-- lapack_LIB_DEPENDS: general;blas;
-- lapack_pkg_BINARY_DIR: <path>/build/_deps/lapack_pkg-build
-- lapack_pkg_POPULATED: True
-- lapack_pkg_SOURCE_DIR: <path>/lapack/package

How can I query this command to be sure that it has the targets I'd expect? And even better, how can I get actual CMake targets from this project? Thanks!

Edit: For additional context, I am consuming the calling project, via ANOTHER project, using FetchContent again. However, I get the following errors:

  Target "lapack" of type UTILITY may not be linked into another target.  One
  may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

  Target "blas" of type UTILITY may not be linked into another target.  One
  may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

My understanding is that this has to do with the fact that lapack/blas aren't being treated as real-deal CMake targets, and I would very much like them to be! The problem occurs when I try to link to lapack and blas in the fetched project:

target_link_libraries(<my_fortran_lib> lapack blas)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions