File: FindAWK.cmake

package info (click to toggle)
spring 106.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 55,316 kB
  • sloc: cpp: 543,954; ansic: 44,800; python: 12,575; java: 12,201; awk: 5,889; sh: 1,796; asm: 1,546; xml: 655; perl: 405; php: 211; objc: 194; makefile: 76; sed: 2
file content (85 lines) | stat: -rw-r--r-- 2,308 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# - Find AWK binary
# Find the native AWK executable
#
#  AWK_BIN         - AWK executable
#  AWK_VERSION     - AWK version (first line of output of "${AWK_BIN} -W version")
#  AWK_FOUND       - TRUE if AWK binary was found.

INCLUDE(FindPackageHandleStandardArgs)

if (AWK_BIN)
	# Already in cache, be silent
	SET(AWK_FIND_QUIETLY TRUE)
endif ()


SET(AWK_NAMES awk gawk mawk nawk)

if (CMAKE_HOST_WIN32)
	set(AWK_BIN "${MINGWLIBS}/bin/awk.exe")
	if (NOT EXISTS AWK_BIN)
		find_program(AWK_BIN NAMES ${AWK_NAMES})
	endif ()
else ()
	find_program(AWK_BIN NAMES ${AWK_NAMES})
endif ()

# Handle the QUIETLY and REQUIRED arguments and set AWK_FOUND to TRUE
# if AWK_BIN is valid
FIND_PACKAGE_HANDLE_STANDARD_ARGS(AWK DEFAULT_MSG AWK_BIN)

if (AWK_FOUND)
	# Try to fetch the AWK version
	#
	# There are different ways of doing this, and not all implementations
	# support all of them. What is worse: none of the ways is supported by all
	# implementations. :/
	#
	# Common Implementations:
	# * GAWK: linux (& windows) standard
	# * MAWK: gentoo
	# * BWK:  OS X & BSDs (announces itsself just as "awk version 20070501")
	# more info: http://en.wikipedia.org/wiki/AWK#Versions_and_implementations
	#
	# a) awk -Wv        (the standard, not supported by BWK)
	# b) awk -W version (less standard, more verbose version of the above)
	# c) awk --version  (works for BWK and GAWK)
	# d) awk -version   (works for BWK)
	#
	# So we first try a) and if output is "", we try c)
	#
	EXECUTE_PROCESS(COMMAND ${AWK_BIN} -Wv
		RESULT_VARIABLE RET_VAL
		OUTPUT_VARIABLE AWK_VERSION
		ERROR_QUIET
		OUTPUT_STRIP_TRAILING_WHITESPACE)
	if ( NOT${RET_VAL} EQUAL 0 OR AWK_VERSION STREQUAL "")
		EXECUTE_PROCESS(COMMAND ${AWK_BIN} --version
			RESULT_VARIABLE RET_VAL
			OUTPUT_VARIABLE AWK_VERSION
			ERROR_QUIET
			OUTPUT_STRIP_TRAILING_WHITESPACE)
	endif ()

	if (${RET_VAL} EQUAL 0)
		# reduce to first line
		String(REGEX REPLACE "\n.*" "" AWK_VERSION "${AWK_VERSION}")
		if (NOT AWK_FIND_QUIETLY)
			message (STATUS "AWK version: ${AWK_VERSION}")
		endif ()
	else ()
		# failed to fetch version, clear
		set(AWK_VERSION)
	endif ()
else ()
	# clear
	set(AWK_BIN)
	set(AWK_VERSION)
endif ()

# Show these variables only in the advanced view in the GUI, and make them global
MARK_AS_ADVANCED(
	AWK_FOUND
	AWK_BIN
	AWK_VERSION
	)