Skip to content

Commit

Permalink
Merge pull request kokkos#230 from mhoemmen/Fix-CMake-CXX-version
Browse files Browse the repository at this point in the history
Permit C++ < 20
  • Loading branch information
mhoemmen authored Jun 7, 2022
2 parents 2f9397e + 96403aa commit 5e516d2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
50 changes: 40 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,72 @@ option(LINALG_ENABLE_EXAMPLES "Build examples." Off)

# Option to override which C++ standard to use
set(LINALG_CXX_STANDARD DETECT CACHE STRING "Override the default CXX_STANDARD to compile with.")
set_property(CACHE LINALG_CXX_STANDARD PROPERTY STRINGS DETECT 20)
set_property(CACHE LINALG_CXX_STANDARD PROPERTY STRINGS DETECT 14 17 20 23)

option(LINALG_ENABLE_CONCEPTS "Try to enable concepts support by giving extra flags." On)

################################################################################

# Make sure that the compiler supports C++20
if(LINALG_CXX_STANDARD STREQUAL "20")
# Decide on the standard to use
if(LINALG_CXX_STANDARD STREQUAL "17")
if("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(STATUS "Using C++17 standard")
set(CMAKE_CXX_STANDARD 17)
else()
message(FATAL_ERROR "Requested LINALG_CXX_STANDARD \"17\" not supported by provided C++ compiler")
endif()
elseif(LINALG_CXX_STANDARD STREQUAL "14")
if("cxx_std_14" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(STATUS "Using C++14 standard")
set(CMAKE_CXX_STANDARD 14)
else()
message(FATAL_ERROR "Requested LINALG_CXX_STANDARD \"14\" not supported by provided C++ compiler")
endif()
elseif(LINALG_CXX_STANDARD STREQUAL "20")
if("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(STATUS "Using C++20 standard")
set(CMAKE_CXX_STANDARD 20)
else()
message(FATAL_ERROR "Requested LINALG_CXX_STANDARD \"20\" not supported by provided C++ compiler")
endif()
elseif(LINALG_CXX_STANDARD STREQUAL "23")
if("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(STATUS "Using C++23 standard")
set(CMAKE_CXX_STANDARD 23)
else()
message(FATAL_ERROR "Requested LINALG_CXX_STANDARD \"23\" not supported by provided C++ compiler")
endif()
else()
if("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
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++20")
message(FATAL_ERROR "Cannot detect CXX_STANDARD of C++14 or newer.")
endif()
endif()

################################################################################

if(LINALG_ENABLE_CONCEPTS)
if(CMAKE_CXX_STANDARD STREQUAL "20")
if(CMAKE_CXX_STANDARD GREATER_EQUAL 20)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-fconcepts" COMPILER_SUPPORTS_FCONCEPTS)
check_cxx_compiler_flag("-fconcepts" COMPILER_SUPPORTS_FCONCEPTS)
if(COMPILER_SUPPORTS_FCONCEPTS)
message(STATUS "-- Using \"-fconcepts\" to enable concepts support")
message(STATUS "Using \"-fconcepts\" to enable concepts support")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fconcepts")
else()
CHECK_CXX_COMPILER_FLAG("-fconcepts-ts" COMPILER_SUPPORTS_FCONCEPTS_TS)
check_cxx_compiler_flag("-fconcepts-ts" COMPILER_SUPPORTS_FCONCEPTS_TS)
if(COMPILER_SUPPORTS_FCONCEPTS)
message(STATUS "-- Using \"-fconcepts-ts\" to enable concepts support")
message(STATUS "Using \"-fconcepts-ts\" to enable concepts support")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fconcepts-ts")
endif()
endif()
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

This is a reference implementation of P1673,
"A free function linear algebra interface based on the BLAS."
You can find the latest revision of P1673 at wg21.link/p1673.
You can find the latest submitted revision of P1673
[at this URL](https://wg21.link/p1673).

## Requirements

- CMake >= 3.17 (earlier versions may work, but are not tested)
- C++ build environment that supports C++20
- C++ build environment that supports C++17 or greater

## Tested compilers

We run github's automated tests on every pull request.
Automated tests use "ubuntu-latest",
which presumably defaults to a fairly new GCC.

Before we started requiring concepts, MSVC 2019 16.7.0 was able to build and run tests and examples as of 2021/05/27.
We will start testing on MSVC 2019 16.10 soon, which claims full support for C++20.
Other compilers, including MSVC 2019, have been tested in the past.

## Brief build instructions

Expand Down

0 comments on commit 5e516d2

Please sign in to comment.