This commit is contained in:
Davis King 2016-02-02 20:35:37 -05:00
commit 032e5e3f4b
4 changed files with 60 additions and 34 deletions

View File

@ -49,44 +49,46 @@ if (UNIX)
include(CheckLibraryExists)
# Don't try to use the Intel MKL when we are building a MATLAB mex file
# since it will usually conflict with MATLAB's copy of the MKL and cause
# problems.
if (NOT BUILDING_MATLAB_MEX_FILE)
# Search for the needed libraries from the MKL. We will try to link against the mkl_rt
# file first since this way avoids linking bugs in some cases.
find_library(mkl_rt mkl_rt ${mkl_search_path})
mark_as_advanced( mkl_rt )
# if we found the MKL
if ( mkl_rt)
set(blas_libraries ${mkl_rt} )
set(lapack_libraries ${mkl_rt} )
# Search for the needed libraries from the MKL. We will try to link against the mkl_rt
# file first since this way avoids linking bugs in some cases.
find_library(mkl_rt mkl_rt ${mkl_search_path})
mark_as_advanced( mkl_rt )
# if we found the MKL
if ( mkl_rt)
set(blas_libraries ${mkl_rt} )
set(lapack_libraries ${mkl_rt} )
set(blas_found 1)
set(lapack_found 1)
set(found_intel_mkl 1)
message(STATUS "Found Intel MKL BLAS/LAPACK library")
if (BUILDING_MATLAB_MEX_FILE)
message(STATUS "\n!!!! Don't forget to set the BLAS_VERSION and LAPACK_VERSION environment variables to !!!!\n!!!! ${blas_libraries} so MATLAB doesn't explode when you run this mex file !!!!\n")
endif()
endif()
if (BUILDING_MATLAB_MEX_FILE)
return()
endif()
if (NOT found_intel_mkl)
# Search for the needed libraries from the MKL. This time try looking for a different
# set of MKL files and try to link against those.
find_library(mkl_core mkl_core ${mkl_search_path})
find_library(mkl_thread mkl_intel_thread ${mkl_search_path})
find_library(mkl_iomp iomp5 ${mkl_search_path})
find_library(mkl_pthread pthread ${mkl_search_path})
mark_as_advanced( mkl_intel mkl_core mkl_thread mkl_iomp mkl_pthread)
# If we found the MKL
if (mkl_intel AND mkl_core AND mkl_thread AND mkl_iomp AND mkl_pthread)
set(blas_libraries ${mkl_intel} ${mkl_core} ${mkl_thread} ${mkl_iomp} ${mkl_pthread})
set(lapack_libraries ${mkl_intel} ${mkl_core} ${mkl_thread} ${mkl_iomp} ${mkl_pthread})
set(blas_found 1)
set(lapack_found 1)
set(found_intel_mkl 1)
message(STATUS "Found Intel MKL BLAS/LAPACK library")
endif()
if (NOT found_intel_mkl)
# Search for the needed libraries from the MKL. This time try looking for a different
# set of MKL files and try to link against those.
find_library(mkl_core mkl_core ${mkl_search_path})
find_library(mkl_thread mkl_intel_thread ${mkl_search_path})
find_library(mkl_iomp iomp5 ${mkl_search_path})
find_library(mkl_pthread pthread ${mkl_search_path})
mark_as_advanced( mkl_intel mkl_core mkl_thread mkl_iomp mkl_pthread)
# If we found the MKL
if (mkl_intel AND mkl_core AND mkl_thread AND mkl_iomp AND mkl_pthread)
set(blas_libraries ${mkl_intel} ${mkl_core} ${mkl_thread} ${mkl_iomp} ${mkl_pthread})
set(lapack_libraries ${mkl_intel} ${mkl_core} ${mkl_thread} ${mkl_iomp} ${mkl_pthread})
set(blas_found 1)
set(lapack_found 1)
set(found_intel_mkl 1)
message(STATUS "Found Intel MKL BLAS/LAPACK library")
endif()
endif()
endif()
endif()
# try to find some other LAPACK libraries if we didn't find the MKL

View File

@ -8,6 +8,14 @@
// ----------------------------------------------------------------------------------------
void check_for_ctrl_c();
/*!
ensures
- If the user of MATLAB has pressed ctrl+c then this function will throw an
exception.
!*/
// ----------------------------------------------------------------------------------------
class matlab_struct
{

View File

@ -6,6 +6,7 @@
cmake_minimum_required(VERSION 2.8.4)
set(BUILDING_MATLAB_MEX_FILE true)
set(CMAKE_POSITION_INDEPENDENT_CODE True)
# Find MATLAB's include directory and needed libraries
find_program(MATLAB_EXECUTABLE matlab PATHS
@ -67,6 +68,7 @@ INCLUDE(InstallRequiredSystemLibraries)
MACRO(add_mex_function name )
ADD_LIBRARY(${name} MODULE ${name}.cpp )
# Change the output file extension to a mex extension.
if (WIN32)
set_target_properties(${name} PROPERTIES SUFFIX ".mexw64")

View File

@ -253,6 +253,8 @@ namespace mex_binding
// -------------------------------------------------------
struct user_hit_ctrl_c {};
struct invalid_args_exception
{
invalid_args_exception(const std::string& msg_): msg(msg_) {}
@ -897,7 +899,7 @@ namespace mex_binding
}
else if (is_same_type<dlib::rgb_pixel, type>::value)
{
mwSize dims[3] = {(unsigned long)item.nr(), (unsigned long)item.nc(), 3};
mwSize dims[3] = {(mwSize)item.nr(), (mwSize)item.nc(), 3};
plhs = mxCreateNumericArray(3, dims, mxUINT8_CLASS, mxREAL);
assign_image_to_matlab((dlib::uint8*)mxGetData(plhs), item);
@ -1573,6 +1575,10 @@ namespace mex_binding
mexErrMsgIdAndTxt("mex_function:validate_and_populate_arg",
("Input" + e.msg).c_str());
}
catch (user_hit_ctrl_c& )
{
// do nothing, just return to matlab
}
catch (dlib::error& e)
{
mexErrMsgIdAndTxt("mex_function:error",
@ -2371,6 +2377,14 @@ void call_matlab (
call_matlab("feval", funct);
}
extern "C" bool utIsInterruptPending();
void check_for_ctrl_c(
)
{
if (utIsInterruptPending())
throw mex_binding::user_hit_ctrl_c();
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------