CMake issues -- Could not find a package configuration file provided by "OpenCV" - c++

I am having an issue building a project using Cmake, which I have never done before. I am new to C++ and the concept of Cmake and Makefiles. I am trying to recreate some results from some code off of GitHub. The instructions/files can be found here if you would like to take a more detailed look:
https://github.com/jan-dufek/Fotokite
So basically there are four steps he lists to do:
1-)Install CMake:
https://cmake.org
2-) In Terminal, change directory into the root directory of the project and run the following command to generate makefile:
cmake .
3-) Compile the project:
make
4-) Run:
./Fotokite
Basically I am stuck on the 2nd step right now because I keep getting the following error in my terminal after navigating to the folder and running "cmake .".
The C compiler identification is AppleClang 11.0.3.11030032
The CXX compiler identification is AppleClang 11.0.3.11030032
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
Detecting CXX compile features
Detecting CXX compile features - done
CMake Error at CMakeLists.txt:5 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
I have OpenCV downloaded onto my Desktop as well, and I tried incorporating the path into the Cmake file but still am not having any luck.
Here is also the Cmakelists.txt:
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
project(Fotokite)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
file(GLOB SOURCES
*.h
*.hpp
*.cpp
)
list(FILTER SOURCES EXCLUDE REGEX "main.*.cpp")
list(FILTER SOURCES EXCLUDE REGEX "Visualization.*")
foreach (FILE "" Takeoff GoToWaypoint ExecutePath Land)
add_executable(Fotokite${FILE} ${SOURCES} main${FILE}.cpp)
target_link_libraries(Fotokite${FILE} ${OpenCV_LIBS} pthread)
endforeach(FILE)
First time posting on this website so sorry if something is unclear, if so I can provide more details! Looking forward to your responses.

