Search⌘ K

Command Definitions: Macros

Explore how to define macros in CMake and understand their unique behavior compared to functions. Learn about variable scope, argument access, and side effects to write clearer build scripts for your C++ projects.

We'll cover the following...

Command definitions

There are two ways to define our own command: we can use the macro() command or the function() command. The easiest way to explain the differences between these commands is by comparing them to C-style preprocessor macrosMacros are predefined code snippets in programming that can be invoked with a specific name and expanded inline, typically used for code generation or to simplify repetitive tasks. and actual C++ functions:

  • A macro() command works more like a find-and-replace instruction than an actual subroutine call such as function(). Contrary to ...