• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1macro(find_llvm_parts)
2# Rely on llvm-config.
3  set(CONFIG_OUTPUT)
4  find_program(LLVM_CONFIG "llvm-config")
5  if(DEFINED LLVM_PATH)
6    set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
7    set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
8    set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
9    set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
10  elseif(LLVM_CONFIG)
11    message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
12    set(CONFIG_COMMAND ${LLVM_CONFIG}
13      "--includedir"
14      "--prefix"
15      "--src-root")
16    execute_process(
17      COMMAND ${CONFIG_COMMAND}
18      RESULT_VARIABLE HAD_ERROR
19      OUTPUT_VARIABLE CONFIG_OUTPUT
20    )
21    if(NOT HAD_ERROR)
22      string(REGEX REPLACE
23        "[ \t]*[\r\n]+[ \t]*" ";"
24        CONFIG_OUTPUT ${CONFIG_OUTPUT})
25    else()
26      string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
27      message(STATUS "${CONFIG_COMMAND_STR}")
28      message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
29    endif()
30
31    list(GET CONFIG_OUTPUT 0 INCLUDE_DIR)
32    list(GET CONFIG_OUTPUT 1 LLVM_OBJ_ROOT)
33    list(GET CONFIG_OUTPUT 2 MAIN_SRC_DIR)
34
35    set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include")
36    set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
37    set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
38    set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/share/llvm/cmake")
39  else()
40    set(LLVM_FOUND OFF)
41    return()
42  endif()
43
44  if (NOT EXISTS ${LLVM_MAIN_SRC_DIR})
45    message(FATAL_ERROR "Not found: ${LLVM_MAIN_SRC_DIR}")
46  endif()
47
48  if(NOT EXISTS ${LLVM_CMAKE_PATH})
49    message(FATAL_ERROR "Not found: ${LLVM_CMAKE_PATH}")
50  endif()
51
52  list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
53  list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
54
55  set(LLVM_FOUND ON)
56endmacro(find_llvm_parts)
57
58
59if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
60  set(LIBCXX_BUILT_STANDALONE 1)
61  message(STATUS "Configuring for standalone build.")
62
63  find_llvm_parts()
64
65  # LLVM Options --------------------------------------------------------------
66  include(FindPythonInterp)
67  if( NOT PYTHONINTERP_FOUND )
68    message(WARNING "Failed to find python interpreter. "
69                    "The libc++ test suite will be disabled.")
70    set(LLVM_INCLUDE_TESTS OFF)
71  endif()
72
73  if (NOT DEFINED LLVM_INCLUDE_TESTS)
74    set(LLVM_INCLUDE_TESTS ${LLVM_FOUND})
75  endif()
76
77  # Required LIT Configuration ------------------------------------------------
78  # Define the default arguments to use with 'lit', and an option for the user
79  # to override.
80  set(LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported")
81  if (MSVC OR XCODE)
82    set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
83  endif()
84  set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
85
86  # Make sure we can use the console pool for recent cmake and ninja > 1.5
87  # Needed for add_lit_testsuite
88  if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
89    set(cmake_3_2_USES_TERMINAL)
90  else()
91    set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
92  endif()
93
94  # Add LLVM Functions --------------------------------------------------------
95  include(AddLLVM OPTIONAL)
96endif()
97