summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-01-23 14:23:18 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-01-23 14:23:18 -0800
commit6002fdbc030bb1c93f100d2b6a4df5cefec963f1 (patch)
tree8d7e92ec0504cc13b327d076de91bce916559ece
parent96a4e04522584aab4ea1fe444f971bec935abc8a (diff)
parent8a5b76740102dad3d7f1be154af1910174c973f0 (diff)
Merge pull request #296 from nwellnhof/version_info
Improve version information
-rw-r--r--CMakeLists.txt4
-rw-r--r--api_test/main.c9
-rw-r--r--man/man3/cmark.351
-rw-r--r--src/CMakeLists.txt15
-rw-r--r--src/cmark.c3
-rw-r--r--src/cmark.h29
-rw-r--r--src/cmark_version.h.in7
-rw-r--r--src/main.c2
8 files changed, 96 insertions, 24 deletions
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/api_test/main.c b/api_test/main.c
index af40a9f..d341246 100644
--- a/api_test/main.c
+++ b/api_test/main.c
@@ -53,6 +53,14 @@ static void
test_continuation_byte(test_batch_runner *runner, const char *utf8);
static void
+version(test_batch_runner *runner)
+{
+ INT_EQ(runner, cmark_version, CMARK_VERSION, "cmark_version");
+ STR_EQ(runner, cmark_version_string, CMARK_VERSION_STRING,
+ "cmark_version_string");
+}
+
+static void
constructor(test_batch_runner *runner)
{
for (int i = 0; i < num_node_types; ++i) {
@@ -666,6 +674,7 @@ int main() {
int retval;
test_batch_runner *runner = test_batch_runner_new();
+ version(runner);
constructor(runner);
accessors(runner);
node_check(runner);
diff --git a/man/man3/cmark.3 b/man/man3/cmark.3
index f889521..4b24391 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
@@ -10,18 +10,6 @@ DESCRIPTION
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[])
.PP
@@ -532,6 +520,43 @@ 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
+extern const int cmark_version;
+.RE
+\f[]
+.fi
+
+.PP
+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
+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
+extern const char cmark_version_string[];
+.RE
+\f[]
+.fi
+
+.PP
+The library version string for runtime checks. Also available as
+macro CMARK_VERSION_STRING for compile time checks.
+
.SH
AUTHORS
.PP
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 254c065..033a9be 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
@@ -73,8 +76,11 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif ()
add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES})
-set_target_properties(${LIBRARY}
- PROPERTIES OUTPUT_NAME "cmark")
+# Include minor version in soname as long as major version is 0.
+set_target_properties(${LIBRARY} PROPERTIES
+ OUTPUT_NAME "cmark"
+ SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
+ VERSION ${PROJECT_VERSION})
set_property(TARGET ${LIBRARY}
APPEND PROPERTY MACOSX_RPATH true)
@@ -92,7 +98,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.c b/src/cmark.c
index 1d7a500..2ec9be9 100644
--- a/src/cmark.c
+++ b/src/cmark.c
@@ -6,6 +6,9 @@
#include "cmark.h"
#include "buffer.h"
+const int cmark_version = CMARK_VERSION;
+const char cmark_version_string[] = CMARK_VERSION_STRING;
+
char *cmark_markdown_to_html(const char *text, int len)
{
cmark_node *doc;
diff --git a/src/cmark.h b/src/cmark.h
index 8177fa8..9f312bc 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -2,7 +2,8 @@
#define CMARK_H
#include <stdio.h>
-#include "cmark_export.h"
+#include <cmark_export.h>
+#include <cmark_version.h>
#ifdef __cplusplus
extern "C" {
@@ -18,10 +19,6 @@ extern "C" {
* ## Simple Interface
*/
-/** Current version of library.
- */
-#define CMARK_VERSION "0.1"
-
/** Convert 'text' (assumed to be a UTF-8 encoded string with length
* 'len' from CommonMark Markdown to HTML, returning a null-terminated,
* UTF-8-encoded string.
@@ -499,6 +496,28 @@ char *cmark_render_man(cmark_node *root, long options);
*/
#define CMARK_OPT_NORMALIZE 4
+/**
+ * ## Version information
+ */
+
+/** 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.
+ * * Bits 0-7 contain the patchlevel.
+ *
+ * In hexadecimal format, the number 0x010203 represents version 1.2.3.
+ */
+CMARK_EXPORT
+extern const int cmark_version;
+
+/** 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[];
+
/** # AUTHORS
*
* John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer.
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
diff --git a/src/main.c b/src/main.c
index 5855868..ef40a88 100644
--- a/src/main.c
+++ b/src/main.c
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--version") == 0) {
- printf("cmark %s", CMARK_VERSION);
+ printf("cmark %s", CMARK_VERSION_STRING);
printf(" - CommonMark converter (c) 2014 John MacFarlane\n");
exit(0);
} else if (strcmp(argv[i], "--sourcepos") == 0) {