I have a simple cmake setup between two projects, a library project and an executable project. The library project I want to be installed on the system (Linux container), and the executable project I want to link with the library package after finding it with find_package(XXX CONFIG). I successfully build and install the library project just fine, however, when I configure the executable project I get an error in the vein of
CMake Error at MyExecutable/CMakeLists.txt:35 (add_executable): Target "MyExecutable" links to target "CUDA::toolkit" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
CUDA::toolkit is a PRIVATE target linked to the library project.
The CMakeLists.txt for the library project looks like this
add_library(SiftCuda ${SOURCES} ${CUDA_KERNELS})
target_link_libraries(MyLibrary PRIVATE
CUDA::cudart
CUDA::cublas
)
set_target_properties(MyLibrary PROPERTIES
PUBLIC_HEADER "${HEADERS}"
CUDA_SEPARABLE_COMPILATION ON
)
target_include_directories(MyLibrary PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/MyLibrary>
)
target_compile_features(MyLibrary PUBLIC
cxx_std_11
)
# Alias library
add_library(MyLibrary::MyLibrary ALIAS MyLibrary)
###### Installation #####
include(GNUInstallDirs)
# Install library
install(TARGETS MyLibrary
EXPORT MyLibraryConfig
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/MyLibrary
)
# For exposing internal configuration of the package
export(
TARGETS MyLibrary
NAMESPACE MyLibrary::
FILE "${CMAKE_CURRENT_BINARY_DIR}/MyLibraryConfig.cmake"
)
# Install exports
install(EXPORT MyLibraryConfig
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/MyLibrary"
NAMESPACE MyLibrary::
)
The CMakeLists.txt for the executable looks like this
find_package(MyLibrary CONFIG)
add_executable(MyExe
${SOURCES}
)
target_link_libraries(MyExe PUBLIC
MyLibrary::MyLibrary
)
I get the feeling that linking MyExe to the CUDA targets would resolve this issue, however, doing so seems incorrect as I usually don't have to be aware of transitive dependencies for libraries I use.