我试图在运行时将资源文件提供给可执行文件。我正在使用以下CMakeLists.txt。
cmake_minimum_required(VERSION 2.8)
project(open-gl-test)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 REQUIRED)
add_executable(${PROJECT_NAME} "main.c")
message(Executable is set!)
target_link_libraries(${PROJECT_NAME} ${GLEW_LIBRARIES} ${OPENGL_gl_LIBRARY} glfw)
# List of files for which we add a copy rule.
set(data_SHADOW "basic.shader")
# We don't want to copy if we're building in the sourse dir.
if (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
message(WARNING "Directories are not equal")
foreach(item IN LISTS data_SHADOW)
message(STATUS ${item})
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/res/shaders/${item}"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/res/shaders/${item}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/res/shaders/${item}"
)
endforeach()
else()
message(WARNING "Directories are equal")
endif()
# Files are only copied if a target depends on them.
add_custom_target(data-target ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/res/shaders/${data_SHADOW}")
这就是我访问文件的方式。
struct ShaderProgramSource source = parseShader("res/shaders/basic.shader");
但是什么也不会复制到项目构建目录,甚至消息也不会显示在 * compile output 窗口中。我收到的错误消息是:
打开文件时出错:没有这样的文件或目录
可能是什么问题?