llvm_fetch.cmake.in 5.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# ******************************************************************************
# Copyright 2017-2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************

cmake_minimum_required(VERSION 3.4.3)

include(ExternalProject)

project(llvm NONE)

set(NGRAPH_USE_PREBUILT_LLVM @NGRAPH_USE_PREBUILT_LLVM@)
set(LLVM_TARBALL_URL @LLVM_TARBALL_URL@)
set(LLVM_SHA1_HASH @LLVM_SHA1_HASH@)

if(NGRAPH_USE_PREBUILT_LLVM)
    message(STATUS "LLVM: Using prebuilt LLVM")
    # Override default LLVM binaries
    if(NOT DEFINED LLVM_TARBALL_URL)
Sang Ik Lee's avatar
Sang Ik Lee committed
31
        set(NGRAPH_LLVM_VERSION 9.0.1)
32
        if(APPLE)
Sang Ik Lee's avatar
Sang Ik Lee committed
33 34
            set(LLVM_TARBALL_URL https://github.com/llvm/llvm-project/releases/download/llvmorg-${NGRAPH_LLVM_VERSION}/clang+llvm-${NGRAPH_LLVM_VERSION}-x86_64-apple-darwin.tar.xz)
            set(LLVM_SHA1_HASH 693e7c2d2fcd005f0d8198ea0174ae30ec78bb7c)
35 36 37
        elseif(UNIX AND NOT APPLE)
            if(EXISTS /etc/lsb-release)
                execute_process(COMMAND grep DISTRIB_RELEASE /etc/lsb-release OUTPUT_VARIABLE UBUNTU_VER_LINE)
Sang Ik Lee's avatar
Sang Ik Lee committed
38 39 40
                string(REGEX MATCH "[0-9.]+" UBUNTU_VERSION ${UBUNTU_VER_LINE})
                message(STATUS "Ubuntu version: ${UBUNTU_VERSION} detected.")
                if(UBUNTU_VERSION VERSION_LESS 16.04)
41
                    message(FATAL_ERROR "No prebuilt LLVM available for Ubuntu ${UBUNTU_VER} on llvm.org, please set LLVM_TARBALL_URL manually.")
Sang Ik Lee's avatar
Sang Ik Lee committed
42 43
                else()
                    set(LLVM_SHA1_HASH 608285fb0503ee6d15ce9acb8f4575bba4d78e06)
44
                endif()
Sang Ik Lee's avatar
Sang Ik Lee committed
45
                set(LLVM_TARBALL_URL https://github.com/llvm/llvm-project/releases/download/llvmorg-${NGRAPH_LLVM_VERSION}/clang+llvm-${NGRAPH_LLVM_VERSION}-x86_64-linux-gnu-ubuntu-16.04.tar.xz)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
            else()
                message(FATAL_ERROR "Prebuilt LLVM: Only Ubuntu Linux is supported.")
            endif()
        else()
            message(FATAL_ERROR "Prebuilt LLVM: unsupported OS.")
        endif()
    else()
        if(NOT DEFINED LLVM_SHA1_HASH)
            message(FATAL_ERROR "Prebuilt LLVM: please provide LLVM_SHA_HASH.")
        endif()
    endif()

    ExternalProject_Add(
        ext_llvm
        PREFIX llvm
        URL ${LLVM_TARBALL_URL}
        URL_HASH SHA1=${LLVM_SHA1_HASH}
63 64 65
        CMAKE_GENERATOR "${CMAKE_GENERATOR}"
        CMAKE_GENERATOR_PLATFORM "${CMAKE_GENERATOR_PLATFORM}"
        CMAKE_GENERATOR_TOOLSET "${CMAKE_GENERATOR_TOOLSET}"
66 67 68 69 70
        CONFIGURE_COMMAND ""
        BUILD_COMMAND ""
        INSTALL_COMMAND ""
        UPDATE_COMMAND ""
        SOURCE_DIR @LLVM_INSTALL_ROOT@
Sang Ik Lee's avatar
Sang Ik Lee committed
71
        DOWNLOAD_NO_PROGRESS OFF
72 73 74 75 76
        )

else()
    message(STATUS "LLVM: Building LLVM from source")

Sang Ik Lee's avatar
Sang Ik Lee committed
77 78
    set(LLVM_GIT_REPOSITORY https://github.com/llvm/llvm-project.git)
    set(LLVM_GIT_TAG llvmorg-9.0.1)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

    set(LLVM_CMAKE_ARGS @NGRAPH_FORWARD_CMAKE_ARGS@
                   -DCMAKE_INSTALL_PREFIX=@LLVM_INSTALL_ROOT@
                   -DLLVM_ENABLE_PROJECTS:STRING=clang$<SEMICOLON>openmp
                   -DLLVM_INCLUDE_DOCS=OFF
                   -DLLVM_INCLUDE_TESTS=OFF
                   -DLLVM_INCLUDE_GO_TESTS=OFF
                   -DLLVM_INCLUDE_EXAMPLES=OFF
                   -DLLVM_INCLUDE_BENCHMARKS=OFF
                   -DLLVM_BUILD_TOOLS=OFF
                   -DLLVM_BUILD_UTILS=OFF
                   -DLLVM_BUILD_RUNTIMES=OFF
                   -DLLVM_BUILD_RUNTIME=OFF
                   -DLLVM_TARGETS_TO_BUILD=X86
                   -DLLVM_ENABLE_BINDINGS=OFF
                   -DLLVM_ENABLE_TERMINFO=OFF
                   -DLLVM_ENABLE_ZLIB=OFF
                   -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON
97 98
                   -DLLVM_ENABLE_WARNINGS=OFF
                   -DLLVM_ENABLE_PEDANTIC=OFF
99 100 101 102
                   -DLIBOMP_OMPT_SUPPORT=OFF
                   -DCLANG_ENABLE_ARCMT=OFF
                   -DCLANG_ENABLE_STATIC_ANALYZER=OFF)

Sang Ik Lee's avatar
Sang Ik Lee committed
103
    if(CMAKE_VERSION VERSION_LESS 3.7)
104 105 106
        ExternalProject_Add(
            ext_llvm
            PREFIX llvm
Sang Ik Lee's avatar
Sang Ik Lee committed
107 108
            GIT_REPOSITORY ${LLVM_GIT_REPOSITORY}
            GIT_TAG ${LLVM_GIT_TAG}
109 110 111
            CMAKE_GENERATOR "${CMAKE_GENERATOR}"
            CMAKE_GENERATOR_PLATFORM "${CMAKE_GENERATOR_PLATFORM}"
            CMAKE_GENERATOR_TOOLSET "${CMAKE_GENERATOR_TOOLSET}"
112
            UPDATE_COMMAND ""
113
            CONFIGURE_COMMAND ${CMAKE_COMMAND} ../ext_llvm/llvm -G "@CMAKE_GENERATOR@" -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} ${LLVM_CMAKE_ARGS} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
114 115 116 117 118
            )
    else()
        ExternalProject_Add(
            ext_llvm
            PREFIX llvm
Sang Ik Lee's avatar
Sang Ik Lee committed
119 120
            GIT_REPOSITORY ${LLVM_GIT_REPOSITORY}
            GIT_TAG ${LLVM_GIT_TAG}
121
            GIT_SHALLOW 1
122 123 124
            CMAKE_GENERATOR "${CMAKE_GENERATOR}"
            CMAKE_GENERATOR_PLATFORM "${CMAKE_GENERATOR_PLATFORM}"
            CMAKE_GENERATOR_TOOLSET "${CMAKE_GENERATOR_TOOLSET}"
125 126 127 128 129 130
            CMAKE_ARGS ${LLVM_CMAKE_ARGS} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
            UPDATE_COMMAND ""
            SOURCE_SUBDIR llvm
            )
    endif()
endif()