Qt6使用CMake自定义QML模块
立即下载
资源介绍:
演示如何创建自定义的QML库并使用
cmake_minimum_required(VERSION 3.16)
project(test 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)
find_package(Qt6 REQUIRED COMPONENTS
Core
Qml
Quick
Widgets
)
#根据编译的选项创建输出的路径
set(POJECT_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
string(APPEND POJECT_OUTPUT_PATH "/x64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
string(APPEND POJECT_OUTPUT_PATH "/x86")
else()
message(FATAL_ERROR "Unknown Architecture")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
string(APPEND POJECT_OUTPUT_PATH "/release")
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
string(APPEND POJECT_OUTPUT_PATH "/debug")
else()
message(FATAL_ERROR "Unknown CompileMode")
endif()
message("POJECT_OUTPUT_PATH : ${POJECT_OUTPUT_PATH}")
#指定输出路径
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${POJECT_OUTPUT_PATH})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${POJECT_OUTPUT_PATH})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${POJECT_OUTPUT_PATH})
#添加QML模块的搜索路径
function(add_qml_module_path path)
set(tmp_list ${QML_IMPORT_PATH})
list(APPEND tmp_list ${path})
list(REMOVE_DUPLICATES tmp_list)
set(QML_IMPORT_PATH ${tmp_list} CACHE STRING "Qml module search path" FORCE)
endfunction()
add_subdirectory(${CMAKE_SOURCE_DIR}/LibMyControl)
add_subdirectory(${CMAKE_SOURCE_DIR}/ExeMain)