1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2# 3# Copyright 2023 Google LLC 4# 5# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); 6# you may not use this file except in compliance with the License. You may 7# obtain a copy of the License at 8# 9# https://llvm.org/LICENSE.txt 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14# License for the specific language governing permissions and limitations under 15# the License. 16# 17# Author: Aleksei Vetrov 18 19#[=======================================================================[.rst: 20FindLibDw 21--------- 22 23Finds the DWARF processing library (libdw). 24 25Imported Targets 26^^^^^^^^^^^^^^^^ 27 28This module provides the following imported targets, if found: 29 30``LibDw::LibDw`` 31 The LibDw library 32 33Result Variables 34^^^^^^^^^^^^^^^^ 35 36This will define the following variables: 37 38``LibDw_FOUND`` 39 True if the system has the LibDw library. 40``LibDw_VERSION`` 41 The version of the LibDw library which was found. 42``LibDw_INCLUDE_DIRS`` 43 Include directories needed to use LibDw. 44``LibDw_LIBRARIES`` 45 Libraries needed to link to LibDw. 46``LibDw_DEFINITIONS`` 47 the compiler switches required for using LibDw 48 49Cache Variables 50^^^^^^^^^^^^^^^ 51 52The following cache variables may also be set: 53 54``LibDw_INCLUDE_DIR`` 55 The directory containing ``dwarf.h``. 56``LibDw_LIBRARY`` 57 The path to the ``libdw.so``. 58 59#]=======================================================================] 60 61find_package(PkgConfig) 62pkg_check_modules(PC_LibDw QUIET libdw) 63 64find_library( 65 LibDw_LIBRARY 66 NAMES dw 67 HINTS ${PC_LibDw_LIBDIR} ${PC_LibDw_LIBRARY_DIRS}) 68# Try the value from user if the library is not found. 69if(DEFINED LibDw_LIBRARIES AND NOT DEFINED LibDw_LIBRARY) 70 set(LibDw_LIBRARY ${LibDw_LIBRARIES}) 71endif() 72mark_as_advanced(LibDw_LIBRARY) 73 74find_path( 75 LibDw_INCLUDE_DIR 76 NAMES dwarf.h 77 HINTS ${PC_LibDw_INCLUDEDIR} ${PC_LibDw_INCLUDE_DIRS}) 78# Try the value from user if the library is not found. 79if(DEFINED LibDw_INCLUDE_DIRS AND NOT DEFINED LibDw_INCLUDE_DIR) 80 set(LibDw_INCLUDE_DIR ${LibDw_INCLUDE_DIRS}) 81endif() 82mark_as_advanced(LibDw_INCLUDE_DIR) 83 84set(LibDw_VERSION ${PC_LibDw_VERSION}) 85 86include(FindPackageHandleStandardArgs) 87find_package_handle_standard_args( 88 LibDw 89 REQUIRED_VARS LibDw_LIBRARY LibDw_INCLUDE_DIR 90 VERSION_VAR LibDw_VERSION) 91 92if(LibDw_FOUND) 93 set(LibDw_LIBRARIES ${LibDw_LIBRARY}) 94 set(LibDw_INCLUDE_DIRS ${LibDw_INCLUDE_DIR}) 95 set(LibDw_DEFINITIONS ${PC_LibDw_CFLAGS_OTHER}) 96endif() 97 98if(LibDw_FOUND AND NOT TARGET LibDw::LibDw) 99 add_library(LibDw::LibDw UNKNOWN IMPORTED) 100 set_target_properties( 101 LibDw::LibDw 102 PROPERTIES IMPORTED_LOCATION "${LibDw_LIBRARY}" 103 INTERFACE_COMPILE_OPTIONS "${PC_LibDw_CFLAGS_OTHER}" 104 INTERFACE_INCLUDE_DIRECTORIES "${LibDw_INCLUDE_DIR}") 105endif() 106