Skip to content
Browse files

CMake: Make building the tracker module optional

  • Loading branch information...
1 parent 4288aeb commit 50fae043fe4a2cb34db807d46048968e0fc6b68d @thp committed Aug 12, 2012
Showing with 62 additions and 19 deletions.
  1. +1 −0 .gitignore
  2. +33 −18 CMakeLists.txt
  3. +0 −1 contrib/psmoveapi.pc.in
  4. +12 −0 examples/c/test_tracker.c
  5. +5 −0 include/psmove_config.h.in
  6. +5 −0 include/psmove_tracker.h
  7. +6 −0 src/psmove_tracker.c
View
1 .gitignore
@@ -0,0 +1 @@
+include/psmove_config.h
View
51 CMakeLists.txt
@@ -21,6 +21,28 @@ set(PSMOVEAPI_PLATFORM_SRC)
# Put any other libraries that you might need in here
link_directories(${PSMOVEAPI_SOURCE_DIR}/external/libs)
+# Build the OpenCV-based camera tracking module? (see psmove_tracker.h)
+option(PSMOVE_BUILD_TRACKER "Build the Tracker module (needs OpenCV)" ON)
+
+# Search for OpenCV, if we don't have it, build without tracker
+FIND_PACKAGE(OpenCV QUIET)
+if(OpenCV_FOUND AND PSMOVE_BUILD_TRACKER)
+ list(APPEND PSMOVE_REQUIRED_LIBS ${OpenCV_LIBS})
+
+ file(GLOB PSMOVEAPI_TRACKER_SRC
+ "${PSMOVEAPI_SOURCE_DIR}/src/tracker/*.c"
+ "${PSMOVEAPI_SOURCE_DIR}/external/iniparser/*.c"
+ )
+
+ set(BUILD_PSMOVE_TRACKER "Yes")
+ set(PSMOVE_HAVE_TRACKER ON)
+else()
+ set(PSMOVEAPI_TRACKER_SRC "")
+
+ set(BUILD_PSMOVE_TRACKER "No ")
+ set(PSMOVE_HAVE_TRACKER OFF)
+endif()
+
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
find_library(IOKIT IOKit)
find_library(COREFOUNDATION CoreFoundation)
@@ -29,20 +51,12 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND PSMOVE_REQUIRED_LIBS ${COREFOUNDATION})
list(APPEND PSMOVE_REQUIRED_LIBS ${IOBLUETOOTH})
- # XXX: Make this optional
- FIND_PACKAGE(OpenCV REQUIRED)
- list(APPEND PSMOVE_REQUIRED_LIBS ${OpenCV_LIBS})
-
set(HIDAPI_SRC ${PSMOVEAPI_SOURCE_DIR}/external/hidapi/mac/hid.c)
list(APPEND PSMOVEAPI_PLATFORM_SRC ${PSMOVEAPI_SOURCE_DIR}/src/platform/psmove_osxsupport.m)
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
list(APPEND PSMOVE_REQUIRED_LIBS setupapi bthprops kernel32 ws2_32)
list(APPEND MOVED_CLIENT_REQUIRED_LIBS ws2_32)
- # XXX: Make this optional
- FIND_PACKAGE(OpenCV REQUIRED)
- list(APPEND PSMOVE_REQUIRED_LIBS ${OpenCV_LIBS})
-
# If you want to use the CL Eye SDK, uncomment the following line
#list(APPEND PSMOVE_REQUIRED_LIBS CLEyeMulticam)
@@ -61,22 +75,12 @@ ELSE()
include_directories(${BLUEZ_INCLUDE_DIRS})
list(APPEND PSMOVE_REQUIRED_LIBS ${BLUEZ_LIBRARIES})
- # XXX: Make this optional
- pkg_check_modules(OPENCV REQUIRED opencv)
- include_directories(${OPENCV_INCLUDE_DIRS})
- list(APPEND PSMOVE_REQUIRED_LIBS ${OPENCV_LIBRARIES})
-
set(HIDAPI_SRC ${PSMOVEAPI_SOURCE_DIR}/external/hidapi/linux/hid.c)
list(APPEND PSMOVEAPI_PLATFORM_SRC ${PSMOVEAPI_SOURCE_DIR}/src/platform/psmove_linuxsupport.c)
ENDIF()
include_directories(${PSMOVEAPI_SOURCE_DIR}/include)
-file(GLOB PSMOVEAPI_TRACKER_SRC
- "${PSMOVEAPI_SOURCE_DIR}/src/tracker/*.c"
- "${PSMOVEAPI_SOURCE_DIR}/external/iniparser/*.c"
-)
-
file(GLOB PSMOVEAPI_MOVED_SRC
"${PSMOVEAPI_SOURCE_DIR}/src/daemon/*.c"
)
@@ -178,6 +182,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/contrib/psmoveapi.pc.in
${CMAKE_CURRENT_BINARY_DIR}/psmoveapi.pc
@ONLY)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/psmove_config.h.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/psmove_config.h
+ @ONLY)
+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/psmoveapi.pc DESTINATION lib/pkgconfig)
install(TARGETS psmovepair psmoveapi
@@ -204,5 +212,12 @@ MESSAGE(" | Python bindings: " ${PADDING} ${BUILD_PYTHON_BINDINGS} " |")
MESSAGE(" | Java bindings: " ${PADDING} ${BUILD_JAVA_BINDINGS} " |")
MESSAGE(" | Qt bindings: " ${PADDING} ${BUILD_QT_BINDINGS} " |")
MESSAGE(" +---------------------------------------------+ ")
+MESSAGE(" | Tracker module: " ${PADDING} ${BUILD_PSMOVE_TRACKER} " |")
+MESSAGE(" +---------------------------------------------+ ")
+MESSAGE("")
+if(NOT OpenCV_FOUND)
+ MESSAGE(" If you want to build the tracker module, install OpenCV!")
+endif()
+MESSAGE("")
MESSAGE("")
View
1 contrib/psmoveapi.pc.in
@@ -7,7 +7,6 @@ Name: psmoveapi
Description: API for Sony Motion Controllers (PS Move)
URL: http://thp.io/2010/psmove/
Version: @PSMOVEAPI_VERSION@
-Requires.private: libusb-1.0
Libs: -L${libdir} -lpsmoveapi
Cflags: -I${includedir}
View
12 examples/c/test_tracker.c
@@ -1,5 +1,8 @@
#include <stdio.h>
+
+#if defined(PSMOVE_HAVE_TRACKER)
+
#include <time.h>
#include <unistd.h>
#include <assert.h>
@@ -77,3 +80,12 @@ int main(int arg, char** args) {
return 0;
}
+#else /* PSMOVE_HAVE_TRACKER */
+
+int main()
+{
+ printf("PS Move API compiled without Tracker support.\n");
+ return 1;
+}
+
+#endif
View
5 include/psmove_config.h.in
@@ -0,0 +1,5 @@
+
+/* This file is auto-generated from psmove_config.h.in by CMake */
+
+#cmakedefine PSMOVE_HAVE_TRACKER
+
View
5 include/psmove_tracker.h
@@ -30,11 +30,14 @@
**/
#include "psmove.h"
+#include "psmove_config.h"
#ifdef __cplusplus
extern "C" {
#endif
+#if defined(PSMOVE_HAVE_TRACKER)
+
/* Defines the range of x/y values for the position getting, etc.. */
#define PSMOVE_TRACKER_POSITION_X_MAX 640
#define PSMOVE_TRACKER_POSITION_Y_MAX 480
@@ -224,6 +227,8 @@ ADDCALL psmove_tracker_get_position(PSMoveTracker *tracker,
ADDAPI void
ADDCALL psmove_tracker_free(PSMoveTracker *tracker);
+#endif /* defined(PSMOVE_HAVE_TRACKER) */
+
#ifdef __cplusplus
}
#endif
View
6 src/psmove_tracker.c
@@ -26,6 +26,10 @@
* POSSIBILITY OF SUCH DAMAGE.
**/
+#include "psmove_config.h"
+
+#if defined(PSMOVE_HAVE_TRACKER)
+
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -1227,3 +1231,5 @@ CvPoint psmove_tracker_better_roi_center(TrackedController* tc, PSMoveTracker* t
cvResetImageROI(t->frame);
return erg;
}
+
+#endif /* defined(PSMOVE_HAVE_TRACKER) */

0 comments on commit 50fae04

Please sign in to comment.
Something went wrong with that request. Please try again.