How it works

The new aspects in this recipe are the named arguments so we can focus on the cmake/testing.cmake module. CMake provides the cmake_parse_arguments command, which we call with the function name (add_catch_test) options (in our case, none), one-value arguments (here, NAME and COST), and multi-value arguments (here, LABELS, DEPENDS, and REFERENCE_FILES):

function(add_catch_test)  set(options)  set(oneValueArgs NAME COST)  set(multiValueArgs LABELS DEPENDS REFERENCE_FILES)  cmake_parse_arguments(add_catch_test    "${options}"    "${oneValueArgs}"    "${multiValueArgs}"    ${ARGN}    )  ...endfunction()

The cmake_parse_arguments command parses options and arguments, and defines the following in our case:

  • add_catch_test_NAME
  • add_catch_test_COST
  • add_catch_test_LABELS ...

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.