add option to enable/disable udev support

This commit is contained in:
Gwenhael Goavec-Merou 2020-03-14 19:42:07 +01:00
parent 35b56887de
commit 8f2d6cb1c9
5 changed files with 45 additions and 3 deletions

View File

@ -5,6 +5,7 @@ cmake_minimum_required(VERSION 3.0)
project(openFPGALoader VERSION 0.1 LANGUAGES CXX) project(openFPGALoader VERSION 0.1 LANGUAGES CXX)
option(BUILD_STATIC "Whether or not to build with static libraries" OFF) option(BUILD_STATIC "Whether or not to build with static libraries" OFF)
option(ENABLE_UDEV "use udev to search JTAG adapter from /dev/xx" ON)
## specify the C++ standard ## specify the C++ standard
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
@ -23,7 +24,16 @@ add_definitions(-DDATA_DIR=\"${CMAKE_INSTALL_FULL_DATAROOTDIR}\")
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBFTDI REQUIRED libftdi1) pkg_check_modules(LIBFTDI REQUIRED libftdi1)
pkg_check_modules(LIBUSB REQUIRED libusb-1.0) pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
pkg_check_modules(LIBUDEV REQUIRED libudev)
if(ENABLE_UDEV)
pkg_check_modules(LIBUDEV libudev)
if (LIBUDEV_FOUND)
add_definitions(-DUSE_UDEV)
else()
message("libudev not found, disabling udev support and -d parameter")
set(ENABLE_UDEV OFF)
endif()
endif()
# for non glibc, argp-standalone is required and must be # for non glibc, argp-standalone is required and must be
# explicitly linked. This code will fail for others libc # explicitly linked. This code will fail for others libc
@ -92,17 +102,21 @@ add_executable(openFPGALoader
${OPENFPGALOADER_HEADERS} ${OPENFPGALOADER_HEADERS}
) )
include_directories(${LIBUDEV_INCLUDE_DIRS} include_directories(
${LIBUSB_INCLUDE_DIRS} ${LIBUSB_INCLUDE_DIRS}
${LIBFTDI_INCLUDE_DIRS} ${LIBFTDI_INCLUDE_DIRS}
) )
target_link_libraries(openFPGALoader target_link_libraries(openFPGALoader
${LIBUDEV_LIBRARIES}
${LIBUSB_LIBRARIES} ${LIBUSB_LIBRARIES}
${LIBFTDI_LIBRARIES} ${LIBFTDI_LIBRARIES}
) )
if(ENABLE_UDEV)
include_directories(${LIBUDEV_INCLUDE_DIRS})
target_link_libraries(openFPGALoader ${LIBUDEV_LIBRARIES})
endif()
if(NOT HAVE_ARGP) if(NOT HAVE_ARGP)
target_link_libraries(openFPGALoader /usr/lib/libargp.a) target_link_libraries(openFPGALoader /usr/lib/libargp.a)
endif() endif()

View File

@ -6,6 +6,7 @@
$ mkdir build $ mkdir build
$ cd build $ cd build
$ cmake ../ # add -DBUILD_STATIC=ON to build a static version $ cmake ../ # add -DBUILD_STATIC=ON to build a static version
# add -DENABLE_UDEV=OFF to disable udev support and -d /dev/xxx
$ cmake --build . $ cmake --build .
or or
$ make -j$(nproc) $ make -j$(nproc)

View File

@ -36,6 +36,12 @@ depending of the distribution, headers too)
```bash ```bash
apt-get install libftdi1-2 libftdi1-dev libudev-dev cmake apt-get install libftdi1-2 libftdi1-dev libudev-dev cmake
``` ```
**libudev-dev** is optional, may be replaced by **eudev-dev** or just not installed.
By default, **(e)udev** support is enabled (used to open a device by his */dev/xx*
node). If you don't want this option, use:
```-DENABLE_UDEV=OFF```
For distributions using non-glibc (musl, uClibc) **argp-standalone** must be For distributions using non-glibc (musl, uClibc) **argp-standalone** must be
installed. installed.
@ -47,6 +53,7 @@ To build the app:
$ mkdir build $ mkdir build
$ cd build $ cd build
$ cmake ../ # add -DBUILD_STATIC=ON to build a static version $ cmake ../ # add -DBUILD_STATIC=ON to build a static version
# add -DENABLE_UDEV=OFF to disable udev support and -d /dev/xxx
$ cmake --build . $ cmake --build .
or or
$ make -j$(nproc) $ make -j$(nproc)

View File

@ -7,7 +7,9 @@
#include <iostream> #include <iostream>
#ifdef USE_UDEV
#include <libudev.h> #include <libudev.h>
#endif
#include <libusb.h> #include <libusb.h>
#include "ftdipp_mpsse.hpp" #include "ftdipp_mpsse.hpp"
@ -346,6 +348,7 @@ int FTDIpp_MPSSE::mpsse_read(unsigned char *rx_buff, int len)
return num_read; return num_read;
} }
#ifdef USE_UDEV
unsigned int FTDIpp_MPSSE::udevstufftoint(const char *udevstring, int base) unsigned int FTDIpp_MPSSE::udevstufftoint(const char *udevstring, int base)
{ {
char *endp; char *endp;
@ -436,3 +439,16 @@ bool FTDIpp_MPSSE::search_with_dev(const string &device)
return true; return true;
} }
#else
unsigned int FTDIpp_MPSSE::udevstufftoint(const char *udevstring, int base)
{
(void)udevstring;
(void)base;
return 0;
}
bool FTDIpp_MPSSE::search_with_dev(const string &device)
{
(void)device;
return false;
}
#endif

View File

@ -67,7 +67,9 @@ static struct argp_option options[] = {
{"list-cables", LIST_CABLE, 0, 0, "list all supported cables"}, {"list-cables", LIST_CABLE, 0, 0, "list all supported cables"},
{"board", 'b', "BOARD", 0, "board name, may be used instead of cable"}, {"board", 'b', "BOARD", 0, "board name, may be used instead of cable"},
{"list-boards", LIST_BOARD, 0, 0, "list all supported boards"}, {"list-boards", LIST_BOARD, 0, 0, "list all supported boards"},
#ifdef USE_UDEV
{"device", 'd', "DEVICE", 0, "device to use (/dev/ttyUSBx)"}, {"device", 'd', "DEVICE", 0, "device to use (/dev/ttyUSBx)"},
#endif
{"list-fpga", LIST_FPGA, 0, 0, "list all supported FPGA"}, {"list-fpga", LIST_FPGA, 0, 0, "list all supported FPGA"},
{"detect", DETECT, 0, 0, "detect FPGA"}, {"detect", DETECT, 0, 0, "detect FPGA"},
{"write-flash", 'f', 0, 0, {"write-flash", 'f', 0, 0,
@ -215,9 +217,11 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 'r': case 'r':
arguments->reset = true; arguments->reset = true;
break; break;
#ifdef USE_UDEV
case 'd': case 'd':
arguments->device = arg; arguments->device = arg;
break; break;
#endif
case 'v': case 'v':
arguments->verbose = true; arguments->verbose = true;
break; break;