2
0

BuildHelpers.CMakeLists.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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()
  47. # Build a list of file matching a list of regular expression within a given path
  48. # RESULT name of the global variable into which the result is built
  49. # REL_PATH the path under which the files are to be found
  50. # ARGN list of patterns
  51. macro(MAKE_ABSOLUTE RESULT REL_PATH)
  52. set(${RESULT})
  53. foreach(SRC_FILE ${ARGN} )
  54. file(GLOB XX ${REL_PATH}/${SRC_FILE})
  55. list(APPEND ${RESULT} ${XX})
  56. endforeach()
  57. endmacro()
  58. # Build a list of resource files matching a list of regular expression within a given path
  59. # and mark their correct Mac OS X destination, keeping the relative position to a base path
  60. # RESULT name of the global variable into which the result is built
  61. # BASE_SRC_PATH the base path under which the structure is replicated in the bundle
  62. # REL_PATH a pattern to be matched and searched recursively.
  63. macro(COPY_RES_MAC RESULT BASE_SRC_PATH)
  64. set(${RESULT})
  65. foreach(PATTERN ${ARGN} )
  66. file(GLOB_RECURSE XX RELATIVE ${BASE_SRC_PATH} ${BASE_SRC_PATH}/${PATTERN})
  67. foreach(FNAME ${XX})
  68. list(APPEND ${RESULT} ${BASE_SRC_PATH}/${FNAME})
  69. get_filename_component(DIR ${FNAME} DIRECTORY )
  70. set_source_files_properties(
  71. ${BASE_SRC_PATH}/${FNAME}
  72. PROPERTIES
  73. MACOSX_PACKAGE_LOCATION Resources/${DIR}
  74. )
  75. endforeach()
  76. endforeach()
  77. endmacro()