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

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.

Related

How to set CMake variable to include directory

When trying to build this library with Cmake from the Developer Command Prompt for VS, I get this error
CMake Error at cmake/FindEigen.cmake:77 (MESSAGE):
Failed to find Eigen - Could not find eigen3 include directory, set
EIGEN_INCLUDE_DIR to path to eigen3 include directory, e.g.
/usr/local/include/eigen3.
I'd like find out what was intended of me here: am I to set EIGEN_INCLUDE_DIR with a command line argument or by editing the make file?
I've tried cmake -D EIGEN_INGLUDE_DIR=C:\Users\a\Downloads\eigen-3.3.7\eigen-3.3.7 . but received the same error.
cmake -D EIGEN_INGLUDE_DIR=C:\Users\a\Downloads\eigen-3.3.7\eigen-3.3.7 . failed without creating any files (cmake .. at least started building) and gave me this error
CMake Error: The source "C:/Users/a/Downloads/RpolyPlusPlus-master/RpolyPlusPlus-master/build/CMakeLists.txt" does not match the source "C:/Users/a/Downloads/RpolyPlusPlus-master/RpolyPlusPlus-master/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.
So I just ended up adding this to the .cmake file:
# TODO: Add standard Windows search locations for Eigen.
LIST(APPEND EIGEN_CHECK_INCLUDE_DIRS
/usr/local/include
/usr/local/homebrew/include # Mac OS X
/opt/local/var/macports/software # Mac OS X.
/opt/local/include
/usr/include
C:\\Users\\a\\Downloads\\eigen-3.3.7) <---------------------------------------

espidf COMPONENT_DIR

I'm trying to compile a simple Hello_world example using the Smooth component (https://github.com/PerMalmberg/Smooth), and get error: include could not find load file:
../lib/compiler_options.cmake.
It seems that COMPONENT_DIR is not set, but I'm not aware whether/where to set this, or where this should have been set.
I've been staring at this too long, and am not finding the (apparently) obvious problem. Anyone any thoughts?
ERROR
Note: You are using Python 3.8.0. Python 3 support is new, please report any problems you encounter. Search for 'Setting
the Python Interpreter' in the ESP-IDF docs if you want to use Python 2.7.
Checking Python dependencies...
Python requirements from C:\Esp32_tools\esp-idf-v3.3\requirements.txt are satisfied.
Running cmake in directory C:\Temp\esp\testCPP\build
Executing "cmake -G Ninja -DPYTHON_DEPS_CHECKED=1 -DESP_PLATFORM=1 --warn-uninitialized C:\Temp\esp\testCPP"...
Warn about uninitialized values.
-- Building for target esp32
-- ccache will be used for faster builds
CMake Error at C:/Temp/esp/testCPP/externals/smooth/smooth_component/CMakeLists.txt:21 (include):
include could not find load file:
../lib/compiler_options.cmake
Call Stack (most recent call first):
C:/Esp32_tools/esp-idf-v3.3/tools/cmake/scripts/expand_requirements.cmake:107 (include)
C:/Esp32_tools/esp-idf-v3.3/tools/cmake/scripts/expand_requirements.cmake:217 (expand_component_requirements)`
CMake Error at C:/Esp32_tools/esp-idf-v3.3/CMakeLists.txt:39 (message):
Failed to expand component requirements
VERSION
C:\Temp\esp\testCPP>cmake --version
cmake version 3.13.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
CMakeLists.txt
set(CMAKE_CXX_STANDARD 17)
if(${ESP_PLATFORM})
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# Include Smooth as a component
set(EXTRA_COMPONENT_DIRS
externals/smooth/smooth_component)
project(name_of_your_project)
else()
# Empty project when not building for ESP (i.e. when loading the project into an IDE with already configured tool chains for native Linux)
endif()```
CMake Error at C:/Esp32_tools/esp-idf-v3.3/CMakeLists.txt:39 (message):
Failed to expand component requirements
You are missing this line in CMakeLists.txt
https://github.com/espressif/esp-idf/blob/master/examples/get-started/hello_world/CMakeLists.txt#L3

CMake compiler in path not being found

