mavlink: with cmake policy CMP0118 verion 3.20 we can depend on the mavlink_c library instead of including its content in multiple places

This works because the policy now allows to have the generated property available in other places than the library directory itself. Are we ready for cmake 3.20? Then we should increase the minimum version instead of just enabling the policy in a few files.
This commit is contained in:
Matthias Grob 2024-06-21 15:37:07 +02:00
parent 6e27db9490
commit baace65379
4 changed files with 8 additions and 16 deletions

View File

@ -31,6 +31,9 @@
#
############################################################################
# Make GENERATED property available outside of this directory e.g. for simulator_mavlink and mavlink_tests which depend on mavlink_c
cmake_policy(SET CMP0118 NEW)
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})
@ -78,11 +81,9 @@ add_custom_command(
COMMENT "Generating Mavlink ${CONFIG_MAVLINK_DIALECT}: ${MAVLINK_GIT_DIR_RELATIVE}/message_definitions/v1.0/${CONFIG_MAVLINK_DIALECT}.xml"
)
add_custom_target(mavlink_c_generate DEPENDS ${MAVLINK_LIBRARY_DIR}/${CONFIG_MAVLINK_DIALECT}/${CONFIG_MAVLINK_DIALECT}.h)
set_source_files_properties(${MAVLINK_LIBRARY_DIR}/${CONFIG_MAVLINK_DIALECT}/${CONFIG_MAVLINK_DIALECT}.h PROPERTIES GENERATED true)
# mavlink header only library
add_library(mavlink_c INTERFACE)
target_compile_options(mavlink_c INTERFACE -Wno-address-of-packed-member -Wno-cast-align)

View File

@ -93,9 +93,7 @@ extern mavlink_status_t *mavlink_get_channel_status(uint8_t chan);
extern mavlink_message_t *mavlink_get_channel_buffer(uint8_t chan);
#include <mavlink.h>
#if !MAVLINK_FTP_UNIT_TEST
#include <uAvionix.h>
#endif
__END_DECLS

View File

@ -35,16 +35,12 @@ px4_add_module(
MODULE modules__mavlink__mavlink_tests
MAIN mavlink_tests
STACK_MAIN 8192
INCLUDES
${MAVLINK_LIBRARY_DIR}
${MAVLINK_LIBRARY_DIR}/${CONFIG_MAVLINK_DIALECT}
COMPILE_FLAGS
-DMAVLINK_FTP_UNIT_TEST
#-DMAVLINK_FTP_DEBUG
-DMavlinkStream=MavlinkStreamTest
-DMavlinkFTP=MavlinkFTPTest
-Wno-cast-align # TODO: fix and enable
-Wno-address-of-packed-member # TODO: fix in c_library_v2
-Wno-double-promotion # The fix has been proposed as PR upstream (2020-03-08)
SRCS
mavlink_tests.cpp
@ -52,5 +48,5 @@ px4_add_module(
../mavlink_stream.cpp
../mavlink_ftp.cpp
DEPENDS
mavlink_c_generate
mavlink_c
)

View File

@ -31,23 +31,20 @@
#
############################################################################
# Make GENERATED property from mavlink_c available
cmake_policy(SET CMP0118 NEW)
px4_add_module(
MODULE modules__simulation__simulator_mavlink
MAIN simulator_mavlink
COMPILE_FLAGS
-Wno-double-promotion
-Wno-cast-align
-Wno-address-of-packed-member # TODO: fix in c_library_v2
INCLUDES
${CMAKE_BINARY_DIR}/mavlink
${CMAKE_BINARY_DIR}/mavlink/development
${CMAKE_BINARY_DIR}/mavlink/common
${CMAKE_BINARY_DIR}/mavlink/standard
SRCS
SimulatorMavlink.cpp
SimulatorMavlink.hpp
DEPENDS
mavlink_c_generate
mavlink_c
conversion
geo
drivers_accelerometer