Skip to content

Commit b7611dd

Browse files
committed
improve: add github actions workflow and rework cmakelists
1 parent f3bb2f3 commit b7611dd

13 files changed

Lines changed: 554 additions & 261 deletions
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
name: Analysis - SonarCloud
3+
4+
on:
5+
pull_request_target:
6+
types: [opened, synchronize, reopened]
7+
push:
8+
branches:
9+
- main
10+
11+
env:
12+
VCPKG_BUILD_TYPE: release
13+
CMAKE_BUILD_PARALLEL_LEVEL: 2
14+
MAKEFLAGS: '-j 2'
15+
NUMBER_OF_PROCESSORS: 2
16+
17+
jobs:
18+
sonarcloud:
19+
name: SonarCloud
20+
runs-on: ubuntu-22.04
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
25+
with:
26+
fetch-depth: 0
27+
ref: ${{github.event.pull_request.head.ref}}
28+
repository: ${{github.event.pull_request.head.repo.full_name}}
29+
30+
- uses: actions/checkout@v3
31+
if: ${{ github.event_name == 'push' }}
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Install Linux Dependencies
36+
run: >
37+
sudo apt-get update && sudo apt-get install ccache linux-headers-$(uname -r)
38+
39+
- name: Switch to gcc-11
40+
run: |
41+
sudo apt install gcc-11 g++-11
42+
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
43+
sudo update-alternatives --set gcc /usr/bin/gcc-11
44+
45+
- name: CCache
46+
id: ccache
47+
uses: actions/cache@main
48+
with:
49+
path: $HOME/.ccache
50+
key: ccache-${{ runner.os }}-${{ hashFiles('**/src') }}
51+
restore-keys: |
52+
ccache-${{ runner.os}}-
53+
54+
- name: Cache SonarCloud packages
55+
uses: actions/cache@main
56+
with:
57+
path: $HOME/.sonar/cache
58+
key: sonar-${{ runner.os}}-${{ hashFiles('**/src') }}
59+
restore-keys: |
60+
sonar-${{ runner.os}}-
61+
62+
- name: Restore artifacts and install vcpkg
63+
id: vcpkg-step
64+
run: |
65+
vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ')
66+
echo "vcpkg commit ID: $vcpkgCommitId"
67+
echo "::set-output name=vcpkgGitCommitId::$vcpkgCommitId"
68+
- name: Get vcpkg commit id from vcpkg.json
69+
uses: lukka/run-vcpkg@main
70+
with:
71+
vcpkgGitURL: "https://github.com/microsoft/vcpkg.git"
72+
vcpkgGitCommitId: ${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }}
73+
74+
- name: Install sonar-scanner
75+
uses: SonarSource/sonarcloud-github-c-cpp@v1
76+
77+
- name: Generate compilation database
78+
run: |
79+
mkdir -p build
80+
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
81+
82+
- name: Run PR sonar-scanner
83+
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
87+
run: |
88+
sonar-scanner \
89+
--define sonar.cfamily.compile-commands=build/compile_commands.json \
90+
--define sonar.pullrequest.key=${{ github.event.pull_request.number }} \
91+
--define sonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} \
92+
--define sonar.pullrequest.base=${{ github.event.pull_request.base_ref }}
93+
94+
- name: Run sonar-scanner
95+
if: ${{ github.event_name == 'push' }}
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
99+
run: |
100+
sonar-scanner \
101+
--define sonar.cfamily.compile-commands=build/compile_commands.json

