File: Example-FindMyPackage.cmake

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (189 lines) | stat: -rw-r--r-- 5,073 bytes parent folder | download | duplicates (7)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# - try to find MyPackage library
#
# Example-FindMyPackage.cmake
#
# This example is for a fairly in-depth library that has four
# internal dependencies as well as an external dependency.
# The dependency tree is described below, in graphviz/dot format, and you
# can remove the #'s from the following lines and run it through graphviz,
# with this command: dot dependencies.dot -O -Tpdf
#
# --- start of dependencies.dot ---
# digraph {
#	BLAS;
#	subgraph cluster_mypackage {
#		label = "Components that are part of MyPackage";
#		libmypackagecore -> libmypackagea;
#		libmypackagea -> libmypackageb;
#		libmypackageb -> libmypackagec;
#		libmypackagec -> BLAS;
#	}
# }
# --- end of dependencies.dot ---
#
# Because our imaginary component "c" requires BLAS and BLAS needs some
# linker flags, MYPACKAGE_..._LINKER_FLAGS joins the usual group of
# _LIBRARY/_LIBRARIES and _INCLUDE_DIR/_INCLUDE_DIRS variables.  If
# you don't use a library like that, you don't need to include the
# lines dealing with that group of variables.
#
# Most library aren't nearly this complex - but some are, and many
# have some parts of the complexity handled here.
#
# Start of what would be a minimal module documentation block:
#
# Cache Variables: (not for direct use in CMakeLists.txt)
#  MYPACKAGE_ROOT
#  MYPACKAGE_LIBRARY
#  MYPACKAGE_INCLUDE_DIR
#  MYPACKAGE_a_LIBRARY
#  MYPACKAGE_a_INCLUDE_DIR
#  MYPACKAGE_b_LIBRARY
#  MYPACKAGE_b_INCLUDE_DIR
#  MYPACKAGE_c_LIBRARY
#  MYPACKAGE_c_INCLUDE_DIR
#
# Non-cache variables you might use in your CMakeLists.txt:
#  MYPACKAGE_FOUND
#
#  MYPACKAGE_LIBRARIES
#  MYPACKAGE_INCLUDE_DIRS
#  MYPACKAGE_LINKER_FLAGS
#
#  MYPACKAGE_a_LIBRARIES
#  MYPACKAGE_a_INCLUDE_DIRS
#  MYPACKAGE_a_LINKER_FLAGS
#
#  MYPACKAGE_b_LIBRARIES
#  MYPACKAGE_b_INCLUDE_DIRS
#  MYPACKAGE_b_LINKER_FLAGS
#
#  MYPACKAGE_c_LIBRARIES
#  MYPACKAGE_c_INCLUDE_DIRS
#  MYPACKAGE_c_LINKER_FLAGS
#
# Use this module this way:
#  find_package(MyPackage)
#  include_directories(${MYPACKAGE_INCLUDE_DIRS})
#  add_executable(myapp ${SOURCES})
#  target_link_libraries(myapp ${MYPACKAGE_LIBRARIES})
#  set_property(TARGET myapp PROPERTY LINK_FLAGS ${MYPACKAGE_LINKER_FLAGS})
#
# Requires these CMake modules:
#  FindPackageHandleStandardArgs (CMake standard module)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC

set(MYPACKAGE_ROOT
	"${MYPACKAGE_ROOT}"
	CACHE
	PATH
	"Root directory to look in")

find_library(MYPACKAGE_LIBRARY
	NAMES
	mypackagecore
	PATHS
	"${MYPACKAGE_ROOT}"
	PATH_SUFFIXES
	lib)

find_path(MYPACKAGE_INCLUDE_DIR
	NAMES
	mypackage/mypackage.h
	PATHS
	"${MYPACKAGE_ROOT}"
	PATH_SUFFIXES
	include)

# Assuming that the components are named libmypackagea, libmypackageb, etc
foreach(lib a b c)
	find_library(MYPACKAGE_${lib}_LIBRARY
		NAMES
		mypackage${lib}
		PATHS
		"${MYPACKAGE_ROOT}"
		PATH_SUFFIXES
		lib)

	find_path(MYPACKAGE_${lib}_INCLUDE_DIR
		NAMES
		mypackage/${lib}/${lib}.h
		PATHS
		"${MYPACKAGE_ROOT}"
		PATH_SUFFIXES
		include)

endforeach()

# Searching for dependencies here - always quiet.
# see /usr/share/cmake-2.x/Modules/FindBLAS.cmake for the variables this will define
if(NOT BLAS_FOUND)
	find_package(BLAS QUIETLY)
endif()

# 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(MyPackage
	DEFAULT_MSG
	MYPACKAGE_LIBRARY
	MYPACKAGE_INCLUDE_DIR
	MYPACKAGE_a_LIBRARY
	MYPACKAGE_a_INCLUDE_DIR
	MYPACKAGE_b_LIBRARY
	MYPACKAGE_b_INCLUDE_DIR
	MYPACKAGE_c_LIBRARY
	MYPACKAGE_c_INCLUDE_DIR
	BLAS_FOUND)

if(MYPACKAGE_FOUND)
	# Set variables containing libraries and their dependencies
	# Always use the plural form for the variables defined by other find modules:
	# they might have dependencies too!

	set(MYPACKAGE_c_LIBRARIES ${MYPACKAGE_c_LIBRARY} ${BLAS_LIBRARIES})
	set(MYPACKAGE_c_INCLUDE_DIRS ${MYPACKAGE_c_INCLUDE_DIR})	# No include dir for BLAS?
	set(MYPACKAGE_c_LINKER_FLAGS ${BLAS_LINKER_FLAGS})

	set(MYPACKAGE_b_LIBRARIES
		${MYPACKAGE_b_LIBRARY}
		${MYPACKAGE_c_LIBRARIES})
	set(MYPACKAGE_b_INCLUDE_DIRS
		${MYPACKAGE_b_INCLUDE_DIR}
		${MYPACKAGE_c_INCLUDE_DIRS})
	set(MYPACKAGE_b_LINKER_FLAGS ${MYPACKAGE_c_LINKER_FLAGS})

	set(MYPACKAGE_a_LIBRARIES
		${MYPACKAGE_a_LIBRARY}
		${MYPACKAGE_b_LIBRARIES})
	set(MYPACKAGE_a_INCLUDE_DIRS
		${MYPACKAGE_a_INCLUDE_DIR}
		${MYPACKAGE_b_INCLUDE_DIRS})
	set(MYPACKAGE_a_LINKER_FLAGS ${MYPACKAGE_b_LINKER_FLAGS})

	set(MYPACKAGE_LIBRARIES ${MYPACKAGE_LIBRARY} ${MYPACKAGE_a_LIBRARIES})
	set(MYPACKAGE_INCLUDE_DIRS
		${MYPACKAGE_INCLUDE_DIR}
		${MYPACKAGE_a_INCLUDE_DIRS})
	set(MYPACKAGE_LINKER_FLAGS ${MYPACKAGE_a_LINKER_FLAGS})

endif()

mark_as_advanced(MYPACKAGE_LIBRARY
	MYPACKAGE_INCLUDE_DIR
	MYPACKAGE_a_LIBRARY
	MYPACKAGE_a_INCLUDE_DIR
	MYPACKAGE_b_LIBRARY
	MYPACKAGE_b_INCLUDE_DIR
	MYPACKAGE_c_LIBRARY
	MYPACKAGE_c_INCLUDE_DIR)

if(MYPACKAGE_FOUND)
	mark_as_advanced(MYPACKAGE_ROOT)
endif()

# End of Example-FindMyPackage.cmake