Search code examples
cmakeraspberry-pi3yoctobitbakefind-package

Yocto: CMake Error (find_package) when trying to bitbake a Recipe, but when running it in Cmake alone it works


i am trying to run a simple program using the pigpio library on my raspberry pi, with the yocto project.

I have already tried out the build with cmake and when i run it in the terminal on my pc it works. But when i try to bitbake my recipe, i get following cmake error and i cant seem to find out whats the problem and why i only get this error in bitbake and not when running cmake in the console.

| CMake Error at /home/ibschwarzfischer/yocto/poky/build-rpi3/tmp/work/cortexa53-poky-linux/blinker/1.0-r0/recipe-sysroot-native/usr/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
|   Could NOT find pigpio (missing: pigpio_INCLUDE_DIR pigpio_LIBRARY
|   pigpiod_if_LIBRARY pigpiod_if2_LIBRARY)
| Call Stack (most recent call first):
|   /home/ibschwarzfischer/yocto/poky/build-rpi3/tmp/work/cortexa53-poky-linux/blinker/1.0-r0/recipe-sysroot-native/usr/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
|   /home/ibschwarzfischer/yocto/packages/pigpio-master/util/Findpigpio.cmake:29 (find_package_handle_standard_args)
|   CMakeLists.txt:12 (find_package)

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.5) project(blinker)

set(CMAKE_BUILD_TYPE RelWithDebInfo)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../packages/pigpio-master/util)

set(pigpio_DIR ${PROJECT_SOURCE_DIR}/../../packages/pigpio-master/cmake)

#target_include_directories(blinker PUBLIC include/pigpio)

find_package(pigpio REQUIRED)

add_executable(blinker main.c)

target_link_libraries(blinker PRIVATE pigpio)

and there is also a Findpigpio.cmake included in the pigpio library:

################################################################################
### Find the pigpio shared libraries.
################################################################################

# Find the path to the pigpio includes.
find_path(pigpio_INCLUDE_DIR 
    NAMES pigpio.h pigpiod_if.h pigpiod_if2.h
    HINTS /usr/local/include)
    
# Find the pigpio libraries.
find_library(pigpio_LIBRARY 
    NAMES libpigpio.so
    HINTS /usr/local/lib)
find_library(pigpiod_if_LIBRARY 
    NAMES libpigpiod_if.so
    HINTS /usr/local/lib)
find_library(pigpiod_if2_LIBRARY 
    NAMES libpigpiod_if2.so
    HINTS /usr/local/lib)
    
# Set the pigpio variables to plural form to make them accessible for 
# the paramount cmake modules.
set(pigpio_INCLUDE_DIRS ${pigpio_INCLUDE_DIR})
set(pigpio_INCLUDES     ${pigpio_INCLUDE_DIR})

# Handle REQUIRED, QUIET, and version arguments 
# and set the <packagename>_FOUND variable.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(pigpio 
    DEFAULT_MSG 
    pigpio_INCLUDE_DIR pigpio_LIBRARY pigpiod_if_LIBRARY pigpiod_if2_LIBRARY)

so if anyone knows something that might help i am very happy about it! Thanks in advance!

i tried to compile it with cmake in the terminal using cmake -S . -B out/build and then cmake --build out/build and when i ran the program in the terminal it worked and cmake didnt give me an error so i know the package is linked to the target and cmake also finds the Findpigpio.cmake.


Solution

  • It seems like cmake is not being able to find the pigpio package for the blinker package you have created. And probably is working on your PC because you have it somehow installed on it, so manually it works as it finds it.

    In order to check if you have that package installed on the recipe sysroot, you can run

    bitbake -e blinker | grep "^OE_BUILD_SYSROOT="

    In that path, you can see if there are the required libraries, pkg-config files, etc. that you need for cmake to build your package properly.

    If the pigpio package is not there, probably you need to add it as a build dependency inside your recipe with

    DEPENDS += "pigpio"

    But for this, you need to have a pigpio recipe that actually provides the package. Doing a search, I found this one, but I don't know if it can work and I can't help you with more context: https://gist.github.com/dir-ableton/7ad9045e242165a9e4707c84e6df754b

    Hope this helps a little