Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is CMake equivalent of 'configure --prefix=DIR && make all install '?

Tags:

cmake

I do cmake . && make all install. This works, but installs to /usr/local.

I need to install to a different prefix (for example, to /usr).

What is the cmake and make command line to install to /usr instead of /usr/local?

like image 227
Andrei Avatar asked May 14 '11 16:05

Andrei


People also ask

What is prefix in CMake?

Classically the primary way of specifying the install directory is via CMAKE_INSTALL_PREFIX . With the introduction of cmake --install we added --prefix to override the existing CMAKE_INSTALL_PREFIX .

How install and configure CMake?

After copying CMake. app into /Applications (or a custom location), run it and follow the “How to Install For Command Line Use” menu item for instructions to make the command-line tools (e.g. cmake) available in the PATH. Or, one may manually add the install directory (e.g. /Applications/CMake.

What is installation prefix?

A prefix is the path on your host computer a software package is installed under. Packages that have a prefix will place all parts under the prefix path. Packages for your host computer typically use a default prefix of /usr/local on FreeBSD and Linux.

Where is Cmake_install_prefix?

Install directory used by install() . If make install is invoked or INSTALL is built, this directory is prepended onto all install directories. This variable defaults to /usr/local on UNIX and c:/Program Files/${PROJECT_NAME} on Windows.


1 Answers

You can pass in any CMake variable on the command line, or edit cached variables using ccmake/cmake-gui. On the command line,

cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr . && make all install

Would configure the project, build all targets and install to the /usr prefix. The type (PATH) is not strictly necessary, but would cause the Qt based cmake-gui to present the directory chooser dialog.

Some minor additions as comments make it clear that providing a simple equivalence is not enough for some. Best practice would be to use an external build directory, i.e. not the source directly. Also to use more generic CMake syntax abstracting the generator.

mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && cmake --build . --target install --config Release

You can see it gets quite a bit longer, and isn't directly equivalent anymore, but is closer to best practices in a fairly concise form... The --config is only used by multi-configuration generators (i.e. MSVC), ignored by others.

like image 51
Marcus D. Hanwell Avatar answered Oct 27 '22 21:10

Marcus D. Hanwell