Skip to content

Commit

Permalink
use toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
wusatosi committed Dec 11, 2024
1 parent ac9408b commit 8057e45
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 49 deletions.
71 changes: 27 additions & 44 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ jobs:
matrix:
platform:
- description: "Ubuntu GCC"
cpp: g++
c: gcc
os: ubuntu-latest
toolchain: "cmake/gnu-toolchain.cmake"
- description: "Ubuntu Clang"
cpp: clang++
c: clang
os: ubuntu-latest
toolchain: "cmake/llvm-toolchain.cmake"
cpp_version: [17, 20, 23, 26]
cmake_args:
- description: "Default"
Expand All @@ -51,42 +49,40 @@ jobs:
include:
- platform:
description: "Ubuntu GCC"
cpp: g++
c: gcc
os: ubuntu-latest
toolchain: "cmake/gnu-toolchain.cmake"
cpp_version: 17
cmake_args:
description: "Werror"
args: "-DCMAKE_CXX_FLAGS='-Werror=all -Werror=extra'"
- platform:
description: "Ubuntu GCC"
cpp: g++
c: gcc
os: ubuntu-latest
toolchain: "cmake/gnu-toolchain.cmake"
cpp_version: 17
cmake_args:
description: "Dynamic"
args: "-DBUILD_SHARED_LIBS=on"
- platform:
description: "Windows MSVC"
cpp: cl
c: cl
os: windows-latest
cpp_version: 17
cmake_args:
description: "Default"
args: ""
- platform:
description: "Windows MSVC"
cpp: cl
c: cl
os: windows-latest
cpp_version: 17
cmake_args:
description: "ASan"
# Debug infomation needed to avoid cl: C5072
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-c5072?view=msvc-170
args: "-DCMAKE_CXX_FLAGS='/fsanitize=address /Zi'"
# - platform:
# description: "Windows MSVC"
# cpp: cl
# c: cl
# os: windows-latest
# cpp_version: 17
# cmake_args:
# description: "Default"
# args: ""
# - platform:
# description: "Windows MSVC"
# cpp: cl
# c: cl
# os: windows-latest
# cpp_version: 17
# cmake_args:
# description: "ASan"
# # Debug infomation needed to avoid cl: C5072
# # https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-c5072?view=msvc-170
# args: "-DCMAKE_CXX_FLAGS='/fsanitize=address /Zi'"


name: "Unit: ${{ matrix.platform.description }} ${{ matrix.cpp_version }} ${{ matrix.cmake_args.description }}"
Expand All @@ -106,27 +102,14 @@ jobs:
- name: Print installed softwares
shell: bash
run: |
echo "Compiler:"
# cl does not have a --version option
if [ "${{ matrix.platform.cpp }}" != "cl" ]; then
${{ matrix.platform.cpp }} --version
${{ matrix.platform.c }} --version
else
${{ matrix.platform.cpp }}
${{ matrix.platform.c }}
fi
echo "Build system:"
cmake --version
ninja --version
- name: Configure CMake
run: |
cmake -B build -S . -DCMAKE_CXX_STANDARD=${{ matrix.cpp_version }} ${{ matrix.cmake_args.args }}
env:
CC: ${{ matrix.platform.c }}
CXX: ${{ matrix.platform.cpp }}
CMAKE_GENERATOR: "Ninja Multi-Config"
cmake -B build -S . -DCMAKE_CXX_STANDARD=${{ matrix.cpp_version }} \
-DCMAKE_TOOLCHAIN_FILE=${{ matrix.platform.toolchain }} \
${{ matrix.cmake_args.args }}
- name: Build Release
run: |
# Portable commands only
Expand Down
9 changes: 4 additions & 5 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_FLAGS": "-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak -fsanitize=undefined"
"BEMAN_BUILDSYS_SANITIZER": "ASan"
}
},
{
"name": "_release-base",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_CXX_FLAGS": "-O3"
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
Expand All @@ -34,7 +33,7 @@
"_debug-base"
],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "g++"
"CMAKE_TOOLCHAIN_FILE": "cmake/gnu-toolchain.cmake"
}
},
{
Expand All @@ -45,7 +44,7 @@
"_release-base"
],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "g++"
"CMAKE_TOOLCHAIN_FILE": "cmake/gnu-toolchain.cmake"
}
}
],
Expand Down
18 changes: 18 additions & 0 deletions cmake/gnu-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_GENERATOR "Ninja Multi-Config")

if(BEMAN_BUILDSYS_SANITIZER STREQUAL "ASan")
set(CMAKE_CXX_FLAGS_DEBUG_INIT
"-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
)
set(CMAKE_C_FLAGS_DEBUG_INIT
"-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
)
elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "TSan")
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-fsanitize=thread")
set(CMAKE_C_FLAGS_DEBUG_INIT "-fsanitize=thread")
endif()

set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O3")
18 changes: 18 additions & 0 deletions cmake/llvm-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_GENERATOR "Ninja Multi-Config")

if(BEMAN_BUILDSYS_SANITIZER STREQUAL "ASan")
set(CMAKE_CXX_FLAGS_DEBUG_INIT
"-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
)
set(CMAKE_C_FLAGS_DEBUG_INIT
"-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
)
elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "TSan")
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-fsanitize=thread")
set(CMAKE_C_FLAGS_DEBUG_INIT "-fsanitize=thread")
endif()

set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O3")

0 comments on commit 8057e45

Please sign in to comment.