>From 288993e0b1fedeaea6dec34a8c01404b66fee1ba Mon Sep 17 00:00:00 2001 From: Martin Zenzes (spacelab1-u) Date: Thu, 8 Jul 2010 15:23:09 +0200 Subject: [PATCH] added function-call get version information MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I had some trouble with different versions of libftdi installed on the same system -- leading to confusion because i didn't notice the wrong version of the library was linked. I found no way to extract the versionnumber as a normal user. I modified the code to provide the minor and major version number to the user trough a normal functioncall. Therefore, I introduced a new headerfile, which is generated by cmake. Two preprocessor #defines MAJOR_VERSION and MINOR_VERSION are build from the ones provided in CMakeLists.txt. They can be accessed by a call to ftdi_library_version(int* major, int* minor, char[8] snapshot_version). An additional char-array is supplied, which may later be used to encode the exact revision of the git-repo at build time, but this is not implemented yet, only zeros are returned. A fix-sized array is used to prevent possible memory leaks. The technique used to provide version information is taken from online-tutorial, see http://www.cmake.org/cmake/help/cmake_tutorial.html I'm sure, my solution is far from perfect, but it works for me. Sending the patch to provide some input for a discussion about how to implement his properly. See the patch for more details, its not very complicated. There are currently two TODOs: - I only use cmake, but there are people using autotools, I suppose... - add shell script which should be invoked from make at build time and defines a #define to be feed into this function as a return-array Signed-off-by: Martin Zenzes (spacelab1-u) added thomas vorschläge Signed-off-by: Martin Zenzes (spacelab1-u) --- .gitignore | 1 + CMakeLists.txt | 5 +++++ src/ftdi.c | 17 +++++++++++++++++ src/ftdi.h | 2 ++ versioninfo.h.in | 7 +++++++ 5 files changed, 32 insertions(+), 0 deletions(-) create mode 100644 versioninfo.h.in diff --git a/.gitignore b/.gitignore index 0426964..cc38edc 100644 --- a/.gitignore +++ b/.gitignore @@ -60,6 +60,7 @@ bindings/python/ftdi_wrap.c # libftdi specific libftdi-config libftdi.spec +src/versioninfo.h # CMake CMakeCache.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 8197615..f959a37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,11 @@ set(MINOR_VERSION 18) set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}) SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}") +configure_file ( + "versioninfo.h.in" + "${CMAKE_SOURCE_DIR}/src/versioninfo.h" + ) + # CMake if("${CMAKE_BUILD_TYPE}" STREQUAL "") set(CMAKE_BUILD_TYPE Debug) diff --git a/src/ftdi.c b/src/ftdi.c index bbbeb9a..988dadf 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -34,6 +34,7 @@ #include #include "ftdi.h" +#include "versioninfo.h" /* stuff needed for async write */ #ifdef LIBFTDI_LINUX_ASYNC_MODE @@ -84,6 +85,22 @@ int gettimeofday( struct timeval *tv, void null) #endif /** + Get some status informatio about currently used library-version. + \todo Access somehow the current git-hash + + \param major Major-versionnumber of current build + \param minor Minor-versionnumber of current build + \param snapshot_version char-array which may contain the revision of the actual repository. not implemented yet... + + \retval none +*/ +void ftdi_get_library_version(int *major, int *minor, char snapshot_version[8]){ + *major = MAJOR_VERSION; + *minor = MINOR_VERSION; + memset(&snapshot_version,0,8); +} + +/** Internal function to close usb device pointer. Sets ftdi->usb_dev to NULL. \internal diff --git a/src/ftdi.h b/src/ftdi.h index 24a7f5b..cb4a0ac 100644 --- a/src/ftdi.h +++ b/src/ftdi.h @@ -279,6 +279,8 @@ extern "C" { #endif + void ftdi_get_library_version(int *major, int *minor, char snapshot_version[8]); + int ftdi_init(struct ftdi_context *ftdi); struct ftdi_context *ftdi_new(void); int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface interface); diff --git a/versioninfo.h.in b/versioninfo.h.in new file mode 100644 index 0000000..8ec4bdd --- /dev/null +++ b/versioninfo.h.in @@ -0,0 +1,7 @@ +#ifndef _VERSIONINFO_H_ +#define _VERSIONINFO_H_ + +#define MAJOR_VERSION @MAJOR_VERSION@ +#define MINOR_VERSION @MINOR_VERSION@ + +#endif // _VERSIONINFO_H_ -- 1.7.0.4