if (__flags_included)
  return ()
endif()

set(__basic_flags "-Wall -Wextra -Wshadow")
list(APPEND __basic_flags "-fopenmp")
list(APPEND __basic_flags "-Wno-sign-compare")
list(APPEND __basic_flags "-Wno-uninitialized")
list(APPEND __basic_flags "-Wno-unused-variable")
list(APPEND __basic_flags "-Wno-unused-parameter")
list(APPEND __basic_flags "-DEULER_VERSION=${EULER_VERSION}")

if (CMAKE_CXX_COMPILER MATCHES "icpx")
  # for aligned new
  set(__cxx_flags "-std=c++17")
else()
  set(__cxx_flags "-std=c++11")
endif()

if (__debug)
  set(__opt_flags "-O0 -g -DDEBUG")
elseif (__profiling)
  set(__opt_flags "-O2 -g -DNDEBUG")
else ()
  set(__opt_flags "-O2 -DNDEBUG")
endif ()

if (ENABLE_USER_FP16)
  list(APPEND __opt_flags "-DENABLE_USER_FP16")
endif()

if (WITH_GK)
  list(APPEND __opt_flags "-DWITH_GK")
endif()

if (WITH_VNNI)
  list(APPEND __opt_flags "-DWITH_VNNI")
endif()
if (WITH_DPBF16)
  list(APPEND __opt_flags "-DWITH_DPBF16")
endif()

if(MT_RUNTIME STREQUAL "omp")
  list(APPEND __opt_flags "-DMT_RUNTIME=MT_RUNTIME_OMP")
elseif(MT_RUNTIME STREQUAL "tbb")
  list(APPEND __opt_flags "-DMT_RUNTIME=MT_RUNTIME_TBB")
else()
  MESSAGE(FATAL_ERROR "MT_RUNTIME=" ${MT_RUNTIME} " is not supported. omp|tbb")
endif()

MESSAGE("-- MT_RUNTIME: " ${MT_RUNTIME})

if (CMAKE_CXX_COMPILER MATCHES "icpc")
  list(APPEND __opt_flags "-xHost")
  #  list(APPEND __opt_flags "-qopt-report=5")
  list(APPEND __opt_flags "-qopt-zmm-usage=high")
  list(APPEND __opt_flags "-no-inline-max-size")
  list(APPEND __opt_flags "-no-inline-max-total-size")
  list(APPEND __opt_flags "-wd15335") # disable remark #15335: was not vectorized
elseif(CMAKE_CXX_COMPILER MATCHES "icpx")
  list(APPEND __opt_flags "-xHost")
  list(APPEND __basic_flags "-Wno-pragmas")
  list(APPEND __basic_flags "-Wno-pass-failed")
  list(APPEND __basic_flags "-Wno-missing-braces")
  if (WITH_VNNI)
    list(APPEND __opt_flags "-mavx512vnni")
  endif()
  list(APPEND __opt_flags "-mavx512f")
  list(APPEND __opt_flags "-mavx512dq")
  list(APPEND __opt_flags "-mavx512bw")
  list(APPEND __opt_flags "-mfma -mavx512vl")
elseif(CMAKE_CXX_COMPILER MATCHES "clang")
  list(APPEND __opt_flags "-mavx512f")
  list(APPEND __opt_flags "-mavx512dq")
  list(APPEND __opt_flags "-mavx512bw")
  list(APPEND __opt_flags "-mfma -mavx512vl")
else()
  list(APPEND __basic_flags "-Wno-unused-result")
  list(APPEND __basic_flags "-Wno-unused-but-set-variable")
  list(APPEND __basic_flags "-Wno-misleading-indentation")
  list(APPEND __basic_flags "-Wno-unknown-pragmas")
  list(APPEND __basic_flags "-Wno-implicit-fallthrough")
  list(APPEND __opt_flags "-mavx512f")
  list(APPEND __opt_flags "-mavx512dq")
  list(APPEND __opt_flags "-mavx512bw")
  list(APPEND __opt_flags "-mfma -mavx512vl")
endif()

add_definitions(${__basic_flags} ${__cxx_flags} ${__opt_flags})
