+# Set up execinfo
+
+# The problem with this library is that it is built-in in the Linux glib,
+# while on systems like FreeBSD, it is installed separately and thus needs to be linked to.
+# Therefore, we search for the header to see if the it's available in the first place.
+# If it is available, we try to locate the library to figure out whether it is built-in or not.
+
+find_path(EXECINFO_H_DIR "execinfo.h")
+
+if(NOT EXECINFO_H_DIR STREQUAL "EXECINFO_H_DIR-NOTFOUND")
+ # We found the header file's include dir.
+ # Let's add it so the compiler finds it as well.
+ include_directories(${EXECINFO_H_DIR})
+
+ # Now determine if it's built-in or not, by searching the library file.
+ find_library(EXECINFO_LIB_PATH "execinfo")
+
+ if(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
+ # Built-in, no further action is needed
+ message(STATUS "Found execinfo")
+ else(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
+ # It's an external library, link it.
+ link_libraries(${EXECINFO_LIB_PATH})
+ message(STATUS "Found execinfo: ${EXECINFO_LIB_PATH}")
+ endif(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
+
+ set(HAVE_EXECINFO true)
+
+endif(NOT EXECINFO_H_DIR STREQUAL "EXECINFO_H_DIR-NOTFOUND")
+
+if(HAVE_EXECINFO)
+ add_definitions(-DHAVE_EXECINFO)
+endif(HAVE_EXECINFO)