From b3af0c176161b7520653f138dfd213529eb84772 Mon Sep 17 00:00:00 2001 From: Marco Barbone Date: Tue, 10 Nov 2026 10:19:57 -0500 Subject: [PATCH] Document FetchContent usage and test it Show how to consume xsimd with FetchContent. Drop the CPM.cmake section, as the reviewer asked. The recipe is a small project under .github/cmake-test-fetchcontent. The docs include its CMakeLists.txt with literalinclude, so the page and the test cannot drift. The cmake.yml workflow builds the recipe on each push and pull request, using the checkout as the xsimd source through FETCHCONTENT_SOURCE_DIR_XSIMD. Assisted-by: Hermes Agent --- .github/cmake-test-fetchcontent/CMakeLists.txt | 11 +++++++++++ .github/cmake-test-fetchcontent/main.cpp | 15 +++++++++++++++ .github/workflows/cmake.yml | 7 +++++++ docs/source/installation.rst | 15 +++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 .github/cmake-test-fetchcontent/CMakeLists.txt create mode 100644 .github/cmake-test-fetchcontent/main.cpp diff --git a/.github/cmake-test-fetchcontent/CMakeLists.txt b/.github/cmake-test-fetchcontent/CMakeLists.txt new file mode 100644 index 000000000..3234625bf --- /dev/null +++ b/.github/cmake-test-fetchcontent/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.19) +project(fetchcontent-test VERSION 0.0.1) + +include(FetchContent) +FetchContent_Declare(xsimd + GIT_REPOSITORY https://github.com/xtensor-stack/xsimd.git + GIT_TAG 14.3.0) +FetchContent_MakeAvailable(xsimd) + +add_executable(app main.cpp) +target_link_libraries(app PRIVATE xsimd) diff --git a/.github/cmake-test-fetchcontent/main.cpp b/.github/cmake-test-fetchcontent/main.cpp new file mode 100644 index 000000000..6307a5f9b --- /dev/null +++ b/.github/cmake-test-fetchcontent/main.cpp @@ -0,0 +1,15 @@ +#include "xsimd/xsimd.hpp" + +#include + +int main() +{ + xsimd::batch a(1.0), b(2.0); + double res = (a + b).get(0); + if (res != 3.0) + { + std::fprintf(stderr, "check failed: got %f, expected 3\n", res); + return 1; + } + return 0; +} diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 0ff2cd0a4..9d1771feb 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -23,4 +23,11 @@ jobs: ls $PWD/../_install/share/cmake/xsimd cmake . -DCMAKE_PREFIX_PATH=$PWD/../_install/share/cmake/xsimd cmake --build . + - name: Check FetchContent + run: | + cmake -S ${{ github.workspace }}/.github/cmake-test-fetchcontent \ + -B _fetchcontent_build \ + -D FETCHCONTENT_SOURCE_DIR_XSIMD=${{ github.workspace }} + cmake --build _fetchcontent_build + ./_fetchcontent_build/app diff --git a/docs/source/installation.rst b/docs/source/installation.rst index 63e4fe5ba..87a51a654 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -87,3 +87,18 @@ as forward other xsimd requirements (minimum C++ version for instance). find_package(xsimd REQUIRED) target_link_libraries(myproject PRIVATE xsimd) + +Using FetchContent +~~~~~~~~~~~~~~~~~~ + +CMake can download `xsimd` at configure time with `FetchContent `_. The recipe below is the ``CMakeLists.txt`` of ``.github/cmake-test-fetchcontent``. CI builds it on every pull request: + +.. literalinclude:: ../../.github/cmake-test-fetchcontent/CMakeLists.txt + :language: cmake + +The ``xsimd`` target requires C++17. The program in ``main.cpp`` uses ``xsimd::batch``. From the ``.github/cmake-test-fetchcontent`` directory, build the recipe with: + +.. code:: bash + + cmake -B build/ + cmake --build build/