I need to link the c++ bindings of libgpiod
to my project, but I cannot figure out how to do this.
I did some research the last few days but without any luck and now I'm kinda stuck.
I would like to add the repo as a submodule, build the module and then link against the module so that I can move the generated binaries (including the module binaries) to the target device.
I cannot simply install the library via a packet manager, because the devices, on which the library should be installed, has no internet access. I could download the package and ship it with the binaries (my current best solution), but I would prefer a "self-containing" build.
My project structure looks roughly as following:
dependencies/
├─ libgpiod/
CMakeLists.txt
main.cpp
and my CMakeLists looks like this:
cmake_minimum_required(VERSION 3.16.3)
project(my_project VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(GPIOD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libgpiod)
set(GPIOD_BIN ${CMAKE_CURRENT_BINARY_DIR}/dependencies/libgpiod)
set(GPIOD_LIB_DIR ${GPIOD_BIN}/lib)
set(GPIOD_INCLUDE_DIR ${GPIOD_BIN}/include)
ExternalProject_Add(libgpiod-project
PREFIX ${GPIOD_BIN}
SOURCE_DIR ${GPIOD_DIR}
CONFIGURE_COMMAND ${GPIOD_DIR}/autogen.sh --enable-tools=no --prefix=${GPIOD_BIN} --enable-bindings-cxx
BUILD_COMMAND make && make install
# INSTALL_COMMAND make install
BUILD_BYPRODUCTS ${GPIOD_LIB_DIR}/libgpiodcxx.so
)
add_executable(my_project main.cpp)
target_link_libraries(my_project PRIVATE
# todo what to link against?
)
The source code is also available on GitHub, if you need a closer look: https://github.com/mobergmann/led-cube/tree/9e8c7bc4d0de2e8c796a30d19f903c23903cd5bd/cxx