Where should I install FindXXX.cmake file of my own project and how to find it? - cmake

I am developing two CMake projects: libABC and libXYZ. libXYZ requires libABC, and so I would like install FindABC.cmake in an appropriate location on Mac and Linux machines.
libABC and its related files are installed under /usr/local by default, and I think FindABC.cmake also should be installed under the same directory. I tried installing it in the following six different locations.
/usr/local/lib/cmake/ABC/FindABC.cmake
/usr/local/share/cmake/ABC/FindABC.cmake
/usr/local/lib/ABC/FindABC.cmake
/usr/local/share/ABC/FindABC.cmake
/usr/local/lib/ABC/cmake/FindABC.cmake
/usr/local/share/ABC/cmake/FindABC.cmake
However CMakeList.txt of libXYZ cannot find it with the following error.
CMake Error at CMakeLists.txt:51 (find_package):
By not providing "FindABC.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"ABC", but CMake did not find one.
My cmake command was installed under /opt/local by using MacPorts on OS X. So I think it searches not /usr/local but only /opt/local.
I know that defining CMAKE_MODULE_PATH when executing cmake command solve this issue (e.g., cmake -DCMAKE_MODULE_PATH=/usr/local/lib/cmake/ABC), but I do not want to ask all users to do it every time.
My questions are
Q1. Where should I install FindABC.cmake during the libABC installation process?
Q2. How do I properly find FindABC.cmake in CMakeLists.txt of libXYZ without hard-coding CMAKE_MODULE_PATH in it?

Related

clion wsl "CMake 3.20 or higher is required. You are running version 3.16.3"

