xref: /btstack/port/qt-usb/CMakeLists.txt (revision ced70f9bfeafe291ec597a3a9cc862e39e0da3ce)
1cmake_minimum_required(VERSION 3.5)
2
3project(qt-usb LANGUAGES C CXX)
4
5set(CMAKE_INCLUDE_CURRENT_DIR ON)
6
7set(CMAKE_AUTOUIC ON)
8set(CMAKE_AUTOMOC ON)
9set(CMAKE_AUTORCC ON)
10
11set(CMAKE_CXX_STANDARD 11)
12set(CMAKE_CXX_STANDARD_REQUIRED ON)
13
14message("${Qt5_DIR}")
15
16find_package(Qt5Core)
17include(FindPythonInterp)
18
19# pkgconfig
20find_package(PkgConfig QUIET)
21
22# portaudio
23if (PkgConfig_FOUND)
24    pkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0)
25    if(PORTAUDIO_FOUND)
26        message("HAVE_PORTAUDIO")
27        include_directories(${PORTAUDIO_INCLUDE_DIRS})
28        link_directories(${PORTAUDIO_LIBRARY_DIRS})
29        link_libraries(${PORTAUDIO_LIBRARIES})
30        # CMake 3.12 - add_compile_definitions(HAVE_PORTAUDIO)
31        SET(CMAKE_C_FLAGS  "-DHAVE_PORTAUDIO")
32    endif()
33endif()
34
35# BTstack Root
36set(BTSTACK_ROOT "../..")
37message("BTSTACK_ROOT: ${BTSTACK_ROOT}")
38
39# BTstack include
40include_directories(${BTSTACK_ROOT}/3rd-party/micro-ecc)
41include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/include)
42include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/include)
43include_directories(${BTSTACK_ROOT}/3rd-party/md5)
44include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player)
45include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player/mod)
46include_directories(${BTSTACK_ROOT}/3rd-party/lwip/core/src/include)
47include_directories(${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server)
48include_directories(${BTSTACK_ROOT}/3rd-party/rijndael)
49include_directories(${BTSTACK_ROOT}/3rd-party/yxml)
50include_directories(${BTSTACK_ROOT}/3rd-party/tinydir)
51include_directories(${BTSTACK_ROOT}/src)
52include_directories(${BTSTACK_ROOT}/platform/posix)
53include_directories(${BTSTACK_ROOT}/platform/embedded)
54include_directories(${BTSTACK_ROOT}/platform/lwip)
55include_directories(${BTSTACK_ROOT}/platform/lwip/port)
56include_directories(${BTSTACK_ROOT}/platform/qt)
57include_directories(.)
58
59# BTstack sources
60file(GLOB SOURCES_SRC       "${BTSTACK_ROOT}/src/*.c" "${BTSTACK_ROOT}/example/sco_demo_util.c")
61file(GLOB SOURCES_BLE       "${BTSTACK_ROOT}/src/ble/*.c")
62file(GLOB SOURCES_GATT      "${BTSTACK_ROOT}/src/ble/gatt-service/*.c")
63file(GLOB SOURCES_CLASSIC   "${BTSTACK_ROOT}/src/classic/*.c")
64file(GLOB SOURCES_MESH      "${BTSTACK_ROOT}/src/mesh/*.c")
65file(GLOB SOURCES_BLUEDROID "${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/srce/*.c" "${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/srce/*.c")
66file(GLOB SOURCES_MD5       "${BTSTACK_ROOT}/3rd-party/md5/md5.c")
67file(GLOB SOURCES_UECC      "${BTSTACK_ROOT}/3rd-party/micro-ecc/uECC.c")
68file(GLOB SOURCES_YXML      "${BTSTACK_ROOT}/3rd-party/yxml/yxml.c")
69file(GLOB SOURCES_HXCMOD    "${BTSTACK_ROOT}/3rd-party/hxcmod-player/*.c"  "${BTSTACK_ROOT}/3rd-party/hxcmod-player/mods/*.c")
70file(GLOB SOURCES_RIJNDAEL  "${BTSTACK_ROOT}/3rd-party/rijndael/rijndael.c")
71
72set(SOURCES_POSIX
73    ${BTSTACK_ROOT}/platform/posix/btstack_audio_portaudio.c
74    ${BTSTACK_ROOT}/platform/posix/btstack_tlv_posix.c
75    ${BTSTACK_ROOT}/platform/posix/hci_dump_posix_fs.c
76    ${BTSTACK_ROOT}/platform/posix/wav_util.c
77)
78
79
80set(LWIP_CORE_SRC
81        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/def.c
82        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/inet_chksum.c
83        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/init.c
84        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ip.c
85        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/mem.c
86        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/memp.c
87        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/netif.c
88        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/pbuf.c
89        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp.c
90        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp_in.c
91        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp_out.c
92        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/timeouts.c
93        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/udp.c
94)
95set (LWIP_IPV4_SRC
96        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/acd.c
97        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/dhcp.c
98        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/etharp.c
99        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/icmp.c
100        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4.c
101        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4_addr.c
102        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4_frag.c
103)
104set (LWIP_NETIF_SRC
105        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/netif/ethernet.c
106)
107set (LWIP_HTTPD
108        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/altcp_proxyconnect.c
109        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/fs.c
110        ${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/httpd.c
111)
112set (LWIP_DHCPD
113        ${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server/dhserver.c
114)
115set (LWIP_PORT
116        ${BTSTACK_ROOT}/platform/lwip/port/sys_arch.c
117        ${BTSTACK_ROOT}/platform/lwip/bnep_lwip.c
118)
119
120set (SOURCES_LWIP ${LWIP_CORE_SRC} ${LWIP_IPV4_SRC} ${LWIP_NETIF_SRC} ${LWIP_HTTPD} ${LWIP_DHCPD} ${LWIP_PORT})
121
122file(GLOB SOURCES_BLE_OFF   "${BTSTACK_ROOT}/src/ble/le_device_db_memory.c")
123list(REMOVE_ITEM SOURCES_BLE ${SOURCES_BLE_OFF})
124
125
126# select POSIX vs Windows versions
127IF (WIN32)
128    message("Building for Windows using WinUSB")
129    set(SOURCES_HCI_USB ${BTSTACK_ROOT}/platform/windows/hci_transport_h2_winusb.c)
130    set(SOURCES_STDIN   ${BTSTACK_ROOT}/platform/windows/btstack_stdin_windows.c)
131    link_libraries( winusb setupapi)
132ELSE()
133    message("Building for POSIX using libusb")
134
135    # fink pkgconfig
136    find_package(PkgConfig REQUIRED)
137
138    # libusb
139    pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
140    include_directories(${LIBUSB_INCLUDE_DIRS})
141    link_directories(${LIBUSB_LIBRARY_DIRS})
142    link_libraries(${LIBUSB_LIBRARIES})
143
144    set(SOURCES_HCI_USB ${BTSTACK_ROOT}/platform/libusb/hci_transport_h2_libusb.c)
145    set(SOURCES_STDIN   ${BTSTACK_ROOT}/platform/posix/btstack_stdin_posix.c ${BTSTACK_ROOT}/platform/posix/btstack_signal.c)
146
147    list(APPEND SOURCES_POSIX ${BTSTACK_ROOT}/platform/posix/btstack_network_posix.c)
148ENDIF()
149
150set(SOURCES
151        ${SOURCES_MD5}
152        ${SOURCES_YXML}
153        ${SOURCES_BLUEDROID}
154        ${SOURCES_POSIX}
155        ${SOURCES_RIJNDAEL}
156        ${SOURCES_HCI_USB}
157        ${SOURCES_STDIN}
158        ${SOURCES_SRC}
159        ${SOURCES_BLE}
160        ${SOURCES_GATT}
161        ${SOURCES_MESH}
162        ${SOURCES_CLASSIC}
163        ${SOURCES_UECC}
164        ${SOURCES_HXCMOD}
165)
166list(SORT SOURCES)
167
168# create static lib
169add_library(btstack-lib STATIC ${SOURCES})
170
171# create targets for all examples
172file(GLOB EXAMPLES_C    "${BTSTACK_ROOT}/example/*.c")
173list(SORT EXAMPLES_C)
174file(GLOB EXAMPLES_GATT "${BTSTACK_ROOT}/example/*.gatt")
175
176# remove some
177file(GLOB EXAMPLES_OFF  "${BTSTACK_ROOT}/example/panu_demo.c" "${BTSTACK_ROOT}/example/*demo_util*.c" "${BTSTACK_ROOT}/example/ant_test.c" "${BTSTACK_ROOT}/example/avrcp_browsing_client.c")
178list(REMOVE_ITEM EXAMPLES_C ${EXAMPLES_OFF})
179
180# on Mac 10.14, adding lwip to libstack results in a yet not understood link error
181# workaround: add lwip sources only to lwip_examples
182set (LWIP_EXAMPLES pan_lwip_http_server)
183
184# create targets
185foreach(EXAMPLE_FILE ${EXAMPLES_C})
186        get_filename_component(EXAMPLE ${EXAMPLE_FILE} NAME_WE)
187        set (SOURCES_EXAMPLE ${EXAMPLE_FILE})
188
189        # add qt main.cpp and run loop
190        list(APPEND SOURCES_EXAMPLE ${BTSTACK_ROOT}/platform/qt/btstack_run_loop_qt.cpp main.cpp)
191
192        # add lwip sources for lwip examples
193        if ( "${LWIP_EXAMPLES}" MATCHES ${EXAMPLE} )
194                list(APPEND SOURCES_EXAMPLE ${SOURCES_LWIP})
195        endif()
196
197        # add GATT DB creation
198        if ( "${EXAMPLES_GATT}" MATCHES ${EXAMPLE} )
199                message("example ${EXAMPLE} -- with GATT DB")
200                add_custom_command(
201                    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h
202                        COMMAND  ${PYTHON_EXECUTABLE}
203                        ARGS ${BTSTACK_ROOT}/tool/compile_gatt.py ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h
204                )
205                list(APPEND SOURCES_EXAMPLE ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h)
206
207                # generated file does not need AUTOMOC and AUOUIC processing
208                set_property(SOURCE {CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h PROPERTY SKIP_AUTOGEN ON)
209        else()
210                message("example ${EXAMPLE}")
211        endif()
212        add_executable(${EXAMPLE} ${SOURCES_EXAMPLE} )
213        target_link_libraries(${EXAMPLE} btstack-lib Qt5::Core)
214endforeach(EXAMPLE_FILE)
215