How to do it

We will introduce small modifications in the CMake code, as shown here:

  1. Only one additional line is added in the top-level CMakeLists.txt, since we will include a module located under cmake:
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  1. We keep src/CMakeLists.txt unmodified.
  2. In tests/CMakeLists.txt, we move the add_catch_test function definition to cmake/testing.cmake and define two tests:
add_executable(cpp_test test.cpp)target_link_libraries(cpp_test sum_integers)include(testing)add_catch_test(  NAME    short  LABELS    short    cpp_test  COST    1.5  )add_catch_test(  NAME    long  LABELS    long    cpp_test  COST    2.5  )
  1. The add_catch_test function is now defined in cmake/testing.cmake:
function(add_catch_test) set(options) ...

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.