Not found Eigen3_DIR when configuring a cmake project in Windows - c++

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

Related

Cmake package not found

I've installed Drogon using vcpkg, and in my IDE I have following error:
Package 'Drogon' not found. After installing, regenerate the CMake cache.
I am using Visual Studio 2022
vcpkg_rf.txt:
install
drogon
CMakeLists.txt:
# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)
project ("Drogon Server1")
# Include sub-projects.
add_subdirectory ("Drogon Server1")
# Line below is showing the error
find_package(Drogon CONFIG REQUIRED)
target_link_libraries("Drogon Server1" PRIVATE Drogon::Drogon)
I have found this error also:
CMake Error at C:/Users/MY_USERNAME/Documents/sdk/vcpkg/scripts/buildsystems/vcpkg.cmake:829 (_find_package):
Could not find a package configuration file provided by "Drogon" with any
of the following names:
DrogonConfig.cmake
drogon-config.cmake
Add the installation prefix of "Drogon" to CMAKE_PREFIX_PATH or set
"Drogon_DIR" to a directory containing one of the above files. If "Drogon"
provides a separate development package or SDK, be sure it has been
installed.
Considering the given information:
Visual Studio 2022
-> Means CMake will default to x64 -> vcpkg will use VCPKG_TARGET_TRIPLET=x64-windows
vcpkg_rf.txt: install drogon
-> Means you use a response file to install drogon. Without specifying the triplet this is x86-windows
As such your triplet used by CMake and vcpkg doesn't agree. Consider using vcpkg in manifest mode by providing a vcpkg.json with the dependency instead of a response file. This way you won't have a discrepancy in your triplet selection
(As always chanigng this also requires to delete the cmake cache for a clean reconfigure. Furthermore don't have spaces in your target and paths; you are just asking for trouble.)

CMake Error at C:\Users\...\Desktop\imgwarp-opencv\imgwarp-opencv\src\CMakeLists.txt:2 (FIND_PACKAGE)

I am using Window 10, Visual Studio 2017. I have installed OpenCV properly and I can run some basic projects of C++ OpenCV that can be found around the internet.
I have also followed this video which shows How to Build Open Source Projects Using CMake and Visual Studio.
But, I can not run this project on my machine. I try File->Open->CMake to open the CMakeLists.txt which can be found in the downloaded repository, and I get this error:
CMake Error at C:\Users\Majid\Desktop\imgwarp-opencv\imgwarp-opencv\src\CMakeLists.txt:2 (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 think I must extract the downloaded opencv-4.0.1-vc14_vc15.exe file somewhere in the project folder and link the CMakeLists.txt file (which one?) to the OpenCVConfig.cmake which is in the extracted opencv. Or maybe not.
I have also CMake gui and if I should run it that way I will appreciate that you explain it that way instead of using Visual Studio File->Open->CMake. No matter how, any way that helps me run this project is welcome. Please explain it step by step.
In one line (forget all the above): What should I do to run this project properly?

CMake "find_package" command on a package that was not installed is unexpectedly successful

I am following chapter-02/recipe-06 in "CMake Cookbook". This particular example requires the Eigen C++ libraries.
I attempted to build the example and got the error that Eigen was not found.
CMake Error at CMakeLists.txt:9 (find_package):
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.
This was expected because the library was not installed on my system.
I then downloaded the ".zip" file for the Eigen libraries and unzipped it to an arbitrary location outside of my project. I created a "build" folder in the Eigen directory and ran cmake .. in the "build" folder. (I only ran cmake - I did NOT build or install the package.)
After running CMake on the Eigen build directory, I went back to the example code for "recipe-06" and it was magically able to find the Eigen library and built successfully even though Eigen was never built or installed.
Somehow just running CMake in the Eigen project made CMake aware of the Eigen libraries location. After doing this, any projects that do find_package to find Eigen3 somehow get the ${Eigen3_DIR} variable defined and are able to find it.
Looking at the CMake documentation for find_package I don't see any explanation of why this works. Eigen is not in any of the typical locations that find_package searches. According to the documentation it looks like it should NOT be found.
Even more interesting - it doesn't matter where I put Eigen on my system. I can put it literally anywhere and it will still find it.
According to everything I see in the documentation it should not be found... but it is found. So the question is how? Why does this work?
Additional info: I am using CMake version 3.13.3
There are 2 "origins" of XXXConfig.cmake files, used internally by find_package() call.
Usually, XXXConfig.cmake file is produced when the project is installed, and the file contains information about installed libraries and headers.
But CMake provides also an export() command, which allows to export build tree.
export(PACKAGE <name>)
Store the current build directory in the CMake user package registry for package <name>. The find_package command may consider the directory while searching for package <name>.
Eigen's CMakeLists.txt uses export() command, so the project becomes detectable with find_package just after running cmake for Eigen.

OpenCV Environment variable changed

I had my standalone installation of OpenCV on my Linux machine and it was running OK. I installed ROS (comes with its OpenCV) and today I cannot run my CMakeLists.txt in any of my OpenCV projects, getting the error of :
CMake Error at CMakeLists.txt:20 (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 am kinda sure this happened because some environment variable got changed however I don't know where to look at.
Could someone walk me through this?
Reinstalling OpenCV solved the problem for me, since it re-modified the Environment variable.

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"