1macro(find_llvm_parts) 2# Rely on llvm-config. 3 set(CONFIG_OUTPUT) 4 if(NOT LLVM_CONFIG_PATH) 5 find_program(LLVM_CONFIG_PATH "llvm-config") 6 endif() 7 if(DEFINED LLVM_PATH) 8 set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include") 9 set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree") 10 set(LLVM_MAIN_SRC_DIR ${LLVM_PATH}) 11 set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules") 12 elseif(LLVM_CONFIG_PATH) 13 message(STATUS "Found LLVM_CONFIG_PATH as ${LLVM_CONFIG_PATH}") 14 set(LIBCXX_USING_INSTALLED_LLVM 1) 15 set(CONFIG_COMMAND ${LLVM_CONFIG_PATH} 16 "--includedir" 17 "--prefix" 18 "--src-root") 19 execute_process( 20 COMMAND ${CONFIG_COMMAND} 21 RESULT_VARIABLE HAD_ERROR 22 OUTPUT_VARIABLE CONFIG_OUTPUT 23 ) 24 if(NOT HAD_ERROR) 25 string(REGEX REPLACE 26 "[ \t]*[\r\n]+[ \t]*" ";" 27 CONFIG_OUTPUT ${CONFIG_OUTPUT}) 28 else() 29 string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}") 30 message(STATUS "${CONFIG_COMMAND_STR}") 31 message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}") 32 endif() 33 34 list(GET CONFIG_OUTPUT 0 INCLUDE_DIR) 35 list(GET CONFIG_OUTPUT 1 LLVM_OBJ_ROOT) 36 list(GET CONFIG_OUTPUT 2 MAIN_SRC_DIR) 37 38 set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include") 39 set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree") 40 set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree") 41 42 # --cmakedir is supported since llvm r291218 (4.0 release) 43 execute_process( 44 COMMAND ${LLVM_CONFIG_PATH} --cmakedir 45 RESULT_VARIABLE HAD_ERROR 46 OUTPUT_VARIABLE CONFIG_OUTPUT 47 ERROR_QUIET) 48 if(NOT HAD_ERROR) 49 string(STRIP "${CONFIG_OUTPUT}" LLVM_CMAKE_PATH_FROM_LLVM_CONFIG) 50 file(TO_CMAKE_PATH "${LLVM_CMAKE_PATH_FROM_LLVM_CONFIG}" LLVM_CMAKE_PATH) 51 else() 52 file(TO_CMAKE_PATH "${LLVM_BINARY_DIR}" LLVM_BINARY_DIR_CMAKE_STYLE) 53 set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") 54 endif() 55 else() 56 set(LLVM_FOUND OFF) 57 message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: " 58 "llvm-config not found and LLVM_PATH not defined.\n" 59 "Reconfigure with -DLLVM_CONFIG_PATH=path/to/llvm-config " 60 "or -DLLVM_PATH=path/to/llvm-source-root.") 61 return() 62 endif() 63 64 if (EXISTS "${LLVM_CMAKE_PATH}") 65 list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") 66 elseif (EXISTS "${LLVM_MAIN_SRC_DIR}/cmake/modules") 67 list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules") 68 else() 69 set(LLVM_FOUND OFF) 70 message(WARNING "Neither ${LLVM_CMAKE_PATH} nor ${LLVM_MAIN_SRC_DIR}/cmake/modules found") 71 return() 72 endif() 73 74 set(LLVM_FOUND ON) 75endmacro(find_llvm_parts) 76 77macro(configure_out_of_tree_llvm) 78 message(STATUS "Configuring for standalone build.") 79 set(LIBCXX_STANDALONE_BUILD 1) 80 81 find_llvm_parts() 82 83 # Add LLVM Functions -------------------------------------------------------- 84 if (LLVM_FOUND AND LIBCXX_USING_INSTALLED_LLVM) 85 include(LLVMConfig) # For TARGET_TRIPLE 86 else() 87 if (WIN32) 88 set(LLVM_ON_UNIX 0) 89 set(LLVM_ON_WIN32 1) 90 else() 91 set(LLVM_ON_UNIX 1) 92 set(LLVM_ON_WIN32 0) 93 endif() 94 endif() 95 if (LLVM_FOUND) 96 include(AddLLVM OPTIONAL) 97 endif() 98 99 # LLVM Options -------------------------------------------------------------- 100 if (NOT DEFINED LLVM_INCLUDE_TESTS) 101 set(LLVM_INCLUDE_TESTS ${LLVM_FOUND}) 102 endif() 103 if (NOT DEFINED LLVM_INCLUDE_DOCS) 104 set(LLVM_INCLUDE_DOCS ${LLVM_FOUND}) 105 endif() 106 if (NOT DEFINED LLVM_ENABLE_SPHINX) 107 set(LLVM_ENABLE_SPHINX OFF) 108 endif() 109 110 # In a standalone build, we don't have llvm to automatically generate the 111 # llvm-lit script for us. So we need to provide an explicit directory that 112 # the configurator should write the script into. 113 set(LLVM_LIT_OUTPUT_DIR "${libcxx_BINARY_DIR}/bin") 114 115 if (LLVM_INCLUDE_TESTS) 116 # Required LIT Configuration ------------------------------------------------ 117 # Define the default arguments to use with 'lit', and an option for the user 118 # to override. 119 set(LLVM_EXTERNAL_LIT "${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py") 120 set(LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported") 121 if (MSVC OR XCODE) 122 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") 123 endif() 124 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") 125 endif() 126 127 # Required doc configuration 128 if (LLVM_ENABLE_SPHINX) 129 find_package(Sphinx REQUIRED) 130 endif() 131 132 if (LLVM_ON_UNIX AND NOT APPLE) 133 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1) 134 else() 135 set(LLVM_HAVE_LINK_VERSION_SCRIPT 0) 136 endif() 137endmacro(configure_out_of_tree_llvm) 138 139configure_out_of_tree_llvm() 140