From 3248801a925449644071671dcd85e370303071b4 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Fri, 23 Jan 2015 17:04:14 +0100 Subject: Improve version information Add version number and string as macros and symbols. Version numbers can be easily compared, for example in the C preprocessor: #include #if CMARK_VERSION < 0x020200 #error Requires libcmark 2.2.0 or higher #endif Storing the version in a global variable allows to check the library version at runtime. For example: if (CMARK_VERSION != cmark_version) { warn("Compiled against libcmark %s, but using %s", CMARK_VERSION_STRING, cmark_version_string); } The version should be updated whenever the public API is changed. --- man/man3/cmark.3 | 74 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 13 deletions(-) (limited to 'man/man3/cmark.3') diff --git a/man/man3/cmark.3 b/man/man3/cmark.3 index f889521..f03a3ae 100644 --- a/man/man3/cmark.3 +++ b/man/man3/cmark.3 @@ -1,4 +1,4 @@ -.TH cmark 3 "January 20, 2015" "LOCAL" "Library Functions Manual" +.TH cmark 3 "January 23, 2015" "LOCAL" "Library Functions Manual" .SH NAME .PP @@ -9,18 +9,6 @@ DESCRIPTION .SS Simple Interface -.PP -.nf -\fC -.RS 0n -#define CMARK_VERSION "0.1" -.RE -\f[] -.fi - -.PP -Current version of library. - .PP \fIchar *\f[] \fBcmark_markdown_to_html\f[](\fIconst char *text\f[], \fIint len\f[]) @@ -532,6 +520,66 @@ Render \f[C]softbreak\f[] elements as hard line breaks. .PP Normalize tree by consolidating adjacent text nodes. +.SS +Version information + +.PP +.nf +\fC +.RS 0n +#define CMARK_VERSION 0x000100 +.RE +\f[] +.fi + +.PP +Macro containing the library version as integer for compile time +checks. +.IP \[bu] 2 +Bits 16\-23 contain the major version. +.IP \[bu] 2 +Bits 8\-15 contain the minor version. +.IP \[bu] 2 +Bits 0\-7 contain the patchlevel. +.PP +In hexadecimal format, the number 0x010203 represents version 1.2.3. + +.PP +.nf +\fC +.RS 0n +#define CMARK_VERSION_STRING "0.1.0" +.RE +\f[] +.fi + +.PP +Macro containing the library version string for compile time checks. + +.PP +.nf +\fC +.RS 0n +extern const int cmark_version; +.RE +\f[] +.fi + +.PP +The library version as integer for runtime checks. + +.PP +.nf +\fC +.RS 0n +extern const char cmark_version_string[]; +.RE +\f[] +.fi + +.PP +The library version string for runtime checks. + .SH AUTHORS .PP -- cgit v1.2.3 From 3ed64d7568437e81a0746554af273faeaf2037b4 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Fri, 23 Jan 2015 21:26:49 +0100 Subject: Let cmake update version Add a new template cmark_version.h.in to generate cmark_version.h containing version information. --- CMakeLists.txt | 4 ++-- man/man3/cmark.3 | 33 +++++---------------------------- src/CMakeLists.txt | 8 +++++++- src/cmark.h | 18 ++++++------------ src/cmark_version.h.in | 7 +++++++ 5 files changed, 27 insertions(+), 43 deletions(-) create mode 100644 src/cmark_version.h.in (limited to 'man/man3/cmark.3') diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bf4cd6..a6caee6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,8 @@ endif() set(PROJECT_NAME "cmark") set(PROJECT_VERSION_MAJOR 0) -set(PROJECT_VERSION_MINOR 0) -set(PROJECT_VERSION_PATCH 1) +set(PROJECT_VERSION_MINOR 1) +set(PROJECT_VERSION_PATCH 0) set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} ) add_subdirectory(src) diff --git a/man/man3/cmark.3 b/man/man3/cmark.3 index f03a3ae..4b24391 100644 --- a/man/man3/cmark.3 +++ b/man/man3/cmark.3 @@ -527,14 +527,14 @@ Version information .nf \fC .RS 0n -#define CMARK_VERSION 0x000100 +extern const int cmark_version; .RE \f[] .fi .PP -Macro containing the library version as integer for compile time -checks. +The library version as integer for runtime checks. Also available as +macro CMARK_VERSION for compile time checks. .IP \[bu] 2 Bits 16\-23 contain the major version. .IP \[bu] 2 @@ -544,30 +544,6 @@ Bits 0\-7 contain the patchlevel. .PP In hexadecimal format, the number 0x010203 represents version 1.2.3. -.PP -.nf -\fC -.RS 0n -#define CMARK_VERSION_STRING "0.1.0" -.RE -\f[] -.fi - -.PP -Macro containing the library version string for compile time checks. - -.PP -.nf -\fC -.RS 0n -extern const int cmark_version; -.RE -\f[] -.fi - -.PP -The library version as integer for runtime checks. - .PP .nf \fC @@ -578,7 +554,8 @@ extern const char cmark_version_string[]; .fi .PP -The library version string for runtime checks. +The library version string for runtime checks. Also available as +macro CMARK_VERSION_STRING for compile time checks. .SH AUTHORS diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 254c065..a76ad0a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,6 +47,9 @@ set(PROGRAM_SOURCES include_directories(. ${CMAKE_CURRENT_BINARY_DIR}) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmark_version.h.in + ${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @@ -92,7 +95,10 @@ install(TARGETS ${PROGRAM} ${LIBRARY} LIBRARY DESTINATION lib ) -install(FILES cmark.h ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h +install(FILES + cmark.h + ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h + ${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h DESTINATION include ) diff --git a/src/cmark.h b/src/cmark.h index faa5150..9f312bc 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -2,7 +2,8 @@ #define CMARK_H #include -#include "cmark_export.h" +#include +#include #ifdef __cplusplus extern "C" { @@ -499,8 +500,8 @@ char *cmark_render_man(cmark_node *root, long options); * ## Version information */ -/** Macro containing the library version as integer for compile time - * checks. +/** The library version as integer for runtime checks. Also available as + * macro CMARK_VERSION for compile time checks. * * * Bits 16-23 contain the major version. * * Bits 8-15 contain the minor version. @@ -508,18 +509,11 @@ char *cmark_render_man(cmark_node *root, long options); * * In hexadecimal format, the number 0x010203 represents version 1.2.3. */ -#define CMARK_VERSION 0x000100 - -/** Macro containing the library version string for compile time checks. - */ -#define CMARK_VERSION_STRING "0.1.0" - -/** The library version as integer for runtime checks. - */ CMARK_EXPORT extern const int cmark_version; -/** The library version string for runtime checks. +/** The library version string for runtime checks. Also available as + * macro CMARK_VERSION_STRING for compile time checks. */ CMARK_EXPORT extern const char cmark_version_string[]; diff --git a/src/cmark_version.h.in b/src/cmark_version.h.in new file mode 100644 index 0000000..41de3ac --- /dev/null +++ b/src/cmark_version.h.in @@ -0,0 +1,7 @@ +#ifndef CMARK_VERSION_H +#define CMARK_VERSION_H + +#define CMARK_VERSION ((@PROJECT_VERSION_MAJOR@ << 16) | (@PROJECT_VERSION_MINOR@ << 8) | @PROJECT_VERSION_PATCH@) +#define CMARK_VERSION_STRING "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@" + +#endif -- cgit v1.2.3