4

In my application suite I build Libtiff from source and then link it to an application that I write myself. Libtiff's CMakeLists.txt files specify that the static libraries go into the library location CMAKE_INSTALL_FULL_LIBDIR, determined by CMake's GNUInstallDirs option.

When I first built and tested my application, I did so in Debian and on this platform CMAKE_INSTALL_FULL_LIBDIR gets set to ${CMAKE_INSTALL_PREFIX}/lib. Well and good, so in my own application's CMakeLists.txt file I told it to search for the the static tiff libraries there. No problem...

Now I've taken the same build suite to a Red Hat Linux platform (Pengwin Enterprise for WSL), and it turns out that here CMAKE_INSTALL_FULL_LIBDIR gets set to ${CMAKE_INSTALL_PREFIX}/lib64. I've checked the CMake documentation and it seems to say that in fact the choice of 'lib' or 'lib64' is determined automatically and is platform-dependent.

So, in my own application's CMakeLists.txt file, is there a way of finding out which it is on my current platform? How else am I supposed to guess where to look for the library? I've looked round but I can't find a CMAKE standard variable that holds the platform-dependent string, so the only things I can think of are:

  1. Try 'lib', and if that doesn't work try 'lib64', or
  2. Create a new CMAKE_INSTALL_FULL_LIBDIR in my own CMakeLists.txt file and read the end of it

...but both these seem clunkily inelegant and there surely must be a better way.

Carlos Rafael Ramirez
  • 5,984
  • 1
  • 29
  • 36
Eos Pengwern
  • 1,467
  • 3
  • 20
  • 37
  • "Try 'lib', and if that doesn't work try 'lib64', or" - I have seen several projects which use given approach. – Tsyvarev Apr 24 '19 at 09:12

1 Answers1

7

GNUInstallDirs module documents the CMAKE_INSTALL_LIBDIR variable which sounds like it contains the value you want.

CMAKE_INSTALL_LIBDIR = lib
CMAKE_INSTALL_FULL_LIBDIR = /lib

Also find_library should also be searching lib and lib64 as necessary in the default path search even when using CMAKE_LIBRARY_PATH to define a custom prefix.

fdk1342
  • 3,274
  • 1
  • 16
  • 17
  • Yes, that's it. As is usually my experience when reading the CMake documentation, it's not at all clear when reading it in isolation; but having been given that hint and looked up a few usage examples on the internet, it's obvious that that's the solution. – Eos Pengwern Apr 24 '19 at 13:12