I recently discovered the awesome Frut project and have used it to convert my Projucer project to CMake. I use CLion with the generated CMakeLists.txt file (which then handles all the build details with Xcode in the background using the default CLion toolchain).
I would also like to migrate my unit tests to Catch2 and set up a build target for them in CMake/CLion but I’m having trouble figuring out how to do this (I’m new to both Juce and CMake, and not terribly experienced with C++ either).
So far, I have tried adding a file to the project with the following contents:
// CatchTest.cpp
#define CATCH_CONFIG_MAIN
#include "../External/Catch/catch.hpp"
TEST_CASE("Test")
{
REQUIRE(1 == 1);
}
I am able to set up a new target and run the test by appending this line to the to the CMakeLists.txt file:
add_executable(tests Source/CatchTest.cpp)
So far so good. But the build fails as soon as I include Juce library files in my tests (the included Juce files cannot be found). I could of course try to fix this but I don’t think I’m on the right track here. I think that “circumventing” the Frut generated build for testing is probably just asking for trouble down the road.
I see from other posts on the forum that calling Catch::Session::run() from the main function conditionally based on preprocessor flags might be a viable approach - but since my project is a plugin library there is no main function, so I’m not really sure how to go about doing that…
I wonder if there might be a way to hook into the Standalone plugin “wrapper” (or roll your own)?