CMake Error at CMakeLists.txt:3 (find_package) - c++

I'm trying to control raspberry pi camera via c++. I found api (raspicam), installed, checked. It works with an example provided by developer. Now I create my own project and got an error of CMakeLists:
CMake Error at CMakeLists.txt:3 (find_package):
By not providing "Findraspicam.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "raspicam",
but CMake did not find one.
Could not find a package configuration file provided by "raspicam" with any
of the following names:
raspicamConfig.cmake
raspicam-config.cmake
Add the installation prefix of "raspicam" to CMAKE_PREFIX_PATH or set
"raspicam_DIR" to a directory containing one of the above files. If
"raspicam" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
See also "/home/pi/raspicam/build/CMakeFiles/CMakeOutput.log".
And it is my CmakeLists.txt file:
make_minimum_required (VERSION 2.8)
project (raspicam_test)
find_package(raspicam REQUIRED)
add_executable (simpletest_raspicam simpletest_raspicam.cpp)
target_link_libraries (simpletest_raspicam ${raspicam_LIBS})
I just have started and already got a problem... Could you help please guys? :/

For those who used default instructions in the readme file of the raspicam (as of v 0.1.3, might differ in future):
you can also add
set(raspicam_DIR "/usr/local/lib/cmake")
to your cmake file before you use
find_package(raspicam REQUIRED)
That is when you have raspicamConfig.cmake at /usr/local/lib/cmake. If you did not have it at that directory, you can simply search your raspberry to find where it is or you can go to "build" folder in raspicam you used to install before. Then type sudo make install again, which will return "Up-to-date" message along with all a list of files and their locations, including raspicamConfig.cmake. Hope this helps to some.

This works for me.
$ brew install vcpkg
$ vcpkg install raspicam
$ vcpkg integrate install # get path
$ cmake -DCMAKE_TOOLCHAIN_FILE=/usr/local/Cellar/vcpkg/2021.05.12/libexec/scripts/buildsystems/vcpkg.cmake ..

Related

How can I use mbedtls in CMake?

I'm trying to use mbedtls in my CMakelists.txt file. I used the vcpkg package manager to install mbedtls: vcpkg install mbedtls
I added my find_package() statement before add_executable() but despite adding -DCMAKE_TOOLCHAIN_FILE=/bin/vcpkg/scripts/buildsystems/vcpkg.cmake to my CLion CMake options, CLion does not find mbedtls.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.22)
project(mbedtls_ssl_server)
set(CMAKE_CXX_STANDARD 20)
find_package(mbedtls REQUIRED)
add_executable(mbedtls_ssl_server
main.cpp)
target_link_libraries(mbedtls_ssl_server mbedtls::mbedtls)
The error message is:
CMake Error at /bin/vcpkg/scripts/buildsystems/vcpkg.cmake:838 (_find_package):
By not providing "Findmbedtls.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "mbedtls", but
CMake did not find one.
Could not find a package configuration file provided by "mbedtls" with any
of the following names:
mbedtlsConfig.cmake
mbedtls-config.cmake
Add the installation prefix of "mbedtls" to CMAKE_PREFIX_PATH or set
"mbedtls_DIR" to a directory containing one of the above files. If
"mbedtls" provides a separate development package or SDK, be sure it has
been installed.
I also tried running sudo apt install libmbedtls-dev on Ubuntu but that didn't help either, the previous error persists.
I had the same error and i had to set the variable MbedTLS_DIR in CMakelists.txt.
Exemple for MacOS:
set(MbedTLS_DIR /opt/homebrew/Cellar/mbedtls/3.3.0/cmake/) # <-- Here
find_package(MbedTLS REQUIRED )
target_link_libraries(${target_lib} PUBLIC MbedTLS::mbedtls)
This point on folder that contain MbedTLSConfig.cmake

Unable to setup vcpkg CMAKE_TOOLCHAIN_FILE with KDevelop

I have installed vcpkg according to the instructions provided here. I installed the libraries I wanted (in this case fmt and boost), then created a simple new project in KDevelop which runs just fine. Then to add my libraries to the project I added -DCMAKE_TOOLCHAIN_FILE=/VCPKG_LOCATION/vcpkg/scripts/buildsystems/vcpkg.cmake in the "Configure CMake settings", where there is an "Extra arguments field", of KDevelop (Right click on Project folder and then "Open Configuration...").
Then I simply added the following to my CMakeLists.txt:
find_package(fmt REQUIRED)
and I get the following error:
By not providing "Findfmt.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"fmt", but CMake did not find one.
Could not find a package configuration file provided by "fmt" with
any of the following names:
fmtConfig.cmake
fmt-config.cmake
Add the installation prefix of "fmt" to CMAKE_PREFIX_PATH or set
"fmt_DIR" to a directory containing one of the above files. If
"fmt" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
It seems that KDevelop is not recognizing the toolchain file (even though I can clearly see in the build log that that CMake is being called with the "-DCMAKE_TOOLCHAIN_FILE" as required). I have tried to setup the project similarly in Qt Creator which does seem to work perfectly fine.
You can install fmt package. With gcc/g++ installed,
git clone https://github.com/fmtlib/fmt.git
cd fmt
mkdir build
cd build
cmake ..
make
sudo make install

