Could you please advise on this issue. I found similar issue to one that has been posted as “Cannot build sub-directory library if top-level CMakeLists.txt call install(EXPORT …)” but was not answered at https://cmake.org/pipermail/cmake/2018-March/067196.html and not really answered at https://stackoverflow.com/questions/49254613/cannot-build-library-in-subdirectory-when-top-level-cmakelists-txt-calls-install
Consider directory structure as the following
applib (top level SDK library ) |-- top-level CMakeLists.txt (project(top...) |-- sublibTop project(sublibTop... | `-- CMakeLists.txt | |-- sublib (project (sublib .. ) | `-- CMakeLists.txt |..
If subdir target sublib is included into a list of targets (e.g. install(TARGETS sublibTop sublib … ), then cmake fail during build due to the sublib target is not found at sublibTop level directory (target is built ok but in sub-dir) with error:
install TARGETS given target " sublib" which does not exist in this directory.
However if sublib is not included in the list of install(TARGETS, the error is
CMake Error: install(EXPORT “sublibTop” …) includes target “sublibTop” which requires target “sublib” that is not in the export set.
target_link_libraries( sublibTop sublib)
install(TARGETS sublibTop sublib
I am looking for a way to use cmake figure out all installation targets and export elements based on target properties and target dependencies and commands for install/export of single top level target.
On clue is that the 1st error does not occur on machine using cmake 3.17 but with 3.11 being used on another machine (Jenkins) but I am not sure it is not caused by the order or build and I prefere not to include sublib into install(TARGETS list since cmake knows it is required for sublibTop .