Getting ready

We will start out with the following CMake project:

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-06 LANGUAGES NONE)macro(custom_include_guard)  if(NOT DEFINED included_modules)    set(included_modules)  endif()  if ("${CMAKE_CURRENT_LIST_FILE}" IN_LIST included_modules)    message(WARNING "module ${CMAKE_CURRENT_LIST_FILE} processed more than once")  endif()  list(APPEND included_modules ${CMAKE_CURRENT_LIST_FILE})endmacro()include(cmake/custom.cmake)message(STATUS "list of all included modules: ${included_modules}")

This code defines a custom include guard, includes a custom module (the same module as in the previous recipe), and prints the list of all included modules. For CMake 3.10 and higher, we now know from the ...

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.