2023-08-15 14:20:26 +00:00
|
|
|
# SPDX-FileCopyrightText: 2011 Blender Authors
|
2023-06-14 12:49:59 +00:00
|
|
|
#
|
2022-02-11 03:23:56 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2021-02-24 14:13:37 +00:00
|
|
|
# - Find Clang library
|
|
|
|
# Find the native Clang includes and library
|
|
|
|
# This module defines
|
|
|
|
# CLANG_INCLUDE_DIRS, where to find AST/AST.h, Set when
|
|
|
|
# CLANG_INCLUDE_DIR is found.
|
|
|
|
# CLANG_LIBRARIES, libraries to link against to use Clang.
|
|
|
|
# CLANG_ROOT_DIR, The base directory to search for Clang.
|
|
|
|
# This can also be an environment variable.
|
|
|
|
# CLANG_FOUND, If false, do not try to use Clang.
|
|
|
|
|
2023-07-29 03:47:55 +00:00
|
|
|
# If `CLANG_ROOT_DIR` was defined in the environment, use it.
|
|
|
|
if(DEFINED CLANG_ROOT_DIR)
|
|
|
|
# Pass.
|
|
|
|
elseif(DEFINED ENV{CLANG_ROOT_DIR})
|
2021-02-24 14:13:37 +00:00
|
|
|
set(CLANG_ROOT_DIR $ENV{CLANG_ROOT_DIR})
|
2023-07-29 03:47:55 +00:00
|
|
|
else()
|
|
|
|
set(CLANG_ROOT_DIR "")
|
2021-02-24 14:13:37 +00:00
|
|
|
endif()
|
|
|
|
|
2021-06-08 09:14:52 +00:00
|
|
|
if(NOT LLVM_ROOT_DIR)
|
|
|
|
if(DEFINED LLVM_VERSION)
|
|
|
|
message(running llvm-config-${LLVM_VERSION})
|
|
|
|
find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
|
|
|
|
endif()
|
|
|
|
if(NOT LLVM_CONFIG)
|
|
|
|
find_program(LLVM_CONFIG llvm-config)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
execute_process(COMMAND ${LLVM_CONFIG} --prefix
|
|
|
|
OUTPUT_VARIABLE LLVM_ROOT_DIR
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
set(LLVM_ROOT_DIR ${LLVM_ROOT_DIR} CACHE PATH "Path to the LLVM installation")
|
|
|
|
endif()
|
|
|
|
|
2024-03-07 23:53:03 +00:00
|
|
|
set(_clang_SEARCH_DIRS
|
2021-02-24 14:13:37 +00:00
|
|
|
${CLANG_ROOT_DIR}
|
2021-06-08 09:14:52 +00:00
|
|
|
${LLVM_ROOT_DIR}
|
2021-02-24 14:13:37 +00:00
|
|
|
/opt/lib/clang
|
|
|
|
)
|
|
|
|
|
|
|
|
find_path(CLANG_INCLUDE_DIR
|
|
|
|
NAMES
|
|
|
|
AST/AST.h
|
|
|
|
HINTS
|
2024-03-07 23:53:03 +00:00
|
|
|
${_clang_SEARCH_DIRS}
|
2021-02-24 14:13:37 +00:00
|
|
|
PATH_SUFFIXES
|
|
|
|
include
|
|
|
|
include/clang
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-03-07 23:53:03 +00:00
|
|
|
set(_clang_FIND_COMPONENTS
|
2021-02-24 14:13:37 +00:00
|
|
|
clangDependencyScanning
|
|
|
|
clangDynamicASTMatchers
|
|
|
|
clangFrontendTool
|
|
|
|
clangStaticAnalyzerFrontend
|
|
|
|
clangHandleCXX
|
|
|
|
clangStaticAnalyzerCheckers
|
|
|
|
clangStaticAnalyzerCore
|
|
|
|
clangToolingASTDiff
|
|
|
|
clangToolingRefactoring
|
|
|
|
clangToolingSyntax
|
|
|
|
clangARCMigrate
|
|
|
|
clangCodeGen
|
|
|
|
clangCrossTU
|
|
|
|
clangIndex
|
|
|
|
clangTooling
|
|
|
|
clangFormat
|
|
|
|
clangToolingInclusions
|
|
|
|
clangRewriteFrontend
|
|
|
|
clangFrontend
|
|
|
|
clangSerialization
|
|
|
|
clangDriver
|
|
|
|
clangToolingCore
|
|
|
|
clangParse
|
|
|
|
clangRewrite
|
|
|
|
clangSema
|
|
|
|
clangEdit
|
|
|
|
clangAnalysis
|
|
|
|
clangASTMatchers
|
|
|
|
clangAST
|
|
|
|
clangLex
|
|
|
|
clangBasic
|
|
|
|
)
|
|
|
|
|
2024-03-07 23:53:03 +00:00
|
|
|
set(_clang_LIBRARIES)
|
|
|
|
foreach(COMPONENT ${_clang_FIND_COMPONENTS})
|
2021-02-24 14:13:37 +00:00
|
|
|
string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
|
|
|
|
|
|
|
|
find_library(CLANG_${UPPERCOMPONENT}_LIBRARY
|
|
|
|
NAMES
|
|
|
|
${COMPONENT}
|
|
|
|
HINTS
|
2024-03-07 23:53:03 +00:00
|
|
|
${_clang_SEARCH_DIRS}
|
2021-02-24 14:13:37 +00:00
|
|
|
PATH_SUFFIXES
|
|
|
|
lib64 lib
|
|
|
|
)
|
2023-03-22 13:15:46 +00:00
|
|
|
if(CLANG_${UPPERCOMPONENT}_LIBRARY)
|
2024-03-07 23:53:03 +00:00
|
|
|
list(APPEND _clang_LIBRARIES "${CLANG_${UPPERCOMPONENT}_LIBRARY}")
|
2023-03-22 13:15:46 +00:00
|
|
|
endif()
|
2021-02-24 14:13:37 +00:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
|
|
# Handle the QUIETLY and REQUIRED arguments and set CLANG_FOUND to TRUE if
|
|
|
|
# all listed variables are TRUE.
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
find_package_handle_standard_args(Clang DEFAULT_MSG
|
2024-03-07 23:53:03 +00:00
|
|
|
_clang_LIBRARIES CLANG_INCLUDE_DIR)
|
2021-02-24 14:13:37 +00:00
|
|
|
|
|
|
|
if(CLANG_FOUND)
|
2024-03-07 23:53:03 +00:00
|
|
|
set(CLANG_LIBRARIES ${_clang_LIBRARIES})
|
2021-02-24 14:13:37 +00:00
|
|
|
set(CLANG_INCLUDE_DIRS ${CLANG_INCLUDE_DIR})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
mark_as_advanced(
|
|
|
|
CLANG_INCLUDE_DIR
|
|
|
|
)
|
|
|
|
|
2024-03-07 23:53:03 +00:00
|
|
|
foreach(COMPONENT ${_clang_FIND_COMPONENTS})
|
2021-02-24 14:13:37 +00:00
|
|
|
string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
|
|
|
|
mark_as_advanced(CLANG_${UPPERCOMPONENT}_LIBRARY)
|
|
|
|
endforeach()
|
|
|
|
|
2024-03-07 23:53:03 +00:00
|
|
|
unset(_clang_SEARCH_DIRS)
|
|
|
|
unset(_clang_FIND_COMPONENTS)
|
|
|
|
unset(_clang_LIBRARIES)
|