Skip to content

Commit

Permalink
CMake: Make building the tracker module optional
Browse files Browse the repository at this point in the history
  • Loading branch information
thp committed Aug 12, 2012
1 parent 4288aeb commit 50fae04
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
include/psmove_config.h
51 changes: 33 additions & 18 deletions CMakeLists.txt
Expand Up @@ -21,6 +21,28 @@ set(PSMOVEAPI_PLATFORM_SRC)
# Put any other libraries that you might need in here # Put any other libraries that you might need in here
link_directories(${PSMOVEAPI_SOURCE_DIR}/external/libs) 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") IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
find_library(IOKIT IOKit) find_library(IOKIT IOKit)
find_library(COREFOUNDATION CoreFoundation) find_library(COREFOUNDATION CoreFoundation)
Expand All @@ -29,20 +51,12 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND PSMOVE_REQUIRED_LIBS ${COREFOUNDATION}) list(APPEND PSMOVE_REQUIRED_LIBS ${COREFOUNDATION})
list(APPEND PSMOVE_REQUIRED_LIBS ${IOBLUETOOTH}) 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) set(HIDAPI_SRC ${PSMOVEAPI_SOURCE_DIR}/external/hidapi/mac/hid.c)
list(APPEND PSMOVEAPI_PLATFORM_SRC ${PSMOVEAPI_SOURCE_DIR}/src/platform/psmove_osxsupport.m) list(APPEND PSMOVEAPI_PLATFORM_SRC ${PSMOVEAPI_SOURCE_DIR}/src/platform/psmove_osxsupport.m)
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
list(APPEND PSMOVE_REQUIRED_LIBS setupapi bthprops kernel32 ws2_32) list(APPEND PSMOVE_REQUIRED_LIBS setupapi bthprops kernel32 ws2_32)
list(APPEND MOVED_CLIENT_REQUIRED_LIBS 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 # If you want to use the CL Eye SDK, uncomment the following line
#list(APPEND PSMOVE_REQUIRED_LIBS CLEyeMulticam) #list(APPEND PSMOVE_REQUIRED_LIBS CLEyeMulticam)


Expand All @@ -61,22 +75,12 @@ ELSE()
include_directories(${BLUEZ_INCLUDE_DIRS}) include_directories(${BLUEZ_INCLUDE_DIRS})
list(APPEND PSMOVE_REQUIRED_LIBS ${BLUEZ_LIBRARIES}) 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) set(HIDAPI_SRC ${PSMOVEAPI_SOURCE_DIR}/external/hidapi/linux/hid.c)
list(APPEND PSMOVEAPI_PLATFORM_SRC ${PSMOVEAPI_SOURCE_DIR}/src/platform/psmove_linuxsupport.c) list(APPEND PSMOVEAPI_PLATFORM_SRC ${PSMOVEAPI_SOURCE_DIR}/src/platform/psmove_linuxsupport.c)
ENDIF() ENDIF()


include_directories(${PSMOVEAPI_SOURCE_DIR}/include) 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 file(GLOB PSMOVEAPI_MOVED_SRC
"${PSMOVEAPI_SOURCE_DIR}/src/daemon/*.c" "${PSMOVEAPI_SOURCE_DIR}/src/daemon/*.c"
) )
Expand Down Expand Up @@ -178,6 +182,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/contrib/psmoveapi.pc.in
${CMAKE_CURRENT_BINARY_DIR}/psmoveapi.pc ${CMAKE_CURRENT_BINARY_DIR}/psmoveapi.pc
@ONLY) @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(FILES ${CMAKE_CURRENT_BINARY_DIR}/psmoveapi.pc DESTINATION lib/pkgconfig)


install(TARGETS psmovepair psmoveapi install(TARGETS psmovepair psmoveapi
Expand All @@ -204,5 +212,12 @@ MESSAGE(" | Python bindings: " ${PADDING} ${BUILD_PYTHON_BINDINGS} " |")
MESSAGE(" | Java bindings: " ${PADDING} ${BUILD_JAVA_BINDINGS} " |") MESSAGE(" | Java bindings: " ${PADDING} ${BUILD_JAVA_BINDINGS} " |")
MESSAGE(" | Qt bindings: " ${PADDING} ${BUILD_QT_BINDINGS} " |") MESSAGE(" | Qt bindings: " ${PADDING} ${BUILD_QT_BINDINGS} " |")
MESSAGE(" +---------------------------------------------+ ") 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("") MESSAGE("")


1 change: 0 additions & 1 deletion contrib/psmoveapi.pc.in
Expand Up @@ -7,7 +7,6 @@ Name: psmoveapi
Description: API for Sony Motion Controllers (PS Move) Description: API for Sony Motion Controllers (PS Move)
URL: http://thp.io/2010/psmove/ URL: http://thp.io/2010/psmove/
Version: @PSMOVEAPI_VERSION@ Version: @PSMOVEAPI_VERSION@
Requires.private: libusb-1.0
Libs: -L${libdir} -lpsmoveapi Libs: -L${libdir} -lpsmoveapi
Cflags: -I${includedir} Cflags: -I${includedir}


12 changes: 12 additions & 0 deletions examples/c/test_tracker.c
@@ -1,5 +1,8 @@


#include <stdio.h> #include <stdio.h>

#if defined(PSMOVE_HAVE_TRACKER)

#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
Expand Down Expand Up @@ -77,3 +80,12 @@ int main(int arg, char** args) {
return 0; return 0;
} }


#else /* PSMOVE_HAVE_TRACKER */

int main()
{
printf("PS Move API compiled without Tracker support.\n");
return 1;
}

#endif
5 changes: 5 additions & 0 deletions 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

5 changes: 5 additions & 0 deletions include/psmove_tracker.h
Expand Up @@ -30,11 +30,14 @@
**/ **/


#include "psmove.h" #include "psmove.h"
#include "psmove_config.h"


#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif


#if defined(PSMOVE_HAVE_TRACKER)

/* Defines the range of x/y values for the position getting, etc.. */ /* Defines the range of x/y values for the position getting, etc.. */
#define PSMOVE_TRACKER_POSITION_X_MAX 640 #define PSMOVE_TRACKER_POSITION_X_MAX 640
#define PSMOVE_TRACKER_POSITION_Y_MAX 480 #define PSMOVE_TRACKER_POSITION_Y_MAX 480
Expand Down Expand Up @@ -224,6 +227,8 @@ ADDCALL psmove_tracker_get_position(PSMoveTracker *tracker,
ADDAPI void ADDAPI void
ADDCALL psmove_tracker_free(PSMoveTracker *tracker); ADDCALL psmove_tracker_free(PSMoveTracker *tracker);


#endif /* defined(PSMOVE_HAVE_TRACKER) */

#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
Expand Down
6 changes: 6 additions & 0 deletions src/psmove_tracker.c
Expand Up @@ -26,6 +26,10 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
**/ **/


#include "psmove_config.h"

#if defined(PSMOVE_HAVE_TRACKER)

#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
Expand Down Expand Up @@ -1227,3 +1231,5 @@ CvPoint psmove_tracker_better_roi_center(TrackedController* tc, PSMoveTracker* t
cvResetImageROI(t->frame); cvResetImageROI(t->frame);
return erg; return erg;
} }

#endif /* defined(PSMOVE_HAVE_TRACKER) */

0 comments on commit 50fae04

Please sign in to comment.