cmake find_package unable to find Eigen3Config.cmake spectra Windows - cmake

I am using Eigen3 with spectra (https://spectralib.org/), a library built on top of Eigen. Spectra uses find_package to find Eigen, and comes up with the error:
Could not find a package configuration file provided by "Eigen3" with any
of the following names:
Eigen3Config.cmake
eigen3-config.cmake
Looking through the directory of Eigen, I found that there were no files by those names, but rather one called Eigen3Config.cmake.in. I tried copying the file and renaming it Eigen3Config.cmake, but that gave me a different error of
find_package Error reading CMake code from "C:/Program Files
(x86)/Eigen3/cmake/Eigen3Config.cmake".
which was somewhat expected, but it does tell me that it can at least find the directory where Eigen3Config.cmake.in is. I'm assuming that either find_package is supposed to use Eigen3Config.cmake.in, or Eigen3Config.cmake.in is supposed to generate Eigen3Config.cmake, but i'm very new to cmake, so i'm not sure. How do I fix this?

There is no need to build/install Eigen to use it if you include it manually, as done in the getting started example (https://eigen.tuxfamily.org/dox/GettingStarted.html#title0)
But in order to be found by CMake, you will need to build / install it, as explained in the INSTALL file. https://gitlab.com/libeigen/eigen/-/blob/master/INSTALL
Usually, your error is followed by an hint asking you to set the variable Eigen3_DIR (or something similar) to point the build/install dir of the target project (Eigen3 here). It appears typically when you have built but not installed the project.
So:
Build Eigen
Install it (optional)
For spectra set the cmake var Eigen3_DIR to /path/to/Eigen/build . (if eigen not install or still not found)

These steps worked for me:
Install Eigen
Create a build directory for Eigen
cd into the build directory created
run "cmake ../"Your Eigen Source Directory""
After this is done, in your CMakeLists.txt of your project, you'll want to add "find_package( Eigen3 REQUIRED)" and "include_directories( ${EIGEN3_INCLUDE_DIR})".

Related

How to perform the "make install" step after building aws-sdk-cpp using Qt Creator and CMake

I am trying to add aws-sdk-cpp as a submodule in my Qt application using Qt Creator and CMake. I want it to build for any platform without doing the building and installing on the command line as described here.
My project structure and CMakeLists.txt files looks like this:
I have successfully built the entire aws-sdk-cpp using MSVC2019 in debug mode using Qt Creator. My projects build folder is now 15 GB containing all the built libraries. The current issue I'm now facing is this error:
CMake Error at app/CMakeLists.txt:23 (find_package):
By not providing "FindAWSSDK.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "AWSSDK", but
CMake did not find one.
Could not find a package configuration file provided by "AWSSDK" with any
of the following names:
AWSSDKConfig.cmake
awssdk-config.cmake
Add the installation prefix of "AWSSDK" to CMAKE_PREFIX_PATH or set
"AWSSDK_DIR" to a directory containing one of the above files. If "AWSSDK"
provides a separate development package or SDK, be sure it has been
installed.
I think what is missing is the make install step described here and to set the path to AWSSDK_DIR.
I'm very new to CMake and I have not found any way to perform the make install step in the CMakeLists.txt file and then be able to set the AWSSDK_DIR which points to the AWSSDKConfig.cmake or awssdk-config.cmake file missing.
I'm also not sure which CMakeLists.txt file this should be written or if there is an entire other way to do this? Currently I'm stuck getting nowhere..

How to instruct "find_package" to find a package installed in a user-specified location?

I installed a software package using CMake, on a customized location, with the command line below
cmake .. -DCMAKE_INSTALL_PREFIX=../install
Now CMake can no more find the package with the find_package. The error message suggests me to specify either CMAKE_MODULE_PATH or CMAKE_PREFIX_PATH.
I tried to specify the installation path using
cmake .. -DCMAKE_MODULE_PATH=../install
It did not work. But the following worked:
cmake .. -DCMAKE_PREFIX_PATH=../install
Question: In general, what would be the sound and reliable way to specify the path for "find_package" to work correctly for finding a package installed to a user-specified location?

Is it possible to alter CMAKE_MODULE_PATH from CMake commandline?

Edit: The accepted answer actually shows that it is pretty normally possible to set CMAKE_MODULE_PATH as any other CMake variable e.g. via the -DCMAKE_MODULE_PATH path CLI parameter. It seems that in my case there is some included CMake script that calls set(CMAKE_MODULE_PATH /library_path), which erases all previous paths set to the variable. That's why I couldn't get the variable to do what I wanted it to do. I'll leave the question here in case anybody else faces this kind of situation.
I'm building a (3rd party) project that uses the Protobuf library (but this question is general). My system has a system-wide install of a newer version of Protobuf than the project is compatible with. So I've downloaded and compiled from source an older version of Protobuf.
The project uses CMake, and in its CMakeLists.txt, there is:
find_package(Protobuf REQUIRED)
Which, however, finds the (incompatible) system install. Of course, CMake doesn't know about my custom build of Protobuf. But how do I tell it?
I've created a FindProtobuf.cmake file in, say, ~/usr/share/cmake-3.0/Modules/ and want the build process to use this one for finding Protobuf. But I haven't succeeded forcing CMake to pick up this one and not the system one. I think the reason is quite obvious from the CMake docs of find_package:
The command has two modes by which it searches for packages: “Module” mode and “Config” mode. Module mode is available when the command is invoked with the above reduced signature. CMake searches for a file called Find<package>.cmake in the CMAKE_MODULE_PATH followed by the CMake installation. If the file is found, it is read and processed by CMake. ... If no module is found and the MODULE option is not given the command proceeds to Config mode.
So until I succeed to change CMAKE_MODULE_PATH, CMake will just pick up the FindProtobuf.cmake installed to the default system path and won't ever proceed to the "Config" mode where I could probably make use of CMAKE_PREFIX_PATH.
It's important for me to not edit the CMakeLists.txt since it belongs to a 3rd party project I don't maintain.
What I've tried (all without success):
calling CMAKE_MODULE_PATH=~/usr/share/cmake-3.0/Modules cmake ... (the env. variable is not "transferred" to the CMake variable with the same name)
calling cmake -DCMAKE_MODULE_PATH=~/usr/share/cmake-3.0/Modules ... (doesn't work, probably by design?)
calling Protobuf_DIR=path/to/my/protobuf cmake ... (the project doesn't support this kind of override for Protobuf)
It seems to me that, unfortunately, the only way to alter the CMAKE_MODULE_PATH used by find_package is to alter it from within CMakeLists.txt, which is exactly what I want to avoid.
Do you have any ideas/workarounds on how not to touch the CMakeLists.txt and still convince find_package to find my custom Protobuf?
For reference, the CMake part of this project is on github .
As a direct answer to your question, yes, you can set CMAKE_MODULE_PATH at the command line by running cmake -DCMAKE_MODULE_PATH=/some/path -S /path/to/src -B /path/to/build.
But that probably doesn't do what you want it to do; see below.
The Bitbucket link you supplied is dead, but here are a few suggestions that might help.
Avoid writing your own find modules, especially when the upstream supplies CMake config modules.
You can direct CMake to your custom Protobuf installation by setting one of CMAKE_PREFIX_PATH or Protobuf_ROOT (v3.12+) to the Protobuf install root.
You can tell find_package to try CONFIG mode first by setting CMAKE_FIND_PACKAGE_PREFER_CONFIG to true (v3.15+). Then set Protobuf_DIR to the directory containing ProtobufConfig.cmake.
Failing all else, you can manually set the variables documented in CMake's own FindProtobuf module, here: https://cmake.org/cmake/help/latest/module/FindProtobuf.html
All these variables can be set at the configure command line with the -D flag.
There are very few environment variables that populate CMake variables to start and I would avoid relying on them. There is an exhaustive list here: https://cmake.org/cmake/help/latest/manual/cmake-env-variables.7.html. CMAKE_MODULE_PATH is not among them.

CMake does not compíle Qt5 generate from buildroot

I generate a tarball with Qt5 using Buildroot 2014.05.
When I uncompressed this files to compile my project using CMake I receive the following error message:
CMake Error at <project> /sysroot/usr/lib/cmake/Qt5Core/Qt5CoreConfig.cmake:27 (message):
The imported target "Qt5::Core" references the file
"<project>/host/usr/bin/qmake"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/<project>/sysroot/usr/lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake"
but not all the files it references.
I'm using the cmake configs under
<project>/sysroot/usr/lib/cmake/
and my CMakeLists.txt
set(CMAKE_PREFIX_PATH <project>/sysroot/usr/lib/cmake/QtWidgets/ )
find_package(Qt5Widgets REQUIRED)
Any suggestion?
Buildroot 2014.05 does not have qmake to install
This part: I generate a tarball with Qt5 using Buildroot does make much sense. What do you mean exactly by this ?
If by this you mean that you tarball'ed the contents of output/host/ (which is the toolchain and all the libraries that you need to build applications for your target), then beware that it is not relocatable. So it has to be installed in the same location as the one it was generated in. So for now, if you want to do this, you should set the BR2_HOST_DIR configuration option to something like /opt/<something>/, and then tarball that up and uncompress it on the other machines where you want to use the toolchain.
It's in our TODO-list to make this relocatable.

CMake could not find the VTKConfig.cmake

I'm trying to compile a program in CMake but I'm getting this error.
By not providing "FindVTK.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "VTK", but
CMake did not find one.
Could not find a package configuration file provided by "VTK" (requested
version 6.1) with any of the following names:
VTKConfig.cmake
vtk-config.cmake
I can't find the relevant files (VTKConfig.cmake or vtk-config.cmake) on the machine but do have VTKConfig.cmake.in (which also doesn't work).
Does anyone know where I can download the file from, or what I might be doing wrong.
It seems like you just have the VTK source code but haven't built it yet. VTKConfig.cmake.in is a template used by CMake to generate the VTKConfig.cmake file in the build and install directory. Look at http://www.vtk.org/Wiki/VTK/Building to see how to build VTK.
When you have successfully built VTK you can give CMake a hint where to look for VTK with the VTK_DIR-parameter:
cmake -DVTK_DIR=/path/to/vtk/build-directory /path/to/your/source-directory
If you have successfully built VTK, you would end up with a VTK-Release-build folder containing all the build files, one of which is VTKConfig.cmake. Your program is not able to find this file. You just need to set an environment variable named VTK_DIR before running your program. You can do so by running:
export VTK_DIR=/path/to/VTK-Release-build/
"FindVTK.cmake"the file of cmake is made in build directry.
please add this Path. export VTK_DIR=/path/VTK-Release-version/build