Following the build documentation causes a fail when building (cmake .. stage) on macOS Catalina.
Resolution is to clone and install Catch2. May be worth adding into build docs as a dependency. Resolved by setting up Catch2
$ git clone https://github.com/catchorg/Catch2
$ cd Catch2
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install
cmake .. will then complete and you can continue with the build process.
Yes, the person who made the latest cmake scripts told me about it. But I am not a master in cmake so I need someone's help here.
Hi there,
integration of catch2 is rather straight forward. You basically have two options, the first one is pulling catch2 from github directly (recommended) and the second one is to put the source files in this repo and create targets for it. Both are easy to do
For both my recommendation would be to make a dependencies folder and a folder for each depedency you have (this keeps your top level cmake file clean and creates a new scope for every dependency, which is especially important for the first way of handling this).
In the top level CMakeLists you just have a include_subdirectories(dependencies), do this before you set up any targets or tests.
This basically pulls in cach2 directly from github (or any source), you can specify a specific branch or tag if you want to.
dependencies/CMakeLists.txt
include(FetchContent)
if(BUILD_TESTING)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
# Other configuration like specification of a tag comes here
)
endif()
if(BUILD_TESTING)
add_subdirectory(catch2)
endif()
As you see you repeat the if, but the idea is to first write all the FetchContent_Declare as this is helpful if dependencies share dependencies :)
dependencies/catch2/CMakeLists.txt
# Here you can configure catch2, consult catch2 repo for information what you can configure
# set(someOption OFF) -> works if it's a cache variable declared with option() in catch2
# set(someOption OFF INTERNAL) -> works if it's a "normal" cache variable declared with set(CACHE) in catch2
FetchContent_MakeAvailable(catch2)
Put the files of catch2 in extern/catch2 or something similar
dependencies/CMakeLists.txt
if(BUILD_TESTING)
add_subdirectory(catch2)
endif()
dependencies/catch2/CMakeLists.txt
add_library(Catch2::Catch2 IMPORTED INTERFACE GLOBAL)
add_target_include_directories(Catch2::Catch2 ${PRROJECT_SOURCE_DIR}/extern/catch2)
I would personally use Approach 1, even though it seems slightly more complex. Updating catch2 is rather easy (just change the tag) and you can use the targets of catch2 directly instead of creating your own.
Somwhere in your test folder you would then have
target_link_libraries(yourTestTarget PRIVATE Catch2::Catch2)
I might be able to also submit a pull request, if you don't want to do it yourself, let me then know, which option you prefer. But you might want to use this as a chance to learn a little bit about cmake :)
Note: This is pretty much just coded from my head, so you might need to fix some typos or smaller issues.
Fixed with #575 #572, can be closed I think.
@Leon0402 thank you