> On Jun 30, 2017, at 6:40 AM, Louis-Paul CORDIER <[email protected]> 
> wrote:
> 
> Hi,
> 
> I'm particularly familiar with find_package() command, add_library(... 
> IMPORTED) and find_library(). However, I found there are many differences on 
> find_package() usage depending of the library being imported.
> 
> For instance, using find_package() on Qt5 will retrieve a bunch of 
> *Config.cmake files in the Qt installation tree, and add each components as a 
> library using add_library(Qt5::COMPONENT SHARED IMPORTED).
> One nice feature with that is the possibility to retrieve the LOCATION 
> property on each component to get the DLL file.
> 
> That said when using find_package(sharedLibFOO) that will make use of 
> hand-written FindsharedLibFOO.cmake, some variables like FindsharedLib_FOUND, 
> FindsharedLib_LIBRARIES, FindsharedLib_VERSION (etc.) are set by the script, 
> but there is almost never add_library() command used inside this CMake find 
> script.
> 
> 1. Should it be mandatory to use add_library() in FindXXX.cmake scripts, so 
> the user just needs to target_link_libraries() and all compile definitions, 
> includes dir, and lib dir are automatically imported?

This probably should be the case, but I think a lack of contributions is the 
problem with the current Find modules not being update on each module.

> 2. If not, is it a good practice to use add_library() when writing our 
> FindXXX.cmake package?

When writing your own FindXXX.cmake, you should first report a bug to library 
XXX for not supporting cmake downstream. Also, the purpose of `find_package` is 
to find prebuilt binaries, its not to add new libraries to be built.

> 3. When making an application, is it a good practice to create an imported 
> target for each library, instead of appending manually to the current project 
> using target_link_libraries(), target_compile_definitions(), 
> target_include_directories() and so on?

Yes, it is good practice to make your dependencies imported targets as it 
allows for the dependencies to be relocatable.

Here is some more information about cmake packages:

https://cmake.org/cmake/help/v3.7/manual/cmake-packages.7.html


-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to