macOS shares the Linux transport: TlsChannel.h now dispatches __APPLE__ to the OpenSSL implementation, so handshake, pinned trust anchor, reload and removal all come from client/TlsChannelLinux.cpp. Only the platform glue is new: ConfigDir() follows initConfigPaths (HOME, then getpwuid(), then /tmp; no XDG) so the anchor sits next to config.conf, and ExeDir() uses _NSGetExecutablePath. First connect stays plaintext. The operator turns TLS on from the online list: COMMAND_TLS_ENABLE carries the anchor PEM, COMMAND_TLS_DISABLE removes it. macos/main.mm saves the anchor, calls TlsReload() and only reconnects when the transport actually changed, so re-saving the same anchor does not drop a live session. RES_TLS is filled from TlsEnabled() and refreshed on every reconnect; fillLoginInfo clears szReserved first now, because AddReserved appends and it runs twice on a group change. CMake builds arm64 only (deployment target 11.0) and links Homebrew openssl@3 statically when libcrypto.a is present, so the binary carries no Homebrew path dependency. Not built or run on a Mac yet: the Apple branch was syntax-checked under WSL and the login refresh probe-tested; macos/README.txt has the build and verify steps. Co-Authored-By: deepseek-flash
129 lines
5.0 KiB
CMake
129 lines
5.0 KiB
CMake
cmake_minimum_required(VERSION 3.15)
|
||
project(ghost_macos)
|
||
|
||
set(CMAKE_CXX_STANDARD 17)
|
||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||
|
||
# macOS deployment target。arm64 的底线就是 11.0(Apple Silicon 首发系统),
|
||
# 与 Homebrew openssl@3 自身的最低版本一致,避免链接时出现 "built for newer" 告警。
|
||
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimum macOS version")
|
||
|
||
# 只构建 Apple Silicon。仓库里发布过的 macos/ghost 一直是 arm64-only(universal 设置从未
|
||
# 真正落地),且 Homebrew 的 OpenSSL 是单架构——保留 x86_64 slice 会让链接直接失败。
|
||
# 将来真要支持 Intel Mac,应单独用 x86_64 的 OpenSSL 构建一份,而不是把这里改回 universal。
|
||
# 注意 CMAKE_OSX_ARCHITECTURES 是 cache 变量:旧 build 目录里存的值不会因这里改字面量而
|
||
# 更新,build.sh 因此显式传 -DCMAKE_OSX_ARCHITECTURES=arm64。
|
||
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Build architectures (arm64 only)")
|
||
|
||
include_directories(../)
|
||
include_directories(../client)
|
||
include_directories(../compress)
|
||
|
||
# Source files
|
||
set(SOURCES
|
||
main.mm
|
||
../client/Buffer.cpp
|
||
../client/IOCPClient.cpp
|
||
# TLS 传输(OpenSSL 实现,与 Linux/Android 共用)。文件名叫 Linux 是历史原因,
|
||
# 平台守卫为 __linux__ || __APPLE__;macOS 的差异只有 ExeDir() 用 _NSGetExecutablePath。
|
||
../client/TlsChannelLinux.cpp
|
||
../client/sign_shim_unix.cpp
|
||
ScreenHandler.mm
|
||
InputHandler.mm
|
||
SystemManager.mm
|
||
Permissions.mm
|
||
H264Encoder.mm
|
||
)
|
||
|
||
# Create executable
|
||
add_executable(ghost ${SOURCES})
|
||
|
||
# Include directories
|
||
target_include_directories(ghost PRIVATE
|
||
${CMAKE_CURRENT_SOURCE_DIR}
|
||
)
|
||
|
||
# Find and link macOS frameworks
|
||
find_library(COCOA_FRAMEWORK Cocoa REQUIRED)
|
||
find_library(COREGRAPHICS_FRAMEWORK CoreGraphics REQUIRED)
|
||
find_library(IOKIT_FRAMEWORK IOKit REQUIRED)
|
||
find_library(IOSURFACE_FRAMEWORK IOSurface REQUIRED)
|
||
find_library(APPLICATIONSERVICES_FRAMEWORK ApplicationServices REQUIRED)
|
||
find_library(SECURITY_FRAMEWORK Security REQUIRED)
|
||
find_library(CARBON_FRAMEWORK Carbon REQUIRED)
|
||
find_library(VIDEOTOOLBOX_FRAMEWORK VideoToolbox REQUIRED)
|
||
find_library(COREMEDIA_FRAMEWORK CoreMedia REQUIRED)
|
||
find_library(COREVIDEO_FRAMEWORK CoreVideo REQUIRED)
|
||
find_library(ACCELERATE_FRAMEWORK Accelerate REQUIRED)
|
||
find_library(ICONV_LIBRARY iconv REQUIRED)
|
||
|
||
# ---- OpenSSL(TLS 传输,见 client/TlsChannelLinux.cpp)----
|
||
# macOS 不自带 OpenSSL。优先用 Homebrew 的 openssl@3;也可显式指定
|
||
# cmake .. -DOPENSSL_ROOT_DIR=/path/to/openssl
|
||
# Apple Silicon 的 Homebrew 前缀是 /opt/homebrew,Intel 是 /usr/local。
|
||
if(NOT OPENSSL_ROOT_DIR)
|
||
foreach(_openssl_candidate
|
||
/opt/homebrew/opt/openssl@3
|
||
/usr/local/opt/openssl@3
|
||
/opt/homebrew/opt/openssl
|
||
/usr/local/opt/openssl)
|
||
if(EXISTS "${_openssl_candidate}/include/openssl/ssl.h")
|
||
set(OPENSSL_ROOT_DIR "${_openssl_candidate}")
|
||
break()
|
||
endif()
|
||
endforeach()
|
||
endif()
|
||
if(NOT OPENSSL_ROOT_DIR)
|
||
message(FATAL_ERROR
|
||
"找不到 OpenSSL。先执行: brew install openssl@3\n"
|
||
"或显式指定: cmake .. -DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl@3")
|
||
endif()
|
||
|
||
# 有静态库就静态链接:产物保持单文件,install.sh 不需要打包 dylib 或修 @rpath。
|
||
# Homebrew 的 openssl@3 同时装 .a 和 .dylib;只有动态库时这里退化为动态链接并告警,
|
||
# 那种情况下发布前必须把 libssl/libcrypto dylib 一并放进 .app 的 Contents/Frameworks。
|
||
if(EXISTS "${OPENSSL_ROOT_DIR}/lib/libssl.a" AND EXISTS "${OPENSSL_ROOT_DIR}/lib/libcrypto.a")
|
||
set(OPENSSL_USE_STATIC_LIBS TRUE)
|
||
else()
|
||
message(WARNING
|
||
"OpenSSL 静态库不存在(${OPENSSL_ROOT_DIR}/lib/libssl.a),将动态链接;"
|
||
"发布前请确认目标 Mac 装有同一份 OpenSSL,或把 dylib 放进 Contents/Frameworks。")
|
||
endif()
|
||
find_package(OpenSSL REQUIRED)
|
||
message(STATUS "OpenSSL: ${OPENSSL_VERSION} (${OPENSSL_INCLUDE_DIR})")
|
||
|
||
target_link_libraries(ghost PRIVATE
|
||
${COCOA_FRAMEWORK}
|
||
${COREGRAPHICS_FRAMEWORK}
|
||
${IOKIT_FRAMEWORK}
|
||
${IOSURFACE_FRAMEWORK}
|
||
${APPLICATIONSERVICES_FRAMEWORK}
|
||
${SECURITY_FRAMEWORK}
|
||
${CARBON_FRAMEWORK}
|
||
${VIDEOTOOLBOX_FRAMEWORK}
|
||
${COREMEDIA_FRAMEWORK}
|
||
${COREVIDEO_FRAMEWORK}
|
||
${ACCELERATE_FRAMEWORK}
|
||
${ICONV_LIBRARY}
|
||
"${CMAKE_SOURCE_DIR}/lib/libzstd.a"
|
||
# 私有签名库(提供 signMessage / verifyMessage,源码不开源)
|
||
# 该库由 SimplePlugins 仓库本地构建后放置于 lib/,构建机需先准备好
|
||
# libsign.a 内部使用 macOS CommonCrypto(HMAC-SHA256),CCHmac 在 libSystem
|
||
# 中已被 Cocoa/CoreFoundation 等链接自动引入,故此处无需额外 framework
|
||
"${CMAKE_SOURCE_DIR}/lib/libsign.a"
|
||
OpenSSL::SSL
|
||
OpenSSL::Crypto
|
||
)
|
||
|
||
# Compiler flags
|
||
target_compile_options(ghost PRIVATE
|
||
-Wall
|
||
-Wextra
|
||
-fobjc-arc
|
||
)
|
||
|
||
# Output directory
|
||
set_target_properties(ghost PROPERTIES
|
||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||
)
|