-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMakeLists.txt
154 lines (132 loc) · 3.43 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
cmake_minimum_required (VERSION 3.5)
project(crazyflie-link-cpp)
# define some options
option(BUILD_PYTHON_BINDINGS "Generate Python Bindings" ON)
option(BUILD_CPP_EXAMPLES "Generate C++ Examples" ON)
# Enable C++14 and warnings
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Compile static libraries with hidden visibility
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
if (MSVC)
# Avoid min/max macros in Windows.h (pulled in from libusb)
add_definitions(-DNOMINMAX)
# warning level 4
# Ideally we would also treat warnings as errors (/WX), but there are still some warnings to fix
add_compile_options(/W4)
else()
# lots of warnings and all warnings as errors
add_compile_options(-Wall -Wextra -Werror)
endif()
# dependencies
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/tools/build)
if (WIN32)
# build libusb
include_directories(
libusb/msvc
)
add_library(libusb
libusb/libusb/core.c
libusb/libusb/descriptor.c
libusb/libusb/os/events_windows.c
libusb/libusb/hotplug.c
libusb/libusb/io.c
libusb/libusb/strerror.c
libusb/libusb/sync.c
libusb/libusb/os/threads_windows.c
libusb/libusb/os/windows_common.c
libusb/libusb/os/windows_usbdk.c
libusb/libusb/os/windows_winusb.c
)
set(LIBUSB_INCLUDE_DIR libusb/libusb)
set(LIBUSB_LIBRARY libusb)
else()
find_package(libusb REQUIRED)
endif()
include_directories(
include
${LIBUSB_INCLUDE_DIR}
)
# C++ library
add_library(crazyflieLinkCpp
src/USBManager.cpp
src/Connection.cpp
src/USBDevice.cpp
src/Crazyradio.cpp
src/CrazyradioThread.cpp
src/CrazyflieUSB.cpp
src/CrazyflieUSBThread.cpp
src/Version.cpp
)
# target_include_directories(libCrazyflieLinkCpp
# PUBLIC
# $<INSTALL_INTERFACE:include/crazyflie_cpp>
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/crazyflie_cpp>
# )
# Apple macOS libraries
if (APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-lobjc -framework IOKit -framework CoreFoundation -framework Security")
set(CMAKE_MODULE_LINKER_FLAGS "-lobjc -framework IOKit -framework CoreFoundation -framework Security")
endif()
# Link pthread on Linux and Mac only
if (NOT MSVC)
target_link_libraries(crazyflieLinkCpp
PRIVATE
pthread
)
endif()
target_link_libraries(crazyflieLinkCpp
PRIVATE
${LIBUSB_LIBRARY}
)
set_property(TARGET crazyflieLinkCpp PROPERTY POSITION_INDEPENDENT_CODE ON)
# C++ example application
if (BUILD_CPP_EXAMPLES)
# example_console
add_executable(example_console
examples/console.cpp
)
target_link_libraries(example_console
crazyflieLinkCpp
)
# example_scan
add_executable(example_scan
examples/scan.cpp
)
target_link_libraries(example_scan
crazyflieLinkCpp
)
# example_benchmark
add_executable(example_benchmark
examples/benchmark.cpp
)
target_link_libraries(example_benchmark
crazyflieLinkCpp
)
# example_broadcast
add_executable(example_broadcast
examples/broadcast.cpp
)
target_link_libraries(example_broadcast
crazyflieLinkCpp
)
# example_broadcast_and_console
add_executable(example_broadcast_and_console
examples/broadcast_and_console.cpp
)
target_link_libraries(example_broadcast_and_console
crazyflieLinkCpp
)
endif()
if (BUILD_PYTHON_BINDINGS)
# Python bindings
add_subdirectory(pybind11 EXCLUDE_FROM_ALL)
pybind11_add_module(cflinkcpp
src/python_bindings.cpp
)
target_link_libraries(cflinkcpp
PRIVATE
crazyflieLinkCpp
)
endif()