install(... INCLUDES DESTINATION ...) is accumlating include directories across multiple exports
When I call install(TARGETS targetname EXPORT exportname INCLUDES DESTINATION ....)
for the same target across more than one export with include directories specified, the generated import target in each of the resultant export cmake scripts contains all of the destination subdirectories for all of the install calls. My expected result (and the prior behvior) is that the export scripts would only specify the include dirs for the matching install call.
Here's a minimal repro
cmake_minimum_required(VERSION 3.19)
project(cmake-install-include-dir-repro LANGUAGES C)
add_library(testlib STATIC test_func.c)
install(
EXPORT pkg1
FILE pkg1Config.cmake
DESTINATION pkg1/cmake
NAMESPACE pkg1::
)
install(
TARGETS testlib EXPORT pkg1
ARCHIVE DESTINATION pkg1/lib
INCLUDES DESTINATION pkg1/inc
)
install(
EXPORT pkg2
FILE pkg2Config.cmake
DESTINATION pkg2/cmake
NAMESPACE pkg2::
)
install(
TARGETS testlib EXPORT pkg2
ARCHIVE DESTINATION pkg2/lib
INCLUDES DESTINATION pkg2/inc
)
The resultant contents of pkg1/cmake/pkg1Config.cmake
# Create imported target pkg1::testlib
add_library(pkg1::testlib STATIC IMPORTED)
set_target_properties(pkg1::testlib PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/pkg1/inc;${_IMPORT_PREFIX}/pkg2/inc"
)
and similarly the resultant contents for pkg2/cmake/pkg2Config.cmake
# Create imported target pkg2::testlib
add_library(pkg2::testlib STATIC IMPORTED)
set_target_properties(pkg2::testlib PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/pkg1/inc;${_IMPORT_PREFIX}/pkg2/inc"
)
The behavior above occurs in 3.22.2
This does not occur with 3.19 where each pkg#Config.cmake only contains a single include directory. While I haven't verified directly myself, a colleague reports the 3.19 behavior on 3.21.