Skip to content

Commit

Permalink
improve: add github actions workflow and rework cmakelists
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Mar 28, 2023
1 parent f3bb2f3 commit b7611dd
Show file tree
Hide file tree
Showing 13 changed files with 554 additions and 261 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/analysis-sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
name: Analysis - SonarCloud

on:
pull_request_target:
types: [opened, synchronize, reopened]
push:
branches:
- main

env:
VCPKG_BUILD_TYPE: release
CMAKE_BUILD_PARALLEL_LEVEL: 2
MAKEFLAGS: '-j 2'
NUMBER_OF_PROCESSORS: 2

jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
with:
fetch-depth: 0
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}

- uses: actions/checkout@v3
if: ${{ github.event_name == 'push' }}
with:
fetch-depth: 0

- name: Install Linux Dependencies
run: >
sudo apt-get update && sudo apt-get install ccache linux-headers-$(uname -r)
- name: Switch to gcc-11
run: |
sudo apt install gcc-11 g++-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
sudo update-alternatives --set gcc /usr/bin/gcc-11
- name: CCache
id: ccache
uses: actions/cache@main
with:
path: $HOME/.ccache
key: ccache-${{ runner.os }}-${{ hashFiles('**/src') }}
restore-keys: |
ccache-${{ runner.os}}-
- name: Cache SonarCloud packages
uses: actions/cache@main
with:
path: $HOME/.sonar/cache
key: sonar-${{ runner.os}}-${{ hashFiles('**/src') }}
restore-keys: |
sonar-${{ runner.os}}-
- name: Restore artifacts and install vcpkg
id: vcpkg-step
run: |
vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ')
echo "vcpkg commit ID: $vcpkgCommitId"
echo "::set-output name=vcpkgGitCommitId::$vcpkgCommitId"
- name: Get vcpkg commit id from vcpkg.json
uses: lukka/run-vcpkg@main
with:
vcpkgGitURL: "https://github.com/microsoft/vcpkg.git"
vcpkgGitCommitId: ${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }}

- name: Install sonar-scanner
uses: SonarSource/sonarcloud-github-c-cpp@v1

- name: Generate compilation database
run: |
mkdir -p build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DOPTIONS_ENABLE_CCACHE=ON -S . -B build
- name: Run PR sonar-scanner
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner \
--define sonar.cfamily.compile-commands=build/compile_commands.json \
--define sonar.pullrequest.key=${{ github.event.pull_request.number }} \
--define sonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} \
--define sonar.pullrequest.base=${{ github.event.pull_request.base_ref }}
- name: Run sonar-scanner
if: ${{ github.event_name == 'push' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner \
--define sonar.cfamily.compile-commands=build/compile_commands.json
84 changes: 84 additions & 0 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
name: Build - Ubuntu

on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
push:
branches:
- main

env:
CMAKE_BUILD_PARALLEL_LEVEL: 2
MAKEFLAGS: '-j 2'

jobs:
job:
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
name: ${{ matrix.os }}-${{ matrix.buildtype }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
buildtype: [Release, Debug]
include:
- os: ubuntu-22.04
triplet: x64-linux

steps:
- name: Checkout repository
uses: actions/checkout@main

- name: Install Linux Dependencies
run: >
sudo apt-get update && sudo apt-get install ccache linux-headers-$(uname -r)
- name: Switch to gcc-11
run: |
sudo apt install gcc-11 g++-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
sudo update-alternatives --set gcc /usr/bin/gcc-11
- name: CCache
uses: hendrikmuhs/ccache-action@main
with:
max-size: "1G"
key: ccache-${{ matrix.os }}-${{ matrix.buildtype }}
restore-keys: |
ccache-${{ matrix.os }}
- name: Restore artifacts and install vcpkg
id: vcpkg-step
run: |
vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ')
echo "vcpkg commit ID: $vcpkgCommitId"
echo "::set-output name=vcpkgGitCommitId::$vcpkgCommitId"
- name: Get vcpkg commit id from vcpkg.json
uses: lukka/run-vcpkg@main
with:
vcpkgGitURL: "https://github.com/microsoft/vcpkg.git"
vcpkgGitCommitId: ${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }}

- name: Get latest CMake and ninja
uses: lukka/get-cmake@main

- name: Install additional libraries
run: sudo apt-get install libasio-dev nlohmann-json3-dev libfmt-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev mesa-common-dev libxrandr-dev libxxf86vm-dev libglib2.0-dev at-spi2-core libwxgtk3.0-gtk3-dev libarchive-dev freeglut3-dev libxmu-dev libdbus-1-dev libxtst-dev

- name: Run CMake Cache and Build
uses: lukka/run-cmake@v3
with:
cmakeListsTxtPath: ${{ github.workspace }}/CMakeLists.txt
useVcpkgToolchainFile: true
buildDirectory: ${{ github.workspace }}/build/
cmakeBuildType: ${{ matrix.buildtype }}

- name: Create and Upload Artifact
uses: actions/upload-artifact@main
with:
name: remeres-map-editor-${{ matrix.os }}-${{ matrix.buildtype }}-${{ github.sha }}
path: |
${{ github.workspace }}/build/bin/
49 changes: 49 additions & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: Build - Windows

on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
push:
branches:
- main
- master

jobs:
job:
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
name: ${{ matrix.os }}-${{ matrix.buildtype }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-2022]
buildtype: [Release, Debug]
include:
- os: windows-2022
triplet: x64-windows
packages: >
sccache
steps:
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.1

- name: Checkout repository
uses: actions/checkout@v2

- name: Install vcpkg
run: |
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat
./vcpkg integrate install
- name: Build project
run: msbuild.exe /p:VcpkgEnableManifest=true /p:Configuration=Release /p:Platform=x64 /p:VcpkgRoot=$env:GITHUB_WORKSPACE/vcpkg vcproj/RME.sln

- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.os }}-${{ matrix.buildtype }}
path: |
${{ github.workspace }}/vcproj/x64/${{ matrix.buildtype }}/
138 changes: 91 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,52 +1,96 @@
cmake_minimum_required(VERSION 3.1)

