-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
200 lines (172 loc) · 5.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
cmake_minimum_required(VERSION 3.15)
project(last_letter_lib VERSION 2.1.0)
# Set compiler standards
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
# Configure compile options
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# Find dependences
# find_package(ament_cmake REQUIRED)
find_package(Eigen3 REQUIRED NO_MODULE)
# include(FindEigen3.cmake)
find_package(LAPACK REQUIRED)
# find_package(NLopt REQUIRED) # Will enable later with trimmer
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
message(STATUS "Current Python site-packages dir: ${Python3_SITELIB}")
find_package(pybind11 PATHS ${Python3_SITELIB}/pybind11/share/cmake/pybind11 CONFIG REQUIRED)
# add_subdirectory(external/pybind11)
# Declare and compile the yaml-cpp project
include(ExternalProject)
ExternalProject_Add(ext-yaml-cpp
SOURCE_DIR ${CMAKE_SOURCE_DIR}/external/yaml-cpp
CMAKE_ARGS "-DYAML_CPP_BUILD_TESTS=OFF"
"-DYAML_CPP_BUILD_TOOLS=OFF"
"-DBUILD_SHARED_LIBS=ON"
INSTALL_COMMAND "" # Do not install in system, library needed only locally
USES_TERMINAL_BUILD true
)
# Construct include directories path
ExternalProject_Get_Property(ext-yaml-cpp SOURCE_DIR) # Access the source directory
set(YAML_CPP_INCLUDE_DIR ${SOURCE_DIR}/include) # Aggregate headers to variable
message(STATUS "YAML_CPP_INCLUDE_DIR set to ${YAML_CPP_INCLUDE_DIR}")
# Expose built library
add_library(yaml-cpp SHARED IMPORTED) # Declare the shared library
ExternalProject_Get_Property(ext-yaml-cpp BINARY_DIR) # Access the binaries location
set_target_properties(yaml-cpp PROPERTIES
IMPORTED_LOCATION ${BINARY_DIR}/libyaml-cpp.so # Attach the .so file to the library
INTERFACE_INCLUDE_DIRECTORIES ${YAML_CPP_INCLUDE_DIR}
)
add_dependencies(yaml-cpp ext-yaml-cpp) # Declare a dependency on the 3rd party project, just in case
set(YAML_CPP_LIBRARIES yaml-cpp) # Aggregate all libraries to variable
message(STATUS "yaml-cpp library (YAML_CPP_LIBRARIES) found at ${YAML_CPP_LIBRARIES}")
include_directories(
include
${EIGEN3_INCLUDE_DIRS}
${LAPACK_INCLUDE_DIRS}
${NLOPT_INCLUDE_DIRS}
# "/usr/local/include" # Used to include nlopt
${YAML_CPP_INCLUDE_DIR}
)
# Declare the project library
add_library(last_letter_lib SHARED
src/math_utils.cpp
src/uav_utils.cpp
src/geo_mag_declination.cpp
src/prog_utils.cpp
src/systems.cpp
src/environment.cpp
src/gravity.cpp
src/aerodynamics.cpp
src/propulsion/propulsion.cpp
src/ground_reaction/ground_reaction.cpp
src/link.cpp
src/dynamics.cpp
src/kinematics.cpp
src/sensors.cpp
src/uav_model.cpp
)
target_link_libraries(last_letter_lib
Eigen3::Eigen
${LAPACK_LIBRARIES}
${YAML_CPP_LIBRARIES}
)
# add_library(lib_trimmer src/trimmer.cpp)
# target_link_libraries(lib_trimmer
# ${NLOPT_LIBRARIES}
# lib_uav_model)
list(APPEND pybind11_sources
src/python_api.cpp
)
pybind11_add_module(cpp_last_letter_lib ${pybind11_sources})
target_link_libraries(cpp_last_letter_lib PRIVATE last_letter_lib)
# Copy data files to home folder
# file(COPY last_letter_models DESTINATION $ENV{HOME}) # Deprecated, using new models folder
file(COPY models DESTINATION $ENV{HOME}/last_letter_models)
file(COPY last_letter_models/HID.yaml DESTINATION $ENV{HOME}/last_letter_models)
# Export the header files for use by consumers of the library
# ament_export_include_directories(include) # Unnecessary according to https://index.ros.org/doc/ros2/Tutorials/Ament-CMake-Documentation/#building-a-library
# Export the library binaries themselves
# ament_export_libraries(
# last_letter_lib
# ) # Unnecessary according to https://index.ros.org/doc/ros2/Tutorials/Ament-CMake-Documentation/#building-a-library
# # Export the libraries
# ament_export_targets(
# export_last_letterlib HAS_LIBRARY_TARGET
# )
# # Declare dependencies of this library to its consumers
# ament_export_dependencies(
# Eigen3
# LAPACK
# )
# Compile test files
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.13.0.zip
)
FetchContent_MakeAvailable(googletest)
enable_testing()
list(APPEND test_sources
tests/cpp/test_utils.cpp
tests/cpp/test_prog_utils.cpp
tests/cpp/test_uav_utils.cpp
tests/cpp/test_math_utils.cpp
tests/cpp/test_systems.cpp
tests/cpp/test_environment.cpp
tests/cpp/test_aerodynamics.cpp
tests/cpp/test_propulsion.cpp
tests/cpp/test_gravity.cpp
tests/cpp/test_dynamics.cpp
tests/cpp/test_uav_model.cpp
# tests/cpp/test_pybind.cpp
)
add_executable(all_tests ${test_sources})
target_include_directories(all_tests PUBLIC
tests/cpp
)
target_link_libraries(all_tests
GTest::gtest_main
${YAML_CPP_LIBRARIES}
last_letter_lib
)
# Perhaps copy over the test data to the build folder?
include(GoogleTest)
gtest_discover_tests(all_tests)
# # the following line skips the linter which checks for copyrights
# # uncomment the line when a copyright and license is not present in all source files
# #set(ament_cmake_copyright_FOUND TRUE)
# # the following line skips cpplint (only works in a git repo)
# # uncomment the line when this package is not in a git repo
# #set(ament_cmake_cpplint_FOUND TRUE)
# install(DIRECTORY tests/cpp/test_parameters DESTINATION share/${PROJECT_NAME})
# endif()
install(
DIRECTORY include/ DESTINATION include
)
list(APPEND exported_libs
last_letter_lib
)
install(
TARGETS ${exported_libs}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
EXPORT last_letter_lib_targets
)
# install(
# TARGETS last_letter_lib
# EXPORT export_last_letter_lib
# LIBRARY DESTINATION lib
# ARCHIVE DESTINATION lib
# RUNTIME DESTINATION bin
# INCLUDES DESTINATION include
# )