Skip to content

Commit

Permalink
Switch to a sane CMake-based buildsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
marcan committed Nov 10, 2010
1 parent 286e42a commit 63eba92
Show file tree
Hide file tree
Showing 15 changed files with 225 additions and 191 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
testcam
*.o
build
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PROJECT(libfreenect)

cmake_minimum_required(VERSION 2.6)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/Modules/")

set(CMAKE_C_FLAGS "-Wall -O3 -g")

add_subdirectory (lib)
add_subdirectory (examples)
13 changes: 0 additions & 13 deletions Makefile

This file was deleted.

31 changes: 31 additions & 0 deletions Modules/FindUSB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# - Try to find libusb-1.0
# Once done, this will define
#
# USB_FOUND - system has libusb-1.0
# USB_INCLUDE_DIRS - the libusb-1.0 include directories
# USB_LIBRARIES - link these to use libusb-1.0

include(LibFindMacros)

# Dependencies

# Use pkg-config to get hints about paths
libfind_pkg_check_modules(USB_PKGCONF libusb-1.0>=1.0.3)

# Include dir
find_path(USB_INCLUDE_DIR
NAMES libusb.h
PATHS ${USB_PKGCONF_INCLUDE_DIRS}
)

# Finally the library itself
find_library(USB_LIBRARY
NAMES usb-1.0
PATHS ${USB_PKGCONF_LIBRARY_DIRS}
)

# Set the include dir variables and the libraries and let libfind_process do the rest.
# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
set(USB_PROCESS_INCLUDES USB_INCLUDE_DIR)
set(USB_PROCESS_LIBS USB_LIBRARY)
libfind_process(USB)
99 changes: 99 additions & 0 deletions Modules/LibFindMacros.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
# used for the current package. For this to work, the first parameter must be the
# prefix of the current package, then the prefix of the new package etc, which are
# passed to find_package.
macro (libfind_package PREFIX)
set (LIBFIND_PACKAGE_ARGS ${ARGN})
if (${PREFIX}_FIND_QUIETLY)
set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
endif (${PREFIX}_FIND_QUIETLY)
if (${PREFIX}_FIND_REQUIRED)
set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
endif (${PREFIX}_FIND_REQUIRED)
find_package(${LIBFIND_PACKAGE_ARGS})
endmacro (libfind_package)

# Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
# where they added pkg_check_modules. Consequently I need to support both in my scripts
# to avoid those deprecated warnings. Here's a helper that does just that.
# Works identically to pkg_check_modules, except that no checks are needed prior to use.
macro (libfind_pkg_check_modules PREFIX PKGNAME)
if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
include(UsePkgConfig)
pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(${PREFIX} ${PKGNAME})
endif (PKG_CONFIG_FOUND)
endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
endmacro (libfind_pkg_check_modules)

# Do the final processing once the paths have been detected.
# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
# all the variables, each of which contain one include directory.
# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
# Also handles errors in case library detection was required, etc.
macro (libfind_process PREFIX)
# Skip processing if already processed during this run
if (NOT ${PREFIX}_FOUND)
# Start with the assumption that the library was found
set (${PREFIX}_FOUND TRUE)

# Process all includes and set _FOUND to false if any are missing
foreach (i ${${PREFIX}_PROCESS_INCLUDES})
if (${i})
set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
mark_as_advanced(${i})
else (${i})
set (${PREFIX}_FOUND FALSE)
endif (${i})
endforeach (i)

# Process all libraries and set _FOUND to false if any are missing
foreach (i ${${PREFIX}_PROCESS_LIBS})
if (${i})
set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
mark_as_advanced(${i})
else (${i})
set (${PREFIX}_FOUND FALSE)
endif (${i})
endforeach (i)

# Print message and/or exit on fatal error
if (${PREFIX}_FOUND)
if (NOT ${PREFIX}_FIND_QUIETLY)
message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
endif (NOT ${PREFIX}_FIND_QUIETLY)
else (${PREFIX}_FOUND)
if (${PREFIX}_FIND_REQUIRED)
foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
message("${i}=${${i}}")
endforeach (i)
message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
endif (${PREFIX}_FIND_REQUIRED)
endif (${PREFIX}_FOUND)
endif (NOT ${PREFIX}_FOUND)
endmacro (libfind_process)

macro(libfind_library PREFIX basename)
set(TMP "")
if(MSVC80)
set(TMP -vc80)
endif(MSVC80)
if(MSVC90)
set(TMP -vc90)
endif(MSVC90)
set(${PREFIX}_LIBNAMES ${basename}${TMP})
if(${ARGC} GREATER 2)
set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
endif(${ARGC} GREATER 2)
find_library(${PREFIX}_LIBRARY
NAMES ${${PREFIX}_LIBNAMES}
PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
)
endmacro(libfind_library)

1 change: 0 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ called as libusb processes events.

TODO:
- TONS of cleanup. I mean LOTS.
- Proper buildsystem (CMake probably)
- Determine exactly what the inits do
- Bayer to RGB conversion that doesn't suck
- Integrate support for the servo and accelerometer (which have already been
Expand Down
14 changes: 14 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include_directories (${CMAKE_SOURCE_DIR}/include)
link_directories (${CMAKE_BINARY_DIR}/lib)

find_package(Threads REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLU REQUIRED)
find_package(GLUT REQUIRED)

find_package(USB REQUIRED)
include_directories(${USB_INCLUDE_DIRS})

add_executable(glview glview.c)
find_library (PTHREAD pthread)
target_link_libraries(glview freenect GL GLU glut)
4 changes: 2 additions & 2 deletions main.c → examples/glview.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This code is licensed to you under the terms of the GNU GPL, version 2 or versio

#include <stdio.h>
#include <string.h>
#include <libusb-1.0/libusb.h>
#include "cameras.h"
#include <libusb.h>
#include "libfreenect.h"

#include <pthread.h>

Expand Down
17 changes: 3 additions & 14 deletions cameras.h → include/libfreenect.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@ This code is licensed to you under the terms of the GNU GPL, version 2 or versio
http://www.gnu.org/licenses/gpl-3.0.txt
*/

#ifndef CAMERAS_H
#define CAMERAS_H

#include <stdint.h>

struct caminit {
uint16_t command;
uint16_t tag;
int cmdlen;
int replylen;
uint8_t cmddata[1024];
uint8_t replydata[1024];
};
#ifndef LIBFREENECT_H
#define LIBFREENECT_H

typedef void (*depthcb)(uint16_t *buf, int width, int height);
typedef void (*rgbcb)(uint8_t *buf, int width, int height);

void cams_init(libusb_device_handle *d, depthcb depth_cb, rgbcb rgb_cb);

#endif
#endif
144 changes: 0 additions & 144 deletions inits.h

This file was deleted.

15 changes: 15 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include_directories (${CMAKE_SOURCE_DIR}/include)
include_directories (${CMAKE_SOURCE_DIR}/lib)

find_package(Threads REQUIRED)
find_package(USB REQUIRED)
include_directories(${USB_INCLUDE_DIRS})

add_library (freenect cameras.c ${CMAKE_CURRENT_BINARY_DIR}/inits.c)
find_library (PTHREAD pthread)
target_link_libraries (freenect ${CMAKE_THREAD_LIBS_INIT} ${USB_LIBRARIES})

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/inits.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/geninits.py
MAIN_DEPENDENCY inits.txt
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/geninits.py ${CMAKE_CURRENT_SOURCE_DIR}/inits.txt ${CMAKE_CURRENT_BINARY_DIR}/inits.c)
Loading

0 comments on commit 63eba92

Please sign in to comment.