[CMake] /path/to/libpng.so automatic conversion to -lpng ?

Eric Noulard eric.noulard at gmail.com
Thu Jul 13 05:36:33 EDT 2017


2017-07-13 2:04 GMT+02:00 René J. V. Bertin <rjvbertin at gmail.com>:

> Andreas Naumann wrote:
>
> > cmake instrospects your compiler and asks for system directories.
>
> Just stumbled across this documentation tidbit:
>

Thanks you for digging this.
I totally ignored that "feature".



>
> >>>>>>>
> CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES
> --------------------------------------
>
> Implicit linker search path detected for language ``<LANG>``.
>
> Compilers typically pass directories containing language runtime
> libraries and default library search paths when they invoke a linker.
> These paths are implicit linker search directories for the compiler's
> language.  CMake automatically detects these directories for each
> language and reports the results in this variable.
>
> When a library in one of these directories is given by full path to
> :command:`target_link_libraries` CMake will generate the ``-l<name>``
> form on
> link lines to ensure the linker searches its implicit directories for the
> library.  Note that some toolchains read implicit directories from an
> environment variable such as ``LIBRARY_PATH`` so keep its value consistent
> when operating in a given build tree.
> <<<<<<<
>
> Note the
> > CMake will generate the ``-l<name>`` form on link lines to ensure the
> linker
> > searches its implicit directories
>
> What's the point in doing that when a full path is given? Full path means
> searching isn't required. Full path (probably) means that the operator
> wants to
> ensure that a specific library is linked. Full path thus means that
> searching
> can even have counterproductive effects


>
I you have a look at file:
https://github.com/Kitware/CMake/blob/master/Source/cmComputeLinkInformation.cxx

you may discovered (as I just did) that not all CMake supported systems
kindly accept full path to library for linking...
so may be the implicit system link dir was introduced for them in the first
place.
I guess the author/contributor to this part of CMake may certainly explain
that better than me.

Looking the code is interesting because apparently what you need is to set
 CMP0060 to NEW:

$ cmake --help-policy CMP0060
CMP0060
-------

Link libraries by full path even in implicit directories.
....

The OLD behavior for this policy is to ask the linker to search for
libraries whose full paths are known to be in implicit link directories.
The NEW behavior for this policy is to link libraries by full path even
if they are in implicit link directories.

This policy was introduced in CMake version 3.3.  Unlike most policies,
CMake version 3.7.2 does *not* warn by default when this policy
is not set and simply uses OLD behavior.  See documentation of the
``CMAKE_POLICY_WARNING_CMP0060``
variable to control the warning.


The thing I don't understand is that you use CMake 3.8.2 so you should get
the new behavior.
However since digikam does a cmake_minimum_required(VERSION 3.0.0) which may
set the CMP0060 to old.

-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170713/865896a6/attachment-0001.html>


More information about the CMake mailing list