yes, since it is required to make self-contained package so consuming project does not need to be aware of its dependencies, the package created by myprojhas to include all libraries IMPORTED by the project. However there is no problem with duplicity in the installation prefix. So there is no need to make any assumptions because I specify installation directory arguments such that results in ${CMAKE_INSTALL_PREFIX} equal to single myproject/install dir. Each sub-project or being built creates directory set to its ${PROJECT_NAME}/include, ${PROJECT_NAME}/lib under this directory as per relative path setting in INSTALL_INTERFACE, INCLUDES DESTINATION, PUBLIC_HEADER DESTINATION, etc variables. The same install destination is maintained for IMPORTED or INTERFACE libraries. So they all are under one dir tree.
Again, I am using approach with creating INTERFACE wrapper for each IMPORTED target and there is issue that you mentioned. cmake writes myprojectTargets.cmake such that for each INTERFACE wrapper there is add_library(…INTERFACE IMPORTED)… This is still better than asking my consumers to track all few dozens of dependencies themselves. Again the goal is for consumer to focus only on their project and receive all myproj dependency via find_package().
I am thinking of another alternative - to add add_library(…INTERFACE IMPORTED) for each IMPORTED lib into myprojectTargets.cmake 9similar to your suggestion to use find_package() there). This again much more efforts comparing to disabling cmake block on install(TARGETS myimported …) for IMPORTED libraries. BTW cmake error message is wrong for this case. The error message is like installing target which does not exists, while simple check if (TARGET myimported) shows it does exists.
Finally my question still remains and it is about another approach - using INTERFACE instead of IMPORTED in add_library() command to “import” library. Then the target library could be installed. However how could the library file LOCATION property be set ? There is no issue for include directory since it is done via target_include_directories() command (sets INTERFACE_INCLUDE_DIRECTORIES) but there is no “target_lib_directories” command and LOCATION property is not set by target_link_libraries , I think…?