Skip to content

Commit 94826f7

Browse files
committed
Merge pull request #376 from xlz/megarefactor
0.1 release build system restructuring
2 parents 4cf31d6 + 5ab1a6a commit 94826f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+211
-653
lines changed

.gitignore

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
# generated config file
2-
examples/protonect/include/libfreenect2/config.h
3-
4-
# generated resource file
5-
examples/protonect/src/resources.inc.h
6-
examples/protonect/build
7-
examples/protonect/lib
1+
build
82

93
# Dependency folders
104
depends/*/
Lines changed: 82 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12.1)
22

33
if(WIN32 AND NOT MINGW)
44
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
55
set(CMAKE_DEBUG_POSTFIX "d")
66
endif()
77
endif()
88

9+
IF(NOT DEFINED CMAKE_BUILD_TYPE)
10+
# No effect for multi-configuration generators (e.g. for Visual Studio)
11+
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose: RelWithDebInfo Release Debug MinSizeRel None")
12+
ENDIF()
13+
914
PROJECT(libfreenect2)
10-
SET(CMAKE_BUILD_TYPE RelWithDebInfo)
1115

1216
SET(MY_DIR ${libfreenect2_SOURCE_DIR})
13-
SET(DEPENDS_DIR "${MY_DIR}/../../depends" CACHE STRING "dependency directory must be set to 'false' if external deps are used")
17+
SET(DEPENDS_DIR "${MY_DIR}/depends" CACHE STRING "dependency directory must be set to 'false' if external deps are used")
1418

19+
OPTION(BUILD_SHARED_LIBS "Build shared (ON) or static (OFF) libraries" ON)
20+
OPTION(BUILD_EXAMPLES "Build examples" ON)
1521
OPTION(ENABLE_CXX11 "Enable C++11 support" OFF)
1622
OPTION(ENABLE_OPENCL "Enable OpenCL support" ON)
1723
OPTION(ENABLE_OPENGL "Enable OpenGL support" ON)
@@ -39,10 +45,10 @@ INCLUDE(SetupLibfreenect2Threading)
3945
INCLUDE(GenerateResources)
4046

4147
#set the default path for built executables to the "bin" directory
42-
SET(EXECUTABLE_OUTPUT_PATH ${MY_DIR}/bin)
48+
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
4349

4450
#set the default path for built libraries to the "lib" directory
45-
SET(LIBRARY_OUTPUT_PATH ${MY_DIR}/lib)
51+
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
4652

4753
# dependencies
4854
FIND_PACKAGE(PkgConfig) # try find PKGConfig as it will be used if found
@@ -52,43 +58,45 @@ FIND_PACKAGE(TurboJPEG REQUIRED) #does not provide a package-config file
5258
# Add includes
5359
INCLUDE_DIRECTORIES(
5460
"${MY_DIR}/include"
61+
"${MY_DIR}/include/internal"
62+
${PROJECT_BINARY_DIR} # for generated headers
5563
${LIBFREENECT2_THREADING_INCLUDE_DIR}
5664
${LibUSB_INCLUDE_DIRS}
5765
${TurboJPEG_INCLUDE_DIRS}
5866
)
5967

6068
LINK_DIRECTORIES(${LibUSB_LIBRARY_DIRS})
6169

62-
SET(RESOURCES_INC_FILE "${MY_DIR}/src/resources.inc.h")
70+
SET(RESOURCES_INC_FILE "${PROJECT_BINARY_DIR}/resources.inc.h")
71+
SET(CONFIG_H_FILE "${PROJECT_BINARY_DIR}/libfreenect2/config.h")
6372

6473
SET(SOURCES
65-
include/libfreenect2/protocol/command.h
66-
include/libfreenect2/protocol/command_transaction.h
67-
include/libfreenect2/protocol/response.h
68-
include/libfreenect2/protocol/usb_control.h
69-
70-
include/libfreenect2/usb/event_loop.h
71-
include/libfreenect2/usb/transfer_pool.h
74+
include/internal/libfreenect2/protocol/command.h
75+
include/internal/libfreenect2/protocol/command_transaction.h
76+
include/internal/libfreenect2/protocol/response.h
77+
include/internal/libfreenect2/protocol/usb_control.h
78+
79+
include/internal/libfreenect2/usb/event_loop.h
80+
include/internal/libfreenect2/usb/transfer_pool.h
7281

7382
include/libfreenect2/logger.h
74-
include/libfreenect2/logging.h
83+
include/internal/libfreenect2/logging.h
7584

76-
include/libfreenect2/async_packet_processor.h
85+
include/internal/libfreenect2/async_packet_processor.h
7786
include/libfreenect2/depth_packet_processor.h
78-
include/libfreenect2/depth_packet_stream_parser.h
79-
include/libfreenect2/double_buffer.h
87+
include/internal/libfreenect2/depth_packet_stream_parser.h
88+
include/internal/libfreenect2/double_buffer.h
8089
include/libfreenect2/frame_listener.hpp
8190
include/libfreenect2/frame_listener_impl.h
82-
include/libfreenect2/config.h
8391
include/libfreenect2/libfreenect2.hpp
8492
include/libfreenect2/packet_pipeline.h
8593
include/libfreenect2/packet_processor.h
8694
include/libfreenect2/registration.h
87-
include/libfreenect2/resource.h
95+
include/internal/libfreenect2/resource.h
8896
include/libfreenect2/rgb_packet_processor.h
89-
include/libfreenect2/rgb_packet_stream_parser.h
90-
include/libfreenect2/threading.h
91-
97+
include/internal/libfreenect2/rgb_packet_stream_parser.h
98+
include/internal/libfreenect2/threading.h
99+
92100
src/transfer_pool.cpp
93101
src/event_loop.cpp
94102
src/usb_control.cpp
@@ -106,9 +114,10 @@ SET(SOURCES
106114
src/registration.cpp
107115
src/logging.cpp
108116
src/libfreenect2.cpp
109-
117+
110118
${LIBFREENECT2_THREADING_SOURCE}
111119
${RESOURCES_INC_FILE}
120+
${CONFIG_H_FILE}
112121
)
113122

114123
SET(LIBRARIES
@@ -118,9 +127,9 @@ SET(LIBRARIES
118127
)
119128

120129
SET(RESOURCES
121-
11to16.bin
122-
xTable.bin
123-
zTable.bin
130+
data/11to16.bin
131+
data/xTable.bin
132+
data/zTable.bin
124133
)
125134

126135
IF(ENABLE_OPENGL)
@@ -136,10 +145,10 @@ IF(ENABLE_OPENGL)
136145
)
137146
SET(LIBFREENECT2_WITH_OPENGL_SUPPORT 1)
138147
LIST(APPEND SOURCES
139-
src/flextGL.c
148+
src/flextGL.cpp
140149
src/opengl_depth_packet_processor.cpp
141150
)
142-
151+
143152
LIST(APPEND RESOURCES
144153
src/shader/debug.fs
145154
src/shader/default.vs
@@ -154,18 +163,18 @@ ENDIF(ENABLE_OPENGL)
154163
IF(ENABLE_OPENCL)
155164
FIND_PACKAGE(OpenCL)
156165

157-
IF(OPENCL_FOUND)
166+
IF(OPENCL_FOUND)
158167
SET(LIBFREENECT2_WITH_OPENCL_SUPPORT 1)
159168
INCLUDE_DIRECTORIES(${OPENCL_INCLUDE_DIRS})
160-
169+
161170
LIST(APPEND SOURCES
162171
src/opencl_depth_packet_processor.cpp
163172
)
164173

165174
LIST(APPEND LIBRARIES
166175
${OPENCL_LIBRARIES}
167176
)
168-
177+
169178
LIST(APPEND RESOURCES
170179
src/opencl_depth_packet_processor.cl
171180
)
@@ -179,54 +188,56 @@ IF(ENABLE_OPENCL)
179188
ENDIF(OPENCL_FOUND)
180189
ENDIF(ENABLE_OPENCL)
181190

182-
SET(CMAKE_INSTALL_RPATH ${LibUSB_LIBDIR})
191+
# RPATH handling for private libusb copies
192+
# Users have two options:
193+
# 1. Build libusb in depends/ and leave it there:
194+
# Do NOT set CMAKE_INSTALL_RPATH. It works by default.
195+
# 2. Build libusb and install it somewhere:
196+
# Set CMAKE_INSTALL_RPATH to the libusb.so installation directory before compiling.
197+
# Both command line -DCMAKE_INSTALL_RPATH=... and CMake GUI settings are accepted.
198+
#
199+
# Anyway if wrong versions of libusb is used, errors will be reported explicitly.
200+
IF(NOT DEFINED CMAKE_INSTALL_RPATH)
201+
SET(CMAKE_INSTALL_RPATH ${LibUSB_LIBDIR} CACHE STRING "Set RPATH for a private libusb")
202+
ELSE()
203+
SET(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} CACHE STRING "Set RPATH for a private libusb")
204+
ENDIF()
205+
IF(DEFINED CMAKE_INSTALL_RPATH)
206+
MESSAGE(STATUS "RPATH set to ${CMAKE_INSTALL_RPATH}")
207+
ENDIF()
183208

184-
CONFIGURE_FILE("${MY_DIR}/include/libfreenect2/config.h.in" "${MY_DIR}/include/libfreenect2/config.h" @ONLY)
209+
CONFIGURE_FILE("${MY_DIR}/include/libfreenect2/config.h.in" "${CONFIG_H_FILE}" @ONLY)
185210
GENERATE_RESOURCES(${RESOURCES_INC_FILE} ${MY_DIR} ${RESOURCES})
186211

187212
ADD_DEFINITIONS(-DRESOURCES_INC)
188-
ADD_LIBRARY(freenect2 OBJECT ${SOURCES})
189-
set_target_properties(freenect2 PROPERTIES POSITION_INDEPENDENT_CODE 1)
190-
ADD_LIBRARY(freenect2shared SHARED $<TARGET_OBJECTS:freenect2>)
191-
ADD_LIBRARY(freenect2static STATIC $<TARGET_OBJECTS:freenect2>)
192-
set_target_properties(freenect2shared PROPERTIES OUTPUT_NAME freenect2)
193-
set_target_properties(freenect2static PROPERTIES OUTPUT_NAME freenect2)
194-
IF(MSVC)
195-
set_target_properties(freenect2static PROPERTIES OUTPUT_NAME freenect2static)
196-
ENDIF()
197-
MESSAGE("Linking with these libraries: ${LIBRARIES}")
198-
TARGET_LINK_LIBRARIES(freenect2shared ${LIBRARIES})
199-
200-
SET(Protonect_src
201-
Protonect.cpp
202-
)
203-
204-
IF (ENABLE_OPENGL AND OPENGL_FOUND)
205-
LIST(APPEND Protonect_src
206-
viewer.h
207-
viewer.cpp
208-
src/flextGL.c
209-
)
210-
ENDIF()
211-
212-
ADD_EXECUTABLE(Protonect
213-
${Protonect_src}
214-
215-
)
216-
217-
TARGET_LINK_LIBRARIES(Protonect
218-
freenect2shared
213+
SET(CMAKE_CXX_VISIBILITY_PRESET hidden)
214+
SET(CMAKE_C_VISIBILITY_PRESET hidden)
215+
SET(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
216+
INCLUDE(GenerateExportHeader)
217+
218+
ADD_LIBRARY(freenect2 ${SOURCES})
219+
GENERATE_EXPORT_HEADER(freenect2
220+
BASE_NAME libfreenect2
219221
)
220222

223+
IF(MSVC AND NOT BUILD_SHARED_LIBS)
224+
# MSVC creates freenect2.lib for both dynamic and static by default
225+
set_target_properties(freenect2 PROPERTIES SUFFIX "static.lib")
226+
ENDIF()
227+
MESSAGE(STATUS "Linking with these libraries: ${LIBRARIES}")
228+
TARGET_LINK_LIBRARIES(freenect2 ${LIBRARIES})
229+
221230
CONFIGURE_FILE(freenect2.cmake.in "${PROJECT_BINARY_DIR}/freenect2Config.cmake" @ONLY)
222231
CONFIGURE_FILE(freenect2.pc.in "${PROJECT_BINARY_DIR}/freenect2.pc" @ONLY)
223232

224-
INSTALL(TARGETS freenect2shared DESTINATION lib)
225-
INSTALL(TARGETS freenect2static DESTINATION lib)
226-
INSTALL(DIRECTORY "${MY_DIR}/include/" DESTINATION include PATTERN "*.in" EXCLUDE)
227-
IF(LIBFREENECT2_THREADING_TINYTHREAD)
228-
INSTALL(FILES "${MY_DIR}/src/tinythread/tinythread.h" DESTINATION include/${PROJECT_NAME}/tinythread/)
229-
ENDIF(LIBFREENECT2_THREADING_TINYTHREAD)
233+
INSTALL(TARGETS freenect2 DESTINATION lib)
234+
INSTALL(DIRECTORY "${MY_DIR}/include/${PROJECT_NAME}" DESTINATION include PATTERN "*.in" EXCLUDE)
235+
INSTALL(FILES "${CONFIG_H_FILE}" DESTINATION include/${PROJECT_NAME})
236+
INSTALL(FILES "${PROJECT_BINARY_DIR}/libfreenect2_export.h" DESTINATION include/${PROJECT_NAME})
230237
INSTALL(FILES "${PROJECT_BINARY_DIR}/freenect2Config.cmake" DESTINATION lib/cmake/freenect2/)
231238
INSTALL(FILES "${PROJECT_BINARY_DIR}/freenect2.pc" DESTINATION lib/pkgconfig/)
232-
239+
240+
IF(BUILD_EXAMPLES)
241+
MESSAGE(STATUS "Configurating examples")
242+
ADD_SUBDIRECTORY(${MY_DIR}/examples)
243+
ENDIF()

README.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ Joshua Blake provided a Debug version binary: https://www.dropbox.com/s/madoye1a
136136
#### Build
137137

138138
```
139-
cd example\protonect
140139
mkdir build && cd build
141140
cmake .. -G "Visual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX=.
142141
cmake --build . --config Release --target install
@@ -180,7 +179,6 @@ sh ./depends/install_mac.sh
180179
1. Build the actual protonect executable
181180

182181
```
183-
cd ./examples/protonect/
184182
mkdir build && cd build
185183
cmake ..
186184
make
@@ -221,7 +219,6 @@ sudo dpkg -i libglfw3*_3.0.4-1_*.deb # Ubuntu 14.04 only
221219
1. Build the actual protonect executable
222220

223221
```
224-
cd ../examples/protonect/
225222
mkdir build && cd build
226223
cmake ..
227224
make
@@ -238,23 +235,6 @@ sudo make install
238235

239236
I'm not sure, but look for libusbx installation instructions for your OS. Figure out how to attach the driver to the Xbox NUI Sensor composite parent device, VID 045E PID 02C4, then contribute your procedure.
240237

241-
## Building
242-
243-
Make sure you install the driver as describe above first.
244-
245-
1. Follow directions in the ./depends/README.depends.txt to get the dependencies. (Process may be streamlined later.)
246-
247-
### Windows / Visual Studio
248-
249-
1. Use CMake to generate a solution.
250-
2. Build and run.
251-
252-
### Other platforms
253-
254-
2. ?
255-
3. Build and run.
256-
4. Contribute your solution for your platform back to the project please.
257-
258238
## Required notification
259239

260240
The K4W2 hardware is currently pre-release. Per the K4W2 developer program agreement, all public demonstrations and code should display this notice:
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/protonect/cmake_modules/GenerateResources.cmake renamed to cmake_modules/GenerateResources.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FUNCTION(GENERATE_RESOURCES OUTPUT BASE_FOLDER)
22

33
ADD_EXECUTABLE(generate_resources_tool
4-
src/generate_resources.cpp
4+
tools/generate_resources.cpp
55
)
66

77
ADD_CUSTOM_COMMAND(

examples/protonect/cmake_modules/SetupLibfreenect2Threading.cmake renamed to cmake_modules/SetupLibfreenect2Threading.cmake

File renamed without changes.

0 commit comments

Comments
 (0)