Add git-version.c generation to CMake.

This commit is contained in:
Unknown W. Brackets 2013-03-02 11:01:08 -08:00
parent 96a22063e3
commit 4694d4f1a3
2 changed files with 55 additions and 1 deletions

View File

@ -823,11 +823,23 @@ add_library(${CoreLibName} ${CoreLinkType}
Core/Util/ppge_atlas.cpp
Core/Util/ppge_atlas.h
$<TARGET_OBJECTS:GPU>
Globals.h)
Globals.h
git-version.c)
target_link_libraries(${CoreLibName} Common native kirk cityhash
${GLEW_LIBRARIES} ${OPENGL_LIBRARIES})
setup_target_project(${CoreLibName} Core)
# Generate git-version.c at build time.
add_custom_target(GitVersion ALL
DEPENDS something_that_never_exists)
add_custom_command(OUTPUT something_that_never_exists
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/git-version.cmake)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/git-version.c
PROPERTIES GENERATED TRUE)
add_dependencies(${CoreLibName} GitVersion)
add_library(GPU OBJECT
GPU/GLES/DisplayListInterpreter.cpp
GPU/GLES/DisplayListInterpreter.h

42
git-version.cmake Normal file
View File

@ -0,0 +1,42 @@
set(GIT_VERSION_FILE "${SOURCE_DIR}/git-version.c")
set(GIT_VERSION "unknown")
set(GIT_VERSION_UPDATE "1")
find_package(Git)
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --always
RESULT_VARIABLE exit_code
OUTPUT_VARIABLE GIT_VERSION)
if(NOT ${exit_code} EQUAL 0)
message(WARNING "git describe failed, unable to include version.")
endif()
string(STRIP ${GIT_VERSION} GIT_VERSION)
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 "PPSSPP_GIT_VERSION_NO_UPDATE = 1")
if(NOT $[match} EQUAL "")
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} EQUAL "")
set(GIT_VERSION_UPDATE "0")
endif()
endif()
set(code_string "// This is a generated file.\n\n"
"const char *PPSSPP_GIT_VERSION = \"${GIT_VERSION}\"\;\n\n"
"// If you don't want this file to update/recompile, change to 1.\n"
"#define PPSSPP_GIT_VERSION_NO_UPDATE 0\n")
message(WARNING "UPDATE: ${GIT_VERSION_FILE}")
if ("${GIT_VERSION_UPDATE}" EQUAL "1")
file(WRITE ${GIT_VERSION_FILE} ${code_string})
endif()