Skip to content

Commit

Permalink
Add github CI workflow and multi-platform/config CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterTh committed Dec 11, 2023
1 parent 3923046 commit 7b26327
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 18 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/simsycl_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: SimSYCL CI

on:
push:
pull_request:

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release, Debug]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl

steps:
- uses: actions/checkout@v3

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
28 changes: 17 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(Boost 1.60 COMPONENTS context REQUIRED)

# Function to set properties, compile options, and link options for all simsycl targets
function(set_simsycl_target_options target)
set_target_properties(${target} PROPERTIES CXX_STANDARD 20)
set_target_properties(${target} PROPERTIES CXX_STANDARD_REQUIRED ON)
target_compile_options(${target} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX $<$<CONFIG:Debug>:/fsanitize=address>>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic $<$<CONFIG:Debug>:-fsanitize=address>>
)
target_link_options(${target} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:$<$<CONFIG:Debug>:/fsanitize=address>>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:$<$<CONFIG:Debug>:-fsanitize=address>>
)
endfunction()

add_library(simsycl
include/sycl/sycl.hpp
include/CL/sycl.hpp
Expand Down Expand Up @@ -46,20 +60,12 @@ add_library(simsycl
src/simsycl/dummy.cc
)
target_link_libraries(simsycl Boost::context)

target_include_directories(simsycl PUBLIC include)
set_target_properties(simsycl PROPERTIES CXX_STANDARD 20)
set_target_properties(simsycl PROPERTIES CXX_STANDARD_REQUIRED ON)
target_compile_options(simsycl PRIVATE -Wall -Wextra -Wpedantic)
target_compile_options(simsycl PRIVATE -fsanitize=address)
target_link_options(simsycl PRIVATE -fsanitize=address)
set_simsycl_target_options(simsycl)

add_executable(main src/test/main.cc)
target_link_libraries(main simsycl)
set_target_properties(main PROPERTIES CXX_STANDARD 20)
set_target_properties(main PROPERTIES CXX_STANDARD_REQUIRED ON)
target_compile_options(main PRIVATE -Wall -Wextra -Wpedantic)
target_compile_options(main PRIVATE -fsanitize=address)
target_link_options(main PRIVATE -fsanitize=address)
set_simsycl_target_options(main)

enable_testing()
add_subdirectory(test)
13 changes: 6 additions & 7 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ FetchContent_Declare(
FetchContent_MakeAvailable(Catch2)

add_executable(tests group_op_tests.cc)

set_target_properties(tests PROPERTIES CXX_STANDARD 20)
set_target_properties(tests PROPERTIES CXX_STANDARD_REQUIRED ON)
target_compile_options(tests PRIVATE -Wall -Wextra -Wpedantic)
target_compile_options(tests PRIVATE -fsanitize=address)

target_link_libraries(tests PRIVATE Catch2::Catch2WithMain simsycl)
target_link_options(tests PRIVATE -fsanitize=address)
set_simsycl_target_options(tests)

list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
include(CTest)
include(Catch)
catch_discover_tests(tests)

0 comments on commit 7b26327

Please sign in to comment.