From a8169aba8e72e352f34cab912c4f95688e0fd6e4 Mon Sep 17 00:00:00 2001
From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com>
Date: Sun, 23 Jul 2023 15:57:44 -0400
Subject: [PATCH] Add integration tests for cmake (#17)
---
.github/workflows/cmake-integration.yml | 105 +++++++++++++++++++
README.md | 1 +
test/fetchcontent-integration/CMakeLists.txt | 16 +++
test/fetchcontent-integration/main.cpp | 14 +++
test/findpackage-integration/CMakeLists.txt | 8 ++
test/findpackage-integration/main.cpp | 14 +++
6 files changed, 158 insertions(+)
create mode 100644 .github/workflows/cmake-integration.yml
create mode 100644 test/fetchcontent-integration/CMakeLists.txt
create mode 100644 test/fetchcontent-integration/main.cpp
create mode 100644 test/findpackage-integration/CMakeLists.txt
create mode 100644 test/findpackage-integration/main.cpp
diff --git a/.github/workflows/cmake-integration.yml b/.github/workflows/cmake-integration.yml
new file mode 100644
index 0000000..4b4ffd1
--- /dev/null
+++ b/.github/workflows/cmake-integration.yml
@@ -0,0 +1,105 @@
+name: cmake-integration
+
+on:
+ push:
+ pull_request:
+
+# Awful hackery: github.event.workflow_run.head_sha is defined on push, github.event.pull_request.base.sha is defined on
+# pull
+
+
+jobs:
+ test-linux-fetchcontent:
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/checkout@v2
+ - name: test
+ run: |
+ tag=$(git rev-parse --abbrev-ref HEAD)
+ cd ..
+ cp -rv cpptrace/test/fetchcontent-integration .
+ mkdir fetchcontent-integration/build
+ cd fetchcontent-integration/build
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG=$tag
+ make
+ ./main
+ test-linux-findpackage:
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/checkout@v2
+ - name: build
+ run: |
+ tag=$(git rev-parse --abbrev-ref HEAD)
+ mkdir build
+ cd build
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=On
+ sudo make -j install
+ cd ../..
+ cp -rv cpptrace/test/findpackage-integration .
+ mkdir findpackage-integration/build
+ cd findpackage-integration/build
+ cmake .. -DCMAKE_BUILD_TYPE=Debug
+ make
+ ./main
+ test-macos-fetchcontent:
+ runs-on: macos-13
+ steps:
+ - uses: actions/checkout@v2
+ - name: test
+ run: |
+ tag=$(git rev-parse --abbrev-ref HEAD)
+ cd ..
+ cp -rv cpptrace/test/fetchcontent-integration .
+ mkdir fetchcontent-integration/build
+ cd fetchcontent-integration/build
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG=$tag
+ make
+ ./main
+ test-macos-findpackage:
+ runs-on: macos-13
+ steps:
+ - uses: actions/checkout@v2
+ - name: build
+ run: |
+ tag=$(git rev-parse --abbrev-ref HEAD)
+ mkdir build
+ cd build
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=On
+ sudo make -j install
+ cd ../..
+ cp -rv cpptrace/test/findpackage-integration .
+ mkdir findpackage-integration/build
+ cd findpackage-integration/build
+ cmake .. -DCMAKE_BUILD_TYPE=Debug
+ make
+ ./main
+ test-mingw-fetchcontent:
+ runs-on: windows-2019
+ steps:
+ - uses: actions/checkout@v2
+ - name: test
+ run: |
+ $tag=$(git rev-parse --abbrev-ref HEAD)
+ cd ..
+ cp -Recurse cpptrace/test/fetchcontent-integration .
+ mkdir fetchcontent-integration/build
+ cd fetchcontent-integration/build
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG="$tag" -DCMAKE_BUILD_TYPE=g++ "-GUnix Makefiles"
+ make
+ .\main.exe
+ test-windows-fetchcontent:
+ runs-on: windows-2019
+ steps:
+ - uses: actions/checkout@v2
+ - name: Enable Developer Command Prompt
+ uses: ilammy/msvc-dev-cmd@v1.10.0
+ - name: test
+ run: |
+ $tag=$(git rev-parse --abbrev-ref HEAD)
+ cd ..
+ cp -Recurse cpptrace/test/fetchcontent-integration .
+ mkdir fetchcontent-integration/build
+ cd fetchcontent-integration/build
+ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_TAG="$tag"
+ msbuild demo_project.sln
+ .\Debug\main.exe
diff --git a/README.md b/README.md
index cd89ade..518d367 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,7 @@
[](https://github.com/jeremy-rifkin/cpptrace/actions/workflows/test.yml)
[](https://github.com/jeremy-rifkin/cpptrace/actions/workflows/performance-tests.yml)
[](https://github.com/jeremy-rifkin/cpptrace/actions/workflows/lint.yml)
+[](https://github.com/jeremy-rifkin/cpptrace/actions/workflows/cmake-integration.yml)
[-Community%20Discord-blue?labelColor=2C3239&color=7289DA&style=flat&logo=discord&logoColor=959DA5)](https://discord.gg/7kv5AuCndG)
diff --git a/test/fetchcontent-integration/CMakeLists.txt b/test/fetchcontent-integration/CMakeLists.txt
new file mode 100644
index 0000000..817cc85
--- /dev/null
+++ b/test/fetchcontent-integration/CMakeLists.txt
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.8)
+
+project(demo_project VERSION 0.0.1 LANGUAGES CXX)
+
+add_executable(main main.cpp)
+
+set(CPPTRACE_TAG "" CACHE STRING "cpptrace git tag")
+
+include(FetchContent)
+FetchContent_Declare(
+ cpptrace
+ GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git
+ GIT_TAG ${CPPTRACE_TAG}
+)
+FetchContent_MakeAvailable(cpptrace)
+target_link_libraries(main cpptrace)
diff --git a/test/fetchcontent-integration/main.cpp b/test/fetchcontent-integration/main.cpp
new file mode 100644
index 0000000..899d4a0
--- /dev/null
+++ b/test/fetchcontent-integration/main.cpp
@@ -0,0 +1,14 @@
+#include
+
+void trace() {
+ cpptrace::print_trace();
+}
+
+void foo(int) {
+ trace();
+}
+
+int main() {
+ foo(0);
+}
+
diff --git a/test/findpackage-integration/CMakeLists.txt b/test/findpackage-integration/CMakeLists.txt
new file mode 100644
index 0000000..39bb68b
--- /dev/null
+++ b/test/findpackage-integration/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.8)
+
+project(demo_project VERSION 0.0.1 LANGUAGES CXX)
+
+add_executable(main main.cpp)
+
+find_package(cpptrace REQUIRED)
+target_link_libraries(main cpptrace::cpptrace)
diff --git a/test/findpackage-integration/main.cpp b/test/findpackage-integration/main.cpp
new file mode 100644
index 0000000..899d4a0
--- /dev/null
+++ b/test/findpackage-integration/main.cpp
@@ -0,0 +1,14 @@
+#include
+
+void trace() {
+ cpptrace::print_trace();
+}
+
+void foo(int) {
+ trace();
+}
+
+int main() {
+ foo(0);
+}
+