Commit e2d105dc authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

Make LIBRARIES_ABSOLUTE_PATH more generic

parent 16f9bfa2
......@@ -19,24 +19,28 @@
# @date 13-04-2018
#
###
cmake_minimum_required(VERSION 3.3)
# Transform relative path into absolute path for libraries
# lib_list (input/output): the name of the CMake variable containing libraries, e.g. BLAS_LIBRARIES
# hints_paths (input): additional paths to add when looking for libraries
macro(LIBRARIES_ABSOLUTE_PATH lib_list hints_paths)
# collect environment paths to dig
list(APPEND _lib_env "$ENV{LIBRARY_PATH}")
if(WIN32)
string(REPLACE ":" ";" _lib_env2 "$ENV{LIB}")
elseif(APPLE)
string(REPLACE ":" ";" _lib_env2 "$ENV{DYLD_LIBRARY_PATH}")
else()
string(REPLACE ":" ";" _lib_env2 "$ENV{LD_LIBRARY_PATH}")
endif()
list(APPEND _lib_env "${_lib_env2}")
# collect environment paths to dig
# Should not need to do that
set(_lib_env ENV LIBRARY_PATH)
if (WIN32)
list(APPEND _lib_env ENV LIB)
elseif (APPLE)
list(APPEND _lib_env ENV DYLD_LIBRARY_PATH)
else ()
list(APPEND _lib_env ENV LD_LIBRARY_PATH)
endif ()
list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
# copy the lib list
# copy the lib list
set (${lib_list}_COPY "${${lib_list}}")
# reset the lib list to populate
set(${lib_list} "")
foreach(_library ${${lib_list}_COPY})
......@@ -46,15 +50,21 @@ macro(LIBRARIES_ABSOLUTE_PATH lib_list hints_paths)
else()
# replace pattern -lfoo -> foo
string(REGEX REPLACE "^-l" "" _library "${_library}")
# remove extensions if exist
get_filename_component(_lext "${_library}" LAST_EXT)
get_filename_component(_ext "${_library}" EXT)
set(_lib_extensions ".so" ".a" ".dyld" ".dll")
list(FIND _lib_extensions "${_ext}" _index)
if (${_index} GREATER -1)
if ( "${_lext}" IN_LIST CMAKE_FIND_LIBRARY_SUFFIXES )
get_filename_component(_library "${_library}" NAME_WLE)
elseif ( "${_ext}" IN_LIST CMAKE_FIND_LIBRARY_SUFFIXES )
get_filename_component(_library "${_library}" NAME_WE)
endif()
# try to find the lib
find_library(_library_path NAMES ${_library} HINTS ${hints_paths} ${_lib_env})
find_library(_library_path
NAMES ${_library}
HINTS ${hints_paths} ${_lib_env}
)
if (_library_path)
list(APPEND ${lib_list} ${_library_path})
else()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment