#if(NOT blas_cmake_included)
#    message(FATAL_ERROR "Please use blas.cmake, which will include cblas.cmake if required")
#endif()
#
# toolchain has been broken at some point -- FindBLAS/FindCBLAS no longer work
#
if(cblas_cmake_included)
    return()
endif()
set(cblas_cmake_included true)
include("cmake/options.cmake")
include("cmake/SDL.cmake")

if (DNNL_BLAS_VENDOR STREQUAL "NONE")
    return()
endif()

if(0)
    set(CBLAS_FIND_REQUIRED TRUE)
    #set(BLAS_FIND_QUIETLY FALSE)
    #set(BLAS_FIND_REQUIRED FALSE)
    #set(CBLAS_FIND_REQUIRED FALSE)
    #set(CBLAS_DIR ${VE_CBLAS_DIR})
    #set(CBLAS_INCDIR ${VE_CBLAS_INCLUDE_DIR})
    find_package(CBLAS)
else()
    # ve toolchain is not finding blas/cblas any more.  Hardwire as per toolchain.
    # (maybe issue with ...PREFIX_PATH toolchain/platform settings?) XXX
    set(CBLAS_DIR "${VE_CBLAS_DIR}")
    set(CBLAS_FOUND TRUE)
    set(CBLAS_LINKER_FLAGS "${VE_NLC_C_LDFLAGS}")
    set(CBLAS_LIBRARY_DIRS)
    set(CBLAS_LIBRARIES "${VE_NLC_LIBS}")
    set(CBLAS_INCLUDE_DIRS "${VE_CBLAS_INCLUDE_DIR}")
    set(CBLAS_INCLUDE_DIRS_DEP)
    set(CBLAS_LIBRARY_DIRS_DEP)
    set(CBLAS_LIBRARIES_DEP)
    set(CBLAS_HAS_ZGEMM3M)
endif()

if(CBLAS_FOUND)
    message(STATUS "BLAS_FOUND              ${BLAS_FOUND}")
    message(STATUS "BLAS_LINKER_FLAGS       ${BLAS_LINKER_FLAGS}")
    message(STATUS "BLAS_LIBRARIES          ${BLAS_LIBRARIES}")
    message(STATUS "BLAS95_FOUND            ${BLAS95_FOUND}")
    message(STATUS "BLAS95_LIBRARIES        ${BLAS95_LIBRARIES}")
    message(STATUS "CBLAS_FOUND             ${CBLAS_FOUND}")
    message(STATUS "CBLAS_INCLUDE_DIRS      ${CBLAS_INCLUDE_DIRS}")
    message(STATUS "CBLAS_LIBRARY_DIRS      ${CBLAS_LIBRARY_DIRS}")
    message(STATUS "CBLAS_LIBRARIES         ${CBLAS_LIBRARIES}")
    message(STATUS "CBLAS_INCLUDE_DIRS_DEP  ${CBLAS_INCLUDE_DIRS_DEP}")
    message(STATUS "CBLAS_LIBRARY_DIRS_DEP  ${CBLAS_LIBRARY_DIRS_DEP}")
    message(STATUS "CBLAS_LIBRARIES_DEP     ${CBLAS_LIBRARIES_DEP}")
    include_directories(${CBLAS_INCLUDE_DIRS})
    include_directories(${CBLAS_INCLUDE_DIRS_DEP})
    #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CBLAS_LINKER_FLAGS} ${CBLAS_LIBRARY_DIRS} ${CBLAS_LIBRARY_DIRS_DEP}")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CBLAS_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}")
    #list(APPEND EXTRA_SHARED_LIBS ${CBLAS_LINKER_FLAGS} ${CBLAS_LIBRARIES} ${CBLAS_LIBRARY_DIRS_DEP} ${CBLAS_LIBRARIES_DEP} ${BLAS_LIBRARIES})
    #set(EXTRA_SHARED_LIBS "${EXTRA_SHARED_LIBS} ${CBLAS_LINKER_FLAGS} ${CBLAS_LIBRARIES} ${CBLAS_LIBRARY_DIRS_DEP} ${CBLAS_LIBRARIES_DEP} ${BLAS_LIBRARIES}")
    #list(APPEND EXTRA_SHARED_LIBS ${CBLAS_LINKER_FLAGS} ${CBLAS_LIBRARIES} ${CBLAS_LIBRARY_DIRS_DEP} ${CBLAS_LIBRARIES_DEP} ${BLAS_LIBRARIES})
    string(STRIP "${EXTRA_SHARED_LIBS} ${CBLAS_LINKER_FLAGS} ${CBLAS_LIBRARIES} ${CBLAS_LIBRARY_DIRS_DEP} ${CBLAS_LIBRARIES_DEP} ${BLAS_LIBRARIES}" EXTRA_SHARED_LIBS)
    
    message(STATUS "cblas.cmake CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}")
    message(STATUS "cblas.cmake EXTRA_SHARED_LIBS      = ${EXTRA_SHARED_LIBS}")
    add_definitions(-DUSE_CBLAS)
endif()
# vim: sw=4 ts=4 et
