Skip to content

Better Out-of-the-box CMake Support #7904

@AndrewGaspar

Description

@AndrewGaspar

This is a bit of a vague feature request, but hoping it may at least start some good discussion.

My typical CMake workflow in a project is to have multiple build directories with different compilers, build types, configurations, etc. I might move between them depending on what I'm testing. Each of these directories may want to depend on a different version of a spackage. e.g. The intel build directory should depend on a matching intel compiled version of the spackage, similarly with gcc, clang, etc.

You can do this today by using a combination of spack load and find_package when configuring each compiler. However, it requires the user to have already installed the package and know how to correctly load it. The process of registering compilers, crafting the correct spack spec, and going through the process of installing dependencies is kind of complex for people not familiar with spack, and creates a bit of a learning curve for people new to a project that prefers to fill its dependencies from spack.

It would be convenient if there was a CMake module for Spack that made adding dependencies from Spack very easy. I'm imagining something like this in a CMakeLists.txt:

find_package(Spack REQUIRED)

find_spackage(Kokkos +cuda REQUIRED)

include_directories(${Kokkos_SPACK_INCLUDE_DIR})
link_directories(${Kokkos_SPACK_LINK_DIR})

find_spackage would, during CMake configuration, produce a compiler spec from the currently loaded CMAKE_C_COMPILER, CMAKE_CXX_COMPILER, etc., if one does not already exist, install Kokkos according to the spec (including any options specified in find_spackage) if it is not already installed, produce some variables like ${<package_name>_SPACK_INCLUDE_DIR}, and save those variables to the CMake cache.

This would make it much easier for people building the project for the first time - the only dependency they're required to install independently is spack. Once they've done that, their CMake configuration will take care of the rest of the work, and they don't have to understand spack too intimately. More-so, it makes adding new dependencies to a CMake project almost completely painless, kind of like Cargo or npm.

Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureA feature is missing in Spack

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions