'How to get relative parent source files for use in tests subdirectory

I have a directory structure like..

/
    source_1.cpp
    source_2.cpp
    source_1.hpp
    source_2.hpp
    CMakeLists.txt
    /tests
        test_1.cpp
        test_2.cpp
        CMakeLists.txt

I'm writing the tests in the tests directory but the tests need to be build with the parent source as well. I don't want to make my root build a library.

I can get access to the parent files by using

get_target_properties( <parent-target> PARENT_SOURCE SOURCES )

but the list returned is simply a list of the file names and doesn't have the PATH, i.e. source_1.cpp;source_2.cpp;.. etc.

Does anyone know how to get a list of relative paths to the parent targets source files ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source