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:
...but both these seem clunkily inelegant and there surely must be a better way.
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.