How to do it

We will now describe how to configure, build, test, and finally, submit the test results for our example project to the dashboard:

  1. The source targets are defined in src/CMakeLists.txt, as follows:
# example libraryadd_library(sum_integers "")target_sources(sum_integers  PRIVATE    sum_integers.cpp  PUBLIC    ${CMAKE_CURRENT_LIST_DIR}/sum_integers.hpp  )target_include_directories(sum_integers  PUBLIC    ${CMAKE_CURRENT_LIST_DIR}  )# main codeadd_executable(sum_up main.cpp)target_link_libraries(sum_up sum_integers)
  1. The tests are defined in tests/CMakeLists.txt:
add_executable(test_short test_short.cpp)target_link_libraries(test_short sum_integers)add_executable(test_long test_long.cpp)target_link_libraries(test_long sum_integers)add_test( ...

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.