Skip to content

Commit

Permalink
Merge pull request #7 from pasbi/add-tests-ci
Browse files Browse the repository at this point in the history
Create cmake-multi-platform.yml
  • Loading branch information
pasbi authored Oct 5, 2024
2 parents a9ef70a + 1d62d2d commit 737c628
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 0 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: CMake on multiple platforms

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

jobs:
build:
env:
CONAN_HOME: "${{ github.workspace }}/.conan2"

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]
compiler: [gcc, msvc]
build_type: [Release]
exclude:
- os: windows-latest
compiler: gcc
- os: ubuntu-latest
compiler: msvc
include:
- compiler: gcc
generator: "Unix Makefiles"
cppstd: gnu20
libcxx: libstdc++
compiler_version: 11
- compiler: msvc
generator: "Visual Studio 17 2022"
cppstd: 20
compiler_runtime: dynamic
compiler_version: 194

steps:
- uses: actions/checkout@v4

- if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt-get update; sudo apt-get install ninja-build

- name: Install Conan
id: conan
uses: turtlebrowser/get-conan@main

- name: Conan version
run: echo "${{ steps.conan.outputs.version }}"

- name: Cache Conan Dependencies
id: cache-conan
uses: actions/cache@v4
with:
path: ${{ env.CONAN_HOME }}
key: conan-cache-${{ runner.os }}-${{ hashFiles('conanfile.py') }}
restore-keys: conan-cache-${{ runner.os }}-

- uses: DamianReeves/write-file-action@master
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
path: ${{ env.CONAN_HOME }}/profiles/default
contents: |
[settings]
arch=x86_64
build_type=${{ matrix.build_type }}
compiler=${{ matrix.compiler }}
compiler.cppstd=${{ matrix.cppstd }}
compiler.version=${{ matrix.compiler_version }}
os=${{ runner.os }}
compiler.libcxx=${{ matrix.libcxx }}
[conf]
tools.system.package_manager:mode=install
tools.system.package_manager:sudo=True
write-mode: append

- uses: DamianReeves/write-file-action@master
if: ${{ matrix.os == 'windows-latest' }}
with:
path: ${{ env.CONAN_HOME }}/profiles/default
contents: |
[settings]
arch=x86_64
build_type=${{ matrix.build_type }}
compiler=${{ matrix.compiler }}
compiler.cppstd=${{ matrix.cppstd }}
compiler.version=${{ matrix.compiler_version }}
os=${{ runner.os }}
compiler.runtime=${{ matrix.compiler_runtime }}
write-mode: append


- name: PrintProfile
run: cat ${{ env.CONAN_HOME }}/profiles/default

- name: list packages
if: ${{ matrix.os == 'ubuntu-latest' }}
run: dpkg --list

- name: Install Dependencies
run: conan install . --build=missing --output-folder=build

- name: Build
run: |
cmake -G "${{ matrix.generator }}" -S . -B build -DCMAKE_TOOLCHAIN_FILE="build/build/generators/conan_toolchain.cmake" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
cmake --build build --config ${{ matrix.build_type }} --parallel
- name: Test
run: ctest --build-config ${{ matrix.build_type }} --test-dir build
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "googletest"]
path = googletest
url = [email protected]:google/googletest.git
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

add_subdirectory(src)
if (BUILD_TESTING)
add_subdirectory(googletest)
include(CTest)
add_subdirectory(test/unit)
endif ()
62 changes: 62 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps


class TireRecipe(ConanFile):
name = "tire"
version = "1.0"

# Optional metadata
license = "<Put the package license here>"
author = "<Put your name here> <And your email here>"
url = "<Package recipe repository url here, for issues about the package>"
description = "<Description of hello package here>"
topics = ("<Put some tag here>", "<here>", "<and here>")

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "src/*", "include/*", "test/*"

def requirements(self):
self.requires("qt/[>=6.4]", options={
"openssl": False,
"with_pq": False,
"with_md4c": False,
"with_odbc": False,
"with_brotli": False,
"with_libpng": False,
"with_sqlite3": True,
"shared": True,
})
self.requires("spdlog/[>=1.14]")
self.requires("nlohmann_json/[>=3.0]")
self.requires("fmt/[>=10.0]")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def layout(self):
cmake_layout(self)

def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["hello"]
1 change: 1 addition & 0 deletions googletest
Submodule googletest added at 0953a1
7 changes: 7 additions & 0 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

include(GoogleTest)
add_executable(tests
test.cpp
)
target_link_libraries(tests PRIVATE GTest::gtest_main)
gtest_discover_tests(tests)
10 changes: 10 additions & 0 deletions test/unit/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <gtest/gtest.h>

// Demonstrate some basic assertions.
TEST(HelloTest, BasicAssertions) {
// Expect two strings not to be equal.
EXPECT_STRNE("hello", "world");
// Expect equality.
EXPECT_EQ(7 * 6, 42);
}

0 comments on commit 737c628

Please sign in to comment.