Home | History | Annotate | Download | only in Modules
      1 macro(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}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
     39   else()
     40     set(LLVM_FOUND OFF)
     41     return()
     42   endif()
     43 
     44   if (NOT EXISTS ${LLVM_MAIN_SRC_DIR})
     45     set(LLVM_FOUND OFF)
     46     message(WARNING "Not found: ${LLVM_MAIN_SRC_DIR}")
     47     return()
     48   endif()
     49 
     50   if(NOT EXISTS ${LLVM_CMAKE_PATH})
     51     set(LLVM_FOUND OFF)
     52     message(WARNING "Not found: ${LLVM_CMAKE_PATH}")
     53     return()
     54   endif()
     55 
     56   list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
     57   list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
     58 
     59   set(LLVM_FOUND ON)
     60 endmacro(find_llvm_parts)
     61 
     62 
     63 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     64   set(LIBCXX_BUILT_STANDALONE 1)
     65   message(STATUS "Configuring for standalone build.")
     66 
     67   find_llvm_parts()
     68 
     69   # LLVM Options --------------------------------------------------------------
     70   include(FindPythonInterp)
     71   if( NOT PYTHONINTERP_FOUND )
     72     message(WARNING "Failed to find python interpreter. "
     73                     "The libc++ test suite will be disabled.")
     74     set(LLVM_INCLUDE_TESTS OFF)
     75   endif()
     76 
     77   if (NOT DEFINED LLVM_INCLUDE_TESTS)
     78     set(LLVM_INCLUDE_TESTS ${LLVM_FOUND})
     79   endif()
     80   if (NOT DEFINED LLVM_INCLUDE_DOCS)
     81     set(LLVM_INCLUDE_DOCS ${LLVM_FOUND})
     82   endif()
     83   if (NOT DEFINED LLVM_ENABLE_SPHINX)
     84     set(LLVM_ENABLE_SPHINX OFF)
     85   endif()
     86 
     87   # Required LIT Configuration ------------------------------------------------
     88   # Define the default arguments to use with 'lit', and an option for the user
     89   # to override.
     90   set(LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported")
     91   if (MSVC OR XCODE)
     92     set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
     93   endif()
     94   set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
     95 
     96   # Make sure we can use the console pool for recent cmake and ninja > 1.5
     97   # Needed for add_lit_testsuite
     98   if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
     99     set(cmake_3_2_USES_TERMINAL)
    100   else()
    101     set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
    102   endif()
    103 
    104   # Required doc configuration
    105   if (LLVM_ENABLE_SPHINX)
    106     message(STATUS "Sphinx enabled.")
    107     find_package(Sphinx REQUIRED)
    108   else()
    109     message(STATUS "Sphinx disabled.")
    110   endif()
    111 
    112   # FIXME - This is cribbed from HandleLLVMOptions.cmake.
    113   if(WIN32)
    114     set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
    115     if(CYGWIN)
    116       set(LLVM_ON_WIN32 0)
    117       set(LLVM_ON_UNIX 1)
    118     else(CYGWIN)
    119       set(LLVM_ON_WIN32 1)
    120       set(LLVM_ON_UNIX 0)
    121     endif(CYGWIN)
    122   else(WIN32)
    123     if(UNIX)
    124       set(LLVM_ON_WIN32 0)
    125       set(LLVM_ON_UNIX 1)
    126       if(APPLE)
    127         set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
    128       else(APPLE)
    129         set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
    130       endif(APPLE)
    131     else(UNIX)
    132       MESSAGE(SEND_ERROR "Unable to determine platform")
    133     endif(UNIX)
    134   endif(WIN32)
    135 
    136   # Add LLVM Functions --------------------------------------------------------
    137   include(AddLLVM OPTIONAL)
    138 endif()
    139