From c891229d08efde647ae589a5cff1db14015d8f0e Mon Sep 17 00:00:00 2001 From: RossHartley Date: Thu, 13 Sep 2018 18:21:25 -0400 Subject: [PATCH] Added export(PACKAGE ...) to CMakeLists.txt so that we can run find_package(inekf) in the ROS wrapper --- CMakeLists.txt | 62 +++++++++++++++++++++++++++++++-- include/InEKF.h | 5 +-- include/LieGroup.h | 3 ++ include/RobotState.h | 3 ++ inekfConfig.cmake.in | 13 +++++++ src/InEKF.cpp | 8 +++-- src/LieGroup.cpp | 5 +++ src/RobotState.cpp | 7 +++- src/examples/landmarks.cpp | 1 + src/tests/correction_speed.cpp | 1 + src/tests/propagation_speed.cpp | 1 + 11 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 inekfConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index e7ac330..8fbecbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,9 +11,11 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DEIGEN_NO_DEBUG -march=native -Wl,- project(inekf) # Set the output folder where your program will be created -set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) -set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) -set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) +#set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) +#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) +#set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) ############################################ # The following folders will be included # @@ -26,10 +28,12 @@ find_package (Threads) # Boost find_package(Boost 1.58 REQUIRED COMPONENTS system) include_directories(${Boost_INCLUDE_DIR}) +message("Boost_INCLUDE_DIR: " ${Boost_INCLUDE_DIR}) # Eigen find_package(Eigen3 REQUIRED) include_directories(${EIGEN3_INCLUDE_DIR}) +message("EIGEN3_INCLUDE_DIR: " ${EIGEN3_INCLUDE_DIR}) # Adding all classes file(GLOB src_files @@ -48,6 +52,58 @@ add_executable(correction_speed ${PROJECT_SOURCE_DIR}/src/tests/correction_speed target_link_libraries(landmarks ${Boost_LIBRARIES}) target_link_libraries(correction_speed ${Boost_LIBRARIES}) +# Create Library +add_library(inekf SHARED + "${PROJECT_SOURCE_DIR}/src/InEKF.cpp" + "${PROJECT_SOURCE_DIR}/src/RobotState.cpp" + "${PROJECT_SOURCE_DIR}/src/LieGroup.cpp" +) +set_target_properties(inekf PROPERTIES LIBRARY_OUTPUT_NAME inekf) + + + +#============================================= +# to allow find_package() on kindr +#============================================= +# +# the following case be used in an external project requiring kindr: +# ... +# find_package(kindr) +# include_directories(${kindr_INCLUDE_DIRS}) +# ... + +# NOTE: the following will support find_package for 1) local build (make) and 2) for installed files (make install) + +# 1- local build # + +# Register the local build in case one doesn't use "make install" +export(PACKAGE inekf) + +# Create variable for the local build tree +#set_target_properties(inekf PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) +get_property(inekf_include_dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) +get_property(inekf_library_dirs TARGET inekf PROPERTY LIBRARY_OUTPUT_DIRECTORY) +get_property(inekf_libraries TARGET inekf PROPERTY LIBRARY_OUTPUT_NAME) + +message("inekf_include_dirs: " ${inekf_include_dirs}) +message("inekf_library_dirs: " ${inekf_library_dirs}) +message("inekf_libraries: " ${inekf_libraries}) + +# Configure config file for local build tree +configure_file(inekfConfig.cmake.in + "${PROJECT_BINARY_DIR}/inekfConfig.cmake" @ONLY) + +message("PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR}) + +# # 2- installation build # +# # Change the include location for the case of an install location +# set(inekf_include_dirs ${CMAKE_INSTALL_PREFIX}/include ${EIGEN_INCLUDE_DIR}) +# # We put the generated file for installation in a different repository (i.e., ./CMakeFiles/) +# configure_file(inekfConfig.cmake.in +# "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/inekfConfig.cmake" @ONLY) +# install(FILES +# "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/inekfConfig.cmake" +# DESTINATION share/inekf/cmake COMPONENT dev) diff --git a/include/InEKF.h b/include/InEKF.h index 140c206..603d1c7 100644 --- a/include/InEKF.h +++ b/include/InEKF.h @@ -9,6 +9,8 @@ #include "RobotState.h" #include "LieGroup.h" +namespace inekf { + typedef std::map,Eigen::aligned_allocator>> mapIntVector3d; typedef std::vector> vectorPairIntVector3d; @@ -93,6 +95,5 @@ class InEKF { std::map estimated_landmarks_; }; - - +} // end inekf namespace #endif diff --git a/include/LieGroup.h b/include/LieGroup.h index caaf968..3d037b4 100644 --- a/include/LieGroup.h +++ b/include/LieGroup.h @@ -3,6 +3,8 @@ #include #include +namespace inekf { + #define TOLERANCE 1e-10 Eigen::Matrix3d skew(const Eigen::Vector3d& v); @@ -10,4 +12,5 @@ Eigen::Matrix3d Exp_SO3(const Eigen::Vector3d& w); Eigen::MatrixXd Exp_SEK3(const Eigen::VectorXd& v); Eigen::MatrixXd Adjoint_SEK3(const Eigen::MatrixXd& X); +} // end inekf namespace #endif diff --git a/include/RobotState.h b/include/RobotState.h index dfe6c3e..1e943d0 100644 --- a/include/RobotState.h +++ b/include/RobotState.h @@ -3,6 +3,8 @@ #include #include +namespace inekf { + class RobotState { public: @@ -44,4 +46,5 @@ class RobotState { }; +} // end inekf namespace #endif diff --git a/inekfConfig.cmake.in b/inekfConfig.cmake.in new file mode 100644 index 0000000..fc312a6 --- /dev/null +++ b/inekfConfig.cmake.in @@ -0,0 +1,13 @@ +# - Config file for the inekf package +# It defines the following variables +# inekf_INCLUDE_DIRS - include directories for inekf +# inekf_LIBRARY_DIRS - directories for inekf library + +# Compute paths +get_filename_component(inekf_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(inekf_INCLUDE_DIRS "@inekf_include_dirs@") +set(inekf_LIBRARY_DIRS "@inekf_library_dirs@") +set(inekf_LIBRARIES "@inekf_libraries@") + +# This causes catkin_simple to link against these libraries +set(inekf_FOUND_CATKIN_PROJECT true) \ No newline at end of file diff --git a/src/InEKF.cpp b/src/InEKF.cpp index 0d5c09f..f5b38f2 100644 --- a/src/InEKF.cpp +++ b/src/InEKF.cpp @@ -1,6 +1,8 @@ #include "InEKF.h" -using namespace std; +namespace inekf { + +using namespace std; // ------------ NoiseParams ------------- // Default Constructor @@ -333,4 +335,6 @@ void InEKF::CorrectLandmarks(const vectorPairIntVector3d& measured_landmarks) { } return; -} \ No newline at end of file +} + +} // end inekf namespace \ No newline at end of file diff --git a/src/LieGroup.cpp b/src/LieGroup.cpp index e48d3ec..03d3695 100644 --- a/src/LieGroup.cpp +++ b/src/LieGroup.cpp @@ -1,4 +1,7 @@ #include "LieGroup.h" + +namespace inekf { + using namespace std; Eigen::Matrix3d skew(const Eigen::Vector3d& v) { @@ -62,3 +65,5 @@ Eigen::MatrixXd Adjoint_SEK3(const Eigen::MatrixXd& X) { } return Adj; } + +} // end inekf namespace \ No newline at end of file diff --git a/src/RobotState.cpp b/src/RobotState.cpp index 5482da3..9ff4c34 100644 --- a/src/RobotState.cpp +++ b/src/RobotState.cpp @@ -1,5 +1,8 @@ #include "RobotState.h" #include "LieGroup.h" + +namespace inekf { + using namespace std; // Default constructor @@ -62,4 +65,6 @@ ostream& operator<<(ostream& os, const RobotState& s) { os << "P:\n" << s.P_ << endl; os << "-----------------------------------"; return os; -} \ No newline at end of file +} + +} // end inekf namespace \ No newline at end of file diff --git a/src/examples/landmarks.cpp b/src/examples/landmarks.cpp index d6e8ff5..80407a7 100644 --- a/src/examples/landmarks.cpp +++ b/src/examples/landmarks.cpp @@ -9,6 +9,7 @@ #define DT_MAX 1 using namespace std; +using namespace inekf; int main() { diff --git a/src/tests/correction_speed.cpp b/src/tests/correction_speed.cpp index 3496b47..e958156 100644 --- a/src/tests/correction_speed.cpp +++ b/src/tests/correction_speed.cpp @@ -13,6 +13,7 @@ #define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT using namespace std; +using namespace inekf; typedef vector>> vectorPairIntVector6d; diff --git a/src/tests/propagation_speed.cpp b/src/tests/propagation_speed.cpp index 2c3a10f..c673cf6 100644 --- a/src/tests/propagation_speed.cpp +++ b/src/tests/propagation_speed.cpp @@ -12,6 +12,7 @@ #define DT_MAX 1 using namespace std; +using namespace inekf; typedef vector>> vectorPairIntVector6d;