···11+set(MANUALLY_SET_COMPILER_ERROR_MESSAGE
22+"If you already have a supported version of clang installed, you may need to \
33+manually set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER. Refer to the Darling docs \
44+for more details."
55+)
66+77+macro(clang_version_check compiler source_type clang_minimum_version)
88+ if (compiler STREQUAL "")
99+ message(FATAL_ERROR "Unable to find a compatible compiler")
1010+ endif (compiler STREQUAL "")
1111+1212+ file(WRITE "${CMAKE_BINARY_DIR}/clang_major.${source_type}" "#include <stdio.h>\n"
1313+ "#if !__clang__\n" "#error \"Not running on a clang compiler!\"\n" "#endif\n" "int main() { printf(\"%d\", __clang_major__); }")
1414+ execute_process(COMMAND "${compiler}" "${CMAKE_BINARY_DIR}/clang_major.${source_type}" "-o" "clang_${source_type}_major"
1515+ RESULT_VARIABLE BUILD_CLANG_TEST_RESULT
1616+ OUTPUT_VARIABLE BUILD_CLANG_TEST_OUTPUT
1717+ COMMAND_ECHO NONE
1818+ )
1919+2020+ if (BUILD_CLANG_TEST_RESULT)
2121+ message(FATAL_ERROR
2222+ "Failed to build ${CMAKE_BINARY_DIR}/clang_major.${source_type}\n"
2323+ "This could indicate that `${compiler}` is either not a clang compiler, "
2424+ "or the path does not exist. ${MANUALLY_SET_COMPILER_ERROR_MESSAGE}")
2525+ endif (BUILD_CLANG_TEST_RESULT)
2626+2727+ execute_process(COMMAND "${CMAKE_BINARY_DIR}/clang_${source_type}_major"
2828+ RESULT_VARIABLE CLANG_MAJOR_VERSION_RESULT
2929+ OUTPUT_VARIABLE CLANG_MAJOR_VERSION_OUTPUT
3030+ )
3131+3232+ if (CLANG_MAJOR_VERSION_RESULT)
3333+ # This should normally never fail...
3434+ message(FATAL_ERROR "Failed to check clang major version")
3535+ endif (CLANG_MAJOR_VERSION_RESULT)
3636+3737+ if ("${CLANG_MAJOR_VERSION_OUTPUT}" LESS ${clang_minimum_version})
3838+ message(FATAL_ERROR
3939+ "Your clang version (${CLANG_MAJOR_VERSION_OUTPUT}) is below the recommend supported version (${clang_minimum_version})\n"
4040+ "${MANUALLY_SET_COMPILER_ERROR_MESSAGE}")
4141+ endif ("${CLANG_MAJOR_VERSION_OUTPUT}" LESS ${clang_minimum_version})
4242+endmacro()