Skip to content

Commit

Permalink
feat: reorg entire project
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenvukhang committed Feb 17, 2023
1 parent c1da458 commit f1756e3
Show file tree
Hide file tree
Showing 76 changed files with 3,298 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BreakBeforeBraces: Linux
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: WithoutElse
128 changes: 128 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: ci

on:
push:
branches:
- main
- dev
- ci
tags:
- "v[0-9]+.[0-9]+.[0-9]+**"

permissions:
contents: write

env:
QT_STATIC_DIR: Qt/static

# Standard format of uploaded asset:
# CanvasSync-${{ github.ref_name }}-${{ matrix.os }}.{app,exe,deb}

jobs:
mac:
strategy:
fail-fast: false
matrix:
version: [6.2.4]
os: [macos-11, macos-12]
runs-on: ${{ matrix.os }}
steps:
- name: Set environment variables
run: |
echo "ASSET=Canvas-Sync-${{ github.ref_name }}-${{ matrix.os }}.dmg" >>$GITHUB_ENV
echo "QT_STATIC_DIR=$PWD/${{ env.QT_STATIC_DIR }}" >>$GITHUB_ENV
- uses: actions/checkout@v3

- name: download pre-build static Qt libraries
run: |
curl -fLo qt.tar.gz https://github.com/nguyenvukhang/qt-static/releases/download/v0.0.18/qt-${{ matrix.version }}-${{ matrix.os }}.tar.gz
mkdir -p ${{ env.QT_STATIC_DIR }}
tar -xvzf qt.tar.gz && mv qt_output/* ${{ env.QT_STATIC_DIR }}
# build canvas-sync
- run: make build

# package app
- run: |
mkdir dmg
cp -a 'build/Canvas Sync.app' 'dmg/Canvas Sync.app'
mv ./deploy/mac-readme.txt dmg/README.txt
ln -s /Applications dmg/Applications
hdiutil create -volname CanvasSync \
-srcfolder dmg \
-fs HFS+ -ov -format UDBZ \
${{ env.ASSET }}
# upload release package
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }}
files: ${{ env.ASSET }}
generate_release_notes: true

win:
strategy:
fail-fast: false
matrix:
version: [6.2.4]
os: [windows-2019, windows-2022]
runs-on: ${{ matrix.os }}
steps:
- name: Set environment variables
shell: bash
run: |
echo "ASSET=Canvas-Sync-Installer-${{ github.ref_name }}.exe" >>$GITHUB_ENV
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
arch: win64_msvc2019_64
version: ${{ matrix.version }}
setup-python: false
tools: tools_ifw
archives: qtbase qttools

- name: Install MSVC 2022
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64

- name: Install build dependencies
shell: bash
run: cinst -y ninja

- uses: actions/checkout@v3

- name: Build
run: |
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build -G Ninja `
-DCMAKE_PREFIX_PATH=${{ env.Qt6_DIR }}
cmake --build build --parallel
- name: Use windeployqt to load libraries
shell: bash
run: |
TARGET=deploy/windows/packages/com.nguyenvukhang.canvassync/data
mv 'build/Canvas Sync.exe' $TARGET
cd $TARGET
$Qt6_DIR/bin/windeployqt.exe 'Canvas Sync.exe'
- name: Package the installer
shell: bash
run: |
cd deploy/windows
$IQTA_TOOLS/QtInstallerFramework/4.5/bin/binarycreator.exe \
-c config/config.xml -p packages ${{ env.ASSET }}
mv ${{ env.ASSET }} ../..
# upload release package
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/') && matrix.os == 'windows-2019'
with:
prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }}
files: ${{ env.ASSET }}
generate_release_notes: true
80 changes: 80 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------

*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
/.qmake.cache
/.qmake.stash

# qtcreator generated files
*.pro.user*
CMakeLists.txt.user*

# xemacs temporary files
*.flc

# Vim temporary files
.*.swp

# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*

# MinGW generated files
*.Debug
*.Release

# Python byte code
*.pyc

# Binaries
# --------
*.dll
*.exe

# additional stuff
.cache
.env

/compile_commands.json
build/
build.*/
/Qt
68 changes: 68 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
cmake_minimum_required(VERSION 3.5)

project(cs2 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)

# additional flags set for canvas-sync development
set(CMAKE_EXPORT_COMPILE_COMMANDS 1) # to build compile_commands.json
# note that CMAKE_PREFIX_PATH must contain a Qt directory. Meaning that
# if you `ls` on this directory then stuff like bin/ and include/ shows

