Overlaid patches from 'patch'
This commit is contained in:
252
CMakeLists.txt
252
CMakeLists.txt
@@ -1,87 +1,185 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
cmake_minimum_required (VERSION 3.5)
|
||||
project (mavlink NONE)
|
||||
|
||||
project(mavlink)
|
||||
# Note: patched version for installation as ROS 3-rd party library
|
||||
# Provides C-headers and C++11
|
||||
|
||||
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}")
|
||||
|
||||
set(EXAMPLE_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/mavlink/${MAVLINK_DIALECT}/mavlink.h)
|
||||
|
||||
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
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS message_definitions/v1.0/${MAVLINK_DIALECT}.xml
|
||||
COMMENT "Generating C 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)
|
||||
# settings
|
||||
set(PROJECT_VERSION_MAJOR "1")
|
||||
set(PROJECT_VERSION_MINOR "0")
|
||||
set(PROJECT_VERSION_PATCH "9")
|
||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||
set(PROJECT_CONTACT_EMAIL http://groups.google.com/group/mavlink)
|
||||
set(PROJECT_CONTACT_VENDOR mavlink)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
target_include_directories(mavlink
|
||||
INTERFACE
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
# hack from urdfdom: by default this would be 'lib/x86_64-linux-gnu'
|
||||
set(CMAKE_INSTALL_LIBDIR lib)
|
||||
|
||||
install(TARGETS mavlink
|
||||
EXPORT MAVLinkTargets
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
if (DEFINED ENV{ROS_PYTHON_VERSION})
|
||||
set(Py_VERSION $ENV{ROS_PYTHON_VERSION})
|
||||
else()
|
||||
message(WARNING "ENV ROS_PYTHON_VERSION is not set. Use default: 3")
|
||||
set(Py_VERSION "3")
|
||||
endif()
|
||||
|
||||
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/mavlink"
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
)
|
||||
if (NOT CMAKE_VERSION VERSION_LESS "3.12")
|
||||
find_package(Python${Py_VERSION} COMPONENTS Interpreter)
|
||||
set(Python_EXECUTABLE "${Python${Py_VERSION}_EXECUTABLE}")
|
||||
else()
|
||||
# find libraries with cmake modules
|
||||
find_package(PythonInterp ${Py_VERSION} REQUIRED)
|
||||
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
|
||||
endif()
|
||||
|
||||
install(EXPORT MAVLinkTargets
|
||||
FILE MAVLinkTargets.cmake
|
||||
NAMESPACE MAVLink::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/MAVLink
|
||||
)
|
||||
message(STATUS "Python ${Py_VERSION} iterpretator: ${Python_EXECUTABLE}")
|
||||
|
||||
# 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)
|
||||
# Try to read package version from package.xml
|
||||
if(EXISTS ${CMAKE_SOURCE_DIR}/package.xml)
|
||||
file(WRITE ${CMAKE_BINARY_DIR}/package_version.py
|
||||
"import re, sys\n"
|
||||
"from xml.etree import ElementTree as ET\n"
|
||||
"doc = ET.parse('${CMAKE_SOURCE_DIR}/package.xml')\n"
|
||||
"ver = doc.find('version').text\n"
|
||||
"if re.match('\\d+\\.\\d+\\.\\d+', ver):\n"
|
||||
" sys.stdout.write(ver)\n"
|
||||
"else:\n"
|
||||
" sys.stderr.write('Version format error.\\n')\n"
|
||||
" sys.exit(1)\n"
|
||||
)
|
||||
|
||||
install(FILES
|
||||
"${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/MAVLinkConfig.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/MAVLink
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${Python_EXECUTABLE} ${CMAKE_BINARY_DIR}/package_version.py
|
||||
OUTPUT_VARIABLE XML_VERSION
|
||||
RESULT_VARIABLE XML_RESULT
|
||||
)
|
||||
|
||||
string(STRIP "${XML_VERSION}" XML_VERSION)
|
||||
if(NOT ${XML_RESULT})
|
||||
set(PROJECT_VERSION ${XML_VERSION})
|
||||
message(STATUS "Package version: ${PROJECT_VERSION}")
|
||||
else()
|
||||
message(WARNING "Package version: package.xml parse error, default used: ${PROJECT_VERSION}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# config files
|
||||
configure_file(config.h.in config.h)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/config.h DESTINATION include/${PROJECT_NAME} COMPONENT Dev)
|
||||
|
||||
# mavlink generation
|
||||
set(mavgen_path ${CMAKE_SOURCE_DIR}/pymavlink/tools/mavgen.py)
|
||||
set(common_xml_path ${CMAKE_SOURCE_DIR}/message_definitions/v1.0/common.xml)
|
||||
macro(generateMavlink_v10 definitions)
|
||||
foreach(definitionAbsPath ${definitions})
|
||||
get_filename_component(definition ${definitionAbsPath} NAME_WE)
|
||||
message(STATUS "processing v1.0: ${definitionAbsPath}")
|
||||
add_custom_command(
|
||||
OUTPUT include/v1.0/${definition}/${definition}.h
|
||||
COMMAND /usr/bin/env PYTHONPATH="${CMAKE_SOURCE_DIR}:$ENV{PYTHONPATH}"
|
||||
${Python_EXECUTABLE} ${mavgen_path} --lang=C --wire-protocol=1.0
|
||||
--output=include/v1.0 ${definitionAbsPath}
|
||||
DEPENDS ${definitionAbsPath} ${common_xml_path} ${mavgen_path}
|
||||
)
|
||||
add_custom_target(${definition}.xml-v1.0
|
||||
ALL DEPENDS include/v1.0/${definition}/${definition}.h
|
||||
)
|
||||
endforeach()
|
||||
endmacro()
|
||||
macro(generateMavlink_v20 definitions)
|
||||
foreach(definitionAbsPath ${definitions})
|
||||
get_filename_component(definition ${definitionAbsPath} NAME_WE)
|
||||
message(STATUS "processing v2.0: ${definitionAbsPath}")
|
||||
|
||||
# mavgen C++ also do C gen
|
||||
add_custom_command(
|
||||
OUTPUT ${definition}-v2.0-cxx-stamp
|
||||
#OUTPUT include/v2.0/${definition}/${definition}.hpp
|
||||
COMMAND /usr/bin/env PYTHONPATH="${CMAKE_SOURCE_DIR}:$ENV{PYTHONPATH}"
|
||||
${Python_EXECUTABLE} ${mavgen_path} --lang=C++11 --wire-protocol=2.0
|
||||
--output=include/v2.0 ${definitionAbsPath}
|
||||
COMMAND touch ${definition}-v2.0-cxx-stamp
|
||||
DEPENDS ${definitionAbsPath} ${common_xml_path} ${mavgen_path}
|
||||
)
|
||||
add_custom_target(${definition}.xml-v2.0
|
||||
ALL DEPENDS
|
||||
${definition}-v2.0-cxx-stamp
|
||||
#include/v2.0/${definition}/${definition}.hpp
|
||||
)
|
||||
endforeach()
|
||||
|
||||
# XXX NOTE: that is workaround v2.0 mavgen bug:
|
||||
# when it generate other dialect than common.xml
|
||||
# resulting common.h/.hpp does not have extended enums like MAV_CMD
|
||||
#
|
||||
# So we use stamp file to force run of mavgen and add all other xml to common.xml dependencies.
|
||||
foreach(definitionAbsPath ${definitions})
|
||||
get_filename_component(definition ${definitionAbsPath} NAME_WE)
|
||||
add_dependencies(common.xml-v2.0 ${definition}.xml-v2.0)
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# build v1.0
|
||||
file(GLOB V10DEFINITIONS ${CMAKE_SOURCE_DIR}/message_definitions/v1.0/*.xml)
|
||||
|
||||
# do not generate testing dialects
|
||||
foreach(definition minimal test python_array_test)
|
||||
list(REMOVE_ITEM V10DEFINITIONS "${CMAKE_SOURCE_DIR}/message_definitions/v1.0/${definition}.xml")
|
||||
endforeach()
|
||||
list(SORT V10DEFINITIONS)
|
||||
|
||||
generateMavlink_v10("${V10DEFINITIONS}")
|
||||
|
||||
# build v2.0 if it is supported. for now it uses same definitions as v1.0
|
||||
if(EXISTS "${CMAKE_SOURCE_DIR}/pymavlink/generator/C/include_v2.0")
|
||||
set(V20DEFINITIONS "${V10DEFINITIONS}")
|
||||
generateMavlink_v20("${V20DEFINITIONS}")
|
||||
endif()
|
||||
|
||||
# build pymavlink
|
||||
# NOTE: pymavlink removed from mavlink package on @tridge request.
|
||||
# use `rosdep install python-pymavlink` to solve that dependency.
|
||||
#add_subdirectory(pymavlink)
|
||||
|
||||
# install files
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/include/ DESTINATION include/${PROJECT_NAME} COMPONENT Dev FILES_MATCHING PATTERN "*.h*")
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/src/ DESTINATION share/${PROJECT_NAME} COMPONENT Dev FILES_MATCHING PATTERN "*.c*")
|
||||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/share/${PROJECT_NAME} DESTINATION share COMPONENT Dev FILES_MATCHING PATTERN "*.c*")
|
||||
|
||||
# thanks for urdfdom project
|
||||
set(PKG_NAME ${PROJECT_NAME})
|
||||
set(PKG2_NAME "${PROJECT_NAME}2")
|
||||
set(PKG_VERSION ${PROJECT_VERSION})
|
||||
set(PKG_DESC "MAVLink micro air vehicle marshalling / communication library")
|
||||
set(PKG_LIBRARIES )
|
||||
set(PKG_DEPENDS )
|
||||
set(PKG_MAVLINK_DEFINITIONS "${V10DEFINITIONS}")
|
||||
set(PKG2_MAVLINK_DEFINITIONS "${V20DEFINITIONS}")
|
||||
foreach(def ${V10DEFINITIONS})
|
||||
get_filename_component(dialect "${def}" NAME_WE)
|
||||
list(APPEND PKG_MAVLINK_DIALECTS ${dialect})
|
||||
endforeach()
|
||||
foreach(def ${V20DEFINITIONS})
|
||||
get_filename_component(dialect "${def}" NAME_WE)
|
||||
list(APPEND PKG2_MAVLINK_DIALECTS ${dialect})
|
||||
endforeach()
|
||||
|
||||
|
||||
configure_file(config.cmake.in ${PROJECT_NAME}-config.cmake @ONLY)
|
||||
install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake/ COMPONENT cmake)
|
||||
|
||||
configure_file(pc.in ${PROJECT_NAME}.pc @ONLY)
|
||||
install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.pc
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ COMPONENT pkgconfig)
|
||||
|
||||
# add file extensions and set resource files
|
||||
configure_file("COPYING" "COPYING.txt" COPYONLY)
|
||||
install(FILES ${PROJECT_BINARY_DIR}/COPYING.txt
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/ COMPONENT license)
|
||||
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/package.xml
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/ COMPONENT catkin)
|
||||
|
||||
# vim:sw=4 ts=4 expandtab:
|
||||
|
||||
39
config.cmake.in
Normal file
39
config.cmake.in
Normal file
@@ -0,0 +1,39 @@
|
||||
# Force case-sensitive search
|
||||
string(COMPARE EQUAL "@PKG_NAME@" "${CMAKE_FIND_PACKAGE_NAME}" case_sensitive_match)
|
||||
if (NOT case_sensitive_match)
|
||||
if (NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
|
||||
message(AUTHOR_WARNING "got '${CMAKE_FIND_PACKAGE_NAME}', use case-sensitive find_package(@PKG_NAME@) instead")
|
||||
endif()
|
||||
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND false)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if (@PKG_NAME@_CONFIG_INCLUDED)
|
||||
return()
|
||||
endif()
|
||||
set(@PKG_NAME@_CONFIG_INCLUDED TRUE)
|
||||
|
||||
get_filename_component(include "${@PKG_NAME@_DIR}/../../../include" ABSOLUTE)
|
||||
set(@PKG_NAME@_INCLUDE_DIRS ${include})
|
||||
set(@PKG_NAME@_DIALECTS @PKG_MAVLINK_DIALECTS@)
|
||||
set(@PKG2_NAME@_DIALECTS @PKG2_MAVLINK_DIALECTS@)
|
||||
|
||||
foreach(lib @PKG_LIBRARIES@)
|
||||
set(onelib "${lib}-NOTFOUND")
|
||||
find_library(onelib ${lib}
|
||||
PATHS "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@"
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
if(NOT onelib)
|
||||
message(FATAL_ERROR "Library '${lib}' in package @PKG_NAME@ is not installed properly")
|
||||
endif()
|
||||
list(APPEND @PKG_NAME@_LIBRARIES ${onelib})
|
||||
endforeach()
|
||||
|
||||
foreach(dep @PKG_DEPENDS@)
|
||||
if(NOT ${dep}_FOUND)
|
||||
find_package(${dep})
|
||||
endif()
|
||||
list(APPEND @PKG_NAME@_INCLUDE_DIRS ${${dep}_INCLUDE_DIRS})
|
||||
list(APPEND @PKG_NAME@_LIBRARIES ${${dep}_LIBRARIES})
|
||||
endforeach()
|
||||
1
config.h.in
Normal file
1
config.h.in
Normal file
@@ -0,0 +1 @@
|
||||
#define MAVLINK_VERSION "${PROJECT_VERSION}"
|
||||
39
package.xml
Normal file
39
package.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||
<package format="3">
|
||||
<name>mavlink</name>
|
||||
<version>2025.9.9</version>
|
||||
<description>MAVLink message marshaling library.
|
||||
This package provides C-headers and C++11 library
|
||||
for both 1.0 and 2.0 versions of protocol.
|
||||
|
||||
For pymavlink use separate install via rosdep (python-pymavlink).
|
||||
</description>
|
||||
|
||||
<maintainer email="vooon341@gmail.com">Vladimir Ermakov</maintainer>
|
||||
|
||||
<url type="website">https://mavlink.io/en/</url>
|
||||
<url type="repository">https://github.com/mavlink/mavlink.git</url>
|
||||
<url type="bugtracker">https://github.com/mavlink/mavlink/issues</url>
|
||||
|
||||
<author>Lorenz Meier</author>
|
||||
<license>LGPLv3</license>
|
||||
|
||||
<buildtool_depend>cmake</buildtool_depend>
|
||||
|
||||
<build_depend condition="$ROS_PYTHON_VERSION == 2">python</build_depend>
|
||||
<build_depend condition="$ROS_PYTHON_VERSION == 2">python-lxml</build_depend>
|
||||
<build_depend condition="$ROS_PYTHON_VERSION == 2">python-future</build_depend>
|
||||
|
||||
<build_depend condition="$ROS_PYTHON_VERSION == 3">python3-dev</build_depend>
|
||||
<build_depend condition="$ROS_PYTHON_VERSION == 3">python3-lxml</build_depend>
|
||||
<build_depend condition="$ROS_PYTHON_VERSION == 3">python3-future</build_depend>
|
||||
|
||||
<exec_depend condition="$ROS_VERSION == 1">catkin</exec_depend>
|
||||
<buildtool_depend condition="$ROS_VERSION == 2">ament_cmake</buildtool_depend>
|
||||
<buildtool_depend condition="$ROS_VERSION == 2">ros_environment</buildtool_depend>
|
||||
|
||||
<export>
|
||||
<build_type>cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
Reference in New Issue
Block a user