Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc suggestion] CMake Fetch Content #2802

Open
TobiasWallner opened this issue Aug 18, 2024 · 1 comment
Open

[Doc suggestion] CMake Fetch Content #2802

TobiasWallner opened this issue Aug 18, 2024 · 1 comment

Comments

@TobiasWallner
Copy link

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
)
@spectre-ns
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants