I’m so utterly flabbergasted. The tutorial page says to use the CMake integration and includes a link, but the link sends me to a page with a ton of hyper specific information that doesn’t exactly walk me through set up, and I actually cannot find any real guides to help with this. I tried copy pasting the Cmake snippet into the CMakeLists.txt and running cmake -B build but it broke, with 3 errors: Cannot find source file: test.cpp, No SOURCES given to target: tests, and No SOURCES given to target: custom-main-tests. When I comment out the offending line (add_executable(tests test.cpp)) I end up with the error Cannot specify link libraries for target "tests" which is not built by this project. I’ve already installed Catch2 as a system package via my software manager (Linux Mint). Is this a directory issue? Am I supposed to clone a git repo or copy-paste libraries in somewhere? I don’t understand and the CMake integration link on Catch2’s tutorial page is seemingly of no help.

Not using any IDEs, just my default text editor and Xed. I am also not at all versed in CMake whatsoever, like, at all. No real understanding of what it is or what it does or how it works, it’s basically magic to me.

  • ImgurRefugee114@reddthat.com
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    2 days ago

    This issue doesn’t sound specific to catch2; it sounds like a misconfiguration of your project’s CMake / file directory.

    The first error says it can’t find test.cpp ; if just a bare relative path, then it should be right beside the CMakeLists.txt

    Its been a while since I messed with Catch2, but it may be worthwhile trying to use it without CMake first just to separate the concerns

    E.g. test.cpp

    #include <catch2/catch_test_macros.hpp>
    
    TEST_CASE("Arithmetic") {
        REQUIRE(2 + 2 == 4);
    }
    

    Compile (e.g. with gnu toolchain; Assuming g++ and catch2 are installed system-wide and properly integrated into the environment by your package manager)

    g++ -std=c++17 test.cpp -o tests -lCatch2Main -lCatch2
    

    Then just run ./tests