Is there a CMake '--install' switch? - cmake

With reference to this question there is a so-called 'install' phase in CMake. I'm used to run CMake in a sequence that looks like this:
cmake ..
cmake --build . --config Debug
cmake --build . --config Release
Is there a cmake --install command line switch meant to be invoked after this?
Although I figure it is somehow related, I'm not looking for the so called install command here (I perceive this to be a function rather than a command, but this is likely a terminology issue).

No, this switch does not exist (until CMake 3.15, see my other answer).
If a project uses the install command, it generates the target install. You can call it with
cmake --build . --target install
This uses CMake's Build Tool Mode, which is an abstract interface for a couple of commands to the native build tool (e.g. make or Ninja) and can also be used to pass arbitrary arguments to the native build tool.

Beginning with version 3.15, CMake offers an install switch. From the release notes:
The "cmake(1)" command gained a new "--install" option. This may
be used after building a project to run installation without using
the generated build system or the native build tool.
Source: https://cmake.org/cmake/help/v3.15/release/3.15.html#id6
So you can use
cmake --install <dir> [--prefix <install-dir>]
The optional --prefix flag lets you override the CMAKE_INSTALL_PREFIX.

Related

How to use CMake to install

I can build my projects successfully with CMake, but can I use it to install the results?
With Make I add the target install and call that from the command line. I cannot figure out if this is possible with CMake.
The final goal is to install a static library, dynamic library and corresponding header files in a platform-portable way. How I imagine it would work: On Linux, copy to /usr/include and /usr/lib. On Windows it would probably be a user-provided folder with an include and lib folder.
The install rule suggests that something like this is possible. But how do I actually use it?
Currently I do the following:
mkdir build
cd build
cmake ..
cmake --build .
Here I would expect to do something like this:
cmake --install .
You can use the command cmake --build . --target install --config Debug for installation.
CMake's build tool mode supports further arguments that are of interest in this case.
You can select the target to build by --target option, the configuration to build by --config option, and pass arguments to the underlying build tool by means of the -- option. See the documentation (Build Tool Mode) for the build-tool-mode.
In CMake 3.15 and newer, you can use the simpler cmake --install command to Install a Project:
cmake --install . --config Debug
It additionally supports --prefix, --component and --strip.
You can use the install command on your CMakeLists that will generate installation rules for your project. A basic example is shown bellow but check the cmake documentation if you need something more complex.
project (Test)
add_executable(test main.cpp)
install(TARGETS test DESTINATION bin)
Then after generate the makefiles you can ust type sudo make install and the test application will be installed on system bin folder.

How to use CPack from CMake in bitbake

How is it possible to override bitbakes regular internal packaging function (do_package) and use CPack? So a normal CMake build looks like this:
cmake ../src
cmake --build ../src
cmake --build ../src --target install
So bitbake correctly handles all of this assuming I use the install command inside CMakeLists.txt and construct my recipes correctly. So building on that, I would like to use CMake's deb package generator to build my packages. Normally this would look something like this in a CMake build to generate the .deb packages after the above:
make package
or
cmake --build ../src/ --target package
I was hoping I didn't have to write a pile of custom functions.
Technically, yes. You'd have to reimplement do_package to call cmake and move the files into the right places.
Realistically, why? Packaging is mostly trivial.

CMake error not providing FindGnuradio.cmake

Getting the following error when running cmake and am unsure how to fix it. It seems like it's telling me exactly what to do, but not very familiar with Linux.
CMake Error at CMakeLists.txt:153 (find_package):
By not providing "FindGnuradio.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Gnuradio",
but CMake did not find one.
Could not find a package configuration file provided by "Gnuradio"
(requested version 3.7.3) with any of the following names:
GnuradioConfig.cmake
gnuradio-config.cmake
Add the installation prefix of "Gnuradio" to CMAKE_PREFIX_PATH or set
"Gnuradio_DIR" to a directory contaning one of the above files. If
"Gnuradio" provides a separate development package or SDK, be sure it has
been installed.
EDIT: So I've located something called FindGnuradioRuntime.cmake but am still unsure what to do with it. The error message makes me think it was looking for something named "FindGnuradio.cmake" when it was actually called "FindGnuradioRuntime.cmake"
Commands that were run on a fresh Ubuntu install:
git clone git://git.osmocom.org/rtl-sdr.git
cd rtl-sdr/
mkdir build
cd build
cmake ../
make
sudo make install
sudo ldconfig
git clone git://git.osmocom.org/gr-osmosdr
cd gr-osmosdr/
mkdir build
cd build/
cmake ../ (here is where I ran into a the problem above)
Install / build GNU Radio.
Remove the CMakeCache.txt
When you call cmake .. you can pass arguments. Add the path to the parent directory of GnuradioConfig.cmake or FindGnuRadio.cmake as in
cmake -DCMAKE_PREFIX_PATH=/gnu/radio/path ..
Making my somewhat hidden response an actual answer:
Just found out that the install script provided on GNURadio's website not only installs GNURadio, but also the RTL SDR requirements as well, so I wiped my VM and started over and was successful. It takes a few hours, but it is complete and automated so definitely the best way to install GNURadio. Script is here http://www.sbrac.org/files/build-gnuradio
As previous answers noted you didn't describe where you ran into this problem. I'm going to assume it happened when creating an Out Of Tree (OOT) module.
On the OOT Module Page, see the "Notes" Section. They note that you need to install gr-dev. That package will install GnuradioConfig.cmake. You can find it in the standard yum repos, and install it with sudo yum install gnuradio-devel.

Configuring Cmake Command-Line

I'm new to using the Cmake command-line. Using the GUI I can specify a source directory and a build directory then generate. It works just fine.
When I run the command-line variant I don't get any output in the build directory.
cmake -G "Visual Studio 12 2013 Win64" --build C:\MySource\Build C:\MySource
I also get other errors because it's trying to use Win32 yet I specify Win64.
Leave out the --build option. When you do the cmake configure step (equivalent to what happens by the cmake gui), you do not use --build. After you have generated the solution and projects you may build with cmake --build . --config Debug. (You can also specify which target to build with --target MyTarget.)
cd c:\MySource\Build
cmake -G "Visual Studio 12 2013 Win64" C:\MySource
cmake --build . --config Debug
For the configure step (with the -G option), you may use a relative directory .. rather than the absolute path--either way is fine.

For CMake's “install”, what does the CONFIGURATIONS argument do?

I don't know what the CONFIGURATIONS argument of CMake's install command does. When I use CONFIGURATIONS with debug or release in installing files, no file gets installed. What happened?
Can someone explain it in more detail. It will be best if you give me some examples.
P.S. This is not the same as: For CMake's "install" command, what can the COMPONENT argument do?
From the docs:
The CONFIGURATIONS argument specifies a list of build configurations for which the install rule applies (Debug, Release, etc.).
So for example, consider the following CMakeListst.txt:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(Test)
add_executable(MyTest main.cc)
install(TARGETS MyTest DESTINATION bin CONFIGURATIONS Release)
This means that
cmake --build . --target install --config Release
will place the executable MyTest (or MyTest.exe) in ${CMAKE_INSTALL_PREFIX}/bin, and
cmake --build . --target install --config Debug
won't install anything.