Skip to content

Commit 09d6a73

Browse files
committed
Separate public and internal API
Several LIBFREENECT_API macros are removed from identifiers that are no longer public. Several headers are moved to internal directory and no longer exported. Build for Protonect out-of-tree with public API only. This provides a demo on how to use the public API. Protonect will be built by default in libfreenect2, controlled with BUILD_EXAMPLES.
1 parent 441c8b3 commit 09d6a73

23 files changed

+125
-42
lines changed

CMakeLists.txt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ SET(MY_DIR ${libfreenect2_SOURCE_DIR})
1717
SET(DEPENDS_DIR "${MY_DIR}/depends" CACHE STRING "dependency directory must be set to 'false' if external deps are used")
1818

1919
OPTION(BUILD_SHARED_LIBS "Build shared (ON) or static (OFF) libraries" ON)
20+
OPTION(BUILD_EXAMPLES "Build examples" ON)
2021
OPTION(ENABLE_CXX11 "Enable C++11 support" OFF)
2122
OPTION(ENABLE_OPENCL "Enable OpenCL support" ON)
2223
OPTION(ENABLE_OPENGL "Enable OpenGL support" ON)
@@ -57,6 +58,7 @@ FIND_PACKAGE(TurboJPEG REQUIRED) #does not provide a package-config file
5758
# Add includes
5859
INCLUDE_DIRECTORIES(
5960
"${MY_DIR}/include"
61+
"${MY_DIR}/include/internal"
6062
${PROJECT_BINARY_DIR} # for generated headers
6163
${LIBFREENECT2_THREADING_INCLUDE_DIR}
6264
${LibUSB_INCLUDE_DIRS}
@@ -69,31 +71,31 @@ SET(RESOURCES_INC_FILE "${PROJECT_BINARY_DIR}/resources.inc.h")
6971
SET(CONFIG_H_FILE "${PROJECT_BINARY_DIR}/libfreenect2/config.h")
7072

7173
SET(SOURCES
72-
include/libfreenect2/protocol/command.h
73-
include/libfreenect2/protocol/command_transaction.h
74-
include/libfreenect2/protocol/response.h
75-
include/libfreenect2/protocol/usb_control.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
7678

77-
include/libfreenect2/usb/event_loop.h
78-
include/libfreenect2/usb/transfer_pool.h
79+
include/internal/libfreenect2/usb/event_loop.h
80+
include/internal/libfreenect2/usb/transfer_pool.h
7981

8082
include/libfreenect2/logger.h
81-
include/libfreenect2/logging.h
83+
include/internal/libfreenect2/logging.h
8284

83-
include/libfreenect2/async_packet_processor.h
85+
include/internal/libfreenect2/async_packet_processor.h
8486
include/libfreenect2/depth_packet_processor.h
85-
include/libfreenect2/depth_packet_stream_parser.h
86-
include/libfreenect2/double_buffer.h
87+
include/internal/libfreenect2/depth_packet_stream_parser.h
88+
include/internal/libfreenect2/double_buffer.h
8789
include/libfreenect2/frame_listener.hpp
8890
include/libfreenect2/frame_listener_impl.h
8991
include/libfreenect2/libfreenect2.hpp
9092
include/libfreenect2/packet_pipeline.h
9193
include/libfreenect2/packet_processor.h
9294
include/libfreenect2/registration.h
93-
include/libfreenect2/resource.h
95+
include/internal/libfreenect2/resource.h
9496
include/libfreenect2/rgb_packet_processor.h
95-
include/libfreenect2/rgb_packet_stream_parser.h
96-
include/libfreenect2/threading.h
97+
include/internal/libfreenect2/rgb_packet_stream_parser.h
98+
include/internal/libfreenect2/threading.h
9799

98100
src/transfer_pool.cpp
99101
src/event_loop.cpp
@@ -220,10 +222,12 @@ CONFIGURE_FILE(freenect2.cmake.in "${PROJECT_BINARY_DIR}/freenect2Config.cmake"
220222
CONFIGURE_FILE(freenect2.pc.in "${PROJECT_BINARY_DIR}/freenect2.pc" @ONLY)
221223

222224
INSTALL(TARGETS freenect2 DESTINATION lib)
223-
INSTALL(DIRECTORY "${MY_DIR}/include/" DESTINATION include PATTERN "*.in" EXCLUDE)
225+
INSTALL(DIRECTORY "${MY_DIR}/include/${PROJECT_NAME}" DESTINATION include PATTERN "*.in" EXCLUDE)
224226
INSTALL(FILES "${CONFIG_H_FILE}" DESTINATION include/${PROJECT_NAME})
225-
IF(LIBFREENECT2_THREADING_TINYTHREAD)
226-
INSTALL(FILES "${MY_DIR}/src/tinythread/tinythread.h" DESTINATION include/${PROJECT_NAME}/tinythread/)
227-
ENDIF(LIBFREENECT2_THREADING_TINYTHREAD)
228227
INSTALL(FILES "${PROJECT_BINARY_DIR}/freenect2Config.cmake" DESTINATION lib/cmake/freenect2/)
229228
INSTALL(FILES "${PROJECT_BINARY_DIR}/freenect2.pc" DESTINATION lib/pkgconfig/)
229+
230+
IF(BUILD_EXAMPLES)
231+
MESSAGE(STATUS "Configurating examples")
232+
ADD_SUBDIRECTORY(${MY_DIR}/examples)
233+
ENDIF()

examples/CMakeLists.txt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12.1)
2+
3+
if(WIN32 AND NOT MINGW)
4+
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
5+
set(CMAKE_DEBUG_POSTFIX "d")
6+
endif()
7+
endif()
8+
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+
14+
PROJECT(libfreenect2_examples)
15+
16+
SET(MY_DIR ${libfreenect2_examples_SOURCE_DIR})
17+
SET(DEPENDS_DIR "${MY_DIR}/../depends" CACHE STRING "Dependency directory")
18+
19+
OPTION(ENABLE_OPENGL "Enable OpenGL support" ON)
20+
21+
# The example build system is standalone and will work out-of-tree with these files copied
22+
SET(freenect2_ROOT_DIR ${MY_DIR}/..)
23+
SET(flextGL_SOURCES ${freenect2_ROOT_DIR}/src/flextGL.c)
24+
SET(flextGL_INCLUDE_DIRS ${freenect2_ROOT_DIR}/src) # for flextGL.h
25+
26+
FIND_PACKAGE(PkgConfig) # try find PKGConfig as it will be used if found
27+
LIST(APPEND CMAKE_MODULE_PATH ${freenect2_ROOT_DIR}/cmake_modules) # FindGLFW3.cmake
28+
29+
IF(TARGET freenect2)
30+
MESSAGE(STATUS "Using in-tree freenect2 target")
31+
SET(freenect2_LIBRARIES freenect2)
32+
ELSE()
33+
FIND_PACKAGE(freenect2 REQUIRED)
34+
ENDIF()
35+
36+
INCLUDE_DIRECTORIES(
37+
${freenect2_INCLUDE_DIR}
38+
)
39+
40+
LINK_DIRECTORIES(
41+
${freenect2_LIBRARY_DIRS}
42+
)
43+
44+
SET(Protonect_src
45+
Protonect.cpp
46+
)
47+
48+
SET(Protonect_LIBRARIES
49+
${freenect2_LIBRARIES}
50+
)
51+
52+
IF(ENABLE_OPENGL)
53+
FIND_PACKAGE(GLFW3)
54+
FIND_PACKAGE(OpenGL)
55+
IF(GLFW3_FOUND AND OPENGL_FOUND)
56+
INCLUDE_DIRECTORIES(
57+
${GLFW3_INCLUDE_DIRS}
58+
${flextGL_INCLUDE_DIRS}
59+
)
60+
61+
LINK_DIRECTORIES(${GLFW3_LIBRARY_DIRS})
62+
LIST(APPEND Protonect_src
63+
viewer.cpp
64+
${flextGL_SOURCES}
65+
)
66+
LIST(APPEND Protonect_LIBRARIES
67+
${GLFW3_LIBRARIES}
68+
${OPENGL_gl_LIBRARY}
69+
)
70+
ADD_DEFINITIONS(-DEXAMPLES_WITH_OPENGL_SUPPORT=1)
71+
ENDIF()
72+
ENDIF(ENABLE_OPENGL)
73+
74+
ADD_EXECUTABLE(Protonect
75+
${Protonect_src}
76+
)
77+
78+
TARGET_LINK_LIBRARIES(Protonect
79+
${Protonect_LIBRARIES}
80+
)

examples/Protonect.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131

3232
#include <libfreenect2/libfreenect2.hpp>
3333
#include <libfreenect2/frame_listener_impl.h>
34-
#include <libfreenect2/threading.h>
3534
#include <libfreenect2/registration.h>
3635
#include <libfreenect2/packet_pipeline.h>
3736
#include <libfreenect2/logger.h>
38-
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
37+
#ifdef EXAMPLES_WITH_OPENGL_SUPPORT
3938
#include "viewer.h"
4039
#endif
4140

@@ -186,7 +185,7 @@ int main(int argc, char *argv[])
186185
libfreenect2::Registration* registration = new libfreenect2::Registration(dev->getIrCameraParams(), dev->getColorCameraParams());
187186

188187
size_t framecount = 0;
189-
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
188+
#ifdef EXAMPLES_WITH_OPENGL_SUPPORT
190189
Viewer viewer;
191190
if (viewer_enabled)
192191
viewer.initialize();
@@ -212,7 +211,7 @@ int main(int argc, char *argv[])
212211
continue;
213212
}
214213

215-
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
214+
#ifdef EXAMPLES_WITH_OPENGL_SUPPORT
216215
viewer.addFrame("RGB", rgb);
217216
viewer.addFrame("ir", ir);
218217
viewer.addFrame("depth", depth);

examples/viewer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <string>
88
#include <map>
99

10-
#include <../src/flextGL.h>
10+
#include "flextGL.h"
1111
#include <GLFW/glfw3.h>
1212

1313
struct Vertex

freenect2.cmake.in

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,3 @@ FIND_PATH(freenect2_INCLUDE_DIR @PROJECT_NAME@/libfreenect2.hpp
77
PATHS @CMAKE_INSTALL_PREFIX@/include
88
NO_DEFAULT_PATH
99
)
10-
11-
IF("@LIBFREENECT2_THREADING_TINYTHREAD@")
12-
SET(freenect2_INCLUDE_DIRS ${freenect2_INCLUDE_DIR} ${freenect2_INCLUDE_DIR}/tinythread)
13-
ENDIF("@LIBFREENECT2_THREADING_TINYTHREAD@")
File renamed without changes.

include/libfreenect2/data_callback.h renamed to include/internal/libfreenect2/data_callback.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
namespace libfreenect2
3636
{
3737

38-
class LIBFREENECT2_API DataCallback
38+
class DataCallback
3939
{
4040
public:
4141
/**

include/libfreenect2/depth_packet_stream_parser.h renamed to include/internal/libfreenect2/depth_packet_stream_parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace libfreenect2
4343
{
4444

4545
/** Footer of a depth packet. */
46-
LIBFREENECT2_PACK(struct LIBFREENECT2_API DepthSubPacketFooter
46+
LIBFREENECT2_PACK(struct DepthSubPacketFooter
4747
{
4848
uint32_t magic0;
4949
uint32_t magic1;
@@ -58,7 +58,7 @@ LIBFREENECT2_PACK(struct LIBFREENECT2_API DepthSubPacketFooter
5858
* Parser of th depth stream, recognizes valid depth packets in the stream, and
5959
* passes them on for further processing.
6060
*/
61-
class LIBFREENECT2_API DepthPacketStreamParser : public DataCallback
61+
class DepthPacketStreamParser : public DataCallback
6262
{
6363
public:
6464
DepthPacketStreamParser();

include/libfreenect2/double_buffer.h renamed to include/internal/libfreenect2/double_buffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace libfreenect2
3636
{
3737

3838
/** Data of a single buffer. */
39-
struct LIBFREENECT2_API Buffer
39+
struct Buffer
4040
{
4141
public:
4242
size_t capacity; ///< Capacity of the buffer.
@@ -45,7 +45,7 @@ struct LIBFREENECT2_API Buffer
4545
};
4646

4747
/** Double bufffer class. */
48-
class LIBFREENECT2_API DoubleBuffer
48+
class DoubleBuffer
4949
{
5050
public:
5151
DoubleBuffer();

0 commit comments

Comments
 (0)