mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-16 23:17:29 +00: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:
|
While still in the project root:
|
||||||
|
|
||||||
1) `cd .. && mkdir rpcs3_build && cd rpcs3_build`
|
1) `cd .. && mkdir rpcs3_build && cd rpcs3_build`
|
||||||
2) `cmake ../rpcs3/ && make GitVersion && make`
|
2) `cmake ../rpcs3/ && make`
|
||||||
3) Run RPCS3 with `./bin/rpcs3`
|
3) Run RPCS3 with `./bin/rpcs3`
|
||||||
|
|
||||||
When using GDB, configure it to ignore SIGSEGV signal (`handle SIGSEGV nostop noprint`).
|
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)
|
include(cotire)
|
||||||
|
|
||||||
# Generate git-version.h at build time.
|
# Generate git-version.h at build time.
|
||||||
add_custom_target(GitVersion ALL
|
include(${CMAKE_CURRENT_SOURCE_DIR}/git-version.cmake)
|
||||||
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/git-version.cmake)
|
|
||||||
|
|
||||||
# Check for a sufficient compiler and set build options
|
# Check for a sufficient compiler and set build options
|
||||||
include(ConfigureCompiler)
|
include(ConfigureCompiler)
|
||||||
@ -54,7 +52,7 @@ else()
|
|||||||
add_executable(rpcs3 ${RPCS3_SRC})
|
add_executable(rpcs3 ${RPCS3_SRC})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_dependencies(rpcs3 GitVersion)
|
gen_git_version(${RPCS3_SRC_DIR})
|
||||||
set_target_properties(rpcs3
|
set_target_properties(rpcs3
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
AUTOMOC ON
|
AUTOMOC ON
|
||||||
|
@ -1,42 +1,57 @@
|
|||||||
set(GIT_VERSION_FILE "${SOURCE_DIR}/git-version.h")
|
set(RPCS3_GIT_VERSION "unknown")
|
||||||
set(GIT_VERSION "unknown")
|
set(RPCS3_GIT_BRANCH "unknown")
|
||||||
set(GIT_BRANCH "unknown")
|
set(RPCS3_GIT_TAG "unknown")
|
||||||
set(GIT_VERSION_UPDATE "1")
|
|
||||||
|
|
||||||
find_package(Git)
|
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
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-list HEAD --count
|
||||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
RESULT_VARIABLE exit_code
|
RESULT_VARIABLE exit_code
|
||||||
OUTPUT_VARIABLE GIT_VERSION)
|
OUTPUT_VARIABLE RPCS3_GIT_VERSION)
|
||||||
if(NOT ${exit_code} EQUAL 0)
|
if(NOT ${exit_code} EQUAL 0)
|
||||||
message(WARNING "git rev-list failed, unable to include version.")
|
message(WARNING "git rev-list failed, unable to include version.")
|
||||||
endif()
|
endif()
|
||||||
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD
|
||||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
RESULT_VARIABLE exit_code
|
RESULT_VARIABLE exit_code
|
||||||
OUTPUT_VARIABLE GIT_VERSION_)
|
OUTPUT_VARIABLE GIT_VERSION_)
|
||||||
if(NOT ${exit_code} EQUAL 0)
|
if(NOT ${exit_code} EQUAL 0)
|
||||||
message(WARNING "git rev-parse failed, unable to include version.")
|
message(WARNING "git rev-parse failed, unable to include version.")
|
||||||
endif()
|
endif()
|
||||||
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
|
||||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
RESULT_VARIABLE exit_code
|
RESULT_VARIABLE exit_code
|
||||||
OUTPUT_VARIABLE GIT_BRANCH)
|
OUTPUT_VARIABLE RPCS3_GIT_BRANCH)
|
||||||
if(NOT ${exit_code} EQUAL 0)
|
if(NOT ${exit_code} EQUAL 0)
|
||||||
message(WARNING "git rev-parse failed, unable to include git branch.")
|
message(WARNING "git rev-parse failed, unable to include git branch.")
|
||||||
endif()
|
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_)
|
||||||
string(STRIP ${GIT_VERSION}-${GIT_VERSION_} GIT_VERSION)
|
string(STRIP ${RPCS3_GIT_VERSION}-${GIT_VERSION_} RPCS3_GIT_VERSION)
|
||||||
string(STRIP ${GIT_BRANCH} GIT_BRANCH)
|
string(STRIP ${RPCS3_GIT_BRANCH} RPCS3_GIT_BRANCH)
|
||||||
message(STATUS "GIT_VERSION: " ${GIT_VERSION})
|
string(STRIP ${RPCS3_GIT_TAG} RPCS3_GIT_TAG)
|
||||||
message(STATUS "GIT_BRANCH: " ${GIT_BRANCH})
|
string(REPLACE "v" "" RPCS3_GIT_TAG ${RPCS3_GIT_TAG})
|
||||||
else()
|
else()
|
||||||
message(WARNING "git not found, unable to include version.")
|
message(WARNING "git not found, unable to include version.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(EXISTS ${GIT_VERSION_FILE})
|
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.
|
# Don't update if marked not to update.
|
||||||
file(STRINGS ${GIT_VERSION_FILE} match
|
file(STRINGS ${GIT_VERSION_FILE} match
|
||||||
REGEX "RPCS3_GIT_VERSION_NO_UPDATE 1")
|
REGEX "RPCS3_GIT_VERSION_NO_UPDATE 1")
|
||||||
@ -50,14 +65,15 @@ if(EXISTS ${GIT_VERSION_FILE})
|
|||||||
if(NOT "${match}" STREQUAL "")
|
if(NOT "${match}" STREQUAL "")
|
||||||
set(GIT_VERSION_UPDATE "0")
|
set(GIT_VERSION_UPDATE "0")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(code_string "// This is a generated file.\n\n"
|
set(code_string "// This is a generated file.\n\n"
|
||||||
"#define RPCS3_GIT_VERSION \"${GIT_VERSION}\"\n"
|
"#define RPCS3_GIT_VERSION \"${GIT_VERSION}\"\n"
|
||||||
"#define RPCS3_GIT_BRANCH \"${GIT_BRANCH}\"\n\n"
|
"#define RPCS3_GIT_BRANCH \"${GIT_BRANCH}\"\n\n"
|
||||||
"// If you don't want this file to update/recompile, change to 1.\n"
|
"// If you don't want this file to update/recompile, change to 1.\n"
|
||||||
"#define RPCS3_GIT_VERSION_NO_UPDATE 0\n")
|
"#define RPCS3_GIT_VERSION_NO_UPDATE 0\n")
|
||||||
|
|
||||||
if ("${GIT_VERSION_UPDATE}" EQUAL "1")
|
if ("${GIT_VERSION_UPDATE}" EQUAL "1")
|
||||||
file(WRITE ${GIT_VERSION_FILE} ${code_string})
|
file(WRITE ${GIT_VERSION_FILE} ${code_string})
|
||||||
endif()
|
endif()
|
||||||
|
endfunction()
|
||||||
|
Loading…
Reference in New Issue
Block a user