Working with CMake
This is a developer-oriented introduction to CMake and how to modify the CMake build scripts.
We assume you already know the basics of how to use cmake to configure and build Inkscape (if not, see Inkscape's README).
Functions and Variables
cmake has its own language and syntax, but it's pretty simple. Essentially, everything is a function call.
message("Hello world!")
Even just setting variables is a function call:
set(MYVAR "foobar")
Function calls have parenthesis but arguments aren't separated with commas. CMake isn't strict about casing for function names, so SET() and set() are equivalent, but it is strict about variable name casing. We'll adopt the convention of keeping function names lower case, and variable names upper case.
Strings don't always have to be quoted, although it's also a good convention to follow. So, these are all equivalent:
SET(MYVAR "foobar") set(MYVAR foobar) SET(MYVAR foobar)
Variables are referenced using a dollar sign and curly brackets:
set(MYVAR "foobar") message("${MYVAR}")
Your First CMake Script
You now know enough to create a trivial cmake program.
Create an empty directory and open a file named 'CMakeLists.txt' in your favorite text editor.
mkdir cmake-tutorial cd cmake-tutorial gedit CMakeLists.txt
Type the following lines into this CMakeLists.txt file:
set(MYVAR "foobar") message("${MYVAR}")
Save the text file, exit your editor, and run cmake in this directory:
$ cmake . foobar -- Configuring done -- Generating done -- Build files have been written to: /tmp/cmake-tutorial