How should I export from a cmake module?

I’m trying to replace another NN architecture with pytorch. I can compile the simple demos with no problem but run into trouble when I try to compile a library for inclusion into another binary.

As a typical configuration (which worked with the previous architecture) I’m building the library as:

file(GLOB SOURCES src/*.cpp src/*.cu)
cuda_add_library(${ModuleName} SHARED ${SOURCES})
target_include_directories(${ModuleName} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_include_directories(${ModuleName} PRIVATE ${TORCH_INCLUDE_DIRS})
target_link_libraries(${ModuleName} image engine cuda ${TORCH_LIBRARIES})

I then export this using something like:

install(TARGETS ${ModuleName}
        EXPORT ${ModuleName}Targets
        LIBRARY DESTINATION lib/${ProjectName}
        INCLUDES DESTINATION include/${ProjectName})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/${ModuleName} DESTINATION include/${ProjectName})
install(EXPORT ${ModuleName}Targets DESTINATION share/cmake/${ProjectName})

In this case, cmake gives errors about not being able to find caffe2 and caffe2_gpu. If I try to add them to any of the install messages or to their own export I get errors about not having built them within this module.

I’ve also tried making an interface library and exporting that instead. Still no success. Any pointers?