[CMake] [EXTERNAL]: To include external libraries using Cmake

Matthew Woehlke matthew.woehlke at kitware.com
Wed Jan 4 17:23:21 EST 2017


(Arf, re-send with an account that's allowed to post to the list...)

On 2017-01-04 14:52, Parag Chandra wrote:
> If I’m not mistaken, when a library cannot be found, the value of
> the variable “ARMADILLO” will be set to “ARMADILLO-NOTFOUND”.

Correct. But...

> So I think you need to adjust your test to:
> 
> IF (${ARMADILLO} STREQUAL “ARMADILLO-NOTFOUND”)
>   # do what you want
> ENDIF ()

CMake treats several strings as having the Boolean value 'false',
including "FALSE" (duh), "0", "OFF", and anything that ends with
"-NOTFOUND". So, it's clearer to just write `if(NOT ARMADILLO)`.

(That said, note that it is convention to name variables that receive
the location of a library like ARMADILLO_LIBRARY. Also, uppercase
commands are sooo last decade ;-).)

BTW, avoid writing unquoted variable expansions in `if()`, as they are
subject to multiple expansion that way. (And it's only recently that
quoted values are not subject to expansion!) Instead, just write the
variable name without the `${` and `}`; it will be expanded for you.

-- 
Matthew


More information about the CMake mailing list