1# Copyright (c) 2023-2024 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14if (NOT PANDA_BUILD_LLVM_BACKEND) 15 message(FATAL_ERROR "PANDA_BUILD_LLVM_BACKEND must be true") 16endif() 17 18if (CROSS_VALUES_CONFIG) 19 message(FATAL_ERROR "LLVM_BACKEND must be disabled in cross_values") 20endif() 21 22find_package(LLVM 15 REQUIRED CONFIG NO_DEFAULT_PATH CMAKE_FIND_ROOT_PATH_BOTH PATHS ${LLVM_TARGET_PATH}) 23message(STATUS "LLVM backend:") 24message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") 25message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") 26 27find_library(LIB_LLVM LLVM REQUIRED NO_DEFAULT_PATH CMAKE_FIND_ROOT_PATH_BOTH PATHS ${LLVM_LIBRARY_DIR}) 28message(STATUS "LIB_LLVM ${LIB_LLVM}") 29 30if (NOT CMAKE_CROSSCOMPILING AND PANDA_LLVM_INTERPRETER_INLINING) 31 find_program(LLVM_LINK NAMES llvm-link REQUIRED NO_DEFAULT_PATH CMAKE_FIND_ROOT_PATH_BOTH PATHS "${LLVM_BINARY_DIR}/bin") 32 message(STATUS "LLVM_LINK ${LLVM_LINK}") 33endif() 34 35set(LLVM_COPY_NAME "libLLVM-${LLVM_VERSION_MAJOR}.so") 36add_custom_target(copy-libLLVM.so 37 COMMENT "Copying ${LIB_LLVM} into ${PANDA_BINARY_ROOT}/lib/${LLVM_COPY_NAME}" 38 COMMAND ${CMAKE_COMMAND} -E copy_if_different "${LIB_LLVM}" "${PANDA_BINARY_ROOT}/lib/${LLVM_COPY_NAME}") 39