1
1
CMAKE_MINIMUM_REQUIRED (VERSION 2.6 )
2
2
3
-
4
- function (auto_detect_lib LIBNAME )
5
- if (NOT DEFINED ${${LIBNAME}_FOUND} )
6
- find_package (PkgConfig )
3
+ macro (auto_detect_lib LIBNAME )
4
+ if (NOT DEFINED ${${LIBNAME}_FOUND} )
7
5
if ( PKG_CONFIG_FOUND )
8
6
string (TOLOWER ${LIBNAME} LOWER_${LIBNAME} )
9
7
pkg_check_modules (${LIBNAME} ${ARGN} ${LOWER_${LIBNAME}} )
10
- MESSAGE ("LIB ${LIBNAME} found and include is in ${${LIBNAME} _INCLUDE_DIRS}" )
11
- else ()
12
- MESSAGE ("Fallback to non-pkg-config" )
8
+ MESSAGE (STATUS "LIB ${LIBNAME} found and include is in ${${LIBNAME} _INCLUDE_DIRS}" )
9
+ else (PKG_CONFIG_FOUND )
10
+ # MESSAGE("Fallback to non-pkg-config")
13
11
FIND_PACKAGE (${LIBNAME} ${ARGN} )
14
- endif ()
15
- else ()
16
- MESSAGE ("WARNING lib was already known ${LIBNAME} becasue of ${${LIBNAME} _FOUND}" )
17
- endif ()
18
-
19
- if (NOT ${${LIBNAME}_FOUND} )
20
- MESSAGE ("WARNING lib #{LIBNAME} Not found" )
12
+ endif (PKG_CONFIG_FOUND )
21
13
else ()
14
+ MESSAGE (STATUS "LIB was already known ${LIBNAME} becasue of ${${LIBNAME} _FOUND}" )
22
15
endif ()
23
-
24
- MESSAGE ("LIB ${LIBNAME} found and include is in ${${LIBNAME} _INCLUDE_DIRS}" )
25
- #Still include paths because we are assuming FOUND is givern externally
26
- INCLUDE_DIRECTORIES (${${LIBNAME}_INCLUDE_DIRS} )
27
- LINK_DIRECTORIES (${${LIBNAME}_LIBRARY_DIRS} )
28
- endfunction ()
29
-
16
+ endmacro ()
30
17
31
18
PROJECT (libfreenect2 )
32
19
SET (CMAKE_BUILD_TYPE RelWithDebInfo )
33
20
21
+ SET (MY_DIR ${libfreenect2_SOURCE_DIR} )
22
+
34
23
OPTION (ENABLE_CXX11 "Enable C++11 support" OFF )
35
24
OPTION (ENABLE_OPENCL "Enable OpenCL support" ON )
36
25
OPTION (ENABLE_OPENGL "Enable OpenGL support" ON )
@@ -49,62 +38,35 @@ IF(ENABLE_CXX11)
49
38
ENDIF (ENABLE_CXX11 )
50
39
51
40
# additional cmake modules
52
- LIST (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR } /cmake_modules )
41
+ LIST (APPEND CMAKE_MODULE_PATH ${MY_DIR } /cmake_modules )
53
42
54
43
# setup threading
55
44
INCLUDE (SetupLibfreenect2Threading )
56
- INCLUDE_DIRECTORIES (${LIBFREENECT2_THREADING_INCLUDE_DIR} )
57
45
58
46
INCLUDE (GenerateResources )
59
47
60
48
#set the default path for built executables to the "bin" directory
61
- SET (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR } /bin )
49
+ SET (EXECUTABLE_OUTPUT_PATH ${MY_DIR } /bin )
62
50
63
51
#set the default path for built libraries to the "lib" directory
64
- SET (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR} /lib )
65
-
66
- FIND_PACKAGE (OpenCL )
67
- FIND_PACKAGE (OpenCV REQUIRED )
68
- FIND_PACKAGE (TurboJPEG REQUIRED )
69
-
52
+ SET (LIBRARY_OUTPUT_PATH ${MY_DIR} /lib )
70
53
71
54
# dependencies
72
- auto_detect_lib (LibUsb REQUIRED )
73
- auto_detect_lib (GLEW REQUIRED )
74
- auto_detect_lib (GLEWmx REQUIRED )
75
- auto_detect_lib (GLFW3 )
76
-
77
-
78
- ADD_DEFINITIONS (-DGLEW_MX )
79
-
80
- #Our headers include libusb a bit haky, so we need to workaround the given path here
81
- INCLUDE_DIRECTORIES (${LibUsb_INCLUDEDIR} /libusb-1.0 )
82
-
55
+ find_package (PkgConfig ) # try find PKGConfig as it will be used if found
56
+ auto_detect_lib (LibUSB REQUIRED )
57
+ auto_detect_lib (OpenCV REQUIRED )
58
+ auto_detect_lib (TJPEG REQUIRED )
83
59
84
60
# Add includes
85
- #INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS} ${LibUSB_INCLUDE_DIR} ${GLEW_INCLUDE_DIR} ${TJPEG_INCLUDE_DIR})
86
- IF (ENABLE_OPENGL )
87
-
88
- #Assuming local build witout global deps, ugly to to this automatic but to keep backward compatibiliy
89
- if (not ${GLFW_FOUND} )
90
- # GLFW
91
- SET (BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries" )
92
- SET (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "Build the GLFW example programs" )
93
- SET (GLFW_BUILD_TESTS OFF CACHE BOOL "Build the GLFW test programs" )
94
- SET (GLFW_BUILD_DOCS OFF CACHE BOOL "Build the GLFW documentation" )
95
-
96
- ADD_SUBDIRECTORY (${MY_DIR} /../../depends/glfw_src/ ${MY_DIR} /../../depends/glfw )
97
- INCLUDE_DIRECTORIES (${MY_DIR} /../../depends/glfw_src/include/ )
98
- ENDIF (ENABLE_OPENGL )
99
- endif ()
61
+ INCLUDE_DIRECTORIES ("${MY_DIR} /include" ${LIBFREENECT2_THREADING_INCLUDE_DIR} ${OpenCV_INCLUDE_DIRS} ${LibUSB_INCLUDE_DIR} ${TJPEG_INCLUDE_DIR} )
100
62
101
- if (APPLE )
63
+ if (APPLE AND NOT ${TurboJPEG_FOUND} )
102
64
# libjpeg-turbo
103
- INCLUDE_DIRECTORIES ("${CMAKE_CURRENT_SOURCE_DIR } /../../depends/libjpeg_turbo/include/" )
104
- LINK_DIRECTORIES ("${CMAKE_CURRENT_SOURCE_DIR } /../../depends/libjpeg_turbo/lib/" )
65
+ INCLUDE_DIRECTORIES ("${MY_DIR } /../../depends/libjpeg_turbo/include/" )
66
+ LINK_DIRECTORIES ("${MY_DIR } /../../depends/libjpeg_turbo/lib/" )
105
67
endif ()
106
68
107
- SET (RESOURCES_INC_FILE "${CMAKE_CURRENT_SOURCE_DIR } /src/resources.inc" )
69
+ SET (RESOURCES_INC_FILE "${MY_DIR } /src/resources.inc" )
108
70
109
71
SET (SOURCES
110
72
@@ -136,8 +98,6 @@ SET(LIBRARIES
136
98
${LibUSB_LIBRARIES}
137
99
${TJPEG_LIBRARY}
138
100
${LIBFREENECT2_THREADING_LIBRARIES}
139
- ${GLEW_LIBRARIES}
140
- ${GLEWmx_LIBRARIES}
141
101
)
142
102
143
103
SET (RESOURCES
@@ -148,17 +108,32 @@ SET(RESOURCES
148
108
149
109
150
110
IF (ENABLE_OPENGL )
111
+ auto_detect_lib (GLFW )
112
+
113
+ #Assuming local build witout global deps, ugly to to this automatic but to keep backward compatibiliy
114
+ if (${GLFW_FOUND} STREQUAL "FALSE" )
115
+ # GLFW
116
+ SET (BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries" )
117
+ SET (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "Build the GLFW example programs" )
118
+ SET (GLFW_BUILD_TESTS OFF CACHE BOOL "Build the GLFW test programs" )
119
+ SET (GLFW_BUILD_DOCS OFF CACHE BOOL "Build the GLFW documentation" )
120
+
121
+ ADD_SUBDIRECTORY (${MY_DIR} /../../depends/glfw_src/ ${MY_DIR} /../../depends/glfw )
122
+ INCLUDE_DIRECTORIES (${MY_DIR} /../../depends/glfw_src/include/ )
123
+ else ()
124
+ INCLUDE_DIRECTORIES (${GLFW_INCLUDE_DIR} )
125
+
126
+ LIST (APPEND LIBRARIES
127
+ ${GLFW_LIBRARY}
128
+ )
129
+ endif ()
130
+
151
131
SET (LIBFREENECT2_WITH_OPENGL_SUPPORT 1 )
152
132
LIST (APPEND SOURCES
153
133
src/flextGL.c
154
134
src/opengl_depth_packet_processor.cpp
155
135
)
156
-
157
- LIST (APPEND LIBRARIES
158
- glfw
159
- ${GLFW_LIBRARIES}
160
- )
161
-
136
+
162
137
LIST (APPEND RESOURCES
163
138
src/shader/debug.fs
164
139
src/shader/default.vs
@@ -169,28 +144,29 @@ IF(ENABLE_OPENGL)
169
144
)
170
145
ENDIF (ENABLE_OPENGL )
171
146
172
- IF (ENABLE_OPENCL AND OPENCL_FOUND )
173
- SET (LIBFREENECT2_WITH_OPENCL_SUPPORT 1 )
174
- INCLUDE_DIRECTORIES (${OPENCL_INCLUDE_DIRS} )
175
-
176
- LIST (APPEND SOURCES
177
- src/opencl_depth_packet_processor.cpp
178
- )
179
-
180
- LIST (APPEND LIBRARIES
181
- ${OPENCL_LIBRARIES}
182
- )
183
-
184
- LIST (APPEND RESOURCES
185
- src/opencl_depth_packet_processor.cl
186
- )
187
- ENDIF (ENABLE_OPENCL AND OPENCL_FOUND )
147
+ IF (ENABLE_OPENCL )
148
+ FIND_PACKAGE (OpenCL )
149
+
150
+ IF (OPENCL_FOUND )
151
+ SET (LIBFREENECT2_WITH_OPENCL_SUPPORT 1 )
152
+ INCLUDE_DIRECTORIES (${OPENCL_INCLUDE_DIRS} )
153
+
154
+ LIST (APPEND SOURCES
155
+ src/opencl_depth_packet_processor.cpp
156
+ )
157
+
158
+ LIST (APPEND LIBRARIES
159
+ ${OPENCL_LIBRARIES}
160
+ )
161
+
162
+ LIST (APPEND RESOURCES
163
+ src/opencl_depth_packet_processor.cl
164
+ )
165
+ ENDIF (OPENCL_FOUND )
166
+ ENDIF (ENABLE_OPENCL )
188
167
189
168
CONFIGURE_FILE ("${MY_DIR} /include/libfreenect2/config.h.in" "${MY_DIR} /include/libfreenect2/config.h" @ONLY )
190
- GENERATE_RESOURCES (${RESOURCES_INC_FILE} ${CMAKE_CURRENT_SOURCE_DIR} ${RESOURCES} )
191
-
192
-
193
- INCLUDE_DIRECTORIES ("${CMAKE_CURRENT_SOURCE_DIR} /include" )
169
+ GENERATE_RESOURCES (${RESOURCES_INC_FILE} ${MY_DIR} ${RESOURCES} )
194
170
195
171
ADD_DEFINITIONS (-DRESOURCES_INC )
196
172
ADD_LIBRARY (freenect2 SHARED ${SOURCES} )
0 commit comments