Skip to content

Commit

Permalink
mavlink: cmake generate mavlink headers at build time
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
JacobCrabill authored Nov 6, 2021
1 parent 88489ae commit 5969508
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 32 deletions.
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "mavlink/include/mavlink/v2.0"]
path = mavlink/include/mavlink/v2.0
url = https://github.com/mavlink/c_library_v2.git
[submodule "src/modules/mavlink/mavlink"]
path = src/modules/mavlink/mavlink
url = https://github.com/mavlink/mavlink.git
branch = master
[submodule "src/drivers/uavcan/libuavcan"]
path = src/drivers/uavcan/libuavcan
Expand Down Expand Up @@ -65,7 +65,7 @@
url = https://github.com/mavlink/libevents.git
[submodule "Tools/simulation-ignition"]
path = Tools/simulation-ignition
url = https://github.com/Auterion/px4-simulation-ignition.git
url = https://github.com/PX4/px4-simulation-ignition.git
[submodule "src/lib/crypto/libtomcrypt"]
path = src/lib/crypto/libtomcrypt
url = https://github.com/PX4/libtomcrypt.git
Expand Down
1 change: 1 addition & 0 deletions Tools/astyle/files_to_check_code_style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exec find boards msg src platforms test \
-path src/lib/parameters/uthash -prune -o \
-path src/modules/ekf2/EKF -prune -o \
-path src/modules/gyro_fft/CMSIS_5 -prune -o \
-path src/modules/mavlink/mavlink -prune -o \
-path src/modules/micrortps_bridge/micro-CDR -prune -o \
-path src/modules/micrortps_bridge/microRTPS_client -prune -o \
-path test/mavsdk_tests/catch2 -prune -o \
Expand Down
2 changes: 1 addition & 1 deletion Tools/flightgear_bridge
2 changes: 1 addition & 1 deletion Tools/jsbsim_bridge
1 change: 1 addition & 0 deletions Tools/setup/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ empy>=3.3
jinja2>=2.8
jsonschema
kconfiglib
lxml
matplotlib>=3.0.*
numpy>=1.13
nunavut>=1.1.0
Expand Down
2 changes: 2 additions & 0 deletions Tools/setup/ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends i
gdb \
git \
lcov \
libxml2-dev \
libxml2-utils \
make \
ninja-build \
python3 \
Expand Down
2 changes: 1 addition & 1 deletion Tools/sitl_gazebo
4 changes: 2 additions & 2 deletions cmake/px4_add_module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function(px4_add_module)
# as well as interface include and libraries
foreach(dep ${DEPENDS})
get_target_property(dep_type ${dep} TYPE)
if (${dep_type} STREQUAL "STATIC_LIBRARY")
if((${dep_type} STREQUAL "STATIC_LIBRARY") OR (${dep_type} STREQUAL "INTERFACE_LIBRARY"))
target_link_libraries(${MODULE}_original PRIVATE ${dep})
else()
add_dependencies(${MODULE}_original ${dep})
Expand Down Expand Up @@ -205,7 +205,7 @@ function(px4_add_module)
# as well as interface include and libraries
foreach(dep ${DEPENDS})
get_target_property(dep_type ${dep} TYPE)
if (${dep_type} STREQUAL "STATIC_LIBRARY")
if((${dep_type} STREQUAL "STATIC_LIBRARY") OR (${dep_type} STREQUAL "INTERFACE_LIBRARY"))
target_link_libraries(${MODULE} PRIVATE ${dep})
else()
add_dependencies(${MODULE} ${dep})
Expand Down
1 change: 0 additions & 1 deletion mavlink/include/mavlink/v2.0
Submodule v2.0 deleted from 5571ff
4 changes: 2 additions & 2 deletions src/lib/version/px_update_git_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@


# 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"""
Expand Down
47 changes: 40 additions & 7 deletions src/modules/mavlink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -70,9 +103,9 @@ px4_add_module(
drivers_barometer
drivers_gyroscope
drivers_magnetometer
git_mavlink_v2
conversion
geo
mavlink_c
version
UNITY_BUILD
)
Expand Down
1 change: 1 addition & 0 deletions src/modules/mavlink/mavlink
Submodule mavlink added at 3718ee
4 changes: 2 additions & 2 deletions src/modules/mavlink/mavlink_bridge_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/modules/mavlink/mavlink_ftp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mavlink/mavlink_ftp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/modules/mavlink/mavlink_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mavlink/mavlink_tests/mavlink_ftp_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 4 additions & 3 deletions src/modules/simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@ 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
drivers_barometer
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)
4 changes: 2 additions & 2 deletions src/modules/simulator/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 5969508

Please sign in to comment.