<div dir="ltr">Sorry, hit the send button prematurely. To achieve your desired goal of creating a header only library as a target in Visual Studio, it somewhat depends on what you want to do with that library. If you just want it to be there so you can see the header in the IDE, then simply defining a dummy custom target is one approach I've seen people use. E.g.<div><br></div><div><font face="monospace, monospace">  add_custom_target(foo SOURCES foo.h)</font></div><div><br></div><div>If you want to actually link to the target so it can provide header search path dependencies, then the approach you tried is probably the closest (with the use of absolute paths as described in my previous email). As you discovered though, it adds the header to the sources list of each project linking against it, which it sounds like you want to avoid. An interface library doesn't create build output on its own, so it doesn't make sense for it to have its own list of sources. The only way sources make sense for it is for those sources to be added to anything linking against it, which is the behaviour you are seeing.</div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jul 10, 2016 at 10:04 AM, Craig Scott <span dir="ltr"><<a href="mailto:craig.scott@crascit.com" target="_blank">craig.scott@crascit.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">When using target_sources(), if you specify the source file(s) with a relative path, CMake does not convert that to an absolute path when storing it in the target's SOURCES property (that's my interpretation anyway). The end result is that the source you specify is going to be interpreted as being relative to the source directory the dependent target is defined in, not the directory where you called target_sources().  You can prevent the problem you described by ensuring the path for the source file(s) is always an absolute one. For example:<div><br></div><div>target_sources(<span style="font-size:13px">foo INTERFACE "${CMAKE_CURRENT_LIST_DIR}/foo.h")</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">You may find the following blog article useful (it discusses the above problem and also other related material):</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px"><a href="https://crascit.com/2016/01/31/enhanced-source-file-handling-with-target_sources/" target="_blank">https://crascit.com/2016/01/31/enhanced-source-file-handling-with-target_sources/</a><br></span></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Sun, Jul 10, 2016 at 9:03 AM, Robert Dailey <span dir="ltr"><<a href="mailto:rcdailey.lists@gmail.com" target="_blank">rcdailey.lists@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have the following:<br>
<br>
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)<br>
project(foo)<br>
add_library(foo INTERFACE)<br>
target_sources(foo INTERFACE foo.h)<br>
add_subdirectory(subdir)<br>
<br>
And inside subdir, I specify add_executable() and then<br>
target_link_libraries(myexe foo).<br>
<br>
I get an error:<br>
<br>
Cannot find source file: foo.h<br>
<br>
I'm using CMake 3.6. What am I doing wrong here?<br>
<br>
My goal is to generate a header-only project in Visual Studio.<br>
According to the documentation, what I'm trying to do won't give me<br>
that. Instead, foo.h would exist in every project that links to it as<br>
a dependency (that's what it seems like anyhow).<br>
<br>
Advice is appreciated.<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><br>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="http://crascit.com" target="_blank">http://crascit.com</a><br></div></div></div></div></div>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="http://crascit.com" target="_blank">http://crascit.com</a><br></div></div></div></div></div>
</div>