Skip to content

Commit 05f1be7

Browse files
committed
Update CMake config and CI, improve example test
Bump CMake minimum version to 3.24 and update to cpp-library 5.0.0. Add CPM source cache to CMakePresets, remove unused install preset, and update CI workflow to use newer actions and a pinned Doxygen version. Clean up VSCode extension recommendations and settings, and improve enum_ops_example_test.cpp with MSVC warning suppression.
1 parent d212a13 commit 05f1be7

6 files changed

Lines changed: 44 additions & 44 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
runs-on: ubuntu-latest
9898

9999
steps:
100-
- uses: actions/checkout@v5
100+
- uses: actions/checkout@v6
101101

102102
- name: Configure CMake with clang-tidy
103103
run: cmake --preset=clang-tidy
@@ -117,10 +117,11 @@ jobs:
117117
contents: read
118118

119119
steps:
120-
- uses: actions/checkout@v5
120+
- uses: actions/checkout@v6
121121

122+
# ssciwr/doxygen-install@1.6.4
122123
- name: Install Doxygen
123-
uses: ssciwr/doxygen-install@v1
124+
uses: ssciwr/doxygen-install@501e53b879da7648ab392ee226f5b90e42148449
124125

125126
- name: Configure CMake
126127
run: cmake --preset=docs

.vscode/extensions.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"recommendations": [
33
"matepek.vscode-catch2-test-adapter",
44
"llvm-vs-code-extensions.vscode-clangd",
5-
"ms-vscode.live-server",
6-
"xaver.clang-format"
5+
"ms-vscode.live-server"
76
]
87
}

.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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +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(enum-ops)
5-
6-
# Setup cpp-library infrastructure
7-
if(PROJECT_IS_TOP_LEVEL AND NOT CPM_SOURCE_CACHE AND NOT DEFINED ENV{CPM_SOURCE_CACHE})
8-
set(CPM_SOURCE_CACHE "${CMAKE_SOURCE_DIR}/.cache/cpm" CACHE PATH "CPM source cache")
9-
message(STATUS "Setting cpm cache dir to: ${CPM_SOURCE_CACHE}")
10-
endif()
113
include(cmake/CPM.cmake)
124

13-
# Fetch cpp-library via CPM
14-
15-
# 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
167
# CPMAddPackage(
178
# NAME cpp-library
18-
# URL "${CMAKE_SOURCE_DIR}/../cpp-library"
9+
# SOURCE_DIR "${CMAKE_SOURCE_DIR}/../cpp-library"
1910
# )
20-
CPMAddPackage("gh:stlab/cpp-library#4f09b3b7f0abcc4ef1b39060ce03784920ce32e5")
21-
# CPMAddPackage("gh:stlab/cpp-library@4.0.5")
22-
11+
# CPMAddPackage("gh:stlab/cpp-library#65dbed9fff9a0331355bd51dc1e8156262390154")
12+
CPMAddPackage("gh:stlab/cpp-library@5.0.0")
2313
include(${cpp-library_SOURCE_DIR}/cpp-library.cmake)
2414

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+
2524
# Let cpp-library handle the project declaration and version detection
2625
cpp_library_setup(
2726
DESCRIPTION "Type-safe operators for enums"

CMakePresets.json

Lines changed: 11 additions & 21 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,21 +70,8 @@
6670
"BUILD_TESTING": "OFF",
6771
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
6872
"CMAKE_CXX_EXTENSIONS": "OFF",
69-
"CPP_LIBRARY_FORCE_INIT": "ON"
70-
}
71-
},
72-
{
73-
"name": "install",
74-
"displayName": "Local Install Test",
75-
"description": "Configuration for testing installation locally (installs to build/install/prefix)",
76-
"binaryDir": "${sourceDir}/build/install",
77-
"generator": "Ninja",
78-
"cacheVariables": {
79-
"CMAKE_BUILD_TYPE": "Release",
80-
"BUILD_TESTING": "OFF",
81-
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
82-
"CMAKE_CXX_EXTENSIONS": "OFF",
83-
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build/install/prefix"
73+
"CPP_LIBRARY_FORCE_INIT": "ON",
74+
"CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm"
8475
}
8576
}
8677
],
@@ -89,8 +80,7 @@
8980
{ "name": "test", "displayName": "Build Tests", "configurePreset": "test" },
9081
{ "name": "docs", "displayName": "Build Docs", "configurePreset": "docs", "targets": "docs" },
9182
{ "name": "clang-tidy", "displayName": "Build with Clang-Tidy", "configurePreset": "clang-tidy" },
92-
{ "name": "init", "displayName": "Initialize Templates", "configurePreset": "init" },
93-
{ "name": "install", "displayName": "Build for Local Install", "configurePreset": "install" }
83+
{ "name": "init", "displayName": "Initialize Templates", "configurePreset": "init" }
9484
],
9585
"testPresets": [
9686
{ "name": "test", "displayName": "Run All Tests", "configurePreset": "test", "output": { "outputOnFailure": true } },

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)