Skip to content

Commit ba18a5a

Browse files
authored
Merge pull request #4 from stlab/sean-parent/cpp-library-update
Updating to cpp-library 5.0 with install support.
2 parents f8bf2d5 + 05f1be7 commit ba18a5a

File tree

6 files changed

+106
-39
lines changed

6 files changed

+106
-39
lines changed

.github/workflows/ci.yml

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,23 @@ on:
1313

1414
jobs:
1515
test:
16+
name: Test (${{ matrix.name }})
1617
strategy:
18+
fail-fast: false
1719
matrix:
18-
os: [ubuntu-latest, macos-latest, windows-latest]
19-
compiler: [gcc, clang, msvc]
20-
exclude:
21-
- os: ubuntu-latest
22-
compiler: msvc
23-
- os: macos-latest
24-
compiler: msvc
25-
- os: macos-latest
26-
compiler: gcc
27-
- os: windows-latest
28-
compiler: gcc
29-
- os: windows-latest
30-
compiler: clang
20+
include:
21+
- name: Ubuntu GCC
22+
os: ubuntu-latest
23+
cc: gcc
24+
cxx: g++
25+
- name: Ubuntu Clang
26+
os: ubuntu-latest
27+
cc: clang
28+
cxx: clang++
29+
- name: macOS
30+
os: macos-latest
31+
- name: Windows
32+
os: windows-latest
3133

3234
runs-on: ${{ matrix.os }}
3335

@@ -36,18 +38,66 @@ jobs:
3638

3739
- name: Configure CMake
3840
run: cmake --preset=test
41+
env:
42+
CC: ${{ matrix.cc }}
43+
CXX: ${{ matrix.cxx }}
44+
if: ${{ matrix.cc }}
45+
46+
- name: Configure CMake
47+
run: cmake --preset=test
48+
if: ${{ !matrix.cc }}
3949

4050
- name: Build
4151
run: cmake --build --preset=test
4252

4353
- name: Test
4454
run: ctest --preset=test
4555

56+
- name: Build and Install
57+
run: |
58+
cmake --preset=default
59+
cmake --build --preset=default
60+
cmake --install build/default --prefix ${{ runner.temp }}/install
61+
env:
62+
CC: ${{ matrix.cc }}
63+
CXX: ${{ matrix.cxx }}
64+
if: ${{ matrix.cc }}
65+
66+
- name: Build and Install
67+
run: |
68+
cmake --preset=default
69+
cmake --build --preset=default
70+
cmake --install build/default --prefix ${{ runner.temp }}/install
71+
if: ${{ !matrix.cc }}
72+
73+
- name: Test find_package
74+
shell: bash
75+
run: |
76+
# Create a minimal test to verify the installation works with find_package
77+
mkdir -p ${{ runner.temp }}/test-find-package
78+
cd ${{ runner.temp }}/test-find-package
79+
80+
# Create test CMakeLists.txt
81+
cat > CMakeLists.txt << EOF
82+
cmake_minimum_required(VERSION 3.20)
83+
project(test-find-package CXX)
84+
85+
find_package(stlab-enum-ops REQUIRED)
86+
87+
message(STATUS "Successfully found stlab-enum-ops")
88+
EOF
89+
90+
# Convert paths to forward slashes for CMake (works on all platforms)
91+
INSTALL_PREFIX=$(echo '${{ runner.temp }}/install' | sed 's|\\|/|g')
92+
93+
# Test find_package with CMAKE_PREFIX_PATH
94+
cmake -B build -S . -DCMAKE_PREFIX_PATH="${INSTALL_PREFIX}"
95+
4696
clang-tidy:
4797
runs-on: ubuntu-latest
4898

4999
steps:
50-
- uses: actions/checkout@v5
100+
- uses: actions/checkout@v6
51101

52102
- name: Configure CMake with clang-tidy
53103
run: cmake --preset=clang-tidy
@@ -67,10 +117,11 @@ jobs:
67117
contents: read
68118

69119
steps:
70-
- uses: actions/checkout@v5
120+
- uses: actions/checkout@v6
71121

122+
# ssciwr/doxygen-install@1.6.4
72123
- name: Install Doxygen
73-
uses: ssciwr/doxygen-install@v1
124+
uses: ssciwr/doxygen-install@501e53b879da7648ab392ee226f5b90e42148449
74125

75126
- name: Configure CMake
76127
run: cmake --preset=docs

.vscode/extensions.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
2-
"_comment": "Auto-generated from cpp-library (https://github.com/stlab/cpp-library) - Do not edit this file directly",
32
"recommendations": [
43
"matepek.vscode-catch2-test-adapter",
54
"llvm-vs-code-extensions.vscode-clangd",
6-
"ms-vscode.live-server",
7-
"xaver.clang-format"
5+
"ms-vscode.live-server"
86
]
97
}

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"cSpell.words": [
33
"dontinclude",
44
"NOLINTNEXTLINE"
5-
]
5+
],
6+
"cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json"
67
}

