diff --git a/modules/cblas.cmake b/modules/cblas.cmake index b5db822..3f168ee 100644 --- a/modules/cblas.cmake +++ b/modules/cblas.cmake @@ -20,10 +20,6 @@ option(ENABLE_CBLAS "Detect and link to CBLAS" OFF) if(ENABLE_CBLAS) - if(ENABLE_STATIC_LINKING) - set(CMAKE_FIND_LIBRARY_SUFFIXES .a) - endif() - include(CheckIncludeFile) function(_find_include_dir _names _hints _result) @@ -68,6 +64,10 @@ if(ENABLE_CBLAS) set(CBLAS_LIBRARIES "undefined") set(CBLAS_INCLUDE_DIR "undefined") + if(ENABLE_STATIC_LINKING) + set(CMAKE_FIND_LIBRARY_SUFFIXES .a) + endif() + if(APPLE) _find_include_dir(Accelerate/Accelerate.h /usr CBLAS_INCLUDE_DIR) _find_library(Accelerate cblas_dgemm CBLAS_LIBRARIES) @@ -76,7 +76,9 @@ if(ENABLE_CBLAS) _find_library(cblas cblas_dgemm CBLAS_LIBRARIES) endif() - if(NOT ${CBLAS_INCLUDE_DIR} STREQUAL "undefined" AND NOT ${CBLAS_LIBRARIES} STREQUAL "undefined") - set(CBLAS_FOUND TRUE) + if(NOT "${CBLAS_LIBRARIES}" STREQUAL "undefined") + if(NOT "${CBLAS_INCLUDE_DIR}" STREQUAL "undefined") + set(CBLAS_FOUND TRUE) + endif() endif() endif() diff --git a/modules/detect/detect_include_files.cmake b/modules/detect/detect_include_files.cmake new file mode 100644 index 0000000..dfa8dca --- /dev/null +++ b/modules/detect/detect_include_files.cmake @@ -0,0 +1,16 @@ +include(CheckIncludeFile) + +function(_find_include_dir _names _hints _result) + find_path(_include_dir + NAMES ${_names} + HINTS ${_hints} + ) + set(_all_include_files_work TRUE) + foreach(_name ${_names}) + check_include_file(${_include_dir}/${_name} _include_file_works) + set(_all_include_files_work (${_all_include_files_work} AND ${_include_file_works})) + endforeach() + if(${_all_include_files_work}) + set(${_result} ${_include_dir} PARENT_SCOPE) + endif() +endfunction() diff --git a/modules/detect/detect_libraries.cmake b/modules/detect/detect_libraries.cmake new file mode 100644 index 0000000..0683d8c --- /dev/null +++ b/modules/detect/detect_libraries.cmake @@ -0,0 +1,22 @@ +include(CheckFunctionExists) + +function(_find_library _names _check_function _result) + if(APPLE) + find_library(_lib + NAMES ${_names} + PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 + ENV DYLD_LIBRARY_PATH + ) + else() + find_library(_lib + NAMES ${_names} + PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 + ENV LD_LIBRARY_PATH + ) + endif() + set(CMAKE_REQUIRED_LIBRARIES ${_lib}) + check_function_exists(${_check_function} _library_works) + if(${_library_works}) + set(${_result} ${_lib} PARENT_SCOPE) + endif() +endfunction()