Skip to content

Commit ecbab3e

Browse files
committed
Add BGL Modern: C++20 graph library foundation
- Add C++20 version checking and compiler detection (version.hpp) - Add graph_traits with type aliases and direction/parallel edge traits - Add C++20 concepts: Graph, IncidenceGraph, BidirectionalGraph, VertexListGraph, EdgeListGraph, AdjacencyGraph, MutableGraph, PropertyGraph - Add range-returning free functions: vertices(), edges(), out_edges(), in_edges(), adjacent_vertices(), source(), target(), out_neighbors(), in_neighbors() - Add CMake build system with proper C++20 configuration - Add comprehensive test suite covering all concepts and range functions - Add GitHub Actions CI workflow All tests pass with GCC 15 in C++20 mode.
1 parent 54a9491 commit ecbab3e

32 files changed

+4514
-0
lines changed
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
name: BGL Modern CI
2+
3+
on:
4+
push:
5+
branches: [main, develop, bgl2]
6+
paths:
7+
- 'libs/graph/modern/**'
8+
- '.github/workflows/bgl-modern-ci.yml'
9+
pull_request:
10+
branches: [main, develop]
11+
paths:
12+
- 'libs/graph/modern/**'
13+
- '.github/workflows/bgl-modern-ci.yml'
14+
workflow_dispatch:
15+
16+
jobs:
17+
# ===========================================================================
18+
# GCC Tests (Linux)
19+
# ===========================================================================
20+
gcc:
21+
name: GCC ${{ matrix.gcc }} - ${{ matrix.build_type }}
22+
runs-on: ubuntu-24.04
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
gcc: ['10', '11', '12', '13', '14']
27+
build_type: [Release, Debug]
28+
include:
29+
- gcc: '10'
30+
install: g++-10
31+
- gcc: '11'
32+
install: g++-11
33+
- gcc: '12'
34+
install: g++-12
35+
- gcc: '13'
36+
install: g++-13
37+
- gcc: '14'
38+
install: g++-14
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Install GCC ${{ matrix.gcc }}
44+
run: |
45+
sudo apt-get update
46+
sudo apt-get install -y ${{ matrix.install }}
47+
48+
- name: Configure
49+
run: |
50+
cmake -S libs/graph/modern -B build \
51+
-DCMAKE_CXX_COMPILER=g++-${{ matrix.gcc }} \
52+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
53+
-DBGL_MODERN_BUILD_TESTS=ON \
54+
-DBGL_MODERN_BUILD_EXAMPLES=ON
55+
56+
- name: Build
57+
run: cmake --build build --parallel $(nproc)
58+
59+
- name: Test
60+
run: ctest --test-dir build --output-on-failure
61+
62+
# ===========================================================================
63+
# Clang Tests (Linux)
64+
# ===========================================================================
65+
clang:
66+
name: Clang ${{ matrix.clang }} - ${{ matrix.build_type }}
67+
runs-on: ubuntu-24.04
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
clang: ['13', '14', '15', '16', '17', '18']
72+
build_type: [Release, Debug]
73+
74+
steps:
75+
- uses: actions/checkout@v4
76+
77+
- name: Install Clang ${{ matrix.clang }}
78+
run: |
79+
wget https://apt.llvm.org/llvm.sh
80+
chmod +x llvm.sh
81+
sudo ./llvm.sh ${{ matrix.clang }}
82+
sudo apt-get install -y libc++-${{ matrix.clang }}-dev libc++abi-${{ matrix.clang }}-dev
83+
84+
- name: Configure (libstdc++)
85+
run: |
86+
cmake -S libs/graph/modern -B build \
87+
-DCMAKE_CXX_COMPILER=clang++-${{ matrix.clang }} \
88+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
89+
-DBGL_MODERN_BUILD_TESTS=ON \
90+
-DBGL_MODERN_BUILD_EXAMPLES=ON
91+
92+
- name: Build
93+
run: cmake --build build --parallel $(nproc)
94+
95+
- name: Test
96+
run: ctest --test-dir build --output-on-failure
97+
98+
# ===========================================================================
99+
# MSVC Tests (Windows)
100+
# ===========================================================================
101+
msvc:
102+
name: MSVC ${{ matrix.vs }} - ${{ matrix.build_type }}
103+
runs-on: ${{ matrix.os }}
104+
strategy:
105+
fail-fast: false
106+
matrix:
107+
include:
108+
- os: windows-2022
109+
vs: '2022'
110+
generator: 'Visual Studio 17 2022'
111+
build_type: Release
112+
- os: windows-2022
113+
vs: '2022'
114+
generator: 'Visual Studio 17 2022'
115+
build_type: Debug
116+
117+
steps:
118+
- uses: actions/checkout@v4
119+
120+
- name: Configure
121+
run: |
122+
cmake -S libs/graph/modern -B build `
123+
-G "${{ matrix.generator }}" `
124+
-DBGL_MODERN_BUILD_TESTS=ON `
125+
-DBGL_MODERN_BUILD_EXAMPLES=ON
126+
127+
- name: Build
128+
run: cmake --build build --config ${{ matrix.build_type }} --parallel
129+
130+
- name: Test
131+
run: ctest --test-dir build --config ${{ matrix.build_type }} --output-on-failure
132+
133+
# ===========================================================================
134+
# macOS Tests (AppleClang)
135+
# ===========================================================================
136+
macos:
137+
name: macOS ${{ matrix.os }} - ${{ matrix.build_type }}
138+
runs-on: ${{ matrix.os }}
139+
strategy:
140+
fail-fast: false
141+
matrix:
142+
os: [macos-14, macos-15]
143+
build_type: [Release, Debug]
144+
145+
steps:
146+
- uses: actions/checkout@v4
147+
148+
- name: Configure
149+
run: |
150+
cmake -S libs/graph/modern -B build \
151+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
152+
-DBGL_MODERN_BUILD_TESTS=ON \
153+
-DBGL_MODERN_BUILD_EXAMPLES=ON
154+
155+
- name: Build
156+
run: cmake --build build --parallel $(sysctl -n hw.ncpu)
157+
158+
- name: Test
159+
run: ctest --test-dir build --output-on-failure
160+
161+
# ===========================================================================
162+
# Sanitizers (Linux)
163+
# ===========================================================================
164+
sanitizers:
165+
name: ${{ matrix.sanitizer }} Sanitizer
166+
runs-on: ubuntu-24.04
167+
strategy:
168+
fail-fast: false
169+
matrix:
170+
sanitizer: [address, undefined, thread]
171+
172+
steps:
173+
- uses: actions/checkout@v4
174+
175+
- name: Configure
176+
run: |
177+
cmake -S libs/graph/modern -B build \
178+
-DCMAKE_CXX_COMPILER=clang++-18 \
179+
-DCMAKE_BUILD_TYPE=Debug \
180+
-DCMAKE_CXX_FLAGS="-fsanitize=${{ matrix.sanitizer }} -fno-omit-frame-pointer" \
181+
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=${{ matrix.sanitizer }}" \
182+
-DBGL_MODERN_BUILD_TESTS=ON
183+
184+
- name: Build
185+
run: cmake --build build --parallel $(nproc)
186+
187+
- name: Test
188+
run: ctest --test-dir build --output-on-failure
189+
env:
190+
ASAN_OPTIONS: detect_leaks=1
191+
UBSAN_OPTIONS: print_stacktrace=1
192+
193+
# ===========================================================================
194+
# Code Coverage
195+
# ===========================================================================
196+
coverage:
197+
name: Code Coverage
198+
runs-on: ubuntu-24.04
199+
steps:
200+
- uses: actions/checkout@v4
201+
202+
- name: Install lcov
203+
run: sudo apt-get install -y lcov
204+
205+
- name: Configure
206+
run: |
207+
cmake -S libs/graph/modern -B build \
208+
-DCMAKE_CXX_COMPILER=g++-14 \
209+
-DCMAKE_BUILD_TYPE=Debug \
210+
-DCMAKE_CXX_FLAGS="--coverage" \
211+
-DCMAKE_EXE_LINKER_FLAGS="--coverage" \
212+
-DBGL_MODERN_BUILD_TESTS=ON
213+
214+
- name: Build
215+
run: cmake --build build --parallel $(nproc)
216+
217+
- name: Test
218+
run: ctest --test-dir build --output-on-failure
219+
220+
- name: Generate Coverage Report
221+
run: |
222+
lcov --capture --directory build --output-file coverage.info
223+
lcov --remove coverage.info '/usr/*' --output-file coverage.info
224+
lcov --list coverage.info

modern/CMakeLists.txt

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# BGL Modern - C++20 Graph Library
2+
# Modernized Boost Graph Library with C++20 concepts, ranges, and standard library only
3+
#
4+
# Copyright 2024 Boost Authors
5+
# Distributed under the Boost Software License, Version 1.0.
6+
# https://www.boost.org/LICENSE_1_0.txt
7+
8+
cmake_minimum_required(VERSION 3.20)
9+
10+
project(bgl_modern
11+
VERSION 2.0.0
12+
DESCRIPTION "Modernized Boost Graph Library for C++20"
13+
LANGUAGES CXX
14+
)
15+
16+
# ==============================================================================
17+
# C++20 Requirement
18+
# ==============================================================================
19+
20+
set(CMAKE_CXX_STANDARD 20)
21+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
22+
set(CMAKE_CXX_EXTENSIONS OFF)
23+
24+
# Verify compiler support
25+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
26+
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0")
27+
message(FATAL_ERROR "GCC 10+ required for C++20 concepts and ranges. Found: ${CMAKE_CXX_COMPILER_VERSION}")
28+
endif()
29+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
30+
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "13.0")
31+
message(FATAL_ERROR "Clang 13+ required for C++20 concepts and ranges. Found: ${CMAKE_CXX_COMPILER_VERSION}")
32+
endif()
33+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
34+
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.29")
35+
message(FATAL_ERROR "MSVC 2019 16.10+ required for C++20 concepts and ranges. Found: ${CMAKE_CXX_COMPILER_VERSION}")
36+
endif()
37+
else()
38+
message(WARNING "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}. C++20 support not verified.")
39+
endif()
40+
41+
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
42+
message(STATUS "C++ Standard: C++${CMAKE_CXX_STANDARD}")
43+
44+
# ==============================================================================
45+
# Build Options
46+
# ==============================================================================
47+
48+
option(BGL_MODERN_BUILD_TESTS "Build unit tests" ON)
49+
option(BGL_MODERN_BUILD_EXAMPLES "Build example programs" ON)
50+
option(BGL_MODERN_BUILD_BENCHMARKS "Build performance benchmarks" OFF)
51+
option(BGL_MODERN_ENABLE_WARNINGS "Enable strict compiler warnings" ON)
52+
53+
# ==============================================================================
54+
# Compiler Warnings
55+
# ==============================================================================
56+
57+
if(BGL_MODERN_ENABLE_WARNINGS)
58+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
59+
add_compile_options(
60+
-Wall
61+
-Wextra
62+
-Wpedantic
63+
-Wconversion
64+
-Wshadow
65+
-Wno-unused-parameter
66+
)
67+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
68+
add_compile_options(
69+
/W4
70+
/permissive-
71+
)
72+
endif()
73+
endif()
74+
75+
# ==============================================================================
76+
# Header-Only Library Target
77+
# ==============================================================================
78+
79+
add_library(bgl_modern INTERFACE)
80+
add_library(bgl::modern ALIAS bgl_modern)
81+
82+
target_include_directories(bgl_modern INTERFACE
83+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
84+
$<INSTALL_INTERFACE:include>
85+
)
86+
87+
target_compile_features(bgl_modern INTERFACE cxx_std_20)
88+
89+
# ==============================================================================
90+
# Tests
91+
# ==============================================================================
92+
93+
if(BGL_MODERN_BUILD_TESTS)
94+
enable_testing()
95+
add_subdirectory(test)
96+
endif()
97+
98+
# ==============================================================================
99+
# Examples
100+
# ==============================================================================
101+
102+
if(BGL_MODERN_BUILD_EXAMPLES)
103+
add_subdirectory(examples)
104+
endif()
105+
106+
# ==============================================================================
107+
# Installation
108+
# ==============================================================================
109+
110+
include(GNUInstallDirs)
111+
include(CMakePackageConfigHelpers)
112+
113+
install(TARGETS bgl_modern
114+
EXPORT bgl_modern_targets
115+
)
116+
117+
install(DIRECTORY include/
118+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
119+
)
120+
121+
install(EXPORT bgl_modern_targets
122+
FILE bgl_modern-targets.cmake
123+
NAMESPACE bgl::
124+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bgl_modern
125+
)
126+
127+
configure_package_config_file(
128+
${CMAKE_CURRENT_SOURCE_DIR}/cmake/bgl_modern-config.cmake.in
129+
${CMAKE_CURRENT_BINARY_DIR}/bgl_modern-config.cmake
130+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bgl_modern
131+
)
132+
133+
write_basic_package_version_file(
134+
${CMAKE_CURRENT_BINARY_DIR}/bgl_modern-config-version.cmake
135+
VERSION ${PROJECT_VERSION}
136+
COMPATIBILITY SameMajorVersion
137+
)
138+
139+
install(FILES
140+
${CMAKE_CURRENT_BINARY_DIR}/bgl_modern-config.cmake
141+
${CMAKE_CURRENT_BINARY_DIR}/bgl_modern-config-version.cmake
142+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bgl_modern
143+
)
144+
145+
# ==============================================================================
146+
# Summary
147+
# ==============================================================================
148+
149+
message(STATUS "")
150+
message(STATUS "BGL Modern ${PROJECT_VERSION} Configuration:")
151+
message(STATUS " Build tests: ${BGL_MODERN_BUILD_TESTS}")
152+
message(STATUS " Build examples: ${BGL_MODERN_BUILD_EXAMPLES}")
153+
message(STATUS " Build benchmarks: ${BGL_MODERN_BUILD_BENCHMARKS}")
154+
message(STATUS " Warnings enabled: ${BGL_MODERN_ENABLE_WARNINGS}")
155+
message(STATUS "")

0 commit comments

Comments
 (0)