2020-03-27 19:11:16 +00:00
|
|
|
set(RPCS3_GIT_VERSION "local_build")
|
|
|
|
set(RPCS3_GIT_BRANCH "local_build")
|
|
|
|
set(RPCS3_GIT_FULL_BRANCH "local_build")
|
2015-01-15 01:58:11 +00:00
|
|
|
|
|
|
|
find_package(Git)
|
2019-02-13 20:06:19 +00:00
|
|
|
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git/")
|
2015-10-04 17:07:19 +00:00
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-list HEAD --count
|
2019-02-13 20:06:19 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
2015-01-15 01:58:11 +00:00
|
|
|
RESULT_VARIABLE exit_code
|
2019-02-13 20:06:19 +00:00
|
|
|
OUTPUT_VARIABLE RPCS3_GIT_VERSION)
|
2015-01-15 01:58:11 +00:00
|
|
|
if(NOT ${exit_code} EQUAL 0)
|
2015-10-04 17:07:19 +00:00
|
|
|
message(WARNING "git rev-list failed, unable to include version.")
|
|
|
|
endif()
|
2018-08-27 18:53:45 +00:00
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD
|
2019-02-13 20:06:19 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
2019-10-22 10:29:56 +00:00
|
|
|
RESULT_VARIABLE exit_code
|
2015-10-04 17:07:19 +00:00
|
|
|
OUTPUT_VARIABLE GIT_VERSION_)
|
2019-10-22 10:29:56 +00:00
|
|
|
if(NOT ${exit_code} EQUAL 0)
|
2015-10-04 17:07:19 +00:00
|
|
|
message(WARNING "git rev-parse failed, unable to include version.")
|
2015-01-15 01:58:11 +00:00
|
|
|
endif()
|
2017-12-08 23:53:05 +00:00
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
|
2019-02-13 20:06:19 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
2017-12-08 23:53:05 +00:00
|
|
|
RESULT_VARIABLE exit_code
|
2019-02-13 20:06:19 +00:00
|
|
|
OUTPUT_VARIABLE RPCS3_GIT_BRANCH)
|
2017-12-08 23:53:05 +00:00
|
|
|
if(NOT ${exit_code} EQUAL 0)
|
|
|
|
message(WARNING "git rev-parse failed, unable to include git branch.")
|
|
|
|
endif()
|
2019-09-17 20:17:20 +00:00
|
|
|
|
2019-10-22 10:29:56 +00:00
|
|
|
string(STRIP ${RPCS3_GIT_VERSION} RPCS3_GIT_VERSION)
|
|
|
|
string(STRIP ${GIT_VERSION_} GIT_VERSION_)
|
|
|
|
string(STRIP ${RPCS3_GIT_VERSION}-${GIT_VERSION_} RPCS3_GIT_VERSION)
|
|
|
|
string(STRIP ${RPCS3_GIT_BRANCH} RPCS3_GIT_BRANCH)
|
2015-01-15 01:58:11 +00:00
|
|
|
else()
|
|
|
|
message(WARNING "git not found, unable to include version.")
|
|
|
|
endif()
|
|
|
|
|
2019-02-13 20:06:19 +00:00
|
|
|
function(gen_git_version rpcs3_src_dir)
|
|
|
|
set(GIT_VERSION_FILE "${rpcs3_src_dir}/git-version.h")
|
|
|
|
set(GIT_VERSION_UPDATE "1")
|
2015-01-15 01:58:11 +00:00
|
|
|
|
2020-03-27 13:37:27 +00:00
|
|
|
# These environment variables are defined by Azure pipelines
|
|
|
|
# BUILD_REPOSITORY_NAME will look like "RPCS3/rpcs3"
|
|
|
|
# BUILD_SOURCEBRANCHNAME will look like "master"
|
|
|
|
# See https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables
|
2020-03-27 19:44:10 +00:00
|
|
|
if (DEFINED ENV{BUILD_REPOSITORY_NAME} AND NOT "$ENV{BUILD_REPOSITORY_NAME}" STREQUAL "")
|
2020-03-27 13:37:27 +00:00
|
|
|
set(RPCS3_GIT_FULL_BRANCH "$ENV{BUILD_REPOSITORY_NAME}/$ENV{BUILD_SOURCEBRANCHNAME}")
|
|
|
|
endif()
|
|
|
|
|
2019-02-13 20:06:19 +00:00
|
|
|
message(STATUS "RPCS3_GIT_VERSION: " ${RPCS3_GIT_VERSION})
|
|
|
|
message(STATUS "RPCS3_GIT_BRANCH: " ${RPCS3_GIT_BRANCH})
|
2020-03-27 13:37:27 +00:00
|
|
|
message(STATUS "RPCS3_GIT_FULL_BRANCH: " ${RPCS3_GIT_FULL_BRANCH})
|
2019-02-13 20:06:19 +00:00
|
|
|
|
|
|
|
if(EXISTS ${GIT_VERSION_FILE})
|
|
|
|
# Don't update if marked not to update.
|
|
|
|
file(STRINGS ${GIT_VERSION_FILE} match
|
|
|
|
REGEX "RPCS3_GIT_VERSION_NO_UPDATE 1")
|
|
|
|
if(NOT "${match}" STREQUAL "")
|
|
|
|
set(GIT_VERSION_UPDATE "0")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Don't update if it's already the same.
|
|
|
|
file(STRINGS ${GIT_VERSION_FILE} match
|
2019-02-28 01:05:29 +00:00
|
|
|
REGEX "${RPCS3_GIT_VERSION}")
|
2019-02-13 20:06:19 +00:00
|
|
|
if(NOT "${match}" STREQUAL "")
|
|
|
|
set(GIT_VERSION_UPDATE "0")
|
|
|
|
endif()
|
2018-08-27 18:53:45 +00:00
|
|
|
endif()
|
2015-01-15 01:58:11 +00:00
|
|
|
|
2019-02-13 20:06:19 +00:00
|
|
|
set(code_string "// This is a generated file.\n\n"
|
2019-02-28 01:05:29 +00:00
|
|
|
"#define RPCS3_GIT_VERSION \"${RPCS3_GIT_VERSION}\"\n"
|
2020-03-27 13:37:27 +00:00
|
|
|
"#define RPCS3_GIT_BRANCH \"${RPCS3_GIT_BRANCH}\"\n"
|
|
|
|
"#define RPCS3_GIT_FULL_BRANCH \"${RPCS3_GIT_FULL_BRANCH}\"\n\n"
|
2019-02-13 20:06:19 +00:00
|
|
|
"// If you don't want this file to update/recompile, change to 1.\n"
|
|
|
|
"#define RPCS3_GIT_VERSION_NO_UPDATE 0\n")
|
2015-01-15 01:58:11 +00:00
|
|
|
|
2019-02-13 20:06:19 +00:00
|
|
|
if ("${GIT_VERSION_UPDATE}" EQUAL "1")
|
|
|
|
file(WRITE ${GIT_VERSION_FILE} ${code_string})
|
|
|
|
endif()
|
|
|
|
endfunction()
|