How can I configure CMake with CGAL?

I am working on the installation of CGAL for my 3D project.
I installed CGAL using the vcpkg package (library) and tried to configure a compiler/linker CMake with CGAL.
Unfortunately I am getting an error to configure CGAL with CMake (see below). How is it possible to link these two together? What does the error mean?
****CMake Error at CMakeLists.txt:22 (find_package):
By not providing "FindCGAL.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "CGAL", but
CMake did not find one.
Could not find a package configuration file provided by "CGAL" with any of
the following names:
CGALConfig.cmake
cgal-config.cmake
Add the installation prefix of "CGAL" to CMAKE_PREFIX_PATH or set
"CGAL_DIR" to a directory containing one of the above files. If "CGAL"
provides a separate development package or SDK, be sure it has been
installed.****
Configuring incomplete, errors occurred!
See also "C:/Users/Desktop/CGAL-5.0.2/examples/Triangulation_2/build/CMakeFiles/CMakeOutput.log".

How to configure cmake-based project for a build with Qt

here is a doc about that, but it doesn't look correct for me ,
so I've copied cmake instructions into my cmakelists.txt and it doesn't work.
it's clear why it doesn't work - because there is no one instruction how to search qt:
I suppose two cases:
some additional cmake instructions requires to set
some environment variables should be set
but nothing about that.
the instruction :
find_package(Qt5Widgets)
refers to extra cmake script from qt kit , isn't it?
I see the directory with that name (annd contains *.cmake scripts but another names) but there is no the script with this name
these are the only .cmake files with qt in names in cmake 3.6 :
cmake-3.6\Modules\DeployQt4.cmake
cmake-3.6\Modules\FindosgQt.cmake
cmake-3.6\Modules\FindQt.cmake
cmake-3.6\Modules\FindQt3.cmake
cmake-3.6\Modules\FindQt4.cmake
cmake-3.6\Modules\Qt4ConfigDependentSettings.cmake
cmake-3.6\Modules\Qt4Macros.cmake
cmake-3.6\Modules\UseQt4.cmake
===================
C:\dev\tools\CLion.RC\bin\cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug
-G "CodeBlocks - MinGW Makefiles" C:\dev\workspace\algolist.v2 CMake Warning at CMakeLists.txt:14 (find_package): By not providing
"FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project has asked
CMake to find a package configuration file provided by "Qt5Widgets",
but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets"
with any of the following names:
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or
set "Qt5Widgets_DIR" to a directory containing one of the above
files. If "Qt5Widgets" provides a separate development package or
SDK, be sure it has been installed.
CMake Error at CMakeLists.txt:20 (target_link_libraries): Cannot
specify link libraries for target "helloworld" which is not built by
this project.
-- Configuring incomplete, errors occurred! See also "C:/dev/workspace/algolist.v2/cmake-build-debug/CMakeFiles/CMakeOutput.log".
seems it found Qt5Widgets, but absolutely not clear how it does this...
so it looks for cmake files inside Qt5Widgets folder, in Qt kit.
I can add this folder to the path but I don't think this is a valid way,
because there is a lot of subfolders with cmake files
Qt5.8 beta, built with MinGW, Win10, cmake 3.6
You need to use CMAKE_PREFIX_PATH.
For example:
cmake.exe -DCMAKE_PREFIX_PATH="C:/path/to/Qt/5.X/compiler/lib/cmake"

Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH

I don't know a lot about cmake, I'm trying to build a client using cmake and Qt. Getting the following error:
CMake Error at alethzero/CMakeLists.txt:26 (find_package): By not
providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"Qt5Widgets", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets"
with any of the following names:
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or
set "Qt5Widgets_DIR" to a directory containing one of the above
files. If "Qt5Widgets" provides a separate development package or
SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
As far as I understand, I need to add the QT path to CMake. How do I do it? I have Qt installed in /home/user/Programs. All the explanations I find are "just do this or that". I need the exact Terminal commands so I can just learn how to do it in the future.
Thanks!
UPDATE: export CMAKE_PREFIX_PATH=/home/user/Programs did not help me.
Well, here you have a solution for Windows: How to find qt5 CMake module on windows
set (CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.0.1\\5.0.1\\msvc2010\\")
For your environment, I think you will have to change the path where Qt is located...
Maybe this will help you:
https://github.com/Cockatrice/Cockatrice/issues/205
This is documented:
http://doc.qt.io/qt-5/cmake-manual.html
The easiest way to use CMake is to set the CMAKE_PREFIX_PATH
environment variable to the install prefix of Qt 5
Do this
export CMAKE_PREFIX_PATH=/home/user/Programs/<other_stuff>
where references the compiler etc, so that this complete path is valid:
/home/user/Programs/<other_stuff>/bin/qmake*
I needed this on my macOS after Qt installation with brew install qt5:
export CMAKE_PREFIX_PATH=/usr/local/Cellar/qt5/5.7.0/
For ubuntu:
cmake -DCMAKE_PREFIX_PATH=/home/ryan/Qt/5.11.2/gcc_64 ..
/home/ryan/Qt/ is the Qt installation root path
at an Ubuntu 16.04.4 LTS desktop the solution was
cmake .. -DMAKE_PREFIX_PATH=/usr/include/x86_64-linux-gnu/qt5