Regression: CMake no longer allows altering targets not built by current project
A project of mine depends on CUDA, and also on another library, call it libfoo, which itself depends on CUDA. The CMakeLists.txt
of libfoo has:
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()
and my own project has:
FetchContent_Declare(foo
# bunch of args here
OVERRIDE_FIND_PACKAGE
)
find_package(foo REQUIRED)
Now, with CMake 3.24.2 and earlier, configuring my project succeeds. But with 3.25.3 and later, 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.
This change of behavior does not seem necessary; and even if you deemed it to be, there should have been some controllable policy for backwards-compatibility.
Edited by Eyal Rozenberg