Jordan
Jordan

Reputation: 4212

How to tell CMake NOT to search system paths for libraries

I have a project that uses several different open source libraries (FFmpeg, OpenSSL, for example).

No matter what I try, CMake is linking against the SYSTEM installed versions of these libraries, rather than the custom built ones I need for my projects.

Here is an example of what I've tried to add the FFmpeg library 'libswresample':

set(FFMPEG_PATH "/shared/dev/libs/ffmpeg/3.4.2")
find_library(LIBSWRESAMPLE_LIB NAMES swresample
        PATHS ${FFMPEG_PATH}/lib/darwin-amd64
        NO_DEFAULT_PATH
        NO_CMAKE_ENVIRONMENT PATH
        NO_CMAKE_PATH
        NO_SYSTEM_ENVIRONMENT_PATH
        NO_CMAKE_SYSTEM_PATH
        NO_CMAKE_FIND_ROOT_PATH)
list(APPEND includes "${FFMPEG_PATH}/include")
link_directories("${FFMPEG_PATH}/lib/${ARCH}")
list(APPEND libs ${LIBSWRESAMPLE_LIB})
MESSAGE(STATUS "libs: ${libs}")

I've tried setting CMAKE_PREFIX_PATH to the location of my shared libraries - no luck.

I've tried this with various combinations of the "NO_SOMETHING_PATH" options, which doesn't seem to help. I also tried just giving ${FFMPEG_PATH} to the PATHS parameter of find_library() and providing PATH_SUFFIXES lib ${ARCH} (which would be ideal, since I build this project for multiple platforms), but that didn't work either.

No matter what I've tried, MESSAGE outputs libs: /usr/local/lib/libswresample.dylib, rather than libs: /shared/dev/libs/ffmpeg/3.4.2/lib/darwin-amd64/libswresample.dylib

I've found several FindFFMpeg modules, but they all are pretty much doing what I'm trying here and wind up finding the system installed FFmpeg libraries rather than the one I actually want to link with.

If I explicitly provide the absolute path to the library I can get it to work, but this is obviously not optimal since some platforms use static libraries, some use shared libs, and so on. If I were to go that route, I'd have to additional work to figure out which platform I'm building for, and that doesn't seem like the right way to go about it anyways.

I know I must be missing something simple. Can anyone point me in the right direction?

Upvotes: 2

Views: 2283

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 66298

The code works, but you should clear CMake cache (remove CMakeCache.txt file from build directory) for re-search the library.


Option NO_DEFAULT_PATH implies all other NO_* options, so you may omit them.

Upvotes: 4

Related Questions