summaryrefslogtreecommitdiffhomepage
path: root/cmake
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-02-09 18:46:52 +0100
committerAki <please@ignore.pl>2022-02-09 18:46:52 +0100
commit9ea64a9714712961a60fa436ccdaf3fd7c3a09e3 (patch)
tree1aed83e2a5a79757e864a595420f4438a4379afd /cmake
parent39b36e332725498bcfa0a712b2a880b4abe8a174 (diff)
downloadstarshatter-9ea64a9714712961a60fa436ccdaf3fd7c3a09e3.zip
starshatter-9ea64a9714712961a60fa436ccdaf3fd7c3a09e3.tar.gz
starshatter-9ea64a9714712961a60fa436ccdaf3fd7c3a09e3.tar.bz2
Somewhat finalized AddDatafile and AddDownloadableResource
Ready-to-distribute datafiles can now be produced by the build chain. This is already done for shatter.dat, content.dat, and start.dat
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/AddDatafile.cmake18
-rw-r--r--cmake/modules/AddDownloadableResource.cmake37
2 files changed, 46 insertions, 9 deletions
diff --git a/cmake/modules/AddDatafile.cmake b/cmake/modules/AddDatafile.cmake
index 3bf2388..f54b892 100644
--- a/cmake/modules/AddDatafile.cmake
+++ b/cmake/modules/AddDatafile.cmake
@@ -1,17 +1,20 @@
-# TODO: Update to match new AddDownloadableResource.
-# Adds a target that creates a datafile archive containing all files under selected directory tree. For example:
+# Adds a target that creates a datafile archive containing all files under selected source directory tree. For example:
#
# add_datafile(
# shatter
# SOURCE shatter
# OUTPUT shatter.dat
+# RESOURCES resource_shatter
# )
#
# Will create 'shatter.dat' in the respective binary directory containing all files in 'shatter' subdirectory of current
# source directory. SOURCE option's argument defaults to the target name. OUTPUT option's argument defaults to the
# target name with ".dat" suffix.
#
-# To create the archive Datafile.exe is used, so for non-Windows platforms an emulator that can run it is needed.
+# Optionally, RESOURCES can be used to specify binary resource targets from AddDownloadableResource that will provide
+# additional directories with files that will also get included in the final datafile.
+#
+# To create the archive the Datafile.exe is used - for non-Windows platforms an emulator that can run it is required.
function(add_datafile)
set(DATAFILE_TARGET ${ARGV0})
@@ -51,14 +54,13 @@ function(add_datafile)
$<TARGET_FILE:Datafile> $<SHELL_PATH:${DATAFILE_OUTPUT}> -mak
COMMENT "Creating datafile ${DATAFILE_TARGET}"
)
- foreach(RESOURCE IN ITEMS ${DATAFILE_RESOURCES})
- cmake_path(ABSOLUTE_PATH RESOURCE NORMALIZE BASE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
- message(STATUS ${RESOURCE})
+ foreach(RESOURCE_TARGET IN ITEMS ${DATAFILE_RESOURCES})
+ get_property(RESOURCE_DIRECTORY TARGET ${RESOURCE_TARGET} PROPERTY RESOURCE_DIRECTORY)
add_custom_command(
OUTPUT ${DATAFILE_OUTPUT} APPEND
- DEPENDS ${RESOURCE}
+ DEPENDS ${RESOURCE_TARGET}
COMMAND
- ${CMAKE_COMMAND} -E chdir ${RESOURCE}
+ ${CMAKE_COMMAND} -E chdir ${RESOURCE_DIRECTORY}
${CMAKE_COMMAND} -E env "${DATAFILE_VAR}='${DATAFILE_PATHS}'"
${CMAKE_CORSSCOMPILING_EMULATOR}
$<TARGET_FILE:Datafile> $<SHELL_PATH:${DATAFILE_OUTPUT}> -mak
diff --git a/cmake/modules/AddDownloadableResource.cmake b/cmake/modules/AddDownloadableResource.cmake
index bbef5b7..d0374ad 100644
--- a/cmake/modules/AddDownloadableResource.cmake
+++ b/cmake/modules/AddDownloadableResource.cmake
@@ -1,4 +1,35 @@
-# TODO: Document this and how it interacts with AddDatafile.
+# Adds a target that downloads an archive containing binary files that should be part of game distribution but are not
+# part of the version control system. For example:
+#
+# add_downloadable_resource(
+# resource_shatter
+# ARCHIVE shatter.tar.xz
+# DIRECTORY shatter.d
+# BASE_URL https://ftp.ignore.pl/starshatter/resource/latest
+# SHA1 bbed14649213a45499e0a158142f19fd619a54af
+# )
+#
+# Will download 'shatter.tar.xz' from 'https://ftp.ignore.pl/starshatter/resouce/latest' and unpack it into 'shatter.d'
+# subdirectory under respective binary directory. The archive will be validated for correctness with SHA1.
+#
+# Selected options provide default arguments:
+# * ARCHIVE defaults to '<target_name>.tar.xz'
+# * DIRECTORY defaults to '<target_name>.d'
+# * BASE_URL defaults to 'https://ftp.ignore.pl/starshatter/resource/latest'
+#
+# Targets are designed to be used with AddDatafile targets via their RESOURCES option:
+#
+# add_downloadable_resource(resource_shatter ...)
+# add_datafile(
+# shatter
+# RESOURCES resource_shatter
+# )
+#
+# This will automatically make the datafile generated by 'shatter' target to include files downloaded by
+# 'resource_shatter'.
+#
+# Downloaded archives are not cleaned by default to avoid unnecessarily long build times. Instead they need to be
+# cleaned explicitly either by removing them manually or by running 'clean_downloaded_<target_name>' target.
set(ADD_DOWNLOADABLE_RESOURCE_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/download_resource.cmake.in)
function(add_downloadable_resource)
@@ -46,4 +77,8 @@ function(add_downloadable_resource)
${CMAKE_COMMAND} -E tar xf ${RESOURCE_ARCHIVE}
)
add_custom_target(${RESOURCE_TARGET} DEPENDS ${RESOURCE_DIRECTORY})
+ set_property(
+ TARGET ${RESOURCE_TARGET}
+ PROPERTY RESOURCE_DIRECTORY ${RESOURCE_DIRECTORY}
+ )
endfunction()