Skip to content

Instantly share code, notes, and snippets.

@vadixidav
Created June 28, 2017 22:04
Show Gist options
  • Save vadixidav/cbda6fd2fbf74f546f82221d9e0cf434 to your computer and use it in GitHub Desktop.
Save vadixidav/cbda6fd2fbf74f546f82221d9e0cf434 to your computer and use it in GitHub Desktop.
function(conan_check_compiler)
if(NOT DEFINED CMAKE_CXX_COMPILER_ID)
if(DEFINED CMAKE_C_COMPILER_ID)
message(STATUS "This project seems to be plain C, using '${CMAKE_C_COMPILER_ID}' compiler")
set(CMAKE_CXX_COMPILER_ID ${CMAKE_C_COMPILER_ID})
set(CMAKE_CXX_COMPILER_VERSION ${CMAKE_C_COMPILER_VERSION})
else()
message(FATAL_ERROR "This project seems to be plain C, but no compiler defined")
endif()
endif()
if(CONAN_DISABLE_CHECK_COMPILER)
message(STATUS "WARN: Disabled conan compiler checks")
return()
endif()
if(NOT DEFINED CONAN_COMPILER)
conan_get_compiler(CONAN_COMPILER CONAN_COMPILER_VERSION)
if(NOT DEFINED CONAN_COMPILER)
message(STATUS "WARN: CONAN_COMPILER variable not set, please make sure yourself that "
"your compiler and version matches your declared settings")
return()
endif()
endif()
if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL ${CMAKE_SYSTEM_NAME})
set(CROSS_BUILDING 1)
endif()
# Avoid checks when cross compiling, apple-clang crashes because its APPLE but not apple-clang
# Actually CMake is detecting "clang" when you are using apple-clang, only if CMP0025 is set to NEW will detect apple-clang
if( (CONAN_COMPILER STREQUAL "Visual Studio" AND NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC) OR
(CONAN_COMPILER STREQUAL "gcc" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR
(CONAN_COMPILER STREQUAL "apple-clang" AND NOT CROSS_BUILDING AND (NOT APPLE OR NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")) OR
(CONAN_COMPILER STREQUAL "clang" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR
(CONAN_COMPILER STREQUAL "sun-cc" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "SunPro") )
message(FATAL_ERROR "Incorrect '${CONAN_COMPILER}', is not the one detected by CMake: '${CMAKE_CXX_COMPILER_ID}'")
endif()
if(NOT DEFINED CONAN_COMPILER_VERSION)
message(STATUS "WARN: CONAN_COMPILER_VERSION variable not set, please make sure yourself "
"that your compiler version matches your declared settings")
return()
endif()
check_compiler_version()
endfunction()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment