blob: c0eefc54b9f4cbfd4d2760d8d6b090009944a40a [file] [log] [blame]
Imre Kisc0d4b442019-12-03 23:52:26 +01001#
2# Copyright (c) 2019, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7#[=======================================================================[.rst:
8FindLibClang
9-------
10
11Finds the LibClang library.
12
13Imported Targets
14^^^^^^^^^^^^^^^^
15
16This module provides the following imported targets, if found:
17
18``LibClang``
19 The Clang library
20
21Result Variables
22^^^^^^^^^^^^^^^^
23
24This will define the following variables:
25
26``LibClang_FOUND``
27 True if the system has the Clang library.
28``LibClang_LIBRARY_DIRS``
29 Libraries needed to link to Clang.
30
31#]=======================================================================]
32
33
34# 1. Use llvm-config
35find_program(_LLVM_CONFIG_COMMAND "llvm-config")
36
37if (_LLVM_CONFIG_COMMAND)
38 message(STATUS "Setting LibClang_LIBRARY_DIRS using ${_LLVM_CONFIG_COMMAND}")
39
40 execute_process(
41 COMMAND ${_LLVM_CONFIG_COMMAND} --libdir
42 OUTPUT_VARIABLE _LLVM_CONFIG_OUTPUT
43 )
44
45 # Stripping newline
46 string(STRIP ${_LLVM_CONFIG_OUTPUT} LibClang_LIBRARY_DIRS)
47endif()
48
49# 2. Try to find as library
50if (NOT LibClang_LIBRARY_DIRS)
51 message(STATUS "Setting LibClang_LIBRARY_DIRS based on common directories list")
52
53 set(LIBCLANG_COMMON_PATHS
54 /usr/lib/llvm-9/lib
55 /usr/lib/llvm-8/lib
56 /usr/lib/llvm-7/lib
57 /usr/lib/llvm-6.0/lib)
58
59 if (WIN32)
60 set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
61 set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll")
62
63 get_filename_component(LLVM_PATH_FROM_REGISTRY [HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\LLVM\\LLVM] ABSOLUTE)
64 list(APPEND LIBCLANG_COMMON_PATHS "${LLVM_PATH_FROM_REGISTRY}/bin")
65 endif()
66
67 find_library(_LIBCLANG_PATH
68 NAMES clang
69 HINTS ${LIBCLANG_COMMON_PATHS}
70 )
71
72 if (_LIBCLANG_PATH)
73 get_filename_component(LibClang_LIBRARY_DIRS ${_LIBCLANG_PATH} DIRECTORY)
74 endif()
75endif()
76
77include(FindPackageHandleStandardArgs)
78find_package_handle_standard_args(LibClang
79 "Please install llvm-config or set LibClang path manually"
80 LibClang_LIBRARY_DIRS
81)