Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,84 @@ jobs:
- name: Test
run: ctest --preset=test

install-test:
name: Test Installation (${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v5

- name: Build and Install
run: |
cmake --preset=default
cmake --build --preset=default
cmake --install build/default --prefix ${{ runner.temp }}/install

- name: Test find_package
shell: bash
run: |
# Create a minimal test to verify the installation works with find_package
mkdir -p ${{ runner.temp }}/test-find-package
cd ${{ runner.temp }}/test-find-package

# Get project name from CMakeLists.txt
PACKAGE_NAME=$(grep -m1 "project(" ${{ github.workspace }}/CMakeLists.txt | sed 's/project(\([^)]*\)).*/\1/' | awk '{print $1}')

# Create test CMakeLists.txt
cat > CMakeLists.txt << EOF
cmake_minimum_required(VERSION 3.20)
project(test-find-package CXX)

set(CMAKE_PREFIX_PATH "${{ runner.temp }}/install")
find_package(${PACKAGE_NAME} REQUIRED)

message(STATUS "Successfully found ${PACKAGE_NAME}")
EOF

# Test find_package
cmake -B build -S .

- name: Test CPMFindPackage
shell: bash
run: |
# Create test to verify CPMFindPackage works (tries find_package first, then CPM)
mkdir -p ${{ runner.temp }}/test-cpm
cd ${{ runner.temp }}/test-cpm

# Download CPM.cmake
mkdir cmake
curl -L https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake -o cmake/CPM.cmake

# Get project name from CMakeLists.txt
PACKAGE_NAME=$(grep -m1 "project(" ${{ github.workspace }}/CMakeLists.txt | sed 's/project(\([^)]*\)).*/\1/' | awk '{print $1}')

# Create test CMakeLists.txt that uses CPMFindPackage
cat > CMakeLists.txt << EOF
cmake_minimum_required(VERSION 3.20)
project(test-cpm CXX)

set(CMAKE_PREFIX_PATH "${{ runner.temp }}/install")
set(CPM_SOURCE_CACHE \${CMAKE_SOURCE_DIR}/.cache/cpm CACHE PATH "CPM cache")
include(cmake/CPM.cmake)

# CPMFindPackage tries find_package first, then falls back to CPMAddPackage
CPMFindPackage(
NAME ${PACKAGE_NAME}
GITHUB_REPOSITORY ${{ github.repository }}
GIT_TAG ${{ github.sha }}
)

message(STATUS "Successfully acquired ${PACKAGE_NAME} via CPMFindPackage")
EOF

# Test CPMFindPackage (should find the installed version first)
cmake -B build -S .

clang-tidy:
runs-on: ubuntu-latest

Expand Down
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"_comment": "Auto-generated from cpp-library (https://github.com/stlab/cpp-library) - Do not edit this file directly",
"recommendations": [
"matepek.vscode-catch2-test-adapter",
"llvm-vs-code-extensions.vscode-clangd",
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ include(cmake/CPM.cmake)
# NAME cpp-library
# URL "${CMAKE_SOURCE_DIR}/../cpp-library"
# )
CPMAddPackage("gh:stlab/[email protected]")
CPMAddPackage("gh:stlab/cpp-library#79bc0a0f8680185273ae33477f9fbd7b6d137ccb")
# CPMAddPackage("gh:stlab/[email protected]")

include(${cpp-library_SOURCE_DIR}/cpp-library.cmake)

# Let cpp-library handle the project declaration and version detection
Expand Down
17 changes: 16 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,29 @@
"CMAKE_CXX_EXTENSIONS": "OFF",
"CPP_LIBRARY_FORCE_INIT": "ON"
}
},
{
"name": "install",
"displayName": "Local Install Test",
"description": "Configuration for testing installation locally (installs to build/install/prefix)",
"binaryDir": "${sourceDir}/build/install",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"BUILD_TESTING": "OFF",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_CXX_EXTENSIONS": "OFF",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build/install/prefix"
}
}
],
"buildPresets": [
{ "name": "default", "displayName": "Default Build", "configurePreset": "default" },
{ "name": "test", "displayName": "Build Tests", "configurePreset": "test" },
{ "name": "docs", "displayName": "Build Docs", "configurePreset": "docs", "targets": "docs" },
{ "name": "clang-tidy", "displayName": "Build with Clang-Tidy", "configurePreset": "clang-tidy" },
{ "name": "init", "displayName": "Initialize Templates", "configurePreset": "init" }
{ "name": "init", "displayName": "Initialize Templates", "configurePreset": "init" },
{ "name": "install", "displayName": "Build for Local Install", "configurePreset": "install" }
],
"testPresets": [
{ "name": "test", "displayName": "Run All Tests", "configurePreset": "test", "output": { "outputOnFailure": true } },
Expand Down
Loading