From 5bc18cc92a9e223f8a6f799a2462cb0acae64c70 Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Fri, 22 Aug 2025 13:06:30 +0200 Subject: [PATCH] [DOC] Add CPM example and test --- .github/workflows/ci_readme.yml | 51 ++++++++++++++++++++++++ CMakeLists.txt | 4 ++ README.md | 65 +++++++++++++++++++++++++++++++ test/CMakeLists.txt | 51 ++++++++++++++++++++++++ test/CPM/CMakeLists.txt | 18 +++++++++ test/CPM/example.cpp | 17 ++++++++ test/CPM/example.expected | 3 ++ test/CPM/example.expected.license | 3 ++ 8 files changed, 212 insertions(+) create mode 100644 .github/workflows/ci_readme.yml create mode 100644 test/CPM/CMakeLists.txt create mode 100644 test/CPM/example.cpp create mode 100644 test/CPM/example.expected create mode 100644 test/CPM/example.expected.license diff --git a/.github/workflows/ci_readme.yml b/.github/workflows/ci_readme.yml new file mode 100644 index 0000000..85fea5b --- /dev/null +++ b/.github/workflows/ci_readme.yml @@ -0,0 +1,51 @@ +# SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin +# SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik +# SPDX-License-Identifier: CC0-1.0 + +name: Update README + +on: + push: + branches: + - 'main' + workflow_dispatch: + +concurrency: + group: readme-${{ github.ref }} + cancel-in-progress: true + +env: + TZ: Europe/Berlin + +defaults: + run: + shell: bash -Eeuxo pipefail {0} + +jobs: + readme: + name: Update README + runs-on: ubuntu-latest + timeout-minutes: 15 + if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + token: ${{ secrets.SEQAN_ACTIONS_PAT }} + + - name: Import GPG key + uses: crazy-max/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.SEQAN_ACTIONS_GPG_KEY }} + passphrase: ${{ secrets.SEQAN_ACTIONS_GPG_PASSPHRASE }} + git_user_signingkey: true + git_commit_gpgsign: true + + - name: Update README + uses: dineshsonachalam/markdown-autodocs@v1.0.7 + with: + commit_author: seqan-actions[bot] + commit_user_email: seqan-actions@users.noreply.github.com + commit_message: "[MISC] Update README.md" + output_file_paths: '[./README.md]' + categories: '[code-block]' diff --git a/CMakeLists.txt b/CMakeLists.txt index cc1fb27..6ae961c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,10 @@ project (SEQAN_STD DESCRIPTION "Implementation of several C++23/26 views" ) +if (TARGET seqan::std) + return () +endif () + add_library (seqan-std INTERFACE) target_sources (seqan-std INTERFACE FILE_SET HEADERS diff --git a/README.md b/README.md index 4670417..4754b73 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,69 @@ SPDX-License-Identifier: CC-BY-4.0 --> # seqan-std + Implementation of several C++23 views + +## Quick start + +### CMake with CPM + + + +```cmake +# SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin +# SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik +# SPDX-License-Identifier: CC0-1.0 + +cmake_minimum_required (VERSION 3.25) + +project (example + LANGUAGES CXX) + +# CPM Documentation: +# Adding CPM: https://github.com/cpm-cmake/CPM.cmake?tab=readme-ov-file#adding-cpm +# Example : https://github.com/cpm-cmake/CPM.cmake?tab=readme-ov-file#full-cmakelists-example +# For CPM's example, "${CPM_FILE}" would be "cmake/CPM.cmake" +include (${CPM_FILE}) +CPMAddPackage ("gh:seqan/seqan-std#main") + +add_executable (example example.cpp) +target_link_libraries (example seqan::std) +``` + + +### Example + + + +```cpp +// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin +// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik +// SPDX-License-Identifier: CC0-1.0 + +#include +#include +#include + +#include + +int main() +{ + std::vector vec{"Hello", "World", "!"}; + + for (auto const [index, str] : seqan::stl::views::enumerate(vec)) + std::cout << index << ": " << str << '\n'; +} +``` + + +### Output + + + +```txt +0: Hello +1: World +2: ! +``` + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6074547..aa6d332 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -82,3 +82,54 @@ add_test (NAME "file_set_check" -P "${CMAKE_CURRENT_SOURCE_DIR}/check_file_set.cmake") set_tests_properties (header_test PROPERTIES DEPENDS file_set_check) + +################################################################################ +############################ CPM integration check ############################# +################################################################################ + +set (CPM_FILE "${CMAKE_CURRENT_BINARY_DIR}/CPM.cmake" CACHE STRING "Path to CPM.cmake") + +if (FETCHCONTENT_FULLY_DISCONNECTED AND NOT EXISTS "${CPM_FILE}") + message (STATUS "Not testing CPM integration.") + return () +endif () + +if (NOT EXISTS "${CPM_FILE}") + file (DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/CPM.cmake + ${CPM_FILE} + STATUS cpm_download_status) + + list (GET cpm_download_status 0 cpm_download_return_code) + list (GET cpm_download_status 1 cpm_download_message) + + if (NOT ${cpm_download_return_code} EQUAL 0) + message (WARNING "CPM download failed. " + "Exit code: ${cpm_download_return_code}. " + "Message: ${cpm_download_message}") + return () + endif () +endif () + +include (ExternalProject) + +ExternalProject_Add (CPM_integration_test + PREFIX CPM_integration_test + SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/CPM" + CMAKE_ARGS "-DCPM_FILE=${CPM_FILE}" + "-DCPM_seqan-std_SOURCE=${PROJECT_SOURCE_DIR}" + INSTALL_COMMAND "") + +ExternalProject_Get_Property (CPM_integration_test BINARY_DIR) +ExternalProject_Get_Property (CPM_integration_test SOURCE_DIR) + +message (STATUS "${SOURCE_DIR}") + +set (expected_output "0: Hello\n1: World\n2: !\n") + +add_test (NAME "example_test" COMMAND "${BINARY_DIR}/example") +set_tests_properties (example_test PROPERTIES + PASS_REGULAR_EXPRESSION "${expected_output}") + +add_test (NAME "example_output" COMMAND ${CMAKE_COMMAND} -E cat "${CMAKE_CURRENT_LIST_DIR}/CPM/example.expected") +set_tests_properties (example_output PROPERTIES + PASS_REGULAR_EXPRESSION "${expected_output}") diff --git a/test/CPM/CMakeLists.txt b/test/CPM/CMakeLists.txt new file mode 100644 index 0000000..a0ee40d --- /dev/null +++ b/test/CPM/CMakeLists.txt @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin +# SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik +# SPDX-License-Identifier: CC0-1.0 + +cmake_minimum_required (VERSION 3.25) + +project (example + LANGUAGES CXX) + +# CPM Documentation: +# Adding CPM: https://github.com/cpm-cmake/CPM.cmake?tab=readme-ov-file#adding-cpm +# Example : https://github.com/cpm-cmake/CPM.cmake?tab=readme-ov-file#full-cmakelists-example +# For CPM's example, "${CPM_FILE}" would be "cmake/CPM.cmake" +include (${CPM_FILE}) +CPMAddPackage ("gh:seqan/seqan-std#main") + +add_executable (example example.cpp) +target_link_libraries (example seqan::std) diff --git a/test/CPM/example.cpp b/test/CPM/example.cpp new file mode 100644 index 0000000..6d1fec2 --- /dev/null +++ b/test/CPM/example.cpp @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin +// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik +// SPDX-License-Identifier: CC0-1.0 + +#include +#include +#include + +#include + +int main() +{ + std::vector vec{"Hello", "World", "!"}; + + for (auto const [index, str] : seqan::stl::views::enumerate(vec)) + std::cout << index << ": " << str << '\n'; +} diff --git a/test/CPM/example.expected b/test/CPM/example.expected new file mode 100644 index 0000000..61fc567 --- /dev/null +++ b/test/CPM/example.expected @@ -0,0 +1,3 @@ +0: Hello +1: World +2: ! diff --git a/test/CPM/example.expected.license b/test/CPM/example.expected.license new file mode 100644 index 0000000..4251f0f --- /dev/null +++ b/test/CPM/example.expected.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin +SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik +SPDX-License-Identifier: CC0-1.0