add some options to CMakeLists.txt to enable build against custom libs (including option to use find_package for threads to ensure correct link order with pthreads)
This commit is contained in:
parent
d24c63ec8a
commit
4bdf8a0dd5
|
|
@ -6,32 +6,36 @@ 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)
|
option(ENABLE_UDEV "use udev to search JTAG adapter from /dev/xx" ON)
|
||||||
|
option(USE_PKGCONFIG "Use pkgconfig to find libraries" ON)
|
||||||
|
option(LINK_CMAKE_THREADS "Use CMake find_package to link the threading library" OFF)
|
||||||
|
|
||||||
## specify the C++ standard
|
## specify the C++ standard
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wextra")
|
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wextra ${CMAKE_CXX_FLAGS_DEBUG}")
|
||||||
|
|
||||||
if (BUILD_STATIC)
|
if (BUILD_STATIC)
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "-static-libstdc++ -static")
|
set(CMAKE_EXE_LINKER_FLAGS "-static-libstdc++ -static ${CMAKE_EXE_LINKER_FLAGS}")
|
||||||
set(BUILD_SHARED_LIBS OFF)
|
set(BUILD_SHARED_LIBS OFF)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
# By default: DATA_DIR="/usr/local/share"
|
# By default: DATA_DIR="/usr/local/share"
|
||||||
add_definitions(-DDATA_DIR=\"${CMAKE_INSTALL_FULL_DATAROOTDIR}\")
|
add_definitions(-DDATA_DIR=\"${CMAKE_INSTALL_FULL_DATAROOTDIR}\")
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
if(USE_PKGCONFIG)
|
||||||
pkg_check_modules(LIBFTDI REQUIRED libftdi1)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
|
pkg_check_modules(LIBFTDI REQUIRED libftdi1)
|
||||||
|
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
|
||||||
|
|
||||||
if(ENABLE_UDEV)
|
if(ENABLE_UDEV)
|
||||||
pkg_check_modules(LIBUDEV libudev)
|
pkg_check_modules(LIBUDEV libudev)
|
||||||
if (LIBUDEV_FOUND)
|
if (LIBUDEV_FOUND)
|
||||||
add_definitions(-DUSE_UDEV)
|
add_definitions(-DUSE_UDEV)
|
||||||
else()
|
else()
|
||||||
message("libudev not found, disabling udev support and -d parameter")
|
message("libudev not found, disabling udev support and -D parameter")
|
||||||
set(ENABLE_UDEV OFF)
|
set(ENABLE_UDEV OFF)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
@ -133,12 +137,17 @@ if (BUILD_STATIC)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (LINK_CMAKE_THREADS)
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
target_link_libraries(openFPGALoader Threads::Threads)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# libftdi < 1.4 as no usb_addr
|
# libftdi < 1.4 as no usb_addr
|
||||||
if (${LIBFTDI_VERSION} VERSION_LESS 1.4)
|
if (${LIBFTDI_VERSION} VERSION_LESS 1.4)
|
||||||
set(CMAKE_CXX_FLAGS "-DOLD_FTDI_VERSION=1")
|
set(CMAKE_CXX_FLAGS "-DOLD_FTDI_VERSION=1 ${CMAKE_CXX_FLAGS}")
|
||||||
else()
|
else()
|
||||||
set(CMAKE_CXX_FLAGS "-DOLD_FTDI_VERSION=0")
|
set(CMAKE_CXX_FLAGS "-DOLD_FTDI_VERSION=0 ${CMAKE_CXX_FLAGS}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
install(TARGETS openFPGALoader DESTINATION bin)
|
install(TARGETS openFPGALoader DESTINATION bin)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue