-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alex Chi <iskyzh@gmail.com> fix clang-tidy Signed-off-by: Alex Chi <iskyzh@gmail.com>
- Loading branch information
Showing
11 changed files
with
471 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# Copyright (c) 2004-present, Facebook, Inc. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the hphp/hsl/ subdirectory of this source tree. | ||
|
||
# - Try to find libdwarf | ||
# Once done this will define | ||
# | ||
# LIBDWARF_FOUND - system has libdwarf | ||
# LIBDWARF_INCLUDE_DIRS - the libdwarf include directory | ||
# LIBDWARF_LIBRARIES - Link these to use libdwarf | ||
# LIBDWARF_DEFINITIONS - Compiler switches required for using libdwarf | ||
# | ||
|
||
# Locate libelf library at first | ||
if(NOT LIBELF_FOUND) | ||
find_package(LibElf) | ||
endif(NOT LIBELF_FOUND) | ||
|
||
if(LIBDWARF_LIBRARIES AND LIBDWARF_INCLUDE_DIRS) | ||
set(LibDwarf_FIND_QUIETLY TRUE) | ||
endif(LIBDWARF_LIBRARIES AND LIBDWARF_INCLUDE_DIRS) | ||
|
||
find_package(PkgConfig) | ||
pkg_check_modules(PkgConfig_LibDwarf QUIET libdwarf) | ||
|
||
find_path(DWARF_INCLUDE_DIR | ||
NAMES | ||
libdwarf.h dwarf.h | ||
PATHS | ||
${PkgConfig_LibDwarf_INCLUDE_DIRS} | ||
/usr/include | ||
/usr/include/libdwarf | ||
/usr/local/include | ||
/usr/local/include/libdwarf | ||
/opt/local/include | ||
/sw/include | ||
ENV CPATH) # PATH and INCLUDE will also work | ||
|
||
if(DWARF_INCLUDE_DIR) | ||
set(LIBDWARF_INCLUDE_DIRS ${DWARF_INCLUDE_DIR}) | ||
endif() | ||
|
||
find_library(LIBDWARF_LIBRARIES | ||
NAMES | ||
dwarf libdwarf | ||
PATHS | ||
/usr/lib | ||
/usr/local/lib | ||
/opt/local/lib | ||
/sw/lib | ||
${PkgConfig_LibDwarf_LIBRARY_DIRS} | ||
ENV LIBRARY_PATH # PATH and LIB will also work | ||
ENV LD_LIBRARY_PATH) | ||
include(FindPackageHandleStandardArgs) | ||
|
||
# handle the QUIETLY and REQUIRED arguments and set LIBDWARF_FOUND to TRUE | ||
# if all listed variables are TRUE | ||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibDwarf DEFAULT_MSG | ||
LIBELF_FOUND | ||
LIBDWARF_LIBRARIES | ||
LIBDWARF_INCLUDE_DIRS) | ||
|
||
if(LIBDWARF_LIBRARIES AND LIBDWARF_INCLUDE_DIRS) | ||
set(CMAKE_REQUIRED_INCLUDES ${LIBDWARF_INCLUDE_DIRS}) | ||
set(CMAKE_REQUIRED_LIBRARIES ${LIBDWARF_LIBRARIES} ${LIBELF_LIBRARIES}) | ||
|
||
# libdwarf makes breaking changes occasionally and doesn't provide an easy | ||
# way to test for them. The following checks should detect the changes and | ||
# pass that information on accordingly. | ||
INCLUDE(CheckCXXSourceCompiles) | ||
INCLUDE(CheckFunctionExists) | ||
|
||
MACRO(CHECK_LIBDWARF_INIT init params var) | ||
# Check for the existence of this particular init function. | ||
unset(INIT_EXISTS CACHE) | ||
CHECK_FUNCTION_EXISTS(${init} INIT_EXISTS) | ||
|
||
if(INIT_EXISTS) | ||
set(LIBDWARF_USE_INIT_C ${var}) | ||
|
||
# Check to see if we can use a const name. | ||
unset(DW_CONST CACHE) | ||
|
||
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") | ||
# -std=c++11 is already set in HPHPCompiler.cmake, don't | ||
# add -std=c++0x on top of that or clang will give errors | ||
set(CMAKE_REQUIRED_FLAGS "-std=c++0x") | ||
endif() | ||
|
||
CHECK_CXX_SOURCE_COMPILES(" | ||
#include <libdwarf.h> | ||
#include <cstddef> | ||
int dwarfCallback(const char * a, int b, Dwarf_Unsigned c, | ||
Dwarf_Unsigned d, Dwarf_Unsigned e, Dwarf_Unsigned f, | ||
Dwarf_Unsigned * g, Dwarf_Ptr h, int * i) {} | ||
int main() { ${init}(${params}); return 0; }" DW_CONST) | ||
|
||
if(DW_CONST) | ||
set(LIBDWARF_CONST_NAME 1) | ||
else() | ||
set(LIBDWARF_CONST_NAME 0) | ||
endif() | ||
endif() | ||
ENDMACRO(CHECK_LIBDWARF_INIT) | ||
|
||
# Order is important, last one is used. | ||
CHECK_LIBDWARF_INIT("dwarf_producer_init" | ||
"0, dwarfCallback, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr" 0) | ||
CHECK_LIBDWARF_INIT("dwarf_producer_init_c" "0, dwarfCallback, nullptr, nullptr, nullptr, nullptr" 1) | ||
|
||
set(CMAKE_REQUIRED_INCLUDES) | ||
set(CMAKE_REQUIRED_LIBRARIES) | ||
endif() | ||
|
||
if(LIBDWARF_CONST_NAME) | ||
message(STATUS "libdwarf uses const char* type") | ||
else() | ||
message(STATUS "libdwarf uses char* type") | ||
endif() | ||
|
||
if(LIBDWARF_USE_INIT_C) | ||
message(STATUS "libdwarf has dwarf_producer_init_c") | ||
else() | ||
message(STATUS "libdwarf does not have dwarf_producer_init_c, using dwarf_producer_init") | ||
endif() | ||
|
||
mark_as_advanced(LIBDW_INCLUDE_DIR DWARF_INCLUDE_DIR) | ||
mark_as_advanced(LIBDWARF_INCLUDE_DIRS LIBDWARF_LIBRARIES) | ||
mark_as_advanced(LIBDWARF_CONST_NAME LIBDWARF_USE_INIT_C) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# - Try to find libelf | ||
# Once done this will define | ||
# | ||
# LIBELF_FOUND - system has libelf | ||
# LIBELF_INCLUDE_DIRS - the libelf include directory | ||
# LIBELF_LIBRARIES - Link these to use libelf | ||
# LIBELF_DEFINITIONS - Compiler switches required for using libelf | ||
# | ||
# Copyright (c) 2008 Bernhard Walle <bernhard.walle@gmx.de> | ||
# | ||
# Redistribution and use is allowed according to the terms of the New | ||
# BSD license. | ||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. | ||
# | ||
|
||
if(LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS) | ||
set(LibElf_FIND_QUIETLY TRUE) | ||
endif(LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS) | ||
|
||
find_package(PkgConfig) | ||
pkg_check_modules(PkgConfig_LibElf QUIET libelf) | ||
|
||
find_path(LIBELF_INCLUDE_DIRS | ||
NAMES | ||
libelf.h | ||
PATHS | ||
${PkgConfig_LibElf_INCLUDE_DIRS} | ||
/usr/include | ||
/usr/include/libelf | ||
/usr/local/include | ||
/usr/local/include/libelf | ||
/opt/local/include | ||
/opt/local/include/libelf | ||
/sw/include | ||
/sw/include/libelf | ||
ENV CPATH) | ||
|
||
find_library(LIBELF_LIBRARIES | ||
NAMES | ||
elf | ||
PATHS | ||
/usr/lib | ||
/usr/local/lib | ||
/opt/local/lib | ||
/sw/lib | ||
${PkgConfig_LibElf_LIBRARY_DIRS} | ||
ENV LIBRARY_PATH | ||
ENV LD_LIBRARY_PATH) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
|
||
# handle the QUIETLY and REQUIRED arguments and set LIBELF_FOUND to TRUE if all listed variables are TRUE | ||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibElf DEFAULT_MSG | ||
LIBELF_LIBRARIES | ||
LIBELF_INCLUDE_DIRS) | ||
|
||
SET(CMAKE_REQUIRED_LIBRARIES elf) | ||
INCLUDE(CheckCXXSourceCompiles) | ||
CHECK_CXX_SOURCE_COMPILES("#include <libelf.h> | ||
int main() { | ||
Elf *e = (Elf*)0; | ||
size_t sz; | ||
elf_getshdrstrndx(e, &sz); | ||
return 0; | ||
}" ELF_GETSHDRSTRNDX) | ||
SET(CMAKE_REQUIRED_LIBRARIES) | ||
|
||
mark_as_advanced(LIBELF_INCLUDE_DIRS LIBELF_LIBRARIES ELF_GETSHDRSTRNDX) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.