Commit a24a413d authored by PRUVOST Florent's avatar PRUVOST Florent

factorize with a more powerful macro

parent 4d09e382
###
#
# @copyright (c) 2018 Inria. All rights reserved.
#
###
#
# @file LibrariesAbsolutePath.cmake
#
# @project MORSE
# MORSE is a software package provided by:
# Inria Bordeaux - Sud-Ouest,
# Univ. of Tennessee,
# King Abdullah Univesity of Science and Technology
# Univ. of California Berkeley,
# Univ. of Colorado Denver.
#
# @version 1.0.0
# @author Florent Pruvost
# @date 13-04-2018
#
###
# 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
if(WIN32)
string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
elseif(APPLE)
string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
else()
string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
endif()
list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
# copy the lib list
set (${lib_list}_COPY "${${lib_list}}")
# reset the lib list to populate
set(${lib_list} "")
foreach(_library ${${lib_list}_COPY})
if(EXISTS "${_library}")
# if already an absolute path, nothing special to do
list(APPEND ${lib_list} ${_library})
else()
# replace pattern -lfoo -> foo
string(REGEX REPLACE "^-l" "" _library "${_library}")
# remove extensions if exist
get_filename_component(_ext "${_library}" EXT)
set(_lib_extensions ".so" ".a" ".dyld" ".dll")
list(FIND _lib_extensions "${_ext}" _index)
if (${_index} GREATER -1)
get_filename_component(_library "${_library}" NAME_WE)
endif()
# try to find the lib
find_library(_library_path NAMES ${_library} HINTS ${hints_paths} ${_lib_env})
if (_library_path)
list(APPEND ${lib_list} ${_library_path})
else()
message(FATAL_ERROR "Dependency of ${lib_list} '${_library}' NOT FOUND")
endif()
unset(_library_path CACHE)
endif()
endforeach()
endmacro()
##
## @end file LibrariesAbsolutePath.cmake
##
......@@ -53,6 +53,9 @@ include(FindHeadersAndLibs)
# To transform relative path from pkg-config into absolute
include(FindPkgconfigLibrariesAbsolutePath)
# To transform relative path into absolute for a list of libraries
include(LibrariesAbsolutePath)
# Some macros to print status when search for headers and libs
# PrintFindStatus.cmake is in cmake_modules/morse/find directory
include(PrintFindStatus)
......
......@@ -610,15 +610,7 @@ if( (NOT BLAS_FOUND_WITH_PKGCONFIG) OR BLAS_GIVEN_BY_USER )
find_package(Threads REQUIRED)
endif()
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
endif ()
set(BLAS_SEARCH_LIBS "")
......
......@@ -203,15 +203,7 @@ if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUN
endif()
set(CHAMELEON_EXTRA_LIBRARIES "")
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
list(APPEND CHAMELEON_EXTRA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
endif ()
......@@ -312,22 +304,7 @@ if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUN
mark_as_advanced(CUDA_SDK_ROOT_DIR)
mark_as_advanced(CUDA_TOOLKIT_ROOT_DIR)
mark_as_advanced(CUDA_VERBOSE_BUILD)
if(WIN32)
string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
elseif(APPLE)
string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
else()
string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
endif()
string(REGEX REPLACE "-l" "" CUDA_LIBS "${CUDA_LIBRARIES}")
set(CUDA_LIBRARIES)
foreach(_lib ${CUDA_LIBS})
find_library(CUDA_${_lib}_LIBRARY NAMES ${_lib}
HINTS $ENV{CUDA_ROOT}/lib64 ${_lib_env} ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (CUDA_${_lib}_LIBRARY)
list(APPEND CUDA_LIBRARIES ${CUDA_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CUDA_LIBRARIES "$ENV{CUDA_ROOT}/lib64")
endif()
endif()
......
......@@ -224,15 +224,7 @@ endif()
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
endif ()
set(ENV_FFTW_DIR "$ENV{FFTW_DIR}")
......
......@@ -467,15 +467,7 @@ if(BLAS_FOUND)
find_package(Threads REQUIRED)
endif()
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
endif ()
set(LAPACK_SEARCH_LIBS "")
......
......@@ -78,22 +78,7 @@ else()
find_package(CUDA)
endif()
if( CUDA_FOUND )
if(WIN32)
string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
elseif(APPLE)
string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
else()
string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
endif()
string(REGEX REPLACE "-l" "" CUDA_LIBS "${CUDA_LIBRARIES}")
set(CUDA_LIBRARIES)
foreach(_lib ${CUDA_LIBS})
find_library(CUDA_${_lib}_LIBRARY NAMES ${_lib}
HINTS $ENV{CUDA_ROOT}/lib64 ${_lib_env} ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (CUDA_${_lib}_LIBRARY)
list(APPEND CUDA_LIBRARIES ${CUDA_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CUDA_LIBRARIES "$ENV{CUDA_ROOT}/lib64")
endif ()
# MAGMA depends on cuBLAS which should come with CUDA, if not found -> error
if (NOT CUDA_CUBLAS_LIBRARIES)
......
......@@ -142,15 +142,7 @@ else()
find_package(Threads)
endif()
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
endif ()
set(MUMPS_EXTRA_LIBRARIES "")
if( THREADS_FOUND )
......
......@@ -118,15 +118,7 @@ else()
find_package(Threads)
endif()
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
endif ()
set(PARSEC_EXTRA_LIBRARIES "")
if( THREADS_FOUND )
......@@ -215,22 +207,7 @@ if (PARSEC_LOOK_FOR_CUDA)
mark_as_advanced(CUDA_SDK_ROOT_DIR)
mark_as_advanced(CUDA_TOOLKIT_ROOT_DIR)
mark_as_advanced(CUDA_VERBOSE_BUILD)
if(WIN32)
string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
elseif(APPLE)
string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
else()
string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
endif()
string(REGEX REPLACE "-l" "" CUDA_LIBS "${CUDA_LIBRARIES}")
set(CUDA_LIBRARIES)
foreach(_lib ${CUDA_LIBS})
find_library(CUDA_${_lib}_LIBRARY NAMES ${_lib}
HINTS $ENV{CUDA_ROOT}/lib64 ${_lib_env} ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (CUDA_${_lib}_LIBRARY)
list(APPEND CUDA_LIBRARIES ${CUDA_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CUDA_LIBRARIES "$ENV{CUDA_ROOT}/lib64")
endif()
endif()
......
......@@ -166,15 +166,7 @@ else()
find_package(Threads)
endif()
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
endif ()
set(PASTIX_EXTRA_LIBRARIES "")
if( THREADS_FOUND )
......
......@@ -88,15 +88,7 @@ else()
find_package(Threads)
endif()
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
endif ()
# PTSCOTCH depends on MPI, try to find it
......
......@@ -89,15 +89,7 @@ else()
find_package(Threads)
endif()
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
endif ()
# QUARK may depend on HWLOC, try to find it
......
......@@ -342,15 +342,7 @@ if(BLAS_FOUND AND LAPACK_FOUND AND MPI_FOUND)
find_package(Threads REQUIRED)
endif()
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
endif ()
set(SCALAPACK_SEARCH_LIBS "")
......
......@@ -77,15 +77,7 @@ else()
find_package(Threads)
endif()
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
endif ()
# Looking for include
......
......@@ -122,17 +122,7 @@ endif()
# STARPU may depend on pthread, try to find it
find_package(Threads)
if( THREADS_FOUND )
string(REGEX REPLACE "-l" "" THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_THREAD_LIBS_INIT)
foreach(_lib ${THREAD_LIBS})
find_library(THREADS_${_lib}_LIBRARY NAMES ${_lib}
HINTS ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (THREADS_${_lib}_LIBRARY)
list(APPEND CMAKE_THREAD_LIBS_INIT ${THREADS_${_lib}_LIBRARY})
endif()
endforeach()
endif ()
if( THREADS_FOUND )
libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
list(APPEND STARPU_EXTRA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
endif ()
# STARPU may depend on libm, try to find it
......@@ -170,22 +160,7 @@ if (STARPU_LOOK_FOR_CUDA)
mark_as_advanced(CUDA_SDK_ROOT_DIR)
mark_as_advanced(CUDA_TOOLKIT_ROOT_DIR)
mark_as_advanced(CUDA_VERBOSE_BUILD)
if(WIN32)
string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
elseif(APPLE)
string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
else()
string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
endif()
string(REGEX REPLACE "-l" "" CUDA_LIBS "${CUDA_LIBRARIES}")
set(CUDA_LIBRARIES)
foreach(_lib ${CUDA_LIBS})
find_library(CUDA_${_lib}_LIBRARY NAMES ${_lib}
HINTS $ENV{CUDA_ROOT}/lib64 ${_lib_env} ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
if (CUDA_${_lib}_LIBRARY)
list(APPEND CUDA_LIBRARIES ${CUDA_${_lib}_LIBRARY})
endif()
endforeach()
libraries_absolute_path(CUDA_LIBRARIES "$ENV{CUDA_ROOT}/lib64")
endif()
endif()
......
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