How to properly add catch2 (or any other dev only library) #8
-
I've been trying to understand what's the proper way to add catch2 dependency to my project. P.S. to exclude tests from cppcheck is it better to change the cppcheck preset, or to append the -itest flag to dev preset? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
The code you have to include in the @@ -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
|
Beta Was this translation helpful? Give feedback.
-
For the cppcheck part, you should include that in the |
Beta Was this translation helpful? Give feedback.
-
Catch2 is now provided by default when a package manager is used with the generated project. This is a not-so-recent addition. |
Beta Was this translation helpful? Give feedback.
The code you have to include in the
test/CMakeLists.txt
file looks like this:This consists of two parts:
Instruct CMake to go looking for a
Catch2
packagefind_package
operates in two modes, module mode and config mode, but in most cases you want to only care …