Difference between revisions of "CMake:Install Commands"

From KitwarePublic
Jump to navigationJump to search
(Remove leading space rectangles from preformatted blocks)
(Replace content with link to new CMake community wiki)
Line 1: Line 1:

CMake has an elaborate install process that simplifies installation of
This page has moved [https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/Install-Commands here].
programs, libraries, and other files. In CMake version 2.4 the new
'''INSTALL''' command was introduced that encompasses the functionality of all
the old '''install''' commands. This page describes the new '''INSTALL'''
command and the transition from the old one.
==Old INSTALL_* Commands==
; INSTALL_FILES : Create rules to install the listed files with the given extension into the given directory.  Only files existing in the current source tree or its corresponding location in the binary tree may be listed.  If a file specified already has an extension, that extension will be removed first.  This is useful for providing lists of source files such as foo.cxx when you want the corresponding foo.h to be installed.  A typical extension is '.h'.
INSTALL_FILES(<dir> extension file file ...)
INSTALL_FILES(<dir> regexp)
: Any files in the current source directory that match the regular expression will be installed.
INSTALL_FILES(<dir> FILES file file ...)
: Any files listed after the FILES keyword will be installed explicitly from the names given.  Full paths are allowed in this form. The directory <dir> is relative to the installation prefix, which is stored in the variable CMAKE_INSTALL_PREFIX.
; INSTALL_PROGRAMS : Create rules to install the listed programs into the given directory.  Use the FILES argument to guarantee that the file list version of the command will be used even when there is only one argument.
INSTALL_PROGRAMS(<dir> file1 file2 [file3 ...])
INSTALL_PROGRAMS(<dir> FILES file1 [file2 ...])
INSTALL_PROGRAMS(<dir> regexp)
: In the third form any program in the current source directory that matches the regular expression will be installed.  This command is intended to install programs that are not built by cmake, such as shell scripts. See the TARGETS form of the INSTALL command to create installation rules for targets built by cmake. The directory <dir> is relative to the installation prefix, which is stored in the variable CMAKE_INSTALL_PREFIX.
; INSTALL_TARGETS : Create rules to install the listed targets into the given directory.  The directory <dir> is relative to the installation prefix, which is stored in the variable CMAKE_INSTALL_PREFIX.  If RUNTIME_DIRECTORY is specified, then on systems with special runtime files (Windows DLL), the files will be copied to that directory.
INSTALL_TARGETS(<dir> [RUNTIME_DIRECTORY dir] target target)
==New INSTALL Command==
The new '''INSTALL''' command replaces all the old commands with a single
command. This command is much more flexible and provide a common interface for
all installation requirements.
In addition to all the old functionality, this command also provides a way to
install directories, run CMake scripts and inline CMake code, as well as a
'''component''' framework.
==Replacing The Old INSTALL_* Commands==
Each of the old commands can be replaced with a proper signature of the new
'''INSTALL''' command.
It is important to note that the new INSTALL command takes all the paths as
relative paths. If absolute path is provided, the absolute path will be used.
===Replace INSTALL_FILES===
Let say that we have files in source and build directory that we are trying to
install. These files are: file1.h, file2.h, file3.h, file4.hxx, file5.txt, and
file6.cmake. Assume file1.h, file2.h, file4.hxx, and file5.txt are in the
source tree, while all the other files are in the build tree.
INSTALL_FILES(/include .h file1.cxx file2.c file3.h)
INSTALL_FILES(/include "\.hxx")
INSTALL_FILES(/share/special_files FILES file5.txt
These lines are replaced with:
  DESTINATION include)
  DESTINATION share/special_files)
Assuming there are scripts scr1 and scr2, where scr2 is in the build directory.
The code in CMake list file would look like this:
This line is replaced with:
Assuming there are targets: ExecutableTarget, StaticLibraryTarget, and
SharedLibraryTarget. Typically there would be code in CMake list file that
would look like this:
INSTALL_TARGETS(/bin ExecutableTarget)
INSTALL_TARGETS(/lib StaticLibraryTarget)
These lines are replaced with:
INSTALL(TARGETS ExecutableTarget StaticLibraryTarget SharedLibraryTarget
'''RUNTIME''' refers to the runtime piece of the target. Runtime piece only
applies to executable targets and DLL (Windows) style shared libraries.
'''LIBRARY''' refers to all the other (non DLL) shared libraries and modules.
'''ARCHIVE''' refers to the static libraries and the import parts of DLL
libraries (LIB files).

Latest revision as of 10:40, 30 April 2018

The CMake community Wiki has moved to the Kitware GitLab Instance.

This page has moved here.