How to do it

Deprecating functions, macros, and variables can be done as follows:

  1. First, we define a function that we will use to deprecate a variable:
function(deprecate_variable _variable _access)  if(_access STREQUAL "READ_ACCESS")    message(DEPRECATION "variable ${_variable} is deprecated")  endif()endfunction()
  1. Then, if the version of CMake is greater than 3.9, we redefine custom_include_guard and attach variable_watch to included_modules:
if (CMAKE_VERSION VERSION_GREATER "3.9")  # deprecate custom_include_guard  macro(custom_include_guard)    message(DEPRECATION "custom_include_guard is deprecated - use built-in include_guard instead")    _custom_include_guard(${ARGV})  endmacro()  # deprecate variable included_modules variable_watch(included_modules ...

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.