artemis/cmake/wg.cmake

77 lines
2.9 KiB
CMake

# cmake/wg.cmake — WireGuard client integration for Artemis (Sunshine fork).
#
# Include from the top-level CMakeLists.txt:
#
# include(cmake/wg.cmake)
# artemis_wg_configure(sunshine) # pass the name of your app target
#
# Prerequisites:
# Run scripts/build-boringtun.sh (Linux/macOS) or
# scripts/build-boringtun-win.ps1 (Windows)
# to produce deps/boringtun/libboringtun.a (or .lib on Windows).
# ─── boringtun static library ─────────────────────────────────────────────────
if(WIN32)
set(ARTEMIS_BORINGTUN_LIB "${CMAKE_SOURCE_DIR}/deps/boringtun/boringtun.lib")
else()
set(ARTEMIS_BORINGTUN_LIB "${CMAKE_SOURCE_DIR}/deps/boringtun/libboringtun.a")
endif()
if(NOT EXISTS "${ARTEMIS_BORINGTUN_LIB}")
message(FATAL_ERROR
"boringtun library not found at ${ARTEMIS_BORINGTUN_LIB}\n"
"Run the appropriate build script in scripts/ and re-run CMake.")
endif()
add_library(artemis_boringtun STATIC IMPORTED GLOBAL)
set_target_properties(artemis_boringtun PROPERTIES
IMPORTED_LOCATION "${ARTEMIS_BORINGTUN_LIB}"
)
# ─── WireGuard source files ───────────────────────────────────────────────────
set(ARTEMIS_WG_SOURCES
src/wg/wgconfig.cpp
src/wg/relayreg.cpp
)
if(WIN32)
list(APPEND ARTEMIS_WG_SOURCES src/wg/wgclient_win.cpp src/wg/displayinfo_win.cpp)
elseif(UNIX AND NOT APPLE)
list(APPEND ARTEMIS_WG_SOURCES src/wg/wgclient_linux.cpp src/wg/displayinfo_linux.cpp)
elseif(APPLE)
# macOS: future — use utun approach from DragonMoonlight if needed
message(WARNING "Artemis WireGuard client not yet implemented for macOS")
endif()
# ─── Configuration function ───────────────────────────────────────────────────
function(artemis_wg_configure TARGET)
target_sources(${TARGET} PRIVATE ${ARTEMIS_WG_SOURCES})
target_include_directories(${TARGET} PRIVATE
"${CMAKE_SOURCE_DIR}/src/wg"
"${CMAKE_SOURCE_DIR}/deps/boringtun" # boringtun_ffi.h
)
target_link_libraries(${TARGET} PRIVATE artemis_boringtun)
# libcurl (already a Sunshine dependency)
find_package(CURL REQUIRED)
target_link_libraries(${TARGET} PRIVATE CURL::libcurl)
if(WIN32)
target_link_libraries(${TARGET} PRIVATE
iphlpapi ws2_32 ntdll ole32
)
elseif(UNIX AND NOT APPLE)
# pthread for std::thread on Linux
target_link_libraries(${TARGET} PRIVATE pthread)
endif()
# Enable the WireGuard relay feature in Artemis source
target_compile_definitions(${TARGET} PRIVATE ARTEMIS_RELAY_ENABLED=1)
message(STATUS "Artemis: WireGuard relay client enabled for target '${TARGET}'")
endfunction()