[CMake] Unable to find source files in different directory using target_sources(INTERFACE)

Robert Dailey rcdailey.lists at gmail.com
Sat Jul 9 19:03:54 EDT 2016


I have the following:

cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(foo)
add_library(foo INTERFACE)
target_sources(foo INTERFACE foo.h)
add_subdirectory(subdir)

And inside subdir, I specify add_executable() and then
target_link_libraries(myexe foo).

I get an error:

Cannot find source file: foo.h

I'm using CMake 3.6. What am I doing wrong here?

My goal is to generate a header-only project in Visual Studio.
According to the documentation, what I'm trying to do won't give me
that. Instead, foo.h would exist in every project that links to it as
a dependency (that's what it seems like anyhow).

Advice is appreciated.


More information about the CMake mailing list