Generate MOJOSHADER_VERSION, etc.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 05 Nov 2008 20:53:05 -0500
changeset 455 d99f47386d51
parent 454 70c9818840eb
child 456 39a9be44129d
Generate MOJOSHADER_VERSION, etc.
.hgignore
CMakeLists.txt
mojoshader.c
mojoshader.h
--- a/.hgignore	Wed Sep 24 07:27:26 2008 -0400
+++ b/.hgignore	Wed Nov 05 20:53:05 2008 -0500
@@ -1,4 +1,5 @@
 syntax:glob
+mojoshader_version.h
 CMakeCache.txt
 CMakeFiles
 Makefile
--- a/CMakeLists.txt	Wed Sep 24 07:27:26 2008 -0400
+++ b/CMakeLists.txt	Wed Nov 05 20:53:05 2008 -0500
@@ -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)
--- a/mojoshader.c	Wed Sep 24 07:27:26 2008 -0400
+++ b/mojoshader.c	Wed Nov 05 20:53:05 2008 -0500
@@ -7702,5 +7702,11 @@
     return MOJOSHADER_VERSION;
 } // MOJOSHADER_version
 
+
+const char *MOJOSHADER_changeset(void)
+{
+    return MOJOSHADER_CHANGESET;
+} // MOJOSHADER_changeset
+
 // end of mojoshader.c ...
 
--- a/mojoshader.h	Wed Sep 24 07:27:26 2008 -0400
+++ b/mojoshader.h	Wed Nov 05 20:53:05 2008 -0500
@@ -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,10 +29,22 @@
  *
  * 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
  *  specify your own allocator, but don't rely on that behaviour).