|
| 1 | +#=========================== begin_copyright_notice ============================ |
| 2 | +# |
| 3 | +# Copyright (c) 2014-2021 Intel Corporation |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), |
| 7 | +# to deal in the Software without restriction, including without limitation |
| 8 | +# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | +# and/or sell copies of the Software, and to permit persons to whom |
| 10 | +# the Software is furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included |
| 13 | +# in all copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | +# IN THE SOFTWARE. |
| 22 | +# |
| 23 | +#============================ end_copyright_notice ============================= |
| 24 | + |
| 25 | +# Order of chosing way how to take opencl-clang |
| 26 | +#1. CCLANG_FROM_SYSTEM - use installed on system opencl-clang toolchain |
| 27 | +#2. CCLANG_BUILD_PREBUILDS - use prebuilded opencl-clang toolchain |
| 28 | +# CCLANG_BUILD_PREBUILDS_DIR - set path to prebuilt cclang folder |
| 29 | +#3. CCLANG_BUILD_INTREE_LLVM - use sources of opencl-clang toolchain |
| 30 | + |
| 31 | +find_library(CCLANG_FROM_SYSTEM ${COMMON_CLANG_LIBRARY_NAME}) |
| 32 | + |
| 33 | +### Check if user manual setup some of flag |
| 34 | +if(NOT CCLANG_BUILD_PREBUILDS) |
| 35 | + set(CCLANG_BUILD_PREBUILDS FALSE) |
| 36 | +else() |
| 37 | + set(CCLANG_FROM_SYSTEM FALSE) |
| 38 | + set(CCLANG_BUILD_INTREE_LLVM FALSE) |
| 39 | +endif() |
| 40 | + |
| 41 | +if(NOT CCLANG_BUILD_INTREE_LLVM) |
| 42 | + set(CCLANG_BUILD_INTREE_LLVM FALSE) |
| 43 | +else() |
| 44 | + set(CCLANG_BUILD_PREBUILDS FALSE) |
| 45 | + set(CCLANG_FROM_SYSTEM FALSE) |
| 46 | +endif() |
| 47 | +### |
| 48 | + |
| 49 | +### Check by order first available way to link with opencl-clang |
| 50 | +if(NOT CCLANG_FROM_SYSTEM) |
| 51 | + if(NOT CCLANG_BUILD_PREBUILDS_DIR) |
| 52 | + # Detect CPU architecture |
| 53 | + igc_arch_get_cpu(cpuSuffix) |
| 54 | + set(CCLANG_BUILD_PREBUILDS_DIR "${IGC_BUILD__GFX_DEV_SRC_DIR}/../../prebuild-opencl-clang/Release/${cpuSuffix}") |
| 55 | + |
| 56 | + if(NOT EXISTS ${CCLANG_BUILD_PREBUILDS_DIR}) |
| 57 | + set(CCLANG_BUILD_PREBUILDS_DIR "${IGC_BUILD__GFX_DEV_SRC_DIR}/../prebuild-opencl-clang/Release/${cpuSuffix}") |
| 58 | + endif() |
| 59 | + endif() |
| 60 | + set(CCLANG_BUILD_INTREE_LLVM_DIR ${LLVM_SOURCE_DIR}/projects/opencl-clang) |
| 61 | + ### Check if user by choosing some way of linking with opencl-clang provided required folders |
| 62 | + if(${CCLANG_BUILD_PREBUILDS}) |
| 63 | + if(NOT EXISTS ${CCLANG_BUILD_PREBUILDS_DIR}) |
| 64 | + message(FATAL_ERROR "[IGC] : User setup to use prebuilded opencl-clang but not found folder : ${CCLANG_BUILD_PREBUILDS_DIR}") |
| 65 | + set(CCLANG_BUILD_PREBUILDS FALSE) |
| 66 | + endif() |
| 67 | + elseif(${CCLANG_BUILD_INTREE_LLVM}) |
| 68 | + if(NOT EXISTS ${CCLANG_BUILD_INTREE_LLVM_DIR}) |
| 69 | + message(FATAL_ERROR "[IGC] : User setup to use sources of opencl-clang but not found folder : ${CCLANG_BUILD_INTREE_LLVM_DIR}") |
| 70 | + set(CCLANG_BUILD_INTREE_LLVM FALSE) |
| 71 | + endif() |
| 72 | + ### |
| 73 | + ### User didn't define nothing, then pick the method 2 or 3. |
| 74 | + elseif(EXISTS ${CCLANG_BUILD_PREBUILDS_DIR}) |
| 75 | + set(CCLANG_BUILD_PREBUILDS TRUE) |
| 76 | + elseif(EXISTS ${CCLANG_BUILD_INTREE_LLVM_DIR}) |
| 77 | + message(STATUS "[IGC] : opencl-clang will be taken from sources") |
| 78 | + set(CCLANG_BUILD_INTREE_LLVM TRUE) |
| 79 | + else() |
| 80 | + message(FATAL_ERROR "[IGC] : Cannot find opencl-clang tool-chain, please provide sources or install it on system.") |
| 81 | + endif() |
| 82 | + ### |
| 83 | + |
| 84 | +endif() |
| 85 | +### |
| 86 | + |
| 87 | +#1. CCLANG_FROM_SYSTEM - use installed on system opencl-clang toolchain |
| 88 | +if(CCLANG_FROM_SYSTEM) |
| 89 | + message(STATUS "[IGC] : opencl-clang will be taken from system") |
| 90 | + |
| 91 | + find_library(SYSTEM_COMMON_CLANG ${COMMON_CLANG_LIBRARY_NAME}) |
| 92 | + |
| 93 | + add_library(opencl-clang-lib SHARED IMPORTED GLOBAL) |
| 94 | + set_property(TARGET opencl-clang-lib PROPERTY "IMPORTED_LOCATION" "${SYSTEM_COMMON_CLANG}") |
| 95 | + find_program(CLANG_GE7 clang-${LLVM_VERSION_MAJOR}) |
| 96 | + if(CLANG_GE7) |
| 97 | + message(STATUS "[IGC] Found clang-${LLVM_VERSION_MAJOR} executable: ${CLANG_GE7}") |
| 98 | + |
| 99 | + add_executable(clang-tool IMPORTED GLOBAL) |
| 100 | + set_property(TARGET clang-tool PROPERTY "IMPORTED_LOCATION" "${CLANG_GE7}") |
| 101 | + set(CL_OPTIONS "-finclude-default-header") |
| 102 | + if(LLVM_VERSION_MAJOR VERSION_EQUAL 7) |
| 103 | + message(WARNING "[IGC] : clang-7 should be patched with VME patch (https://reviews.llvm.org/D51484). Assuming that it is. If not, please add -DVME_TYPES_DEFINED=FALSE.") |
| 104 | + endif() |
| 105 | + else(CLANG_GE7) |
| 106 | + message(FATAL_ERROR "[IGC] : Couldn't find clang-${LLVM_VERSION_MAJOR} executable, please install it.") |
| 107 | + endif(CLANG_GE7) |
| 108 | +### |
| 109 | +#2. CCLANG_BUILD_PREBUILDS - use prebuilded opencl-clang toolchain |
| 110 | +elseif(${CCLANG_BUILD_PREBUILDS}) |
| 111 | + message(STATUS "[IGC] : opencl-clang will be taken from prebuilds") |
| 112 | + |
| 113 | + set(CLANG_TOOL_PATH "${CCLANG_BUILD_PREBUILDS_DIR}/clang${CMAKE_EXECUTABLE_SUFFIX}") |
| 114 | + set(LLVM_PACKAGE_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}") |
| 115 | + |
| 116 | + # Get clang-tool version |
| 117 | + execute_process( |
| 118 | + COMMAND ${CLANG_TOOL_PATH} -v |
| 119 | + ERROR_VARIABLE CLANG_TOOL_V_CALL) |
| 120 | + string(REGEX MATCH "clang version ([0-9]*\\.[0-9]*\\.[0-9]*[a-zA-Z0-9]*)" CLANG_TOOL_VERSION "${CLANG_TOOL_V_CALL}") |
| 121 | + set(CLANG_TOOL_VERSION "${CMAKE_MATCH_1}") |
| 122 | + |
| 123 | + # Check if llvm version for IGC is newer or equal with the clang-tool version |
| 124 | + if(${LLVM_PACKAGE_VERSION} VERSION_GREATER ${CLANG_TOOL_VERSION} OR |
| 125 | + ${LLVM_PACKAGE_VERSION} EQUAL ${CLANG_TOOL_VERSION}) |
| 126 | + add_library(opencl-clang-lib SHARED IMPORTED GLOBAL) |
| 127 | + set_property(TARGET opencl-clang-lib PROPERTY "IMPORTED_LOCATION" "${CCLANG_BUILD_PREBUILDS_DIR}/${COMMON_CLANG_LIB_FULL_NAME}") |
| 128 | + |
| 129 | + add_executable(clang-tool IMPORTED GLOBAL) |
| 130 | + set_property(TARGET clang-tool PROPERTY "IMPORTED_LOCATION" "${CLANG_TOOL_PATH}") |
| 131 | + |
| 132 | + set(opencl-header "${CCLANG_BUILD_PREBUILDS_DIR}/opencl-c.h") |
| 133 | + else() |
| 134 | + message(FATAL_ERROR "[IGC] : The clang-tool(${CLANG_TOOL_VERSION}) from prebuilts is newer than llvm(${LLVM_PACKAGE_VERSION}) version for IGC.") |
| 135 | + endif() |
| 136 | +### |
| 137 | +#3. CCLANG_BUILD_INTREE_LLVM - use sources of opencl-clang toolchain |
| 138 | +elseif(${CCLANG_BUILD_INTREE_LLVM}) |
| 139 | + message(STATUS "[IGC] : opencl-clang will be taken from sources") |
| 140 | + |
| 141 | + add_library(opencl-clang-lib ALIAS ${COMMON_CLANG_LIBRARY_NAME}) |
| 142 | + add_executable(clang-tool ALIAS clang) |
| 143 | + get_target_property(CLANG_SOURCE_DIR clang SOURCE_DIR) |
| 144 | + set(opencl-header "${CLANG_SOURCE_DIR}/../../lib/Headers/opencl-c.h") |
| 145 | +endif() |
| 146 | +### |
0 commit comments