.github/workflows/build-ubuntu.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
name: Build - Ubuntu
3+
4+
on:
5+
workflow_dispatch:
6+
pull_request:
7+
types: [opened, synchronize, reopened, ready_for_review]
8+
push:
9+
branches:
10+
- main
11+
12+
env:
13+
CMAKE_BUILD_PARALLEL_LEVEL: 2
14+
MAKEFLAGS: '-j 2'
15+
16+
jobs:
17+
job:
18+
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
19+
name: ${{ matrix.os }}-${{ matrix.buildtype }}
20+
runs-on: ${{ matrix.os }}
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
os: [ubuntu-22.04]
26+
buildtype: [Release, Debug]
27+
include:
28+
- os: ubuntu-22.04
29+
triplet: x64-linux
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@main
34+
35+
- name: Install Linux Dependencies
36+
run: >
37+
sudo apt-get update && sudo apt-get install ccache linux-headers-$(uname -r)
38+
39+
- name: Switch to gcc-11
40+
run: |
41+
sudo apt install gcc-11 g++-11
42+
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
43+
sudo update-alternatives --set gcc /usr/bin/gcc-11
44+
45+
- name: CCache
46+
uses: hendrikmuhs/ccache-action@main
47+
with:
48+
max-size: "1G"
49+
key: ccache-${{ matrix.os }}-${{ matrix.buildtype }}
50+
restore-keys: |
51+
ccache-${{ matrix.os }}
52+
53+
- name: Restore artifacts and install vcpkg
54+
id: vcpkg-step
55+
run: |
56+
vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ')
57+
echo "vcpkg commit ID: $vcpkgCommitId"
58+
echo "::set-output name=vcpkgGitCommitId::$vcpkgCommitId"
59+
- name: Get vcpkg commit id from vcpkg.json
60+
uses: lukka/run-vcpkg@main
61+
with:
62+
vcpkgGitURL: "https://github.com/microsoft/vcpkg.git"
63+
vcpkgGitCommitId: ${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }}
64+
65+
- name: Get latest CMake and ninja
66+
uses: lukka/get-cmake@main
67+
68+
- name: Install additional libraries
69+
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
70+
71+
- name: Run CMake Cache and Build
72+
uses: lukka/run-cmake@v3
73+
with:
74+
cmakeListsTxtPath: ${{ github.workspace }}/CMakeLists.txt
75+
useVcpkgToolchainFile: true
76+
buildDirectory: ${{ github.workspace }}/build/
77+
cmakeBuildType: ${{ matrix.buildtype }}
78+
79+
- name: Create and Upload Artifact
80+
uses: actions/upload-artifact@main
81+
with:
82+
name: remeres-map-editor-${{ matrix.os }}-${{ matrix.buildtype }}-${{ github.sha }}
83+
path: |
84+
${{ github.workspace }}/build/bin/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
name: Build - Windows
3+
4+
on:
5+
workflow_dispatch:
6+
pull_request:
7+
types: [opened, synchronize, reopened, ready_for_review]
8+
push:
9+
branches:
10+
- main
11+
- master
12+
13+
jobs:
14+
job:
15+
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
16+
name: ${{ matrix.os }}-${{ matrix.buildtype }}
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
os: [windows-2022]
21+
buildtype: [Release, Debug]
22+
include:
23+
- os: windows-2022
24+
triplet: x64-windows
25+
packages: >
26+
sccache
27+
steps:
28+
- name: Setup MSBuild.exe
29+
uses: microsoft/[email protected]
30+
31+
- name: Checkout repository
32+
uses: actions/checkout@v2
33+
34+
- name: Install vcpkg
35+
run: |
36+
git clone https://github.com/Microsoft/vcpkg.git
37+
cd vcpkg
38+
./bootstrap-vcpkg.bat
39+
./vcpkg integrate install
40+
41+
- name: Build project
42+
run: msbuild.exe /p:VcpkgEnableManifest=true /p:Configuration=Release /p:Platform=x64 /p:VcpkgRoot=$env:GITHUB_WORKSPACE/vcpkg vcproj/RME.sln
43+
44+
- name: Upload artifacts
45+
uses: actions/upload-artifact@v2
46+
with:
47+
name: ${{ matrix.os }}-${{ matrix.buildtype }}
48+
path: |
49+
${{ github.workspace }}/vcproj/x64/${{ matrix.buildtype }}/

CMakeLists.txt

Lines changed: 91 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,96 @@
11
cmake_minimum_required(VERSION 3.1)
22

3-
project(rme)
3+
project(cmake)
44

