2

I have a find_library() statement that matches below (this is based on the amazon kinesis project):

find_library(SRTP_LIBRARIES NAMES srtp2 REQUIRED PATHS ${OPEN_SRC_INSTALL_LIB_PREFIX})

The OPEN_SRC_INSTALL_LIB_PREFIX correctly points to the location where this library is located. I can observe this directly. However, this find_library() call fails and I am confused as to why it would do so.

I thought that maybe cmake is searching through other paths first and ignoring my specified path, so I also tried it with the NO_DEFAULT_PATH flag, as that should limit the search to only be in the paths specified:

find_library(SRTP_LIBRARIES NAMES srtp2 REQUIRED PATHS ${OPEN_SRC_INSTALL_LIB_PREFIX} NO_DEFAULT_PATH)

... still no luck.

Any ideas why this would not work? I've verified the OPEN_SRC_INSTALL_LIB_PREFIX is the valid directory of the library via message() prints.

Note that this is cross compiling, although I don't see why that would change the behavior of find_library() unless I'm missing something from the documentation

ryeager
  • 873
  • 1
  • 10
  • 24
  • 2
    Add `--debug-find` option to `cmake` and examine output corresponded to your `find_library` call. It should print which paths are actually searched and which paths are ignored. – Tsyvarev Apr 16 '21 at 20:32
  • Good tip @Tsyvarev, I now see that it is not in fact using the PATHS I pass in at all... any ideas on why this would be the case? is there some sort of caching going on? it appears to be using the SYSROOT path instead, and then uses no paths when I specify NO_DEFAULT_PATH (even though PATHS is defined and valid) – ryeager Apr 22 '21 at 22:56
  • This seems very relevant: https://gitlab.kitware.com/cmake/cmake/-/issues/20772 – ryeager Apr 22 '21 at 22:59
  • ```The CMAKE_SYSROOT variable can also be used to specify exactly one directory to use as a prefix. Setting CMAKE_SYSROOT also has other effects. See the documentation for that variable for more.``` – ryeager Apr 22 '21 at 23:06
  • I'm guessing this is what is borking me up – ryeager Apr 22 '21 at 23:06

1 Answers1

1

First want to note I'm on cmake 17.5.

Ok, so the documentation is a bit confusing, but it seems that the NO_DEFAULT_PATH would only use the paths specified by the PATHS argument and none of the other cache variables, but that doesn't seem to be the case if CMAKE_SYSROOT is set.

Using the NO_CMAKE_FIND_ROOT_PATH is what actually causes find_library() to ignore the cached paths.

ryeager
  • 873
  • 1
  • 10
  • 24