Skip to content

Commit

Permalink
Check for supported compilers. (#2411)
Browse files Browse the repository at this point in the history
Utter a dire warning for those who try to build with outdated and/or weird compilers.
XLC is no longer a thing, so we remove checking for it.
  • Loading branch information
thorstenhater authored Oct 16, 2024
1 parent 5e6e241 commit 17d6f9f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 37 deletions.
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_EXPORT_COMPILE_COMMANDS "YES")

# Detect and deprecate xlC.

include("CheckCompilerXLC")

# Compiler options common to library, examples, tests, etc.

include("CompilerOptions")
check_supported_cxx()
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:${CXXOPT_WALL}>")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CUDA_STANDARD 20)
Expand Down
17 changes: 0 additions & 17 deletions cmake/CheckCompilerXLC.cmake

This file was deleted.

35 changes: 19 additions & 16 deletions cmake/CompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,28 @@ set(CXXOPT_WALL
# because there is nothing to fix on our side.

$<IF:$<CXX_COMPILER_ID:GNU>,-Wno-psabi,>

# Intel:
#
# Disable warning for unused template parameter
# this is raised by a templated function in the json library.

$<IF:$<CXX_COMPILER_ID:Intel>,-wd488,>)
)

# Check for supported compilers / versions
function(check_supported_cxx)
set(cxx_supported_ids "AppleClang" "GNU" "Clang")
set(cxx_supported_ver 15 12 12)
foreach(id ver IN ZIP_LISTS cxx_supported_ids cxx_supported_ver)
if(CMAKE_CXX_COMPILER_ID MATCHES ${id} AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL ${ver})
return()
endif()
endforeach()
message(WARNING "Found an unsupported compiler ${CMAKE_CXX_COMPILER_ID} version ${CMAKE_CXX_COMPILER_VERSION}, please consider switching to a supported version of GCC or Clang. Build failure is expected. We reserve the option to close all related issues without consideration.")
endfunction()


# Set ${optvar} in parent scope according to requested architecture.
# Architectures are given by the same names that GCC uses for its
# -mcpu or -march options.

function(set_arch_target optvar optvar_cuda_guarded arch)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# Correct compiler option unfortunately depends upon the target architecture family.
# Extract this information from running the configured compiler with --verbose.

try_compile(ignore ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/dummy.cpp COMPILE_DEFINITIONS --verbose OUTPUT_VARIABLE cc_out)
string(REPLACE "\n" ";" cc_out "${cc_out}")
set(target)
Expand All @@ -106,22 +110,22 @@ function(set_arch_target optvar optvar_cuda_guarded arch)
# architecture.
# See clang / gcc manuals and:
# https://maskray.me/blog/2022-08-28-march-mcpu-mtune
if (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" AND CMAKE_CXX_COMPILER_VERSION LESS 15)
set(arch_opt "")
if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
set(arch_opt "-march=${arch}")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if ("${target}" MATCHES "(arm64|aarch64)-.*")
if("${target}" MATCHES "(arm64|aarch64)-.*")
# on AArch64, this is correct, ...
set(arch_opt "-mcpu=${arch} -mtune=${arch}")
else()
# ... however on x86 mcpu _is_ mtune _and_ deprecated (since 2003!), but ...
set(arch_opt "-march=${arch}")
endif ()
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# ... clang likes march (and possibly mtune)
# See https://discourse.llvm.org/t/when-to-use-mcpu-versus-march/47953/9
set(arch_opt "-march=${arch} -mtune=${arch}")
else ()
message(STATUS "Falling back to -march=${arch} for compiler ${CMAKE_CXX_COMPILER_ID}")
else()
message(STATUS "Setting fallback architecture flags for ${CMAKE_CXX_COMPILER}.")
set(arch_opt "-march=${arch}")
endif()
endif()
Expand All @@ -140,7 +144,6 @@ function(set_arch_target optvar optvar_cuda_guarded arch)
else()
set("${optvar_cuda_guarded}" "${arch_opt}" PARENT_SCOPE)
endif()

endfunction()

# Set ${has_sve} and ${sve_length} in parent scope according to auto detection.
Expand Down

0 comments on commit 17d6f9f

Please sign in to comment.