Commit 6b5f9a8a authored by Davis King's avatar Davis King

Setup the cmake files so that they can find and link to BLAS libraries

when available (on UNIX, no windows CMake BLAS stuff yet).

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402763
parent 13a920d5
......@@ -48,12 +48,15 @@ set (DLIB_ENABLE_ASSERTS_STR
"Enable this if you want to turn on the DLIB_ASSERT macro" )
set (DLIB_ENABLE_SHARED_BUILD_STR
"Enable this if you want to create a shared dlib library (.dll, .so)" )
set (DLIB_USE_BLAS_STR
"Disable this if you don't want to use a BLAS library" )
option(DLIB_ISO_CPP_ONLY ${DLIB_ISO_CPP_ONLY_STR} OFF)
option(DLIB_NO_GUI_SUPPORT ${DLIB_NO_GUI_SUPPORT_STR} OFF)
option(DLIB_ENABLE_STACK_TRACE ${DLIB_ENABLE_STACK_TRACE_STR} OFF)
option(DLIB_ENABLE_ASSERTS ${DLIB_ENABLE_ASSERTS_STR} OFF)
option(DLIB_ENABLE_SHARED_BUILD ${DLIB_ENABLE_SHARED_BUILD_STR} OFF)
option(DLIB_USE_BLAS ${DLIB_USE_BLAS_STR} ON)
if (DLIB_ENABLE_SHARED_BUILD)
......@@ -142,6 +145,17 @@ if (NOT DLIB_ISO_CPP_ONLY)
add_global_define(DLIB_PNG_SUPPORT)
endif()
if (DLIB_USE_BLAS)
# Try to find a BLAS library
include(cmake_find_blas.txt)
if (blas_found)
set (dlib_needed_libraries ${dlib_needed_libraries} ${blas_libraries})
else()
set(DLIB_USE_BLAS OFF CACHE STRING ${DLIB_USE_BLAS_STR} FORCE )
endif()
endif()
target_link_libraries(dlib ${dlib_needed_libraries} )
......@@ -153,6 +167,13 @@ include(TestForSTDNamespace)
include(TestForANSIStreamHeaders)
if (DLIB_USE_BLAS AND blas_found)
add_global_define(DLIB_USE_BLAS)
else()
remove_global_define(DLIB_USE_BLAS)
endif()
if (DLIB_ISO_CPP_ONLY)
add_global_define(DLIB_ISO_CPP_ONLY)
else()
......
#
# This is a CMake makefile. You can find the cmake utility and
# information about it at http://www.cmake.org
#
#
# This cmake file tries to find an installed BLAS library. It looks
# for an installed copy of the Intel MKL library first and then
# attempts to find some other BLAS library.
#
# blas_found - True if BLAS is available
# blas_libraries - link against these to use BLAS library
# setting this makes CMake allow normal looking if else statements
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
SET(blas_found 0)
if (UNIX)
message(STATUS "Searching for a BLAS library")
set( mkl_search_path
/opt/intel/mkl/*/lib/32
)
include(CheckLibraryExists)
# Search for the needed libraries from the MKL
find_library(mkl_mkl mkl ${mkl_search_path})
find_library(mkl_core mkl_core ${mkl_search_path})
find_library(mkl_guide guide ${mkl_search_path})
#MKL also needs pthreads so search for that as well
find_library(mkl_pthread pthread ${mkl_search_path})
mark_as_advanced( mkl_mkl mkl_core mkl_guide mkl_pthread)
# if we found the MKL
if (mkl_mkl AND mkl_core AND mkl_guide AND mkl_pthread)
set(blas_libraries ${mkl_mkl} ${mkl_core} ${mkl_guide} ${mkl_pthread})
set(blas_found 1)
message(STATUS "Found Intel MKL BLAS library")
endif()
# try to find some other BLAS libraries if we didn't find the MKL
if (NOT blas_found)
find_library(generic_cblas cblas)
if (generic_cblas)
set(blas_libraries ${generic_cblas})
set(blas_found 1)
message(STATUS "Found CBLAS library")
endif()
mark_as_advanced( generic_cblas)
endif()
if (NOT blas_found)
find_library(atlas_lib atlas)
if (atlas_lib)
set(blas_libraries ${atlas_lib})
set(blas_found 1)
message(STATUS "Found ATLAS BLAS library")
endif()
mark_as_advanced( atlas_lib)
endif()
if (NOT blas_found)
find_library(generic_blas blas)
if (generic_blas)
set(blas_libraries ${generic_blas})
set(blas_found 1)
message(STATUS "Found BLAS library")
endif()
mark_as_advanced( generic_blas)
endif()
if (NOT blas_found)
message(STATUS "***** No BLAS library found *****")
endif()
endif()
......@@ -5,7 +5,7 @@
#include "matrix_assign.h"
#ifdef DLIB_FOUND_BLAS
#ifdef DLIB_USE_BLAS
#include "cblas.h"
#endif
......@@ -16,7 +16,7 @@ namespace dlib
namespace blas_bindings
{
#ifdef DLIB_FOUND_BLAS
#ifdef DLIB_USE_BLAS
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
......@@ -356,7 +356,7 @@ namespace dlib
} DLIB_END_BLAS_BINDING
#endif // DLIB_FOUND_BLAS
#endif // DLIB_USE_BLAS
}
......
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