I've got shader files that are a part of library's source tree. It means that these files will be read at library's initialization stage. Although, when launching an application that uses this library - shader files can't be read. It is expected as shader files are not located in application's working directory. How should I solve this problem? I've tried copying built in shaders using this CMake custom command:
add_custom_command(
TARGET ${SANDBOX_TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/assets $<TARGET_FILE_DIR:${SANDBOX_TARGET_NAME}>/assets
)
This approach isn't that great because projects that will depend on my library should also always copy shader files to application working directory in order for my library to initilize properly.
In root CMakeLists.txt I set output directories for library and application:
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) # library and built in shader files will be located here
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # application will be located here
Built in shader files are added as library's sources and are copied to lib/ directory:
set(LIBRARY_SHADERS_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/shader.frag
${CMAKE_CURRENT_SOURCE_DIR}/shader.vert
)
target_sources(${LIBRARY_TARGET_NAME} PRIVATE ${LIBRARY_SHADERS_SRCS})