einpoklum
einpoklum

Reputation: 132128

Cannot specify link libraries for target which is not built by this project - but I really want to

A project of mine depends on CUDA, and also on another library, call it libfoo, which itself depends on CUDA. Now, in the CMakeLists.txt of libfoo, we find:

find_package(CUDAToolkit REQUIRED)
find_package(Threads REQUIRED)
if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.1)
    _CUDAToolkit_find_and_add_import_lib(nvptxcompiler_static)
    target_link_libraries(CUDA::nvptxcompiler_static INTERFACE Threads::Threads) 
endif()

Now,

  1. I can't change the CMake of libfoo and
  2. The target_link_libraries command is valid and legitimate, to the best of my understanding.

However, when I write:

FetchContent_Declare(foo
    # bunch of args here
    OVERRIDE_FIND_PACKAGE
    )
find_package(foo REQUIRED)

in my project, I get this error:

CMake Error at build/_deps/foo-src/CMakeLists.txt:80 (target_link_libraries):
  Cannot specify link libraries for target "CUDA::nvptxcompiler_static" which
  is not built by this project.

How can I get CMake to be willing to run this command, even though it doesn't like it?

As a second-best alternative - can I get CMake to skip the command in this case rather than fail?

Upvotes: 0

Views: 346

Answers (1)

einpoklum
einpoklum

Reputation: 132128

Apparently, this is a change of behavior which occured with CMake v3.25.3 ; with v3.24.2 and earlier it does not occur, and I can configure my project fine with libfoo.

Have filed this bug with KitWare. Advice is welcome...

Upvotes: 0

Related Questions