1# - Try to find GDB
2#
3# Once done, this will define:
4#  GDB_FOUND - system has GDB
5#  GDB_COMMAND - the command to run
6#  GDB_VERSION - version
7#  GDB_HAS_RETURN_CHILD_RESULT - if the --return-child-result flag is supported
8#
9# Useful configuration variables you might want to add to your cache:
10#  GDB_ROOT_DIR - A directory prefix to search
11#
12# Original Author:
13# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
14# http://academic.cleardefinition.com
15# Iowa State University HCI Graduate Program/VRAC
16#
17# Copyright Iowa State University 2009-2010.
18# Distributed under the Boost Software License, Version 1.0.
19# (See accompanying file LICENSE_1_0.txt or copy at
20# http://www.boost.org/LICENSE_1_0.txt)
21
22
23set(GDB_ROOT_DIR
24	"${GDB_ROOT_DIR}"
25	CACHE
26	PATH
27	"Directory to start our search in")
28
29find_program(GDB_COMMAND
30	NAMES
31	gdb
32	HINTS
33	"${GDB_ROOT_DIR}"
34	PATH_SUFFIXES
35	bin
36	libexec)
37
38if(GDB_COMMAND)
39	execute_process(COMMAND
40		gdb
41		--version
42		COMMAND
43		head
44		-n
45		1
46		OUTPUT_VARIABLE
47		GDB_VERSION
48		OUTPUT_STRIP_TRAILING_WHITESPACE)
49	string(REGEX
50		REPLACE
51		"[^0-9]*([0-9]+[0-9.]*).*"
52		"\\1"
53		GDB_VERSION
54		"${GDB_VERSION}")
55endif()
56
57# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
58# all listed variables are TRUE
59include(FindPackageHandleStandardArgs)
60find_package_handle_standard_args(GDB
61	DEFAULT_MSG
62	GDB_COMMAND
63	GDB_VERSION)
64
65if(GDB_FOUND)
66	mark_as_advanced(GDB_ROOT_DIR)
67	if(GDB_VERSION VERSION_LESS 6.4)
68		set(GDB_HAS_RETURN_CHILD_RESULT FALSE)
69	else()
70		set(GDB_HAS_RETURN_CHILD_RESULT TRUE)
71	endif()
72endif()
73
74mark_as_advanced(GDB_COMMAND)
75