You have to think of your folder structures as an "Interface". Then there's three interfaces:
- source interface
- build interface
- install interface
Each interface has a different folder structure with different files in it. The install interface is just the folder structure you get by installing with cmake. Essentially, it takes all your relevant files lying around in your build folder and creates a nice folder structure which other projects can use.
Typically, in an out-of-source build (what is best practice), your source interface will be a subfolder of your project root, e.g. src
or source
. You then typically configure, generate and build your lib to a directory build
which lives right next to src
so that your project structure looks like this:
source and build interfaces:
project_root
├── CMakeLists.txt
├── src
│ └── CMakeLists.txt
├── build
│ └── CMakeCache.txt
...
So that covers the source and build interfaces. But what about the install interface? Answer: The install interface goes wherever the user wants it to go to. The location is specified by CMAKE_INSTALL_PREFIX. You can override it by specifying the --prefix
argument
cmake --install . --prefix "/where/I/want/it/to/go"
This would create the install interface according to the install()
-rules you declared in your CMakeLists.txt
. For example if using a default layout using GNUInstallDirs
(highly recommended even for windows), this would create a folder structure under /where/I/want/it/to/go/project_root like so:
install interface:
project_root
├── bin
│ └── executables
├── sbin
│ └── sysadmin executables
├── lib
│ ├── compiled libraries (*.so (unix) or *.dll (windows))
│ └── library archive files (*.lib (windows))
├── libexec
│ └── executables not directly invoked by user
├── include
│ └── header files
├── doc
│ └── documentation
You can see that almost all of the nonsense that we used for developing has vanished and we're left with a pure directory that contains mostly precompiled stuff that other apps can use. You would use the install interface of a project B if your project depends on B and you know that it's going to be installed on windows or linux platforms. The install interface is typically not of much use when developing for embedded systems that only run minimal operating systems or none at all, in this case you would build your whole app using the source interface of project B by including it in your project and add it using add_subdirectory()
install
does what it kind of implies, in which it will install whatever targets you specify (in this case${PROJECT_NAME}_node
and${PROJECT_NAME}
to the destinations you've specified for each target configuration (ARCHIVE
,LIBRARY
, andRUNTIME
). – SteffensC:/MyProject
- Inside your project you have your source files and respective CMakeLists.txt file underC:/MyProject/src
. When you specify yourinstall()
command like above, it will basically move everything you need to run your application into their respective folders where your executable expects them to be. For example, your .exe and .dll's will go into yourC:/MyProjects/bin
folder. .libs go installed in theC:/MyProjects/lib
folder, etc. You specify that destination after the keywordDESTINATION
. – Steffens