Add all files under a folder to a CMake glob?
<p>I've just read this:</p>

<p><a href="https://stackoverflow.com/q/3201154/1593077">CMake - Automatically add all files in a folder to a target?</a></p>

<p>With the answer suggesting a file glob, e.g.:</p>

<pre><code>file(GLOB "*.h" "*.cpp")
</code></pre>

<p>now, what if I want my target to depend on all files of a certain type under a certain folder - which might be within multiple subfolders? I tried using</p>

<pre><code>execute_process(COMMAND find src/baz/ -name "*.cpp" OUTPUT_VARIABLE BAR)
</code></pre>

<p>and then</p>

<pre><code>add_executable(foo ${BAR}
</code></pre>

<p>but this gives me the error:</p>

<p>Cannot find source file:</p>

<pre><code>  src/baz/some/file/here

src/baz/some/other_file/here

src/baz/some/other_file/here2
</code></pre>

<p>(yes, with that spacing.)</p>

<p>What am I doing wrong here?</p>