From 77e0d845087fb92b2ff45b4011daa77526f9816d Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 5 Nov 2008 20:53:05 -0500 Subject: [PATCH] Generate MOJOSHADER_VERSION, etc. --- .hgignore | 1 + CMakeLists.txt | 27 +++++++++++++++++++++++++++ mojoshader.c | 6 ++++++ mojoshader.h | 22 +++++++++++++++++++++- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/.hgignore b/.hgignore index c7cc941c..bc37aa21 100644 --- a/.hgignore +++ b/.hgignore @@ -1,4 +1,5 @@ syntax:glob +mojoshader_version.h CMakeCache.txt CMakeFiles Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a9bc352..1aa0fe33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,33 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.4) PROJECT(MojoShader) +EXECUTE_PROCESS( + COMMAND hg tip --template {rev} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE HGVERSION_RC + OUTPUT_VARIABLE MOJOSHADER_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE +) +EXECUTE_PROCESS( + COMMAND hg tip --template hg-{rev}:{node|short} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE HGVERSION_RC + OUTPUT_VARIABLE MOJOSHADER_CHANGESET + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +WRITE_FILE( + "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_version.h" + "/* This file was autogenerated. Do not edit! */\n" + "#ifndef _INCL_MOJOSHADER_VERSION_H_\n" + "#define _INCL_MOJOSHADER_VERSION_H_\n" + "#define MOJOSHADER_VERSION ${MOJOSHADER_VERSION}\n" + "#define MOJOSHADER_CHANGESET \"${MOJOSHADER_CHANGESET}\"\n" + "#endif\n" +) + IF(CMAKE_COMPILER_IS_GNUCC) ADD_DEFINITIONS(-Wall -ggdb3) ENDIF(CMAKE_COMPILER_IS_GNUCC) diff --git a/mojoshader.c b/mojoshader.c index 0136fc8f..88e275c3 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -7702,5 +7702,11 @@ int MOJOSHADER_version(void) return MOJOSHADER_VERSION; } // MOJOSHADER_version + +const char *MOJOSHADER_changeset(void) +{ + return MOJOSHADER_CHANGESET; +} // MOJOSHADER_changeset + // end of mojoshader.c ... diff --git a/mojoshader.h b/mojoshader.h index bb437985..f8506c6c 100644 --- a/mojoshader.h +++ b/mojoshader.h @@ -14,6 +14,14 @@ extern "C" { #endif +/* You can define this if you aren't generating mojoshader_version.h */ +#ifndef MOJOSHADER_NO_VERSION_INCLUDE +#include "mojoshader_version.h" +#else +#define MOJOSHADER_VERSION -1 +#define MOJOSHADER_CHANGESET "???" +#endif + /* * For determining the version of MojoShader you are using: * const int compiled_against = MOJOSHADER_VERSION; @@ -21,9 +29,21 @@ extern "C" { * * The version is a single integer that increments, not a major/minor value. */ -#define MOJOSHADER_VERSION 1 int MOJOSHADER_version(void); +/* + * For determining the revision control changeste of MojoShader you are using: + * const const *compiled_against = MOJOSHADER_CHANGESET; + * const char *linked_against = MOJOSHADER_changeset(); + * + * The version is an arbitrary, null-terminated ASCII string. It is probably + * a hash that represents a revision control changeset, and can't be + * compared to any other string to determine chronology. + * + * Do not attempt to free this string; it's statically allocated. + */ +const char *MOJOSHADER_changeset(void); + /* * These allocators work just like the C runtime's malloc() and free() * (in fact, they probably use malloc() and free() internally if you don't