On my workstation, I have to load module to increment the LD_LIBRARY_PATH
environment variable (module load arpack
). It seems that cmake can only access this variable by using $ENV{LD_LIBRARY_PATH}
. But when printing this variable I get a list of directories seperated by :
and I believe cmake does not understand it as a list of directories to find libraries, as a consequence, the following does not work:
find_library (Arpack_LIBRARY libarpack.a PATH $ENV{LD_LIBRARY_PATH})
and
message(STATUS $ENV{LD_LIBRARY_PATH})
prints
/home/user:/home/user/lib:/usr/lib:/lib
This is how I want to find my library. How can I transform $ENV{LD_LIBRARY_PATH}
to an exploitable list of directories ?
In CMake a list is just a string with semicolon-separated parts. For make colon-separated string to be semicolon-separated, use string(REPLACE) command:
string(REPLACE ":" ";" LIBRARY_DIRS $ENV{LD_LIBRARY_PATH})
Resulted variable can be used in find_library
call:
find_library (Arpack_LIBRARY libarpack.a PATHS ${LIBRARY_DIRS})
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