mavlink: cmake generate mavlink headers at build time

- mavlink/mavlink is now directly included as a submodule instead of the generated mavlink/c_library_v2
 - this also switches to mavlink development.xml by default
This commit is contained in:
Jacob Crabill
2021-11-05 23:01:38 -04:00
committed by GitHub
parent 88489ae8bd
commit 5969508fa7
20 changed files with 71 additions and 32 deletions
+2 -2
View File
@@ -135,9 +135,9 @@ if (os.path.exists('src/lib/ecl/.git')):
# Mavlink
if (os.path.exists('mavlink/include/mavlink/v2.0/.git')):
if (os.path.exists('src/modules/mavlink/mavlink/.git')):
mavlink_git_version = subprocess.check_output('git rev-parse --verify HEAD'.split(),
cwd='mavlink/include/mavlink/v2.0', stderr=subprocess.STDOUT).decode('utf-8').strip()
cwd='src/modules/mavlink/mavlink', stderr=subprocess.STDOUT).decode('utf-8').strip()
mavlink_git_version_short = mavlink_git_version[0:16]
header += f"""
+40 -7
View File
@@ -1,6 +1,6 @@
############################################################################
#
# Copyright (c) 2015-2017 PX4 Development Team. All rights reserved.
# Copyright (c) 2015-2021 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -31,18 +31,51 @@
#
############################################################################
px4_add_git_submodule(TARGET git_mavlink_v2 PATH "${PX4_SOURCE_DIR}/mavlink/include/mavlink/v2.0")
set(MAVLINK_DIALECT "development") # standard, development, etc
# force mavlink dialect to standard if flash constrained
if(px4_constrained_flash_build)
set(MAVLINK_DIALECT "standard")
endif()
set(MAVLINK_GIT_DIR "${CMAKE_CURRENT_LIST_DIR}/mavlink")
set(MAVLINK_LIBRARY_DIR "${CMAKE_BINARY_DIR}/mavlink")
file(RELATIVE_PATH MAVLINK_GIT_DIR_RELATIVE ${CMAKE_SOURCE_DIR} ${MAVLINK_GIT_DIR})
px4_add_git_submodule(TARGET git_mavlink_v2 PATH "${MAVLINK_GIT_DIR}")
add_custom_command(
OUTPUT ${MAVLINK_LIBRARY_DIR}/${MAVLINK_DIALECT}/${MAVLINK_DIALECT}.h
COMMAND
${PYTHON_EXECUTABLE} ${MAVLINK_GIT_DIR}/pymavlink/tools/mavgen.py
--lang C --wire-protocol 2.0
#--no-validate
#--strict-units
--output ${MAVLINK_LIBRARY_DIR}
${MAVLINK_GIT_DIR}/message_definitions/v1.0/${MAVLINK_DIALECT}.xml
DEPENDS
git_mavlink_v2
${MAVLINK_GIT_DIR}/pymavlink/tools/mavgen.py
${MAVLINK_GIT_DIR}/message_definitions/v1.0/${MAVLINK_DIALECT}.xml
COMMENT "Generating Mavlink ${MAVLINK_DIALECT}: ${MAVLINK_GIT_DIR_RELATIVE}/message_definitions/v1.0/${MAVLINK_DIALECT}.xml"
USES_TERMINAL
)
add_custom_target(mavlink_c_generate DEPENDS ${MAVLINK_LIBRARY_DIR}/${MAVLINK_DIALECT}/${MAVLINK_DIALECT}.h)
# mavlink header only library
add_library(mavlink_c INTERFACE)
target_sources(mavlink_c INTERFACE ${MAVLINK_LIBRARY_DIR}/${MAVLINK_DIALECT}/${MAVLINK_DIALECT}.h)
set_source_files_properties(${MAVLINK_LIBRARY_DIR}/${MAVLINK_DIALECT}/${MAVLINK_DIALECT}.h PROPERTIES GENERATED true)
target_include_directories(mavlink_c INTERFACE ${MAVLINK_LIBRARY_DIR} ${MAVLINK_LIBRARY_DIR}/${MAVLINK_DIALECT})
target_compile_options(mavlink_c INTERFACE -Wno-address-of-packed-member -Wno-cast-align)
px4_add_module(
MODULE modules__mavlink
MAIN mavlink
COMPILE_FLAGS
-Wno-cast-align # TODO: fix and enable
-Wno-address-of-packed-member # TODO: fix in c_library_v2
-Wno-enum-compare # ROTATION <-> MAV_SENSOR_ROTATION
#-DDEBUG_BUILD
INCLUDES
${PX4_SOURCE_DIR}/mavlink/include/mavlink
SRCS
mavlink.c
mavlink_command_sender.cpp
@@ -70,9 +103,9 @@ px4_add_module(
drivers_barometer
drivers_gyroscope
drivers_magnetometer
git_mavlink_v2
conversion
geo
mavlink_c
version
UNITY_BUILD
)
+2 -2
View File
@@ -61,7 +61,7 @@
# define MAVLINK_COMM_5 static_cast<mavlink_channel_t>(5)
#endif
#include <v2.0/mavlink_types.h>
#include <mavlink_types.h>
#include <unistd.h>
__BEGIN_DECLS
@@ -92,7 +92,7 @@ void mavlink_end_uart_send(mavlink_channel_t chan, int length);
extern mavlink_status_t *mavlink_get_channel_status(uint8_t chan);
extern mavlink_message_t *mavlink_get_channel_buffer(uint8_t chan);
#include <v2.0/standard/mavlink.h>
#include <mavlink.h>
__END_DECLS
+1 -1
View File
@@ -48,7 +48,7 @@
#ifndef MAVLINK_FTP_UNIT_TEST
#include "mavlink_main.h"
#else
#include <v2.0/standard/mavlink.h>
#include <mavlink.h>
#endif
using namespace time_literals;
+1 -1
View File
@@ -46,7 +46,7 @@
#ifndef MAVLINK_FTP_UNIT_TEST
#include "mavlink_bridge_header.h"
#else
#include <v2.0/standard/mavlink.h>
#include <mavlink.h>
#endif
class MavlinkFtpTest;
@@ -31,12 +31,13 @@
#
############################################################################
include_directories(${PX4_SOURCE_DIR}/mavlink/include/mavlink)
px4_add_module(
MODULE modules__mavlink__mavlink_tests
MAIN mavlink_tests
STACK_MAIN 8192
INCLUDES
${CMAKE_BINARY_DIR}/mavlink
${CMAKE_BINARY_DIR}/mavlink/common
COMPILE_FLAGS
-DMAVLINK_FTP_UNIT_TEST
#-DMAVLINK_FTP_DEBUG
@@ -40,7 +40,7 @@
#ifndef MAVLINK_FTP_UNIT_TEST
#include "../mavlink_bridge_header.h"
#else
#include <v2.0/standard/mavlink.h>
#include <mavlink.h>
#endif
#include "../mavlink_ftp.h"
+4 -3
View File
@@ -55,12 +55,13 @@ px4_add_module(
-Wno-cast-align
-Wno-address-of-packed-member # TODO: fix in c_library_v2
INCLUDES
${PX4_SOURCE_DIR}/mavlink/include/mavlink
${CMAKE_BINARY_DIR}/mavlink
${CMAKE_BINARY_DIR}/mavlink/development
SRCS
simulator.cpp
simulator_mavlink.cpp
DEPENDS
git_mavlink_v2
mavlink_c_generate
conversion
geo
drivers_accelerometer
@@ -68,6 +69,6 @@ px4_add_module(
drivers_gyroscope
drivers_magnetometer
)
target_include_directories(modules__simulator INTERFACE ${PX4_SOURCE_DIR}/mavlink/include/mavlink)
target_include_directories(modules__simulator INTERFACE ${CMAKE_BINARY_DIR}/mavlink)
add_subdirectory(battery_simulator)
+2 -2
View File
@@ -76,8 +76,8 @@
#include <random>
#include <v2.0/common/mavlink.h>
#include <v2.0/mavlink_types.h>
#include <mavlink.h>
#include <mavlink_types.h>
using namespace time_literals;