1 # Load LLVM/Clang |
1 # - Try to find the Clang/LLVM executable |
2 if (CLANG) |
2 # Once done this will define |
3 set(CLANG_EXECUTABLE ${CLANG}) |
3 # |
4 else() |
4 # CLANG_FOUND - system has Clang |
5 find_program(CLANG_EXECUTABLE |
5 # CLANG_VERSION - Clang version |
|
6 # CLANG_EXECUTABLE - Clang executable |
|
7 # |
|
8 # Copyright (c) 2013, Vittorio Giovara <vittorio.giovara@gmail.com> |
|
9 # |
|
10 # Redistribution and use is allowed according to the terms of the BSD license. |
|
11 # For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
|
12 |
|
13 find_program(CLANG_EXECUTABLE |
6 NAMES clang-mp-3.3 clang-mp-3.2 clang-mp-3.1 clang-mp-3.0 clang |
14 NAMES clang-mp-3.3 clang-mp-3.2 clang-mp-3.1 clang-mp-3.0 clang |
7 PATHS /opt/local/bin /usr/local/bin /usr/bin) |
15 PATHS /opt/local/bin /usr/local/bin /usr/bin) |
|
16 |
|
17 if (CLANG_EXECUTABLE) |
|
18 execute_process(COMMAND ${CLANG_EXECUTABLE} --version |
|
19 OUTPUT_VARIABLE CLANG_VERSION_OUTPUT |
|
20 ERROR_VARIABLE CLANG_VERSION_ERROR |
|
21 RESULT_VARIABLE CLANG_VERSION_RESULT |
|
22 OUTPUT_STRIP_TRAILING_WHITESPACE |
|
23 ) |
|
24 |
|
25 if(${CLANG_VERSION_RESULT} EQUAL 0) |
|
26 string(REGEX MATCH "[0-9]+\\.[0-9]+" CLANG_VERSION "${CLANG_VERSION_OUTPUT}") |
|
27 string(REGEX REPLACE "([0-9]+\\.[0-9]+)" "\\1" CLANG_VERSION "${CLANG_VERSION}") |
|
28 else() |
|
29 message(SEND_ERROR "Command \"${CLANG_EXECUTABLE} --version\" failed with output: ${CLANG_VERSION_ERROR}") |
|
30 endif() |
8 endif() |
31 endif() |
9 |
32 |
10 # Check LLVM/Clang version |
33 include(FindPackageHandleStandardArgs) |
11 if (CLANG_EXECUTABLE) |
34 find_package_handle_standard_args(Clang DEFAULT_MSG CLANG_EXECUTABLE CLANG_VERSION) |
12 exec_program(${CLANG_EXECUTABLE} ARGS "-v" OUTPUT_VARIABLE CLANG_VERSION_FULL) |
35 mark_as_advanced(CLANG_VERSION) |
13 |
36 |
14 string(REGEX MATCH "[0-9]+\\.[0-9]+" CLANG_VERSION_LONG "${CLANG_VERSION_FULL}") |
|
15 string(REGEX REPLACE "([0-9]+\\.[0-9]+)" "\\1" CLANG_VERSION "${CLANG_VERSION_LONG}") |
|
16 else() |
|
17 message(FATAL_ERROR "No LLVM/Clang compiler found (required for engine_c target)") |
|
18 endif() |
|
19 |
|
20 set(CMAKE_C_COMPILER ${CLANG_EXECUTABLE}) |
|
21 set(CMAKE_CXX_COMPILER ${CLANG_EXECUTABLE}) |
|