85 lines
2.5 KiB
CMake
Executable File
85 lines
2.5 KiB
CMake
Executable File
cmake_minimum_required(VERSION 3.16)
|
||
|
||
project(XNSysMonitor VERSION 0.1 LANGUAGES CXX)
|
||
|
||
set(CMAKE_AUTOUIC ON)
|
||
set(CMAKE_AUTOMOC ON)
|
||
set(CMAKE_AUTORCC ON)
|
||
|
||
set(CMAKE_CXX_STANDARD 17)
|
||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||
|
||
add_definitions(-DQCUSTOMPLOT_USE_OPENGL)
|
||
|
||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets PrintSupport OpenGLWidgets)
|
||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets PrintSupport OpenGLWidgets)
|
||
find_package(OpenGL REQUIRED)
|
||
|
||
#set(QT_SOURCE_FILE qdarkstyle/light/lightstyle.qrc) # 将资源文件放到工程目录下,该部分会由RCC编译器预编译为cpp文件
|
||
set(QT_SOURCE_FILE ../qdarkstyle/dark/darkstyle.qrc)
|
||
|
||
# 根据 Qt 版本选择正确的资源添加函数
|
||
qt6_add_resources(QT_RESOURCES ${QT_SOURCE_FILE})
|
||
|
||
set(PROJECT_SOURCES
|
||
main.cpp
|
||
mainwindow.cpp
|
||
mainwindow.h
|
||
qcustomplot.h
|
||
qcustomplot.cpp
|
||
cpuworker.h
|
||
cpuworker.cpp
|
||
mainwindow.ui
|
||
${QT_RESOURCES}
|
||
)
|
||
|
||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||
qt_add_executable(XNSysMonitor
|
||
MANUAL_FINALIZATION
|
||
${PROJECT_SOURCES}
|
||
)
|
||
# Define target properties for Android with Qt 6 as:
|
||
# set_property(TARGET XNSysMonitor APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
|
||
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
|
||
else()
|
||
if(ANDROID)
|
||
add_library(XNSysMonitor SHARED
|
||
${PROJECT_SOURCES}
|
||
)
|
||
# Define properties for Android with Qt 5 after find_package() calls as:
|
||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||
else()
|
||
add_executable(XNSysMonitor
|
||
${PROJECT_SOURCES}
|
||
)
|
||
endif()
|
||
endif()
|
||
|
||
target_link_libraries(XNSysMonitor PRIVATE
|
||
Qt${QT_VERSION_MAJOR}::Widgets
|
||
Qt${QT_VERSION_MAJOR}::OpenGLWidgets
|
||
Qt${QT_VERSION_MAJOR}::PrintSupport
|
||
OpenGL::GL
|
||
)
|
||
|
||
# Check if CMAKE_INSTALL_PREFIX is set to its default value
|
||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../Release" CACHE PATH "Install path prefix" FORCE)
|
||
endif()
|
||
|
||
include(GNUInstallDirs)
|
||
install(TARGETS XNSysMonitor
|
||
BUNDLE DESTINATION .
|
||
LIBRARY DESTINATION .
|
||
RUNTIME DESTINATION .
|
||
)
|
||
|
||
# Add a post-installation command to set the application icon using gio
|
||
install(CODE "
|
||
execute_process(COMMAND gio set -t string ${CMAKE_INSTALL_PREFIX}/XNSysMonitor \"metadata::custom-icon\" \"file://${CMAKE_INSTALL_PREFIX}/resource/XNSysMonitor.png\")
|
||
")
|
||
|
||
if(QT_VERSION_MAJOR EQUAL 6)
|
||
qt_finalize_executable(XNSysMonitor)
|
||
endif() |