forked from GONAvionics/mavlink_ros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
117 lines (98 loc) · 4.46 KB
/
CMakeLists.txt
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
project (mavlink NONE)
# Note: patched version for installation as ROS 3-rd party library
# Provides C-headers and pymavlink
# settings
cmake_minimum_required (VERSION 2.8.2)
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)
# hack from urdfdom: by default this would be 'lib/x86_64-linux-gnu'
set(CMAKE_INSTALL_LIBDIR lib)
# find libraries with cmake modules
set(PythonInterp_FIND_VERSION "2")
find_package(PythonInterp REQUIRED)
# 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"
)
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: ${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()
# build only v1.0
file(GLOB V10DEFINITIONS ${CMAKE_SOURCE_DIR}/message_definitions/v1.0/*.xml)
generateMavlink_v10("${V10DEFINITIONS}")
# build pymavlink
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(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}")
foreach(def ${V10DEFINITIONS})
get_filename_component(dialect "${def}" NAME_WE)
list(APPEND PKG_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