How to get the install destination of files of an imported target?

Let’s assume there is a project A with the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.27)

project(A VERSION 1.0.0 LANGUAGES CXX)

set(library_name ProjectA)
add_library(${library_name} INTERFACE)
add_library(My::ProjectA ALIAS ${library_name})

target_sources(${library_name}
    INTERFACE
    FILE_SET HEADERS
    BASE_DIRS
        include
    FILES
        include/header.h
)

target_include_directories(${library_name}
    INTERFACE
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

install(TARGETS ${library_name} EXPORT ProjectA
    FILE_SET HEADERS
    DESTINATION lib/subdir/include/another/dir
    INCLUDES DESTINATION lib/subdir/include
)
install(EXPORT ProjectA DESTINATION cmake NAMESPACE My::)
export(EXPORT ProjectA NAMESPACE My::)

This project has the header files in the directory include, but installs them to another directory lib/subdir/include/another/dir and adds the directory lib/subdir/include as include directory.

If another project fetches the source code with FetchContent, is there a way to automatically figure out in a CMakeLists.txt to which destination the header files are installed?

At the moment, I have other projects B and C, which use the install tree and expect the headers to be in another/dir, but there is also a test project T that fetches the source code of A, B, and C directly and manually copies the header files around. Therefore, I was wondering what might be the best way to have the headers in the right location when building T and the dependencies without changing the layout in Project A, B, and C.

You can’t in general query what things will be installed where. Things can be installed to multiple places, for multiple components, etc. Basically, you need to look through the project to see what it does, and in your consuming project you make use of that knowledge to either re-use the existing install rules, or you define your own install rules for the consumed dependency and ignore the ones it defines (you would do this with components, adding only those components you want for your top level project’s install/packaging logic).

Thank you! It is good to know that I haven’t missed anything there.