mirror of
https://github.com/linuxdeepin/deepin-music.git
synced 2026-10-16 21:20:47 +08:00
ea724921f9
- Wrap linker flags with NOT WIN32 condition (root CMakeLists.txt) - Replace hardcoded VLC include paths with find_path for portability - Force-include poll.h for VLC headers compatibility - Disable AUTORCC, use qt_add_resources explicitly - Add --export-all-symbols for MinGW (libdmusic) - Conditionally link MPRIS only on Linux - Add WIN32 executable support with Windows resource file - Add Qt6::Svg dependency, add appicon.rc for Windows build: 适配 CMakeLists 以支持跨平台(Windows/MSYS2)编译 - 将链接器标志包裹在 NOT WIN32 条件中(根 CMakeLists.txt) - 用 find_path 替代 VLC 硬编码 include 路径以提高可移植性 - 强制 include poll.h 以兼容 VLC 头文件 - 禁用 AUTORCC,显式使用 qt_add_resources - 为 MinGW 添加 --export-all-symbols(libdmusic) - 仅在 Linux 上条件链接 MPRIS - 添加 WIN32 可执行文件支持及 Windows 资源文件 - 添加 Qt6::Svg 依赖,添加 appicon.rc 用于 Windows
69 lines
3.0 KiB
CMake
69 lines
3.0 KiB
CMake
cmake_minimum_required(VERSION 3.10)
|
|
|
|
project(deepin-music)
|
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
set(CMAKE_AUTOMOC ON)
|
|
set(CMAKE_AUTORCC ON)
|
|
set(CMAKE_AUTOUIC ON)
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
|
|
endif()
|
|
|
|
# 编译加固
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
message("Enable build hardening.")
|
|
|
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
|
|
set(HARDENING_FLAGS "-Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -ffile-prefix-map=${CMAKE_SOURCE_DIR}=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HARDENING_FLAGS}")
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${HARDENING_FLAGS}")
|
|
if (NOT WIN32)
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now")
|
|
endif()
|
|
endif()
|
|
|
|
# 编译优化参数
|
|
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "mips64")
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections -ftree-vectorize -march=loongson3a -mhard-float -mno-micromips -mno-mips16 -flax-vector-conversions -mloongson-ext2 -mloongson-mmi -z noexecstack")
|
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections -ftree-vectorize -march=loongson3a -mhard-float -mno-micromips -mno-mips16 -flax-vector-conversions -mloongson-ext2 -mloongson-mmi -z noexecstack")
|
|
else()
|
|
if (WIN32)
|
|
# Windows: -Wl,-E (export-dynamic) not supported, use -Wl,--export-all-symbols if needed
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections")
|
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections")
|
|
else()
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections")
|
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections")
|
|
endif()
|
|
endif()
|
|
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
|
|
endif()
|
|
|
|
include_directories(${PROJECT_BINARY_DIR})
|
|
include_directories(${PROJECT_SOURCE_DIR})
|
|
|
|
configure_file(${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h @ONLY)
|
|
|
|
# 单元测试覆盖率:Debug 构建时为所有目标开启 gcov 插桩,供 lcov/gcov 统计被测库(dmusic)的行覆盖率
|
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -g")
|
|
endif()
|
|
|
|
# Application
|
|
add_subdirectory(src)
|
|
|
|
# Unit Tests
|
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
add_subdirectory(tests)
|
|
endif()
|
|
|