generated from LizardByte/template-base
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7ba048
commit 4626492
Showing
13 changed files
with
468 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
--- | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
types: | ||
- opened | ||
- synchronize | ||
- reopened | ||
push: | ||
branches: | ||
- master | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build_win: | ||
name: Windows | ||
runs-on: windows-2019 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Prepare tests | ||
id: prepare-tests | ||
run: | | ||
# function to download and extract a zip file | ||
function DownloadAndExtract { | ||
param ( | ||
[string]$Uri, | ||
[string]$OutFile | ||
) | ||
$maxRetries = 5 | ||
$retryCount = 0 | ||
$success = $false | ||
while (-not $success -and $retryCount -lt $maxRetries) { | ||
$retryCount++ | ||
Write-Host "Downloading $Uri to $OutFile, attempt $retryCount of $maxRetries" | ||
try { | ||
Invoke-WebRequest -Uri $Uri -OutFile $OutFile | ||
$success = $true | ||
} catch { | ||
Write-Host "Attempt $retryCount of $maxRetries failed with error: $($_.Exception.Message). Retrying..." | ||
Start-Sleep -Seconds 5 | ||
} | ||
} | ||
if (-not $success) { | ||
Write-Host "Failed to download the file after $maxRetries attempts." | ||
exit 1 | ||
} | ||
# use .NET to get the base name of the file | ||
$baseName = (Get-Item $OutFile).BaseName | ||
# Extract the zip file | ||
Expand-Archive -Path $OutFile -DestinationPath $baseName | ||
} | ||
# virtual display driver | ||
DownloadAndExtract ` | ||
-Uri "https://www.amyuni.com/downloads/usbmmidd_v2.zip" ` | ||
-OutFile "usbmmidd_v2.zip" | ||
# install | ||
Set-Location -Path usbmmidd_v2/usbmmidd_v2 | ||
./deviceinstaller64 install usbmmidd.inf usbmmidd | ||
# create up to 4 virtual displays | ||
for ($i = 1; $i -le 4; $i++) { | ||
./deviceinstaller64 enableidd 1 | ||
} | ||
- name: Setup python | ||
id: setup-python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Python Path | ||
id: python-path | ||
shell: msys2 {0} | ||
run: | | ||
# replace backslashes with double backslashes | ||
python_path=$(echo "${{ steps.setup-python.outputs.python-path }}" | sed 's/\\/\\\\/g') | ||
# step output | ||
echo "python-path=${python_path}" | ||
echo "python-path=${python_path}" >> $GITHUB_OUTPUT | ||
- name: Setup Dependencies Windows | ||
uses: msys2/setup-msys2@v2 | ||
with: | ||
update: true | ||
install: >- | ||
base-devel | ||
make | ||
mingw-w64-x86_64-binutils | ||
mingw-w64-x86_64-cmake | ||
mingw-w64-x86_64-toolchain | ||
- name: Build Windows | ||
shell: msys2 {0} | ||
run: | | ||
mkdir build | ||
cd build | ||
cmake \ | ||
-G "MinGW Makefiles" \ | ||
.. | ||
mingw32-make -j$(nproc) | ||
- name: Run tests | ||
id: test | ||
shell: msys2 {0} | ||
working-directory: build/tests | ||
run: | | ||
./test_libdisplaydevice.exe --gtest_color=yes | ||
- name: Generate gcov report | ||
# any except canceled or skipped | ||
if: always() && (steps.test.outcome == 'success' || steps.test.outcome == 'failure') | ||
id: test_report | ||
shell: msys2 {0} | ||
working-directory: build | ||
run: | | ||
${{ steps.python-path.outputs.python-path }} -m pip install gcovr | ||
${{ steps.python-path.outputs.python-path }} -m gcovr -r .. \ | ||
--exclude ../tests/ \ | ||
--exclude ../third-party/ \ | ||
--xml-pretty \ | ||
-o coverage.xml | ||
- name: Upload coverage | ||
# any except canceled or skipped | ||
if: always() && (steps.test_report.outcome == 'success') | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
fail_ci_if_error: true | ||
files: ./build/coverage.xml | ||
flags: ${{ runner.os }} | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Prerequisites | ||
*.d | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Fortran module files | ||
*.mod | ||
*.smod | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
|
||
# JetBrains IDE | ||
.idea/ | ||
|
||
# build directories | ||
build/ | ||
cmake-*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[submodule "third-party/googletest"] | ||
path = third-party/googletest | ||
url = https://github.com/google/googletest.git | ||
branch = v1.14.x | ||
[submodule "third-party/json"] | ||
path = third-party/json | ||
url = https://github.com/nlohmann/json.git | ||
branch = master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
cmake_minimum_required(VERSION 3.13) # todo: what is the minimum version required? | ||
|
||
project(libdisplaydevice | ||
DESCRIPTION "Library to modify display devices." | ||
HOMEPAGE_URL "https://app.lizardbyte.dev") | ||
|
||
set(PROJECT_LICENSE "GPL-3.0") | ||
|
||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) | ||
message(STATUS "Setting build type to 'Release' as none was specified.") | ||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE) | ||
endif() | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
# set the module path, used for includes | ||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") | ||
|
||
# options | ||
option(BUILD_TESTS "Build tests" ON) | ||
|
||
# if windows | ||
if(WIN32) | ||
include(${CMAKE_MODULE_PATH}/windows.cmake) | ||
elseif(APPLE) | ||
message(FATAL_ERROR "MacOS is not supported yet.") | ||
# include(${CMAKE_MODULE_PATH}/macos.cmake) | ||
else() | ||
message(FATAL_ERROR "Linux is not supported yet.") | ||
# include(${CMAKE_MODULE_PATH}/linux.cmake) | ||
endif() | ||
|
||
# glob src | ||
file(GLOB_RECURSE SRC_FILES src/*.cpp) | ||
|
||
# tests | ||
if(BUILD_TESTS) | ||
add_subdirectory(tests) | ||
endif() | ||
|
||
# lib | ||
add_library(${PROJECT_NAME} ${SRC_FILES}) | ||
target_include_directories(${PROJECT_NAME} PUBLIC include) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @file main.cpp | ||
*/ | ||
|
||
#include <iostream> | ||
|
||
int main() { | ||
std::cout << "Hello, World!" << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
# https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md#foundational-c-support | ||
|
||
project(test_libdisplaydevice) | ||
|
||
include_directories("${CMAKE_SOURCE_DIR}") | ||
|
||
enable_testing() | ||
|
||
# Add GoogleTest directory to the project | ||
set(GTEST_SOURCE_DIR "${CMAKE_SOURCE_DIR}/third-party/googletest") | ||
set(INSTALL_GTEST OFF) | ||
set(INSTALL_GMOCK OFF) | ||
add_subdirectory("${GTEST_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/googletest") | ||
include_directories("${GTEST_SOURCE_DIR}/googletest/include" "${GTEST_SOURCE_DIR}") | ||
|
||
# coverage | ||
# https://gcovr.com/en/stable/guide/compiling.html#compiler-options | ||
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage -O1") | ||
set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage -O1") | ||
|
||
# if windows | ||
if (WIN32) | ||
# For Windows: Prevent overriding the parent project's compiler/linker settings | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # cmake-lint: disable=C0103 | ||
endif () | ||
|
||
file(GLOB_RECURSE TEST_SOURCES | ||
${CMAKE_SOURCE_DIR}/tests/conftest.cpp | ||
${CMAKE_SOURCE_DIR}/tests/utils.cpp | ||
${CMAKE_SOURCE_DIR}/tests/test_*.cpp) | ||
|
||
set(DD_SOURCES | ||
${DD_FILES}) | ||
|
||
# remove main.cpp from the list of sources | ||
list(REMOVE_ITEM DD_SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp) | ||
|
||
add_executable(${PROJECT_NAME} | ||
${TEST_SOURCES} | ||
${DISPLAY_DEVICE_SOURCES}) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17) | ||
target_link_libraries(${PROJECT_NAME} | ||
${DD_EXTERNAL_LIBRARIES} | ||
gtest | ||
gtest_main # if we use this we don't need our own main function | ||
${PLATFORM_LIBRARIES}) | ||
target_compile_definitions(${PROJECT_NAME} PUBLIC ${DD_DEFINITIONS} ${TEST_DEFINITIONS}) | ||
target_compile_options(${PROJECT_NAME} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${DD_COMPILE_OPTIONS}> -std=c++17) | ||
target_link_options(${PROJECT_NAME} PRIVATE) | ||
|
||
add_test(NAME ${PROJECT_NAME} COMMAND libdisplaydevice_test) |
Oops, something went wrong.