CMake
CMake is the most widely used C++ build system, so liblsl and most labstreaminglayer apps use it to build binaries for all major platforms.
Command Line Options
The basic options for the first run, i.e. to create a build folder and apply some settings are:
- -S path/to/the/build/folder
(optional, if not set the current working directory is used)
- -B path/to/the/build/directory
where the build files will be written
- -DVARIABLENAME=value
Set a CMake variable, e.g.
cmake -DCMAKE_BUILD_TYPE=Release.
- -G "Generator"
See Generators
cmake -S . -B build -DLSL_UNITTESTS=1 -G Ninja.
Common Variables
Some often used CMake variables:
CMAKE_INSTALL_PREFIX (default:
build/install)CMAKE_BUILD_TYPE (default:
Release)QT5_DIR
Generators
On the first run, a CMake Generator
can be specified via the -G option to set the native build system.
The defaults are Makefiles on Unix and a Visual Studio version on Windows.
Example: cmake -G "Visual Studio 16 2019"
Building a project
Once a build folder is populated successfully, the binaries can be built either
with the native build system (e.g. ninja install, msbuild …) or you can
let CMake figure out which build system is used and how to run it via
cmake --build path/to/build/folder --config Release -j --target install.
See Build a Project.
Targets
A target is either a binary to be
built (e.g. the liblsl target builds lsl.dll on Windows, the
LabRecorder target builds LabRecorder.exe and so on), a command
to be run or an internal CMake target.
The most important CMake targets are:
clean
cmake --build . --target clean removes all built binaries but keeps the CMake configuration.
install
CMake places built binary files as well as build sideproducts in a build folder that should be separate from the source directory. To copy only the needed files (and additional library files they depend on) to a folder you can share with colleagues or copy onto another PC, you need to ‘install’ them. This doesn’t mean ‘installing’ them in a traditional sense (i.e., with Windows installers or package managers on Linux / OS X, see package for that), but only copying them to a separate folder and fixing some hardcoded paths in the binaries.
package
CMake can create packages for installed targets, e.g. ZIP files, Windows installers or Debian / Ubuntu packages.
See the CPack manual for more information.