##Copyright (C) 2020, Advanced Micro Devices, Inc.## 

cmake_minimum_required(VERSION 3.0.0)

project(AOCL-LibBlis-Win C)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
if (MSVC)
    set(TARGET_ARCH zen2)
    message(STATUS "Setting MSVC flags2")
	message(${TARGET_ARCH})
	option(BUILD_SHARED_LIBS "Build shared library" ON)
	option(ENABLE_MULTITHREADING "Enable Multi threading" OFF)

    include_directories(${PROJECT_SOURCE_DIR}/external/msvc)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
	add_definitions(-DBLIS_ENABLE_CBLAS)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MD ")
	#add_definitions(-DBLIS_IS_BUILDING_LIBRARY)
	if(NOT BUILD_SHARED_LIBS)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT ")
	add_definitions(-DBLIS_IS_BUILDING_LIBRARY)
	endif()

    if(ENABLE_MULTITHREADING)
    add_definitions(-DBLIS_ENABLE_OPENMP)
    endif()

    SET(ENABLE_SIMD_FLAGS "AVX2" CACHE STRING "Set compiler SIMD flags")
    SET_PROPERTY(CACHE ENABLE_SIMD_FLAGS PROPERTY STRINGS none SSE2 AVX AVX2) 

    if(${ENABLE_SIMD_FLAGS} MATCHES "AVX2")
        add_definitions(/arch:AVX2)
        message(STATUS "Enabling AVX2 instructions")
    elseif(${ENABLE_SIMD_FLAGS} MATCHES "AVX")
        add_definitions(/arch:AVX)
        message(STATUS "Enabling AVX instructions")
    elseif(${ENABLE_SIMD_FLAGS} MATCHES "SSE2")
        add_definitions(/arch:SSE2)
        message(STATUS "Enabling SSE2 instructions")
    endif()

    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0 ")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
	#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /openmp")
    set(INTR_GENERAL_LINK_FLAGS "${INTR_GENERAL_LINK_FLAGS} /RELEGE") 
    #add_definitions(-D_USRDLL)
    add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
    #add_definitions(-D_WIN32)
    #add_definitions(-D_BLIS)
    add_definitions(-DBLIS_OS_WINDOWS)
    add_definitions(-D_MSC_VER)
	add_definitions(-DBLIS_CNAME=${TARGET_ARCH})
endif(MSVC)

