-
Notifications
You must be signed in to change notification settings - Fork 217
/
CMakeLists.txt
166 lines (158 loc) · 5.47 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
# v3.14 required for FetchContent_MakeAvailable
cmake_minimum_required(VERSION 3.14)
if (DEFINED MCU)
include(FetchContent)
FetchContent_Declare(
mcu_support
GIT_REPOSITORY https://github.com/bolderflight/mcu-support.git
GIT_TAG v1.1.0
)
FetchContent_MakeAvailable(mcu_support)
# Setting up the toolchain
set(CMAKE_TOOLCHAIN_FILE "${mcu_support_SOURCE_DIR}/cmake/cortex.cmake")
# Project information
project(InvensenseImu
VERSION 6.0.3
DESCRIPTION "Invensense IMU sensor driver"
LANGUAGES CXX
)
# Grab the processor and set up definitions and compile options
include(${mcu_support_SOURCE_DIR}/cmake/config_mcu.cmake)
configMcu(${MCU} ${mcu_support_SOURCE_DIR})
# Fetch core
FetchContent_Declare(
core
GIT_REPOSITORY https://github.com/bolderflight/core.git
GIT_TAG v3.1.3
)
FetchContent_MakeAvailable(core)
# Add the library target
add_library(invensense_imu
src/invensense_imu.cpp
src/invensense_imu.h
src/mpu9250.cpp
src/mpu9250.h
src/mpu6500.cpp
src/mpu6500.h
)
# Link libraries
target_link_libraries(invensense_imu
PUBLIC
core
)
# Setup include directories
target_include_directories(invensense_imu PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>
)
# Example and test if this project is built separately
if (PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME)
### MPU-6500
# Add the spi example target
add_executable(mpu6500_spi_example examples/cmake/mpu6500/spi.cc)
# Add the includes
target_include_directories(mpu6500_spi_example PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Link libraries to the example target
target_link_libraries(mpu6500_spi_example
PRIVATE
invensense_imu
)
# Add hex and upload targets
include(${mcu_support_SOURCE_DIR}/cmake/flash_mcu.cmake)
FlashMcu(mpu6500_spi_example ${MCU} ${mcu_support_SOURCE_DIR})
# Add the i2c example target
add_executable(mpu6500_i2c_example examples/cmake/mpu6500/i2c.cc)
# Add the includes
target_include_directories(mpu6500_i2c_example PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Link libraries to the example target
target_link_libraries(mpu6500_i2c_example
PRIVATE
invensense_imu
)
# Add hex and upload targets
include(${mcu_support_SOURCE_DIR}/cmake/flash_mcu.cmake)
FlashMcu(mpu6500_i2c_example ${MCU} ${mcu_support_SOURCE_DIR})
# Add the drdy interrupt example
add_executable(mpu6500_drdy_spi_example examples/cmake/mpu6500/drdy_spi.cc)
# Add the includes
target_include_directories(mpu6500_drdy_spi_example PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Link libraries to the example target
target_link_libraries(mpu6500_drdy_spi_example
PRIVATE
invensense_imu
)
# Add hex and upload targets
include(${mcu_support_SOURCE_DIR}/cmake/flash_mcu.cmake)
FlashMcu(mpu6500_drdy_spi_example ${MCU} ${mcu_support_SOURCE_DIR})
### MPU-9250
# Add the spi example target
add_executable(mpu9250_spi_example examples/cmake/mpu9250/spi.cc)
# Add the includes
target_include_directories(mpu9250_spi_example PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Link libraries to the example target
target_link_libraries(mpu9250_spi_example
PRIVATE
invensense_imu
)
# Add hex and upload targets
include(${mcu_support_SOURCE_DIR}/cmake/flash_mcu.cmake)
FlashMcu(mpu9250_spi_example ${MCU} ${mcu_support_SOURCE_DIR})
# Add the i2c example target
add_executable(mpu9250_i2c_example examples/cmake/mpu9250/i2c.cc)
# Add the includes
target_include_directories(mpu9250_i2c_example PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Link libraries to the example target
target_link_libraries(mpu9250_i2c_example
PRIVATE
invensense_imu
)
# Add hex and upload targets
include(${mcu_support_SOURCE_DIR}/cmake/flash_mcu.cmake)
FlashMcu(mpu9250_i2c_example ${MCU} ${mcu_support_SOURCE_DIR})
# Add the drdy interrupt example
add_executable(mpu9250_drdy_spi_example examples/cmake/mpu9250/drdy_spi.cc)
# Add the includes
target_include_directories(mpu9250_drdy_spi_example PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Link libraries to the example target
target_link_libraries(mpu9250_drdy_spi_example
PRIVATE
invensense_imu
)
# Add hex and upload targets
include(${mcu_support_SOURCE_DIR}/cmake/flash_mcu.cmake)
FlashMcu(mpu9250_drdy_spi_example ${MCU} ${mcu_support_SOURCE_DIR})
# Add the wom example
add_executable(mpu9250_wom_example examples/cmake/mpu9250/wom_i2c.cc)
# Add the includes
target_include_directories(mpu9250_wom_example PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Link libraries to the example target
target_link_libraries(mpu9250_wom_example
PRIVATE
invensense_imu
)
# Add hex and upload targets
include(${mcu_support_SOURCE_DIR}/cmake/flash_mcu.cmake)
FlashMcu(mpu9250_wom_example ${MCU} ${mcu_support_SOURCE_DIR})
endif()
endif()