add_library(uc_common STATIC dol.cpp dol_scan.cpp ppc/isa.cpp analyzer/config.cpp analyzer/analyzer.cpp translator/emit.cpp sig/dsy.cpp ppc/format.cpp)
target_include_directories(uc_common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_library(uc_ui_mode STATIC ui_mode.cpp)   # which view starts: desktop (as on Windows) or deck (Game Mode), see docs/superpowers/specs/2026-11-02-linux-desktop-ui-design.md
target_include_directories(uc_ui_mode PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_library(uc_input STATIC input_bindings.cpp)
add_library(uc_netplay STATIC netplay.cpp netplay_stream.cpp netplay_datagram.cpp)
target_include_directories(uc_netplay PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
if(WIN32)
  target_link_libraries(uc_netplay PUBLIC ws2_32)
endif()
add_library(uc_cpu_topology STATIC $<IF:$<BOOL:${WIN32}>,cpu_topology_win.cpp,cpu_topology_posix.cpp>)
add_library(uc_diagnostics STATIC $<IF:$<BOOL:${WIN32}>,diagnostic_log_win.cpp,diagnostic_log_posix.cpp>)
add_library(uc_path_io STATIC path_io.cpp)   # fopen_path, exe_path, user_data_dir, open_folder
target_include_directories(uc_path_io PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
if(UNIX)
  target_link_libraries(uc_path_io PUBLIC ${CMAKE_DL_LIBS})
endif()
if(WIN32)   # Windows-only: the launcher/updater handshake and Windows command-line quoting
  add_library(uc_client_update_lock STATIC client_update_lock.cpp)
  add_library(uc_windows_args STATIC windows_args.cpp)
  target_include_directories(uc_windows_args PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
  target_include_directories(uc_client_update_lock PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
  target_compile_definitions(uc_client_update_lock PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
endif()
target_include_directories(uc_diagnostics PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(uc_cpu_topology PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(uc_input PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_library(uc_gamepad_math STATIC gamepad_math.cpp)
target_include_directories(uc_gamepad_math PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_library(uc_wiimote_protocol STATIC wiimote_protocol.cpp)   # the Wii Remote's HID reports as pure bytes
target_include_directories(uc_wiimote_protocol PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_library(uc_evdev_logic STATIC evdev_logic.cpp)   # Linux input devices as pure logic: what they are, what their events mean (the fd layer is game/evdev_backend.cpp)
target_include_directories(uc_evdev_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(uc_evdev_logic PUBLIC uc_wiimote_protocol)
add_library(uc_wiimote_math STATIC wiimote_math.cpp)   # the IR pointer, the nunchuk stick and the swing detector
target_link_libraries(uc_wiimote_math PUBLIC uc_wiimote_protocol)
add_library(uc_input_prompts STATIC input_prompts.cpp)
target_include_directories(uc_input_prompts PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(uc_input_prompts PUBLIC uc_input uc_gamepad_config)
add_library(uc_public_release INTERFACE)   # public_release.h: a release client writes no logs or debug files
target_include_directories(uc_public_release INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
include(FetchContent)
set(JSON_BuildTests OFF CACHE BOOL "" FORCE)
set(json_archive "https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz")
if(EXISTS "${CMAKE_SOURCE_DIR}/build/deps/json-3.12.0.tar.xz")
  set(json_archive "${CMAKE_SOURCE_DIR}/build/deps/json-3.12.0.tar.xz")
endif()
FetchContent_Declare(nlohmann_json URL "${json_archive}"
  URL_HASH SHA256=42f6e95cad6ec532fd372391373363b62a14af6d771056dbfc86160e6dfff7aa
  DOWNLOAD_EXTRACT_TIMESTAMP FALSE)
FetchContent_MakeAvailable(nlohmann_json)
add_library(uc_input_config STATIC input_config.cpp)
target_include_directories(uc_input_config PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(uc_input_config PUBLIC uc_input nlohmann_json::nlohmann_json)
add_library(uc_gamepad_config STATIC gamepad_config.cpp)   # the gamepad object of config.json
target_include_directories(uc_gamepad_config PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(uc_gamepad_config PUBLIC uc_input_config uc_gamepad_math)
add_library(uc_coop_roster STATIC coop_roster.cpp)   # who plays: the second player joins by pressing a button on a new device
target_include_directories(uc_coop_roster PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_library(uc_coop_config STATIC coop_config.cpp)   # the player2 object of config.json
target_include_directories(uc_coop_config PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(uc_coop_config PUBLIC uc_gamepad_config)
add_library(uc_wiimote_config STATIC wiimote_config.cpp)   # the wiimote object of config.json
target_include_directories(uc_wiimote_config PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(uc_wiimote_config PUBLIC uc_input_config)
install(FILES ${nlohmann_json_SOURCE_DIR}/LICENSE.MIT DESTINATION licenses/nlohmann_json)
