forked from mavlink/mavlink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
103 lines (84 loc) · 3.41 KB
/
Copy pathCMakeLists.txt
File metadata and controls
103 lines (84 loc) · 3.41 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
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
cmake_minimum_required(VERSION 3.13)
project(mavlink)
find_package(Python COMPONENTS Interpreter REQUIRED)
# We automatically install the pip dependencies locally below.
# Therefore, we check whether pip is available here.
execute_process(
COMMAND ${Python_EXECUTABLE} -m pip -V
RESULT_VARIABLE EXIT_CODE
OUTPUT_QUIET
)
if (NOT ${EXIT_CODE} EQUAL 0)
message(FATAL_ERROR "Python pip not found, pip is required")
endif()
if (NOT MAVLINK_DIALECT)
set(MAVLINK_DIALECT common)
endif()
message(STATUS "MAVLink dialect: ${MAVLINK_DIALECT}")
if (NOT MAVLINK_VERSION)
set(MAVLINK_VERSION 2.0)
endif()
message(STATUS "MAVLink version: ${MAVLINK_VERSION}")
# Generate both the C headers (--lang=C, produces *.h) and the C++11 headers
# (--lang=C++11, produces *.hpp). The C++11 generator also emits the C headers,
# so both examples in examples/ build against the same install.
option(MAVLINK_ENABLE_CXX "Also generate and install the C++11 (*.hpp) headers" ON)
set(EXAMPLE_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/mavlink/${MAVLINK_DIALECT}/mavlink.h)
if (MAVLINK_ENABLE_CXX)
set(GENERATE_CXX_COMMAND
COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pip-dependencies/" ${Python_EXECUTABLE}
-m pymavlink.tools.mavgen
--lang=C++11
--wire-protocol=${MAVLINK_VERSION}
--output ${CMAKE_CURRENT_BINARY_DIR}/include/mavlink/
message_definitions/v1.0/${MAVLINK_DIALECT}.xml)
endif()
add_custom_command(OUTPUT ${EXAMPLE_HEADER}
COMMAND ${Python_EXECUTABLE}
-m pip install -r pymavlink/requirements.txt --upgrade -t ${CMAKE_CURRENT_BINARY_DIR}/pip-dependencies/
COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pip-dependencies/" ${Python_EXECUTABLE}
-m pymavlink.tools.mavgen
--lang=C
--wire-protocol=${MAVLINK_VERSION}
--output ${CMAKE_CURRENT_BINARY_DIR}/include/mavlink/
message_definitions/v1.0/${MAVLINK_DIALECT}.xml
${GENERATE_CXX_COMMAND}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS message_definitions/v1.0/${MAVLINK_DIALECT}.xml
COMMENT "Generating C and C++11 headers")
# Unfortunately, the dependencies don't work for INTERFACE libraries.
# The only way I could make it work is to add ALL which means it
# will do the file generation every time even when nothing has changed.
add_custom_target(generate_c_headers
ALL
DEPENDS ${EXAMPLE_HEADER})
add_library(mavlink INTERFACE)
add_dependencies(mavlink generate_c_headers)
include(GNUInstallDirs)
target_include_directories(mavlink
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
install(TARGETS mavlink
EXPORT MAVLinkTargets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/mavlink"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp"
)
install(EXPORT MAVLinkTargets
FILE MAVLinkTargets.cmake
NAMESPACE MAVLink::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/MAVLink
)
# For the build tree
configure_file(MAVLinkConfig.cmake.in
"${PROJECT_BINARY_DIR}/MAVLinkConfig.cmake" @ONLY)
# For the install tree
configure_file(MAVLinkConfig.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/MAVLinkConfig.cmake" @ONLY)
install(FILES
"${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/MAVLinkConfig.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/MAVLink
)