Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
add dependency to pigpio library in CMake build
Browse files Browse the repository at this point in the history
use CMake's [`ExternalProject`] functionality to pull in the [`pigpio`]
library.

we explicitly check out the latest release tag (instead of just the
default branch) to ensure that we always have the same version.
the installation directory is explicitly specified as otherwise it tries
to install the library globally, which would require root access. as we
only need it for our build we don't want to interfer with the rest of
the system and don't need root.

in the best case this would've been mostly provided by the library
directly, but so far this isn't the case. two issues,
joan2937/pigpio#572 and joan2937/pigpio#573 have been raised by me while
implementing this to hopefully make this better in the future.

[`ExternalProject`]: https://cmake.org/cmake/help/latest/module/ExternalProject.html
[`pigpio`]: https://github.com/joan2937/pigpio
  • Loading branch information
rursprung committed Apr 20, 2023
1 parent bc8a0e4 commit fbb86b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions smt_movement_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.0.2)
project(smt_movement_controller)

## Additional CMake Modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

Expand All @@ -14,6 +17,7 @@ find_package(catkin REQUIRED COMPONENTS

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
find_package(pigpio REQUIRED)


## Uncomment this if the package has a setup.py. This macro ensures
Expand Down Expand Up @@ -115,9 +119,9 @@ catkin_package(
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
${catkin_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/include
${catkin_INCLUDE_DIRS}
${pigpio_INCLUDE_DIR}
)

# Declare a C++ executable
Expand All @@ -136,6 +140,7 @@ add_executable(
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME} pigpio)

## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
Expand All @@ -156,7 +161,7 @@ add_executable(
target_link_libraries(
${PROJECT_NAME}
${catkin_LIBRARIES}
pigpio
${pigpio_LIBRARIES}
)

#############
Expand Down
13 changes: 13 additions & 0 deletions smt_movement_controller/cmake/Findpigpio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include(ExternalProject)
ExternalProject_Add(pigpio
GIT_REPOSITORY https://github.com/joan2937/pigpio.git
GIT_TAG v79
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
)

ExternalProject_Get_Property(pigpio INSTALL_DIR)

set(pigpio_INCLUDE_DIR ${INSTALL_DIR}/include)
set(pigpio_LIBRARIES ${INSTALL_DIR}/lib/libpigpio.so)

mark_as_advanced(pigpio_INCLUDE_DIR pigpio_LIBRARIES)

0 comments on commit fbb86b9

Please sign in to comment.