2023-06-08 23:19:38 +08:00
|
|
|
|
cmake_minimum_required(VERSION 3.20)
|
2023-04-01 21:01:46 +08:00
|
|
|
|
|
2024-03-23 22:17:03 +08:00
|
|
|
|
project(example VERSION 1.0)
|
2023-04-01 21:01:46 +08:00
|
|
|
|
|
2023-05-05 18:51:40 +08:00
|
|
|
|
#配置通用编译
|
2023-12-14 22:06:26 +08:00
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2024-03-18 17:07:44 +08:00
|
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
|
|
|
set(CMAKE_AUTOMOC ON)
|
|
|
|
|
set(CMAKE_AUTORCC ON)
|
2023-04-27 09:38:57 +08:00
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
2023-12-14 22:06:26 +08:00
|
|
|
|
|
2023-07-10 19:07:54 +08:00
|
|
|
|
#判断FluentUI库类型
|
2024-04-11 14:51:43 +08:00
|
|
|
|
if (FLUENTUI_BUILD_STATIC_LIB)
|
2023-07-10 19:07:54 +08:00
|
|
|
|
add_definitions(-DFLUENTUI_BUILD_STATIC_LIB)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endif ()
|
2023-04-09 17:59:00 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#设置可执行文件输出目录
|
2024-03-18 14:10:50 +08:00
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE})
|
2023-04-03 22:45:18 +08:00
|
|
|
|
|
2024-04-11 14:51:43 +08:00
|
|
|
|
if (APPLE)
|
2024-03-09 19:46:02 +08:00
|
|
|
|
set(APPLICATION_DIR_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/MacOS)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
else ()
|
2024-03-09 19:46:02 +08:00
|
|
|
|
set(APPLICATION_DIR_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endif ()
|
2024-03-09 19:46:02 +08:00
|
|
|
|
|
2023-12-21 18:12:43 +08:00
|
|
|
|
#导入Qt相关依赖包
|
2023-08-24 15:50:37 +08:00
|
|
|
|
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Quick Svg Network)
|
|
|
|
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Quick Svg Network)
|
2023-06-25 11:30:25 +08:00
|
|
|
|
|
2024-03-18 17:07:44 +08:00
|
|
|
|
#添加国际化脚本
|
2024-04-15 01:38:52 +08:00
|
|
|
|
find_program(QT_LUPDATE NAMES lupdate lupdate-qt6)
|
|
|
|
|
find_program(QT_LRELEASE NAMES lrelease lrelease-qt6)
|
2024-03-18 00:14:50 +08:00
|
|
|
|
file(GLOB TS_FILE_PATHS ${CMAKE_CURRENT_LIST_DIR}/ *.ts)
|
2024-03-18 17:07:44 +08:00
|
|
|
|
add_custom_target(Script-UpdateTranslations
|
2024-04-11 14:51:43 +08:00
|
|
|
|
COMMAND ${QT_LUPDATE} ${CMAKE_CURRENT_LIST_DIR} -ts ${PROJECT_NAME}_en_US.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
|
|
|
|
COMMAND ${QT_LUPDATE} ${CMAKE_CURRENT_LIST_DIR} -ts ${PROJECT_NAME}_zh_CN.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
|
|
|
|
COMMAND ${QT_LRELEASE} ${PROJECT_NAME}_en_US.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
|
|
|
|
COMMAND ${QT_LRELEASE} ${PROJECT_NAME}_zh_CN.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${APPLICATION_DIR_PATH}/i18n
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_NAME}_en_US.qm ${PROJECT_NAME}_zh_CN.qm ${APPLICATION_DIR_PATH}/i18n
|
|
|
|
|
SOURCES ${TS_FILE_PATHS}
|
2024-03-18 00:14:50 +08:00
|
|
|
|
)
|
2024-03-09 15:35:48 +08:00
|
|
|
|
|
2023-08-10 16:08:27 +08:00
|
|
|
|
##生成版本信息头文件
|
2024-03-09 19:46:02 +08:00
|
|
|
|
set(HEADER_FILE_VERSION_PATH ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}/Version.h)
|
2023-08-10 16:08:27 +08:00
|
|
|
|
configure_file(
|
2024-04-11 14:51:43 +08:00
|
|
|
|
${CMAKE_SOURCE_DIR}/.cmake/Version.h.in
|
|
|
|
|
${HEADER_FILE_VERSION_PATH}
|
2023-08-10 16:08:27 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#遍历所有Cpp文件
|
|
|
|
|
file(GLOB_RECURSE CPP_FILES *.cpp *.h)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
foreach (filepath ${CPP_FILES})
|
2023-04-27 09:38:57 +08:00
|
|
|
|
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
|
|
|
|
|
list(APPEND sources_files ${filename})
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endforeach (filepath)
|
2023-04-27 09:38:57 +08:00
|
|
|
|
|
2024-04-11 14:51:43 +08:00
|
|
|
|
if (WIN32)
|
2024-01-04 18:00:44 +08:00
|
|
|
|
list(APPEND sources_files "src/app_dmp.h")
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endif ()
|
2024-01-04 18:00:44 +08:00
|
|
|
|
|
2023-09-29 16:08:42 +08:00
|
|
|
|
#如果是Windows平台,则生成rc文件,还有inno setup脚本文件
|
2023-08-10 16:08:27 +08:00
|
|
|
|
set(EXAMPLE_VERSION_RC_PATH "")
|
2024-04-11 14:51:43 +08:00
|
|
|
|
if (WIN32)
|
2024-03-09 15:35:48 +08:00
|
|
|
|
set(EXAMPLE_VERSION_RC_PATH ${CMAKE_CURRENT_BINARY_DIR}/version_${PROJECT_NAME}.rc)
|
2023-08-10 16:08:27 +08:00
|
|
|
|
configure_file(
|
2024-04-11 14:51:43 +08:00
|
|
|
|
${CMAKE_SOURCE_DIR}/.cmake/version_exe.rc.in
|
|
|
|
|
${EXAMPLE_VERSION_RC_PATH}
|
2023-08-10 16:08:27 +08:00
|
|
|
|
)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
configure_file(
|
|
|
|
|
${CMAKE_SOURCE_DIR}/.cmake/InstallerScript.iss.in
|
2024-04-17 21:39:55 +08:00
|
|
|
|
${CMAKE_SOURCE_DIR}/package/InstallerScript.iss
|
2024-04-11 14:51:43 +08:00
|
|
|
|
)
|
|
|
|
|
endif ()
|
2023-08-10 16:08:27 +08:00
|
|
|
|
|
2024-06-21 13:21:32 +08:00
|
|
|
|
list(APPEND sources_files ${PROJECT_NAME}.qrc)
|
2024-03-20 12:44:35 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#添加可执行文件
|
2024-04-11 14:51:43 +08:00
|
|
|
|
if (WIN32)
|
2024-03-18 17:07:44 +08:00
|
|
|
|
list(APPEND sources_files ${EXAMPLE_VERSION_RC_PATH})
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endif ()
|
|
|
|
|
if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
2024-03-18 17:07:44 +08:00
|
|
|
|
qt_add_executable(${PROJECT_NAME}
|
2024-04-11 14:51:43 +08:00
|
|
|
|
MANUAL_FINALIZATION
|
|
|
|
|
${sources_files}
|
2023-04-27 15:43:45 +08:00
|
|
|
|
)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
else ()
|
2024-03-09 19:46:02 +08:00
|
|
|
|
add_executable(${PROJECT_NAME}
|
2024-04-11 14:51:43 +08:00
|
|
|
|
${sources_files}
|
2023-04-27 15:43:45 +08:00
|
|
|
|
)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endif ()
|
2024-03-18 17:07:44 +08:00
|
|
|
|
add_dependencies(${PROJECT_NAME} Script-UpdateTranslations)
|
2024-03-18 00:14:50 +08:00
|
|
|
|
|
2023-12-21 18:12:43 +08:00
|
|
|
|
#复制程序运行所需要的动态库
|
2024-04-11 14:51:43 +08:00
|
|
|
|
if (WIN32)
|
|
|
|
|
if (MSVC)
|
|
|
|
|
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
|
2024-01-22 16:38:20 +08:00
|
|
|
|
file(GLOB_RECURSE 3RDPARTY_DLL_DIR ${CMAKE_SOURCE_DIR}/3rdparty/msvc/x86/*.dll)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
2024-01-22 16:38:20 +08:00
|
|
|
|
file(GLOB_RECURSE 3RDPARTY_DLL_DIR ${CMAKE_SOURCE_DIR}/3rdparty/msvc/x64/*.dll)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endif ()
|
|
|
|
|
elseif (MINGW)
|
2024-01-22 16:38:20 +08:00
|
|
|
|
file(GLOB_RECURSE 3RDPARTY_DLL_DIR ${CMAKE_SOURCE_DIR}/3rdparty/mingw/*.dll)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endif ()
|
2024-03-18 00:14:50 +08:00
|
|
|
|
file(COPY ${3RDPARTY_DLL_DIR} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endif ()
|
2023-04-01 21:01:46 +08:00
|
|
|
|
|
2024-03-12 10:31:19 +08:00
|
|
|
|
#复制FluentUI源码到运行目录下,用于脚手架生成
|
2024-03-18 14:10:50 +08:00
|
|
|
|
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/source/)
|
|
|
|
|
file(COPY ${CMAKE_SOURCE_DIR}/src/ DESTINATION ${APPLICATION_DIR_PATH}/source/)
|
2024-03-09 15:35:48 +08:00
|
|
|
|
|
2023-07-21 18:58:09 +08:00
|
|
|
|
#导入component头文件,不然通过QML_NAMED_ELEMENT生成的c++类会找不到头文件报错
|
2024-03-09 19:46:02 +08:00
|
|
|
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
2024-04-11 14:51:43 +08:00
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/component
|
2023-07-21 18:58:09 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-11-02 11:34:02 +08:00
|
|
|
|
#如果是静态库则需要手动注册插件,导入FluentUI.h头文件
|
2024-04-11 14:51:43 +08:00
|
|
|
|
if (FLUENTUI_BUILD_STATIC_LIB)
|
2024-03-09 19:46:02 +08:00
|
|
|
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
2024-04-11 14:51:43 +08:00
|
|
|
|
${CMAKE_SOURCE_DIR}/src
|
2023-09-09 20:09:20 +08:00
|
|
|
|
)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endif ()
|
2023-09-09 20:09:20 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#设置属性
|
2024-03-09 19:46:02 +08:00
|
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
2024-04-11 14:51:43 +08:00
|
|
|
|
MACOSX_BUNDLE_GUI_IDENTIFIER my.${PROJECT_NAME}.com
|
|
|
|
|
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
|
|
|
|
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
|
|
|
|
MACOSX_BUNDLE TRUE
|
|
|
|
|
WIN32_EXECUTABLE TRUE
|
2023-04-01 21:01:46 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-12-21 18:12:43 +08:00
|
|
|
|
#Release也支持日志打印代码位置
|
2024-03-09 19:46:02 +08:00
|
|
|
|
target_compile_definitions(${PROJECT_NAME}
|
2024-04-11 14:51:43 +08:00
|
|
|
|
PRIVATE
|
|
|
|
|
QT_MESSAGELOGCONTEXT
|
2023-12-06 23:57:30 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-12-21 18:12:43 +08:00
|
|
|
|
#目标文件链接库
|
2024-03-09 19:46:02 +08:00
|
|
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
2024-04-11 14:51:43 +08:00
|
|
|
|
Qt${QT_VERSION_MAJOR}::Quick
|
|
|
|
|
Qt${QT_VERSION_MAJOR}::Svg
|
|
|
|
|
Qt${QT_VERSION_MAJOR}::Network
|
|
|
|
|
fluentuiplugin
|
2023-09-09 20:09:20 +08:00
|
|
|
|
)
|
2023-05-18 15:19:39 +08:00
|
|
|
|
|
2024-03-18 17:07:44 +08:00
|
|
|
|
#添加部署脚本
|
|
|
|
|
if (CMAKE_BUILD_TYPE MATCHES "Release")
|
|
|
|
|
if (APPLE)
|
|
|
|
|
find_program(QT_DEPLOY_QT NAMES macdeployqt)
|
|
|
|
|
add_custom_target(Script-DeployRelease
|
2024-04-11 14:51:43 +08:00
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_SOURCE_DIR}/dist
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${CMAKE_SOURCE_DIR}/dist
|
|
|
|
|
COMMAND ${QT_DEPLOY_QT} ${CMAKE_SOURCE_DIR}/dist/${PROJECT_NAME}.app -qmldir=${CMAKE_CURRENT_LIST_DIR}
|
|
|
|
|
COMMENT "MacOs Deploying Qt Dependencies After Build........."
|
|
|
|
|
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
2024-03-18 17:07:44 +08:00
|
|
|
|
)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endif ()
|
|
|
|
|
if (WIN32)
|
2024-03-18 17:07:44 +08:00
|
|
|
|
find_program(QT_DEPLOY_QT NAMES windeployqt)
|
|
|
|
|
add_custom_target(Script-DeployRelease
|
2024-04-11 14:51:43 +08:00
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_SOURCE_DIR}/dist
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${CMAKE_SOURCE_DIR}/dist
|
|
|
|
|
COMMAND ${QT_DEPLOY_QT} --qmldir=${CMAKE_CURRENT_LIST_DIR} --plugindir ${CMAKE_SOURCE_DIR}/dist/plugins --no-translations --compiler-runtime ${CMAKE_SOURCE_DIR}/dist/${PROJECT_NAME}.exe
|
|
|
|
|
COMMENT "Windows Deploying Qt Dependencies After Build........."
|
|
|
|
|
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
2024-03-18 17:07:44 +08:00
|
|
|
|
)
|
2024-04-11 14:51:43 +08:00
|
|
|
|
endif ()
|
|
|
|
|
endif ()
|