Skip to content

Commit

Permalink
feat: support arch
Browse files Browse the repository at this point in the history
  • Loading branch information
mhduiy committed May 13, 2024
1 parent d48ce23 commit 001d981
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 54 deletions.
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ cmake_minimum_required(VERSION 3.16)

project(MFloat VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(example)
add_subdirectory(src)
set(CMAKE_INSTALL_PREFIX /usr)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wextra")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed")

add_subdirectory(src)
add_subdirectory(example)
40 changes: 8 additions & 32 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,26 @@
cmake_minimum_required(VERSION 3.20)

project(MFloat_Example VERSION 0.1 LANGUAGES CXX)
set(BIN_NAME MFloat-Example-bin)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick)

# 无法成功编译资源文件,暂时换回老方法
#qt_standard_project_setup()

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(resource_files
example.qrc
)

set(QT_SDK_DIR "${Qt${QT_VERSION_MAJOR}_DIR}")
cmake_path(GET QT_SDK_DIR PARENT_PATH QT_SDK_DIR)
cmake_path(GET QT_SDK_DIR PARENT_PATH QT_SDK_DIR)
cmake_path(GET QT_SDK_DIR PARENT_PATH QT_SDK_DIR)

set(QML_IMPORT_PATH qrc:/qt/qml)

qt_add_executable(${PROJECT_NAME}
qt_add_executable(${BIN_NAME}
main.cpp
${resource_files}
)

qt_add_qml_module(${PROJECT_NAME}
URI "MFloat_Example"
VERSION 1.0
QML_FILES Main.qml
RESOURCES ${resource_files}
RESOURCE_PREFIX "/"
find_library(MY_LIBRARY
NAMES mylibrary
PATHS ${MY_LIBRARY_PATH}
)

set_target_properties(${PROJECT_NAME} 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
)

target_link_libraries(${PROJECT_NAME} PRIVATE
target_link_libraries(${BIN_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Quick
mfloatui
)
)
44 changes: 24 additions & 20 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ cmake_minimum_required(VERSION 3.20)

project(mfloatui VERSION 1.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick Qml)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core Quick Qml)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick Qml)

qt_standard_project_setup()
set(PLUGIN_OUTPUT_DIR ${PROJECT_BINARY_DIR}/plugins/)
set(LIB_NAME mfloatui)
set(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE STRING "Library install path")
set(QML_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/qt${QT_VERSION_MAJOR}/qml" CACHE STRING "Qml plugin install directory")

# 遍历所有头文件
file(GLOB_RECURSE HEAD_PATHS *.h)
foreach(filepath ${HEAD_PATHS})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
list(APPEND head_files ${filename})
endforeach(filepath)

# 遍历所有源文件
file(GLOB_RECURSE SRC_PATHS *.cpp *.hpp)
Expand Down Expand Up @@ -38,31 +45,28 @@ foreach(filepath IN LISTS qml_files res_files)
set_source_files_properties(${filepath} PROPERTIES QT_RESOURCE_ALIAS ${filename})
endforeach()

set(QT_SDK_DIR "${Qt${QT_VERSION_MAJOR}_DIR}")
cmake_path(GET QT_SDK_DIR PARENT_PATH QT_SDK_DIR)
cmake_path(GET QT_SDK_DIR PARENT_PATH QT_SDK_DIR)
cmake_path(GET QT_SDK_DIR PARENT_PATH QT_SDK_DIR)

# 设置qml模块输出目录
set(MFLOAT_QML_PLUGIN_DIRECTORY ${QT_SDK_DIR}/qml/MFloat)

qt_add_library(${PROJECT_NAME} SHARED)
qt_add_qml_module(${PROJECT_NAME}
qt_add_qml_module( ${LIB_NAME}
PLUGIN_TARGET "mfloatuipugin"
OUTPUT_DIRECTORY ${MFLOAT_QML_PLUGIN_DIRECTORY}
VERSION 1.0
URI "MFloat"
SHARED
TYPEINFO "plugins.qmltypes"
SOURCES ${src_files}
SOURCES ${src_files} ${head_files}
QML_FILES ${qml_files}
RESOURCES ${res_files}
RESOURCE_PREFIX "/qt/qml"
OUTPUT_DIRECTORY "${PLUGIN_OUTPUT_DIR}/MFloat"
)

target_link_libraries(${PROJECT_NAME} PUBLIC
target_link_libraries(${LIB_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::CorePrivate
Qt${QT_VERSION_MAJOR}::QuickPrivate
Qt${QT_VERSION_MAJOR}::QmlPrivate
)
#安装
install(DIRECTORY ${MFLOAT_QML_PLUGIN_DIRECTORY} DESTINATION ${CMAKE_INSTALL_PREFIX}/imports)

# Install library
install(TARGETS ${LIB_NAME} DESTINATION "${LIB_INSTALL_DIR}")

# Install plugin
install(TARGETS ${PLUGIN_NAME} DESTINATION "${QML_INSTALL_DIR}")
install(DIRECTORY "${PLUGIN_OUTPUT_DIR}/MFloat" DESTINATION "${QML_INSTALL_DIR}")

0 comments on commit 001d981

Please sign in to comment.