2023-06-08 23:19:38 +08:00
|
|
|
|
cmake_minimum_required(VERSION 3.20)
|
2023-04-01 21:01:46 +08:00
|
|
|
|
|
2024-01-04 18:00:44 +08:00
|
|
|
|
project(example VERSION 1.0 LANGUAGES CXX)
|
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)
|
2023-04-27 09:38:57 +08:00
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
2023-12-14 22:06:26 +08:00
|
|
|
|
|
2023-07-27 17:46:18 +08:00
|
|
|
|
#导入exmaple的QML位置,不然import example有时候会爆红
|
2023-07-26 11:02:33 +08:00
|
|
|
|
set(QML_IMPORT_PATH ${CMAKE_BINARY_DIR}/example CACHE STRING "Qt Creator extra QML import paths" FORCE)
|
|
|
|
|
|
2023-07-10 19:07:54 +08:00
|
|
|
|
#判断FluentUI库类型
|
|
|
|
|
if(FLUENTUI_BUILD_STATIC_LIB)
|
|
|
|
|
add_definitions(-DFLUENTUI_BUILD_STATIC_LIB)
|
|
|
|
|
endif()
|
2023-04-09 17:59:00 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#设置可执行文件输出目录
|
2023-04-03 22:45:18 +08:00
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2023-11-27 18:23:36 +08:00
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${FLUENTUI_DIRECTORY}/bin/debug>)
|
2023-04-03 22:45:18 +08:00
|
|
|
|
else()
|
2023-11-27 18:23:36 +08:00
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${FLUENTUI_DIRECTORY}/bin/release>)
|
2023-04-03 22:45:18 +08:00
|
|
|
|
endif()
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
if(QT_VERSION VERSION_GREATER_EQUAL "6.3")
|
|
|
|
|
qt_standard_project_setup()
|
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_AUTOMOC ON)
|
|
|
|
|
set(CMAKE_AUTORCC ON)
|
|
|
|
|
set(CMAKE_AUTOUIC ON)
|
|
|
|
|
endif()
|
2023-04-27 09:38:57 +08:00
|
|
|
|
|
2023-08-10 16:08:27 +08:00
|
|
|
|
##生成版本信息头文件
|
2023-08-17 12:38:44 +08:00
|
|
|
|
set(HEADER_FILE_VERSION_PATH ${FLUENTUI_DIRECTORY}/example/Version.h)
|
2023-08-10 16:08:27 +08:00
|
|
|
|
configure_file(
|
2023-08-17 12:38:44 +08:00
|
|
|
|
${FLUENTUI_DIRECTORY}/.cmake/Version.h.in
|
2023-08-10 16:08:27 +08:00
|
|
|
|
${HEADER_FILE_VERSION_PATH}
|
|
|
|
|
)
|
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#遍历所有Cpp文件
|
|
|
|
|
file(GLOB_RECURSE CPP_FILES *.cpp *.h)
|
|
|
|
|
foreach(filepath ${CPP_FILES})
|
|
|
|
|
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
|
|
|
|
|
list(APPEND sources_files ${filename})
|
|
|
|
|
endforeach(filepath)
|
|
|
|
|
|
2024-01-04 18:00:44 +08:00
|
|
|
|
if(WIN32)
|
|
|
|
|
list(APPEND sources_files "src/app_dmp.h")
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-08-24 15:50:37 +08:00
|
|
|
|
if(QT_VERSION VERSION_GREATER_EQUAL "6.2")
|
|
|
|
|
#遍历所有qml文件
|
2023-12-21 18:12:43 +08:00
|
|
|
|
file(GLOB_RECURSE QML_PATHS *.qml qmldir)
|
2023-08-24 15:50:37 +08:00
|
|
|
|
foreach(filepath ${QML_PATHS})
|
|
|
|
|
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
|
2023-12-21 18:12:43 +08:00
|
|
|
|
if(${filepath} MATCHES "qml-Qt6")
|
|
|
|
|
string(REPLACE "qml-Qt6" "qml" filealias ${filename})
|
2023-08-24 15:50:37 +08:00
|
|
|
|
set_source_files_properties(${filename} PROPERTIES QT_RESOURCE_ALIAS ${filealias})
|
2023-12-21 18:12:43 +08:00
|
|
|
|
if(${filename} MATCHES "qmldir")
|
|
|
|
|
list(APPEND resource_files ${filename})
|
|
|
|
|
else()
|
|
|
|
|
list(APPEND qml_files ${filename})
|
|
|
|
|
endif()
|
2023-08-24 15:50:37 +08:00
|
|
|
|
endif()
|
|
|
|
|
endforeach(filepath)
|
|
|
|
|
|
|
|
|
|
#遍历所有资源文件
|
2023-12-21 18:12:43 +08:00
|
|
|
|
file(GLOB_RECURSE RES_PATHS *.png *.jpg *.svg *.ico *.ttf *.webp *.obj)
|
2023-08-24 15:50:37 +08:00
|
|
|
|
foreach(filepath ${RES_PATHS})
|
|
|
|
|
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
|
|
|
|
|
list(APPEND resource_files ${filename})
|
|
|
|
|
endforeach(filepath)
|
2023-12-21 18:12:43 +08:00
|
|
|
|
|
2023-08-24 15:50:37 +08:00
|
|
|
|
endif()
|
2023-04-27 09:38:57 +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 "")
|
|
|
|
|
if(WIN32)
|
|
|
|
|
set(EXAMPLE_VERSION_RC_PATH ${CMAKE_BINARY_DIR}/version_${PROJECT_NAME}.rc)
|
|
|
|
|
configure_file(
|
2023-08-17 12:38:44 +08:00
|
|
|
|
${FLUENTUI_DIRECTORY}/.cmake/version_exe.rc.in
|
2023-08-10 16:08:27 +08:00
|
|
|
|
${EXAMPLE_VERSION_RC_PATH}
|
|
|
|
|
)
|
2023-12-06 23:57:30 +08:00
|
|
|
|
configure_file(
|
|
|
|
|
${FLUENTUI_DIRECTORY}/.cmake/InstallerScript.iss.in
|
|
|
|
|
${FLUENTUI_DIRECTORY}/action-cli/InstallerScript.iss
|
|
|
|
|
)
|
2023-08-10 16:08:27 +08:00
|
|
|
|
endif()
|
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#添加可执行文件
|
2023-08-10 16:08:27 +08:00
|
|
|
|
if (WIN32)
|
2023-08-24 15:50:37 +08:00
|
|
|
|
add_executable(example
|
2023-04-27 15:43:45 +08:00
|
|
|
|
${sources_files}
|
2023-08-10 16:08:27 +08:00
|
|
|
|
${EXAMPLE_VERSION_RC_PATH}
|
2023-04-27 15:43:45 +08:00
|
|
|
|
)
|
|
|
|
|
else ()
|
2023-08-24 15:50:37 +08:00
|
|
|
|
add_executable(example
|
2023-04-27 15:43:45 +08:00
|
|
|
|
${sources_files}
|
|
|
|
|
)
|
|
|
|
|
endif ()
|
2023-04-01 21:01:46 +08:00
|
|
|
|
|
2023-12-21 18:12:43 +08:00
|
|
|
|
#复制程序运行所需要的动态库
|
2023-04-01 21:01:46 +08:00
|
|
|
|
if(WIN32)
|
2023-10-11 23:56:16 +08:00
|
|
|
|
if(MSVC)
|
2023-12-21 18:12:43 +08:00
|
|
|
|
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)
|
2023-12-21 18:12: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)
|
2023-12-21 18:12:43 +08:00
|
|
|
|
endif()
|
2023-10-11 23:56:16 +08:00
|
|
|
|
elseif(MINGW)
|
2024-01-22 16:38:20 +08:00
|
|
|
|
file(GLOB_RECURSE 3RDPARTY_DLL_DIR ${CMAKE_SOURCE_DIR}/3rdparty/mingw/*.dll)
|
2023-04-01 21:01:46 +08:00
|
|
|
|
endif()
|
2023-04-09 17:59:00 +08:00
|
|
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
2024-01-22 16:38:20 +08:00
|
|
|
|
${3RDPARTY_DLL_DIR}
|
2023-04-09 17:59:00 +08:00
|
|
|
|
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
|
|
|
|
)
|
2023-04-01 21:01:46 +08:00
|
|
|
|
endif()
|
|
|
|
|
|
2023-08-24 15:50:37 +08:00
|
|
|
|
if(QT_VERSION VERSION_GREATER_EQUAL "6.2")
|
2023-12-21 18:12:43 +08:00
|
|
|
|
#如果是Qt6.2以上,则使用qt_add_qml_module添加资源文件
|
2023-08-24 15:50:37 +08:00
|
|
|
|
qt_add_qml_module(example
|
|
|
|
|
URI "example"
|
|
|
|
|
VERSION 1.0
|
|
|
|
|
QML_FILES ${qml_files}
|
|
|
|
|
RESOURCES ${resource_files}
|
|
|
|
|
RESOURCE_PREFIX "/"
|
|
|
|
|
)
|
|
|
|
|
else()
|
2023-12-21 18:12:43 +08:00
|
|
|
|
#如果是Qt6.2以下,则使用qrc添加资源文件
|
2023-08-24 15:50:37 +08:00
|
|
|
|
target_include_directories(example PRIVATE
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
|
)
|
2024-01-22 16:38:20 +08:00
|
|
|
|
target_sources(example PRIVATE example.qrc)
|
2023-08-24 15:50:37 +08:00
|
|
|
|
endif()
|
2023-04-01 21:01:46 +08:00
|
|
|
|
|
2023-07-21 18:58:09 +08:00
|
|
|
|
#导入component头文件,不然通过QML_NAMED_ELEMENT生成的c++类会找不到头文件报错
|
|
|
|
|
target_include_directories(example PRIVATE
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/component
|
|
|
|
|
)
|
|
|
|
|
|
2023-11-02 11:34:02 +08:00
|
|
|
|
#如果是静态库则需要手动注册插件,导入FluentUI.h头文件
|
2023-09-09 20:09:20 +08:00
|
|
|
|
if(FLUENTUI_BUILD_STATIC_LIB)
|
|
|
|
|
target_include_directories(example PRIVATE
|
|
|
|
|
${CMAKE_SOURCE_DIR}/src
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#设置属性
|
|
|
|
|
set_target_properties(example PROPERTIES
|
|
|
|
|
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.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也支持日志打印代码位置
|
2023-12-06 23:57:30 +08:00
|
|
|
|
target_compile_definitions(example
|
|
|
|
|
PRIVATE
|
|
|
|
|
QT_MESSAGELOGCONTEXT
|
|
|
|
|
)
|
|
|
|
|
|
2023-12-21 18:12:43 +08:00
|
|
|
|
#目标文件链接库
|
2023-09-09 20:09:20 +08:00
|
|
|
|
target_link_libraries(example PRIVATE
|
|
|
|
|
Qt${QT_VERSION_MAJOR}::Quick
|
|
|
|
|
Qt${QT_VERSION_MAJOR}::Svg
|
|
|
|
|
Qt${QT_VERSION_MAJOR}::Network
|
|
|
|
|
fluentuiplugin
|
|
|
|
|
)
|
2023-05-18 15:19:39 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#安装
|
|
|
|
|
install(TARGETS example
|
|
|
|
|
BUNDLE DESTINATION .
|
2023-06-16 17:17:21 +08:00
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
|
)
|