I'm attempting to compile a program using cmake that gives me the following error(s):
CMake Error at /.../3dg.cmake:8 (enable_language):
The CMAKE_CXX_COMPILER:
CC
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
Call Stack (most recent call first):
CMakeLists.txt:8 (include)
CMake Error at /.../3dg.cmake:8 (enable_language):
The CMAKE_C_COMPILER:
cc
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
I am setting both of these variables in my cmake file with:
set(CMAKE_C_COMPILER cc)
set(CMAKE_CXX_COMPILER CC)
Moreover, I can confirm that both of them are in my path and at the correct location.
>>which cc
/opt/cray/pe/craype/2.5.14/bin/cc
>>which CC
/opt/cray/pe/craype/2.5.14/bin/CC
And my path includes this directory!
>>echo $PATH
/opt/cray/rca/2.2.18-6.0.7.0_33.3__g2aa4f39.ari/bin:/opt/cray/alps/6.6.43-6.0.7.0_26.4__ga796da3.ari/sbin:/opt/cray/job/2.2.3-6.0.7.0_44.1__g6c4e934.ari/bin:/opt/cray/pe/hdf5/1.10.0.3/bin:/opt/cray/pe/craype/2.5.14/bin:/opt/intel/compilers_and_libraries_2018.1.163/linux/bin/intel64:/usr/common/software/metis/5.1.0/bin:/usr/common/software/darshan/3.1.4/bin:/usr/common/software/altd/2.0/bin:/usr/common/software/bin:/usr/common/mss/bin:/usr/common/nsg/bin:/opt/cray/pe/mpt/7.7.0/gni/bin:/opt/ovis/bin:/opt/ovis/sbin:/usr/syscom/nsg/sbin:/usr/syscom/nsg/bin:/opt/cray/pe/modules/3.2.10.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin:/opt/cray/pe/bin:
The cmake file sees the same path as the terminal. I have confirmed that this error goes away if I change my cmake code to:
set(CMAKE_C_COMPILER /opt/cray/pe/craype/2.5.14/bin/cc)
set(CMAKE_CXX_COMPILER /opt/cray/pe/craype/2.5.14/bin/CC)
But this is not a long term fix as the actual location of cc/CC depends on which modules I am using and the updated version of the compilers.
Does anyone know what is going on, and how to force cmake to recognize that these compilers are located in the correct location? Thanks.
Go to download page of glfw and download their source package. Now unzip it and enter into the directory.
Now generate the make file with sudo cmake -G "Unix Makefiles".
Now do sudo make and sudo cmake. The install process should be complete.
For more info take a look at here

Build MPICH with CMake

I need to force my Cmake to build and link my MPI code with MPICH. My MPICH is installed using the Ubuntu Package manager, in a standard location /usr/lib/mpich/. However, CMake still looks for the OpenMPI libraries, which I do not use. How can I instruct CMake to look for MPICH instead?
Below, you can see the output of some basic diagnostics:
$ whereis openmpi
openmpi:
$ whereis mpich
mpich: /usr/lib/mpich /usr/include/mpich
$ mpicc -v
mpicc for MPICH version 3.2
Below, I also provide the Cmake script and the errors I get from cmake and the mpirun.mpich. My Cmake is 3.5.1 and I run on Ubuntu Xenial 16.04.
cmake_minimum_required(VERSION 3.0)
message (STATUS "Adding mpiService")
find_package(MPI REQUIRED)
set(CMAKE_C_COMPILER mpicc)
set(CMAKE_CXX_COMPILER mpicxx)
set(MPI_GUESS_LIBRARY_NAME MPICH2)
message(STATUS ${MPI_INCLUDE_PATH})
message(STATUS ${MPI_C_LIBRARIES})
#add_definitions(-DOMPI_SKIP_MPICXX)
add_executable(mpiService main.cpp)
set(CMAKE_VERBOSE_MAKEFILE ON)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
target_link_libraries(
mpiService
PRIVATE
${MPI_C_LIBRARIES}
)
From the Cmake STATUS I get the following output:
/usr/lib/openmpi/include/openmpi/opal/mca/event/libevent2021/libevent/usr/lib/openmpi/include/openmpi/opal/mca/event/libevent2021/libevent/include/usr/lib/openmpi/include/usr/lib/openmpi/include/openmpi
/usr/lib/openmpi/lib/libmpi.so
And when I run the binary I get the following:
ubuntu#node1:~$ mpirun.mpich -np 2 --host node1,node2 mpiService
mpiService: error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory
mpiService: error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory
How can I instruct CMake to look for MPICH instead?
According to FindMPI documentation, you may set MPI_<lang>_COMPILER variable to the desired MPI compiler:
Set MPI_<lang>_COMPILER to the MPI wrapper (mpicc, etc.) of your
choice and reconfigure. FindMPI will attempt to determine all the
necessary variables using THAT compiler's compile and link flags.
set(MPI_CXX_COMPILER <path-to-mpich-compiler>)
find_package(MPI REQUIRED)
Alternatively, since CMake version 3.10, variable MPI_EXECUTABLE_SUFFIX can be set instead:
A suffix which is appended to all names that are being looked for. For instance you may set this to .mpich or .openmpi to prefer the one or the other on Debian and its derivatives.
set(MPI_EXECUTABLE_SUFFIX ".mpich")
find_package(MPI REQUIRED)
Herewith my current solution.
find_package(MPI REQUIRED)
# ----------------
# This is the only thing that made it work
# ----------------
set(MPI_C_LIBRARIES "/usr/lib/mpich/lib/libmpich.so")
set(MPI_INCLUDE_PATH "/usr/include/mpich")
# ----------------
add_executable(mpiService main.cpp)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
target_link_libraries(
mpiService
${MPI_C_LIBRARIES}
)
I personally do not like this solution, as I have to explicitly specify the path. Any other proposed solution was still building with OpenMPI. If I find a better alternative, I will re-post.

