CMake

Have a CMakeLists.txt file in each directory that
contains project source code. The root folder of all the
directories containing CMakeLists.txt files is referred
to as the source directory.

The source directory along with the binary directory
constitute the set of folders that CMake performs builds
in. A out-of-source build is one where CMake is reading
from the source directory and writing artefacts to the
binary directory. This is the default. By default CMake
will not write into the source directory, only read from
it. A in-source build is where CMake is configured to
write artifacts into the source directory, in other words
where source and binary directory are the same.

out-of-source builds are easier to maintain, because by
checking in the source directory to a version control
system and leaving the binary directory unversioned,
you are sure to not commit artifacts. Also you can
erase the binary directory and clean your project that
way.

CMakeLists.txt files contain one or more CMake commands

A command has the syntax: command (args…) where
command is the name of a command and args is a white-
space separated list of arguments. (Arguments with
embedded white-space should be double quoted).
Commands are also used for controlling the program flow
if() else() endif()

Variables are defined using the ${VAR} syntax.
Assigning a value is done using set(Foo a b c) which
sets the variable Foo to the list of values a b and c.
Using a variable: command(${Foo}) which is equivalent to
command(a b c) if Foo has the values a b c set.

Environment variables can be used: $ENV{VAR}

Building from the command line:
CMake offers the –build option, which is described as a
convenience that allows you to build your project from the
command line even if this requires launching an IDE.
The syntax is:
cmake –build <dir> [options] [– [native-options]]
cmake –build . — -v
will build in the current working directory and pass the
parameter -v to the underlying build tool.

Open Questions

Can I build with CMake?


Q: If CMake is a tool to generate build configurations
for different platforms, why can eclipse use cmake to
directly build a binary for my project?
A: CMake offers the –build option, which is described as a
convenience that allows you to build your project from the
command line even if this requires launching an IDE

Where does the build folder and the contained folders
in my EclipseCDT project come from?


Q: When looking at my CMake project in EclipseCDT, it
has a build folder and a lot of folders and files below
it, where do these folders come from?
A: ???

Leave a Reply