Linking cpp files to a sub CMakeList that will compile to the Root Cmake Lists.

Hello there. So i have this configuration of files:

I placed the main CMakeLists.txt in the root folder, this creates an executable. In ./imgui/CMakeLists.txt I would like this CMakeList to point to specific cpp files so that root can compile the executable with them.

This is the root cmake file:

And currently the second one is empty. How would I be able to achieve this with cmake

Have you considered making the imgui/ folder a static or object library with its own sources and then linking your top-level executable to that?

Otherwise you could just add the sources found in the subdirectory in the top-level CMakeLists. Nothing says you must put a CMakeLists in every sub folder.

Alternatively you could use target_sources in the subdirectory (having created the initial target in the top level).

target_sources seems like the worst option to me though—keeping everything in the top level makes it very obvious what your exe depends on, and treating imgui/ as a separate library instead would be a great way to separate easily-testable/reusable/isolated code from your app code.