We have a header-only library apiDefines (INTERFACE) which has a generated API.h (declspec imports/exports) as source which is used as a helper target to link to in other library targets:
set(generatedFile ${CMAKE_CURRENT_BINARY_DIR}/API.h)
set_property(SOURCE ${generatedFile} PROPERTY GENERATED ON)
set(linkTarget "apiDefines")
add_library(${linkTarget} INTERFACE)
target_sources(${linkTarget} PUBLIC ${generatedFile})
set_property(TARGET ${linkTarget} PROPERTY PUBLIC_HEADER)
target_compile_definitions(${linkTarget}
INTERFACE "API_EXPORTS")
target_include_directories(${linkTarget}
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)
When we want to install this cmake complains about:
Target "apiDefines" INTERFACE_SOURCES property contains
path:
"/workspaces/cmake-general/tests/project/build/linux-clang-libstdc++-debug/src/plugins/internal/API.h"
which is prefixed in the build directory.
If we use target_sources(${linkTarget} PRIVATE ${generatedFile}) that would certainly solve the problem, but this is somehow wrong as API.h is a public source for apiDefines.
I am not quite sure how to achieve that I can install a header-only library which uses generated sources in the binary tree?