summaryrefslogtreecommitdiffstats
path: root/contrib/cmake/FindMILES.cmake
blob: f86e6956fad40a62b7a28e3d145b8d4021dfe655 (plain)
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
# - Find Miles
# This module checks if Miles is installed and determines where the
# include files and libraries are. This code sets the following
# variables:
#
# MILES_INCLUDE_DIR             = The full path to the miles headers
# MILES_LIBRARIES               = All miles libraries for release and debug builds
#
# Example:
#   find_package(MILES REQUIRED audio network)
#   include_directories(${MILES_INCLUDE_DIR})
#

# is this a 64Bit host?
# if (NOT APPLE)
# 	if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# 		set(_MILES_64BIT_LIB_POSTFIX 64)
# 	else()
# 		set(_MILES_64BIT_LIB_POSTFIX "")
# 	endif()
# endif()

###################################################
# where to search for miles headers and libraries
###################################################
set(_MILES_LIB_SEARCHPATH 
	"/usr/local" 
	"/opt/local" 
	"C:/Program Files (x86)/miles"
	"C:/Program Files/miles"
)

###################################################
# get a list of components the user requested
###################################################
set(_MILES_COMPONENTS_TO_PROCESS)
foreach(_MILES_COMPONENT ${MILES_FIND_COMPONENTS})
	STRING(TOUPPER ${_MILES_COMPONENT} _MILES_COMPONENT_UC)
	list(APPEND _MILES_COMPONENTS_TO_PROCESS ${_MILES_COMPONENT_UC})
endforeach()
list(APPEND _MILES_COMPONENTS_TO_PROCESS "CORE")
list(REMOVE_DUPLICATES _MILES_COMPONENTS_TO_PROCESS)

###################################################
# find the miles header files
###################################################
FIND_PATH(MILES_INCLUDE_DIR miles/miles.h
  PATH_SUFFIXES include 
	PATHS ${_MILES_LIB_SEARCHPATH}
	ENV MILES_INCLUDE_DIR
)

###################################################
# iterate components and try to find libraries
# in debug and release configuration. For release
# we prefer MinSizeRel, for debug we prefer 
# RelWithDebInfo.
###################################################
SET(MILES_LIBRARIES)

list(LENGTH MILES_FIND_COMPONENTS MILES_NR_COMPONENTS)
if (MILES_NR_COMPONENTS GREATER 0)
	foreach (_MILES_COMPONENT ${_MILES_COMPONENTS_TO_PROCESS})
		SET(_CURR_COMPONENT "MILES_${_MILES_COMPONENT}_LIBRARY")
		STRING(TOLOWER ${_MILES_COMPONENT}${_MILES_64BIT_LIB_POSTFIX} _MILES_COMPONENT_LC)

		# prefer MinSizeRel libraries
		FIND_LIBRARY(${_CURR_COMPONENT} 
			PATH_SUFFIXES lib
	  	NAMES miles_${_MILES_COMPONENT_LC}_s 
			PATHS ${_MILES_LIB_SEARCHPATH}
			ENV MILES_LIB_DIR
		)
		if (${_CURR_COMPONENT})
			list(APPEND MILES_LIBRARIES optimized ${${_CURR_COMPONENT}})
		else()
			# if no minsize libraries were found try normal release
			FIND_LIBRARY(${_CURR_COMPONENT} 
				PATH_SUFFIXES lib
		  	NAMES miles_${_MILES_COMPONENT_LC} 
				PATHS ${_MILES_LIB_SEARCHPATH}
				ENV MILES_LIB_DIR
			)
			if (${_CURR_COMPONENT})
				list(APPEND MILES_LIBRARIES optimized ${${_CURR_COMPONENT}})
			endif()
		endif()
	
		# prefer RelWithDebInfo libraries
		FIND_LIBRARY(${_CURR_COMPONENT}_DEBUG 
			PATH_SUFFIXES lib
	  	NAMES miles_${_MILES_COMPONENT_LC}_rd
	 		PATHS ${_MILES_LIB_SEARCHPATH}
			ENV MILES_LIB_DIR
		)
		if (${_CURR_COMPONENT}_DEBUG)
			list(APPEND MILES_LIBRARIES debug ${${_CURR_COMPONENT}_DEBUG})
		else()
			FIND_LIBRARY(${_CURR_COMPONENT}_DEBUG 
				PATH_SUFFIXES lib
	  		NAMES miles_${_MILES_COMPONENT_LC}_d
	 			PATHS ${_MILES_LIB_SEARCHPATH}
				ENV MILES_LIB_DIR
			)
			if (${_CURR_COMPONENT}_DEBUG)
				list(APPEND MILES_LIBRARIES debug ${${_CURR_COMPONENT}_DEBUG})
			endif()
		endif()	
	endforeach()
else()
	FIND_LIBRARY(MILES_RELEASE
		PATH_SUFFIXES lib
		NAMES miles_s 
		PATHS ${_MILES_LIB_SEARCHPATH}
		ENV MILES_LIB_DIR
	)
	if (MILES_RELEASE)
		list(APPEND MILES_LIBRARIES optimized ${MILES_RELEASE})
	else()
		# if no minsize libraries were found try normal release
		FIND_LIBRARY(MILES_RELEASE
			PATH_SUFFIXES lib
	  	NAMES miles
			PATHS ${_MILES_LIB_SEARCHPATH}
			ENV MILES_LIB_DIR
		)
		if (MILES_RELEASE)
			list(APPEND MILES_LIBRARIES optimized ${MILES_RELEASE})
		endif()
	endif()

	# prefer RelWithDebInfo libraries
	FIND_LIBRARY(MILES_DEBUG 
		PATH_SUFFIXES lib
  	NAMES miles_rd
 		PATHS ${_MILES_LIB_SEARCHPATH}
		ENV MILES_LIB_DIR
	)
	if (MILES_DEBUG)
		list(APPEND MILES_LIBRARIES debug ${MILES_DEBUG})
	else()
		FIND_LIBRARY(MILES_DEBUG 
			PATH_SUFFIXES lib
  		NAMES miles_d
 			PATHS ${_MILES_LIB_SEARCHPATH}
			ENV MILES_LIB_DIR
		)
		if (MILES_DEBUG)
			list(APPEND MILES_LIBRARIES debug ${MILES_DEBUG})
		endif()
	endif()	

endif()

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MILES DEFAULT_MSG MILES_LIBRARIES MILES_INCLUDE_DIR)
MARK_AS_ADVANCED(MILES_INCLUDE_DIR MILES_LIBRARIES)