How to Understand CMake Syntax
What keeps developers away from C/C++ isn’t memory safety, but build systems
tl;dr:
Think CMake as shell commands, not function calls.
Example
This is first few effective lines from Dawn CMakeLists.txt:
cmake_minimum_required(VERSION 3.22)
project(
Dawn
DESCRIPTION "Dawn, a WebGPU implementation"
LANGUAGES C CXX
HOMEPAGE_URL "https://dawn.googlesource.com/dawn"
VERSION 0.0.0
)
enable_testing()
list(INSERT CMAKE_MODULE_PATH 0 "${Dawn_SOURCE_DIR}/src/cmake")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
It can be imagined like this:
cmake-minimum-required --version 3.22
project Dawn \
--description "Dawn, a WebGPU implementation" \
--languages C CXX \
--homepage-url "https://dawn.googlesource.com/dawn" \
--version 0.0.0
enable-testing
list --insert CMAKE_MODULE_PATH 0 "${Dawn_SOURCE_DIR}/src/cmake"
set-property --global --property USE_FOLDERS on
Of course, you should still write CMake in the formal form.
It’s still a nightmare!
Now it’s time to Google and Stack Overflow.