1cmake_minimum_required (VERSION 3.12) 2 3SET(CMAKE_OSX_SYSROOT /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk) 4SET(CMAKE_EXPORT_COMPILE_COMMANDS ON) 5 6project(BTstack-libusb) 7 8SET(BTSTACK_ROOT ${CMAKE_SOURCE_DIR}/../..) 9 10# extra compiler warnings 11if ("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang.*") 12 # using Clang 13 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-variable -Wswitch-default -Wall -Wextra -Werror -Werror=uninitialized") 14elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") 15 # using GCC 16 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-but-set-variable -Wunused-variable -Wswitch-default -Wall -Wextra -Werror") 17elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel") 18 # using Intel C++ 19elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") 20 # using Visual Studio C++ 21endif() 22 23# to generate .h from .gatt files 24find_package (Python REQUIRED COMPONENTS Interpreter) 25include_directories(${CMAKE_CURRENT_BINARY_DIR}) 26 27# local dir for btstack_config.h after build dir to avoid using .h from Makefile 28include_directories(.) 29 30include_directories(../../3rd-party/micro-ecc) 31include_directories(../../3rd-party/bluedroid/decoder/include) 32include_directories(../../3rd-party/bluedroid/encoder/include) 33include_directories(../../3rd-party/lc3-google/include) 34include_directories(../../3rd-party/md5) 35include_directories(../../3rd-party/hxcmod-player) 36include_directories(../../3rd-party/hxcmod-player/mod) 37include_directories(../../3rd-party/lwip/core/src/include) 38include_directories(../../3rd-party/lwip/dhcp-server) 39include_directories(../../3rd-party/rijndael) 40include_directories(../../3rd-party/yxml) 41include_directories(../../3rd-party/tinydir) 42include_directories(../../src) 43include_directories(../../chipset/realtek) 44include_directories(../../chipset/zephyr) 45include_directories(../../platform/posix) 46include_directories(../../platform/embedded) 47include_directories(../../platform/lwip) 48include_directories(../../platform/lwip/port) 49 50file(GLOB SOURCES_SRC "../../src/*.c" "../../example/sco_demo_util.c") 51file(GLOB SOURCES_BLE "../../src/ble/*.c") 52file(GLOB SOURCES_GATT "../../src/ble/gatt-service/*.c") 53file(GLOB SOURCES_CLASSIC "../../src/classic/*.c") 54file(GLOB SOURCES_MESH "../../src/mesh/*.c" "../../src/mesh/gatt-service/*.c") 55file(GLOB SOURCES_BLUEDROID "../../3rd-party/bluedroid/encoder/srce/*.c" "../../3rd-party/bluedroid/decoder/srce/*.c") 56file(GLOB SOURCES_MD5 "../../3rd-party/md5/md5.c") 57file(GLOB SOURCES_UECC "../../3rd-party/micro-ecc/uECC.c") 58file(GLOB SOURCES_YXML "../../3rd-party/yxml/yxml.c") 59file(GLOB SOURCES_HXCMOD "../../3rd-party/hxcmod-player/*.c" "../../3rd-party/hxcmod-player/mods/*.c") 60file(GLOB SOURCES_RIJNDAEL "../../3rd-party/rijndael/rijndael.c") 61file(GLOB SOURCES_POSIX "../../platform/posix/*.c") 62file(GLOB SOURCES_LIBUSB "../../port/libusb/*.c" "../../platform/libusb/*.c") 63file(GLOB SOURCES_ZEPHYR "../../chipset/zephyr/*.c") 64file(GLOB SOURCES_REALTEK "../../chipset/realtek/*.c") 65file(GLOB SOURCES_LC3_GOOGLE "../../3rd-party/lc3-google/src/*.c") 66 67set(LWIP_CORE_SRC 68 ../../3rd-party/lwip/core/src/core/def.c 69 ../../3rd-party/lwip/core/src/core/inet_chksum.c 70 ../../3rd-party/lwip/core/src/core/init.c 71 ../../3rd-party/lwip/core/src/core/ip.c 72 ../../3rd-party/lwip/core/src/core/mem.c 73 ../../3rd-party/lwip/core/src/core/memp.c 74 ../../3rd-party/lwip/core/src/core/netif.c 75 ../../3rd-party/lwip/core/src/core/pbuf.c 76 ../../3rd-party/lwip/core/src/core/tcp.c 77 ../../3rd-party/lwip/core/src/core/tcp_in.c 78 ../../3rd-party/lwip/core/src/core/tcp_out.c 79 ../../3rd-party/lwip/core/src/core/timeouts.c 80 ../../3rd-party/lwip/core/src/core/udp.c 81) 82set (LWIP_IPV4_SRC 83 ../../3rd-party/lwip/core/src/core/ipv4/acd.c 84 ../../3rd-party/lwip/core/src/core/ipv4/dhcp.c 85 ../../3rd-party/lwip/core/src/core/ipv4/etharp.c 86 ../../3rd-party/lwip/core/src/core/ipv4/icmp.c 87 ../../3rd-party/lwip/core/src/core/ipv4/ip4.c 88 ../../3rd-party/lwip/core/src/core/ipv4/ip4_addr.c 89 ../../3rd-party/lwip/core/src/core/ipv4/ip4_frag.c 90) 91set (LWIP_NETIF_SRC 92 ../../3rd-party/lwip/core/src/netif/ethernet.c 93) 94set (LWIP_HTTPD 95 ../../3rd-party/lwip/core/src/apps/http/altcp_proxyconnect.c 96 ../../3rd-party/lwip/core/src/apps/http/fs.c 97 ../../3rd-party/lwip/core/src/apps/http/httpd.c 98) 99set (LWIP_DHCPD 100 ../../3rd-party/lwip/dhcp-server/dhserver.c 101) 102set (LWIP_PORT 103 ../../platform/lwip/port/sys_arch.c 104 ../../platform/lwip/bnep_lwip.c 105) 106 107set (SOURCES_LWIP ${LWIP_CORE_SRC} ${LWIP_IPV4_SRC} ${LWIP_NETIF_SRC} ${LWIP_HTTPD} ${LWIP_DHCPD} ${LWIP_PORT}) 108 109file(GLOB SOURCES_SRC_OFF "../../src/hci_transport_*.c") 110list(REMOVE_ITEM SOURCES_SRC ${SOURCES_SRC_OFF}) 111 112file(GLOB SOURCES_BLE_OFF "../../src/ble/le_device_db_memory.c") 113list(REMOVE_ITEM SOURCES_BLE ${SOURCES_BLE_OFF}) 114 115file(GLOB SOURCES_POSIX_OFF "../../platform/posix/le_device_db_fs.c") 116list(REMOVE_ITEM SOURCES_POSIX ${SOURCES_POSIX_OFF}) 117 118set(SOURCES 119 ${SOURCES_MD5} 120 ${SOURCES_YXML} 121 ${SOURCES_BLUEDROID} 122 ${SOURCES_POSIX} 123 ${SOURCES_RIJNDAEL} 124 ${SOURCES_LIBUSB} 125 ${SOURCES_LC3_GOOGLE} 126 ${SOURCES_SRC} 127 ${SOURCES_BLE} 128 ${SOURCES_GATT} 129 ${SOURCES_MESH} 130 ${SOURCES_CLASSIC} 131 ${SOURCES_UECC} 132 ${SOURCES_HXCMOD} 133 ${SOURCES_REALTEK} 134 ${SOURCES_ZEPHYR} 135) 136list(SORT SOURCES) 137 138# create static lib 139add_library(btstack STATIC ${SOURCES}) 140 141# pkgconfig required to link libusb 142find_package(PkgConfig REQUIRED) 143 144# libusb 145pkg_check_modules(LIBUSB REQUIRED libusb-1.0) 146include_directories(${LIBUSB_INCLUDE_DIRS}) 147link_directories(${LIBUSB_LIBRARY_DIRS}) 148link_libraries(${LIBUSB_LIBRARIES}) 149 150# portaudio 151pkg_check_modules(PORTAUDIO portaudio-2.0) 152if(PORTAUDIO_FOUND) 153 message("HAVE_PORTAUDIO") 154 include_directories(${PORTAUDIO_INCLUDE_DIRS}) 155 link_directories(${PORTAUDIO_LIBRARY_DIRS}) 156 link_libraries(${PORTAUDIO_LIBRARIES}) 157 add_compile_definitions(HAVE_PORTAUDIO) 158endif() 159 160# pthread 161find_package(Threads) 162link_libraries(${CMAKE_THREAD_LIBS_INIT}) 163 164# create targets for all examples 165file(GLOB EXAMPLES_C "../../example/*.c") 166list(SORT EXAMPLES_C) 167file(GLOB EXAMPLES_GATT "../../example/*.gatt") 168 169# remove some 170file(GLOB EXAMPLES_OFF "../../example/*demo_util*.c" "../../example/ant_test.c" "../../example/avrcp_browsing_client.c") 171list(REMOVE_ITEM EXAMPLES_C ${EXAMPLES_OFF}) 172 173# on Mac 10.14, adding lwip to libstack results in a yet not understood link error 174# workaround: add lwip sources only to lwip_examples 175set (LWIP_EXAMPLES pan_lwip_http_server) 176 177# .gatt files in src 178file(GLOB GATT_FILES "../../src/*/gatt-service/*.gatt") 179 180# create targets 181foreach(EXAMPLE_FILE ${EXAMPLES_C}) 182 get_filename_component(EXAMPLE ${EXAMPLE_FILE} NAME_WE) 183 184 # get c file 185 set (SOURCES_EXAMPLE ${BTSTACK_ROOT}/example/${EXAMPLE}.c) 186 187 # add lwip sources for lwip examples 188 if ( "${LWIP_EXAMPLES}" MATCHES ${EXAMPLE} ) 189 list(APPEND SOURCES_EXAMPLE ${SOURCES_LWIP}) 190 endif() 191 192 # add GATT DB creation 193 if ( "${EXAMPLES_GATT}" MATCHES ${EXAMPLE} ) 194 message("example ${EXAMPLE} -- with GATT DB") 195 add_custom_command( 196 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 197 DEPENDS ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt ${GATT_FILES} 198 COMMAND ${Python_EXECUTABLE} 199 ARGS ${BTSTACK_ROOT}/tool/compile_gatt.py ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 200 ) 201 list(APPEND SOURCES_EXAMPLE ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h) 202 else() 203 message("example ${EXAMPLE}") 204 endif() 205 add_executable(${EXAMPLE} ${SOURCES_EXAMPLE} ) 206 target_link_libraries(${EXAMPLE} btstack) 207endforeach(EXAMPLE_FILE) 208