Elliptical view
Elliptical view

Reputation: 3812

Using cmake: General use of directories and especially default location of output binaries

1) When using cmake, is there a standard way to make the binaries be put in /usr/local/bin?


I'm trying to better understand cmake, especially the major phases, which I think are configure, make, and install.

I want to better understand which directories are used by default and why, for these:


I'm pretty new to Linux and started by making a fresh version of cmake, (which I need to use for another project), as follows:

By default it seemed to:


So I'm confused. I would have thought that by default a sudo install would have installed cmake in such a way into my system as to make it generally visible anywhere.


??? I'm not sure, but think the best way to make system resources visible is to either 1) locate the binaries, or 2) soft links to them, in folders somewhere in the standard PATH. In other words, don't extend PATH with each and every new set of binaries.

Is it possible to have cmake put the binaries in /usr/local/bin by default?


Yes I can make manual bin links:

I'm not asking this question because making these links is hard, but because I think I might be missing something that just does this without me having to. Also bin files are just one of the outputs. There are also things like man pages and how do those get hooked up?

I can also see that cmake uses two main directories

enter image description here

But this is confusing because the "..build the binaries.." directory you give can:

1) Overlap the source directory in which case it merges lots of new files and folders into it, or

2) If set to something like /usr/local/bin fills that with a bunch of junk which includes a secondary /bin with the actual binaries, or

3) If set to some other location like possibly /usr/local/projectname/output, still does not put the output binaries where they can automatically be used.

Is there a standard way to make the binaries be put in /usr/local/bin ?, (i.e. that my PATH will automatically pick up) or failing that, is the any simple and direct way to do this?


Tip:

Upvotes: 1

Views: 711

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 66338

Build directory is UNRELATED to the place, where deliverable files will be installed.

Build directory is a working directory, where compiler, linker and other tools generate deliverable files with some other auxiliary files. E.g., object files (.o) are auxiliary files: they are produced by compiler, used by the linker and are never installed. Also, build directory contains Makefiles and some other files, used by make.

When install files, make install takes deliverable files from build directory, and place them into their final locations. After that project is ready for use, and build directory can be removed.

Place, where deliverable files are installed, is controlled by variable

CMAKE_INSTALL_PREFIX

which you can set in cmake gui tool after the first configuration occures. Normally, binary files are installed into bin/ subdirectory relative to that prefix, so you may set CMAKE_INSTALL_PREFIX to /usr/local for get executables being installed into /usr/local/bin/.

As for build directory, you may create it anywhere. Usually, it is created in the directory where user has write access, so neither configuration nor build requires root priveleges. E.g., you may choose /home/<user>/cmake-build.

Upvotes: 2

Related Questions