EDIT2: in questi giorni Catch2 installa il proprio modulo di CMake così, dopo l'installazione, può essere utilizzato in un altro progetto CMake con
include(GNUInstallDirs)
find_package(Catch2 REQUIRED)
È possibile rendere il vostro progetto CMake dipendono Cattura utilizzando find_package
. In questo modo non includi Catch e puoi aggiornarlo indipendentemente. Il processo è spiegato in this recipe, tranne che in questo caso non è necessario gestire le librerie, poiché Catch è solo intestazione.
CMakeLists.txt (ammesso che abbiate il vostro FindCatch.cmake in atto [vedi sotto] e le vostre prove in my_tests.cpp):
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(Catch REQUIRED)
include_directories(${CATCH_INCLUDE_DIRS})
add_executable(my_tests my_tests.cpp)
add_test(NAME MyTests COMMAND my_tests)
Un esempio my_tests.cpp:
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main()
#include "catch/catch.hpp"
#include "stuff_to_test.h"
TEST_CASE("A test case")
{
...
}
...
Sarà necessario aggiungere un modulo FindCatch.cmake al progetto, sotto cmake/Modules
. Cerca nel web FindCatch.cmake.
Infine, è possibile creare ed eseguire i test con make test
.
EDIT: In alternativa, è possibile avere cmake scaricare Cattura da Git durante la costruzione, seguendo these instructions da github di Catch. Ciò richiede però una dipendenza da git.
C'è una discussione su CMake nella [documentazione di Catch's Build System] (https://github.com/philsquared/Catch/blob/master/docs/build-systems.md#cmake). – phoenix