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

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"

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.

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

Not found Eigen3_DIR when configuring a cmake project in Windows

I want to compile an open project, it needs Eigen3, I followed its guideline but stuck in this step:
"Set environment variable Eigen3_DIR to {YOUR_EIGEN3_DIRECTORY}/eigen3/cmake."
I have installed CMake gui and it printed following errors after configuration
Make Error at src/CMakeLists.txt:15 (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" 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.
But I have downloaded Eigen3 from here, and set the Eigen3_DIR as follows
So what should I do to fix it? I am just a beginner in cmake.
I am assuming you are using Windows. You will need Visual Studio installed. You can use the community version. You will need to do the following:
Create a directory called "build" within your Eigen directory.
Go to the build directory and do "cmake ..". This will create Visual Studio projects.
Load the .sln using Visual Studio.
Build the solution.
Ensure that the project called INSTALL was built also.
This will create the Eigen3Config.cmake file in your install directory. In my case the install directory was "C:\Program Files(X86)\Eigen3. Use this to as the value for Eigen3_DIR variable.
By default Eigen does not come with the Eigen3Config.cmake file. You will see Eigen3Config.cmake.in file. This is used to build the Eigen3Config.cmake file.
HTH

CMake Error at CMakeLists.txt:3 (find_package)

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 ..

CMake find_package not finding Find<package>.cmake

I made and installed the aruco library, which put a Findaruco.cmake file in the /usr/local/lib/cmake directory. In my CMakeLists.txt file I have
...
find_package(aruco REQUIRED)
and it always returns the standard error
By not providing "Findaruco.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "aruco", but
CMake did not find one.
Could not find a package configuration file provided by "aruco" with any of
the following names:
arucoConfig.cmake
aruco-config.cmake
Add the installation prefix of "aruco" to CMAKE_PREFIX_PATH or set
"aruco_DIR" to a directory containing one of the above files. If "aruco"
provides a separate development package or SDK, be sure it has been
installed.
I've set the environment variable $CMAKE_PREFIX_PATH to each of the following, and none work
/usr/local
/usr/local/lib
/usr/local/lib/cmake
The only thing that works is setting the following in CMakeLists
set(CMAKE_MODULE_PATH /usr/local/lib/cmake)
I'm not sure what I'm doing wrong
Try setting CMake variable called CMAKE_PREFIX_PATH, not the environment one. Use -D flag during cmake invocation:
cmake -D CMAKE_PREFIX_PATH=/usr/local/lib <path to source or build dir>
But AFAIR, CMake should look into /usr/local prefix as its default behavior.