@@ -84,6 +84,92 @@ HTML_EXTRA_FILES = @AWESOME_CSS_PATH@/doxygen-awesome-darkmode-toggle.js \
8484HTML_HEADER =
8585USE_MDFILE_AS_MAINPAGE = README.md
8686" )
87+ set (CPP_LIBRARY_CI_TEMPLATE "name: CI
88+
89+ on:
90+ push:
91+ branches: [ main, develop ]
92+ pull_request:
93+ branches: [ main ]
94+
95+ jobs:
96+ test:
97+ strategy:
98+ matrix:
99+ os: [ubuntu-latest, macos-latest, windows-latest]
100+ compiler: [gcc, clang, msvc]
101+ exclude:
102+ - os: ubuntu-latest
103+ compiler: msvc
104+ - os: macos-latest
105+ compiler: msvc
106+ - os: macos-latest
107+ compiler: gcc
108+ - os: windows-latest
109+ compiler: gcc
110+ - os: windows-latest
111+ compiler: clang
112+
113+ runs-on: ${{ matrix.os }}
114+
115+ steps:
116+ - uses: actions/checkout@v4
117+
118+ - name: Setup Ninja
119+ uses: ashutoshvarma/setup-ninja@master
120+
121+ - name: Setup GCC
122+ if: matrix.compiler == 'gcc'
123+ uses: egor-tensin/setup-gcc@v1
124+ with:
125+ version: latest
126+
127+ - name: Setup Clang
128+ if: matrix.compiler == 'clang' && matrix.os == 'ubuntu-latest'
129+ uses: egor-tensin/setup-clang@v1
130+ with:
131+ version: latest
132+
133+ - name: Setup MSVC
134+ if: matrix.compiler == 'msvc'
135+ uses: ilammy/msvc-dev-cmd@v1
136+
137+ - name: Configure CMake
138+ run: cmake --preset=test
139+
140+ - name: Build
141+ run: cmake --build --preset=test
142+
143+ - name: Test
144+ run: ctest --preset=test
145+
146+ docs:
147+ runs-on: ubuntu-latest
148+ if: github.ref == 'refs/heads/main' && github.event_name == 'push'
149+
150+ steps:
151+ - uses: actions/checkout@v4
152+
153+ - name: Setup Ninja
154+ uses: ashutoshvarma/setup-ninja@master
155+
156+ - name: Install Doxygen
157+ run: sudo apt-get update && sudo apt-get install -y doxygen graphviz
158+
159+ - name: Configure CMake
160+ run: cmake --preset=docs
161+
162+ - name: Build Documentation
163+ run: cmake --build --preset=docs
164+
165+ - name: Deploy to GitHub Pages
166+ if: success() && '@ENABLE_DOCS_DEPLOYMENT@' == 'true'
167+ uses: peaceiris/actions-gh-pages@v3
168+ with:
169+ github_token: ${{ secrets.GITHUB_TOKEN }}
170+ publish_dir: ./build/docs/html
171+ destination_dir: @PROJECT_NAME@
172+ " )
87173
88174# === cpp-library-setup.cmake ===
89175function (_cpp_library_setup_core)
@@ -339,13 +425,77 @@ function(_cpp_library_generate_presets)
339425endfunction ()
340426
341427
428+ # === cpp-library-ci.cmake ===
429+ function (_cpp_library_setup_ci)
430+ set (options
431+ CI_DEPLOY_DOCS
432+ )
433+ set (oneValueArgs
434+ NAME
435+ VERSION
436+ DESCRIPTION
437+ )
438+ set (multiValueArgs
439+ CI_PLATFORMS
440+ CI_COMPILERS
441+ )
442+
443+ cmake_parse_arguments (ARG "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
444+
445+ # Set defaults
446+ if (NOT ARG_CI_PLATFORMS)
447+ set (ARG_CI_PLATFORMS "ubuntu-latest" "macos-latest" "windows-latest" )
448+ endif ()
449+ if (NOT ARG_CI_COMPILERS)
450+ set (ARG_CI_COMPILERS "gcc" "clang" "msvc" )
451+ endif ()
452+
453+ # Only generate CI files if they don't exist
454+ if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /.github/workflows/ci.yml" )
455+ # Create .github/workflows directory
456+ file (MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} /.github/workflows" )
457+
458+ # Determine template source
459+ if (DEFINED CPP_LIBRARY_CI_TEMPLATE)
460+ # Embedded template (packaged version)
461+ file (WRITE "${CMAKE_CURRENT_BINARY_DIR} /cpp-library-ci.yml.in" "${CPP_LIBRARY_CI_TEMPLATE} " )
462+ set (TEMPLATE_FILE "${CMAKE_CURRENT_BINARY_DIR} /cpp-library-ci.yml.in" )
463+ else ()
464+ # External template file (development version)
465+ set (TEMPLATE_FILE "${CPP_LIBRARY_ROOT} /templates/.github/workflows/ci.yml.in" )
466+ endif ()
467+
468+ # Configure template variables
469+ set (PROJECT_NAME "${ARG_NAME} " )
470+ set (PROJECT_VERSION "${ARG_VERSION} " )
471+ set (PROJECT_DESCRIPTION "${ARG_DESCRIPTION} " )
472+ if (ARG_CI_DEPLOY_DOCS)
473+ set (ENABLE_DOCS_DEPLOYMENT "true" )
474+ else ()
475+ set (ENABLE_DOCS_DEPLOYMENT "false" )
476+ endif ()
477+
478+ configure_file (
479+ "${TEMPLATE_FILE} "
480+ "${CMAKE_CURRENT_SOURCE_DIR} /.github/workflows/ci.yml"
481+ @ONLY
482+ )
483+
484+ message (STATUS "Generated .github/workflows/ci.yml for ${ARG_NAME} " )
485+ endif ()
486+
487+ endfunction ()
488+
489+
342490# === Main cpp_library_setup function ===
343491# Main entry point function - users call this to set up their library
344492function (cpp_library_setup)
345493 # Parse arguments
346494 set (options
347495 CUSTOM_INSTALL # Skip default installation
348496 NO_PRESETS # Skip CMakePresets.json generation
497+ ENABLE_CI # Generate CI files
498+ CI_DEPLOY_DOCS # Enable docs deployment in CI
349499 )
350500 set (oneValueArgs
351501 NAME # Project name (e.g., "stlab-enum-ops")
@@ -361,6 +511,8 @@ function(cpp_library_setup)
361511 TESTS # Test executables to build
362512 DOCS_EXCLUDE_SYMBOLS # Symbols to exclude from docs
363513 ADDITIONAL_DEPS # Extra CPM dependencies
514+ CI_PLATFORMS # CI platforms (default: ubuntu-latest, macos-latest, windows-latest)
515+ CI_COMPILERS # CI compilers (default: gcc, clang, msvc)
364516 )
365517
366518 cmake_parse_arguments (ARG "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
@@ -419,6 +571,17 @@ function(cpp_library_setup)
419571 )
420572 endif ()
421573
574+ if (ARG_ENABLE_CI AND PROJECT_IS_TOP_LEVEL)
575+ _cpp_library_setup_ci(
576+ NAME "${ARG_NAME} "
577+ VERSION "${ARG_VERSION} "
578+ DESCRIPTION "${ARG_DESCRIPTION} "
579+ CI_PLATFORMS "${ARG_CI_PLATFORMS} "
580+ CI_COMPILERS "${ARG_CI_COMPILERS} "
581+ CI_DEPLOY_DOCS "${ARG_CI_DEPLOY_DOCS} "
582+ )
583+ endif ()
584+
422585 # Build examples if specified
423586 if (PROJECT_IS_TOP_LEVEL AND ARG_EXAMPLES)
424587 foreach (example IN LISTS ARG_EXAMPLES)
0 commit comments