I am trying to set up a learning project using Catch2 and I decided that it was best to clone the repository in a Cpp folder, so I could get updates and use it for other C++ projects. The installing method is as described here.
The basic folder structure is:
Cpp
├───TestProject
│ ├───main.cpp
│ ├───.vscode
│ └───build
│ ├───CMakeFiles
│ └───Testing
└───Catch2
├─── ...
...
As per Catch2 documentation I put this on my CMake file:
find_package(Catch2 REQUIRED)
target_link_libraries(tests Catch2::Catch2)
However, when I try to configure the project in VS Code, I get the following error message:
[cmake] CMake Error at CMakeLists.txt:5 (target_link_libraries):
[cmake] Cannot specify link libraries for target "tests" which is not built by this
[cmake] project.
main.cpp
is just a Hello World file and the complete CMakeLists.txt file contents are:
cmake_minimum_required(VERSION 3.0.0)
project(TestProject VERSION 0.1.0)
find_package(Catch2 REQUIRED)
target_link_libraries(tests Catch2::Catch2)
enable_testing()
add_library(TestProject TestProject.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
I am unsure why this happens. I am a complete newcomer to CMake, save for very basic commands I had to use at work. I guess it would be less work to just drop it as a header file like it's intended to, but this approach made more sense to me...
Note: I have read this SO question. However his question had to do with Catch2 as a header file inside the project.
Note 2: desired behaviour is to build the project using Catch2 as an external library.
(Additional information: CMake --version is 3.13.3, using CMakeTools in VS Code, OS is Windows 10)