Permalink
Browse files

all: Deploy a cmake build system for this code base

There's nothing really complex about what we are doing here. However
this allows us the option of using unit tests in the future along with
library building.
  • Loading branch information...
Zack Moratto authored and yglee committed Aug 27, 2012
1 parent 3f42a67 commit 6422128537c1b4c7c709640d29b59ebeed491911
View
@@ -0,0 +1 @@
+*~
View
@@ -0,0 +1,70 @@
+project(FSLAM CXX)
+cmake_minimum_required(VERSION 2.8)
+
+# Add path for custom modules
+set(CMAKE_MODULE_PATH
+ ${CMAKE_MODULE_PATH}
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
+ )
+
+set(PACKAGE_VERSION "0.1")
+set(PACKAGE_NAME "FastSLAM")
+set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
+set(PACKAGE_BUGREPORT "yeonjin.lee@nasa.gov")
+
+# Local Custom Options
+option(FSLAM_BUILD_TOOLS
+ "Build the FastSLAM test tools." ON)
+option(BUILD_SHARED_LIBS
+ "Produce shared libraries." TRUE)
+option(ENABLE_RPATHS
+ "Use RPaths in executables to find shared libraries." TRUE)
+option(ENABLE_PROFILING
+ "Link against the google perftools." FALSE)
+option(ENABLE_TCMALLOC
+ "Link against the google perftools's tcmalloc." FALSE)
+if (ENABLE_RPATHS)
+ set(CMAKE_SKIP_RPATH FALSE CACHE BOOL "")
+ set(CMAKE_SKIP_BUILD_RPATH FALSE CACHE BOOL "")
+ set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE CACHE BOOL "")
+ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
+ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "")
+ if(APPLE)
+ set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
+ endif(APPLE)
+ mark_as_advanced(
+ CMAKE_SKIP_RPATH
+ CMAKE_SKIP_BUILD_RPATH
+ CMAKE_BUILD_WITH_INSTALL_RPATH
+ CMAKE_INSTALL_RPATH
+ CMAKE_INSTALL_RPATH_USE_LINK_PATH
+ )
+endif(ENABLE_RPATHS)
+
+# Find Dependencies
+include(AddFSLAM)
+find_package(Eigen3 REQUIRED)
+find_package(GooglePerfTools)
+
+# Finish up local custom options based on what was found above
+fslam_enable_testing()
+if (ENABLE_PROFILING AND GOOGLE_PERFTOOLS_FOUND)
+ set(FSLAM_ENABLE_PROFILING ON )
+else()
+ set(FSLAM_ENABLE_PROFILING OFF )
+endif()
+
+if (ENABLE_TCMALLOC AND GOOGLE_PERFTOOLS_FOUND)
+ set(FSLAM_ENABLE_TCMALLOC ON)
+else()
+ set(FSLAM_ENABLE_TCMALLOC OFF)
+endif()
+
+# Add common search locations
+include_directories(${FSLAM_SOURCE_DIR}/cpp)
+include_directories(${FSLAM_BINARY_DIR}/cpp)
+
+# Adding build directories
+add_subdirectory(cpp)
+
+# Adding test directories
View
@@ -1,2 +0,0 @@
-FastSLAM
-========
View
@@ -0,0 +1,81 @@
+macro(add_fslam_executable name)
+ add_executable(${name} ${ARGN})
+ foreach(lib ${FSLAM_USED_LIBS})
+ if( NOT ${lib} STREQUAL "optimized" AND
+ NOT ${lib} STREQUAL "debug" )
+ target_link_libraries( ${name} ${lib} )
+ endif()
+ endforeach(lib)
+ if ( FSLAM_ENABLE_PROFILING )
+ target_link_libraries( ${name} ${PROFILER_LIBRARY} )
+ endif()
+ if ( FSLAM_ENABLE_TCMALLOC )
+ target_link_libraries( ${name} ${TCMALLOC_LIBRARY} )
+ endif()
+ if ( MKL_LIBRARIES )
+ target_link_libraries( ${name} ${MKL_LIBRARIES} )
+ endif()
+endmacro(add_fslam_executable name)
+
+macro(add_fslam_tool name)
+ add_fslam_executable(${name} ${ARGN})
+ if( FSLAM_BUILD_TOOLS )
+ message( "Installing: " ${name} )
+ install(TARGETS ${name} RUNTIME DESTINATION bin)
+ endif()
+ set_target_properties(${name} PROPERTIES FOLDER "tools")
+endmacro(add_fslam_tool name)
+
+function(fslam_enable_testing)
+ set(GTEST_DIR ${CMAKE_SOURCE_DIR}/thirdparty/gtest)
+ include_directories(${VISIONWORKBENCH_INCLUDE_DIRS})
+ include_directories(${GTEST_DIR}/include)
+ add_library(gtest SHARED EXCLUDE_FROM_ALL
+ ${GTEST_DIR}/src/gtest-all.cc
+ ${CMAKE_SOURCE_DIR}/testcode/test_main.cc
+ )
+ target_link_libraries(gtest
+ ${VISIONWORKBENCH_CORE_LIBRARY}
+ ${Boost_FILESYSTEM_LIBRARY}
+ ${Boost_SYSTEM_LIBRARY}
+ )
+ set_target_properties(gtest
+ PROPERTIES
+ COMPILE_FLAGS "-DTEST_SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" -DTEST_DSTDIR=\\\"${CMAKE_CURRENT_BINARY_DIR}\\\""
+ )
+
+ add_custom_target(check)
+ add_dependencies(check gtest)
+endfunction(fslam_enable_testing)
+
+
+function(fslam_add_test source_file)
+ string(REGEX REPLACE "^([A-Za-z0-9_]*)\\.([A-Za-z0-9]*)" "\\1" executable "${source_file}")
+
+ add_executable(${executable} EXCLUDE_FROM_ALL ${source_file} )
+ target_link_libraries( ${executable} gtest )
+ foreach(lib ${FSLAM_USED_LIBS})
+ target_link_libraries( ${executable} ${lib} )
+ endforeach(lib)
+
+ set_target_properties(${executable}
+ PROPERTIES
+ COMPILE_FLAGS "-DTEST_SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" -DTEST_DSTDIR=\\\"${CMAKE_CURRENT_BINARY_DIR}\\\""
+ )
+ add_custom_target(${executable}Exec ${CMAKE_CURRENT_BINARY_DIR}/${executable}
+ DEPENDS ${executable}
+ )
+ add_dependencies(check ${executable}Exec)
+
+ if ( MKL_LIBRARIES )
+ target_link_libraries( ${executable} ${MKL_LIBRARIES} )
+ endif()
+
+ # file(READ "${source_file}" contents)
+ # string(REGEX MATCHALL "TEST_?F?\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})
+ # foreach(hit ${found_tests})
+ # string(REGEX REPLACE ".*\\( *([A-Za-z_0-9]+), *([A-Za-z_0-9]+) *\\).*" "\\1.\\2" test_name ${hit})
+ # message("Added test name: " ${executable} "\t" ${test_name})
+ # add_test(${test_name} ${executable} --gtest_filter=${test_name})
+ # endforeach()
+endfunction(fslam_add_test)
View
@@ -0,0 +1,81 @@
+# - Try to find Eigen3 lib
+#
+# This module supports requiring a minimum version, e.g. you can do
+# find_package(Eigen3 3.1.2)
+# to require version 3.1.2 or newer of Eigen3.
+#
+# Once done this will define
+#
+# EIGEN3_FOUND - system has eigen lib with correct version
+# EIGEN3_INCLUDE_DIR - the eigen include directory
+# EIGEN3_VERSION - eigen version
+
+# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
+# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
+# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
+
+if(NOT Eigen3_FIND_VERSION)
+ if(NOT Eigen3_FIND_VERSION_MAJOR)
+ set(Eigen3_FIND_VERSION_MAJOR 2)
+ endif(NOT Eigen3_FIND_VERSION_MAJOR)
+ if(NOT Eigen3_FIND_VERSION_MINOR)
+ set(Eigen3_FIND_VERSION_MINOR 91)
+ endif(NOT Eigen3_FIND_VERSION_MINOR)
+ if(NOT Eigen3_FIND_VERSION_PATCH)
+ set(Eigen3_FIND_VERSION_PATCH 0)
+ endif(NOT Eigen3_FIND_VERSION_PATCH)
+
+ set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}")
+endif(NOT Eigen3_FIND_VERSION)
+
+macro(_eigen3_check_version)
+ file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
+
+ string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
+ set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
+ string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
+ set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
+ string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
+ set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
+
+ set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
+ if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
+ set(EIGEN3_VERSION_OK FALSE)
+ else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
+ set(EIGEN3_VERSION_OK TRUE)
+ endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
+
+ if(NOT EIGEN3_VERSION_OK)
+
+ message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, "
+ "but at least version ${Eigen3_FIND_VERSION} is required")
+ endif(NOT EIGEN3_VERSION_OK)
+endmacro(_eigen3_check_version)
+
+if (EIGEN3_INCLUDE_DIR)
+
+ # in cache already
+ _eigen3_check_version()
+ set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
+
+else (EIGEN3_INCLUDE_DIR)
+
+ find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
+ PATHS
+ ${CMAKE_INSTALL_PREFIX}/include
+ ${KDE4_INCLUDE_DIR}
+ PATH_SUFFIXES eigen3 eigen
+ )
+
+ if(EIGEN3_INCLUDE_DIR)
+ _eigen3_check_version()
+ endif(EIGEN3_INCLUDE_DIR)
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
+
+ mark_as_advanced(EIGEN3_INCLUDE_DIR)
+
+endif(EIGEN3_INCLUDE_DIR)
+
@@ -0,0 +1,77 @@
+# -*- cmake -*-
+
+# - Find Google perftools
+# Find the Google perftools includes and libraries
+# This module defines
+# GOOGLE_PERFTOOLS_INCLUDE_DIR, where to find heap-profiler.h, etc.
+# GOOGLE_PERFTOOLS_FOUND, If false, do not try to use Google perftools.
+# also defined for general use are
+# TCMALLOC_LIBRARIES, where to find the tcmalloc library.
+# STACKTRACE_LIBRARIES, where to find the stacktrace library.
+# PROFILER_LIBRARIES, where to find the profiler library.
+
+FIND_PATH(GOOGLE_PERFTOOLS_INCLUDE_DIR google/heap-profiler.h
+ HINTS
+ $ENV{GOOGLE_PERFTOOLS_ROOT}
+ ${GOOGLE_PERFTOOLS_ROOT}
+ /usr/local/
+ /usr
+ /opt/local
+ PATH_SUFFIXES include
+)
+
+SET(TCMALLOC_NAMES ${TCMALLOC_NAMES} tcmalloc)
+FIND_LIBRARY(TCMALLOC_LIBRARY
+ NAMES ${TCMALLOC_NAMES}
+ HINTS /usr /usr/local /opt/local
+ ${GOOGLE_PERFTOOLS_INCLUDE_DIR}/..
+ PATH_SUFFIXES lib lib64
+ )
+
+IF (TCMALLOC_LIBRARY AND GOOGLE_PERFTOOLS_INCLUDE_DIR)
+ SET(TCMALLOC_LIBRARIES ${TCMALLOC_LIBRARY})
+ SET(GOOGLE_PERFTOOLS_FOUND "YES")
+ELSE (TCMALLOC_LIBRARY AND GOOGLE_PERFTOOLS_INCLUDE_DIR)
+ SET(GOOGLE_PERFTOOLS_FOUND "NO")
+ENDIF (TCMALLOC_LIBRARY AND GOOGLE_PERFTOOLS_INCLUDE_DIR)
+
+SET(STACKTRACE_NAMES ${STACKTRACE_NAMES} stacktrace)
+FIND_LIBRARY(STACKTRACE_LIBRARY
+ NAMES ${STACKTRACE_NAMES}
+ HINTS /usr /usr/local /opt/local
+ ${GOOGLE_PERFTOOLS_INCLUDE_DIR}/..
+ PATH_SUFFIXES lib lib64
+ )
+
+IF (STACKTRACE_LIBRARY AND GOOGLE_PERFTOOLS_INCLUDE_DIR)
+ SET(STACKTRACE_LIBRARIES ${STACKTRACE_LIBRARY})
+ENDIF (STACKTRACE_LIBRARY AND GOOGLE_PERFTOOLS_INCLUDE_DIR)
+
+SET(PROFILER_NAMES ${PROFILER_NAMES} profiler)
+FIND_LIBRARY(PROFILER_LIBRARY
+ NAMES ${PROFILER_NAMES}
+ HINTS /usr /usr/local /opt/local
+ ${GOOGLE_PERFTOOLS_INCLUDE_DIR}/..
+ PATH_SUFFIXES lib lib64
+ )
+
+IF (PROFILER_LIBRARY AND GOOGLE_PERFTOOLS_INCLUDE_DIR)
+ SET(PROFILER_LIBRARIES ${PROFILER_LIBRARY})
+ENDIF (PROFILER_LIBRARY AND GOOGLE_PERFTOOLS_INCLUDE_DIR)
+
+IF (GOOGLE_PERFTOOLS_FOUND)
+ IF (NOT GOOGLE_PERFTOOLS_FIND_QUIETLY)
+ MESSAGE(STATUS "Found Google perftools: ${GOOGLE_PERFTOOLS_LIBRARIES}")
+ ENDIF (NOT GOOGLE_PERFTOOLS_FIND_QUIETLY)
+ELSE (GOOGLE_PERFTOOLS_FOUND)
+ IF (GOOGLE_PERFTOOLS_FIND_REQUIRED)
+ MESSAGE(FATAL_ERROR "Could not find Google perftools library")
+ ENDIF (GOOGLE_PERFTOOLS_FIND_REQUIRED)
+ENDIF (GOOGLE_PERFTOOLS_FOUND)
+
+MARK_AS_ADVANCED(
+ TCMALLOC_LIBRARY
+ STACKTRACE_LIBRARY
+ PROFILER_LIBRARY
+ GOOGLE_PERFTOOLS_INCLUDE_DIR
+ )
View
@@ -0,0 +1,37 @@
+include_directories(${EIGEN3_INCLUDE_DIR})
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
+
+# Produce a FastSLAM shared library. (For re-use of executables)
+add_library(FastSLAM
+ KF_cholesky_update.cpp add_observation_noise.cpp fastslam2_sim.cpp predict.cpp stratified_resample.cpp
+ KF_joseph_update.cpp compute_jacobians.cpp feature_update.cpp multivariate_gauss.cpp predict_true.cpp
+ TransformToGlobal.cpp compute_steering.cpp gauss_evaluate.cpp observe_heading.cpp resample_particles.cpp
+ add_control_noise.cpp configfile.cpp get_observations.cpp particle.cpp sample_proposal.cpp
+ add_feature.cpp data_associate_known.cpp line_plot_conversion.cpp pi_to_pi.cpp stratified_random.cpp
+ )
+target_link_libraries(FastSLAM) # We don't depend on anything
+
+install(FILES
+ KF_cholesky_update.h compute_jacobians.h gauss_evaluate.h pi_to_pi.h stratified_random.h
+ KF_joseph_update.h compute_steering.h get_observations.h predict.h stratified_resample.h
+ TransformToGlobal.h configfile.h line_plot_conversion.h predict_true.h
+ add_control_noise.h data_associate_known.h multivariate_gauss.h printMat.h
+ add_feature.h fastslam2_sim.h observe_heading.h resample_particles.h
+ add_observation_noise.h feature_update.h particle.h sample_proposal.h
+ DESTINATION include/fslam
+ )
+
+install(TARGETS
+ FastSLAM
+ DESTINATION lib
+ )
+
+# Add an executable that currently runs the simulator
+set(FSLAM_USED_LIBS FastSLAM)
+add_fslam_tool(fastslam_simulation main.cpp)
+
+# Add files that are just example data
+install( FILES example_webmap.mat
+ PERMISSIONS GROUP_READ OWNER_READ
+ DESTINATION bin )
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit 6422128

Please sign in to comment.