Alright, I’m starting to get setup and things are going relatively well, except I am running in to a problem which is probably due to my lacking cmake skills. I decided to go for catch2.
First of all, I installed catch2 systemwide using my package manager (sudo pacman -S catch2
on arch linux).
Then, I added this section to my UGen CMakeLists.txt file. I added an option TESTING
which may be set to turn on/off building the tests binary. Not sure if this is the smartest way of doing such a thing but seems the easiest for me at least.
####################################################################################################
# Testing
option(TESTING "Build tests binary using catch2" ON)
# Tests
if (TESTING)
# Requires that catch2 is installed on the system
find_package(Catch2 REQUIRED)
add_executable(tests test/main.cpp)
target_link_libraries(tests Catch2::Catch2)
endif()
And created a test file in a subdirectory from the root of my project:
test/main.cpp
which looks like this (a silly non-test for testing that it works):
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this
// once
#include "catch2/catch.hpp"
unsigned int Factorial(unsigned int number) {
return number <= 1 ? number : Factorial(number - 1) * number;
}
TEST_CASE("Factorials are computed", "[factorial]") {
REQUIRE(Factorial(1) == 1);
REQUIRE(Factorial(3) == 2);
REQUIRE(Factorial(3) == 6);
REQUIRE(Factorial(10) == 3628800);
}
Then running the usual make/cmake commands, I get the tests
binary in my build directory and running that runs the tests. Hurray!
The problem: Including stuff that includes SC’s plugin api
So, then my problem is this: When I add my header file allpass.hpp
to this test file mentioned above, it cannot find the sc api stuff.
At the top of test/main.cpp
I add this header:
#include "../plugins/Common/allpass.hpp"
It seems to find the header and include it, but compilation of the tests
binary is terminated with this error message:
In file included from /home/mads/code/notamplugins/test/main.cpp:3:
/home/mads/code/notamplugins/test/../plugins/Common/allpass.hpp:11:10: fatal error: SC_PlugIn.hpp: No such file or directory
11 | #include "SC_PlugIn.hpp"
| ^~~~~~~~~~~~~~~
This of course is caused by my allpass.hpp
relying on the SC_PlugIn.hpp
include.
I guess I need to do some cmake trick here. Does anyone have any pointers/tips?