CMakeLists.txt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
cmake_minimum_required(VERSION 3.20)
1+
cmake_minimum_required(VERSION 3.24)
22

3-
# Project declaration - cpp_library_setup will use this name and detect version from git tags
4-
project(stlab-enum-ops)
5-
6-
# Setup cpp-library infrastructure
7-
if(PROJECT_IS_TOP_LEVEL)
8-
set(CPM_SOURCE_CACHE ${CMAKE_SOURCE_DIR}/.cache/cpm CACHE PATH "CPM cache")
9-
endif()
103
include(cmake/CPM.cmake)
114

12-
# Fetch cpp-library via CPM
13-
14-
# https://github.com/stlab/cpp-library/releases
5+
# Fetch cpp-library before project()
6+
# Check https://github.com/stlab/cpp-library/releases for the latest version
157
# CPMAddPackage(
168
# NAME cpp-library
17-
# URL "${CMAKE_SOURCE_DIR}/../cpp-library"
9+
# SOURCE_DIR "${CMAKE_SOURCE_DIR}/../cpp-library"
1810
# )
19-
CPMAddPackage("gh:stlab/cpp-library@4.0.5")
11+
# CPMAddPackage("gh:stlab/cpp-library#65dbed9fff9a0331355bd51dc1e8156262390154")
12+
CPMAddPackage("gh:stlab/cpp-library@5.0.0")
2013
include(${cpp-library_SOURCE_DIR}/cpp-library.cmake)
2114

15+
# Enable dependency tracking before project()
16+
cpp_library_enable_dependency_tracking()
17+
18+
# Now declare project
19+
project(enum-ops)
20+
21+
# Enable CTest infrastructure (required for tests/examples to work)
22+
include(CTest)
23+
2224
# Let cpp-library handle the project declaration and version detection
2325
cpp_library_setup(
2426
DESCRIPTION "Type-safe operators for enums"

CMakePresets.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"CMAKE_BUILD_TYPE": "Release",
1212
"BUILD_TESTING": "OFF",
1313
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
14-
"CMAKE_CXX_EXTENSIONS": "OFF"
14+
"CMAKE_CXX_EXTENSIONS": "OFF",
15+
"CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm"
1516
}
1617
},
1718
{
@@ -24,7 +25,8 @@
2425
"CMAKE_BUILD_TYPE": "Debug",
2526
"BUILD_TESTING": "ON",
2627
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
27-
"CMAKE_CXX_EXTENSIONS": "OFF"
28+
"CMAKE_CXX_EXTENSIONS": "OFF",
29+
"CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm"
2830
}
2931
},
3032
{
@@ -38,7 +40,8 @@
3840
"BUILD_TESTING": "OFF",
3941
"BUILD_DOCS": "ON",
4042
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
41-
"CMAKE_CXX_EXTENSIONS": "OFF"
43+
"CMAKE_CXX_EXTENSIONS": "OFF",
44+
"CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm"
4245
}
4346
},
4447
{
@@ -52,7 +55,8 @@
5255
"BUILD_TESTING": "ON",
5356
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
5457
"CMAKE_CXX_EXTENSIONS": "OFF",
55-
"CMAKE_CXX_CLANG_TIDY": "clang-tidy"
58+
"CMAKE_CXX_CLANG_TIDY": "clang-tidy",
59+
"CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm"
5660
}
5761
},
5862
{
@@ -66,7 +70,8 @@
6670
"BUILD_TESTING": "OFF",
6771
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
6872
"CMAKE_CXX_EXTENSIONS": "OFF",
69-
"CPP_LIBRARY_FORCE_INIT": "ON"
73+
"CPP_LIBRARY_FORCE_INIT": "ON",
74+
"CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm"
7075
}
7176
}
7277
],

examples/enum_ops_example_test.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
22
#include <doctest/doctest.h>
33

4+
#if defined(_MSC_VER) && !defined(__clang__)
5+
#pragma warning(push)
6+
#pragma warning(disable : 4010)
7+
#endif
8+
49
#include <stlab/enum_ops.hpp> /// [EXAMPLE_START]
510

611
#include <iostream>
@@ -18,12 +23,17 @@ int main() {
1823
foo b{foo_8};
1924
foo c{a | b};
2025
std::cout << a << " " << b << " " << c << "\n";
21-
26+
2227
// Bitset operations on enum class
2328
views x = views::text | views::icon;
2429
bool has_text = (x & views::text) == views::text;
2530
bool has_preview = (x & views::preview) == views::preview;
2631
std::cout << has_text << " " << has_preview << "\n";
2732
} /// [EXAMPLE_END]
2833

34+
35+
#if defined(_MSC_VER) && !defined(__clang__)
36+
#pragma warning(pop)
37+
#endif
38+
2939
TEST_CASE("Example: common use cases") { CHECK_NOTHROW(run_example()); }

0 commit comments

Comments
 (0)