>From bd7e89b752723108e5427c629f55d5b04ce3b0bd Mon Sep 17 00:00:00 2001 From: Martin Zenzes (spacelab1-u) Date: Thu, 1 Jul 2010 12:25:08 +0200 Subject: [PATCH] added function-call to access version information 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) 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... - Nicer would be to provide the git-hash of the current source, like openocd does. Doing this, the information is more precise. Signed-off-by: Martin Zenzes (spacelab1-u) --- .gitignore | 1 + CMakeLists.txt | 6 ++++++ src/ftdi.c | 14 ++++++++++++++ src/ftdi.h | 2 ++ versioninfo.h.in | 7 +++++++ 5 files changed, 30 insertions(+), 0 deletions(-) create mode 100644 versioninfo.h.in diff --git a/.gitignore b/.gitignore index d42100b..bce7cee 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,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..a0b21c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,12 @@ 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 2db8d32..5318ddb 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 @@ -50,6 +51,19 @@ return code; \ } while(0); +/** + 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 + + \retval none +*/ +void ftdi_library_version(int *major, int *minor){ + major = MAJOR_VERSION; + minor = MINOR_VERSION; +} /** Internal function to close usb device pointer. diff --git a/src/ftdi.h b/src/ftdi.h index 24a7f5b..ab9d56d 100644 --- a/src/ftdi.h +++ b/src/ftdi.h @@ -279,6 +279,8 @@ extern "C" { #endif + void ftdi_library_version(int *major, int *minor); + 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