<div dir="ltr">Gonzalo, Ray,<div><br></div><div>I think your approaches are not in accordance with some CMake best practices (or at least what I believe they are).</div><div><br></div><div>Please take a look at Ray's example after a heavy refactor: <a href="https://github.com/tamaskenez/cmake-2016-jan-21-shared-lib-exe">https://github.com/tamaskenez/cmake-2016-jan-21-shared-lib-exe</a></div><div><br></div><div>These are the things I changed:</div><div><br></div><div>- In your test executables don't compile the source files of the library-under-test into your test. Instead, link to the library. Reason (1) ODR, (2) this way you'll test the linking operation, too.</div><div>- Don't reach out from a subdirectory ('B') to include a sibling ('A'). It creates harmful coupling between the subdirectories. All information that 'B' needs to know about 'A' should be concentrated in the properties of the target 'A'. So you need to use commands like target_include_directories().</div><div>- Unnecessary verbosity makes it harder to read and debug the CMakeLists.</div><div><br></div><div>With my changes:</div><div><br></div><div>- you can build and test 'A' standalone</div><div>- you can build and test 'A', 'B' and 'X' in one project using the top-level CMakeLists.txt</div><div>- you can't build 'B' standalone or can't build 'X' without 'A' and 'B' being there. If you need that feature, we need to add an install step to 'A' and 'B' and use find_package() in 'B' and 'X' on demand</div><div><br></div><div>Tamas</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 25, 2016 at 10:22 AM, Gonzalo <span dir="ltr"><<a href="mailto:ggarra13@gmail.com" target="_blank">ggarra13@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
El 22/01/16 a las 10:50, Raymond Wan escribió:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Gonzalo,<span class=""><br>
<br>
I recently tried doing this and wrote it up as a record for myself.<br>
Of course, I don't know if it's the right way, but I'm doing it this<br>
way until I figure out a better way...<br>
<br>
See if this helps and let me know if you figure out something better:<br>
<br>
<a href="http://www.rwanwork.info/sysdocs/cmake/overview/" rel="noreferrer" target="_blank">http://www.rwanwork.info/sysdocs/cmake/overview/</a><br>
<br>
Ray<br>
</span></blockquote>
Thanks, Ray.  Your approach is exactly the same as mine.  We already found out that the problem I was having with v3.4.2 is a bug in cmake, which has been fixed in the git repository.<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Gonzalo Garramuño<br>
<a href="mailto:ggarra13@gmail.com" target="_blank">ggarra13@gmail.com</a></font></span><div class="HOEnZb"><div class="h5"><br>
<br>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a></div></div></blockquote></div><br></div>