CMake: how to handle resources of dependencies?

Viewed 184

I'm new to CMake and I'm wondering how people deal with data resources (images, text files, etc.) of dependencies in their cmake projects. I've been googling for a couple of hours now and haven't been able to find an answer to this. Most deal with DLL dependencies, which is not what I'm after. I'm using CMake 3.16 at the moment, so solutions for that version are preferred. But if there's any solutions for newer versions of CMake I'd still be interested in hearing those!

To sketch my setup and my problem:

I have a static library A, that has a number of data resource files (textures in this case), which I define and install like this:

set(A_RESOURCE_FILES
    ${CMAKE_CURRENT_LIST_DIR}/resources/texture.png
)
set_target_properties(A PROPERTIES
                        MACOSX_BUNDLE TRUE
                        MACOSX_FRAMEWORK_IDENTIFIER org.cmake.A
                        RESOURCE "${A_RESOURCE_FILES}"
)

install(TARGETS A
    EXPORT ATargets

    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/${PLATFORM_ID}/$<CONFIG>"
    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PLATFORM_ID}/$<CONFIG>"
    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PLATFORM_ID}/$<CONFIG>"
    RESOURCE DESTINATION "${CMAKE_INSTALL_BINDIR}/${PLATFORM_ID}/$<CONFIG>/resources"
    PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

This works as expected (at least on Windows) and copies my resource files to my install folder for project A. Now I have an executable project B, that has a dependency on lib A. However when I build B it does not copy those resource files to its build folder.

My questions are:

  1. Is there a way for B to automatically copy the resource files dependencies from lib A to its build folder? I would like to avoid making a custom Config.cmake for project A and defining a variable in there and then defining a custom command/target in project B. I have other dependencies that will need something similar. But maybe this is the only way of doing this?
  2. Same question as 1, but what if I want to install project B as well? I would like to gather all resource dependencies in the install folder of project B as well.

Thanks a lot for any help or pointers!

0 Answers
Related