From 5edc0b20077da1ca4e0600c3eab02392c737d9da Mon Sep 17 00:00:00 2001 From: Xiao YaoBing <1109050030@qq.com> Date: Tue, 31 Oct 2023 09:51:36 +0800 Subject: [PATCH] init project --- .github/workflows/archlinux-build.yaml | 59 ++++++++++++ .github/workflows/cppcheck.yml | 18 ++++ CMakeLists.txt | 15 +++ doc/Doxyfile.in | 9 ++ examples/CMakeLists.txt | 1 + examples/imagewallpaperexample/CMakeLists.txt | 35 +++++++ examples/imagewallpaperexample/Main.qml | 12 +++ examples/imagewallpaperexample/main.cpp | 23 +++++ src/CMakeLists.txt | 94 +++++++++++++++++++ src/qmldir | 2 + src/wallpaperglobal.cpp | 3 + src/wallpaperglobal.h | 15 +++ 12 files changed, 286 insertions(+) create mode 100644 .github/workflows/archlinux-build.yaml create mode 100644 .github/workflows/cppcheck.yml create mode 100644 CMakeLists.txt create mode 100644 doc/Doxyfile.in create mode 100644 examples/CMakeLists.txt create mode 100644 examples/imagewallpaperexample/CMakeLists.txt create mode 100644 examples/imagewallpaperexample/Main.qml create mode 100644 examples/imagewallpaperexample/main.cpp create mode 100644 src/CMakeLists.txt create mode 100644 src/qmldir create mode 100644 src/wallpaperglobal.cpp create mode 100644 src/wallpaperglobal.h diff --git a/.github/workflows/archlinux-build.yaml b/.github/workflows/archlinux-build.yaml new file mode 100644 index 0000000..fd852ef --- /dev/null +++ b/.github/workflows/archlinux-build.yaml @@ -0,0 +1,59 @@ +name: Build on archlinux + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + container: + runs-on: ubuntu-latest + container: archlinux:latest + steps: + - name: Run in container + run: | + sed -i /etc/pacman.d/mirrorlist -e "1iServer = https://mirrors.tuna.tsinghua.edu.cn/archlinux/\$repo/os/\$arch" + cat /etc/pacman.d/mirrorlist + pacman-key --init + pacman --noconfirm --noprogressbar -Syu + + - name: Install dep + run: | + pacman -Syu --noconfirm cmake pkgconfig git extra-cmake-modules qt6-base qt6-declarative + pacman -Syu --noconfirm clang ninja zstd doxygen sdl2 mesa assimp wget unzip make gtest + pacman -Syu --noconfirm fakeroot sudo + + - name: Set up user + run: | + useradd -m githubuser + echo -e "root ALL=(ALL:ALL) ALL\ngithubuser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers + + - name: Install KTX-Software from the github + run: | + wget https://github.com/KhronosGroup/KTX-Software/archive/refs/tags/v4.2.0.zip + unzip v4.2.0.zip + cd ./KTX-Software-4.2.0 + mkdir build + cd build + cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -D KTX_FEATURE_LOADTEST_APPS=ON -DKTX_FEATURE_DOC=ON -DKTX_FEATURE_TOOLS=OFF -DKTX_FEATURE_STATIC_LIBRARY=ON .. + make install + + # su githubuser -c "cd ~ && wget https://github.com/KhronosGroup/KTX-Software/archive/refs/tags/v4.2.0.zip && unzip v4.2.0.zip && cd ./KTX-Software-4.2.0 + # && mkdir build && cd ./build && cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -D KTX_FEATURE_LOADTEST_APPS=ON -D KTX_FEATURE_DOC=ON -DKTX_FEATURE_TOOLS=OFF .." + + # - uses: actions/checkout@v3 + # with: + # submodules: true + + # - name: Configure CMake + # run: | + # mkdir -p ${{github.workspace}}/build + # cmake -B ${{github.workspace}}/build -G Ninja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + # - name: Build + # # Build your program with the given configuration + # run: cmake --build ${{github.workspace}}/build \ No newline at end of file diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml new file mode 100644 index 0000000..967fd58 --- /dev/null +++ b/.github/workflows/cppcheck.yml @@ -0,0 +1,18 @@ +name: CppCheck for C++ Project + +on: [push, pull_request] + +jobs: + cppcheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install cppcheck + run: sudo apt-get update && sudo apt-get install -y cppcheck + + - name: Run Cppcheck + if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }} + run: cppcheck --language=c++ . diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e0f33a4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.16) + +project(lychee-wallpaper VERSION 0.1 LANGUAGES CXX) + +SET(CMAKE_AUTOMOC ON) +SET(CMAKE_AUTOUIC ON) +SET(CMAKE_AUTORCC ON) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII) +add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT) + +add_subdirectory(src) +add_subdirectory(examples) diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in new file mode 100644 index 0000000..492e3e1 --- /dev/null +++ b/doc/Doxyfile.in @@ -0,0 +1,9 @@ +PROJECT_NAME = "lychee-wallpaper" +PROJECT_NUMBER = 0.1 +OUTPUT_DIRECTORY = @DOXYGEN_OUTPUT_DIR@ +INPUT = @CMAKE_SOURCE_DIR@/src +RECURSIVE = YES +OUTPUT_LANGUAGE = Chinese +IMAGE_PATH = ../doc/doxygen/images +DOT_PATH = /usr/local/bin +GENERATE TREEVIEW = ALL diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..1921195 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(imagewallpaperexample) diff --git a/examples/imagewallpaperexample/CMakeLists.txt b/examples/imagewallpaperexample/CMakeLists.txt new file mode 100644 index 0000000..4eb885c --- /dev/null +++ b/examples/imagewallpaperexample/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.16) + +project(example VERSION 0.1 LANGUAGES CXX) + +find_package(Qt6 6.4 REQUIRED COMPONENTS Quick) + +qt_standard_project_setup() + +qt_add_executable(imagewallpaperexample + main.cpp +) + +qt_add_qml_module(imagewallpaperexample + URI example + VERSION 1.0 + QML_FILES Main.qml +) + +set_target_properties(imagewallpaperexample 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(imagewallpaperexample + PRIVATE Qt6::Quick +) + +install(TARGETS imagewallpaperexample + BUNDLE DESTINATION . + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/examples/imagewallpaperexample/Main.qml b/examples/imagewallpaperexample/Main.qml new file mode 100644 index 0000000..64814a2 --- /dev/null +++ b/examples/imagewallpaperexample/Main.qml @@ -0,0 +1,12 @@ +import QtQuick +import QtQuick.Window +import QtQuick.Controls +import QtQuick.Layouts +import org.lychee.wallpaper as LYCHEE + +Window { + width: 640 + height: 480 + visible: true + title: qsTr("Hello World") +} diff --git a/examples/imagewallpaperexample/main.cpp b/examples/imagewallpaperexample/main.cpp new file mode 100644 index 0000000..31736b3 --- /dev/null +++ b/examples/imagewallpaperexample/main.cpp @@ -0,0 +1,23 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + QString qmlPath = QGuiApplication::applicationDirPath(); +#ifdef Q_OS_LINUX + qmlPath.replace(QString::fromUtf8("examples/") + QCoreApplication::applicationName(), QString::fromUtf8("")); +#endif + + engine.addImportPath(qmlPath); + + const QUrl url(u"qrc:/example/Main.qml"_qs); + QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, + &app, []() { QCoreApplication::exit(-1); }, + Qt::QueuedConnection); + engine.load(url); + + return app.exec(); +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..7311e5d --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,94 @@ +set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +set(KF_DEP_VERSION "5.240.0") + +find_package(ECM REQUIRED NO_MODULE) +find_package(PkgConfig REQUIRED) +pkg_check_modules(EGL IMPORTED_TARGET egl REQUIRED) +pkg_check_modules(Epoxy IMPORTED_TARGET epoxy REQUIRED) + +find_package(Qt6 6.4 COMPONENTS Quick Core Qml REQUIRED) + +find_package(Doxygen) +if (DOXYGEN_FOUND) + set(DOXYGEN_INPUT ${CMAKE_SOURCE_DIR}/doc/Doxyfile.in) + set(DOXYGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/doc) + configure_file(${DOXYGEN_INPUT} ${CMAKE_BINARY_DIR}/Doxyfile @ONLY) + add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Generating API documentation with Doxygen" VERBATIM) +# Finally, execute "make doc" or "cmake --build --target doc" in the compilation directory to generate Doxygen documentation. +endif () + +set(wallpaper_SRCS + wallpaperglobal.h + wallpaperglobal.cpp +) + +set(control_QMLS +# qml/Switch.qml +) + +#add picture resource +set(image_RSRCS +# image/switch/switch-handle.png +) + +foreach(file IN LISTS control_QMLS image_RSRCS) + get_filename_component(filename ${file} NAME) + set_source_files_properties(${file} PROPERTIES QT_RESOURCE_ALIAS ${filename}) +endforeach() + +qt_add_qml_module(declarative + URI org.lychee.wallpaper + VERSION 1.0 + SOURCES ${wallpaper_SRCS} + QML_FILES ${control_QMLS} + RESOURCES ${image_RSRCS} +) + +set_target_properties(declarative 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_compile_definitions(declarative + PRIVATE $<$,$>:QT_QML_DEBUG>) +target_link_libraries(declarative PRIVATE + Qt6::Quick + Qt6::QuickPrivate + PkgConfig::EGL + PkgConfig::Epoxy + ${KTX_LIBRARIES} +) + +target_include_directories(declarative PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${KTX_INCLUDE_DIRS}) + +# Prevent EGL headers from including platform headers, in particular Xlib.h. +add_definitions(-DMESA_EGL_NO_X11_HEADERS) +add_definitions(-DEGL_NO_X11) +add_definitions(-DEGL_NO_PLATFORM_SPECIFIC_TYPES) + +function(get_qml_install_dir target_var) + get_target_property(QT6_QMAKE_EXECUTABLE Qt6::qmake IMPORTED_LOCATION) + execute_process( + COMMAND ${QT6_QMAKE_EXECUTABLE} -query QT_INSTALL_QML + OUTPUT_VARIABLE QML_INSTALL_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(${target_var} ${QML_INSTALL_DIR} PARENT_SCOPE) +endfunction() + +get_qml_install_dir(QML_INSTALL_DIR) + +install(TARGETS declarative DESTINATION CMAKE_INSTALL_LIBDIR) +install(FILES + qmldir + ${CMAKE_BINARY_DIR}/org/lychee/declarative/libdeclarativeplugin.so + ${CMAKE_BINARY_DIR}/org/lychee/declarative/declarative.qmltypes + DESTINATION ${QML_INSTALL_DIR}/org/lychee/declarative/ +) diff --git a/src/qmldir b/src/qmldir new file mode 100644 index 0000000..8e35b46 --- /dev/null +++ b/src/qmldir @@ -0,0 +1,2 @@ +module com.wsm.declarative +plugin declarative diff --git a/src/wallpaperglobal.cpp b/src/wallpaperglobal.cpp new file mode 100644 index 0000000..856504f --- /dev/null +++ b/src/wallpaperglobal.cpp @@ -0,0 +1,3 @@ +#include "wallpaperglobal.h" + +Q_LOGGING_CATEGORY(LYCHEE_WALLPAPER, "org.lychee.wallpaper", QtInfoMsg) diff --git a/src/wallpaperglobal.h b/src/wallpaperglobal.h new file mode 100644 index 0000000..51d0c2b --- /dev/null +++ b/src/wallpaperglobal.h @@ -0,0 +1,15 @@ +#ifndef WALLPAPERGLOBAL_H +#define WALLPAPERGLOBAL_H + +#include +#include + +#if defined(LYCHEE_WALLPAPER) +#define LYCHEE_WALLPAPER_EXPORT Q_DECL_EXPORT +#else +#define LYCHEE_WALLPAPER_EXPORT Q_DECL_IMPORT +#endif + +Q_DECLARE_LOGGING_CATEGORY(LYCHEE_WALLPAPER) + +#endif // WALLPAPERGLOBAL_H