forked from rpavlik/cmake-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindFlagpoll.cmake
151 lines (136 loc) · 4.35 KB
/
FindFlagpoll.cmake
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# - try to find Flagpoll application, and offer package-finding services
# FLAGPOLL, the executable: if not defined, do not try to use Flagpoll.
#
# Useful configuration variables you might want to add to your cache:
# FLAGPOLL_ROOT_DIR - A directory prefix to search for the app
# (a path that contains bin/ as a subdirectory)
#
# VR Juggler requires this package, so this Find script takes that into
# account when determining where to search for the desired files.
# The VJ_BASE_DIR environment variable is searched (preferentially)
# when searching for this package, so most sane VR Juggler build environments
# should "just work." Note that you need to manually re-run CMake if you
# change this environment variable, because it cannot auto-detect this change
# and trigger an automatic re-run.
#
# You can use Flagpoll to provide directories to use as HINTS for find_*
# These are the provided macros:
# flagpoll_get_include_dirs
# flagpoll_get_library_dirs
# flagpoll_get_library_names
# flagpoll_get_extra_libs
# All take the name of the desired package, optionally NO_DEPS to pass --no-deps
# to Flagpoll, and return yourpkgname_FLAGPOLL_INCLUDE_DIRS(etc. for the other
# macros).
#
# Example usage:
# flagpoll_get_include_dirs(vpr NO_DEPS)
# find_path(VPR20_INCLUDE_DIRS vpr/vpr.h
# HINTS ${vpr_FLAGPOLL_INCLUDE_DIRS})
#
# Original Author:
# 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
###
# Flagpoll detection
###
set(Flagpoll_FIND_QUIETLY true)
find_program(FLAGPOLL
NAMES
flagpoll
flagpoll.exe
PATHS
"${FLAGPOLL_ROOT_DIR}"
"${VRJUGGLER22_ROOT_DIR}"
PATH_SUFFIXES
bin)
# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Flagpoll DEFAULT_MSG FLAGPOLL)
mark_as_advanced(FLAGPOLL)
###
# Macro for internal use - shared workings between all the public macros below.
###
macro(_flagpoll_get_results _package _arg _flag _output)
if(FLAGPOLL)
# If the CMakeLists that called the flagpoll macro passed NO_DEPS,
# we won't return the results for dependencies
if("${ARGN}" MATCHES "NO_DEPS")
set(_FLAGPOLL_NODEP "--no-deps")
else()
set(_FLAGPOLL_NODEP "")
endif()
# Run flagpoll
execute_process(COMMAND
${FLAGPOLL}
${_package}
${_arg}
${_FLAGPOLL_NODEP}
OUTPUT_VARIABLE
_FLAGPOLL_OUTPUT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(_FLAGPOLL_OUTPUT)
# Remove -I and /I(or equivalent for other flags
string(REGEX
REPLACE
"[-/]${_flag}"
""
_FLAGPOLL_OUTPUT
${_FLAGPOLL_OUTPUT})
# Remove extra spaces
string(REGEX REPLACE " +" " " _FLAGPOLL_OUTPUT ${_FLAGPOLL_OUTPUT})
# Make a CMake list, standardize paths, and append only what we want to our final list
separate_arguments(_FLAGPOLL_OUTPUT)
foreach(_RESULT ${_FLAGPOLL_OUTPUT})
string(REGEX MATCH "^-" _BAD ${_RESULT})
if(_RESULT AND NOT _BAD)
file(TO_CMAKE_PATH "${_RESULT}" _RESULT_CLEAN)
list(APPEND ${_output} ${_RESULT_CLEAN})
endif()
endforeach()
endif()
endif()
endmacro()
###
# "Public" macros - to use flagpoll to give you HINTS directories when finding things
###
macro(flagpoll_get_include_dirs _package)
# Passing ARGN along so if they specified NO_DEPS we actually do it.
_flagpoll_get_results(${_package}
"--cflags-only-I"
I
${_package}_FLAGPOLL_INCLUDE_DIRS
${ARGN})
endmacro()
macro(flagpoll_get_library_dirs _package)
# Passing ARGN along so if they specified NO_DEPS we actually do it.
_flagpoll_get_results(${_package}
"--libs-only-L"
L
${_package}_FLAGPOLL_LIBRARY_DIRS
${ARGN})
endmacro()
macro(flagpoll_get_library_names _package)
# Passing ARGN along so if they specified NO_DEPS we actually do it.
_flagpoll_get_results(${_package}
"--libs-only-l"
l
${_package}_FLAGPOLL_LIBRARY_NAMES
${ARGN})
endmacro()
macro(flagpoll_get_extra_libs _package)
# Passing ARGN along so if they specified NO_DEPS we actually do it.
_flagpoll_get_results(${_package}
"--get-extra-libs"
l
${_package}_FLAGPOLL_EXTRA_LIBS
${ARGN})
endmacro()