find_package(OpenMP)
if (OPENMP_FOUND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
else ()
    # icpc
    if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
        message(icpc)
        set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -qopenmp")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -qopenmp")
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
        message(g++)
        set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
    endif ()
endif ()

find_package(TBB)
if (TBB_FOUND)
    add_compile_options(-DTBB=1)
    message("${TBB_VERSION}, ${TBB_INCLUDE_DIRS}, ${TBB_LIBRARIES}")
    include_directories(${TBB_INCLUDE_DIRS})
    link_libraries(${TBB_LIBRARIES})
else ()
    message("TBB NOT FOUND")
endif ()

if (ENABLE_HBW)
    find_package(Memkind)
    if (MEMKIND_FOUND)
        add_compile_options(-DMEM_KIND=1)
        link_libraries(${MEMKIND_LIBRARIES})
    endif ()
endif ()

find_package(Tcmalloc REQUIRED)
if (Tcmalloc_FOUND)
    message("TCMALLOC FOUND")
    link_libraries(${Tcmalloc_LIBRARY})
else ()
    message("NO TCMALLOC ")
endif ()
