Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide Findpigpio.cmake #573

Open
rursprung opened this issue Apr 20, 2023 · 0 comments
Open

provide Findpigpio.cmake #573

rursprung opened this issue Apr 20, 2023 · 0 comments

Comments

@rursprung
Copy link

currently there's no easy way to automate the integration of pigpio into other cmake projects.

using ExternalProject i found a way to do it. for this i created a cmake/Findpigpio.cmake in my project with the following content:

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)

afterwards i could use this in my main CMakeLists.txt:

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
# [..]
find_package(pigpio REQUIRED)
# [..]
include_directories(
  # [..]
  ${pigpio_INCLUDE_DIR}
)
# [..]
add_dependencies(${PROJECT_NAME} pigpio)
# [..]
target_link_libraries(
  ${PROJECT_NAME} 
  # [..]
  ${pigpio_LIBRARIES}
)

i think it'd be great if this project could ship something like this (i'm not sure if this is the best/proper way of doing it) so that others can pull it in more easily.

rursprung added a commit to rursprung/fhgr-mrproj2 that referenced this issue Apr 20, 2023
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
rursprung added a commit to rursprung/fhgr-mrproj2 that referenced this issue Apr 27, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant