Hi Thomas,
> Here's a small list of things to talk about:
thanks for your input.
> - Rename ftdi_library_version() to ftdi_get_library_version()
done...
> - Maybe add a "char *snapshot_version" which can return NULL / empty string?
> See guess-rev.sh
done/TODO. Added "char snapshot_version[8]" (fix-sized array to prevent
possible memory-leaks, is just set completely to zero in the
moment...?). How to say cmake to invoke a shell-script at buildtime to
dynamically define #defines in the header file?
> - Provide autoconf support
TODO/drop?
> - Remove the "baudrate" change not supposed to be in there ;)
done...
> Regarding the third point, we could just apply this patch
> to libftdi 1.x and drop the autoconf support completly. So libftdi 0.x
> would be put in maintenance mode and only receive bug fixes.
I'm not in the position to decide something in this issue, but it seems
to me that supporting different build-methods is confusing and
error-prone to new users... At least it was to me ;)
Greetings
Martin
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [email protected] >From 288993e0b1fedeaea6dec34a8c01404b66fee1ba Mon Sep 17 00:00:00 2001
From: Martin Zenzes (spacelab1-u) <[email protected]>
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) <[email protected]>
added thomas vorschläge
Signed-off-by: Martin Zenzes (spacelab1-u) <[email protected]>
---
.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 <stdio.h>
#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