Skip to content

Commit 197f8d2

Browse files
committed
update cmake for catch2
1 parent 1ae57c9 commit 197f8d2

File tree

2 files changed

+16
-40
lines changed

2 files changed

+16
-40
lines changed

tests/CMakeLists.txt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
1+
find_package(Threads)
22

3-
project(cppzmq-test CXX)
3+
find_package(Catch2 QUIET)
44

5-
# place binaries and libraries according to GNU standards
5+
if (Catch2_FOUND)
6+
include(Catch)
7+
else()
8+
include(FetchContent)
69

7-
include(GNUInstallDirs)
8-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
9-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
10-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
10+
FetchContent_Declare(
11+
Catch2
12+
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
13+
GIT_TAG v2.13.4)
1114

12-
include(CTest)
13-
include(cmake/catch.cmake)
14-
include(${CATCH_MODULE_PATH}/Catch.cmake)
15+
FetchContent_MakeAvailable(Catch2)
1516

16-
find_package(Threads)
17+
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/contrib)
18+
endif()
1719

1820
add_executable(
1921
unit_tests
@@ -32,11 +34,10 @@ add_executable(
3234
utilities.cpp
3335
)
3436

35-
add_dependencies(unit_tests catch)
36-
3737
target_include_directories(unit_tests PUBLIC ${CATCH_MODULE_PATH})
3838
target_link_libraries(
3939
unit_tests
40+
PRIVATE Catch2::Catch2
4041
PRIVATE cppzmq
4142
PRIVATE ${CMAKE_THREAD_LIBS_INIT}
4243
)
@@ -48,4 +49,6 @@ if (COVERAGE)
4849
target_link_libraries(unit_tests PRIVATE --coverage)
4950
endif()
5051

52+
include(CTest)
53+
include(Catch)
5154
catch_discover_tests(unit_tests)

tests/cmake/catch.cmake

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)