[PATCH 4/9] Add libbacktrace CMake build script

Alexander Monakov amonakov at ispras.ru
Sun May 19 07:39:50 PDT 2013


---
 thirdparty/libbacktrace/CMakeLists.txt    | 140 ++++++++++++++++++++++++++++++
 thirdparty/libbacktrace/config.h.in.cmake |  21 +++++
 2 files changed, 161 insertions(+)
 create mode 100644 thirdparty/libbacktrace/CMakeLists.txt
 create mode 100644 thirdparty/libbacktrace/config.h.in.cmake

diff --git a/thirdparty/libbacktrace/CMakeLists.txt b/thirdparty/libbacktrace/CMakeLists.txt
new file mode 100644
index 0000000..7078780
--- /dev/null
+++ b/thirdparty/libbacktrace/CMakeLists.txt
@@ -0,0 +1,140 @@
+#    CMakeLists.txt -- libbacktrace CMake build script
+#    Contributed by Alexander Monakov, ISP RAS
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     (1) Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#
+#     (2) Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in
+#     the documentation and/or other materials provided with the
+#     distribution.
+#
+#     (3) The name of the author may not be used to
+#     endorse or promote products derived from this software without
+#     specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.  */
+
+cmake_minimum_required (VERSION 2.8)
+
+project (libbacktrace)
+
+set (BACKTRACE_SUPPORTED 1)
+
+include (CheckSymbolExists)
+check_symbol_exists (_Unwind_Backtrace unwind.h HAVE_BACKTRACE)
+check_symbol_exists (_Unwind_GetIPInfo unwind.h HAVE_GETIPINFO)
+
+if (HAVE_BACKTRACE)
+    set (BACKTRACE_FILE backtrace.c simple.c)
+else ()
+    set (BACKTRACE_FILE nounwind.c)
+    set (BACKTRACE_SUPPORTED 0)
+endif ()
+
+include (CheckCCompilerFlag)
+check_c_compiler_flag ("-funwind-tables" FLAG_UNWIND_TABLES)
+if (FLAG_UNWIND_TABLES)
+    add_definitions ("-funwind-tables")
+endif ()
+
+add_definitions ("-fPIC")
+
+# Adjust warnings
+if (CMAKE_COMPILER_IS_GNUCC)
+    add_definitions ("-Wno-switch -Wno-enum-compare")
+endif ()
+
+check_c_source_compiles (
+    "int i;
+    int main() {
+    __sync_bool_compare_and_swap (&i, i, i);
+    __sync_lock_test_and_set (&i, 1);
+    __sync_lock_release (&i);}"
+    HAVE_SYNC_FUNCTIONS)
+
+if (HAVE_SYNC_FUNCTIONS)
+    set (BACKTRACE_SUPPORTS_THREADS 1)
+else ()
+    set (BACKTRACE_SUPPORTS_THREADS 0)
+endif ()
+
+if (CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
+    set (FORMAT_FILE elf.c dwarf.c)
+    math (EXPR BACKTRACE_ELF_SIZE 8*${CMAKE_C_SIZEOF_DATA_PTR})
+else ()
+    set (FORMAT_FILE unknown.c)
+    set (BACKTRACE_SUPPORTED 0)
+endif ()
+
+check_symbol_exists (mmap sys/mman.h HAVE_MMAP)
+
+if (HAVE_MMAP)
+    set (VIEW_FILE mmapio.c)
+    check_symbol_exists (MAP_ANONYMOUS sys/mman.h HAVE_MMAP_ANONYMOUS)
+    check_symbol_exists (MAP_ANON sys/mman.h HAVE_MMAP_ANON)
+    if (HAVE_MMAP_ANONYMOUS AND HAVE_MMAP_ANON)
+	set (ALLOC_FILE mmap.c)
+    else ()
+	set (ALLOC_FILE alloc.c)
+    endif ()
+else ()
+    set (VIEW_FILE read.c)
+    set (ALLOC_FILE alloc.c)
+endif ()
+
+if (ALLOC_FILE STREQUAL "alloc.c")
+    set (BACKTRACE_USES_MALLOC 1)
+else ()
+    set (BACKTRACE_USES_MALLOC 0)
+endif ()
+
+add_definitions ("-D_GNU_SOURCE")
+set (CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE)
+check_symbol_exists (dl_iterate_phdr link.h HAVE_DL_ITERATE_PHDR)
+
+include (CheckFunctionExists)
+check_function_exists (fcntl HAVE_FCNTL)
+
+check_function_exists (strnlen HAVE_DECL_STRNLEN)
+
+check_function_exists (getexecname HAVE_GETEXECNAME)
+
+include (CheckIncludeFile)
+check_include_file (dwarf.h HAVE_DWARF_H)
+if (NOT HAVE_DWARF_H)
+    set (FORMAT_FILE unknown.c)
+    set (BACKTRACE_SUPPORTED 0)
+endif ()
+
+configure_file (backtrace-supported.h.in backtrace-supported.h)
+
+configure_file (config.h.in.cmake config.h)
+
+include_directories ("auxincl")
+add_library (backtrace STATIC EXCLUDE_FROM_ALL
+    ${BACKTRACE_FILE} ${FORMAT_FILE} ${VIEW_FILE} ${ALLOC_FILE}
+    fileline.c posix.c print.c state.c)
+
+set (ENABLE_LIBBACKTRACE_TEST false CACHE BOOL "Enable libbacktrace testing")
+if (ENABLE_LIBBACKTRACE_TEST)
+    enable_testing ()
+    add_executable (btest btest.c)
+    set_property (SOURCE btest.c PROPERTY COMPILE_FLAGS "-g")
+    target_link_libraries (btest backtrace)
+    add_test (test-libbacktrace btest)
+endif ()
diff --git a/thirdparty/libbacktrace/config.h.in.cmake b/thirdparty/libbacktrace/config.h.in.cmake
new file mode 100644
index 0000000..b78e970
--- /dev/null
+++ b/thirdparty/libbacktrace/config.h.in.cmake
@@ -0,0 +1,21 @@
+/* ELF size: 32 or 64 */
+#define BACKTRACE_ELF_SIZE @BACKTRACE_ELF_SIZE@
+
+/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
+   don't. */
+#cmakedefine HAVE_DECL_STRNLEN 1
+
+/* Define if dl_iterate_phdr is available. */
+#cmakedefine HAVE_DL_ITERATE_PHDR 1
+
+/* Define to 1 if you have the fcntl function */
+#cmakedefine HAVE_FCNTL 1
+
+/* Define if getexecname is available. */
+#cmakedefine HAVE_GETEXECNAME 1
+
+/* Define if _Unwind_GetIPInfo is available. */
+#cmakedefine HAVE_GETIPINFO 1
+
+/* Define to 1 if you have the __sync functions */
+#cmakedefine HAVE_SYNC_FUNCTIONS 1
-- 
1.8.1.2



More information about the apitrace mailing list