Skip to content

Commit

Permalink
Use only recent compilers supporting C++20 (#7)
Browse files Browse the repository at this point in the history
Use only recent compilers supporting C++20
  • Loading branch information
Klaim authored Feb 29, 2024
1 parent bb4d1a1 commit 62e685f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 39 deletions.
62 changes: 25 additions & 37 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,38 @@ defaults:
jobs:
build:
runs-on: ubuntu-20.04
name: ${{ matrix.sys.compiler }} ${{ matrix.sys.version }}
name: ${{ matrix.sys.compiler }} ${{ matrix.sys.version }} ${{ matrix.sys.stdlib }}
strategy:
fail-fast: false
matrix:
sys:
- {compiler: clang, version: '15'}
- {compiler: clang, version: '16'}
- {compiler: gcc, version: '11'}
- {compiler: gcc, version: '13'}
- {compiler: clang, version: '16', config-flags: '', stdlib: 'libstdc++-13' }
# - {compiler: clang, version: '16', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17' }
- {compiler: clang, version: '17', config-flags: '', stdlib: 'libstdc++-13' }
# - {compiler: clang, version: '17', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17' }
- {compiler: gcc, version: '13', config-flags: '' }

steps:

- name: Setup GCC
if: ${{ matrix.sys.compiler == 'gcc' }}
run: |
GCC_VERSION=${{ matrix.sys.version }}
sudo apt-get update
sudo apt-get --no-install-suggests --no-install-recommends install g++-$GCC_VERSION
CC=gcc-$GCC_VERSION
echo "CC=$CC" >> $GITHUB_ENV
CXX=g++-$GCC_VERSION
echo "CXX=$CXX" >> $GITHUB_ENV

- name: Setup clang
if: ${{ matrix.sys.compiler == 'clang' }}
run: |
LLVM_VERSION=${{ matrix.sys.version }}
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - || exit 1
if [[ $LLVM_VERSION -ge 13 ]]; then
sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-$LLVM_VERSION main" || exit 1
else
sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal main" || exit 1
fi || exit 1
sudo apt-get update || exit 1
sudo apt-get --no-install-suggests --no-install-recommends install clang-$LLVM_VERSION || exit 1
sudo apt-get --no-install-suggests --no-install-recommends install g++-9 g++-9-multilib || exit 1
sudo ln -s /usr/include/asm-generic /usr/include/asm
CC=clang-$LLVM_VERSION
echo "CC=$CC" >> $GITHUB_ENV
CXX=clang++-$LLVM_VERSION
echo "CXX=$CXX" >> $GITHUB_ENV
- name: Install GCC
if: matrix.sys.compiler == 'gcc'
uses: egor-tensin/setup-gcc@v1
with:
version: ${{matrix.sys.version}}
platform: x64

- name: Install LLVM and Clang
if: matrix.sys.compiler == 'clang'
uses: egor-tensin/setup-clang@v1
with:
version: ${{matrix.sys.version}}
platform: x64

- name: Install the specified standard library for clang
if: matrix.sys.compiler == 'clang'
run: sudo apt install ${{matrix.sys.stdlib}}-dev -y


- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -67,10 +58,7 @@ jobs:
cache-downloads: true

- name: Configure using CMake
# env:
# CC: ${{ env.CC }}
# CXX: ${{ env.CXX }}
run: cmake -G Ninja -Bbuild -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON
run: cmake -G Ninja -Bbuild ${{matrix.sys.config-flags}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON

- name: Install
working-directory: build
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
fail-fast: false
matrix:
os:
- 11
- 12

steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*.out
*.app

# Ignore build directory
/build/

# Ignore VSCODE specific options (unless we want to provide shortcuts to build and run, then delete these)
/.vscode/
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.28)

# This is better specified per target, but cmake keeps ignoring these language version
# specification when building this project by itself, in particular the gnu extensions,
# so here we go.
# This will affects all following targets being defined.
set(CMAKE_CXX_EXTENSIONS OFF)

project(sparrow CXX)

set(SPARROW_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
Expand Down Expand Up @@ -53,6 +60,8 @@ target_include_directories(sparrow INTERFACE
$<BUILD_INTERFACE:${SPARROW_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)

# We do not use non-standard C++
set_target_properties(sparrow PROPERTIES CMAKE_CXX_EXTENSIONS OFF)
target_compile_features(sparrow INTERFACE cxx_std_20)

if (BUILD_TESTS)
Expand Down
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

cmake_minimum_required(VERSION 3.8)


if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
project(sparrow-test CXX)

Expand All @@ -40,3 +41,7 @@ set(SPARROW_TESTS
set(test_target "test_sparrow_lib")
add_executable(${test_target} ${SPARROW_TESTS})
target_link_libraries(${test_target} PRIVATE sparrow doctest::doctest)

# We do not use non-standard C++
set_target_properties(${test_target} PROPERTIES CMAKE_CXX_EXTENSIONS OFF)
target_compile_features(${test_target} PRIVATE cxx_std_20)
1 change: 1 addition & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest/doctest.h"

#include <format>

0 comments on commit 62e685f

Please sign in to comment.