1cmake_minimum_required (VERSION 3.18) 2 3project(BTstack-posix-h4) 4 5SET(BTSTACK_ROOT ${CMAKE_SOURCE_DIR}/../..) 6 7# extra compiler warnings 8if ("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang.*") 9 # using Clang 10 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-variable -Wswitch-default -Wall -Wextra -Werror") 11elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") 12 # using GCC 13 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-but-set-variable -Wunused-variable -Wswitch-default -Wall -Wextra -Werror") 14elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel") 15 # using Intel C++ 16elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") 17 # using Visual Studio C++ 18endif() 19 20if(CMAKE_BUILD_TYPE MATCHES "Debug") 21 add_compile_options( 22 -fsanitize=undefined -fsanitize=address 23 ) 24 add_link_options( 25 -fsanitize=undefined -fsanitize=address 26 ) 27endif() 28 29# to generate .h from .gatt files 30find_package (Python REQUIRED COMPONENTS Interpreter) 31include_directories(${CMAKE_CURRENT_BINARY_DIR}) 32 33# local dir for btstack_config.h after build dir to avoid using .h from Makefile 34include_directories(.) 35 36 37include_directories(${BTSTACK_ROOT}/3rd-party/micro-ecc) 38include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/include) 39include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/include) 40include_directories(${BTSTACK_ROOT}/3rd-party/lc3-google/include) 41include_directories(${BTSTACK_ROOT}/3rd-party/md5) 42include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player) 43include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player/mod) 44include_directories(${BTSTACK_ROOT}/3rd-party/lwip/core/src/include) 45include_directories(${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server) 46include_directories(${BTSTACK_ROOT}/3rd-party/rijndael) 47include_directories(${BTSTACK_ROOT}/3rd-party/yxml) 48include_directories(${BTSTACK_ROOT}/3rd-party/tinydir) 49include_directories(${BTSTACK_ROOT}/src) 50include_directories(${BTSTACK_ROOT}/chipset/bcm) 51include_directories(${BTSTACK_ROOT}/chipset/csr) 52include_directories(${BTSTACK_ROOT}/chipset/cc256x) 53include_directories(${BTSTACK_ROOT}/chipset/em9301) 54include_directories(${BTSTACK_ROOT}/chipset/realtek) 55include_directories(${BTSTACK_ROOT}/chipset/tc3566x) 56include_directories(${BTSTACK_ROOT}/chipset/stlc2500d) 57include_directories(${BTSTACK_ROOT}/chipset/zephyr) 58include_directories(${BTSTACK_ROOT}/platform/embedded) 59include_directories(${BTSTACK_ROOT}/platform/lwip) 60include_directories(${BTSTACK_ROOT}/platform/lwip/port) 61include_directories(${BTSTACK_ROOT}/platform/posix) 62 63file(GLOB SOURCES_SRC "${BTSTACK_ROOT}/src/*.c" "${BTSTACK_ROOT}/example/sco_demo_util.c") 64file(GLOB SOURCES_BLE "${BTSTACK_ROOT}/src/ble/*.c") 65file(GLOB SOURCES_BLUEDROID "${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/srce/*.c" "${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/srce/*.c") 66file(GLOB SOURCES_CLASSIC "${BTSTACK_ROOT}/src/classic/*.c") 67file(GLOB SOURCES_MESH "${BTSTACK_ROOT}/src/mesh/*.c") 68file(GLOB SOURCES_GATT "${BTSTACK_ROOT}/src/ble/gatt-service/*.c") 69file(GLOB SOURCES_UECC "${BTSTACK_ROOT}/3rd-party/micro-ecc/uECC.c") 70file(GLOB SOURCES_HXCMOD "${BTSTACK_ROOT}/3rd-party/hxcmod-player/*.c" "${BTSTACK_ROOT}/3rd-party/hxcmod-player/mods/*.c") 71file(GLOB SOURCES_MD5 "${BTSTACK_ROOT}/3rd-party/md5/md5.c") 72file(GLOB SOURCES_RIJNDAEL "${BTSTACK_ROOT}/3rd-party/rijndael/rijndael.c") 73file(GLOB SOURCES_YXML "${BTSTACK_ROOT}/3rd-party/yxml/yxml.c") 74file(GLOB SOURCES_POSIX "${BTSTACK_ROOT}/platform/posix/*.c") 75file(GLOB SOURCES_BCM "${BTSTACK_ROOT}/chipset/bcm/*.c") 76file(GLOB SOURCES_CSR "${BTSTACK_ROOT}/chipset/csr/*.c") 77file(GLOB SOURCES_EM9301 "${BTSTACK_ROOT}/chipset/em9301/*.c") 78file(GLOB SOURCES_STLC2500D "${BTSTACK_ROOT}/chipset/stlc2500d/*.c") 79file(GLOB SOURCES_TC2566X "${BTSTACK_ROOT}/chipset/tc3566x/*.c") 80file(GLOB SOURCES_REALTEK "${BTSTACK_ROOT}/chipset/realtek/*.c") 81file(GLOB SOURCES_ZEPHYR "${BTSTACK_ROOT}/chipset/zephyr/*.c") 82file(GLOB SOURCES_LC3_GOOGLE "${BTSTACK_ROOT}/3rd-party/lc3-google/src/*.c") 83file(GLOB SOURCES_PORT "*.c") 84 85set(LWIP_CORE_SRC 86 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/def.c 87 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/inet_chksum.c 88 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/init.c 89 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ip.c 90 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/mem.c 91 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/memp.c 92 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/netif.c 93 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/pbuf.c 94 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp.c 95 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp_in.c 96 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp_out.c 97 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/timeouts.c 98 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/udp.c 99 ) 100set (LWIP_IPV4_SRC 101 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/acd.c 102 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/dhcp.c 103 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/etharp.c 104 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/icmp.c 105 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4.c 106 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4_addr.c 107 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4_frag.c 108 ) 109set (LWIP_NETIF_SRC 110 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/netif/ethernet.c 111 ) 112set (LWIP_HTTPD 113 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/altcp_proxyconnect.c 114 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/fs.c 115 ${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/httpd.c 116 ) 117set (LWIP_DHCPD 118 ${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server/dhserver.c 119 ) 120set (LWIP_PORT 121 ${BTSTACK_ROOT}/platform/lwip/port/sys_arch.c 122 ${BTSTACK_ROOT}//platform/lwip/bnep_lwip.c 123 ) 124set (SOURCES_LWIP ${LWIP_CORE_SRC} ${LWIP_IPV4_SRC} ${LWIP_NETIF_SRC} ${LWIP_HTTPD} ${LWIP_DHCPD} ${LWIP_PORT}) 125 126file(GLOB SOURCES_BLE_OFF "${BTSTACK_ROOT}/src/ble/le_device_db_memory.c") 127list(REMOVE_ITEM SOURCES_BLE ${SOURCES_BLE_OFF}) 128 129file(GLOB SOURCES_POSIX_OFF "${BTSTACK_ROOT}/platform/posix/le_device_db_fs.c") 130list(REMOVE_ITEM SOURCES_POSIX ${SOURCES_POSIX_OFF}) 131 132set(SOURCES 133 ${SOURCES_BLE} 134 ${SOURCES_BCM} 135 ${SOURCES_BLUEDROID} 136 ${SOURCES_CLASSIC} 137 ${SOURCES_CSR} 138 ${SOURCES_EM9301} 139 ${SOURCES_GATT} 140 ${SOURCES_HXCMOD} 141 ${SOURCES_HXCMOD} 142 ${SOURCES_LIBUSB} 143 ${SOURCES_MD5} 144 ${SOURCES_MESH} 145 ${SOURCES_PORT} 146 ${SOURCES_REALTEK} 147 ${SOURCES_RIJNDAEL} 148 ${SOURCES_SRC} 149 ${SOURCES_CSR} 150 ${SOURCES_STLC2500D} 151 ${SOURCES_TC2566X} 152 ${SOURCES_UECC} 153 ${SOURCES_POSIX} 154 ${SOURCES_YXML} 155 ${SOURCES_ZEPHYR} 156) 157list(SORT SOURCES) 158 159# create static lib 160add_library(btstack STATIC ${SOURCES}) 161 162# pkgconfig 163find_package(PkgConfig) 164 165# portaudio 166if (PkgConfig_FOUND) 167 pkg_check_modules(PORTAUDIO portaudio-2.0) 168 if(PORTAUDIO_FOUND) 169 message("HAVE_PORTAUDIO") 170 include_directories(${PORTAUDIO_INCLUDE_DIRS}) 171 link_directories(${PORTAUDIO_LIBRARY_DIRS}) 172 link_libraries(${PORTAUDIO_LIBRARIES}) 173 add_compile_definitions(HAVE_PORTAUDIO) 174 endif() 175endif() 176 177# pthread 178find_package(Threads) 179link_libraries(${CMAKE_THREAD_LIBS_INIT}) 180 181# Add CC256x Support and specify init script 182set (CC256X_INIT_SCRIPT bluetooth_init_cc2564C_1.5.c) 183include(${BTSTACK_ROOT}/chipset/cc256x/cc256x.cmake) 184 185# Add BCM Support and download PatchRAM files 186include(${BTSTACK_ROOT}/chipset/bcm/bcm.cmake) 187 188# get list of examples, skipping mesh_node_demo 189include(../../example/CMakeLists.txt) 190set (EXAMPLES ${EXAMPLES_GENERAL} ${EXAMPLES_CLASSIC_ONLY} ${EXAMPLES_LE_ONLY} ${EXAMPLES_DUAL_MODE}) 191list(REMOVE_DUPLICATES EXAMPLES) 192list(REMOVE_ITEM EXAMPLES "mesh_node_demo") 193 194# create targets 195foreach(EXAMPLE ${EXAMPLES}) 196 # get c file 197 set (SOURCES_EXAMPLE ${BTSTACK_ROOT}/example/${EXAMPLE}.c) 198 199 # add GATT DB creation 200 if ( "${EXAMPLES_GATT_FILES}" MATCHES ${EXAMPLE} ) 201 message("example ${EXAMPLE} -- with GATT DB") 202 add_custom_command( 203 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 204 DEPENDS ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt 205 COMMAND ${Python_EXECUTABLE} 206 ARGS ${BTSTACK_ROOT}/tool/compile_gatt.py ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 207 ) 208 list(APPEND SOURCES_EXAMPLE ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h) 209 else() 210 message("example ${EXAMPLE}") 211 endif() 212 add_executable(${EXAMPLE} ${SOURCES_EXAMPLE}) 213 target_link_libraries(${EXAMPLE} btstack pthread) 214endforeach(EXAMPLE) 215