Skip to content

How to properly add catch2 (or any other dev only library) #8

Answered by friendlyanon
fpicchi asked this question in Q&A
Discussion options

You must be logged in to vote

The code you have to include in the test/CMakeLists.txt file looks like this:

@@ -10,11 +10,8 @@
   enable_testing()
 endif()

+find_package(Catch2 REQUIRED)
+include(Catch)
+
 add_executable(example_test source/example_test.cpp)
-target_link_libraries(example_test PRIVATE example::example)
+target_link_libraries(example_test PRIVATE example::example Catch2::Catch2)
 target_compile_features(example_test PRIVATE cxx_std_17)

-add_test(NAME example_test COMMAND example_test)
+catch_discover_tests(example_test)

This consists of two parts:

Instruct CMake to go looking for a Catch2 package

find_package operates in two modes, module mode and config mode, but in most cases you want to only care …

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@fpicchi
Comment options

Answer selected by fpicchi
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants