absolute path is record when generate package

I want to generate myself package, and the generated package can be import by find_package().

Everyhing is OK except a cude relative library.

Let’s say I want to generate a Basic package. In the geberated Basic.cmake:

add_library(CudaFunction SHARD IMPORTED)
set_target_properties(CudaFunction PROPERTIES
  INTERFACE_LINK_LIBRARIES “C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.3/lib/x64/cudart_static.lib;C:/Users/zhq/Desktop/Project/Basic/Thirdparty/x64/libtorch/lib/Debug/c10.lib”

The CudaFunction library depends on cudart_static.lib, c10.lib. However, the absolute path is used, and it prevent other user import my Basic package.

The CudaFunction is built by:

set(Torch_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Thirdparty/x64/libtorch/share/cmake/Torch")
find_package(Torch REQUIREd)
target_link_libraries(CudaFunction ${CUDA_LIBRARIES})

Is it possible generate Basic.cmake without the absolute path dependency.

Any suggestion is appreciated~~~

Instead of ${CUDA_LIBRARIES}, you should use any imported targets that you require. The package then needs to re-find any packages that provide those targets.

Do you mean target_link_libraries(CudaFunction c10.dll)?

In addition, why ${CUDA_LIBRARIES} would require absolute path?

I find ${VTK_LIBRARIES} depends VTK::CommonCore?

CUDA_LIBRARIES is just a variable. If it expands to paths, you get paths.

Yes, VTK only uses targets anymore, so you’ll only get targets.