mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 15:10:19 +00:00
AK+CMake: Use the find module to find the correct backtrace(3) header
As recommended by the CMake docs, let's tolerate systems or setups that don't have backtrace(3) in the `<execinfo.h>` header file, such as those using libbacktrace directly.
This commit is contained in:
parent
29b4f21c7b
commit
002bef8635
Notes:
sideshowbarker
2024-07-16 21:51:02 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/002bef8635 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/277
3 changed files with 32 additions and 11 deletions
|
@ -5,15 +5,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
|
#include <AK/Backtrace.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/Platform.h>
|
#include <AK/Platform.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
|
||||||
#if (defined(AK_OS_LINUX) && !defined(AK_OS_ANDROID)) || defined(AK_LIBC_GLIBC) || defined(AK_OS_BSD_GENERIC) || defined(AK_OS_SOLARIS) || defined(AK_OS_HAIKU)
|
|
||||||
# define EXECINFO_BACKTRACE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(AK_OS_ANDROID) && (__ANDROID_API__ >= 33)
|
#if defined(AK_OS_ANDROID) && (__ANDROID_API__ >= 33)
|
||||||
# include <android/log.h>
|
# include <android/log.h>
|
||||||
# define EXECINFO_BACKTRACE
|
# define EXECINFO_BACKTRACE
|
||||||
|
@ -22,9 +19,8 @@
|
||||||
# define PRINT_ERROR(s) (void)fputs((s), stderr)
|
# define PRINT_ERROR(s) (void)fputs((s), stderr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(EXECINFO_BACKTRACE)
|
#if defined(AK_HAS_BACKTRACE_HEADER)
|
||||||
# include <cxxabi.h>
|
# include <cxxabi.h>
|
||||||
# include <execinfo.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(AK_OS_SERENITY)
|
#if defined(AK_OS_SERENITY)
|
||||||
|
@ -33,7 +29,7 @@
|
||||||
# define ERRORLN warnln
|
# define ERRORLN warnln
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(EXECINFO_BACKTRACE)
|
#if defined(AK_HAS_BACKTRACE_HEADER)
|
||||||
namespace {
|
namespace {
|
||||||
ALWAYS_INLINE void dump_backtrace()
|
ALWAYS_INLINE void dump_backtrace()
|
||||||
{
|
{
|
||||||
|
@ -100,7 +96,7 @@ void ak_verification_failed(char const* message)
|
||||||
else
|
else
|
||||||
ERRORLN("VERIFICATION FAILED: {}", message);
|
ERRORLN("VERIFICATION FAILED: {}", message);
|
||||||
|
|
||||||
#if defined(EXECINFO_BACKTRACE)
|
#if defined(AK_HAS_BACKTRACE_HEADER)
|
||||||
dump_backtrace();
|
dump_backtrace();
|
||||||
#endif
|
#endif
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
|
|
17
AK/Backtrace.h.in
Normal file
17
AK/Backtrace.h.in
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#cmakedefine Backtrace_FOUND
|
||||||
|
#if defined(Backtrace_FOUND)
|
||||||
|
# define AK_HAS_BACKTRACE_HEADER
|
||||||
|
# undef Backtrace_FOUND
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(AK_HAS_BACKTRACE_HEADER)
|
||||||
|
# include <@Backtrace_HEADER@>
|
||||||
|
#endif
|
|
@ -329,9 +329,16 @@ install(TARGETS LibC LibCrypt NoCoverage EXPORT LagomTargets)
|
||||||
add_serenity_subdirectory(AK)
|
add_serenity_subdirectory(AK)
|
||||||
lagom_lib(AK ak SOURCES ${AK_SOURCES})
|
lagom_lib(AK ak SOURCES ${AK_SOURCES})
|
||||||
find_package(Backtrace)
|
find_package(Backtrace)
|
||||||
if (Backtrace_FOUND AND NOT "${Backtrace_LIBRARIES}" STREQUAL "")
|
configure_file(../../AK/Backtrace.h.in AK/Backtrace.h @ONLY)
|
||||||
target_link_libraries(AK PRIVATE ${Backtrace_LIBRARIES})
|
if (Backtrace_FOUND)
|
||||||
target_include_directories(AK PRIVATE ${Backtrace_INCLUDE_DIRS})
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.30)
|
||||||
|
target_link_libraries(AK PRIVATE Backtrace::Backtrace)
|
||||||
|
else()
|
||||||
|
target_include_directories(AK PRIVATE ${Backtrace_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(AK PRIVATE ${Backtrace_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(WARNING "Backtrace not found, stack traces will be unavailable")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# LibCoreMinimal
|
# LibCoreMinimal
|
||||||
|
@ -361,6 +368,7 @@ install(
|
||||||
)
|
)
|
||||||
install(FILES
|
install(FILES
|
||||||
${Lagom_BINARY_DIR}/AK/Debug.h
|
${Lagom_BINARY_DIR}/AK/Debug.h
|
||||||
|
${Lagom_BINARY_DIR}/AK/Backtrace.h
|
||||||
COMPONENT Lagom_Development
|
COMPONENT Lagom_Development
|
||||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/AK"
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/AK"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue