Commit 5966d634 authored by PRUVOST Florent's avatar PRUVOST Florent

separate link flags and libraries in Finds

parent ed62a6ed
......@@ -306,6 +306,9 @@ if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_SOURCE_DIR}/cmake_modules/")
# the RPATH to be used when installing
list(APPEND CMAKE_INSTALL_RPATH "${CBLAS_LIBRARY_DIRS}")
endif()
if(CBLAS_LINKER_FLAGS)
list(APPEND CMAKE_EXE_LINKER_FLAGS "${CBLAS_LINKER_FLAGS}")
endif()
else()
if(MORSE_VERBOSE_FIND_PACKAGE)
if(CBLAS_STANDALONE OR NOT CBLAS_WORKS)
......@@ -342,6 +345,9 @@ if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_SOURCE_DIR}/cmake_modules/")
# the RPATH to be used when installing
list(APPEND CMAKE_INSTALL_RPATH "${LAPACKE_LIBRARY_DIRS}")
endif()
if(LAPACKE_LINKER_FLAGS)
list(APPEND CMAKE_EXE_LINKER_FLAGS "${LAPACKE_LINKER_FLAGS}")
endif()
else()
if(MORSE_VERBOSE_FIND_PACKAGE)
if (LAPACKE_STANDALONE OR NOT LAPACKE_WORKS)
......@@ -369,6 +375,9 @@ if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_SOURCE_DIR}/cmake_modules/")
else()
message(FATAL_ERROR "A TMG library is required but has not been found")
endif()
if(TMG_LINKER_FLAGS)
list(APPEND CMAKE_EXE_LINKER_FLAGS "${TMG_LINKER_FLAGS}")
endif()
endif()
# CHAMELEON depends on CUDA/CUBLAS
......@@ -464,6 +473,9 @@ if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_SOURCE_DIR}/cmake_modules/")
# tests for intel mpi
#list(APPEND MPI_C_COMPILE_FLAGS "-mt_mpi")
#list(APPEND MPI_COMPILE_FLAGS "-mt_mpi")
if(MPI_C_LINK_FLAGS)
list(APPEND CMAKE_EXE_LINKER_FLAGS "${MPI_C_LINK_FLAGS}")
endif()
endif (MPI_C_FOUND)
endif (CHAMELEON_USE_MPI)
......@@ -541,6 +553,9 @@ if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_SOURCE_DIR}/cmake_modules/")
" - Activate StarPU in Chameleon${ColourReset}")
add_definitions(-DCHAMELEON_SCHED_STARPU) # TODO: remove that
include_directories(${STARPU_INCLUDE_DIRS})
if(STARPU_LINKER_FLAGS)
list(APPEND CMAKE_EXE_LINKER_FLAGS "${STARPU_LINKER_FLAGS}")
endif()
set(CMAKE_REQUIRED_INCLUDES "${STARPU_INCLUDE_DIRS}")
foreach(libdir ${STARPU_LIBRARY_DIRS})
list(APPEND CMAKE_REQUIRED_FLAGS "-L${libdir}")
......@@ -684,6 +699,9 @@ if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_SOURCE_DIR}/cmake_modules/")
endif()
list(REMOVE_DUPLICATES CMAKE_EXE_LINKER_FLAGS)
string(REPLACE ";" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
# Add define for Fortran Mangling (should be defined somewhere else)
# ------------------------------------------------------------------
message("-- ${Blue}Add definition ADD_"
......@@ -808,7 +826,7 @@ if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_SOURCE_DIR}/cmake_modules/")
string(REGEX MATCH ".*ifort$" _match_ifort ${CMAKE_Fortran_COMPILER})
if(_match_ifort)
#message(STATUS "Add -nofor_main to the Fortran linker")
set(CMAKE_Fortran_FLAGS "-nofor_main")
list(APPEND CMAKE_Fortran_FLAGS "-nofor_main")
endif(_match_ifort)
# Testing executables
......
......@@ -110,7 +110,7 @@ macro(Print_Find_Library_Blas_Status _libname _lib_to_find)
endif()
endif()
message("${BoldYellow}Please indicate where to find ${_lib_to_find}. You have three options:\n"
"- Option 1: Provide the root directory of the library with cmake option: -D${LIBNAME}_DIR=your/path/to/${libname}/\n"
"- Option 1: Provide the Installation directory of BLAS library with cmake option: -D${LIBNAME}_DIR=your/path/to/${libname}/\n"
"- Option 2: Provide the directory where to find the library with cmake option: -D${LIBNAME}_LIBDIR=your/path/to/${libname}/lib/\n"
"- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
"- Option 4: If your library provides a PkgConfig file, make sure pkg-config finds your library${ColourReset}")
......@@ -135,14 +135,13 @@ macro(Print_Find_Library_Blas_CheckFunc_Status _name)
endmacro()
if (NOT BLAS_FOUND)
set(BLAS_DIR "" CACHE PATH "Root directory of BLAS library")
set(BLAS_DIR "" CACHE PATH "Installation directory of BLAS library")
if (NOT BLAS_FIND_QUIETLY)
message(STATUS "A cache variable, namely BLAS_DIR, has been set to specify the install directory of BLAS")
endif()
endif()
option(BLAS_VERBOSE "Print some additional information during BLAS
libraries detection" OFF)
option(BLAS_VERBOSE "Print some additional information during BLAS libraries detection" OFF)
include(CheckFunctionExists)
include(CheckFortranFunctionExists)
......@@ -179,7 +178,7 @@ macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread)
set(_libdir ${ARGN})
set(_libraries_work TRUE)
set(${LIBRARIES} ${_flags})
set(${LIBRARIES})
set(_combined_name)
if (NOT _libdir)
if (BLAS_DIR)
......@@ -192,20 +191,20 @@ macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread)
list(APPEND _libdir "${BLAS_DIR}/lib32")
list(APPEND _libdir "${BLAS_DIR}/lib/ia32")
endif()
endif ()
if (BLAS_LIBDIR)
elseif (BLAS_LIBDIR)
list(APPEND _libdir "${BLAS_LIBDIR}")
endif ()
if (WIN32)
string(REPLACE ":" ";" _libdir2 "$ENV{LIB}")
elseif (APPLE)
string(REPLACE ":" ";" _libdir2 "$ENV{DYLD_LIBRARY_PATH}")
else ()
string(REPLACE ":" ";" _libdir2 "$ENV{LD_LIBRARY_PATH}")
endif ()
list(APPEND _libdir "${_libdir2}")
list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
else()
if (WIN32)
string(REPLACE ":" ";" _libdir2 "$ENV{LIB}")
elseif (APPLE)
string(REPLACE ":" ";" _libdir2 "$ENV{DYLD_LIBRARY_PATH}")
else ()
string(REPLACE ":" ";" _libdir2 "$ENV{LD_LIBRARY_PATH}")
endif ()
list(APPEND _libdir "${_libdir2}")
list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
endif()
endif ()
if (BLAS_VERBOSE)
......@@ -272,10 +271,10 @@ macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread)
endif()
if(_libraries_work)
set(${LIBRARIES} ${${LIBRARIES}} ${_thread})
else()
set(${LIBRARIES} ${${LIBRARIES}} ${_thread})
else(_libraries_work)
set(${LIBRARIES} FALSE)
endif()
endif(_libraries_work)
# message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
......@@ -476,6 +475,9 @@ if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
"${SEARCH_LIBS}"
"${CMAKE_THREAD_LIBS_INIT};${LM}"
)
if(_LIBRARIES)
set(BLAS_LINKER_FLAGS "${additional_flags}")
endif()
endif()
endforeach ()
......@@ -870,7 +872,7 @@ if(BLA_F95)
else(BLAS95_FOUND)
message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas 95 libraries could not be found or check of symbols failed."
"\nPlease indicate where to find blas libraries. You have three options:\n"
"- Option 1: Provide the root directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
"- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
"- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
"- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
"\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
......@@ -890,6 +892,9 @@ if(BLA_F95)
set(BLAS_FOUND TRUE)
set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
if (NOT BLAS_LIBRARIES_DEP)
set(BLAS_LIBRARIES_DEP "${BLAS95_LIBRARIES}")
endif()
else(BLA_F95)
......@@ -906,7 +911,7 @@ else(BLA_F95)
else(BLAS_FOUND)
message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas libraries could not be found or check of symbols failed."
"\nPlease indicate where to find blas libraries. You have three options:\n"
"- Option 1: Provide the root directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
"- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
"- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
"- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
"\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
......@@ -927,3 +932,13 @@ else(BLA_F95)
endif(BLA_F95)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
if (BLAS_FOUND AND NOT BLAS_DIR)
list(GET BLAS_LIBRARIES 0 first_lib)
get_filename_component(first_lib_path "${first_lib}" PATH)
if (${first_lib_path} MATCHES "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)")
string(REGEX REPLACE "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)" "" not_cached_dir "${first_lib_path}")
set(BLAS_DIR "${not_cached_dir}" CACHE PATH "Installation directory of BLAS library" FORCE)
endif()
endif()
......@@ -26,6 +26,7 @@
# This module finds headers and cblas library.
# Results are reported in variables:
# CBLAS_FOUND - True if headers and requested libraries were found
# CBLAS_LINKER_FLAGS - list of required linker flags (excluding -l and -L)
# CBLAS_INCLUDE_DIRS - cblas include directories
# CBLAS_LIBRARY_DIRS - Link directories for cblas libraries
# CBLAS_LIBRARIES - cblas component libraries to be linked
......@@ -65,7 +66,7 @@
if (NOT CBLAS_FOUND)
set(CBLAS_DIR "" CACHE PATH "Root directory of CBLAS library")
set(CBLAS_DIR "" CACHE PATH "Installation directory of CBLAS library")
if (NOT CBLAS_FIND_QUIETLY)
message(STATUS "A cache variable, namely CBLAS_DIR, has been set to specify the install directory of CBLAS")
endif()
......@@ -107,7 +108,7 @@ if (BLAS_FOUND)
# check if a cblas function exists in the BLAS lib
# this can be the case with libs such as MKL, ACML
include(CheckFunctionExists)
set(CMAKE_REQUIRED_LIBRARIES "${BLAS_LIBRARIES}")
set(CMAKE_REQUIRED_LIBRARIES "${BLAS_LINKER_FLAGS};${BLAS_LIBRARIES}")
unset(CBLAS_WORKS CACHE)
check_function_exists(cblas_dscal CBLAS_WORKS)
mark_as_advanced(CBLAS_WORKS)
......@@ -119,10 +120,15 @@ if (BLAS_FOUND)
endif()
# test succeeds: CBLAS is in BLAS
set(CBLAS_LIBRARIES "${BLAS_LIBRARIES}")
set(CBLAS_LIBRARY_DIRS "${BLAS_LIBRARY_DIRS}")
if (BLAS_LIBRARY_DIRS)
set(CBLAS_LIBRARY_DIRS "${BLAS_LIBRARY_DIRS}")
endif()
if(BLAS_INCLUDE_DIRS)
set(CBLAS_INCLUDE_DIRS "${BLAS_INCLUDE_DIRS}")
endif()
if (BLAS_LINKER_FLAGS)
set(CBLAS_LINKER_FLAGS "${BLAS_LINKER_FLAGS}")
endif()
endif()
endif (NOT CBLAS_STANDALONE)
......@@ -258,6 +264,7 @@ if (BLAS_FOUND)
if(CBLAS_LIBRARIES)
set(REQUIRED_INCDIRS)
set(REQUIRED_LDFLAGS)
set(REQUIRED_LIBDIRS)
set(REQUIRED_LIBS)
......@@ -277,10 +284,14 @@ if (BLAS_FOUND)
list(APPEND REQUIRED_LIBDIRS "${BLAS_LIBRARY_DIRS}")
endif()
list(APPEND REQUIRED_LIBS "${BLAS_LIBRARIES}")
if (BLAS_LINKER_FLAGS)
list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}")
endif()
# set required libraries for link
set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
set(CMAKE_REQUIRED_LIBRARIES)
list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}")
foreach(lib_dir ${REQUIRED_LIBDIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
endforeach()
......@@ -297,8 +308,10 @@ if (BLAS_FOUND)
set(CBLAS_LIBRARIES_DEP "${REQUIRED_LIBS}")
set(CBLAS_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
set(CBLAS_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
set(CBLAS_LINKER_FLAGS "${REQUIRED_LDFLAGS}")
list(REMOVE_DUPLICATES CBLAS_LIBRARY_DIRS_DEP)
list(REMOVE_DUPLICATES CBLAS_INCLUDE_DIRS_DEP)
list(REMOVE_DUPLICATES CBLAS_LINKER_FLAGS)
else()
if(NOT CBLAS_FIND_QUIETLY)
message(STATUS "Looking for cblas : test of cblas_dscal with cblas and blas libraries fails")
......@@ -323,6 +336,14 @@ else(BLAS_FOUND)
endif(BLAS_FOUND)
if (CBLAS_LIBRARIES AND NOT CBLAS_DIR)
list(GET CBLAS_LIBRARIES 0 first_lib)
get_filename_component(first_lib_path "${first_lib}" PATH)
if (${first_lib_path} MATCHES "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)")
string(REGEX REPLACE "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)" "" not_cached_dir "${first_lib_path}")
set(CBLAS_DIR "${not_cached_dir}" CACHE PATH "Installation directory of CBLAS library" FORCE)
endif()
endif()
# check that CBLAS has been found
# -------------------------------
......
......@@ -37,6 +37,7 @@
# This module finds headers and chameleon library.
# Results are reported in variables:
# CHAMELEON_FOUND - True if headers and requested libraries were found
# CHAMELEON_LINKER_FLAGS - list of required linker flags (excluding -l and -L)
# CHAMELEON_INCLUDE_DIRS - chameleon include directories
# CHAMELEON_LIBRARY_DIRS - Link directories for chameleon libraries
# CHAMELEON_INCLUDE_DIRS_DEP - chameleon + dependencies include directories
......@@ -67,7 +68,7 @@
if (NOT CHAMELEON_FOUND)
set(CHAMELEON_DIR "" CACHE PATH "Root directory of CHAMELEON library")
set(CHAMELEON_DIR "" CACHE PATH "Installation directory of CHAMELEON library")
if (NOT CHAMELEON_FIND_QUIETLY)
message(STATUS "A cache variable, namely CHAMELEON_DIR, has been set to specify the install directory of CHAMELEON")
endif()
......@@ -116,7 +117,7 @@ endif()
# -------------------------------------------------------------------------------------
include(FindPkgConfig)
find_package(PkgConfig QUIET)
if(PKG_CONFIG_EXECUTABLE)
if(PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_DIR)
pkg_search_module(CHAMELEON chameleon)
if (NOT CHAMELEON_FIND_QUIETLY)
......@@ -155,7 +156,7 @@ if(PKG_CONFIG_EXECUTABLE)
endif()
endif()
endif(PKG_CONFIG_EXECUTABLE)
endif()
if( (NOT PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR NOT CHAMELEON_FOUND )
......@@ -499,10 +500,10 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR NOT CHAMELEON_FOUND )
# check a function to validate the find
if(CHAMELEON_LIBRARIES)
set(REQUIRED_LDFLAGS)
set(REQUIRED_INCDIRS)
set(REQUIRED_LIBDIRS)
set(REQUIRED_LIBS)
set(REQUIRED_FLAGS)
# CHAMELEON
if (CHAMELEON_INCLUDE_DIRS)
......@@ -598,7 +599,7 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR NOT CHAMELEON_FOUND )
list(APPEND REQUIRED_INCDIRS "${MPI_C_INCLUDE_PATH}")
endif()
if (MPI_C_LINK_FLAGS)
list(APPEND REQUIRED_FLAGS "${MPI_C_LINK_FLAGS}")
list(APPEND REQUIRED_LDFLAGS "${MPI_C_LINK_FLAGS}")
endif()
list(APPEND REQUIRED_LIBS "${MPI_C_LIBRARIES}")
endif()
......@@ -637,6 +638,9 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR NOT CHAMELEON_FOUND )
elseif(TMG_LIBRARIES)
list(APPEND REQUIRED_LIBS "${TMG_LIBRARIES}")
endif()
if (TMG_LINKER_FLAGS)
list(APPEND REQUIRED_LDFLAGS "${TMG_LINKER_FLAGS}")
endif()
endif()
# LAPACKE
if (LAPACKE_FOUND)
......@@ -655,6 +659,9 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR NOT CHAMELEON_FOUND )
elseif(LAPACKE_LIBRARIES)
list(APPEND REQUIRED_LIBS "${LAPACKE_LIBRARIES}")
endif()
if (LAPACK_LINKER_FLAGS)
list(APPEND REQUIRED_LDFLAGS "${LAPACK_LINKER_FLAGS}")
endif()
endif()
# CBLAS
if (CBLAS_FOUND)
......@@ -673,6 +680,9 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR NOT CHAMELEON_FOUND )
elseif(CBLAS_LIBRARIES)
list(APPEND REQUIRED_LIBS "${CBLAS_LIBRARIES}")
endif()
if (BLAS_LINKER_FLAGS)
list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}")
endif()
endif()
# EXTRA LIBS such that pthread, m, rt
list(APPEND REQUIRED_LIBS ${CHAMELEON_EXTRA_LIBRARIES})
......@@ -680,11 +690,11 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR NOT CHAMELEON_FOUND )
# set required libraries for link
set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
set(CMAKE_REQUIRED_LIBRARIES)
list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}")
foreach(lib_dir ${REQUIRED_LIBDIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
endforeach()
list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
list(APPEND CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}")
# test link
unset(CHAMELEON_WORKS CACHE)
......@@ -694,15 +704,13 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR NOT CHAMELEON_FOUND )
if(CHAMELEON_WORKS)
# save link with dependencies
if (REQUIRED_FLAGS)
set(CHAMELEON_LIBRARIES_DEP "${REQUIRED_FLAGS};${REQUIRED_LIBS}")
else()
set(CHAMELEON_LIBRARIES_DEP "${REQUIRED_LIBS}")
endif()
set(CHAMELEON_LIBRARIES_DEP "${REQUIRED_LIBS}")
set(CHAMELEON_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
set(CHAMELEON_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
set(CHAMELEON_LINKER_FLAGS "${REQUIRED_LDFLAGS}")
list(REMOVE_DUPLICATES CHAMELEON_LIBRARY_DIRS_DEP)
list(REMOVE_DUPLICATES CHAMELEON_INCLUDE_DIRS_DEP)
list(REMOVE_DUPLICATES CHAMELEON_LINKER_FLAGS)
else()
if(NOT CHAMELEON_FIND_QUIETLY)
message(STATUS "Looking for chameleon : test of MORSE_Init fails")
......@@ -721,6 +729,22 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR NOT CHAMELEON_FOUND )
endif( (NOT PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR NOT CHAMELEON_FOUND )
if (CHAMELEON_LIBRARIES AND NOT CHAMELEON_DIR)
if (CHAMELEON_LIBRARY_DIRS)
foreach(dir ${CHAMELEON_LIBRARY_DIRS})
if ("${dir}" MATCHES "chameleon")
set(first_lib_path "${dir}")
endif()
endforeach()
else()
list(GET CHAMELEON_LIBRARIES 0 first_lib)
get_filename_component(first_lib_path "${first_lib}" PATH)
endif()
if (${first_lib_path} MATCHES "/lib(32|64)?$")
string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
set(CHAMELEON_DIR "${not_cached_dir}" CACHE PATH "Installation directory of CHAMELEON library" FORCE)
endif()
endif()
# check that CHAMELEON has been found
# ---------------------------------
......
......@@ -26,6 +26,8 @@
# This module finds headers and fftw library.
# Results are reported in variables:
# FFTW_FOUND - True if headers and requested libraries were found
# FFTW_C_FLAGS - list of required compilation flags (excluding -I)
# FFTW_LINKER_FLAGS - list of required linker flags (excluding -l and -L)
# FFTW_INCLUDE_DIRS - fftw include directories
# FFTW_LIBRARY_DIRS - Link directories for fftw libraries
# FFTW_LIBRARIES - fftw component libraries to be linked
......@@ -58,7 +60,7 @@
if (NOT FFTW_FOUND)
set(FFTW_DIR "" CACHE PATH "Root directory of FFTW library")
set(FFTW_DIR "" CACHE PATH "Installation directory of FFTW library")
if (NOT FFTW_FIND_QUIETLY)
message(STATUS "A cache variable, namely FFTW_DIR, has been set to specify the install directory of FFTW")
endif()
......@@ -344,6 +346,8 @@ if( NOT FFTW_FOUND )
# check a function to validate the find
if(FFTW_LIBRARIES)
set(REQUIRED_FLAGS)
set(REQUIRED_LDFLAGS)
set(REQUIRED_INCDIRS)
set(REQUIRED_LIBDIRS)
set(REQUIRED_LIBS)
......@@ -363,21 +367,24 @@ if( NOT FFTW_FOUND )
# OMP
if(FFTW_LOOK_FOR_OMP)
if (CMAKE_C_COMPILER MATCHES ".+gcc.*")
set(CMAKE_REQUIRED_FLAGS "-fopenmp")
set(REQUIRED_FLAGS "-fopenmp")
endif()
endif()
# MKL
if(FFTW_LOOK_FOR_MKL)
list(APPEND REQUIRED_LIBS "-Wl,--no-as-needed;${CMAKE_REQUIRED_LIBRARIES};${CMAKE_THREAD_LIBS_INIT};-lm")
list(APPEND REQUIRED_LIBS "${CMAKE_THREAD_LIBS_INIT};-lm")
list(APPEND REQUIRED_LDFLAGS "-Wl,--no-as-needed")
endif()
# set required libraries for link
set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
set(CMAKE_REQUIRED_LIBRARIES)
list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}")
foreach(lib_dir ${REQUIRED_LIBDIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
endforeach()
list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
list(APPEND CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}")
# test link
unset(FFTW_WORKS CACHE)
......@@ -390,13 +397,17 @@ if( NOT FFTW_FOUND )
set(FFTW_LIBRARIES_DEP "${REQUIRED_LIBS}")
set(FFTW_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
set(FFTW_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
set(FFTW_C_FLAGS "${REQUIRED_FLAGS}")
set(FFTW_LINKER_FLAGS "${REQUIRED_LDFLAGS}")
list(REMOVE_DUPLICATES FFTW_LIBRARY_DIRS_DEP)
list(REMOVE_DUPLICATES FFTW_INCLUDE_DIRS_DEP)
list(REMOVE_DUPLICATES FFTW_LINKER_FLAGS)
else()
if(NOT FFTW_FIND_QUIETLY)
message(STATUS "Looking for FFTW : test of ${FFTW_PREC_TESTFUNC}fftw_execute_ with fftw library fails")
message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
message(STATUS "CMAKE_REQUIRED_FLAGS: ${CMAKE_REQUIRED_FLAGS}")
message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
endif()
else()
......@@ -409,6 +420,14 @@ if( NOT FFTW_FOUND )
endif( NOT FFTW_FOUND )
if (FFTW_LIBRARIES AND NOT FFTW_DIR)
list(GET FFTW_LIBRARIES 0 first_lib)
get_filename_component(first_lib_path "${first_lib}" PATH)
if (${first_lib_path} MATCHES "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)")
string(REGEX REPLACE "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)" "" not_cached_dir "${first_lib_path}")
set(FFTW_DIR "${not_cached_dir}" CACHE PATH "Installation directory of FFTW library" FORCE)
endif()
endif()
# check that FFTW has been found
# -------------------------------
......
......@@ -44,7 +44,7 @@
# License text for the above reference.)
if (NOT FXT_FOUND)
set(FXT_DIR "" CACHE PATH "Root directory of FXT library")
set(FXT_DIR "" CACHE PATH "Installation directory of FXT library")
if (NOT FXT_FIND_QUIETLY)
message(STATUS "A cache variable, namely FXT_DIR, has been set to specify the install directory of FXT")
endif()
......@@ -54,7 +54,7 @@ endif()
# -------------------------------------------------------------------------------------
include(FindPkgConfig)
find_package(PkgConfig QUIET)
if(PKG_CONFIG_EXECUTABLE)
if(PKG_CONFIG_EXECUTABLE AND NOT FXT_DIR)
pkg_search_module(FXT fxt)
if (NOT FXT_FIND_QUIETLY)
......@@ -72,7 +72,7 @@ if(PKG_CONFIG_EXECUTABLE)
endif()
endif()
endif(PKG_CONFIG_EXECUTABLE)
endif()
if( (NOT PKG_CONFIG_EXECUTABLE AND NOT FXT_FOUND) OR NOT FXT_FOUND )
......@@ -250,6 +250,18 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT FXT_FOUND) OR NOT FXT_FOUND )
endif( (NOT PKG_CONFIG_EXECUTABLE AND NOT FXT_FOUND) OR NOT FXT_FOUND )
if (FXT_LIBRARIES AND NOT FXT_DIR)
if (FXT_LIBRARY_DIRS)
list(GET FXT_LIBRARY_DIRS 0 first_lib_path)
else()
list(GET FXT_LIBRARIES 0 first_lib)
get_filename_component(first_lib_path "${first_lib}" PATH)
endif()
if (${first_lib_path} MATCHES "/lib(32|64)?$")
string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
set(FXT_DIR "${not_cached_dir}" CACHE PATH "Installation directory of FXT library" FORCE)
endif()
endif()
# check that FXT has been found
# -------------------------------
......
......@@ -45,7 +45,7 @@
if (NOT HWLOC_FOUND)
set(HWLOC_DIR "" CACHE PATH "Root directory of HWLOC library")
set(HWLOC_DIR "" CACHE PATH "Installation directory of HWLOC library")
if (NOT HWLOC_FIND_QUIETLY)
message(STATUS "A cache variable, namely HWLOC_DIR, has been set to specify the install directory of HWLOC")
endif()
......@@ -55,7 +55,7 @@ endif()
# -------------------------------------------------------------------------------------
include(FindPkgConfig)
find_package(PkgConfig QUIET)
if(PKG_CONFIG_EXECUTABLE)
if(PKG_CONFIG_EXECUTABLE AND NOT HWLOC_DIR)
pkg_search_module(HWLOC hwloc)
if (NOT HWLOC_FIND_QUIETLY)
......@@ -73,7 +73,7 @@ if(PKG_CONFIG_EXECUTABLE)
endif()
endif()
endif(PKG_CONFIG_EXECUTABLE)
endif()
if( (NOT PKG_CONFIG_EXECUTABLE AND NOT HWLOC_FOUND) OR NOT HWLOC_FOUND )
......@@ -257,6 +257,18 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT HWLOC_FOUND) OR NOT HWLOC_FOUND )
endif( (NOT PKG_CONFIG_EXECUTABLE AND NOT HWLOC_FOUND) OR NOT HWLOC_FOUND )
if (HWLOC_LIBRARIES AND NOT HWLOC_DIR)
if (HWLOC_LIBRARY_DIRS)
list(GET HWLOC_LIBRARY_DIRS 0 first_lib_path)
else()
list(GET HWLOC_LIBRARIES 0 first_lib)
get_filename_component(first_lib_path "${first_lib}" PATH)
endif()
if (${first_lib_path} MATCHES "/lib(32|64)?$")
string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
set(HWLOC_DIR "${not_cached_dir}" CACHE PATH "Installation directory of HWLOC library" FORCE)
endif()
endif()
# check that HWLOC has been found
# -------------------------------
......
......@@ -106,7 +106,7 @@ macro(Print_Find_Library_Blas_Status _libname _lib_to_find)
endif()
endif()
message("${BoldYellow}Please indicate where to find ${_lib_to_find}. You have three options:\n"
"- Option 1: Provide the root directory of the library with cmake option: -D${LIBNAME}_DIR=your/path/to/${libname}/\n"
"- Option 1: Provide the installation directory of the library with cmake option: -D${LIBNAME}_DIR=your/path/to/${libname}/\n"
"- Option 2: Provide the directory where to find the library with cmake option: -D${LIBNAME}_LIBDIR=your/path/to/${libname}/lib/\n"
"- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
"- Option 4: If your library provides a PkgConfig file, make sure pkg-config finds your library${ColourReset}")
......@@ -114,7 +114,7 @@ macro(Print_Find_Library_Blas_Status _libname _lib_to_find)
endmacro()
if (NOT LAPACK_FOUND)
set(LAPACK_DIR "" CACHE PATH "Root directory of LAPACK library")
set(LAPACK_DIR "" CACHE PATH "Installation directory of LAPACK library")
if (NOT LAPACK_FIND_QUIETLY)
message(STATUS "A cache variable, namely LAPACK_DIR, has been set to specify the install directory of LAPACK")
endif()
......@@ -165,8 +165,7 @@ if (NOT _libdir)
list(APPEND _libdir "${BLAS_DIR}/lib32")
list(APPEND _libdir "${BLAS_DIR}/lib/ia32")
endif()
endif ()
if (BLAS_LIBDIR)
elseif (BLAS_LIBDIR)
list(APPEND _libdir "${BLAS_LIBDIR}")
endif ()
if (LAPACK_DIR)
......@@ -179,20 +178,20 @@ if (NOT _libdir)
list(APPEND _libdir "${LAPACK_DIR}/lib32")
list(APPEND _libdir "${LAPACK_DIR}/lib/ia32")
endif()
endif ()
if (LAPACK_LIBDIR)
elseif (LAPACK_LIBDIR)
list(APPEND _libdir "${LAPACK_LIBDIR}")
else()
if (WIN32)
string(REPLACE ":" ";" _libdir2 "$ENV{LIB}")
elseif (APPLE)
string(REPLACE ":" ";" _libdir2 "$ENV{DYLD_LIBRARY_PATH}")
else ()
string(REPLACE ":" ";" _libdir2 "$ENV{LD_LIBRARY_PATH}")
endif ()
list(APPEND _libdir "${_libdir2}")
list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
endif ()
if (WIN32)
string(REPLACE ":" ";" _libdir2 "$ENV{LIB}")
elseif (APPLE)
string(REPLACE ":" ";" _libdir2 "$ENV{DYLD_LIBRARY_PATH}")
else ()
string(REPLACE ":" ";" _libdir2 "$ENV{LD_LIBRARY_PATH}")
endif ()
list(APPEND _libdir "${_libdir2}")
list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
endif ()
if (LAPACK_VERBOSE)
......@@ -367,6 +366,8 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
set(LAPACK_SEARCH_LIBS "")
set(additional_flags "-Wl,--no-as-needed")
if (BLA_F95)
set(LAPACK_mkl_SEARCH_SYMBOL "CHEEV")
set(_LIBRARIES LAPACK95_LIBRARIES)
......@@ -399,11 +400,14 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
${_LIBRARIES}
BLAS
${LAPACK_mkl_SEARCH_SYMBOL}
""
"${additional_flags}"
""
"${_BLAS_LIBRARIES}"
"${CMAKE_THREAD_LIBS_INIT};${LM}"
)
if(_LIBRARIES)
set(LAPACK_LINKER_FLAGS "${additional_flags}")
endif()
endif ()
# Then try the search libs
foreach (IT ${LAPACK_SEARCH_LIBS})
......@@ -412,11 +416,14 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
${_LIBRARIES}
BLAS