so I just downloaded wslusing the wsl --install command using PowerShell
now I'm trying to connect it to Clion which works
i cant add images so here is a link to it
but when i'm tying to build the project i get this error
"CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.20 or higher is required. You are running version 3.16.3"
my cmake file:
cmake_minimum_required(VERSION 3.20)
project(ex2 C)
set(CMAKE_C_STANDARD 99)
add_executable(ex2
ex2.c ex2.h
main1.c
main2.c)
i tried updating wsl using wsl --update (in powershell)
The CMake installation inside the WSL is used. Unfortunately currently snap doesn't seem to be available in WSL, but installing the latest CMake version isn't too complicated nonetheless:
(optional) uninstall the old cmake installation in WSL; personally I don't see any benefit in multiple CMake installations, but there may be valid reasons for this. Most likely this will just makes the use of cmake more complex, since you need to remember which cmake version is used.
Download the appropriate cmake version from the cmake website ( https://cmake.org/download/ ). The version to choose is the tar.gz file under binary distributions for the x86_64 target. To get version 3.21.4 (currently the latest release), you can download the file from https://github.com/Kitware/CMake/releases/download/v3.21.4/cmake-3.21.4-linux-x86_64.tar.gz (Identical to the link on the CMake download page).
Unpack the archive from WSL. Navigate to the directory where you want the cmake installation to recide. This will add the cmake-3.21.4-linux-x86_64 directory containing all the files required to work with cmake to the current working directory. Let's assume you want to add the cmake files to the /opt directory. Furthermore let's assume the windows user name to be fabian, C: to be the primary hard drive and the download to be saved to the Downloads directory in the user directory:
cd /opt
tar -xf /mnt/c/Users/fabian/Downloads/cmake-3.21.4-linux-x86_64.tar.gz
(optional) make CMake available without specifying the path; this could be done as described here: https://unix.stackexchange.com/questions/3809/how-can-i-make-a-program-executable-from-everywhere ; don't do this, if an existing cmake installation is already available in the command line assuming you did install cmake to /opt, the cmake binary recides at /opt/cmake-3.21.4-linux-x86_64/bin
You should now be able to use cmake specifying either the full path to the executable (/opt/cmake-3.21.4-linux-x86_64/bin/cmake assuming you used the /opt directory) or directly via a command after opening the WLS commandline again (provided you followed step 4).
Now the only thing left to do should be telling CLion about the location of the cmake executable. Note that I haven't tested this, since I don't use this IDE. It's working fine using Visual Studio Code though...

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?

How can I use cmake to locate jupyter notebook installation

Is there a way to use cmake find_package() to locate jupyter_notebook installation?
I tried
FIND_PACKAGE(jupyter-notebook REQUIRED)
but it errors out with
CMake Error at CMakeLists.txt:15 (FIND_PACKAGE):
By not providing "Findjupyter-notebook.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"jupyter-notebook", but CMake did not find one.
Could not find a package configuration file provided by "jupyter-notebook"
with any of the following names:
jupyter-notebookConfig.cmake
jupyter-notebook-config.cmake
Add the installation prefix of "jupyter-notebook" to CMAKE_PREFIX_PATH or
set "jupyter-notebook_DIR" to a directory containing one of the above
files. If "jupyter-notebook" provides a separate development package or
SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
However, it has been installed:
apt-cache show jupyter-notebook
There are a few options when using the find_package command, MODULE and CONFIG. For this case, you likely want the CONFIG setting. The error message is trying to help here. Did either of these files come with the jupyter-notebook installation?
jupyter-notebookConfig.cmake
jupyter-notebook-config.cmake
If so, try setting CMAKE_PREFIX_PATH or jupyter-notebook_DIR to the directory where jupyter-notebook was installed. So you might try something like the following:
list(APPEND CMAKE_PREFIX_PATH /path/to/your/installation) # Try this one.
# SET(jupyter-notebook_DIR /path/to/your/installation) # Or try this one.
FIND_PACKAGE(jupyter-notebook CONFIG REQUIRED)
If your installation does not appear to have the aforementioned CMake config files, nor does it appear to have any CMake support files (a cmake directory, etc.), the find_program command is likely more appropriate for jupyter-notebook.
I suggest spending some time with the documentation for find_package, as it explicitly lays out the search paths (in order) CMake uses to find your packages. Also, check out this answer.

Why won't find_library find libgmp

I'm trying to build a cmake project, and the repo I have been given has the lines
find_library(gmp gmp)
if(NOT gmp)
message(FATAL_ERROR "gmp not found")
endif()
which cause CMake configuration to fail.
I have been told this CMake works on Redhat Enterprise Linux 7.3.
I have also been told this repo should build in any Linux environment with the correct libraries installed, and an Ubuntu environment has been specifically referenced.
I am building in Debian 9.4.0, I have installed gmp, libgmp.so is located at /usr/lib/x86_64-linux-gnu/openssl-1.0.2/engines/libgmp.so
and I also have a libgmp.so.10 at /usr/lib/x86_64-linux-gnu/libgmp.so.10.
So, to recap, I have been handed a repo I have been told builds, but it does not build, it fails at this specific step, and I can't get google to give me any relevant results on how to fix the issue/what I am doing wrong.
libgmp is installed, but the development libraries are not.
Cmake find_libraries looks for the files required for software development, and while the libgmp package is installed, the libgmp-dev package is not.
Install libgmp-dev.
CMake doesn't search "so-version" files:
If find_library is called for "gmp" library name, CMake searches libgmp.so file, but not libgmp.so.10 one.
Normally, the library file without so-version is just a soft link to the newest so-version file. If your Linux distro doesn't create such link, you may create it manually:
ln -s libgmp.so libgmp.so.10
If you want CMake to find /usr/lib/x86_64-linux-gnu/openssl-1.0.2/engines/libgmp.so file, which is not under directory normally searched by CMake, you need to hint CMake about it. E.g. with PATHS option:
find_library(gmp gmp PATHS "/usr/lib/x86_64-linux-gnu/openssl-1.0.2/engines")

kdev-ruby's CMakeFile.txt requires weird stuff like KF5Config.cmake

I'm trying to compile a Ruby plugin for KDevelop: https://github.com/KDE/kdev-ruby
When I cut a folder called build, cd build, and run cmake .., I get lots of errors:
CMake Error at CMakeLists.txt:13 (include):
include could not find load file:
KDEInstallDirs
CMake Error at CMakeLists.txt:14 (include):
include could not find load file:
KDECMakeSettings
CMake Error at CMakeLists.txt:15 (include):
include could not find load file:
KDECompilerSettings
CMake Error at CMakeLists.txt:16 (include):
include could not find load file:
ECMQtDeclareLoggingCategory
CMake Error at CMakeLists.txt:24 (find_package):
By not providing "FindKF5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "KF5", but
CMake did not find one.
Could not find a package configuration file provided by "KF5" (requested
version 5.15.0) with any of the following names:
KF5Config.cmake
kf5-config.cmake
Add the installation prefix of "KF5" to CMAKE_PREFIX_PATH or set "KF5_DIR"
to a directory containing one of the above files. If "KF5" provides a
separate development package or SDK, be sure it has been installed.
How, on Ubuntu, do I install something that provides KF5Config.cmake? Preferably without rebuilding KDevelop or KDE or Qt5.
KDevelop relies on the development headers for various libraries, and finds them via the accompanying CMake files.
The build also uses CMake modules provided by the extra-cmake-modules package.
You must install that and libkf5config-dev.
The apt-file command might help you find the relevant packages for your distro in these situations.