Reputation: 2398
I have got the following problem while migrating from CMake 2.8.x to 3.2.x. Thereby, it seems that the internal behavior of find_library
changed. Here is a minimal example which demonstrates my problem.
Consider that we are search for library called libopenblas.so
which is located in /scratch/local_install/lib
and /usr/lib/openblas-base
. The LD_LIBRARY_PATH
environment variable is set to /scratch/local_install/lib
.
The CMakeLists.txt
file is the following:
PROJECT(TEST)
cmake_minimum_required(VERSION 2.8)
SET(_libname "openblas")
SET(_libdir ENV LD_LIBRARY_PATH "/usr/lib/openblas-base")
find_library(OPENBLAS_LIBRARY
NAMES ${_libname}
HINTS ${_libdir}
PATHS ${_libdir}
)
MESSAGE("OPENBLAS: ${OPENBLAS_LIBRARY}")
If I execute this using CMake 2.8.7 or 2.8.12, I get
OPENBLAS: /scratch/koehlerm/local_install/lib/libopenblas.so
If I configure the code using CMake 3.2.1, I get
OPENBLAS: /usr/lib/openblas-base/libopenblas.so
which I only want to get if there is none libopenblas.so
in the LD_LIBRARY_PATH
. How can I restore the old behavior of CMake 2.8.x even if the code is configured with CMake 3.2.x?
Upvotes: 1
Views: 863
Reputation: 23432
Use NO_DEFAULT_PATH
for find_library
, then it will ignore the default location. See the documentation.
To get the bahvior you want, use find_library twice. First with NO_DEFAULT_PATH and after that without. If it is found the first time, the result is cached and the second call including the default path is skipped. If nothing is found first, it will be re-run and look at the default paths, too.
Upvotes: 1