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

Add compiler check for the supported C++ standard in CMake #2414

Open
SimeonEhrig opened this issue Oct 23, 2024 · 4 comments
Open

Add compiler check for the supported C++ standard in CMake #2414

SimeonEhrig opened this issue Oct 23, 2024 · 4 comments
Milestone

Comments

@SimeonEhrig
Copy link
Member

In a offline discussion with @franzpoeschel he told me, that there are some confusion because alpaka does not compile with C++17 anymore. The reason is because the dev branch only supports C++20 and newer but the latest release (1.2) supports C++17.

Therefore an improvement would be to check the supported C++ standard of the compiler in CMake and display a message that the compiler does not support C++20 and maybe the message also to upgrade the compiler or use alpaka 1.2.

@SimeonEhrig SimeonEhrig added this to the 2.0.0 milestone Oct 23, 2024
@franzpoeschel
Copy link

Even when the compiler supports C++20, problems will occur when including Alpaka into a code that itself is still C++17. So, this check should be more specifically about the C++ configuration of downstream codes that include Alpaka. I expect that this will be a common pitfall during the time shortly after Alpaka switches to C++20.

@fwyzard
Copy link
Contributor

fwyzard commented Oct 23, 2024

Isn't it enough to check

#if __cplusplus < 202002L
#error Alpaka supports only C++ 20 and later standards
#endif

in one of the main alpaka headers ?

@SimeonEhrig
Copy link
Member Author

Isn't it enough to check

#if __cplusplus < 202002L
#error Alpaka supports only C++ 20 and later standards
#endif

in one of the main alpaka headers ?

Yes, and we should implement this for the approach if you don't use CMake. For CMake it would be a fall back, because in the configure phase of CMake, there is no code compiled. Therefore it will not fail at configure time. Therefore we have to solutions:

  1. Check if CMake has a feature to check the support C++ Standard
  2. Define a custom command, which is executed at configure time check if the example code can be compiled. If not, the C++ standard is not supported.

@SimeonEhrig
Copy link
Member Author

Looks like mdspan has our solution :-) If I compile with mdspan, I get following message if I run CMake configure:

[cmake] -- Detected support for C++23 standard

And I found the following CMake code in mdspan:

if("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
    set(CMAKE_CXX_STANDARD 23)
    message(STATUS "Detected support for C++23 standard")
  elseif("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
    set(CMAKE_CXX_STANDARD 20)
    message(STATUS "Detected support for C++20 standard")
  elseif("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
    set(CMAKE_CXX_STANDARD 17)
    message(STATUS "Detected support for C++17 standard")
  elseif("cxx_std_14" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
    set(CMAKE_CXX_STANDARD 14)
    message(STATUS "Detected support for C++14 standard")
  else()
    message(FATAL_ERROR "Cannot detect CXX_STANDARD of C++14 or newer.")
  endif()

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

No branches or pull requests

3 participants