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" )