From 2dc0d278ac5bc0e1068dc2d9fdf65f0753b6f021 Mon Sep 17 00:00:00 2001 From: Cory Bloor Date: Wed, 15 Aug 2018 19:05:02 -0600 Subject: [PATCH] Enhance CMake compiler check on Linux (#102) * Enhance CMake compiler check This commit adds a check for compilers that don't meet the project's minimum requirements. It will catch Clang versions that are too low as well as any non-Clang compilers. * Change SEND_ERROR to FATAL_ERROR --- CMakeLists.txt | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c771ae0c90..d03a499544 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,11 +61,22 @@ set(TOOLS ${CMAKE_SOURCE_DIR}/tools) # ================================================================================================== # Compiler check # ================================================================================================== -if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - message(FATAL_ERROR - "The GCC compiler is not supported, please use clang for both C and C++. " - "Please refer to README.md for more information.") - return() +set(MIN_CLANG_VERSION "5.0") + +if (CMAKE_C_COMPILER_ID MATCHES "Clang") + if (CMAKE_C_COMPILER_VERSION VERSION_LESS MIN_CLANG_VERSION) + message(FATAL_ERROR "Detected C compiler Clang ${CMAKE_C_COMPILER_VERSION} < ${MIN_CLANG_VERSION}") + endif() +else() + message(FATAL_ERROR "Detected C compiler ${CMAKE_C_COMPILER_ID} is unsupported") +endif() + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS MIN_CLANG_VERSION) + message(FATAL_ERROR "Detected CXX compiler Clang ${CMAKE_CXX_COMPILER_VERSION} < ${MIN_CLANG_VERSION}") + endif() +else() + message(FATAL_ERROR "Detected CXX compiler ${CMAKE_CXX_COMPILER_ID} is unsupported") endif() # Detect use of the clang-cl.exe frontend, which does not support all of clangs normal options