Skip to content

Commit

Permalink
[cmake] add support for BUNDLE_DIRECTORIES. allows you to select enti…
Browse files Browse the repository at this point in the history
…re directories to be bundled, this means every single file in those directories (recursively) will be added as BUNDLE_FILES.
  • Loading branch information
harrand committed Nov 17, 2024
1 parent a85b2b1 commit ae5c6e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 8 additions & 1 deletion cmake/bundle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ function(topaz_bundle_files)
TOPAZ_BUNDLE_FILES
""
"TARGET"
"FILES"
"FILES;DIRECTORIES"
${ARGN}
)

# for each bundle directory, glob recursively and add everything as files.
# if a new thing was added in the directory, will reconfigure thanks to CONFIGURE_DEPENDS
foreach(dir IN LISTS TOPAZ_BUNDLE_FILES_DIRECTORIES)
file(GLOB_RECURSE local_files CONFIGURE_DEPENDS RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/${dir}/*)
list(APPEND TOPAZ_BUNDLE_FILES_FILES ${local_files})
endforeach()

# source dir: CMAKE_CURRENT_SOURCE_DIR
# Loop over each file and replicate the directory structure in the binary directory
set_target_properties(${TOPAZ_BUNDLE_FILES_TARGET} PROPERTIES TOPAZ_BUNDLE_DEPENDENCIES "${TOPAZ_BUNDLE_FILES_FILES}")
Expand Down
10 changes: 6 additions & 4 deletions cmake/topaz.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function(topaz_add_library)
TOPAZ_ADD_LIBRARY
"DEFINE_PACKAGE"
"TARGET"
"SOURCES;SHADERS;TEXT_FILES;BUNDLE_FILES"
"SOURCES;SHADERS;TEXT_FILES;BUNDLE_FILES;BUNDLE_DIRECTORIES"
${ARGN}
)

Expand All @@ -23,10 +23,11 @@ function(topaz_add_library)
OUTPUT_DIR ${PROJECT_BINARY_DIR}
TEXT_FILES ${TOPAZ_ADD_LIBRARY_TEXT_FILES}
)
if(TOPAZ_ADD_LIBRARY_BUNDLE_FILES)
if(DEFINED TOPAZ_ADD_LIBRARY_BUNDLE_FILES OR DEFINED TOPAZ_ADD_LIBRARY_BUNDLE_DIRECTORIES)
topaz_bundle_files(
TARGET ${TOPAZ_ADD_LIBRARY_TARGET}
FILES ${TOPAZ_ADD_LIBRARY_BUNDLE_FILES}
DIRECTORIES ${TOPAZ_ADD_LIBRARY_BUNDLE_DIRECTORIES}
)
endif()
if(TOPAZ_ADD_LIBRARY_DEFINE_PACKAGE)
Expand All @@ -39,7 +40,7 @@ function(topaz_add_executable)
TOPAZ_ADD_EXECUTABLE
"DEFINE_PACKAGE"
"TARGET;FAVICON"
"SOURCES;SHADERS;TEXT_FILES;BUNDLE_FILES"
"SOURCES;SHADERS;TEXT_FILES;BUNDLE_FILES;BUNDLE_DIRECTORIES"
${ARGN}
)

Expand All @@ -63,10 +64,11 @@ function(topaz_add_executable)
OUTPUT_DIR ${PROJECT_BINARY_DIR}
TEXT_FILES ${TOPAZ_ADD_EXECUTABLE_TEXT_FILES}
)
if(TOPAZ_ADD_EXECUTABLE_BUNDLE_FILES)
if(DEFINED TOPAZ_ADD_EXECUTABLE_BUNDLE_FILES OR DEFINED TOPAZ_ADD_EXECUTABLE_BUNDLE_DIRECTORIES)
topaz_bundle_files(
TARGET ${TOPAZ_ADD_EXECUTABLE_TARGET}
FILES ${TOPAZ_ADD_EXECUTABLE_BUNDLE_FILES}
DIRECTORIES ${TOPAZ_ADD_EXECUTABLE_BUNDLE_DIRECTORIES}
)
endif()
if(TOPAZ_ADD_EXECUTABLE_DEFINE_PACKAGE)
Expand Down

0 comments on commit ae5c6e8

Please sign in to comment.