The following error message details the cause of the issue:
CMake Error at CMakeLists.txt:5 (find_package): By not providing
"FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has asked CMake
to find a package configuration file provided by "OpenCV", but CMake
did not find one.
Could not find a package configuration file provided by "OpenCV" with
any of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If
"OpenCV" provides a separate development package or SDK, be sure it
has been installed.
What this means is that when the call to find_package is made, CMake has two modes to finding dependencies, “Module” mode and “Config” mode. Module mode means that somewhere on CMakes modules path it can find a file called FindOpenCV.cmake. By default CMake ships with lots of preprepared find modules, however, it does not ship with one for OpenCV by default. In this case, you could add it your self (just google for FindOpenCV.cmake and you'll find examples) however this in the wrong approach, I'll explain why.
When you produce a library build using CMake, if you expect to have downstream clients who will depend on your library then you should make it easy to use. CMake supports this through “Config” mode. When you write a library using CMake as part of the install step (this is the step that can be run to package a library into an installable set of files and folder structure after building). You can see an example of how to set this up for a project here: https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-to-create-a-ProjectConfig.cmake-file. At this point you don't need to know how to do this, just that libraries should do this because they have the information to export targets for a library correctly. If they don't then it become necessary for users to access a library in “Module” mode, which involved creating a find<library>.cmake which instruction detailing how to locate the file.
However, OpenCV using CMake does thankfully correctly create and install a OpenCVConfig.cmake file allowing users to use “Config” mode to access it. There issue here then seems that you have not installed OpenCV into one of the standard system install directories which “Config” mode searched by default. The list of search locations is detailed here: https://cmake.org/cmake/help/v3.19/command/find_package.html. To fix this you can pass in the PATH parameter to find_package so that it looks in additional locations:
find_package(OpenCV REQUIRED PATH <location to OpenCV installation>)

I have seen similar issue while using buildroot to build something.
when I check the log, found
>>> xxxxxx Configuring
>>> xxxxxx Installing to target
xxxxxxxxxxxxxx DESTDIR= xxxxxxxxxxxxxxx
please take a close look at the DESTDIR variable. it might be impacted by "FOO_INSTALL_STAGING = YES" command in xxx.mk file.

Related

Cmake find_package does not detect path in windows

I am trying to build the ceres sovler using Cmake_gui and Visual Studio
I have ceres-solver cloned to E:\Code\libs\ceres-solver
and the required library Eigen3 cloned to E:\Code\libs\eigen-3.3.9
When I run cmake-gui on ceres-solver, I get the following error:
-- Detected available Ceres threading models: [CXX_THREADS, OPENMP, NO_THREADS]
-- Building with C++14
CMake Error at CMakeLists.txt:242 (find_package):
By not providing "FindEigen3.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Eigen3", but
CMake did not find one.
Could not find a package configuration file provided by "Eigen3" (requested
version 3.3) with any of the following names:
Eigen3Config.cmake
eigen3-config.cmake
Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
"Eigen3_DIR" to a directory containing one of the above files. If "Eigen3"
provides a separate development package or SDK, be sure it has been
installed.
I modified ceres CMakeLists.txt line 241
from:
find_package(Eigen3 3.3 REQUIRED)
to
find_package(Eigen3 3.3 REQUIRED PATH "E:/Code/libs/eigen-3.3.9")
But I still get this error above
I also tried
list(APPEND CMAKE_PREFIX_PATH "E:/Code/libs/eigen-3.3.9")
set(Eigen3_DIR "E:/Code/libs/eigen-3.3.9")
My questions are:
What is the correct way to specify the path for find_package? Do I need to use path environment variable within windows or modify CMakeLists.txt?
Am I specifying this path correctly in Windows? Do I need to link to some internal directory of Eigen3? Like E:\Code\libs\eigen-3.3.9\cmake, use forward slashes instead of back slashes, or use quotation marks for the path? I tried all of these things without success.
Does find_package recursively search for the package within the directories specified? Or do I need to point to the exact directory?
Thanks
According to comments:
I must run Cmake-Gui on Eigen3 first, to generate a Build directory. However, it does not necessarily need to be built in VS afterwards,
Then setting on line 240 in CMakeLists.txt for ceres-solver
list(APPEND CMAKE_PREFIX_PATH "E:/Code/libs/eigen-3.3.9/build")
Was sufficient for Cmake-Gui to find the Eigen3Config.cmake file
Notes:
Eigen3 does not have any required dependencies it seems, but it does throw a lot of warnings when generating with Cmake-Gui, I ignored these
glog library or any other libraries are not required, but I did have to check "Enable mini-glog" option and re-run config for ceres-solver.

How to find and link CUDA libraries using CMake 3.15?

I'm using CMake 3.15-rc3 on my Unix-like system.
I need to link a program I'm building with several of the CUDA libraries, including cublas, cufft, cusolver, curand, nppicc, nppial, nppist, nppidei, nppig, nppitc, npps.
Based on what I found online, I need to do something like this:
add_executable(test benchmark.cpp)
find_package(CUDALibs)
target_link_libraries(test CUDA::cudart CUDA::cublas CUDA::cufft CUDA::cusolver CUDA::curand CUDA::nppicc CUDA::nppial CUDA::nppist CUDA::nppidei CUDA::nppig CUDA::nppitc CUDA::npps)
When I run make I get the following error:
CMake Warning at CMakeLists.txt:27 (find_package):
By not providing "FindCUDALibs.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "CUDALibs",
but CMake did not find one.
Could not find a package configuration file provided by "CUDALibs" with any
of the following names:
CUDALibsConfig.cmake
cudalibs-config.cmake
Add the installation prefix of "CUDALibs" to CMAKE_PREFIX_PATH or set
"CUDALibs_DIR" to a directory containing one of the above files. If
"CUDALibs" provides a separate development package or SDK, be sure it has
been installed.
So looks like I need a CUDALibsConfig.cmake file. Where do I get this file and how to I tell cmake to use it?
If I use the following it works:
find_package(CUDA REQUIRED)
target_link_libraries(run_benchmarks tf libmxnet.so ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${CUDA_cublas_LIBRARY} ${CUDA_npp_LIBRARY})
But according to this find_package(cuda) is deprecated, so I want to learn the proper usage.
Edit
I tried what was suggested in one of the responses.
I added CUDA to the project LANGUAGES:
project(
test_project
DESCRIPTION "Test project"
LANGUAGES CXX CUDA
)
And then I used find_package( FindCUDAToolkit REQUIRED)
However, when I run cmake I get the following errors:
 nchafni   dev  …  sample_code  benchmarks  build  1  cmake ..
-- The CXX compiler identification is GNU 7.5.0
-- The CUDA compiler identification is NVIDIA 10.1.243
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working CUDA compiler: /usr/local/cuda-10.1/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda-10.1/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
CMake Error at CMakeLists.txt:17 (find_package):
By not providing "FindFindCUDAToolkit.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"FindCUDAToolkit", but CMake did not find one.
Could not find a package configuration file provided by "FindCUDAToolkit"
with any of the following names:
FindCUDAToolkitConfig.cmake
findcudatoolkit-config.cmake
Add the installation prefix of "FindCUDAToolkit" to CMAKE_PREFIX_PATH or
set "FindCUDAToolkit_DIR" to a directory containing one of the above files.
If "FindCUDAToolkit" provides a separate development package or SDK, be
sure it has been installed.
-- Configuring incomplete, errors occurred!
What am I missing?
find_package(CUDA) is deprecated for the case of programs written in CUDA / compiled with a CUDA compiler (e.g. NVCC). The documentation page says (emphasis mine):
It is no longer necessary to use this module or call find_package(CUDA) for
compiling CUDA code. Instead, list CUDA among the languages named in
the top-level call to the project() command, or call the
enable_language() command with CUDA. Then one can add CUDA (.cu)
sources to programs directly in calls to add_library() and
add_executable().
But find_package(CUDA) was not really deprecated - as of CMake version 3.15 - for C++ code which simply uses CUDA-enabled/CUDA-bundled/CUDA-utilizing libraries.
In CMake 3.17, a new macro/command was introduced: FindCUDAToolkit() (and this, find_package(CUDAToolkit). You can't use that with your version of CMake; find_package(CUDA) will do just fine, even if it's a bit clunky and outdated.
Edit: It is actually very easy to upgrade to a newer CMake version: KitWare offer binary releases which have very little dependencies. On a Linux system they would be:
linux-vdso.so.1
libdl.so.2
librt.so.1
libpthread.so.0
libm.so.6
libc.so.6
/lib64/ld-linux-x86-64.so.2
... and you would be hard-pressed to find a system without these. Also, even when installed under an arbitrary path, CMake will be able to differentiate between its version of shared files and whatever the system version of CMake uses. So - no reason to stick with the old version.
The documentation you linked says that you need to add CUDA to the list of languages in your project() command. And to find CUDA libraries it says to use FindCUDAToolkit module, not that CUDALibs.

CMake can't find protobuf when compiling Google's protobuf example

I am trying to solve this problem for 2 days now with no luck. I've read an endless number of threads allover the web and tried a lot of suggestions but so far with no luck.
I'm doing this on Windows 10 with VS2017 and most recent VS Code installed. I installed protobuf with vcpkg install protobuf:
The package protobuf:x64-windows provides CMake targets:
find_package(protobuf CONFIG REQUIRED)
target_link_libraries(main PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
I downloaded Google's example code and extracted it on my drive. The .PROTO file compiles without a problem:
d:\protobuf-3.12.2\examples>protoc -I=d:\protobuf-3.12.2\examples --cpp_out=d:\protobuf-3.12.2\examples d:\protobuf-3.12.2\examples\addressbook.proto
and creates the two files "addressbook.pb.cc" and "addressbook.pb.h" as expected.
Now when I try to compile the project in Visual Studio Code it constantly fails no matter how I modify the CMakeLists.txt file. As mentioned I went through dozens of threads regarding this problem and tried a lot with no luck.
Update 29.05.2020
I checked that protobuf is installed just once and indeed the demo package also included a full protobuf installation. I removed this extra demo package and un-/installed protobuf with vcpgk. I then compiled the .proto file with protoc (which is in my path) and got the two files "addressbook.pb.cc" and "addressbook.pb.h".
Then I tried to compile the project again, this time using the CMakeLists.txt that came with the demo.
The relevant part seems to be right in the beginning:
# Minimum CMake required
cmake_minimum_required(VERSION 2.8.12)
# Project
project(protobuf-examples)
# Find required protobuf package
find_package(protobuf CONFIG REQUIRED)
if(protobuf_VERBOSE)
message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}")
endif()
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
Compiling this gives me:
[main] Building folder: examples
[main] Configuring folder: examples
[cms-client] Configuring using the "Visual Studio 15 2017" CMake generator with platform "x64" and toolset "host=x64"
[cmake] Selecting Windows SDK version 10.0.17763.0 to target Windows
...
[cmake] CMake Error at CMakeLists.txt:8 (find_package):
[cmake] Could not find a package configuration file provided by "protobuf" with any
[cmake] of the following names:
[cmake]
[cmake] protobufConfig.cmake
[cmake] protobuf-config.cmake
[cmake]
[cmake] Add the installation prefix of "protobuf" to CMAKE_PREFIX_PATH or set
[cmake] "protobuf_DIR" to a directory containing one of the above files. If
[cmake] "protobuf" provides a separate development package or SDK, be sure it has
[cmake] been installed.
[cmake]
[cmake]
[cmake] Configuring incomplete, errors occurred!
[cmake] See also "d:/vcpkg/buildtrees/protobuf/src/v3.12.0-8ba83cbbdb/examples/build/CMakeFiles/CMakeOutput.log".
[cms-driver] Error during CMake configure: [cmake-server] Configuration failed.
The file protobuf-config.cmake can be found multiple times in the protobuf folder:
D:\vcpkg\buildtrees\protobuf\<BUILDCFG>\share\protobuf\protobuf-config.cmake
D:\vcpkg\installed\<BUILDCFG>\share\protobuf\protobuf-config.cmake
D:\vcpkg\packages\<BUILDCFG>\share\protobuf\protobuf-config.cmake
What could be the cause that CMake can't locate these files?
Fair warning I am no expert.
I ran in to a similar problem in my own build trying to get Boost working and I think it has to do with your environment variables and how you have your Visual Studio setup. While you are setting crucial things such as
SET(PROTOBUF_INCLUDE_DIR "d:/vcpkg/packages/protobuf_x64-windows/include/")
The actual find_package(protobuf CONFIG REQUIRED) throws these settings out the window. Once it finds that config file it only cares about what the config file is finding, I think this is the cause of how your first MESSAGE has the right one, and then your 2nd one doesn't find one.
Are you positive you only have one installation of protobuf on your machine?
It appears to be finding this "used as include directory in directory D:/protobuf-3.12.2/examples"
yet you are trying to find "D:/vcpkg/packages/protobuf_x64-windows" no?
Try adding a "-DCMAKE_PREFIX_PATH="d:/vcpkg/packages/protobuf_x64-windows" to your CMake options in Visual Studio
Good luck and sorry if this doesn't help, I'm relatively new to programming but its worth a try.
in this thread fraser solved the problem but if you need to develop according to protobuf CMake config and find_package command in CMake for finding protobuf libraries. your protobuf library must be compiled with CMake and do not use configure routine .
after compile protobuf with CMake , a config file named protobuf-config.cmake will be generated into the prefix/lib/CMake/protobuf directory.
If the problem is in finding the protobuf installation then your protobuf path isn't on the Environment Variables try adding that to your path and let me know in case if it is there.
Will glad to help you more in case this doesn't work

Build uWebSockets on Windows 10 with CMake

I want to use uWebSockets(UWS) in my C++ project to transfer images over the network. The setup will be running on multiple operating systems, so the best way of creating the build files seemed like using CMake.
However, I am new to CMake and having a hard time building UWS. I don't understand how to start working with the official repository on Windows 10, so I found another repository that includes a CMakeFiles.txt file and some of the dependencies (openssl, zlib, libuv, but it doesn't include uSockets for some reason). The root CMakeFiles.txt includes:
[...]
find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
find_path(LIBUV_INCLUDE_DIR uv.h)
find_library(LIBUV_LIBRARY NAMES uv uv1)
[...]
It looks straightforward, but when I try to run mkdir build && cd build; cmake .., it cannot find OpenSSL. Here is the error message it spits out:
[...]
[cmake] Could not find a package configuration file provided by "OpenSSL" with any
[cmake] of the following names:
[cmake]
[cmake] OpenSSLConfig.cmake
[cmake] openssl-config.cmake
[...]
The above error message suggests that I need to set up a config file for each of these libraries. Yet, if I understand the find_package docs correctly, the command itself searches the library in various locations under the root folder. What kind of a folder structure does the find_package need in order to work?
More generally, am I wasting my time with this alternative repo? Is there a better way of using UWS with Windows 10? The official repo has a question about how to use it on Windows but I don't understand how that's an answer to the question. It only points to this page where it says any specific build systems will not officially be supported.
Any help would be appreciated.
Importing dependencies with add_subdirectory seems like a good way around this. When I ran cmake, I was receiving LNK2019 Error. I realized the following code snippet I found online was causing the problem, and the system works when I delete it.
if(MSVC)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS")
endif()

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"