# Copyright Advanced Micro Devices, Inc.
# SPDX-License-Identifier: MIT

# Core sysdeps: This artifact includes libraries that are widely used and are
# typically available on base systems. All of these should be small, fast to
# build, and high fanout to the codebase at large.
# Alpha order unless dependency order needed.
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../common/bzip2" "${CMAKE_CURRENT_BINARY_DIR}/bzip2")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../common/libbacktrace" "${CMAKE_CURRENT_BINARY_DIR}/libbacktrace")
add_subdirectory(libcap)
add_subdirectory(libdrm)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../common/liblzma" "${CMAKE_CURRENT_BINARY_DIR}/liblzma")
add_subdirectory(libmnl)
add_subdirectory(libnl)
add_subdirectory(numactl)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../common/sqlite3" "${CMAKE_CURRENT_BINARY_DIR}/sqlite3")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../common/zlib" "${CMAKE_CURRENT_BINARY_DIR}/zlib")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../common/zstd" "${CMAKE_CURRENT_BINARY_DIR}/zstd")

# Core system deps that depend on the above.
add_subdirectory(elfutils)

therock_provide_artifact(sysdeps
  TARGET_NEUTRAL
  DESCRIPTOR artifact.toml
  COMPONENTS
    dev
    doc
    lib
    run
  SUBPROJECT_DEPS
    therock-bzip2
    therock-elfutils
    therock-libbacktrace
    therock-libcap
    therock-libdrm
    therock-liblzma
    therock-libmnl
    therock-libnl
    therock-numactl
    therock-sqlite3
    therock-zlib
    therock-zstd
)

# Optional sysdep: amd-mesa
if(THEROCK_ENABLE_SYSDEPS_AMD_MESA)
  add_subdirectory(amd-mesa)
  therock_provide_artifact(sysdeps-amd-mesa
    TARGET_NEUTRAL
    DESCRIPTOR artifact-amd-mesa.toml
    COMPONENTS
      dev
      lib
    SUBPROJECT_DEPS
      therock-amd-mesa
  )
endif()

# Optional sysdep: expat
if(THEROCK_ENABLE_SYSDEPS_EXPAT)
  add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../common/expat" "${CMAKE_CURRENT_BINARY_DIR}/expat")
  therock_provide_artifact(sysdeps-expat
    TARGET_NEUTRAL
    DESCRIPTOR artifact-expat.toml
    COMPONENTS
      dev
      doc
      lib
    SUBPROJECT_DEPS
      therock-expat
  )
endif()

# Optional sysdep: gmp
if(THEROCK_ENABLE_SYSDEPS_GMP)
  add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../common/gmp" "${CMAKE_CURRENT_BINARY_DIR}/gmp")
  therock_provide_artifact(sysdeps-gmp
    TARGET_NEUTRAL
    DESCRIPTOR artifact-gmp.toml
    COMPONENTS
      dev
      doc
      lib
    SUBPROJECT_DEPS
      therock-gmp
  )
endif()

# Optional sysdep: mpfr (depends on gmp)
if(THEROCK_ENABLE_SYSDEPS_MPFR)
  add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../common/mpfr" "${CMAKE_CURRENT_BINARY_DIR}/mpfr")
  therock_provide_artifact(sysdeps-mpfr
    TARGET_NEUTRAL
    DESCRIPTOR artifact-mpfr.toml
    COMPONENTS
      dev
      doc
      lib
    SUBPROJECT_DEPS
      therock-mpfr
  )
endif()

# Optional sysdep: ncurses
if(THEROCK_ENABLE_SYSDEPS_NCURSES)
  add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../common/ncurses" "${CMAKE_CURRENT_BINARY_DIR}/ncurses")
  therock_provide_artifact(sysdeps-ncurses
    TARGET_NEUTRAL
    DESCRIPTOR artifact-ncurses.toml
    COMPONENTS
      dev
      doc
      lib
    SUBPROJECT_DEPS
      therock-ncurses
  )
endif()

# Optional sysdep: libpciaccess (PCI device access)
if(THEROCK_ENABLE_SYSDEPS_LIBPCIACCESS)
  add_subdirectory(libpciaccess)
  therock_provide_artifact(sysdeps-libpciaccess
    TARGET_NEUTRAL
    DESCRIPTOR artifact-libpciaccess.toml
    COMPONENTS
      dev
      lib
    SUBPROJECT_DEPS
      therock-libpciaccess
  )
endif()

# Optional sysdep: hwloc (depends on numactl and libpciaccess)
if(THEROCK_ENABLE_SYSDEPS_HWLOC)
  add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../common/hwloc" "${CMAKE_CURRENT_BINARY_DIR}/hwloc")
  therock_provide_artifact(sysdeps-hwloc
    TARGET_NEUTRAL
    DESCRIPTOR artifact-hwloc.toml
    COMPONENTS
      dev
      doc
      lib
    SUBPROJECT_DEPS
      therock-hwloc
  )
endif()

# Optional sysdep: util-linux (for libmount, etc.)
if(THEROCK_ENABLE_SYSDEPS_UTIL_LINUX)
  add_subdirectory(util-linux)
  therock_provide_artifact(sysdeps-util-linux
    TARGET_NEUTRAL
    DESCRIPTOR artifact-util-linux.toml
    COMPONENTS
      dev
      lib
    SUBPROJECT_DEPS
      therock-util-linux
  )
endif()
