-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
59 lines (44 loc) · 2.41 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
cmake_minimum_required(VERSION 3.1.0)
set(CMAKE_C_FLAGS "-std=gnu99")
project(mavlink-serial-bridge C)
set(VERSION_MAJOR 0)
set(VERSION_MINOR 8)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVERSION_MAJOR=${VERSION_MAJOR} -DVERSION_MINOR=${VERSION_MINOR}")
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
if((NOT EXISTS "${PROJECT_SOURCE_DIR}/lib/mavlink/v2.0/protocol.h") OR (NOT EXISTS "${PROJECT_SOURCE_DIR}/lib/c-ringbuf/ringbuf.c"))
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
if(NOT DEFINED MAVLINK_DIALECT)
set(MAVLINK_DIALECT "ardupilotmega")
message(WARNING "MAVLink dialect is not set. Using ardupilotmega by default!")
endif()
configure_file(
"${PROJECT_SOURCE_DIR}/mavlink_dialect.h.in"
"${PROJECT_BINARY_DIR}/mavlink_dialect.h"
)
find_package(PkgConfig REQUIRED)
pkg_check_modules(YAML REQUIRED libcyaml)
add_executable(mavlink-serial-bridge main.c config.c ${PROJECT_SOURCE_DIR}/lib/c-ringbuf/ringbuf.c)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address,undefined,leak")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address,undefined,leak")
target_include_directories(mavlink-serial-bridge PUBLIC ${YAML_INCLUDE_DIRS} ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/lib/c-ringbuf)
target_link_libraries(mavlink-serial-bridge ${YAML_LIBRARIES})
configure_file("${PROJECT_SOURCE_DIR}/[email protected]"
"${PROJECT_BINARY_DIR}/[email protected]")
install(TARGETS mavlink-serial-bridge DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/[email protected]" DESTINATION
"/lib/systemd/system")
install(FILES "${PROJECT_SOURCE_DIR}/config.yaml" DESTINATION
"/etc/mavlink-serial-bridge/" RENAME "example.yaml")