1 #-------------------------------------------------------------------------------
2 # ______ ______ ____ __ __
3 # | ____| | ____/ __ \ /\ | \/ |
4 # | |__ _ __ ___ ___| |__ | | | | / \ | \ / |
5 # | __| '__/ _ \/ _ \ __|| | | |/ /\ \ | |\/| |
6 # | | | | | __/ __/ | | |__| / ____ \| | | |
7 # |_| |_| \___|\___|_| \____/_/ \_\_| |_|
9 # FreeFOAM: The Cross-Platform CFD Toolkit
11 # Copyright (C) 2009 Michael Wild <themiwi@users.sf.net>
12 # Gerber van der Graaf <gerber_graaf@users.sf.net>
13 #-------------------------------------------------------------------------------
15 # This file is part of FreeFOAM.
17 # FreeFOAM is free software; you can redistribute it and/or modify it
18 # under the terms of the GNU General Public License as published by the
19 # Free Software Foundation; either version 2 of the License, or (at your
20 # option) any later version.
22 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
23 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 # You should have received a copy of the GNU General Public License
28 # along with FreeFOAM; if not, write to the Free Software Foundation,
29 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #-------------------------------------------------------------------------------
32 # - Find execinfo (i.e. backtrace() and backtrace_symbols())
34 # This module looks for execinfo support and defines the following values
35 # EXECINFO_FOUND TRUE if execinfo has been found
36 # EXECINFO_INCLUDE_DIRS include path for execinfo
37 # EXECINFO_LIBRARIES libraries to link against (if required)
39 include( FFDetectChangedValue )
41 # take extra care on APPLE, the result depends on the sysroot and the deployment target
43 ff_detect_changed_value( __find_execinfo_CMAKE_OSX_SYSROOT_CHANGED CMAKE_OSX_SYSROOT
44 EXECINFO_INCLUDE_DIR )
45 ff_detect_changed_value( __find_execinfo_CMAKE_OSX_DEPLOYMENT_TARGET_CHANGED CMAKE_OSX_DEPLOYMENT_TARGET
46 EXECINFO_INCLUDE_DIR )
47 set( __find_execinfo_FIND_PATH_OPTS PATHS
48 ${CMAKE_OSX_SYSROOT}/usr/include
51 set( __find_execinfo_FIND_PATH_OPTS )
54 find_path( EXECINFO_INCLUDE_DIR
56 ${__find_execinfo_FIND_PATH_OPTS}
58 mark_as_advanced( EXECINFO_INCLUDE_DIR )
60 set( EXECINFO_INCLUDE_DIRS ${EXECINFO_INCLUDE_DIR} )
62 # now check whether libexecinfo is required
63 set( __find_execinfo_LINK_LIBRARIES ${LINK_LIBRARIES} )
64 set( __find_execinfo_test_SRC
65 "#include <execinfo.h>
68 int frames = backtrace(callstack, 128);
69 char** strs = backtrace_symbols(callstack, frames);
74 set( __find_execinfo_COMPILES FALSE )
75 set( __find_execinfo_REQUIRED_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${EXECINFO_INCLUDE_DIR}" )
76 foreach( __find_execinfo_with_lib FALSE TRUE )
77 if( NOT __find_execinfo_COMPILES )
78 if( __find_execinfo_with_lib )
79 find_library( EXECINFO_LIBRARY NAMES execinfo )
80 mark_as_advanced( EXECINFO_LIBRARY )
81 set( __find_execinfo_REQUIRED_LIBS "-DLINK_LIBRARIES=${EXECINFO_LIBRARY}" )
82 else( __find_execinfo_with_lib )
83 set( __find_execinfo_REQUIRED_LIBS )
84 endif( __find_execinfo_with_lib )
86 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/execinfo_test.c
87 "${__find_execinfo_test_SRC}"
89 try_compile( __find_execinfo_COMPILES ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
90 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/execinfo_test.c
91 CMAKE_FLAGS "${__find_execinfo_REQUIRED_LIBS}" "${__find_execinfo_REQUIRED_INCLUDE_DIRS}"
93 endif( NOT __find_execinfo_COMPILES )
94 endforeach( __find_execinfo_with_lib )
95 # if the test compiled and we found a library, add it...
96 if( __find_execinfo_COMPILES AND EXECINFO_LIBRARY )
97 set( EXECINFO_LIBRARIES ${EXECINFO_LIBRARY} )
98 endif( __find_execinfo_COMPILES AND EXECINFO_LIBRARY )
100 # handle standard stuff
101 include( FindPackageHandleStandardArgs )
102 find_package_handle_standard_args( execinfo
105 __find_execinfo_COMPILES
108 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file