Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to create a proper CMake target. #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: LLVM
IndentWidth: 2
---
Language: Cpp
DeriveLineEnding: false
UseCRLF: true
DerivePointerAlignment: false
PointerAlignment: Left
AlignConsecutiveAssignments: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Empty
AlwaysBreakTemplateDeclarations: Yes
AccessModifierOffset: -2
AlignTrailingComments: true
SpacesBeforeTrailingComments: 2
NamespaceIndentation: Inner
MaxEmptyLinesToKeep: 1
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: true
ColumnLimit: 88
ForEachMacros: ['Q_FOREACH', 'foreach']
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.cpp text eol=crlf
*.h text eol=crlf
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build Github++

on:
push:
branches: master
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
runs-on: windows-2022
steps:
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: 6.7.0
modules:
cache: true

- uses: actions/checkout@v4

- name: Configure Github++ build
shell: pwsh
run: |
cmake --preset vs2022-windows `
"-DCMAKE_PREFIX_PATH=${env:QT_ROOT_DIR}\msvc2019_64" `
"-DCMAKE_INSTALL_PREFIX=install"

- name: Build Github++
run: cmake --build vsbuild --config RelWithDebInfo

- name: Install Github++
run: cmake --install vsbuild --config RelWithDebInfo

- name: Upload Github++ artifact
uses: actions/upload-artifact@master
with:
name: githubpp
path: ./install
16 changes: 16 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint Github++

on:
push:
pull_request:
types: [opened, synchronize, reopened]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check format
uses: ModOrganizer2/check-formatting-action@master
with:
check-path: "."
27 changes: 22 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
cmake_minimum_required(VERSION 3.16)

if(DEFINED DEPENDENCIES_DIR)
include(${DEPENDENCIES_DIR}/modorganizer_super/cmake_common/mo2.cmake)
else()
include(${CMAKE_CURRENT_LIST_DIR}/../cmake_common/mo2.cmake)
endif()
include(CMakePackageConfigHelpers)

project(githubpp)

add_subdirectory(src)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/mo2-githubpp-config.cmake"
INSTALL_DESTINATION "lib/cmake/mo2-githubpp"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/mo2-githubpp-config-version.cmake"
VERSION "0.0.1"
COMPATIBILITY AnyNewerVersion
ARCH_INDEPENDENT
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/mo2-githubpp-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/mo2-githubpp-config-version.cmake
DESTINATION lib/cmake/mo2-githubpp
)
36 changes: 36 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"configurePresets": [
{
"errors": {
"deprecated": true
},
"hidden": true,
"name": "cmake-dev",
"warnings": {
"deprecated": true,
"dev": true
}
},
{
"binaryDir": "${sourceDir}/vsbuild",
"architecture": {
"strategy": "set",
"value": "x64"
},
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/EHsc /MP /W4"
},
"generator": "Visual Studio 17 2022",
"inherits": ["cmake-dev"],
"name": "vs2022-windows",
"toolset": "v143"
}
],
"buildPresets": [
{
"name": "vs2022-windows",
"configurePreset": "vs2022-windows"
}
],
"version": 4
}
3 changes: 3 additions & 0 deletions cmake/config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include ( "${CMAKE_CURRENT_LIST_DIR}/mo2-githubpp-targets.cmake" )
63 changes: 31 additions & 32 deletions src/github.h → include/githubpp/github.h
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
#pragma once

#include <QNetworkAccessManager>
#include <QNetworkCookieJar>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QTimer>
#include <QNetworkAccessManager>
#include <QNetworkCookieJar>
#include <QNetworkReply>
#include <QTimer>
#include <functional>

