Update cmake-integration.md (#2115)

* Update cmake-integration.md

CMake related, mainly more modern and provide an executable to be correct

Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
This commit is contained in:
Florian Berchtold 2020-12-28 13:41:55 +01:00 committed by GitHub
parent 965afc4b2e
commit 045feff834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,7 +25,8 @@ This means that if Catch2 has been installed on the system, it should be
enough to do: enough to do:
```cmake ```cmake
find_package(Catch2 REQUIRED) find_package(Catch2 REQUIRED)
target_link_libraries(tests Catch2::Catch2) add_executable(tests test.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2)
``` ```
@ -33,7 +34,8 @@ This target is also provided when Catch2 is used as a subdirectory.
Assuming that Catch2 has been cloned to `lib/Catch2`: Assuming that Catch2 has been cloned to `lib/Catch2`:
```cmake ```cmake
add_subdirectory(lib/Catch2) add_subdirectory(lib/Catch2)
target_link_libraries(tests Catch2::Catch2) add_executable(tests test.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2)
``` ```
Another possibility is to use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html): Another possibility is to use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html):
@ -47,7 +49,8 @@ FetchContent_Declare(
FetchContent_MakeAvailable(Catch2) FetchContent_MakeAvailable(Catch2)
target_link_libraries(tests Catch2::Catch2) add_executable(tests test.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2)
``` ```
## Automatic test registration ## Automatic test registration
@ -78,7 +81,7 @@ project(baz LANGUAGES CXX VERSION 0.0.1)
find_package(Catch2 REQUIRED) find_package(Catch2 REQUIRED)
add_executable(foo test.cpp) add_executable(foo test.cpp)
target_link_libraries(foo Catch2::Catch2) target_link_libraries(foo PRIVATE Catch2::Catch2)
include(CTest) include(CTest)
include(Catch) include(Catch)
@ -191,7 +194,7 @@ project(baz LANGUAGES CXX VERSION 0.0.1)
find_package(Catch2 REQUIRED) find_package(Catch2 REQUIRED)
add_executable(foo test.cpp) add_executable(foo test.cpp)
target_link_libraries(foo Catch2::Catch2) target_link_libraries(foo PRIVATE Catch2::Catch2)
include(CTest) include(CTest)
include(ParseAndAddCatchTests) include(ParseAndAddCatchTests)