BuildHelpers.CMakeLists.txt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copies files for the given game into the target res directory
  2. # GAME_NAME name of the game
  3. # REL_DIR to which directory these files are relative
  4. # SRC_FILES which files from the REL_DIR to copy (GLOB)
  5. macro(COPY_RES_FILES GAME_NAME GAME_RES_TARGET REL_DIR SRC_FILES)
  6. file( GLOB_RECURSE RES_FILES RELATIVE ${REL_DIR} ${SRC_FILES} )
  7. set(ALL_FILES)
  8. foreach(SRC_FILE ${RES_FILES})
  9. add_custom_command(
  10. OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE}"
  11. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  12. "${REL_DIR}/${SRC_FILE}"
  13. "${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE}"
  14. COMMENT "Copy ${SRC_FILE}"
  15. )
  16. list(APPEND ALL_FILES "${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE}" )
  17. endforeach()
  18. # create target for copying these files
  19. add_custom_target( ${GAME_RES_TARGET} DEPENDS ${ALL_FILES} )
  20. endmacro()
  21. # convenience to call above with current directory and everything in "res"
  22. macro(COPY_RES GAME_NAME)
  23. # a target for all addition asserts (will be done in default compile, but if you target the executable
  24. # it won't be done -- good for testing)
  25. add_custom_target( ${GAME_NAME}_ASSETS ALL )
  26. # copy entire "res" directory and "game.config" if there is one
  27. set(CRG_PATTERN "res/*" "game.config")
  28. COPY_RES_FILES( ${GAME_NAME} ${GAME_NAME}_CORE_RES
  29. ${CMAKE_CURRENT_SOURCE_DIR}
  30. "${CRG_PATTERN}"
  31. )
  32. add_dependencies( ${GAME_NAME}_ASSETS ${GAME_NAME}_CORE_RES )
  33. endmacro()
  34. # Copies resources from an additional directory
  35. # GAME_NAME name of the game
  36. # REL_DIR from which directory
  37. # ARGN which patterns to copy (should include res/ in name if to be placed in the res/ output)
  38. macro(COPY_RES_EXTRA GAME_NAME REL_DIR)
  39. # convert src's to full paths (based on rel_dir)
  40. set(SRC_FILES)
  41. foreach(SRC_FILE ${ARGN} )
  42. list(APPEND SRC_FILES "${REL_DIR}/${SRC_FILE}")
  43. endforeach()
  44. COPY_RES_FILES( ${GAME_NAME} ${GAME_NAME}_EXTRA_RES ${REL_DIR} "${SRC_FILES}" )
  45. add_dependencies( ${GAME_NAME}_ASSETS ${GAME_NAME}_EXTRA_RES )
  46. endmacro()