2023-06-08 23:19:38 +08:00
|
|
|
|
cmake_minimum_required(VERSION 3.20)
|
2023-04-01 21:01:46 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
project(example VERSION 0.1 LANGUAGES CXX)
|
2023-04-01 21:01:46 +08:00
|
|
|
|
|
2023-05-05 18:51:40 +08:00
|
|
|
|
#配置通用编译
|
2023-04-27 09:38:57 +08:00
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
2023-05-05 18:51:40 +08:00
|
|
|
|
if(APPLE)
|
|
|
|
|
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
|
|
|
|
|
endif()
|
2023-07-10 19:07:54 +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-04-27 09:38:57 +08:00
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/debug)
|
2023-04-03 22:45:18 +08:00
|
|
|
|
else()
|
2023-04-27 09:38:57 +08:00
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/release)
|
2023-04-03 22:45:18 +08:00
|
|
|
|
endif()
|
|
|
|
|
|
2023-05-05 18:51:40 +08:00
|
|
|
|
#获取文件路径分隔符(解决执行命令的时候有些平台会报错)
|
|
|
|
|
file(TO_CMAKE_PATH "/" PATH_SEPARATOR)
|
|
|
|
|
|
|
|
|
|
#设置版本号
|
2023-07-28 16:22:15 +08:00
|
|
|
|
add_definitions(-DVERSION=1,4,0,0)
|
2023-05-05 18:51:40 +08:00
|
|
|
|
|
2023-07-20 18:26:47 +08:00
|
|
|
|
find_package(Qt6 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
|
|
|
|
|
|
|
|
|
#遍历所有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)
|
|
|
|
|
|
|
|
|
|
#遍历所有qml文件
|
|
|
|
|
file(GLOB_RECURSE QML_PATHS *.qml)
|
|
|
|
|
foreach(filepath ${QML_PATHS})
|
|
|
|
|
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
|
|
|
|
|
list(APPEND qml_files ${filename})
|
|
|
|
|
endforeach(filepath)
|
|
|
|
|
|
|
|
|
|
#遍历所有资源文件
|
2023-04-27 14:30:10 +08:00
|
|
|
|
file(GLOB_RECURSE RES_PATHS *.png *.jpg *.svg *.ico *.ttf *.webp qmldir)
|
2023-04-27 09:38:57 +08:00
|
|
|
|
foreach(filepath ${RES_PATHS})
|
|
|
|
|
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
|
|
|
|
|
list(APPEND resource_files ${filename})
|
|
|
|
|
endforeach(filepath)
|
|
|
|
|
|
|
|
|
|
#添加可执行文件
|
2023-04-27 15:43:45 +08:00
|
|
|
|
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
|
|
|
|
qt_add_executable(example
|
|
|
|
|
${sources_files}
|
|
|
|
|
example.rc
|
|
|
|
|
)
|
|
|
|
|
else ()
|
|
|
|
|
qt_add_executable(example
|
|
|
|
|
${sources_files}
|
|
|
|
|
)
|
|
|
|
|
endif ()
|
2023-04-01 21:01:46 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#复制动态库到可执行文件同级目录下
|
2023-04-01 21:01:46 +08:00
|
|
|
|
if(WIN32)
|
2023-04-27 14:30:10 +08:00
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
2023-04-27 09:38:57 +08:00
|
|
|
|
set(DLLPATH ${CMAKE_SOURCE_DIR}/3rdparty/msvc/*.dll)
|
2023-04-01 21:01:46 +08:00
|
|
|
|
else()
|
2023-04-27 09:38:57 +08:00
|
|
|
|
set(DLLPATH ${CMAKE_SOURCE_DIR}/3rdparty/mingw/*.dll)
|
2023-04-01 21:01:46 +08:00
|
|
|
|
endif()
|
2023-04-09 17:59:00 +08:00
|
|
|
|
string(REPLACE "/" ${PATH_SEPARATOR} DLLPATH "${DLLPATH}")
|
|
|
|
|
file(GLOB DLL_FILES ${DLLPATH})
|
|
|
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
|
${DLL_FILES}
|
|
|
|
|
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
|
|
|
|
)
|
2023-04-01 21:01:46 +08:00
|
|
|
|
endif()
|
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#添加qml模块
|
|
|
|
|
qt_add_qml_module(example
|
2023-07-26 11:02:33 +08:00
|
|
|
|
URI "example"
|
2023-04-27 09:38:57 +08:00
|
|
|
|
VERSION 1.0
|
2023-04-27 14:30:10 +08:00
|
|
|
|
QML_FILES ${qml_files}
|
2023-04-27 09:38:57 +08:00
|
|
|
|
RESOURCES ${resource_files}
|
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-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-04-27 09:38:57 +08:00
|
|
|
|
#链接库
|
2023-07-09 23:05:52 +08:00
|
|
|
|
if (FLUENTUI_BUILD_STATIC_LIB)
|
|
|
|
|
target_link_libraries(example PRIVATE
|
|
|
|
|
Qt6::Quick
|
2023-07-20 18:26:47 +08:00
|
|
|
|
Qt6::Svg
|
|
|
|
|
Qt6::Network
|
2023-07-09 23:05:52 +08:00
|
|
|
|
fluentui
|
|
|
|
|
fluentuiplugin
|
|
|
|
|
FramelessHelper::Core
|
|
|
|
|
FramelessHelper::Quick
|
|
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
target_link_libraries(example PRIVATE
|
|
|
|
|
Qt6::Quick
|
2023-07-20 18:26:47 +08:00
|
|
|
|
Qt6::Svg
|
|
|
|
|
Qt6::Network
|
2023-07-09 23:05:52 +08:00
|
|
|
|
fluentuiplugin
|
|
|
|
|
FramelessHelper::Core
|
|
|
|
|
FramelessHelper::Quick
|
|
|
|
|
)
|
|
|
|
|
endif()
|
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}
|
|
|
|
|
)
|