mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-25 12:12:50 +01:00
CMake: Refactor git-version.cmake
Refactor git-version.cmake to define the RPCS3_GIT_VERSION, RPCS3_GIT_BRANCH, and RPCS3_GIT_TAG variables, and move the generation of git-version.h to a function (gen_git_version).
This commit is contained in:
parent
c325534f07
commit
923700a167
@ -85,7 +85,7 @@ If you're not using precompiled libs, build the projects in *__BUILD_BEFORE* fol
|
||||
While still in the project root:
|
||||
|
||||
1) `cd .. && mkdir rpcs3_build && cd rpcs3_build`
|
||||
2) `cmake ../rpcs3/ && make GitVersion && make`
|
||||
2) `cmake ../rpcs3/ && make`
|
||||
3) Run RPCS3 with `./bin/rpcs3`
|
||||
|
||||
When using GDB, configure it to ignore SIGSEGV signal (`handle SIGSEGV nostop noprint`).
|
||||
|
@ -3,9 +3,7 @@ cmake_minimum_required(VERSION 3.8.2)
|
||||
include(cotire)
|
||||
|
||||
# Generate git-version.h at build time.
|
||||
add_custom_target(GitVersion ALL
|
||||
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/git-version.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/git-version.cmake)
|
||||
|
||||
# Check for a sufficient compiler and set build options
|
||||
include(ConfigureCompiler)
|
||||
@ -54,7 +52,7 @@ else()
|
||||
add_executable(rpcs3 ${RPCS3_SRC})
|
||||
endif()
|
||||
|
||||
add_dependencies(rpcs3 GitVersion)
|
||||
gen_git_version(${RPCS3_SRC_DIR})
|
||||
set_target_properties(rpcs3
|
||||
PROPERTIES
|
||||
AUTOMOC ON
|
||||
|
@ -1,63 +1,79 @@
|
||||
set(GIT_VERSION_FILE "${SOURCE_DIR}/git-version.h")
|
||||
set(GIT_VERSION "unknown")
|
||||
set(GIT_BRANCH "unknown")
|
||||
set(GIT_VERSION_UPDATE "1")
|
||||
set(RPCS3_GIT_VERSION "unknown")
|
||||
set(RPCS3_GIT_BRANCH "unknown")
|
||||
set(RPCS3_GIT_TAG "unknown")
|
||||
|
||||
find_package(Git)
|
||||
if(GIT_FOUND AND EXISTS "${SOURCE_DIR}/../.git/")
|
||||
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git/")
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} rev-list HEAD --count
|
||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
RESULT_VARIABLE exit_code
|
||||
OUTPUT_VARIABLE GIT_VERSION)
|
||||
OUTPUT_VARIABLE RPCS3_GIT_VERSION)
|
||||
if(NOT ${exit_code} EQUAL 0)
|
||||
message(WARNING "git rev-list failed, unable to include version.")
|
||||
endif()
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD
|
||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
RESULT_VARIABLE exit_code
|
||||
OUTPUT_VARIABLE GIT_VERSION_)
|
||||
if(NOT ${exit_code} EQUAL 0)
|
||||
message(WARNING "git rev-parse failed, unable to include version.")
|
||||
endif()
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
|
||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
RESULT_VARIABLE exit_code
|
||||
OUTPUT_VARIABLE GIT_BRANCH)
|
||||
OUTPUT_VARIABLE RPCS3_GIT_BRANCH)
|
||||
if(NOT ${exit_code} EQUAL 0)
|
||||
message(WARNING "git rev-parse failed, unable to include git branch.")
|
||||
endif()
|
||||
string(STRIP ${GIT_VERSION} GIT_VERSION)
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
RESULT_VARIABLE exit_code
|
||||
OUTPUT_VARIABLE RPCS3_GIT_TAG)
|
||||
if(NOT ${exit_code} EQUAL 0)
|
||||
message(WARNING "git describe failed, unable to include git tag.")
|
||||
endif()
|
||||
|
||||
string(STRIP ${RPCS3_GIT_VERSION} RPCS3_GIT_VERSION)
|
||||
string(STRIP ${GIT_VERSION_} GIT_VERSION_)
|
||||
string(STRIP ${GIT_VERSION}-${GIT_VERSION_} GIT_VERSION)
|
||||
string(STRIP ${GIT_BRANCH} GIT_BRANCH)
|
||||
message(STATUS "GIT_VERSION: " ${GIT_VERSION})
|
||||
message(STATUS "GIT_BRANCH: " ${GIT_BRANCH})
|
||||
string(STRIP ${RPCS3_GIT_VERSION}-${GIT_VERSION_} RPCS3_GIT_VERSION)
|
||||
string(STRIP ${RPCS3_GIT_BRANCH} RPCS3_GIT_BRANCH)
|
||||
string(STRIP ${RPCS3_GIT_TAG} RPCS3_GIT_TAG)
|
||||
string(REPLACE "v" "" RPCS3_GIT_TAG ${RPCS3_GIT_TAG})
|
||||
else()
|
||||
message(WARNING "git not found, unable to include version.")
|
||||
endif()
|
||||
|
||||
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")
|
||||
function(gen_git_version rpcs3_src_dir)
|
||||
set(GIT_VERSION_FILE "${rpcs3_src_dir}/git-version.h")
|
||||
set(GIT_VERSION_UPDATE "1")
|
||||
|
||||
message(STATUS "RPCS3_GIT_VERSION: " ${RPCS3_GIT_VERSION})
|
||||
message(STATUS "RPCS3_GIT_BRANCH: " ${RPCS3_GIT_BRANCH})
|
||||
message(STATUS "RPCS3_GIT_TAG: " ${RPCS3_GIT_TAG})
|
||||
|
||||
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
|
||||
REGEX "${GIT_VERSION}")
|
||||
if(NOT "${match}" STREQUAL "")
|
||||
set(GIT_VERSION_UPDATE "0")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Don't update if it's already the same.
|
||||
file(STRINGS ${GIT_VERSION_FILE} match
|
||||
REGEX "${GIT_VERSION}")
|
||||
if(NOT "${match}" STREQUAL "")
|
||||
set(GIT_VERSION_UPDATE "0")
|
||||
set(code_string "// This is a generated file.\n\n"
|
||||
"#define RPCS3_GIT_VERSION \"${GIT_VERSION}\"\n"
|
||||
"#define RPCS3_GIT_BRANCH \"${GIT_BRANCH}\"\n\n"
|
||||
"// If you don't want this file to update/recompile, change to 1.\n"
|
||||
"#define RPCS3_GIT_VERSION_NO_UPDATE 0\n")
|
||||
|
||||
if ("${GIT_VERSION_UPDATE}" EQUAL "1")
|
||||
file(WRITE ${GIT_VERSION_FILE} ${code_string})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(code_string "// This is a generated file.\n\n"
|
||||
"#define RPCS3_GIT_VERSION \"${GIT_VERSION}\"\n"
|
||||
"#define RPCS3_GIT_BRANCH \"${GIT_BRANCH}\"\n\n"
|
||||
"// If you don't want this file to update/recompile, change to 1.\n"
|
||||
"#define RPCS3_GIT_VERSION_NO_UPDATE 0\n")
|
||||
|
||||
if ("${GIT_VERSION_UPDATE}" EQUAL "1")
|
||||
file(WRITE ${GIT_VERSION_FILE} ${code_string})
|
||||
endif()
|
||||
endfunction()
|
||||
|
Loading…
Reference in New Issue
Block a user