From d8ac2852ba2ddbbde7d5dd4f9c9240a360c16428 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 14 May 2023 12:03:16 +0200 Subject: [PATCH] Regenerate 'build.txt' after DLL project builds This post build event function regenerates the 'build.txt' file after compiling the engine projects. It takes the branch name, commit hash (short), current time and time designator. --- r5dev/cmake/PostBuild.cmake | 49 +++++++++++++++++++++++++++++++++++++ r5dev/core/CMakeLists.txt | 4 +++ 2 files changed, 53 insertions(+) create mode 100644 r5dev/cmake/PostBuild.cmake diff --git a/r5dev/cmake/PostBuild.cmake b/r5dev/cmake/PostBuild.cmake new file mode 100644 index 00000000..a5355aff --- /dev/null +++ b/r5dev/cmake/PostBuild.cmake @@ -0,0 +1,49 @@ +# ----------------------------------------------------------------------------- +# Creates and writes the build string after building a project +# ----------------------------------------------------------------------------- +function( WriteBuildString OUTPUT_DIR ) + # Get the current date and time + string( TIMESTAMP CURRENT_DATE "%Y_%m_%d_%I_%M" ) # Use %I for 12-hour clock + + # Compute AM/PM + string( TIMESTAMP CURRENT_HOUR "%H" ) + if( CURRENT_HOUR LESS 12 ) + set( TIME_DESIGNATOR "AM" ) + else() + set( TIME_DESIGNATOR "PM" ) + endif() + + # Get the current git commit hash + execute_process( COMMAND + git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + # Convert the hash to uppercase + string( TOUPPER + "${GIT_COMMIT_HASH} GIT_COMMIT_HASH" + ) + + # Get the current git branch name + execute_process( COMMAND + git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH_NAME + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + # Construct the build string + set( BUILD_STRING + "R5pc_${GIT_BRANCH_NAME}_N1094_${GIT_COMMIT_HASH}_${CURRENT_DATE}_${TIME_DESIGNATOR}\n" + ) + + # Write the build string to a file + file( WRITE + "${CMAKE_SOURCE_DIR}/${OUTPUT_DIR}/build.txt ${BUILD_STRING}" + ) +endfunction() + +# Initiate the creation command +WriteBuildString( "../../../game" ) diff --git a/r5dev/core/CMakeLists.txt b/r5dev/core/CMakeLists.txt index 1c1c9100..baa7b3b0 100644 --- a/r5dev/core/CMakeLists.txt +++ b/r5dev/core/CMakeLists.txt @@ -120,6 +120,10 @@ target_link_options( ${PROJECT_NAME} PRIVATE "/STACK:8000000" # Match game executable stack reserve size ) +add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -P ${ENGINE_SOURCE_DIR}/cmake/PostBuild.cmake +) + endmacro() add_sdk_project( "gamesdk" )