Skip to content

How to integrate xtensor-blas in cmake by using fetch_content #244

@Roy-Kid

Description

@Roy-Kid

Hi everyone,

I try to use cmake to manage my all dependencies. Here is the code I want it to download xtensor and related packages automatically if find_package is failed:

# define target
file(GLOB_RECURSE MOLCORE_SRC "./*.cpp")
add_library(
    molcore_molcore
    ${MOLCORE_SRC}
)

# introduce deps
find_package(xtl QUIET)
find_package(xtensor QUIET)
find_package(xtensor-blas QUIET)

if(NOT xtl_FOUND)
  message("downloading xtl source...")
  FetchContent_Declare(
    xtl
    GIT_REPOSITORY https://github.com/xtensor-stack/xtl.git
    GIT_TAG        master
  )
  FetchContent_MakeAvailable(xtl)
else()
  message("found xtl ${xtl_VERSION}")
endif()
if(NOT xtensor_FOUND)
  message("downloading xtensor source...")
  FetchContent_Declare(
    xtensor
    GIT_REPOSITORY https://github.com/xtensor-stack/xtensor.git
    GIT_TAG        master
    FIND_PACKAGE_ARGS NAMES xtensor
  )
  FetchContent_MakeAvailable(xtensor)
  target_include_directories(molcore_molcore PUBLIC "$<BUILD_INTERFACE:${xtensor_SOURCE_DIR}/include>" "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
else()
  message("found xtensor ${xtensor_VERSION}")
  target_include_directories(molcore_molcore PUBLIC ${xtensor_INCLUDE_DIRS})
endif()
if(NOT xtensor-blas_FOUND)
  message("downloading xtensor-blas source...")
  FetchContent_Declare(
    xtensor-blas
    GIT_REPOSITORY https://github.com/xtensor-stack/xtensor-blas.git
    GIT_TAG        master
    FIND_PACKAGE_ARGS NAMES xtensor
  )
  FetchContent_MakeAvailable(xtensor-blas)
else()
  message("found xtensor-blas ${xtensor-blas_VERSION}")
endif()

It seems xtensor is found, but still error raises:

found xtl 0.7.2
found xtensor 0.23.10
downloading xtensor-blas source...
-- The C compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- xtensor-blas v0.21.0
CMake Error (dev) at build/dev/_deps/xtensor-blas-src/CMakeLists.txt:49 (set):
  uninitialized variable 'XTENSOR_VERSION_MAJOR'
This error is for project developers. Use -Wno-error=dev to suppress it.

Can you give a receipt about integrating xtensor using cmake instead of conda? I also tried spack, but it was also a little difficult to get a head-only file.

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