Added cmake config file
authorMichel Zou <xantares09@hotmail.com>
Mon, 21 Jan 2013 14:47:22 +0000 (15:47 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 23 Jan 2013 09:09:18 +0000 (10:09 +0100)
CMakeLists.txt
LibFTDIConfig.cmake.in [new file with mode: 0644]
UseLibFTDI.cmake [new file with mode: 0644]
bindings/CMakeLists.txt
examples/cmake_example/CMakeLists.txt [new file with mode: 0644]
examples/cmake_example/main.c [new file with mode: 0644]

index 4e14961..445a38e 100644 (file)
@@ -163,9 +163,27 @@ configure_file(${CMAKE_SOURCE_DIR}/libftdipp1.pc.in ${CMAKE_BINARY_DIR}/libftdip
 install(FILES ${CMAKE_BINARY_DIR}/libftdi1.pc ${CMAKE_BINARY_DIR}/libftdipp1.pc
         DESTINATION lib${LIB_SUFFIX}/pkgconfig)
 
-if(${UNIX})
-    configure_file(${CMAKE_SOURCE_DIR}/libftdi1-config.in ${CMAKE_BINARY_DIR}/libftdi1-config @ONLY)
-    install(PROGRAMS ${CMAKE_BINARY_DIR}/libftdi1-config DESTINATION bin)
-endif(${UNIX})
+if ( UNIX )
+  configure_file ( libftdi1-config.in ${CMAKE_CURRENT_BINARY_DIR}/libftdi1-config @ONLY )
+  install ( PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libftdi1-config
+            DESTINATION bin )
+
+  get_target_property( _LIBFTDI_LIBRARY_LOCATION ftdi1 LOCATION )
+  get_filename_component ( _LIBFTDI_LIBRARY_NAME ${_LIBFTDI_LIBRARY_LOCATION} NAME )
+  set ( LIBFTDI_INCLUDE_DIR ${includedir} )
+  set ( LIBFTDI_INCLUDE_DIRS ${LIBFTDI_INCLUDE_DIR} )
+  set ( LIBFTDI_LIBRARY ${libdir}/${_LIBFTDI_LIBRARY_NAME} )
+  set ( LIBFTDI_LIBRARIES ${LIBFTDI_LIBRARY} )
+  list ( APPEND LIBFTDI_LIBRARIES ${LIBUSB_LIBRARIES} )
+  set ( LIBFTDI_ROOT_DIR ${prefix} )
+  set ( LIBFTDI_VERSION_STRING ${VERSION_STRING} )
+  set ( LIBFTDI_VERSION_MAJOR ${MAJOR_VERSION} )
+  set ( LIBFTDI_VERSION_MINOR ${MINOR_VERSION} )
+  set ( LIBFTDI_USE_FILE ${CMAKE_INSTALL_PREFIX}/lib/cmake/libftdi/UseLibFTDI.cmake )
+  configure_file ( LibFTDIConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/LibFTDIConfig.cmake @ONLY )
+  install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/LibFTDIConfig.cmake UseLibFTDI.cmake
+            DESTINATION lib/cmake/libftdi
+          )
+endif ()
 
 include(CPack)
diff --git a/LibFTDIConfig.cmake.in b/LibFTDIConfig.cmake.in
new file mode 100644 (file)
index 0000000..428518b
--- /dev/null
@@ -0,0 +1,47 @@
+#                                               -*- cmake -*-
+#
+#  LibFTDIConfig.cmake(.in)
+#
+#  Copyright (C) 2013 Intra2net AG and the libftdi developers
+#
+#  This file is part of LibFTDI.
+#
+#  LibFTDI is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU Lesser General Public License
+#  version 2.1 as published by the Free Software Foundation;
+#
+
+# Use the following variables to compile and link against LibFTDI:
+#  LIBFTDI_FOUND              - True if LibFTDI was found on your system
+#  LIBFTDI_USE_FILE           - The file making LibFTDI usable
+#  LIBFTDI_DEFINITIONS        - Definitions needed to build with LibFTDI
+#  LIBFTDI_INCLUDE_DIRS       - Directory where OT.hxx can be found
+#  LIBFTDI_INCLUDE_DIRS       - List of directories of LibFTDI and it's dependencies
+#  LIBFTDI_LIBRARY            - LibFTDI library location
+#  LIBFTDI_LIBRARIES          - List of libraries to link against
+#  LIBFTDI_LIBRARY_DIRS       - List of directories containing LibFTDI' libraries
+#  LIBFTDI_ROOT_DIR           - The base directory of LibFTDI
+#  LIBFTDI_VERSION_STRING     - A human-readable string containing the version
+#  LIBFTDI_VERSION_MAJOR      - The major version of LibFTDI
+#  LIBFTDI_VERSION_MINOR      - The minor version of LibFTDI
+#  LIBFTDI_VERSION_PATCH      - The patch version of LibFTDI
+#  LIBFTDI_PYTHON_MODULE_PATH - Path to the python module
+
+set ( LIBFTDI_FOUND 1 )
+set ( LIBFTDI_USE_FILE     "@LIBFTDI_USE_FILE@" )
+
+set ( LIBFTDI_DEFINITIONS  "@LIBFTDI_DEFINITIONS@" )
+set ( LIBFTDI_INCLUDE_DIR  "@LIBFTDI_INCLUDE_DIR@" )
+set ( LIBFTDI_INCLUDE_DIRS "@LIBFTDI_INCLUDE_DIRS@" )
+set ( LIBFTDI_LIBRARY      "@LIBFTDI_LIBRARY@" )
+set ( LIBFTDI_LIBRARIES    "@LIBFTDI_LIBRARIES@" )
+set ( LIBFTDI_LIBRARY_DIRS "@LIBFTDI_LIBRARY_DIRS@" )
+set ( LIBFTDI_ROOT_DIR     "@LIBFTDI_ROOT_DIR@" )
+
+set ( LIBFTDI_VERSION_STRING "@LIBFTDI_VERSION_STRING@" )
+set ( LIBFTDI_VERSION_MAJOR  "@LIBFTDI_VERSION_MAJOR@" )
+set ( LIBFTDI_VERSION_MINOR  "@LIBFTDI_VERSION_MINOR@" )
+set ( LIBFTDI_VERSION_PATCH  "@LIBFTDI_VERSION_PATCH@" )
+
+set ( LIBFTDI_PYTHON_MODULE_PATH "@LIBFTDI_PYTHON_MODULE_PATH@" )
+
diff --git a/UseLibFTDI.cmake b/UseLibFTDI.cmake
new file mode 100644 (file)
index 0000000..e7e43b0
--- /dev/null
@@ -0,0 +1,18 @@
+#                                               -*- cmake -*-
+#
+#  UseLibFTDI.cmake
+#
+#  Copyright (C) 2013 Intra2net AG and the libftdi developers
+#
+#  This file is part of LibFTDI.
+#
+#  LibFTDI is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU Lesser General Public License
+#  version 2.1 as published by the Free Software Foundation;
+#
+
+
+add_definitions     ( ${LIBFTDI_DEFINITIONS} )
+include_directories ( ${LIBFTDI_INCLUDE_DIRS} )
+link_directories    ( ${LIBFTDI_LIBRARY_DIRS} )
+
index f177425..34de42d 100644 (file)
@@ -54,7 +54,8 @@ if(PYTHON_BINDINGS AND SWIG_FOUND AND PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND)
 
 
     
-    message(STATUS "Building python bindings via swig. Will be installed under ${CMAKE_INSTALL_PREFIX}/${SITEPACKAGE}")
+  set ( LIBFTDI_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/${SITEPACKAGE} PARENT_SCOPE )  
+  message(STATUS "Building python bindings via swig. Will be installed under ${LIBFTDI_PYTHON_MODULE_PATH}")
 else(PYTHON_BINDINGS AND SWIG_FOUND AND PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND)
     message(STATUS "Not building python bindings")
 endif(PYTHON_BINDINGS AND SWIG_FOUND AND PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND)
diff --git a/examples/cmake_example/CMakeLists.txt b/examples/cmake_example/CMakeLists.txt
new file mode 100644 (file)
index 0000000..44bad3a
--- /dev/null
@@ -0,0 +1,13 @@
+cmake_minimum_required ( VERSION 2.8 )
+
+project ( example C )
+
+find_package ( LibFTDI NO_MODULE REQUIRED )
+include ( ${LIBFTDI_USE_FILE} )
+
+add_executable ( example main.c )
+target_link_libraries( example ${LIBFTDI_LIBRARIES} )
+
+install ( TARGETS example
+          DESTINATION bin )
+          
\ No newline at end of file
diff --git a/examples/cmake_example/main.c b/examples/cmake_example/main.c
new file mode 100644 (file)
index 0000000..93b3a79
--- /dev/null
@@ -0,0 +1,24 @@
+/* main.c
+
+   Example for ftdi_new()
+
+   This program is distributed under the GPL, version 2
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ftdi.h>
+
+int main(void)
+{
+  struct ftdi_context *ftdi;
+  int retval = EXIT_SUCCESS;
+
+  if ((ftdi = ftdi_new()) == 0)
+  {
+    fprintf(stderr, "ftdi_new failed\n");
+    return EXIT_FAILURE;
+  }
+  
+  return retval;
+}