cmake Using CMake to configure preproccessor tags

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

The use of CMake in a C++ project if used correctly can allow the programmer to focus less on the platform, program version number and more on the actual program itself. With CMake you can define preprocessor tags that allow for easy checking of which platform or any other preprocessor tags you might need in the actual program. Such as the version number which could be leveraged in a log system.

Syntax

  • #define preprocessor_name "@cmake_value@"

Remarks

It is important to understand not every preprocessor should be defined in the config.h.in. Preprocessor tags are generally used only to make the programmers life easier and should be used with discretion. You should research if a preprocessor tag already exists before defining it as you may run into undefined behavior on different system.



Got any cmake Question?