class GitHubException : public std::exception
{
public:
GitHubException(const QJsonObject &errorObj)
: std::exception()
GitHubException(const QJsonObject& errorObj) : std::exception()
{
initMessage(errorObj);
}

virtual ~GitHubException() throw() override {}

virtual const char *what() const throw()
{
return m_Message.constData();
}
virtual const char* what() const throw() { return m_Message.constData(); }

private:
void initMessage(const QJsonObject &obj)
void initMessage(const QJsonObject& obj)
{
if (obj.contains("http_status")) {
m_Message = QString("HTTP Status %1: %2")
Expand Down Expand Up @@ -55,48 +51,51 @@ class GitHub : public QObject
Q_OBJECT

public:
enum class Method { GET, POST };
enum class Method
{
GET,
POST
};

struct Repository {
Repository(const QString &owner, const QString &project)
: owner(owner)
, project(project)
{
}
struct Repository
{
Repository(const QString& owner, const QString& project)
: owner(owner), project(project)
{}
QString owner;
QString project;
};

public:
GitHub(const char *clientId = nullptr);
GitHub(const char* clientId = nullptr);
~GitHub();

QJsonArray releases(const Repository &repo);
void releases(const Repository &repo,
const std::function<void (const QJsonArray &)> &callback);
QJsonArray releases(const Repository& repo);
void releases(const Repository& repo,
const std::function<void(const QJsonArray&)>& callback);

private:
QJsonDocument request(Method method, const QString &path,
const QByteArray &data, bool relative);
void request(Method method, const QString &path, const QByteArray &data,
const std::function<void (const QJsonDocument &)> &callback,
QJsonDocument request(Method method, const QString& path, const QByteArray& data,
bool relative);
void request(Method method, const QString& path, const QByteArray& data,
const std::function<void(const QJsonDocument&)>& callback,
bool relative);

QJsonDocument handleReply(QNetworkReply *reply);
QNetworkReply *genReply(Method method, const QString &path,
const QByteArray &data, bool relative);
QJsonDocument handleReply(QNetworkReply* reply);
QNetworkReply* genReply(Method method, const QString& path, const QByteArray& data,
bool relative);

private:
struct Request
{
Method method = Method::GET;
QByteArray data;
std::function<void (const QJsonDocument &)> callback;
QTimer* timer = nullptr;
std::function<void(const QJsonDocument&)> callback;
QTimer* timer = nullptr;
QNetworkReply* reply = nullptr;
};

QNetworkAccessManager *m_AccessManager;
QNetworkAccessManager* m_AccessManager;

// remember the replies that are in flight and delete them in the destructor
std::vector<QNetworkReply*> m_replies;
Expand Down
51 changes: 47 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,51 @@
cmake_minimum_required(VERSION 3.16)

find_package(Qt6 CONFIG REQUIRED COMPONENTS Network)

add_library(githubpp STATIC)
mo2_configure_library(githubpp
WARNINGS OFF

target_sources(githubpp
PRIVATE
github.cpp
PUBLIC
FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_LIST_DIR}/../include
FILES ${CMAKE_CURRENT_LIST_DIR}/../include/githubpp/github.h
)

target_link_libraries(githubpp PRIVATE Qt::Core Qt::Network)
set_target_properties(githubpp
PROPERTIES
AUTOMOC ON
PRIVATE_DEPENDS Qt::Core Qt::Network)
mo2_install_target(githubpp)
CXX_STANDARD 20
)
target_include_directories(githubpp PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../include/githubpp)

if (MSVC)
target_compile_options(githubpp
PRIVATE
"/MP"
"/Wall"
"/external:anglebrackets"
"/external:W0"
)
target_link_options(githubpp
PRIVATE
$<$<CONFIG:RelWithDebInfo>:/LTCG /INCREMENTAL:NO /OPT:REF /OPT:ICF>
)

set_target_properties(githubpp PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin
VS_DEBUGGER_COMMAND ${CMAKE_INSTALL_PREFIX}/bin/ModOrganizer.exe
VS_STARTUP_PROJECT githubpp)
endif()

add_library(mo2::githubpp ALIAS githubpp)

# installation
install(TARGETS githubpp EXPORT githubppTargets FILE_SET HEADERS)
install(EXPORT githubppTargets
FILE mo2-githubpp-targets.cmake
NAMESPACE mo2::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mo2-githubpp
)
Loading
Loading