I find the library with the find_library
function
find_library(MY_LIB lib PATHS ${MY_PATH})
If the library is found, ${MY_LIB}
will point to the correct location. If the library is not found ${MY_LIB}
will be MY_LIB-NOTFOUND
.
But how do I test this?
if(${MY_LIB} EQUAL 'MY_LIB-NOTFOUND') ... endif()
always evaluates to false.
This command is used to find a library. A cache entry, or a normal variable if NO_CACHE is specified, named by <VAR> is created to store the result of this command. If the library is found the result is stored in the variable and the search will not be repeated unless the variable is cleared.
You can simply test the variable as such, e.g.:
find_library(LUA_LIB lua) if(NOT LUA_LIB) message(FATAL_ERROR "lua library not found") endif()
Example output:
CMake Error at CMakeLists.txt:99 (message): lua library not found -- Configuring incomplete, errors occurred!
Note that we use
if(NOT LUA_LIB)
and not
if(NOT ${LUA_LIB})
because of the different semantics.
With ${}
, the variable LUA_LIB
is substitued before if()
is evaluated. As part of the evaluation the content would then be interpreted as variable name, unless it matches the definition of a constant. And this isn't what we want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With