<div dir="ltr">Hi Craig,<div>thanks for the clarification.</div><div><br></div><div>Best,<br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Michele</div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 15, 2019 at 2:09 AM Craig Scott <<a href="mailto:craig.scott@crascit.com">craig.scott@crascit.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 3, 2019 at 11:10 AM Michele Rosso <<a href="mailto:mrosso@lbl.gov" target="_blank">mrosso@lbl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hello,<div>according to the doc for CMake 3.14, target_sources() interprets relative source file paths as being relative to the current
source directory, i.e. it should <br></div><div>prepend CMAKE_CURRENT_SOURCE_DIR to the relative paths given by the user. However, this is not the case if the target and the sources are defined in the same directory.</div></div></div></div></blockquote><div><br></div><div>The docs say that target_sources() will <i>interpret</i> relative source file paths that way, but they do not state that it will prepend CMAKE_CURRENT_SOURCE_DIR. The docs for target_sources() only talk about how relative paths are interpreted. The docs for policy CMP0076 are a bit more explicit, but even they only say that target_sources() will convert the relative path to absolute <i>if the conditions also specified in those policy docs are met</i>. In the case where target_sources() is called in the same directory as where the target is defined, the target's SOURCE_DIR property and the CMAKE_CURRENT_SOURCE_DIR variable will hold the same value, so the relative path is not modified, as per the CMP0076 docs. </div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>I attached a simple example to reproduce the issue. The structure of the example is as follows:</div><div><br></div><div>- cmake-bug/</div><div> - CMakeLists.txt</div><div> - main.cpp </div><div> - foo/</div><div> - CMakeLists.txt</div><div> - foo.H</div><div> - foo.cpp</div><div> - bar/</div><div><div> - CMakeLists.txt</div><div> - bar.H</div><div> - bar.cpp</div></div><div><br></div><div>Target "main.exe" is defined in the top-level CMakeLists.txt, while its headers and sources are located in the the top-level directory</div><div>and in the sub-directories 'foo' and 'bar'.</div><div>After target_sources is used to include all the headers and sources, I retrieve the "SOURCES" property for `main.exe`: all the sources and headers</div><div>but `main.cpp` are given the correct (absolute) path.</div><div><br></div><div>Is this the intended behavior? If so, why should a source file located in the same directory where the target is defined be treated any differently?</div></div></div></div></blockquote></div><div><br></div><div>Yes, this is the intended behavior. There's no need to modify the path when target_sources() is called in the same directory as that in which the target is defined because the behavior is unambiguous and is the same whether CMP0076 is set to OLD or NEW. This is consistent with what you'd get if you had listed the sources directly in the add_executable() or add_library() call instead.</div><div><br></div><div><br></div>-- <br><div dir="ltr" class="gmail-m_3220349583521059207gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div><div><br></div><div>Get the hand-book for every CMake user: <a href="https://crascit.com/professional-cmake/" target="_blank">Professional CMake: A Practical Guide</a><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div>