Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiao YaoBing committed Nov 11, 2023
1 parent f89ce00 commit 5edc0b2
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/archlinux-build.yaml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
@@ -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++ .
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions doc/Doxyfile.in
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(imagewallpaperexample)
35 changes: 35 additions & 0 deletions examples/imagewallpaperexample/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)
12 changes: 12 additions & 0 deletions examples/imagewallpaperexample/Main.qml
Original file line number Diff line number Diff line change
@@ -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")
}
23 changes: 23 additions & 0 deletions examples/imagewallpaperexample/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>

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();
}
94 changes: 94 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 <build_dir> --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 $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>: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/
)
2 changes: 2 additions & 0 deletions src/qmldir
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module com.wsm.declarative
plugin declarative
3 changes: 3 additions & 0 deletions src/wallpaperglobal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "wallpaperglobal.h"

Q_LOGGING_CATEGORY(LYCHEE_WALLPAPER, "org.lychee.wallpaper", QtInfoMsg)
15 changes: 15 additions & 0 deletions src/wallpaperglobal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef WALLPAPERGLOBAL_H
#define WALLPAPERGLOBAL_H

#include <QtGlobal>
#include <QLoggingCategory>

#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

0 comments on commit 5edc0b2

Please sign in to comment.