Hi,

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.

I added a second, trivial patch to git-ignore vim's temporary
swp-files...

Greetings
        Martin


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [email protected]   
>From bd7e89b752723108e5427c629f55d5b04ce3b0bd 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] 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       |   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 <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.
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

>From 5ea88e8501060f5eca7a36e11512c4f9a963af65 Mon Sep 17 00:00:00 2001
From: Martin Zenzes (spacelab1-u) <[email protected]>
Date: Thu, 1 Jul 2010 12:49:19 +0200
Subject: [PATCH 2/2] gitignore: temporary swp-files created by vim

nothing special here, just a plain .*.swp

Signed-off-by: Martin Zenzes (spacelab1-u) <[email protected]>
---
 .gitignore |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore
index bce7cee..cc38edc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,6 +55,7 @@ bindings/python/ftdi_wrap.c
 *.orig
 *.rej
 *~
+.*.swp
 
 # libftdi specific
 libftdi-config
-- 
1.7.0.4

Reply via email to