Skip to content

could use cmake's CXX_STANDARD to set the C++ standard #257

@drew-parsons

Description

@drew-parsons

xtensor-blas, at least in tests in test/CMakeLists.txt and in benchmark/CMakeLists.txt, sets a default C++ standard together with an option (CPP17/CPP20/CPP23, depending on xtensor-blas version) to set a more recent standard.

When the C++ standard, alternative flags are used to allow for GNU, Intel, PGI, or for MSVC compilers.

But cmake already has a mechanism for managing the C++ standard, with the CXX_STANDARD variable, that can be given a custom value at the cmake command line via CMAKE_CXX_STANDARD (with CMAKE_CXX_STANDARD_REQUIRED=ON if it must be strict).

CXX_STANDARD also has a fallback mechanism (a "decay behavior") to drop back to an older standard if the compiler does not support the given standard. Depending on what xtensor-blas wants by setting the standard, it be made strict by using CXX_STANDARD_REQUIRED=ON if needed.

Using these flags puts the burden of tracking the right flag for each compiler onto cmake, so might allow xtensor-blas to work with more rare compilers.

https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html

https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html#variable:CMAKE_CXX_STANDARD
https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD_REQUIRED.html#prop_tgt:CXX_STANDARD_REQUIRED

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