镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[Doc suggestion] CMake Fetch Content #2802

Description

@TobiasWallner

Hi, and thanks for the library.

I just tried out xtensor and did so using CMakes FetchContent.

Maybe you would like to add the following way of importing your library into a project to the documentation.
I think that FetchContent is very convenient, because one only has to paste the following into the CMakeLists.txt, the library gets downloaded and built if necessary, and one does not need to do anything else making it almost plug and play.

# ======================== External Libraries =========================

include(FetchContent)

# -------- xtl --------
find_package(xtl QUIET)
if(NOT xtensor_FOUND)
    message(STATUS "xtl not found, attempting to access it via FetchContent")
    FetchContent_Declare(xtl GIT_REPOSITORY https://github.com/xtensor-stack/xtl.git GIT_TAG master)
    FetchContent_MakeAvailable(xtl)
else()
    message(STATUS "Found xtl library.")
endif()

# -------- xtensor --------
find_package(xtensor QUIET)
if(NOT xtensor_FOUND)
    message(STATUS "xtensor not found, attempting to access it via FetchContent")
    FetchContent_Declare(xtensor GIT_REPOSITORY https://github.com/xtensor-stack/xtensor.git GIT_TAG master)
    FetchContent_MakeAvailable(xtensor)
else()
    message(STATUS "Found xtensor library.")
endif()

# ================================== END ===============================

# project building process: 
set(PROJECT_NAME xtensor_tryout)
project(${PROJECT_NAME})

add_executable(${PROJECT_NAME}
	main.cpp
)

target_include_directories(${PROJECT_NAME} PUBLIC
	${xtensor_INCLUDE_DIRS}
)

target_link_libraries(${PROJECT_NAME} PUBLIC
	xtensor
)

Activity

  1. spectre-ns commented on Dec 22, 2024

    @spectre-ns
    Contributor

    Generally I think it is bad practice to use cmake like a package manager. Conda/Mamba/Vcpkg all work for xtensor. The environment-dev.yml file makes it pretty seamless as well.

  2. Radagan commented on May 30, 2025

    @Radagan

    When using this library as part of another library, which is my use case, a pure CMake solution using fetch_content is definitely the way to go. This is a cross-platform library that does not rely on Python or platform specific package managers.

    @TobiasWallner, Thank you for this post!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions