FindMAVLink.cmake
1.97 KB
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
# - Try to find MAVLink
# Once done, this will define
#
# MAVLINK_FOUND : library found
# MAVLINK_INCLUDE_DIRS : include directories
# MAVLINK_VERSION : version
##
# This file was compied form jsbsim_bridge submodule of PX4/Firmware
##
# macros
include(FindPackageHandleStandardArgs)
# Check for ROS_DISTRO
find_program(ROSVERSION rosversion)
execute_process(COMMAND ${ROSVERSION} -d
OUTPUT_VARIABLE ROS_DISTRO
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(_MAVLINK_EXTRA_SEARCH_HINTS
${CMAKE_SOURCE_DIR}/mavlink/
../../mavlink/
../mavlink/
${CATKIN_DEVEL_PREFIX}/
)
set(_MAVLINK_EXTRA_SEARCH_PATHS
/usr/
/usr/local/
)
# look for in the hints first
find_path(_MAVLINK_INCLUDE_DIR
NAMES mavlink/v1.0/mavlink_types.h mavlink/v2.0/mavlink_types.h
PATH_SUFFIXES include
HINTS ${_MAVLINK_EXTRA_SEARCH_HINTS}
NO_DEFAULT_PATH
)
# look for in the hard-coded paths
find_path(_MAVLINK_INCLUDE_DIR
NAMES mavlink/v1.0/mavlink_types.h mavlink/v2.0/mavlink_types.h
PATH_SUFFIXES include
PATHS ${_MAVLINK_EXTRA_SEARCH_PATHS}
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
)
# look specifically for the ROS version if no other was found
find_path(_MAVLINK_INCLUDE_DIR
NAMES mavlink/v1.0/mavlink_types.h mavlink/v2.0/mavlink_types.h
PATH_SUFFIXES include
PATHS /opt/ros/${ROS_DISTRO}/
)
# read the version
if (EXISTS ${_MAVLINK_INCLUDE_DIR}/mavlink/config.h)
file(READ ${_MAVLINK_INCLUDE_DIR}/mavlink/config.h MAVLINK_CONFIG_FILE)
string(REGEX MATCH "#define MAVLINK_VERSION[ ]+\"(([0-9]+\\.)+[0-9]+)\""
_MAVLINK_VERSION_MATCH "${MAVLINK_CONFIG_FILE}")
set(MAVLINK_VERSION "${CMAKE_MATCH_1}")
else()
set(MAVLINK_VERSION "2.0")
endif()
# handle arguments
set(MAVLINK_INCLUDE_DIRS ${_MAVLINK_INCLUDE_DIR})
find_package_handle_standard_args(
MAVLink
REQUIRED_VARS MAVLINK_INCLUDE_DIRS MAVLINK_VERSION
VERSION_VAR MAVLINK_VERSION
)