How it works

This is an example where no code is compiled and no language support is required, and we have indicated this by LANGUAGES NONE:

project(recipe-02 LANGUAGES NONE)

We defined the define_colors macro and placed it in cmake/colors.cmake. We chose to use a macro and not a function since we also wish to use the variables defined inside the macro in the scope of the call to change colors in the messages. We have included the macro and called define_colors using the following lines:

include(colors)define_colors()

However, we also need to tell CMake where to look for the macro:

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

The include(colors) command instructs CMake to search ${CMAKE_MODULE_PATH} for a module with ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.