-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
161 lines (136 loc) · 4.75 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
cmake_minimum_required(VERSION 3.16)
project(lgmath)
option(USE_AMENT "Use ament_cmake to build lgmath for ROS2." ON)
# Compiler setup
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(-march=native -O3 -Wall -pedantic)
## cmake flow (default)
if (NOT USE_AMENT)
set(PROJECT_VERSION 1.1.0)
# Find dependencies
find_package(Eigen3 3.3.7 REQUIRED)
# Build library
file(GLOB_RECURSE SOURCE_FILES "src/*.cpp")
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
target_include_directories(${PROJECT_NAME}
PUBLIC
${EIGEN3_INCLUDE_DIR}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Install
install(
DIRECTORY include/
DESTINATION include
)
install(
TARGETS ${PROJECT_NAME}
DESTINATION lib
EXPORT ${PROJECT_NAME}Targets
)
# Export
set(PROJECT_LIBRARY ${PROJECT_NAME})
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# export to build directory so no need to install in order to use find_package
export(
EXPORT ${PROJECT_NAME}Targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake
)
# install export cmake files
install(
EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION lib/cmake/${PROJECT_NAME}
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION lib/cmake/${PROJECT_NAME}
)
## ROS2 ament_cmake flow
else()
find_package(ament_cmake REQUIRED)
find_package(eigen3_cmake_module REQUIRED)
find_package(Eigen3 3.3.7 REQUIRED)
file(GLOB_RECURSE SOURCE src/*.cpp)
add_library(${PROJECT_NAME} ${SOURCE})
ament_target_dependencies(${PROJECT_NAME} Eigen3)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
install(
DIRECTORY include/
DESTINATION include
)
install(
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION lib/${PROJECT_NAME}
INCLUDES DESTINATION include
)
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
# Unit-tests
ament_add_gtest(so3_tests tests/SO3Tests.cpp)
target_link_libraries(so3_tests ${PROJECT_NAME})
ament_add_gtest(se3_tests tests/SE3Tests.cpp)
target_link_libraries(se3_tests ${PROJECT_NAME})
ament_add_gtest(covariance_tests tests/CovarianceTests.cpp)
target_link_libraries(covariance_tests ${PROJECT_NAME})
ament_add_gtest(rotation_tests tests/RotationTests.cpp)
target_link_libraries(rotation_tests ${PROJECT_NAME})
ament_add_gtest(transform_tests tests/TransformTests.cpp)
target_link_libraries(transform_tests ${PROJECT_NAME})
ament_add_gtest(transform_with_covariance_tests tests/TransformWithCovarianceTests.cpp)
target_link_libraries(transform_with_covariance_tests ${PROJECT_NAME})
# Benchmarks
ament_add_gtest(so3_benchmarks benchmarks/SO3SpeedTest.cpp)
target_link_libraries(so3_benchmarks ${PROJECT_NAME})
ament_add_gtest(se3_benchmarks benchmarks/SE3SpeedTest.cpp)
target_link_libraries(se3_benchmarks ${PROJECT_NAME})
ament_add_gtest(rotation_benchmarks benchmarks/RotationSpeedTest.cpp)
target_link_libraries(rotation_benchmarks ${PROJECT_NAME})
ament_add_gtest(transform_benchmarks benchmarks/TransformSpeedTest.cpp)
target_link_libraries(transform_benchmarks ${PROJECT_NAME})
ament_add_gtest(transform_with_covariance_benchmarks benchmarks/TransformWithCovarianceSpeedTest.cpp)
target_link_libraries(transform_with_covariance_benchmarks ${PROJECT_NAME})
# Linting
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies() # Lint based on linter test_depend in package.xml
endif()
endif()
# Documentation
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM)
else(DOXYGEN_FOUND)
message("Doxygen not found.")
add_custom_target(doc
COMMENT "Doxygen was not found on this system so this target does not exist, please install it and re-run CMake." VERBATIM)
endif(DOXYGEN_FOUND)
if (USE_AMENT)
ament_package()
endif()