-
Notifications
You must be signed in to change notification settings - Fork 103
/
CMakeLists.txt
130 lines (101 loc) · 4.56 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Specify the minimum version for CMake
cmake_minimum_required(VERSION 2.8.3)
# Project's name
project(inekf)
option(USE_CPP11 "Use flag -std=c++11" ON)
option(USE_MUTEX "Use mutex in code" OFF)
message("USE_CPP11: " ${USE_CPP11})
message("USE_MUTEX: " ${USE_MUTEX})
if (USE_MUTEX AND NOT USE_CPP11)
message("test")
message(FATAL_ERROR "You cannot have USE_CPP11 = OFF AND USE_MUTEX = ON")
endif (USE_MUTEX AND NOT USE_CPP11)
# Set compiler flags
if (USE_CPP11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif(USE_CPP11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DEIGEN_NO_DEBUG -march=native -Wl,--no-as-needed")
if (USE_MUTEX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DINEKF_USE_MUTEX=true")
else (USE_MUTEX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DINEKF_USE_MUTEX=false")
endif(USE_MUTEX)
SET(CMAKE_CXX_COMPILER /usr/bin/g++)
message("CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS})
unset(USE_CPP11)
unset(USE_MUTEX)
# Set the output folder where your program will be created
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
############################################
# The following folders will be included #
############################################
include_directories("${PROJECT_SOURCE_DIR}/include/")
# Threading
find_package (Threads)
# Boost
find_package(Boost 1.57 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
"${PROJECT_SOURCE_DIR}/src/*.cpp"
)
######################
# Add Execuatables #
######################
link_directories(${PROJECT_SOURCE_DIR}/${Boost_LIBRARY_DIRS})
add_executable(landmarks ${PROJECT_SOURCE_DIR}/src/examples/landmarks.cpp ${src_files})
add_executable(kinematics ${PROJECT_SOURCE_DIR}/src/examples/kinematics.cpp ${src_files})
add_executable(propagation_speed ${PROJECT_SOURCE_DIR}/src/tests/propagation_speed.cpp ${src_files})
add_executable(correction_speed ${PROJECT_SOURCE_DIR}/src/tests/correction_speed.cpp ${src_files})
target_link_libraries(landmarks ${Boost_LIBRARIES})
target_link_libraries(kinematics ${Boost_LIBRARIES})
target_link_libraries(propagation_speed ${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"
"${PROJECT_SOURCE_DIR}/src/NoiseParams.cpp"
)
set_target_properties(inekf PROPERTIES LIBRARY_OUTPUT_NAME inekf)
#=============================================
# to allow find_package() on inekf
#=============================================
#
# the following case be used in an external project requiring inekf:
# ...
# find_package(inekf)
# include_directories(${inekf_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)