include_directories(${CMAKE_SOURCE_DIR}/aocl_dtl)
include_directories(${CMAKE_SOURCE_DIR}/.)
include_directories(${CMAKE_SOURCE_DIR}/windows/${TARGET_ARCH})
include_directories(${CMAKE_SOURCE_DIR}/frame/include)
include_directories(${CMAKE_SOURCE_DIR}/frame/include/level0)
include_directories(${CMAKE_SOURCE_DIR}/frame/include/level0/1e)
include_directories(${CMAKE_SOURCE_DIR}/frame/include/level0/1m)
include_directories(${CMAKE_SOURCE_DIR}/frame/include/level0/1r)
include_directories(${CMAKE_SOURCE_DIR}/frame/include/level0/bb)
include_directories(${CMAKE_SOURCE_DIR}/frame/include/level0/io)
include_directories(${CMAKE_SOURCE_DIR}/frame/include/level0/ri)
include_directories(${CMAKE_SOURCE_DIR}/frame/include/level0/ri3)
include_directories(${CMAKE_SOURCE_DIR}/frame/include/level0/rih)
include_directories(${CMAKE_SOURCE_DIR}/frame/include/level0/ro)
include_directories(${CMAKE_SOURCE_DIR}/frame/include/level0/rpi)
include_directories(${CMAKE_SOURCE_DIR}/frame/thread)
include_directories(${CMAKE_SOURCE_DIR}/frame/base)
include_directories(${CMAKE_SOURCE_DIR}/frame/base/cast)
include_directories(${CMAKE_SOURCE_DIR}/frame/base/check)
include_directories(${CMAKE_SOURCE_DIR}/frame/base/noopt)
include_directories(${CMAKE_SOURCE_DIR}/frame/base/proj)
include_directories(${CMAKE_SOURCE_DIR}/frame/0)
include_directories(${CMAKE_SOURCE_DIR}/frame/0/copysc)
include_directories(${CMAKE_SOURCE_DIR}/frame/1)
include_directories(${CMAKE_SOURCE_DIR}/frame/1d)
include_directories(${CMAKE_SOURCE_DIR}/frame/1f)
include_directories(${CMAKE_SOURCE_DIR}/frame/1m)
include_directories(${CMAKE_SOURCE_DIR}/frame/1m/packm)
include_directories(${CMAKE_SOURCE_DIR}/frame/1m/unpackm)
include_directories(${CMAKE_SOURCE_DIR}/frame/2)
include_directories(${CMAKE_SOURCE_DIR}/frame/2/gemv)
include_directories(${CMAKE_SOURCE_DIR}/frame/2/ger)
include_directories(${CMAKE_SOURCE_DIR}/frame/2/hemv)
include_directories(${CMAKE_SOURCE_DIR}/frame/2/her)
include_directories(${CMAKE_SOURCE_DIR}/frame/2/her2)
include_directories(${CMAKE_SOURCE_DIR}/frame/2/symv)
include_directories(${CMAKE_SOURCE_DIR}/frame/2/syr)
include_directories(${CMAKE_SOURCE_DIR}/frame/2/syr2)
include_directories(${CMAKE_SOURCE_DIR}/frame/2/trmv)
include_directories(${CMAKE_SOURCE_DIR}/frame/2/trsv)
include_directories(${CMAKE_SOURCE_DIR}/frame/3)
include_directories(${CMAKE_SOURCE_DIR}/frame/3/gemm)
include_directories(${CMAKE_SOURCE_DIR}/frame/3/gemm/ind)
include_directories(${CMAKE_SOURCE_DIR}/frame/3/hemm)
include_directories(${CMAKE_SOURCE_DIR}/frame/3/her2k)
include_directories(${CMAKE_SOURCE_DIR}/frame/3/herk)
include_directories(${CMAKE_SOURCE_DIR}/frame/3/symm)
include_directories(${CMAKE_SOURCE_DIR}/frame/3/syr2k)
include_directories(${CMAKE_SOURCE_DIR}/frame/3/syrk)
include_directories(${CMAKE_SOURCE_DIR}/frame/3/trmm)
include_directories(${CMAKE_SOURCE_DIR}/frame/3/trmm3)
include_directories(${CMAKE_SOURCE_DIR}/frame/3/trsm)
include_directories(${CMAKE_SOURCE_DIR}/frame/compat)
include_directories(${CMAKE_SOURCE_DIR}/frame/compat/blis/thread)
include_directories(${CMAKE_SOURCE_DIR}/frame/compat/cblas)
include_directories(${CMAKE_SOURCE_DIR}/frame/compat/cblas/f77_sub)
include_directories(${CMAKE_SOURCE_DIR}/frame/compat/cblas/src)
include_directories(${CMAKE_SOURCE_DIR}/frame/compat/check)
include_directories(${CMAKE_SOURCE_DIR}/frame/compat/f2c)
include_directories(${CMAKE_SOURCE_DIR}/frame/compat/f2c/util)
include_directories(${CMAKE_SOURCE_DIR}/frame/ind)
include_directories(${CMAKE_SOURCE_DIR}/frame/ind/cntx)
include_directories(${CMAKE_SOURCE_DIR}/frame/ind/oapi)
include_directories(${CMAKE_SOURCE_DIR}/frame/ind/tapi)
include_directories(${CMAKE_SOURCE_DIR}/frame/ind/ukernels)
include_directories(${CMAKE_SOURCE_DIR}/frame/util)
include_directories(${CMAKE_SOURCE_DIR}/config/zen)
include_directories(${CMAKE_SOURCE_DIR}/config/zen2)
include_directories(${CMAKE_SOURCE_DIR}/ref_kernels)
include_directories(${CMAKE_SOURCE_DIR}/kernels)
include_directories(${CMAKE_SOURCE_DIR}/kernels/haswell)
include_directories(${CMAKE_SOURCE_DIR}/kernels/haswell/3)
include_directories(${CMAKE_SOURCE_DIR}/kernels/haswell/3/sup)
include_directories(${CMAKE_SOURCE_DIR}/kernels/zen)
include_directories(${CMAKE_SOURCE_DIR}/kernels/zen/1)
include_directories(${CMAKE_SOURCE_DIR}/kernels/zen/1f)
include_directories(${CMAKE_SOURCE_DIR}/kernels/zen/1m)
include_directories(${CMAKE_SOURCE_DIR}/kernels/zen/3)
include_directories(${CMAKE_SOURCE_DIR}/kernels/zen/3/sup)
include_directories(${CMAKE_SOURCE_DIR}/kernels/zen2)
include_directories(${CMAKE_SOURCE_DIR}/kernels/zen2/1f)
include_directories(${CMAKE_SOURCE_DIR}/kernels/zen2/2)

file(GLOB headers ${CMAKE_SOURCE_DIR}/*.h)

if(BUILD_SHARED_LIBS)
    add_library("${PROJECT_NAME}" SHARED ${CMAKE_SOURCE_DIR}/windows/${TARGET_ARCH}/bli_config.h 
                         ${CMAKE_SOURCE_DIR}/windows/${TARGET_ARCH}/blis.h
     					 ${headers})
	target_compile_definitions("${PROJECT_NAME}" PUBLIC -DBLIS_IS_BUILDING_LIBRARY)
	set_target_properties("${PROJECT_NAME}" PROPERTIES LINKER_LANGUAGE C)
endif()
if(NOT BUILD_SHARED_LIBS)
    add_library("${PROJECT_NAME}" STATIC ${CMAKE_SOURCE_DIR}/windows/${TARGET_ARCH}/bli_config.h 
                         ${CMAKE_SOURCE_DIR}/windows/${TARGET_ARCH}/blis.h
     					 ${headers})
	set_target_properties("${PROJECT_NAME}" PROPERTIES LINKER_LANGUAGE C)
endif()


link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
add_definitions(-DEXPMODULE)

add_subdirectory(config)
add_subdirectory(ref_kernels)
add_subdirectory(kernels)
add_subdirectory(frame)
add_subdirectory(aocl_dtl)
add_subdirectory(test)
add_subdirectory(testsuite)