From the course: Advanced C++: Building Projects with CMake

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Refactoring with functions and macros

Refactoring with functions and macros - C++ Tutorial

From the course: Advanced C++: Building Projects with CMake

Refactoring with functions and macros

- [Instructor] By now, our build setup is working and growing. We've added the core and filters libraries, integrated the CLI tool, and even included an external header only dependency. But if you take a look inside the libs core and libs filters CMakelists.txt files, you will see some repetition. Let me open them side by side and close the terminal. So each library uses ad library sets and include directory and the filters library links to the image light core library. Now this is the perfect time to introduce CMake functions, a way to wrap this common logic into a reusable helper. I will define a new function called add image light module in the top level CMakelists.txt. Let's insert this function just before the add subdirectory lines. This is important because otherwise, the subdirectories wouldn't find the function they need to use it, and therefore, we need to define this function before including the subdirectories. And here's our ad image light module function. It takes the…

Contents