diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0ae37d7..2ec2089 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,20 +1,22 @@ -cmake_minimum_required(VERSION 3.0 FATAL_ERROR) - -project(cppzmq-test CXX) - -# place binaries and libraries according to GNU standards - -include(GNUInstallDirs) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) - -include(CTest) -include(cmake/catch.cmake) -include(${CATCH_MODULE_PATH}/Catch.cmake) - find_package(Threads) +find_package(Catch2 QUIET) + +if (Catch2_FOUND) + include(Catch) +else() + include(FetchContent) + + FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v2.13.4) + + FetchContent_MakeAvailable(Catch2) + + list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/contrib) +endif() + add_executable( unit_tests buffer.cpp @@ -32,11 +34,10 @@ add_executable( utilities.cpp ) -add_dependencies(unit_tests catch) - target_include_directories(unit_tests PUBLIC ${CATCH_MODULE_PATH}) target_link_libraries( unit_tests + PRIVATE Catch2::Catch2 PRIVATE cppzmq PRIVATE ${CMAKE_THREAD_LIBS_INIT} ) @@ -48,4 +49,6 @@ if (COVERAGE) target_link_libraries(unit_tests PRIVATE --coverage) endif() +include(CTest) +include(Catch) catch_discover_tests(unit_tests) diff --git a/tests/cmake/catch.cmake b/tests/cmake/catch.cmake deleted file mode 100644 index d774669..0000000 --- a/tests/cmake/catch.cmake +++ /dev/null @@ -1,27 +0,0 @@ -include(ExternalProject) - -ExternalProject_Add( - catch - PREFIX ${CMAKE_BINARY_DIR}/catch - URL "https://raw.githubusercontent.com/catchorg/Catch2/Catch1.x/single_include/catch.hpp" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" - DOWNLOAD_NO_EXTRACT ON -) - -# Expose variable CATCH_MODULE_PATH to parent scope -ExternalProject_Get_Property(catch DOWNLOAD_DIR) -set(CATCH_MODULE_PATH ${DOWNLOAD_DIR} CACHE INTERNAL "Path to include catch") - -# Download module for CTest integration -if(NOT EXISTS "${CATCH_MODULE_PATH}/Catch.cmake") - file(DOWNLOAD "https://raw.githubusercontent.com/catchorg/Catch2/90e2549cecc2e886d563b7a88e752c9b4104f798/contrib/Catch.cmake" - "${CATCH_MODULE_PATH}/Catch.cmake") -endif() -if(NOT EXISTS "${CATCH_MODULE_PATH}/CatchAddTests.cmake") - file(DOWNLOAD "https://raw.githubusercontent.com/catchorg/Catch2/90e2549cecc2e886d563b7a88e752c9b4104f798/contrib/CatchAddTests.cmake" - "${CATCH_MODULE_PATH}/CatchAddTests.cmake") -endif() -