`generate_export_header` + `target_include_directories` leaves `fatal error C1083: Cannot open include file`

I added these lines to my cmake-example-with-vcpkg/CMakeLists.txt at 993ec593d7b0f26dbd2c7eac3953a894081e69bd · SamuelMarks/cmake-example-with-vcpkg · GitHub

# set(LIBRARY_NAME "versions")


    INTERFACE  # also tried `PUBLIC` and `PRIVATE`
#include "versions_export.h"
/* also tried: #include <versions_export.h> */

But I’m left with this error:

versions\versions.h(17): fatal error C1083: Cannot open include file: 'versions_export.h': No such file or directory

How do I setup the generate_export_header workflow correctly?

Can you see versions_export.h in the build tree? I suspect that EXPORT_FILE_NAME is expecting just a filename, so you’re getting /path/to/binary/dir/path/to/binary/dir/versions_export.h.

versions_export.h appears in my build dir, and my IDE recognises it in the #include.

Relative paths work, as do absolute paths. But regardless when I got to actually build it I get this ‘not found’ error. Maybe it needs its own target so that it is guaranteed generated before it is used or something?

(My CMakeLists.txt is only 53 lines so if you know what it needs just try and see)


Ended up cheating with:

set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/${LIBRARY_NAME}_export.h")
generate_export_header("${LIBRARY_NAME}" EXPORT_FILE_NAME "${_export_file}")

Unfortunately ${CMAKE_CURRENT_SOURCE_DIR} was the only thing that worked. Tried everything from relative paths to ${CMAKE_CURRENT_BINARY_DIR} to no EXPORT_FILE_NAME to completely different targets.