Conditional Builds
Introduction
CMake allows you to conditionally include or exclude parts of your build based on variables, options, or system properties.
Key Concepts
if()
: Used to conditionally execute CMake code.target_compile_definitions()
: Adds compile definitions to a target.set()
: Used to conditionally set variables.
Code Sample
- Create
windows_specific.cpp
file with some dummy code.
- Create
unix_specific.cpp
file with some dummy code.
- Edit the CMakeListsFile.txt to include the extra sources and add them to the executable.