Whoops, the last one was based on libftdi-1.0...

Here the patch again, for discussion!

In some other project (qt-based), I used the guess-rev.sh script of
openocd to provide the git-hash during compile-time as a #define. But I
don't know how to achieve this with cmake...

See these two links for a quick idea: 

http://stackoverflow.com/questions/1537402/retrieve-revision-number-in-vs-with-qmake/3180413#3180413

http://gitorious.org/openocd/openocd/blobs/master/guess-rev.sh

Greetings
        Martin Zenzes

Am Mittwoch, den 07.07.2010, 17:35 +0200 schrieb Thomas Jarosch:
> On Wednesday, 7. July 2010 16:52:06 Uwe Bonnes wrote:
> > Any thought about Martin Zenzes proposal to have an API to query the
> > version. It would be good if applications could query the version to
> > decide if the old or new behaviour of ftdi_read_data() is available.
> 
> Thanks for reminding me. The patch doesn't apply.
> 
> Martin, can you rebase your changes against the current git tree?
> Please without the "baudrate = actual_baudrate" part...
> 
> Thomas
> 
> --
> libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
> To unsubscribe send a mail to [email protected]   



--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [email protected]   
>From 7443ea13855cdad4a9058700215961b197e01744 Mon Sep 17 00:00:00 2001
From: Martin Zenzes (spacelab1-u) <[email protected]>
Date: Thu, 1 Jul 2010 12:25:08 +0200
Subject: [PATCH 1/2] 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) <[email protected]>
---
 .gitignore       |    1 +
 CMakeLists.txt   |    6 ++++++
 src/ftdi.c       |   16 +++++++++++++++-
 src/ftdi.h       |    2 ++
 versioninfo.h.in |    7 +++++++
 5 files changed, 31 insertions(+), 1 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..98be926 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -34,6 +34,7 @@
 #include <stdio.h>
 
 #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.
@@ -1121,7 +1135,7 @@ int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate)
                         index, NULL, 0, ftdi->usb_write_timeout) != 0)
         ftdi_error_return (-2, "Setting new baudrate failed");
 
-    ftdi->baudrate = baudrate;
+    ftdi->baudrate = actual_baudrate;
     return 0;
 }
 
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

Reply via email to