[CMake] find_package and get_target_property

CHEVRIER, Marc marc.chevrier at sap.com
Fri Apr 13 09:10:52 EDT 2018


Using ‘install(EXPORT …)’ you can generate required files to manage imported targets BUT building and exporting targets must be done in a different build environment from the one which imports the targets.


From: Saad Khattak <saadrustam at gmail.com>
Date: Friday 13 April 2018 at 15:02
To: "CHEVRIER, Marc" <marc.chevrier at sap.com>
Subject: Re: [CMake] find_package and get_target_property

Ah I see. In this case, the Libraries I'm depending on are generated, built and installed using CMake. I'm hoping that CMake is able to generate the Find<package>.cmake for me with the appropriate imported targets, as long as INSTALL(export...) was used properly...?

On Fri, Apr 13, 2018 at 8:58 AM CHEVRIER, Marc <marc.chevrier at sap.com<mailto:marc.chevrier at sap.com>> wrote:
Not necessarily. It depends how the package was created. Using EXPORT is a possibility to generate a Config file for the package.
Another possibility is to have a FindLibA.cmake file which creates an imported target by using command ‘add_library (LibA SHARED IMPORTED)’.


From: Saad Khattak <saadrustam at gmail.com<mailto:saadrustam at gmail.com>>
Date: Friday 13 April 2018 at 14:50
To: "CHEVRIER, Marc" <marc.chevrier at sap.com<mailto:marc.chevrier at sap.com>>
Cc: Cmake Mailing List <cmake at cmake.org<mailto:cmake at cmake.org>>
Subject: Re: [CMake] find_package and get_target_property

Thanks Marc. I assume you mean the library does not export its targets properly? Something like this:

# https://cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets
install(TARGETS generator DESTINATION lib/myproj/generators EXPORT myproj-targets)
install(EXPORT myproj-targets DESTINATION lib/myproj)

On Fri, Apr 13, 2018 at 3:05 AM CHEVRIER, Marc <marc.chevrier at sap.com<mailto:marc.chevrier at sap.com>> wrote:
The creation of “imported” target is the responsibility of the package. May be the package “LibA” does not create a such target.
In this case, you have to rely on variables (like LibA_LIBRARIES and so on…). The documentation of the package, if any, generally describe how to use the package.


From: CMake <cmake-bounces at cmake.org<mailto:cmake-bounces at cmake.org>> on behalf of Saad Khattak <saadrustam at gmail.com<mailto:saadrustam at gmail.com>>
Date: Friday 13 April 2018 at 05:29
To: Cmake Mailing List <cmake at cmake.org<mailto:cmake at cmake.org>>
Subject: [CMake] find_package and get_target_property

Hi,

I am successfully able to find a package using find_package(LibA) but I cannot do a get_target_property on the package as I get the error:

get_target_property() called with non-existent target "LibA"

How do I go about the target properties for a package?

- Saad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180413/199b857d/attachment-0001.html>


More information about the CMake mailing list