Skip to content

Commit 867b810

Browse files
Refactor sync_directory function to streamline shader, model, and texture synchronization with directory handling instead of files handling.
1 parent aa83dc8 commit 867b810

1 file changed

Lines changed: 11 additions & 20 deletions

File tree

attachments/CMakeLists.txt

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,51 +178,42 @@ function (add_chapter CHAPTER_NAME)
178178
${CMAKE_GENERATOR} MATCHES "Ninja Multi-Config")
179179

180180
set(EXECUTABLE_DIR $<TARGET_FILE_DIR:${CHAPTER_NAME}>)
181+
181182
if(DEFINED CHAPTER_SHADER)
182183
sync_directory(
183184
"${CMAKE_BINARY_DIR}/${CHAPTER_NAME}/shaders"
184185
"${EXECUTABLE_DIR}/shaders"
185186
${CHAPTER_NAME}
186-
"${CHAPTER_NAME}: Shaders"
187+
"${CHAPTER_NAME}-Shaders"
187188
)
188189
endif()
189-
190190
if(DEFINED CHAPTER_MODELS)
191191
sync_directory(
192192
"${CMAKE_BINARY_DIR}/${CHAPTER_NAME}/models"
193193
"${EXECUTABLE_DIR}/models"
194194
${CHAPTER_NAME}
195-
"${CHAPTER_NAME}: Models"
195+
"${CHAPTER_NAME}-Models"
196196
)
197197
endif()
198-
199198
if(DEFINED CHAPTER_TEXTURES)
200199
sync_directory(
201200
"${CMAKE_BINARY_DIR}/${CHAPTER_NAME}/textures"
202201
"${EXECUTABLE_DIR}/textures"
203202
${CHAPTER_NAME}
204-
"${CHAPTER_NAME}: Textures"
203+
"${CHAPTER_NAME}-Textures"
205204
)
206205
endif()
207206
endif()
208207
endfunction ()
209208

210209
function(sync_directory SRC_DIR DST_DIR TARGET_NAME LABEL)
211-
file(GLOB_RECURSE FILES "${SRC_DIR}/*")
212-
213-
foreach(FILE IN LISTS FILES)
214-
file(RELATIVE_PATH REL_PATH "${SRC_DIR}" "${FILE}")
215-
set(DST_FILE "${DST_DIR}/${REL_PATH}")
216-
get_filename_component(DST_DIR_PATH "${DST_FILE}" DIRECTORY)
217-
218-
add_custom_command(
219-
TARGET ${TARGET_NAME}
220-
POST_BUILD
221-
COMMAND ${CMAKE_COMMAND} -E make_directory "${DST_DIR_PATH}"
222-
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FILE}" "${DST_FILE}"
223-
COMMENT "${LABEL}: Syncing ${REL_PATH}"
224-
)
225-
endforeach()
210+
add_custom_command(
211+
TARGET ${TARGET_NAME}
212+
POST_BUILD
213+
COMMAND ${CMAKE_COMMAND} -E make_directory "${DST_DIR}"
214+
COMMAND ${CMAKE_COMMAND} -E copy_directory "${SRC_DIR}" "${DST_DIR}"
215+
COMMENT "${LABEL}: Syncing directory"
216+
)
226217
endfunction()
227218

228219
add_chapter (00_base_code)

0 commit comments

Comments
 (0)