Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is cmake_install.cmake

I wrote a very simple HelloWorld.c program and ran Cmake. It created a cmake_install.cmake file in my build directory. Can somebody explain to me why CMake generated the file cmake_install.cmake? What is it's purpose and how can I use it?

CMakelists.txt :

cmake_minimum_required(VERSION 3.0)
PROJECT(FirstExample)
add_executable(prog first.c) 

Thanks!

like image 904
JecaJeca Avatar asked Sep 04 '14 15:09

JecaJeca


People also ask

How do I change my path in CMake?

CMake will use whatever path the running CMake executable is in. Furthermore, it may get confused if you switch paths between runs without clearing the cache. So what you have to do is simply instead of running cmake <path_to_src> from the command line, run ~/usr/cmake-path/bin/cmake <path_to_src> .

What is Cmake_current_list_dir?

CMAKE_CURRENT_LIST_DIR: Full directory of the listfile currently being processed. As CMake processes the listfiles in your project this variable will always be set to the directory where the listfile which is currently being processed (CMAKE_CURRENT_LIST_FILE) is located. The value has dynamic scope.

What is install command in CMake?

CMake provides the install command to specify how a project is to be installed. This command is invoked by a project in the CMakeLists file and tells CMake how to generate installation scripts. The scripts are executed at install time to perform the actual installation of files.

How do you clean after CMake?

Simply delete the CMakeFiles/ directory inside your build directory. rm -rf CMakeFiles/ cmake --build . This causes CMake to rerun, and build system files are regenerated. Your build will also start from scratch.


2 Answers

You generally don't use cmake_install.cmake directly. From the v3.12 page it states:

The install() command generates a file, cmake_install.cmake, inside the build directory, which is used internally by the generated install target and by CPack.

With your current CMakeLists.txt, the generated file doesn't do much. To create a useful install you would need to add more INSTALL commands to your CMakeLists.txt using the syntax below.

INSTALL(TARGETS targets... [EXPORT <export-name>]
    [[ARCHIVE|LIBRARY|RUNTIME|FRAMEWORK|BUNDLE|
      PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE]
     [DESTINATION <dir>]
     [INCLUDES DESTINATION [<dir> ...]]
     [PERMISSIONS permissions...]
     [CONFIGURATIONS [Debug|Release|...]]
     [COMPONENT <component>]
     [OPTIONAL] [NAMELINK_ONLY|NAMELINK_SKIP]
    ] [...])

For further reading on this command, check out the documentation site and wiki.

If it's desired to manually execute the script as stated by Nic30g the 3.12 page states that cmake -P accepts the following variables:

COMPONENT
Set this variable to install only a single CPack component as opposed to all of them. For example, if you only want to install the Development component, run

 cmake -DCOMPONENT=Development -P cmake_install.cmake

BUILD_TYPE
Set this variable to change the build type if you are using a multi-config generator. For example, to install with the Debug configuration, run

 cmake -DBUILD_TYPE=Debug -P cmake_install.cmake.

DESTDIR
This is an environment variable rather than a CMake variable. It allows you to change the installation prefix on UNIX systems. See DESTDIR for details.

like image 195
jmstoker Avatar answered Oct 17 '22 23:10

jmstoker


As previous answer tells, the cmake_install.cmake contains the commands generated by install command from your CMakeLists.txt.

You can execute it by cmake -P cmake_install.cmake and it performs the installation of your project even on windows.

https://cmake.org/pipermail/cmake/2007-April/013657.html

like image 21
Nic30g Avatar answered Oct 18 '22 00:10

Nic30g