Skip to content

Instantly share code, notes, and snippets.

@coffeemakr
Last active August 29, 2015 14:07
Show Gist options
  • Save coffeemakr/4880b260b605633e0208 to your computer and use it in GitHub Desktop.
Save coffeemakr/4880b260b605633e0208 to your computer and use it in GitHub Desktop.
Version
#include "version.h"
#include <stdio.h>
/** \file version.cpp Version functions */
void writeVersion(char* prog, FILE* stream)
{
fprintf(stream, "%s Version "VERSION"\n", prog);
}
void writeFullVersion(char* prog, FILE* stream)
{
fprintf(stream, "%s Version "VERSION"\nCompiled with "COMPILER_STRING" version "COMPILER_VERSION_STRING"\n", prog);
}
/** \file version.h Versioning Makros and definitions */
#ifndef _VERSION_H_
#define _VERSION_H_
#include <stdio.h>
/** @defgroup versioning Versioning
*
* \brief Functions and Makros to control the software version.
*
* This functiosn are used to display version and compilation information.
*
* @{
*/
/// Project Version
#define VERSION "1.0.1.3"
/**
* Write project version to a stream
*
* @param prog Program name
* @param stream Stream to write into
*/
void writeFullVersion(char* prog, FILE* stream);
/**
* Write full version to a stream.
*
* This function write compiler name, compiler version and of course
* the programs version to a stream.
*
* @param prog Program name
* @param stream Stream to write into
*/
void writeVersion(char* prog, FILE* stream);
/** @} */
#ifndef DOXYGEN_IGNORE
#define __v_str_helper(x) #x
#define __v_str(x) __v_str_helper(x)
// detect compiler and get its version
#if defined(__clang__)
#define COMPILER_STRING "Clang/LLVM"
#define COMPILER_VERSION_STRING __VERSION__
#elif defined(__ICC) || defined(__INTEL_COMPILER)
#define COMPILER_STRING "ICC/ICPC"
#define COMPILER_VERSION_STRING __VERSION__
#elif defined(__GNUC__) || defined(__GNUG__)
#define COMPILER_STRING "GNU GCC/G++"
#define COMPILER_VERSION_STRING __VERSION__
#elif defined(__HP_cc) || defined(__HP_aCC)
#define COMPILER_STRING "Hewlett-Packard C/aC++"
#define COMPILER_VERSION_STRING __HP_aCC
#elif defined(__IBMC__) || defined(__IBMCPP__)
#define COMPILER_STRING "IBM XL C/C++"
#define COMPILER_VERSION_STRING __xlc__
#elif defined(_MSC_VER)
#define COMPILER_STRING "Microsoft Visual Studio"
#define COMPILER_VERSION_STRING __v_str(_MSC_FULL_VER)
#elif defined(__PGI)
#define COMPILER_STRING "Portland Group PGCC/PGCPP"
#define COMPILER_VERSION_STRING __v_str(__PGIC__)"."__v_str(__PGIC_MINOR)"."__v_str(__PGIC_PATCHLEVEL__)
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
#define COMPILER_STRING "Oracle Solaris Studio"
#define COMPILER_VERSION_STRING __v_str(__SUNPRO_C)
#endif
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment