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