Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use LD_LIBRARY_PATH in CMakeLists?

Tags:

linux

cmake

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 ?

like image 310
ThomasGuenet Avatar asked Oct 12 '25 09:10

ThomasGuenet


1 Answers

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})
like image 98
Tsyvarev Avatar answered Oct 14 '25 23:10

Tsyvarev