Add Git/timestamp --revision support.
This commit is contained in:
Родитель
2ece908e18
Коммит
0b9a884f3f
|
@ -49,6 +49,25 @@ set(spirv-compiler-options "")
|
|||
set(spirv-compiler-defines "")
|
||||
set(spirv-cross-link-flags "")
|
||||
|
||||
message(STATUS "Finding Git version for SPIRV-Cross.")
|
||||
set(spirv-cross-build-version "unknown")
|
||||
find_package(Git)
|
||||
if (GIT_FOUND)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE spirv-cross-build-version
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
message(STATUS "Git hash: ${spirv-cross-build-version}")
|
||||
else()
|
||||
message(STATUS "Git not found, using unknown build version.")
|
||||
endif()
|
||||
|
||||
string(TIMESTAMP spirv-cross-timestamp)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.in.h ${CMAKE_CURRENT_BINARY_DIR}/gitversion.h @ONLY)
|
||||
|
||||
if(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
|
||||
set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
|
||||
endif()
|
||||
|
@ -237,6 +256,8 @@ if (SPIRV_CROSS_STATIC)
|
|||
if (SPIRV_CROSS_ENABLE_C_API)
|
||||
spirv_cross_add_library(spirv-cross-c spirv_cross_c STATIC
|
||||
${spirv-cross-c-sources})
|
||||
target_include_directories(spirv-cross-c PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_compile_definitions(spirv-cross-c PRIVATE HAVE_SPIRV_CROSS_GIT_VERSION)
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
target_link_libraries(spirv-cross-c PRIVATE spirv-cross-glsl)
|
||||
|
@ -266,7 +287,7 @@ if (SPIRV_CROSS_STATIC)
|
|||
endif()
|
||||
|
||||
set(spirv-cross-abi-major 0)
|
||||
set(spirv-cross-abi-minor 9)
|
||||
set(spirv-cross-abi-minor 10)
|
||||
set(spirv-cross-abi-patch 0)
|
||||
|
||||
if (SPIRV_CROSS_SHARED)
|
||||
|
@ -282,6 +303,9 @@ if (SPIRV_CROSS_SHARED)
|
|||
${spirv-cross-core-sources}
|
||||
${spirv-cross-c-sources})
|
||||
|
||||
target_include_directories(spirv-cross-c-shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_compile_definitions(spirv-cross-c-shared PRIVATE HAVE_SPIRV_CROSS_GIT_VERSION)
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-glsl-sources})
|
||||
target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_GLSL=1)
|
||||
|
@ -368,7 +392,8 @@ if (SPIRV_CROSS_CLI)
|
|||
endif()
|
||||
add_executable(spirv-cross main.cpp)
|
||||
target_compile_options(spirv-cross PRIVATE ${spirv-compiler-options})
|
||||
target_compile_definitions(spirv-cross PRIVATE ${spirv-compiler-defines})
|
||||
target_include_directories(spirv-cross PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_compile_definitions(spirv-cross PRIVATE ${spirv-compiler-defines} HAVE_SPIRV_CROSS_GIT_VERSION)
|
||||
set_target_properties(spirv-cross PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
install(TARGETS spirv-cross RUNTIME DESTINATION bin)
|
||||
target_link_libraries(spirv-cross PRIVATE
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef SPIRV_CROSS_GIT_VERSION_H_
|
||||
#define SPIRV_CROSS_GIT_VERSION_H_
|
||||
|
||||
#define SPIRV_CROSS_GIT_REVISION "Git commit: @spirv-cross-build-version@ Timestamp: @spirv-cross-timestamp@"
|
||||
|
||||
#endif
|
20
main.cpp
20
main.cpp
|
@ -31,6 +31,10 @@
|
|||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#ifdef HAVE_SPIRV_CROSS_GIT_VERSION
|
||||
#include "gitversion.h"
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4996)
|
||||
#endif
|
||||
|
@ -545,8 +549,19 @@ struct CLIArguments
|
|||
bool combined_samplers_inherit_bindings = false;
|
||||
};
|
||||
|
||||
static void print_version()
|
||||
{
|
||||
#ifdef HAVE_SPIRV_CROSS_GIT_VERSION
|
||||
fprintf(stderr, "%s\n", SPIRV_CROSS_GIT_REVISION);
|
||||
#else
|
||||
fprintf(stderr, "Git revision unknown. Build with CMake to create timestamp and revision info.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void print_help()
|
||||
{
|
||||
print_version();
|
||||
|
||||
fprintf(stderr, "Usage: spirv-cross\n"
|
||||
"\t[--output <output path>]\n"
|
||||
"\t[SPIR-V file]\n"
|
||||
|
@ -555,6 +570,7 @@ static void print_help()
|
|||
"\t[--version <GLSL version>]\n"
|
||||
"\t[--dump-resources]\n"
|
||||
"\t[--help]\n"
|
||||
"\t[--revision]\n"
|
||||
"\t[--force-temporary]\n"
|
||||
"\t[--vulkan-semantics]\n"
|
||||
"\t[--flatten-ubo]\n"
|
||||
|
@ -1004,6 +1020,10 @@ static int main_inner(int argc, char *argv[])
|
|||
print_help();
|
||||
parser.end();
|
||||
});
|
||||
cbs.add("--revision", [](CLIParser &parser) {
|
||||
print_version();
|
||||
parser.end();
|
||||
});
|
||||
cbs.add("--output", [&args](CLIParser &parser) { args.output = parser.next_string(); });
|
||||
cbs.add("--es", [&args](CLIParser &) {
|
||||
args.es = true;
|
||||
|
|
|
@ -33,6 +33,11 @@
|
|||
#if SPIRV_CROSS_C_API_REFLECT
|
||||
#include "spirv_reflect.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SPIRV_CROSS_GIT_VERSION
|
||||
#include "gitversion.h"
|
||||
#endif
|
||||
|
||||
#include "spirv_parser.hpp"
|
||||
#include <memory>
|
||||
#include <new>
|
||||
|
@ -1902,6 +1907,15 @@ void spvc_get_version(unsigned *major, unsigned *minor, unsigned *patch)
|
|||
*patch = SPVC_C_API_VERSION_PATCH;
|
||||
}
|
||||
|
||||
const char *spvc_get_commit_revision_and_timestamp(void)
|
||||
{
|
||||
#ifdef HAVE_SPIRV_CROSS_GIT_VERSION
|
||||
return SPIRV_CROSS_GIT_REVISION;
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
|
|
@ -33,7 +33,7 @@ extern "C" {
|
|||
/* Bumped if ABI or API breaks backwards compatibility. */
|
||||
#define SPVC_C_API_VERSION_MAJOR 0
|
||||
/* Bumped if APIs or enumerations are added in a backwards compatible way. */
|
||||
#define SPVC_C_API_VERSION_MINOR 9
|
||||
#define SPVC_C_API_VERSION_MINOR 10
|
||||
/* Bumped if internal implementation details change. */
|
||||
#define SPVC_C_API_VERSION_PATCH 0
|
||||
|
||||
|
@ -58,6 +58,9 @@ extern "C" {
|
|||
*/
|
||||
SPVC_PUBLIC_API void spvc_get_version(unsigned *major, unsigned *minor, unsigned *patch);
|
||||
|
||||
/* Gets a human readable version string to identify which commit a particular binary was created from. */
|
||||
SPVC_PUBLIC_API const char *spvc_get_commit_revision_and_timestamp(void);
|
||||
|
||||
/* These types are opaque to the user. */
|
||||
typedef struct spvc_context_s *spvc_context;
|
||||
typedef struct spvc_parsed_ir_s *spvc_parsed_ir;
|
||||
|
|
|
@ -103,6 +103,8 @@ static void compile(spvc_compiler compiler, const char *tag)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *rev = NULL;
|
||||
|
||||
spvc_context context = NULL;
|
||||
spvc_parsed_ir ir = NULL;
|
||||
spvc_compiler compiler_glsl = NULL;
|
||||
|
@ -116,6 +118,12 @@ int main(int argc, char **argv)
|
|||
SpvId *buffer = NULL;
|
||||
size_t word_count = 0;
|
||||
|
||||
rev = spvc_get_commit_revision_and_timestamp();
|
||||
if (!rev || *rev == '\0')
|
||||
return 1;
|
||||
|
||||
printf("Revision: %s\n", rev);
|
||||
|
||||
if (argc != 5)
|
||||
return 1;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче