CLion: How do I get coverage for the actual library code instead of just the tests

I am testing a C++ library and I want to record coverage when I run the tests. Based on the CLion documentation, I added the necessary compiler switches:

option(CODE_COVERAGE "enable code coverage" OFF)

    if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
        message(FATAL_ERROR "Code coverage only available with LLVM/clang.")

add_library(libfoo SHARED
    # ... snip: source files ...

# ... snip: library deps & config

    # ... snip: source files ...
target_link_libraries(libfoo_tests gtest_main libfoo) # using Googletest

With this, I can run the tests with coverage in CLion. And I get coverage reports… on the testing code, but not on the library's code. So this is pretty much useless.

I have no idea what CLion actually does when running the tests with coverage, but the docs on LLVM's coverage tool state clearly that

BIN may be an executable, object file, dynamic library, or archive (thin or otherwise).

So it should be possible to get coverage on the library. What do I need to do to make it happen?