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

René J. V. Bertin rjvbertin at gmail.com
Thu Jul 13 06:07:48 EDT 2017


Eric Noulard wrote:

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

I guess most of us did, it's one of those things that usually works just fine 
but that when it breaks sends you on a nasty quest to figure out WTF is going on 
(IOW, makes you doubt yourself until you realise you just discovered a hidden 
feature).

I found this only because I searched the CMake source tree for LIBRARY_PATH to 
see where it does the rewriting. I would never have guessed to find the feature 
biting me under the concept "implicit directories".

> 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...

CMake being a system that allows to describe how to build a project in a 
platform-agnostic way it could easily have handled those systems individually.

> I guess the author/contributor to this part of CMake may certainly explain
> that better than me.

Presumably, and I guess s/he might admit not having thought of (or tested) the 
kind of situation where rewriting breaks things.

Something you said in a mail that apparently didn't go to the list:

> OK, but I don't think CMake should "fight" the underlying compiler.

No. Clang may have a reason for the different way of handling LIBRARY_PATH which 
means you'd have to leave a possibility for it to work that way - maybe even by 
default. But in this case we're not fighting the compiler, we're trying to let 
it work another way that is just as supported.

> Looking the code is interesting because apparently what you need is to set
>  CMP0060 to NEW:
> 
> $ cmake --help-policy CMP0060
> CMP0060

Ah, great. I would probably have found that by myself, eventually.

> -------
> 
> 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.

Are you sure? I read from the description above that you have to set the policy 
explicitly.

Do you know if one can set policies like this from the commandline rather than 
through patching each toplevel CMakeLists.txt file? Or can it be set for just a 
subdirectory?

> However since digikam does a cmake_minimum_required(VERSION 3.0.0) which may
> set the CMP0060 to old.

Quite possible, I've run into naggles with that with another policy on Mac (25).
It's annoying that this happens with digikam which is a really cumbersome 
project (it takes ages just to run make just to confirm that everything has been 
built).

R.



More information about the CMake mailing list