################################################################################
# Autogenerated by build_tools/bazel_to_cmake/bazel_to_cmake.py from           #
# runtime/src/iree/task/BUILD.bazel                                            #
#                                                                              #
# Use iree_cmake_extra_content from iree/build_defs.oss.bzl to add arbitrary   #
# CMake-only content.                                                          #
#                                                                              #
# To disable autogeneration for this file entirely, delete this header.        #
################################################################################

# Task-based executor requires threading support.
if(NOT IREE_ENABLE_THREADING)
  return()
endif()

iree_add_all_subdirs()

# cpuinfo can be conditionally disabled when it is not supported.
# If disabled then by default the task system will use 1 thread.
set(IREE_CPUINFO_TARGET)
if(IREE_ENABLE_CPUINFO)
  set(IREE_CPUINFO_TARGET cpuinfo)
endif()

iree_cc_library(
  NAME
    api
  HDRS
    "api.h"
  SRCS
    "api.c"
  DEPS
    ::task
    iree::base
    iree::base::internal
    iree::base::tooling::flags
  PUBLIC
)

iree_cc_library(
  NAME
    task
  HDRS
    "affinity_set.h"
    "executor.h"
    "process.h"
    "scope.h"
    "topology.h"
    "tuning.h"
  SRCS
    "executor.c"
    "executor_impl.h"
    "process.c"
    "scope.c"
    "topology.c"
    "topology_cpuinfo.c"
    "topology_darwin.c"
    "topology_fallback.c"
    "topology_sysfs.c"
    "topology_wasm.c"
    "topology_win32.c"
    "worker.c"
    "worker.h"
  DEPS
    iree::base
    iree::base::internal
    iree::base::internal::atomic_slist
    iree::base::internal::cpu
    iree::base::internal::fpu_state
    iree::base::internal::prng
    iree::base::internal::sysfs
    iree::base::threading
    iree::base::threading::thread
  PUBLIC
)

iree_cc_test(
  NAME
    process_test
  SRCS
    "process_test.cc"
  DEPS
    ::task
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
)

iree_cc_test(
  NAME
    executor_test
  SRCS
    "executor_test.cc"
  DEPS
    ::task
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
)

iree_cc_test(
  NAME
    topology_test
  SRCS
    "topology_test.cc"
  DEPS
    ::task
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
)

iree_cc_binary_benchmark(
  NAME
    executor_benchmark
  SRCS
    "executor_benchmark.cc"
  DEPS
    ::task
    benchmark
    iree::base
    iree::testing::benchmark_main
  TESTONLY
)

### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###

# Topology implementation selection.
# All topology sources are compiled unconditionally (required for Bazel).
# Files self-select based on platform guards and IREE_HAVE_CPUINFO.
#
# Priority (first match wins):
# 1. cpuinfo (if IREE_ENABLE_CPUINFO=ON)
# 2. sysfs (Linux/Android, excluding Emscripten/Wasm)
# 3. Platform-specific (Darwin, Windows, Wasm)
# 4. Fallback (single-threaded conservative topology)

if(IREE_ENABLE_CPUINFO)
  target_compile_definitions(iree_task_task PRIVATE IREE_TASK_USE_CPUINFO=1)
  message(STATUS "IREE task topology: using cpuinfo")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT EMSCRIPTEN AND NOT IREE_ARCH STREQUAL "wasm_32")
  message(STATUS "IREE task topology: using sysfs (Linux)")
elseif(APPLE)
  message(STATUS "IREE task topology: using platform-specific (Darwin)")
elseif(WIN32)
  message(STATUS "IREE task topology: using platform-specific (Windows)")
elseif(EMSCRIPTEN OR IREE_ARCH STREQUAL "wasm_32")
  message(STATUS "IREE task topology: using platform-specific (Wasm)")
else()
  message(STATUS "IREE task topology: using fallback (single-threaded)")
endif()