if (EXISTS ${QT_STATIC_DIR})
set(CMAKE_PREFIX_PATH ${QT_STATIC_DIR})
endif()

add_subdirectory(lib)
add_subdirectory(ui)

find_package(Qt6 REQUIRED COMPONENTS Core Widgets Network)

set(PROJECT_SOURCES
main.cc
app.cc
app.h
app.ui
assets.qrc
)

if(WIN32)
set(APP_ICON_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/appicon.rc")
set(PROJECT_SOURCES ${PROJECT_SOURCES} ${APP_ICON_WINDOWS})
elseif(APPLE)
set(APP_ICON_MACOS "${CMAKE_CURRENT_SOURCE_DIR}/assets/app-icon/canvas-sync.icns")
set_source_files_properties(${APP_ICON_MACOS} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
set(PROJECT_SOURCES ${PROJECT_SOURCES} ${APP_ICON_MACOS})
endif()

qt_add_executable(cs2 MANUAL_FINALIZATION ${PROJECT_SOURCES})

target_link_libraries(cs2 PRIVATE
Qt6::Core
Qt6::Widgets
Qt6::Network
cs2lib
csui
)

set_target_properties(cs2 PROPERTIES
OUTPUT_NAME "Canvas Sync"
MACOSX_BUNDLE_GUI_IDENTIFIER canvassync.nguyenvukhang.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE_ICON_FILE canvas-sync.icns
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)

install(TARGETS cs2
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

qt_finalize_executable(cs2)
67 changes: 67 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))

# QT_STATIC_DIR ?= $(MAKEFILE_DIR)/Qt/static
QT_STATIC_DIR ?= $(HOME)/Qt/6.2.4/macos
QT_SRC_DIR ?= $(MAKEFILE_DIR)/Qt/src

QT_CFG_ARGS := -opensource -release -static -nomake examples -nomake tests -skip qt3d -skip qttranslations -skip qt5compat -skip qtactiveqt -skip qtcharts -skip qtcoap -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qthttpserver -skip qtlanguageserver -skip qtlottie -skip qtmqtt -skip qtmultimedia -skip qtnetworkauth -skip qtopcua -skip qtpositioning -skip qtquick3d -skip qtquick3dphysics -skip qtquicktimeline -skip qtremoteobjects -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtshadertools -skip qtspeech -skip qtsvg -skip qttools -skip qtwebsockets
QT_INIT_ARGS := --module-subset=qtbase
QT_VERSION ?= 6.2.4

# current: FORCE
# make main
# make test

main:
@make --no-print-directory build
mv ./build/compile_commands.json .

app: FORCE
cd app && cmake -DBUILD_TESTS=ON -DQT_STATIC_DIR=$(QT_STATIC_DIR) -DCMAKE_BUILD_TYPE=Release \
-S . -B build
cd app && cmake --build build --parallel # alternatively: cd build && make

test: FORCE
$(MAKEFILE_DIR)/build/test/CanvasSyncTest

build: FORCE
@echo "-- USING QT_STATIC_DIR: $(QT_STATIC_DIR)"
cmake -DQT_STATIC_DIR=$(QT_STATIC_DIR) -DCMAKE_BUILD_TYPE=Release \
-S . -B build
cmake --build build --parallel # alternatively: cd build && make

build-win: FORCE
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build -G Ninja
cmake --build build

qt-setup:
make clone-qt
make init-qt

clone-qt:
git clone https://code.qt.io/qt/qt5.git -b v$(QT_VERSION) $(QT_SRC_DIR)

init-qt:
cd $(QT_SRC_DIR) && perl init-repository $(QT_INIT_ARGS)

config-qt:
cd $(QT_SRC_DIR) && ./configure -prefix $(QT_STATIC_DIR) $(QT_CFG_ARGS)

clean-qt:
cd $(QT_SRC_DIR) && ninja clean

build-qt:
cd $(QT_SRC_DIR) && ninja -j6 && ninja install

open:
open 'build/Canvas Sync.app'

reset:
rm -rf ~/files/test/*/*

clean:
rm -rf $(MAKEFILE_DIR)/.cache
rm -rf $(MAKEFILE_DIR)/build

FORCE: ;
Loading

0 comments on commit f1756e3

Please sign in to comment.