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

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