This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 0f822d4110 Add support for libunwind in CMake build (#9862)
0f822d4110 is described below

commit 0f822d41105545880e3b08a2647b38663dfbd474
Author: JosiahWI <[email protected]>
AuthorDate: Fri Jun 16 13:55:13 2023 -0500

    Add support for libunwind in CMake build (#9862)
    
    * Add support for libunwind in CMake build
    
    This adds an option that defaults to ON: ENABLE_UNWIND. On Linux,
    CMake will look for the library and link it globally if it is found.
    On other OSs, CMake will skip the check, because libunwind is only
    available on Linux.
    
    * Move find_package(unwind) to Linux build section
    
    This consolidates the Linux-specific settings.
    
    * Do not REQUIRE libunwind
    
    * Move find_package(unwind) back with other packages
    
    libunwind is also available on Mac, and since we don't fail if
    it's not found, there's no reason to look for it only on some
    operating systems.
---
 CMakeLists.txt                       |  9 +++++++
 cmake/Findunwind.cmake               | 49 ++++++++++++++++++++++++++++++++++++
 include/tscore/ink_config.h.cmake.in |  1 +
 3 files changed, 59 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4040d781a1..691ac7d393 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,6 +48,7 @@ option(ENABLE_POSIX_CAP
 )
 option(ENABLE_PROFILER "Use gperftools profiler (default OFF)")
 option(ENABLE_TCMALLOC "Use TCMalloc (default OFF)")
+option(ENABLE_UNWIND "Use libunwind if found on system (default ON)" ON)
 set(TS_MAX_HOST_NAME_LEN 256 CACHE STRING "Max host name length (default 256)")
 set(TS_USE_SET_RBIO 1 CACHE STRING "Use openssl set_rbio (default 1)")
 set(TS_USE_DIAGS 1 CACHE STRING "Use diags (default 1)")
@@ -151,6 +152,14 @@ if(TSMallocReplacement_FOUND)
     link_libraries(ts::TSMallocReplacement)
 endif()
 
+if(ENABLE_UNWIND)
+    find_package(unwind)
+    if(unwind_FOUND)
+            link_libraries(unwind::unwind)
+    endif()
+    set(TS_USE_REMOTE_UNWINDING ${unwind_FOUND})
+endif()
+
 find_package(ZLIB REQUIRED)
 
 include(Check128BitCas)
diff --git a/cmake/Findunwind.cmake b/cmake/Findunwind.cmake
new file mode 100644
index 0000000000..42d356a01b
--- /dev/null
+++ b/cmake/Findunwind.cmake
@@ -0,0 +1,49 @@
+#######################
+#
+#  Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+#  agreements.  See the NOTICE file distributed with this work for additional 
information regarding
+#  copyright ownership.  The ASF licenses this file to you under the Apache 
License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with the 
License.  You may obtain
+#  a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software 
distributed under the License
+#  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+#  or implied. See the License for the specific language governing permissions 
and limitations under
+#  the License.
+#
+#######################
+
+# Findunwind.cmake
+#
+# This will define the following variables
+#
+#     unwind_FOUND
+#     unwind_LIBRARY
+#     unwind_INCLUDE_DIRS
+#
+# and the following imported targets
+#
+#     unwind::unwind
+#
+
+find_library(unwind_LIBRARY NAMES unwind)
+find_path(unwind_INCLUDE_DIR NAMES unwind.h)
+
+mark_as_advanced(unwind_FOUND unwind_LIBRARY unwind_INCLUDE_DIR)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(unwind
+    REQUIRED_VARS unwind_LIBRARY unwind_INCLUDE_DIR
+)
+
+if(unwind_FOUND)
+    set(unwind_INCLUDE_DIRS ${unwind_INCLUDE_DIR})
+endif()
+
+if(unwind_FOUND AND NOT TARGET unwind::unwind)
+    add_library(unwind::unwind INTERFACE IMPORTED)
+    target_include_directories(unwind::unwind INTERFACE ${unwind_INCLUDE_DIRS})
+    target_link_libraries(unwind::unwind INTERFACE "${unwind_LIBRARY}")
+endif()
diff --git a/include/tscore/ink_config.h.cmake.in 
b/include/tscore/ink_config.h.cmake.in
index 472367b73a..8ae1dcc945 100644
--- a/include/tscore/ink_config.h.cmake.in
+++ b/include/tscore/ink_config.h.cmake.in
@@ -128,6 +128,7 @@ const int DEFAULT_STACKSIZE = @DEFAULT_STACK_SIZE@;
 #cmakedefine01 TS_USE_LINUX_IO_URING
 #cmakedefine01 TS_USE_LINUX_NATIVE_AIO
 #cmakedefine01 TS_USE_POSIX_CAP
+#cmakedefine01 TS_USE_REMOTE_UNWINDING
 #cmakedefine01 TS_USE_SET_RBIO
 #cmakedefine01 TS_USE_TLS13
 

Reply via email to