Skip to content

Commit

Permalink
build: added AIO_ZIP_TO_DIST cmake flag to build AIO zip for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
FlayaN committed Feb 10, 2024
1 parent f622afe commit cf16fb2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
9 changes: 8 additions & 1 deletion BuildRelease.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
@echo off

cmake -S . --preset=ALL --check-stamp-file "build\CMakeFiles\generate.stamp"
set preset="ALL"
if NOT "%1" == "" (
set preset=%1
)

echo Running preset %preset%

cmake -S . --preset=%preset% --check-stamp-file "build\CMakeFiles\generate.stamp"
if %ERRORLEVEL% NEQ 0 exit 1
cmake --build build --config Release
if %ERRORLEVEL% NEQ 0 exit 1
Expand Down
41 changes: 30 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
message("Options:")
option(AUTO_PLUGIN_DEPLOYMENT "Copy the build output and addons to env:CommunityShadersOutputDir." OFF)
option(ZIP_TO_DIST "Zip the base mod and addons to their own 7z file in dist." ON)
option(AIO_ZIP_TO_DIST "Zip the base mod and addons to a AIO 7z file in dist." OFF)
message("\tAuto plugin deployment: ${AUTO_PLUGIN_DEPLOYMENT}")
message("\tZip to dist: ${ZIP_TO_DIST}")
message("\tAIO Zip to dist: ${AIO_ZIP_TO_DIST}")

# #######################################################################################################################
# # Add CMake features
Expand Down Expand Up @@ -85,21 +87,29 @@ endif()
# #######################################################################################################################
file(GLOB FEATURE_PATHS LIST_DIRECTORIES true ${CMAKE_SOURCE_DIR}/features/*)

if(AUTO_PLUGIN_DEPLOYMENT OR AIO_ZIP_TO_DIST)
set(AIO_DIR "${CMAKE_CURRENT_BINARY_DIR}/aio")
message("Copying package folder with dll/pdb with all features to ${AIO_DIR}")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/package "${AIO_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> "${AIO_DIR}/SKSE/Plugins/"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> "${AIO_DIR}/SKSE/Plugins/"
)

foreach(FEATURE_PATH ${FEATURE_PATHS})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${FEATURE_PATH} "${AIO_DIR}"
)
endforeach()
endif()

# Automatic deployment to CommunityShaders output directory.
if(AUTO_PLUGIN_DEPLOYMENT)
foreach(DEPLOY_TARGET $ENV{CommunityShadersOutputDir})
message("Copying package folder with dll/pdb with all features to ${DEPLOY_TARGET}")
message("Copying AIO to ${DEPLOY_TARGET}")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/package "${DEPLOY_TARGET}"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> "${DEPLOY_TARGET}/SKSE/Plugins/"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> "${DEPLOY_TARGET}/SKSE/Plugins/"
COMMAND ${CMAKE_COMMAND} -E copy_directory ${AIO_DIR} "${DEPLOY_TARGET}"
)

foreach(FEATURE_PATH ${FEATURE_PATHS})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${FEATURE_PATH} "${DEPLOY_TARGET}"
)
endforeach()
endforeach()

if(NOT DEFINED ENV{CommunityShadersOutputDir})
Expand All @@ -110,7 +120,6 @@ endif()
# Zip base CommunityShaders and all addons as their own 7z in dist folder
if(ZIP_TO_DIST)
set(ZIP_DIR "${CMAKE_CURRENT_BINARY_DIR}/zip")
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/test/)
add_custom_target(build-time-make-directory ALL
COMMAND ${CMAKE_COMMAND} -E remove_directory "${ZIP_DIR}" ${CMAKE_SOURCE_DIR}/dist
COMMAND ${CMAKE_COMMAND} -E make_directory "${ZIP_DIR}" ${CMAKE_SOURCE_DIR}/dist
Expand Down Expand Up @@ -139,3 +148,13 @@ if(ZIP_TO_DIST)
)
endforeach()
endif()

# Create a AIO zip for easier testing
if(AIO_ZIP_TO_DIST)
set(TARGET_AIO_ZIP "${PROJECT_NAME}_AIO.7z")
message("Zipping ${AIO_DIR} to ${CMAKE_SOURCE_DIR}/dist/${TARGET_AIO_ZIP}")
ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E tar cf ${CMAKE_SOURCE_DIR}/dist/${TARGET_AIO_ZIP} --format=7zip -- .
WORKING_DIRECTORY ${AIO_DIR}
)
endif()
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ cd skyrim-community-shaders
.\BuildRelease.bat
```

### CMAKE Options (optional)
If you want an example CMakeUserPreset to start off with you can copy the `CMakeUserPresets.json.template` -> `CMakeUserPresets.json`
#### AUTO_PLUGIN_DEPLOYMENT
* This option is default `"OFF"`
* Make sure `"AUTO_PLUGIN_DEPLOYMENT"` is set to `"ON"` in `CMakeUserPresets.json`
* Change the `"CommunityShadersOutputDir"` value to match your desired outputs, if you want multiple folders you can separate them by `;` is shown in the template example
#### AIO_ZIP_TO_DIST
* This option is default `"OFF"`
* Make sure `"AIO_ZIP_TO_DIST"` is set to `"ON"` in `CMakeUserPresets.json`
* This will create a `CommunityShaders_AIO.7z` archive in /dist containing all features and base mod
#### ZIP_TO_DIST
* This option is default `"ON"`
* Make sure `"ZIP_TO_DIST"` is set to `"ON"` in `CMakeUserPresets.json`
* This will create a zip for each feature and one for the base Community shaders in /dist containing

When using custom preset you can call BuildRelease.bat with an parameter to specify which preset to configure eg:
`.\BuildRelease.bat ALL-WITH-AUTO-DEPLOYMENT`

When switching between different presets you might need to remove the build folder

## License

### Default
Expand Down

0 comments on commit cf16fb2

Please sign in to comment.