Skip to content

Commit

Permalink
add ci workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
barne856 committed Jul 9, 2024
1 parent 5a0ef4f commit ceeef5c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 33 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: SQUINT CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
strategy:
matrix:
compiler: [g++-12, clang++-15, clang++-16, clang++-17, clang++-18]

steps:
- uses: actions/checkout@v3

- name: Install compiler
run: |
sudo apt-get update
sudo apt-get install -y ${{ matrix.compiler }}
- name: Configure CMake
env:
CXX: ${{ matrix.compiler }}
run: cmake -B ${{github.workspace}}/build -DSQUINT_BUILD_TESTS=ON

- name: Build
run: cmake --build ${{github.workspace}}/build

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest --output-on-failure
78 changes: 45 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
cmake_minimum_required(VERSION 3.28)

## Project Settings
project(SQUINT)
project(SQUINT VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include(ExternalProject)
find_package(Git REQUIRED)

ExternalProject_Add(
doctest
PREFIX ${CMAKE_BINARY_DIR}/doctest
GIT_REPOSITORY https://github.com/doctest/doctest.git
TIMEOUT 10
UPDATE_COMMAND ${GIT_EXECUTABLE} pull
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
# Option to control building tests
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
option(SQUINT_BUILD_TESTS "Build the tests" ON)
else()
option(SQUINT_BUILD_TESTS "Build the tests" OFF)
endif()

# Create interface library for SQUINT
add_library(SQUINT INTERFACE)
target_include_directories(SQUINT INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

# Expose required variable (DOCTEST_INCLUDE_DIR) to parent scope
ExternalProject_Get_Property(doctest source_dir)
set(DOCTEST_INCLUDE_DIR ${source_dir}/doctest CACHE INTERNAL "Path to include folder for doctest")

# add it globally
include_directories(${DOCTEST_INCLUDE_DIR} "include")

# Make test executable
add_executable(quantity_tests tests/quantity_tests.cpp)
target_link_libraries(quantity_tests)

add_executable(dimension_tests tests/dimension_tests.cpp)
target_link_libraries(dimension_tests)

add_executable(tensor_tests tests/tensor_tests.cpp)
target_link_libraries(tensor_tests)

add_executable(main main.cpp)
# Tests
if(SQUINT_BUILD_TESTS)
# Download doctest header
file(DOWNLOAD
https://raw.githubusercontent.com/doctest/doctest/v2.4.11/doctest/doctest.h
${CMAKE_BINARY_DIR}/doctest.h
)

# Create interface library for doctest
add_library(doctest INTERFACE)
target_include_directories(doctest INTERFACE ${CMAKE_BINARY_DIR})

enable_testing()

# Function to create test targets
function(add_squint_test test_name)
add_executable(${test_name} tests/${test_name}.cpp)
target_link_libraries(${test_name} PRIVATE SQUINT doctest)
add_test(NAME ${test_name} COMMAND ${test_name})
endfunction()

# Add tests
add_squint_test(quantity_tests)
add_squint_test(dimension_tests)
add_squint_test(tensor_tests)
endif()

# Main executable (temporary testing purposes)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE SQUINT)
endif()

0 comments on commit ceeef5c

Please sign in to comment.