Skip to content

Commit

Permalink
cmake: check compiler supports C++17 sufficiently (apache#18354)
Browse files Browse the repository at this point in the history
By default cmake accepts any compiler that supports at least some part of C++17.
In practice this leads to hard to understand error messages at later stages
during compilation, as for example gcc5 supports part of C++17 but does not
support C++17 sufficiently to compile MXNet.
  • Loading branch information
leezu authored and AntiZpvoh committed Jul 6, 2020
1 parent 32afdb4 commit 1194f0b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON) # GNU extensions used by src/operator/random/shuffle_op.cc

# Sanity checks for some popular compilers. Make sure their version is
# sufficient. Cmake also automatically checks if a compiler supports c++17. But
# some compilers claim they support c++17 without actually implementing crucial
# parts of the standard leading to hard to understand compilation errors.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
message(FATAL_ERROR "MXNet 2 requires a C++17 compatible compiler. Please update to GCC version 7 or newer.")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
message(FATAL_ERROR "MXNet 2 requires a C++17 compatible compiler. Please update to Clang version 6 or newer.")
endif()
endif()

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)
# Load config.cmake only if mxnet is not compiled as a dependency of another project
include(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)
Expand Down

0 comments on commit 1194f0b

Please sign in to comment.