Let’s say you require Qt5 for your project. Should libs target obtained via find_package be installed & exported together with my own sublibTop built target or rely my library consumer to find my own lib package and then find package for my dependencies? Note typically I put 3rd party libraries ( with arc and include) in separate directory at the same level as my sublibTop project or even under 3rdParty directory which is at the same dir levels as my project What about install( TARGETS and install(EXPORT for such targets ? Is it ok to use add_library on such libs as IMPORTED? So could you please illustrate this statement.Īlso, after I call find_package (implib REQUIRED) I get the libs and include dir which is set by implib’s Find.cmake, I link them with target_ link_libraries. 1st with the the impLib external to my build and 2nd would use my sublibTop target.
You meant that find_package statement is being used for te 1st time in my CMakecode that builds and installs my own sublibTop lib and then 2nd time in the code of a consumer of my library, right?īut these find_package would be used with different package names. Thanks, could you please clarify “ use find_package during the build and again when your package is being found. So I would prefer to export all libraries needed to build with my sublibTop library however I cloud list all libs that require find_ package in my installation notes. Then it seems inconsistent since I’d like to provide self contained package (sublibToopConfig.cmake that defines all libs) to my sublibTop consumers. Then to make my sublibTop library accessible via find_package for my library consumer, I should not include implib targets into install(EXPORT list and rely on consumers to use find_package(implib … in their CMakeLists.txt as well as for my sublibTop library, right? So in this case sublibTop and sublib would be installed using install( TARGETS sublibTop sublib … EXPORT subTargets … but implib would have to be install(FILES implib …Īs I understand your suggestion, it is applicable when xxxFindimplib.cmake exists, and in my CMakeLists.txt I would have find_package(implib_pkg 0.0.1 REQUIRED) (or find_library(implib …) ) and xxxFindimplib.cmake definitions of target names will be used (implib_LIBRARIES as well as implib_INCLUDE_DIRECTORIES, …) in my taget_link_libraries(sublibTop sublib $… and installed with install(TARGETS sublibTop sublib.
target_include_directory( implib INTERFACE …include)Īnd then linked target_link_libraries(sublibTop sublib implib …) as implib is needed for the sublibTop consumers for building their executables. Let’s consider case alternative to find_package when xxxFindPackage.cmake does not exist and external dependency is added via add_library(implib, IMPORTED …) set_target_properties(implib PROPERTIES IMPORTED_LOCATION …). ĭid you mean that imported library should not be exported and if I am exporting my sublibTop library for consumers, consumers have to use find_package for mine and separately for imported libraries? 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. 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. However if sublib is not included in the list of install(TARGETS, the error isĬMake Error: install(EXPORT “sublibTop” …) includes target “sublibTop” which requires target “sublib” that is not in the export set.
Install TARGETS given target " sublib" which does not exist in this directory. 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:
If subdir target sublib is included into a list of targets (e.g. |- top-level CMakeLists.txt (project(top.) 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 and not really answered at Ĭonsider directory structure as the following applib (top level SDK library )