5-
if(NOT CMAKE_BUILD_TYPE)
6-
set(CMAKE_BUILD_TYPE RelWithDebInfo)
5+
# *****************************************************************************
6+
# Vcpkg Configs
7+
# *****************************************************************************
8+
9+
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
10+
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
11+
endif()
12+
13+
if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
14+
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
15+
endif()
16+
17+
set(VCPKG_FEATURE_FLAGS "versions")
18+
set(VCPKG_BUILD_TYPE "release")
19+
20+
# *****************************************************************************
21+
# Set Configs
22+
# *****************************************************************************
23+
24+
set(CMAKE_CXX_STANDARD 20)
25+
set(GNUCXX_MINIMUM_VERSION 11)
26+
set(MSVC_MINIMUM_VERSION "19.32")
27+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
28+
29+
# *****************************************************************************
30+
# Options
31+
# *****************************************************************************
32+
option(OPTIONS_ENABLE_CCACHE "Enable ccache" OFF)
33+
option(OPTIONS_ENABLE_SCCACHE "Use sccache to speed up compilation process" OFF)
34+
35+
# *****************************************************************************
36+
# Set Sanity Check
37+
# *****************************************************************************
38+
39+
# === GCC Minimum Version ===
40+
if (CMAKE_COMPILER_IS_GNUCXX)
41+
message("-- Compiler: GCC - Version: ${CMAKE_CXX_COMPILER_VERSION}")
42+
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS GNUCXX_MINIMUM_VERSION)
43+
message(FATAL_ERROR "GCC version must be at least ${GNUCXX_MINIMUM_VERSION}!")
44+
endif()
45+
endif()
46+
47+
# === Minimum required version for visual studio ===
48+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
49+
message("-- Compiler: Visual Studio - Version: ${CMAKE_CXX_COMPILER_VERSION}")
50+
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS MSVC_MINIMUM_VERSION)
51+
message(FATAL_ERROR "Visual Studio version must be at least ${MSVC_MINIMUM_VERSION}")
52+
endif()
53+
endif()
54+
55+
# *****************************************************************************
56+
# Append cmake search path
57+
# *****************************************************************************
58+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
59+
60+
# *****************************************************************************
61+
# Include cmake tools
62+
# *****************************************************************************
63+
include(MessageColors)
64+
include(LoggingHelper)
65+
66+
# *****************************************************************************
67+
# Options Code
68+
# *****************************************************************************
69+
70+
# === CCACHE ===
71+
if(OPTIONS_ENABLE_CCACHE)
72+
find_program(CCACHE ccache)
73+
if(CCACHE)
74+
log_option_enabled("ccache")
75+
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
76+
else()
77+
log_option_disabled("ccache")
78+
endif()
79+
endif()
80+
81+
# === SCCACHE ===
82+
if(OPTIONS_ENABLE_SCCACHE)
83+
find_program(SCCACHE_PATH sccache)
84+
if(SCCACHE_PATH)
85+
log_option_enabled("sccache")
86+
set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_PATH})
87+
set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_PATH})
88+
else()
89+
log_option_disabled("sccache")
90+
endif()
791
endif()
892

9-
find_package(OpenGL REQUIRED)
10-
11-
# LibArchive disabled in compilation level by default, see "#define OTGZ_SUPPORT" in the "definitions.h" file
12-
#if(APPLE)
13-
# set(CMAKE_PREFIX_PATH /usr/local/opt/libarchive)
14-
#endif()
15-
# If you need use, enable this:
16-
#find_package(LibArchive REQUIRED)
17-
#${LibArchive_INCLUDE_DIRS} ${LibArchive_LIBRARIES}
18-
19-
find_package(asio CONFIG REQUIRED)
20-
find_package(Threads REQUIRED)
21-
find_package(wxWidgets COMPONENTS html aui gl adv core net base CONFIG REQUIRED)
22-
23-
find_package(GLUT REQUIRED)
24-
find_package(ZLIB REQUIRED)
25-
find_package(fmt CONFIG REQUIRED)
26-
find_package(nlohmann_json CONFIG REQUIRED)
27-
28-
include(source/CMakeLists.txt)
29-
30-
add_executable(${PROJECT_NAME} ${rme_H} ${rme_SRC})
31-
32-
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
33-
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON)
34-
35-
# === PRECOMPILED HEADER ===
36-
target_precompile_headers(${PROJECT_NAME} PRIVATE source/main.h)
37-
38-
include_directories(
39-
${OPENGL_INCLUDE_DIR}
40-
${GLUT_INCLUDE_DIRS}
41-
${ZLIB_INCLUDE_DIR}
42-
)
43-
44-
target_link_libraries(${PROJECT_NAME}
45-
${wxWidgets_LIBRARIES}
46-
${OPENGL_LIBRARIES}
47-
${GLUT_LIBRARIES}
48-
${ZLIB_LIBRARIES}
49-
fmt::fmt
50-
asio::asio
51-
nlohmann_json::nlohmann_json
52-
)
93+
# *****************************************************************************
94+
# Add source project
95+
# *****************************************************************************
96+
add_subdirectory(source)

0 commit comments

Comments
 (0)