project(rme)
project(cmake)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
# *****************************************************************************
# Vcpkg Configs
# *****************************************************************************

if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
endif()

if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
endif()

set(VCPKG_FEATURE_FLAGS "versions")
set(VCPKG_BUILD_TYPE "release")

# *****************************************************************************
# Set Configs
# *****************************************************************************

set(CMAKE_CXX_STANDARD 20)
set(GNUCXX_MINIMUM_VERSION 11)
set(MSVC_MINIMUM_VERSION "19.32")
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# *****************************************************************************
# Options
# *****************************************************************************
option(OPTIONS_ENABLE_CCACHE "Enable ccache" OFF)
option(OPTIONS_ENABLE_SCCACHE "Use sccache to speed up compilation process" OFF)

# *****************************************************************************
# Set Sanity Check
# *****************************************************************************

# === GCC Minimum Version ===
if (CMAKE_COMPILER_IS_GNUCXX)
message("-- Compiler: GCC - Version: ${CMAKE_CXX_COMPILER_VERSION}")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS GNUCXX_MINIMUM_VERSION)
message(FATAL_ERROR "GCC version must be at least ${GNUCXX_MINIMUM_VERSION}!")
endif()
endif()

# === Minimum required version for visual studio ===
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message("-- Compiler: Visual Studio - Version: ${CMAKE_CXX_COMPILER_VERSION}")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS MSVC_MINIMUM_VERSION)
message(FATAL_ERROR "Visual Studio version must be at least ${MSVC_MINIMUM_VERSION}")
endif()
endif()

# *****************************************************************************
# Append cmake search path
# *****************************************************************************
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# *****************************************************************************
# Include cmake tools
# *****************************************************************************
include(MessageColors)
include(LoggingHelper)

# *****************************************************************************
# Options Code
# *****************************************************************************

# === CCACHE ===
if(OPTIONS_ENABLE_CCACHE)
find_program(CCACHE ccache)
if(CCACHE)
log_option_enabled("ccache")
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
else()
log_option_disabled("ccache")
endif()
endif()

# === SCCACHE ===
if(OPTIONS_ENABLE_SCCACHE)
find_program(SCCACHE_PATH sccache)
if(SCCACHE_PATH)
log_option_enabled("sccache")
set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_PATH})
set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_PATH})
else()
log_option_disabled("sccache")
endif()
endif()

find_package(OpenGL REQUIRED)

# LibArchive disabled in compilation level by default, see "#define OTGZ_SUPPORT" in the "definitions.h" file
#if(APPLE)
# set(CMAKE_PREFIX_PATH /usr/local/opt/libarchive)
#endif()
# If you need use, enable this:
#find_package(LibArchive REQUIRED)
#${LibArchive_INCLUDE_DIRS} ${LibArchive_LIBRARIES}

find_package(asio CONFIG REQUIRED)
find_package(Threads REQUIRED)
find_package(wxWidgets COMPONENTS html aui gl adv core net base CONFIG REQUIRED)

find_package(GLUT REQUIRED)
find_package(ZLIB REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)

include(source/CMakeLists.txt)

add_executable(${PROJECT_NAME} ${rme_H} ${rme_SRC})

set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON)

# === PRECOMPILED HEADER ===
target_precompile_headers(${PROJECT_NAME} PRIVATE source/main.h)

include_directories(
${OPENGL_INCLUDE_DIR}
${GLUT_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIR}
)

target_link_libraries(${PROJECT_NAME}
${wxWidgets_LIBRARIES}
${OPENGL_LIBRARIES}
${GLUT_LIBRARIES}
${ZLIB_LIBRARIES}
fmt::fmt
asio::asio
nlohmann_json::nlohmann_json
)
# *****************************************************************************
# Add source project
# *****************************************************************************
add_subdirectory(source)
Loading

0 comments on commit b7611dd

Please sign in to comment.