|
| 1 | +if (NOT PATH_TO_LLVM) |
| 2 | + message(FATAL_ERROR " |
| 3 | + The cmake is supposed to be called with PATH_TO_LLVM pointing to |
| 4 | + a precompiled version of LLVM or to to the source code of LLVM |
| 5 | + Examples: |
| 6 | + cmake -G \"${CMAKE_GENERATOR}\" -DPATH_TO_LLVM=/opt/llvm-3.9.0 ${CMAKE_SOURCE_DIR} |
| 7 | + cmake -G \"${CMAKE_GENERATOR}\" -DPATH_TO_LLVM=/opt/llvm/source ${CMAKE_SOURCE_DIR} |
| 8 | +") |
| 9 | +endif() |
| 10 | + |
| 11 | +if (NOT IS_ABSOLUTE ${PATH_TO_LLVM}) |
| 12 | + # Convert relative path to absolute path |
| 13 | + get_filename_component(PATH_TO_LLVM |
| 14 | + "${PATH_TO_LLVM}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") |
| 15 | +endif() |
| 16 | + |
| 17 | +set (BUILD_AGAINST_PRECOMPILED_LLVM TRUE) |
| 18 | +if (EXISTS ${PATH_TO_LLVM}/CMakeLists.txt) |
| 19 | + set (BUILD_AGAINST_PRECOMPILED_LLVM FALSE) |
| 20 | +endif() |
| 21 | + |
| 22 | +if (${BUILD_AGAINST_PRECOMPILED_LLVM}) |
| 23 | + set (search_paths |
| 24 | + ${PATH_TO_LLVM} |
| 25 | + ${PATH_TO_LLVM}/lib/cmake |
| 26 | + ${PATH_TO_LLVM}/lib/cmake/llvm |
| 27 | + ${PATH_TO_LLVM}/lib/cmake/clang |
| 28 | + ${PATH_TO_LLVM}/share/clang/cmake/ |
| 29 | + ${PATH_TO_LLVM}/share/llvm/cmake/ |
| 30 | + ) |
| 31 | + |
| 32 | + find_package(LLVM REQUIRED CONFIG PATHS ${search_paths} NO_DEFAULT_PATH) |
| 33 | +else() |
| 34 | + macro(get_llvm_version_component input component) |
| 35 | + string(REGEX MATCH "${component} ([0-9]+)" match ${input}) |
| 36 | + if (NOT match) |
| 37 | + message(FATAL_ERROR "Cannot find LLVM version component '${component}'") |
| 38 | + endif() |
| 39 | + set (${component} ${CMAKE_MATCH_1}) |
| 40 | + endmacro() |
| 41 | + |
| 42 | + file(READ ${PATH_TO_LLVM}/CMakeLists.txt LLVM_CMAKELISTS) |
| 43 | + get_llvm_version_component("${LLVM_CMAKELISTS}" LLVM_VERSION_MAJOR) |
| 44 | + get_llvm_version_component("${LLVM_CMAKELISTS}" LLVM_VERSION_MINOR) |
| 45 | + get_llvm_version_component("${LLVM_CMAKELISTS}" LLVM_VERSION_PATCH) |
| 46 | + set (LLVM_VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}) |
| 47 | + |
| 48 | + if (LIBIRM_BUILD_32_BITS) |
| 49 | + set (LLVM_BUILD_32_BITS ON CACHE BOOL "Forcing LLVM to be built for 32 bits as well" FORCE) |
| 50 | + endif() |
| 51 | + set (LLVM_ENABLE_PROJECTS "llvm" CACHE BOOL "Don't build anything besides LLVM core" FORCE) |
| 52 | + set (LLVM_TARGETS_TO_BUILD "host" CACHE STRING "Don't build " FORCE) |
| 53 | + |
| 54 | + add_subdirectory(${PATH_TO_LLVM} llvm-build-dir) |
| 55 | + |
| 56 | + # Normally, include paths provided by LLVMConfig.cmake |
| 57 | + # In this case we can 'steal' them from real targets |
| 58 | + get_target_property(LLVM_INCLUDE_DIRS LLVMSupport INCLUDE_DIRECTORIES) |
| 59 | + list(REMOVE_DUPLICATES LLVM_INCLUDE_DIRS) |
| 60 | +endif() |
0 commit comments