Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of a .cmake file?

Tags:

I might be googling wrongly, but I'm unable to find what's the purpose of .cmake files.

I've just stumbled across the CMake tool for a project I've to work with and I'm having a hard time to understand how it works. I do understand that running the CMake command in a directory containing a CMakeLists.txt executes the commands in that file (along with the commands in the CMakeLists.txt contained in the sub-directories) but the purpose of .cmake files is a lot more fuzzy.

It seems that they are used to define functions/set variables that are thereafter used in the CMakeLists.txt but I'm not sure. How are they used by the CMake tool ?

like image 405
Getter Avatar asked Sep 27 '17 20:09

Getter


People also ask

What is .CMake file used for?

CMake is not a build system itself; it generates another system's build files. It supports directory hierarchies and applications that depend on multiple libraries. It is used in conjunction with native build environments such as Make, Qt Creator, Ninja, Android Studio, Apple's Xcode, and Microsoft Visual Studio.

How do I open a .CMake file?

Run cmake-gui.exe, which should be in your Start menu under Program Files, there may also be a shortcut on your desktop, or if you built from source, it will be in the build directory. A GUI will appear similar to what is shown below. The top two entries are the source code and binary directories.

Why is CMake necessary?

CMake handles the difficult aspects of building software such as cross-platform builds, system introspection, and user customized builds, in a simple manner that allows users to easily tailor builds for complex hardware and software systems.

What is CMakeLists TXT used for?

CMakeLists. txt file contains a set of directives and instructions describing the project's source files and targets (executable, library, or both). When you create a new project, CLion generates CMakeLists. txt file automatically and places it in the project root directory.


2 Answers

You can include it with the include command. Similar to how other languages allow you to split source files into modules or header files, they can contain function definitions, macros which can then be reused across multiple CmakeLists.

See https://cmake.org/cmake/help/v3.0/command/include.html

Note that you can actually include any file, but a .cmake extension is commonly used.

like image 76
André Avatar answered Sep 28 '22 09:09

André


Within this file you can define functions of macros which can be used in your CMakeLists.txt file. But there are some more other applications for .cmake files. For example if you want to provide a library or tool they should at least contain a <name>Config.cmake so that your library can be used with the find_package() command. Further information can be found in CMake Wiki

like image 23
FreshD Avatar answered Sep 28 '22 09:09

FreshD