CMake error: For MinGW make to work correctly sh.exe must NOT be in your path

I am trying to built a "Hello World" project with Qt 5 and cmake under MinGW.
This is the CMakeLists.txt file (taken from the on-line doc):
project(Qt5_cmake_test)
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.1.1/5.1.1/mingw48_32")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the QtWidgets library
find_package(Qt5Widgets)
# Add the source files from the current directory
aux_source_directory(. SRC_LIST)
# Tell CMake to create the executable
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
# Use the Widgets module from Qt5
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
The source code is the one generated automatically when creating a new project (which produces an empty window).
Configuring from the Windows command prompt with: cmake -G "MinGW Makefiles" ..\Qt5_cmake_test
I get these errors:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeMinGWFindMake.cmake:20 (message):
sh.exe was found in your PATH, here:
C:/Program Files (x86)/Git/bin/sh.exe
For MinGW make to work correctly sh.exe must NOT be in your path.
Run cmake from a shell that does not have sh.exe in your PATH.
If you want to use a UNIX shell, then use MSYS Makefiles.
Call Stack (most recent call first):
CMakeLists.txt:8 (project)
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:C:/Users/pietro.mele/projects/tests/buildSystem_test/Qt5_cmake_test-build/CMakeFiles/2.8.11.2/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:C:/Users/pietro.mele/projects/tests/buildSystem_test/Qt5_cmake_test-build/CMakeFiles/2.8.11.2/CMakeCXXCompiler.cma
ke
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
So it seems it is not able to find the compiler. Is there a way to let cmake find it on its own, or just giving it the CMAKE_PREFIX_PATH directory?
Do I have to manually specify all those variables in the makefile or as environment variables in Windows?
I tried both from the standard Windows command prompt and from the one provided by Qt, with the same result. Is it OK to build from the Windows command prompt, or should I do it from the MinGW's shell?
Platform:
Qt 5.1
CMake 2.8.11.2
MinGW/GCC 4.8
Windows 7
Get the git path out of your PATH before running cmake.
Here is the magic to do that:
set PATH=%PATH:C:/Program Files (x86)/Git/bin;=%
This CMakeLists.txt file works properly:
project(Qt5_cmake_test)
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.1.1/5.1.1/mingw48_32")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the Qt libraries
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
# Add the source files from the current directory
aux_source_directory(. SRC_LIST)
# Tell CMake to create the executable
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
# Use Qt5 modules
target_link_libraries(${PROJECT_NAME}
Qt5::Widgets
Qt5::WinMain)
The changes are:
Added find_package(Qt5Core REQUIRED).
Added Qt5::WinMain to target_link_libraries.
In some of my answer here on SO, I have described. CMake does not like sh.exe.
sh.exe was found in your PATH, here:
C:/Program Files (x86)/Git/bin/sh.exe
Solution : Rename C:/Program Files (x86)/Git/bin/sh.exe shortly.
For example:
C:/Program Files (x86)/Git/bin/shxx.exe
But do not forget when everything is built. rename properly again.