add_subdirectory(common)
add_subdirectory(gpu-bridge-protocol)
add_subdirectory(steam-bridge-protocol)

include("${PROJECT_SOURCE_DIR}/cmake/steam-bridge.cmake")

add_subdirectory(steam-host-backend)
add_subdirectory(vulkan-bridge-marshal)
add_subdirectory(emulator-platform)
add_subdirectory(disassembler)
add_subdirectory(emulator)
add_subdirectory(gdb-stub)
add_subdirectory(windows-emulator)
add_subdirectory(windows-gdb-stub)
add_subdirectory(linux-emulator)
add_subdirectory(linux-gdb-stub)
add_subdirectory(backend-selection)

if(SOGEN_ENABLE_PYTHON_BINDINGS)
  add_subdirectory(python-bindings)
endif()

sogen_add_subdirectory_and_get_targets("backends" BACKEND_TARGETS)
sogen_targets_set_folder("backends" ${BACKEND_TARGETS})

set(_SOGEN_BUILD_STANDALONE_TARGETS ON)
if(SOGEN_BUILD_STATIC)
  # if static build, tools are opt in
  set(_SOGEN_BUILD_STANDALONE_TARGETS ${SOGEN_BUILD_TOOLS})
endif()

if(_SOGEN_BUILD_STANDALONE_TARGETS)
  add_subdirectory(windows-analyzer)
  add_subdirectory(linux-analyzer)
  add_subdirectory(analyzer)
  add_subdirectory(debugger)
  add_subdirectory(linux-debugger)
  add_subdirectory(fuzzing-engine)
  add_subdirectory(fuzzer)
  if(SOGEN_ENABLE_FUZZING)
    add_subdirectory(windows-emulator-fuzz)
  endif()
  add_subdirectory(windows-emulator-test)
  add_subdirectory(linux-emulator-test)

  if((WIN32 OR LINUX) AND CMAKE_SIZEOF_VOID_P EQUAL 8)
    sogen_add_subdirectory_and_get_targets("tools" TOOL_TARGETS)
    sogen_targets_set_folder("tools" ${TOOL_TARGETS})
  endif()

  if(WIN32)
    sogen_add_subdirectory_and_get_targets("samples" SAMPLE_TARGETS)
    sogen_targets_set_folder("samples" ${SAMPLE_TARGETS})
  endif()

  # The tools baked into the emulation root, grouped so CI builds one target. Each is included only when it
  # exists for the current arch/config (dump-apiset is 64-bit; steam-shim needs the Steam bridge enabled).
  if(WIN32)
    add_custom_target(emulation-root-tools)
    foreach(_root_tool vulkan-shim steam-shim dump-apiset)
      if(TARGET ${_root_tool})
        add_dependencies(emulation-root-tools ${_root_tool})
      endif()
    endforeach()
  endif()
endif()
