mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-27 05:38:37 +08:00
105 lines
3.8 KiB
CMake
105 lines
3.8 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
|
|
project(%1 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)
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE})
|
|
|
|
if(APPLE)
|
|
set(APPLICATION_DIR_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/MacOS)
|
|
else()
|
|
set(APPLICATION_DIR_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
|
endif()
|
|
|
|
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick)
|
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick)
|
|
|
|
find_program(QT_LUPDATE NAMES lupdate)
|
|
find_program(QT_LRELEASE NAMES lrelease)
|
|
file(GLOB TS_FILE_PATHS ${CMAKE_CURRENT_LIST_DIR}/ *.ts)
|
|
add_custom_target(Script-UpdateTranslations
|
|
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}
|
|
)
|
|
|
|
set(PROJECT_SOURCES
|
|
main.cpp
|
|
qml.qrc
|
|
)
|
|
|
|
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
|
qt_add_executable(${PROJECT_NAME}
|
|
MANUAL_FINALIZATION
|
|
${PROJECT_SOURCES}
|
|
)
|
|
else()
|
|
add_executable(${PROJECT_NAME}
|
|
${PROJECT_SOURCES}
|
|
)
|
|
endif()
|
|
|
|
add_dependencies(${PROJECT_NAME} Script-UpdateTranslations)
|
|
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
|
Qt${QT_VERSION_MAJOR}::Core
|
|
Qt${QT_VERSION_MAJOR}::Quick
|
|
fluentuiplugin
|
|
)
|
|
|
|
if(${QT_VERSION} VERSION_LESS 6.1.0)
|
|
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.${PROJECT_NAME})
|
|
endif()
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
${BUNDLE_ID_OPTION}
|
|
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
|
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
|
MACOSX_BUNDLE TRUE
|
|
WIN32_EXECUTABLE TRUE
|
|
)
|
|
|
|
include(GNUInstallDirs)
|
|
install(TARGETS ${PROJECT_NAME}
|
|
BUNDLE DESTINATION .
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
if(QT_VERSION_MAJOR EQUAL 6)
|
|
qt_import_qml_plugins(${PROJECT_NAME})
|
|
qt_finalize_executable(${PROJECT_NAME})
|
|
endif()
|
|
|
|
if (CMAKE_BUILD_TYPE MATCHES "Release")
|
|
if (APPLE)
|
|
find_program(QT_DEPLOY_QT NAMES macdeployqt)
|
|
add_custom_target(Script-DeployRelease
|
|
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} -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}
|
|
)
|
|
endif()
|
|
if(WIN32)
|
|
find_program(QT_DEPLOY_QT NAMES windeployqt)
|
|
add_custom_target(Script-DeployRelease
|
|
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}.exe -qmldir=${CMAKE_CURRENT_LIST_DIR}
|
|
COMMENT "Windows Deploying Qt Dependencies After Build........."
|
|
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
)
|
|
endif()
|
|
endif()
|