Generate a build ID from Git, to display in editor
This commit is contained in:
parent
8f33c90ffb
commit
80ae52a205
3 changed files with 58 additions and 1 deletions
|
|
@ -51,7 +51,9 @@ add_library(sfizz_editor STATIC EXCLUDE_FROM_ALL
|
|||
src/editor/NativeHelpers.cpp
|
||||
src/editor/layout/main.hpp
|
||||
src/editor/utility/vstgui_after.h
|
||||
src/editor/utility/vstgui_before.h)
|
||||
src/editor/utility/vstgui_before.h
|
||||
src/editor/GitBuildId.h
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/git-build-id/GitBuildId.c")
|
||||
add_library(sfizz::editor ALIAS sfizz_editor)
|
||||
target_include_directories(sfizz_editor PUBLIC "src")
|
||||
target_link_libraries(sfizz_editor PUBLIC sfizz::messaging sfizz::plugins-common)
|
||||
|
|
@ -106,3 +108,12 @@ if(NOT CMAKE_CROSSCOMPILING)
|
|||
> "${CMAKE_CURRENT_SOURCE_DIR}/src/editor/layout/main.hpp"
|
||||
DEPENDS layout-maker "${CMAKE_CURRENT_SOURCE_DIR}/layout/main.fl")
|
||||
endif()
|
||||
|
||||
# git build identifier
|
||||
add_custom_target(sfizz_editor_git_build_id
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
"-DSOURCE_DIR=${PROJECT_SOURCE_DIR}"
|
||||
"-DOUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/git-build-id/GitBuildId.c"
|
||||
"-P" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/GitBuildID.cmake"
|
||||
BYPRODUCTS "git-build-id/GitBuildId.c")
|
||||
add_dependencies(sfizz_editor sfizz_editor_git_build_id)
|
||||
|
|
|
|||
29
plugins/editor/cmake/GitBuildID.cmake
Normal file
29
plugins/editor/cmake/GitBuildID.cmake
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# Generate the Git Build ID information into a C source file
|
||||
# This does not overwrite the file if the contents are up-to-date.
|
||||
#
|
||||
# Arguments:
|
||||
# SOURCE_DIR The root directory of the project, expected to be a Git repo
|
||||
# OUTPUT_FILE The file which gets written
|
||||
|
||||
get_filename_component(OUTPUT_NAME "${OUTPUT_FILE}" NAME)
|
||||
get_filename_component(OUTPUT_DIR "${OUTPUT_FILE}" DIRECTORY)
|
||||
|
||||
message("(Git Build ID) Generating ${OUTPUT_NAME}")
|
||||
|
||||
find_package(Git QUIET)
|
||||
|
||||
file(MAKE_DIRECTORY "${OUTPUT_DIR}")
|
||||
|
||||
if(GIT_FOUND)
|
||||
execute_process(COMMAND "${GIT_EXECUTABLE}" "rev-parse" "--short" "HEAD"
|
||||
WORKING_DIRECTORY "${SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE GIT_COMMIT_ID
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
else()
|
||||
set(GIT_COMMIT_ID "")
|
||||
message("(Git Build ID) Error: could not find Git")
|
||||
endif()
|
||||
|
||||
file(WRITE "${OUTPUT_FILE}.temp" "const char* GitBuildId = \"${GIT_COMMIT_ID}\";\n")
|
||||
execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "copy_if_different" "${OUTPUT_FILE}.temp" "${OUTPUT_FILE}")
|
||||
file(REMOVE "${OUTPUT_FILE}.temp")
|
||||
17
plugins/editor/src/editor/GitBuildId.h
Normal file
17
plugins/editor/src/editor/GitBuildId.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
||||
// license. You should have receive a LICENSE.md file along with the code.
|
||||
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
|
||||
/**
|
||||
* @brief Short identifier of the current head commit.
|
||||
* This generated identifier is empty if the build is not from a Git repository.
|
||||
*/
|
||||
extern const char* GitBuildId;
|
||||
|
||||
} // extern "C"
|
||||
Loading…
Add table
Reference in a new issue