CMake: include Linux tunnelmanager + pthread on Linux builds

This commit is contained in:
Zac Gaetano 2026-05-07 00:14:42 -04:00
parent 7819b5fbf2
commit 27958f3514

View file

@ -13,7 +13,7 @@
# macOS/Linux : deps/boringtun/libboringtun.a # macOS/Linux : deps/boringtun/libboringtun.a
# Windows : deps/boringtun/boringtun.lib # Windows : deps/boringtun/boringtun.lib
# boringtun static library # boringtun static library
if(WIN32) if(WIN32)
set(BORINGTUN_LIB "${CMAKE_SOURCE_DIR}/deps/boringtun/boringtun.lib") set(BORINGTUN_LIB "${CMAKE_SOURCE_DIR}/deps/boringtun/boringtun.lib")
@ -27,11 +27,16 @@ if(NOT EXISTS "${BORINGTUN_LIB}")
"boringtun static library not found at ${BORINGTUN_LIB}\n" "boringtun static library not found at ${BORINGTUN_LIB}\n"
"Run: pwsh scripts/build-boringtun-win.ps1\n" "Run: pwsh scripts/build-boringtun-win.ps1\n"
"then re-run CMake.") "then re-run CMake.")
else() elseif(APPLE)
message(FATAL_ERROR message(FATAL_ERROR
"boringtun static library not found at ${BORINGTUN_LIB}\n" "boringtun static library not found at ${BORINGTUN_LIB}\n"
"Run: bash scripts/build-boringtun.sh --universal\n" "Run: bash scripts/build-boringtun.sh --universal\n"
"then re-run CMake.") "then re-run CMake.")
else()
message(FATAL_ERROR
"boringtun static library not found at ${BORINGTUN_LIB}\n"
"Run: bash scripts/build-boringtun.sh\n"
"then re-run CMake.")
endif() endif()
endif() endif()
@ -40,12 +45,12 @@ set_target_properties(boringtun PROPERTIES
IMPORTED_LOCATION "${BORINGTUN_LIB}" IMPORTED_LOCATION "${BORINGTUN_LIB}"
) )
# VPN source files # VPN source files
set(VPN_SOURCES set(VPN_SOURCES
app/vpn/wireguardconfig.cpp app/vpn/wireguardconfig.cpp
app/vpn/relayclient.cpp app/vpn/relayclient.cpp
app/vpn/dragonrelaybackend.cpp # QObject bridge: RelayClient + TunnelManager QML app/vpn/dragonrelaybackend.cpp
) )
if(APPLE) if(APPLE)
@ -53,10 +58,10 @@ if(APPLE)
elseif(WIN32) elseif(WIN32)
list(APPEND VPN_SOURCES app/vpn/tunnelmanager_win.cpp) list(APPEND VPN_SOURCES app/vpn/tunnelmanager_win.cpp)
elseif(UNIX) elseif(UNIX)
list(APPEND VPN_SOURCES app/vpn/tunnelmanager_linux.cpp) # future list(APPEND VPN_SOURCES app/vpn/tunnelmanager_linux.cpp)
endif() endif()
# Integration into moonlight-qt target # Integration into moonlight-qt target.
# Replace moonlight-qt below with whatever your top-level CMakeLists calls the app target. # Replace moonlight-qt below with whatever your top-level CMakeLists calls the app target.
target_sources(moonlight-qt PRIVATE ${VPN_SOURCES}) target_sources(moonlight-qt PRIVATE ${VPN_SOURCES})
@ -68,24 +73,17 @@ target_include_directories(moonlight-qt PRIVATE
target_link_libraries(moonlight-qt PRIVATE boringtun) target_link_libraries(moonlight-qt PRIVATE boringtun)
if(APPLE) if(APPLE)
# Frameworks required by boringtun + tunnel implementation on macOS
target_link_libraries(moonlight-qt PRIVATE target_link_libraries(moonlight-qt PRIVATE
"-framework Security" "-framework Security"
"-framework Network" "-framework Network"
"-framework SystemConfiguration" "-framework SystemConfiguration"
) )
# Objective-C++ ARC needed for tunnelmanager_mac.mm
set_source_files_properties( set_source_files_properties(
app/vpn/tunnelmanager_mac.mm app/vpn/tunnelmanager_mac.mm
PROPERTIES COMPILE_FLAGS "-fobjc-arc" PROPERTIES COMPILE_FLAGS "-fobjc-arc"
) )
elseif(WIN32) elseif(WIN32)
# Windows system libraries required by Wintun + IP Helper API + Winsock
# iphlpapi CreateUnicastIpAddressEntry, CreateIpForwardEntry2
# ws2_32 socket, sendto, recvfrom, WSAEventSelect,
# ntdll required by boringtun's ring0 primitives
# ole32 CoCreateGuid (adapter GUID)
target_link_libraries(moonlight-qt PRIVATE target_link_libraries(moonlight-qt PRIVATE
iphlpapi iphlpapi
ws2_32 ws2_32
@ -93,15 +91,11 @@ elseif(WIN32)
ole32 ole32
) )
# Embed the UAC manifest so Windows prompts for elevation at launch.
# Visual Studio picks this up automatically; for Ninja/MSBuild add
# a custom command that runs mt.exe post-link.
if(MSVC) if(MSVC)
set_target_properties(moonlight-qt PROPERTIES set_target_properties(moonlight-qt PROPERTIES
LINK_FLAGS "/MANIFEST:EMBED /MANIFESTINPUT:${CMAKE_SOURCE_DIR}/app/DragonMoonlight.manifest" LINK_FLAGS "/MANIFEST:EMBED /MANIFESTINPUT:${CMAKE_SOURCE_DIR}/app/DragonMoonlight.manifest"
) )
else() else()
# MinGW: link the manifest as a resource
configure_file( configure_file(
"${CMAKE_SOURCE_DIR}/app/DragonMoonlight.manifest" "${CMAKE_SOURCE_DIR}/app/DragonMoonlight.manifest"
"${CMAKE_CURRENT_BINARY_DIR}/DragonMoonlight.manifest" "${CMAKE_CURRENT_BINARY_DIR}/DragonMoonlight.manifest"
@ -111,16 +105,16 @@ elseif(WIN32)
"${CMAKE_CURRENT_BINARY_DIR}/DragonMoonlight.manifest" "${CMAKE_CURRENT_BINARY_DIR}/DragonMoonlight.manifest"
) )
endif() endif()
elseif(UNIX)
target_link_libraries(moonlight-qt PRIVATE pthread)
endif() endif()
# Qt resources: logo images # Qt resources: logo images
# Assets referenced in QML as qrc:/app/assets/wilddragon-{icon,logo}.jpg
# Both qt5_add_resources and qt_add_resources accept a .qrc file path directly.
set(DRAGON_QRC_FILE "${CMAKE_SOURCE_DIR}/app/assets/dragonmoonlight.qrc") set(DRAGON_QRC_FILE "${CMAKE_SOURCE_DIR}/app/assets/dragonmoonlight.qrc")
if(NOT QT_VERSION_MAJOR) if(NOT QT_VERSION_MAJOR)
# Fallback if QT_VERSION_MAJOR isn't set yet derive from Qt5/Qt6 find_package result
if(Qt6_FOUND) if(Qt6_FOUND)
set(QT_VERSION_MAJOR 6) set(QT_VERSION_MAJOR 6)
else() else()