linux/CMakeLists.txt forced -g into the global flags regardless of build type, so even a Release build carried full DWARF: 7.7MB of the 10.3MB binary was .debug_* material the client never uses at runtime. Drop the forced -g and default CMAKE_BUILD_TYPE to Release, stripping the symbol table at link time (-s) so only Debug builds keep symbols. Do the same for macOS with ld64's -Wl,-x on Release, which drops the 8.3k local symbols while keeping external ones and the signature ld appends. linux/ghost drops from 10.3MB to 2.5MB (UPX on top: 0.87MB). Rebuilt under WSL and verified with readelf: no .debug_*/.symtab/.strtab, BuildID kept. The macOS change is not verified here; it needs a build on the Mac. Co-Authored-By: deepseek-flash
66 lines
2.3 KiB
CMake
66 lines
2.3 KiB
CMake
# 编译方法:cmake . && make
|
||
# 设置 CMake 最低版本要求
|
||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||
set(CMAKE_CXX_STANDARD 11)
|
||
set(CMAKE_CXX_STANDARD_REQUIRED 11)
|
||
|
||
cmake_minimum_required(VERSION 3.22)
|
||
|
||
# 定义项目名称和版本
|
||
project(SimpleRemoter VERSION 1.0)
|
||
|
||
# 对于C++项目,确保标准库也静态链接
|
||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
|
||
endif()
|
||
|
||
# X11 通过 dlopen 运行时加载,编译时无需 X11 开发库
|
||
|
||
include_directories(${CMAKE_SOURCE_DIR}/mterm)
|
||
|
||
# 额外的包含目录
|
||
include_directories(../)
|
||
include_directories(../client)
|
||
include_directories(../compress)
|
||
|
||
# 添加可执行文件
|
||
set(SOURCES
|
||
main.cpp
|
||
ScreenPreview.cpp # 屏幕预览(缩略图)抓屏,见 ScreenPreview.h
|
||
../client/Buffer.cpp
|
||
../client/IOCPClient.cpp
|
||
../client/TlsChannelLinux.cpp # Linux 客户端单向 TLS(OpenSSL),见 client/TlsChannel.h
|
||
../client/sign_shim_unix.cpp
|
||
)
|
||
add_executable(ghost ${SOURCES})
|
||
|
||
|
||
# 默认使用 Release:无调试信息、-O3,链接时剥离符号表(ghost 约 2.5MB);
|
||
# 需要 gdb 调试时用:cmake -DCMAKE_BUILD_TYPE=Debug . && make
|
||
if(NOT CMAKE_BUILD_TYPE)
|
||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
||
endif()
|
||
|
||
# 注意:这里不要再往 CMAKE_CXX_FLAGS 里塞 -g,否则 Release 也会带上 DWARF
|
||
# (ghost 会涨到 10MB 以上,其中 75% 是 .debug_* 段)。
|
||
target_link_options(ghost PRIVATE $<$<CONFIG:Release>:-s>)
|
||
|
||
# 链接 ZSTD 库
|
||
message(STATUS "链接库文件: ${CMAKE_SOURCE_DIR}/lib/libzstd.a")
|
||
target_link_libraries(ghost PRIVATE "${CMAKE_SOURCE_DIR}/lib/libzstd.a")
|
||
|
||
# 链接私有签名库(提供 signMessage / verifyMessage,源码不开源)
|
||
# 该库由 SimplePlugins 仓库本地构建后放置于 lib/,构建机需先准备好
|
||
target_link_libraries(ghost PRIVATE "${CMAKE_SOURCE_DIR}/lib/libsign.a")
|
||
|
||
# libsign.a 内部使用 OpenSSL HMAC,需要在最终可执行链接 libcrypto;
|
||
# 客户端传输层 TLS(client/TlsChannelLinux.cpp)另需 libssl。
|
||
find_package(OpenSSL REQUIRED)
|
||
target_link_libraries(ghost PRIVATE OpenSSL::Crypto OpenSSL::SSL)
|
||
|
||
# 链接 dl 库(dlopen/dlsym 用于运行时加载 X11)
|
||
target_link_libraries(ghost PRIVATE dl)
|
||
|
||
# 链接 pthread 库(std::thread 需要)
|
||
target_link_libraries(ghost PRIVATE pthread)
|