158e8616dSMatthias Ringwaldcmake_minimum_required (VERSION 3.18) 213d67099SMatthias Ringwald 313d67099SMatthias Ringwaldproject(BTstack-posix-h4) 413d67099SMatthias Ringwald 513d67099SMatthias RingwaldSET(BTSTACK_ROOT ${CMAKE_SOURCE_DIR}/../..) 613d67099SMatthias Ringwald 713d67099SMatthias Ringwald# extra compiler warnings 813d67099SMatthias Ringwaldif ("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang.*") 913d67099SMatthias Ringwald # using Clang 10*0f375d52SMatthias Ringwald SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-variable -Wswitch-default -Wall -Wextra -Werror") 1113d67099SMatthias Ringwaldelseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") 1213d67099SMatthias Ringwald # using GCC 13*0f375d52SMatthias Ringwald SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-but-set-variable -Wunused-variable -Wswitch-default -Wall -Wextra -Werror") 1413d67099SMatthias Ringwaldelseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel") 1513d67099SMatthias Ringwald # using Intel C++ 1613d67099SMatthias Ringwaldelseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") 1713d67099SMatthias Ringwald # using Visual Studio C++ 1813d67099SMatthias Ringwaldendif() 1913d67099SMatthias Ringwald 20e2475b4cSMatthias Ringwaldif(CMAKE_BUILD_TYPE MATCHES "Debug") 21e2475b4cSMatthias Ringwald add_compile_options( 22e2475b4cSMatthias Ringwald -fsanitize=undefined -fsanitize=address 23e2475b4cSMatthias Ringwald ) 24e2475b4cSMatthias Ringwald add_link_options( 25e2475b4cSMatthias Ringwald -fsanitize=undefined -fsanitize=address 26e2475b4cSMatthias Ringwald ) 27e2475b4cSMatthias Ringwaldendif() 287367e9aaSMatthias Ringwald 2902bddf72SMatthias Ringwald# to generate .h from .gatt files 3002bddf72SMatthias Ringwaldfind_package (Python REQUIRED COMPONENTS Interpreter) 3113d67099SMatthias Ringwaldinclude_directories(${CMAKE_CURRENT_BINARY_DIR}) 3213d67099SMatthias Ringwald 3313d67099SMatthias Ringwald# local dir for btstack_config.h after build dir to avoid using .h from Makefile 3413d67099SMatthias Ringwaldinclude_directories(.) 3513d67099SMatthias Ringwald 3613d67099SMatthias Ringwald 3713d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/micro-ecc) 3813d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/include) 3913d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/include) 4013d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/lc3-google/include) 4113d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/md5) 4213d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player) 4313d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player/mod) 4413d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/lwip/core/src/include) 4513d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server) 4613d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/rijndael) 4713d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/yxml) 4813d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/3rd-party/tinydir) 4913d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/src) 5013d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/chipset/bcm) 5113d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/chipset/csr) 5213d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/chipset/cc256x) 5313d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/chipset/em9301) 5413d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/chipset/realtek) 5513d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/chipset/tc3566x) 5613d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/chipset/stlc2500d) 5713d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/chipset/zephyr) 5813d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/platform/embedded) 5913d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/platform/lwip) 6013d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/platform/lwip/port) 6113d67099SMatthias Ringwaldinclude_directories(${BTSTACK_ROOT}/platform/posix) 6213d67099SMatthias Ringwald 6313d67099SMatthias Ringwaldfile(GLOB SOURCES_SRC "${BTSTACK_ROOT}/src/*.c" "${BTSTACK_ROOT}/example/sco_demo_util.c") 6413d67099SMatthias Ringwaldfile(GLOB SOURCES_BLE "${BTSTACK_ROOT}/src/ble/*.c") 6513d67099SMatthias Ringwaldfile(GLOB SOURCES_BLUEDROID "${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/srce/*.c" "${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/srce/*.c") 6613d67099SMatthias Ringwaldfile(GLOB SOURCES_CLASSIC "${BTSTACK_ROOT}/src/classic/*.c") 6713d67099SMatthias Ringwaldfile(GLOB SOURCES_MESH "${BTSTACK_ROOT}/src/mesh/*.c") 6813d67099SMatthias Ringwaldfile(GLOB SOURCES_GATT "${BTSTACK_ROOT}/src/ble/gatt-service/*.c") 6913d67099SMatthias Ringwaldfile(GLOB SOURCES_UECC "${BTSTACK_ROOT}/3rd-party/micro-ecc/uECC.c") 7013d67099SMatthias Ringwaldfile(GLOB SOURCES_HXCMOD "${BTSTACK_ROOT}/3rd-party/hxcmod-player/*.c" "${BTSTACK_ROOT}/3rd-party/hxcmod-player/mods/*.c") 7113d67099SMatthias Ringwaldfile(GLOB SOURCES_MD5 "${BTSTACK_ROOT}/3rd-party/md5/md5.c") 7213d67099SMatthias Ringwaldfile(GLOB SOURCES_RIJNDAEL "${BTSTACK_ROOT}/3rd-party/rijndael/rijndael.c") 7313d67099SMatthias Ringwaldfile(GLOB SOURCES_YXML "${BTSTACK_ROOT}/3rd-party/yxml/yxml.c") 7413d67099SMatthias Ringwaldfile(GLOB SOURCES_POSIX "${BTSTACK_ROOT}/platform/posix/*.c") 7513d67099SMatthias Ringwaldfile(GLOB SOURCES_BCM "${BTSTACK_ROOT}/chipset/bcm/*.c") 7613d67099SMatthias Ringwaldfile(GLOB SOURCES_CSR "${BTSTACK_ROOT}/chipset/csr/*.c") 7713d67099SMatthias Ringwaldfile(GLOB SOURCES_EM9301 "${BTSTACK_ROOT}/chipset/em9301/*.c") 7813d67099SMatthias Ringwaldfile(GLOB SOURCES_STLC2500D "${BTSTACK_ROOT}/chipset/stlc2500d/*.c") 7913d67099SMatthias Ringwaldfile(GLOB SOURCES_TC2566X "${BTSTACK_ROOT}/chipset/tc3566x/*.c") 8013d67099SMatthias Ringwaldfile(GLOB SOURCES_REALTEK "${BTSTACK_ROOT}/chipset/realtek/*.c") 8113d67099SMatthias Ringwaldfile(GLOB SOURCES_ZEPHYR "${BTSTACK_ROOT}/chipset/zephyr/*.c") 8213d67099SMatthias Ringwaldfile(GLOB SOURCES_LC3_GOOGLE "${BTSTACK_ROOT}/3rd-party/lc3-google/src/*.c") 8313d67099SMatthias Ringwaldfile(GLOB SOURCES_PORT "*.c") 8413d67099SMatthias Ringwald 8513d67099SMatthias Ringwaldset(LWIP_CORE_SRC 8613d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/def.c 8713d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/inet_chksum.c 8813d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/init.c 8913d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ip.c 9013d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/mem.c 9113d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/memp.c 9213d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/netif.c 9313d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/pbuf.c 9413d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp.c 9513d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp_in.c 9613d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp_out.c 9713d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/timeouts.c 9813d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/udp.c 9913d67099SMatthias Ringwald ) 10013d67099SMatthias Ringwaldset (LWIP_IPV4_SRC 10113d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/acd.c 10213d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/dhcp.c 10313d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/etharp.c 10413d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/icmp.c 10513d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4.c 10613d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4_addr.c 10713d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4_frag.c 10813d67099SMatthias Ringwald ) 10913d67099SMatthias Ringwaldset (LWIP_NETIF_SRC 11013d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/netif/ethernet.c 11113d67099SMatthias Ringwald ) 11213d67099SMatthias Ringwaldset (LWIP_HTTPD 11313d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/altcp_proxyconnect.c 11413d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/fs.c 11513d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/httpd.c 11613d67099SMatthias Ringwald ) 11713d67099SMatthias Ringwaldset (LWIP_DHCPD 11813d67099SMatthias Ringwald ${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server/dhserver.c 11913d67099SMatthias Ringwald ) 12013d67099SMatthias Ringwaldset (LWIP_PORT 12113d67099SMatthias Ringwald ${BTSTACK_ROOT}/platform/lwip/port/sys_arch.c 12213d67099SMatthias Ringwald ${BTSTACK_ROOT}//platform/lwip/bnep_lwip.c 12313d67099SMatthias Ringwald ) 12413d67099SMatthias Ringwaldset (SOURCES_LWIP ${LWIP_CORE_SRC} ${LWIP_IPV4_SRC} ${LWIP_NETIF_SRC} ${LWIP_HTTPD} ${LWIP_DHCPD} ${LWIP_PORT}) 12513d67099SMatthias Ringwald 12613d67099SMatthias Ringwaldfile(GLOB SOURCES_BLE_OFF "${BTSTACK_ROOT}/src/ble/le_device_db_memory.c") 12713d67099SMatthias Ringwaldlist(REMOVE_ITEM SOURCES_BLE ${SOURCES_BLE_OFF}) 12813d67099SMatthias Ringwald 12913d67099SMatthias Ringwaldfile(GLOB SOURCES_POSIX_OFF "${BTSTACK_ROOT}/platform/posix/le_device_db_fs.c") 13013d67099SMatthias Ringwaldlist(REMOVE_ITEM SOURCES_POSIX ${SOURCES_POSIX_OFF}) 13113d67099SMatthias Ringwald 13213d67099SMatthias Ringwaldset(SOURCES 13313d67099SMatthias Ringwald ${SOURCES_BLE} 13413d67099SMatthias Ringwald ${SOURCES_BCM} 13513d67099SMatthias Ringwald ${SOURCES_BLUEDROID} 13613d67099SMatthias Ringwald ${SOURCES_CLASSIC} 13713d67099SMatthias Ringwald ${SOURCES_CSR} 13813d67099SMatthias Ringwald ${SOURCES_EM9301} 13913d67099SMatthias Ringwald ${SOURCES_GATT} 14013d67099SMatthias Ringwald ${SOURCES_HXCMOD} 14113d67099SMatthias Ringwald ${SOURCES_HXCMOD} 14213d67099SMatthias Ringwald ${SOURCES_LIBUSB} 14313d67099SMatthias Ringwald ${SOURCES_MD5} 14413d67099SMatthias Ringwald ${SOURCES_MESH} 14513d67099SMatthias Ringwald ${SOURCES_PORT} 14613d67099SMatthias Ringwald ${SOURCES_REALTEK} 14713d67099SMatthias Ringwald ${SOURCES_RIJNDAEL} 14813d67099SMatthias Ringwald ${SOURCES_SRC} 14913d67099SMatthias Ringwald ${SOURCES_CSR} 15013d67099SMatthias Ringwald ${SOURCES_STLC2500D} 15113d67099SMatthias Ringwald ${SOURCES_TC2566X} 15213d67099SMatthias Ringwald ${SOURCES_UECC} 15313d67099SMatthias Ringwald ${SOURCES_POSIX} 15413d67099SMatthias Ringwald ${SOURCES_YXML} 15513d67099SMatthias Ringwald ${SOURCES_ZEPHYR} 15613d67099SMatthias Ringwald) 15713d67099SMatthias Ringwaldlist(SORT SOURCES) 15813d67099SMatthias Ringwald 15913d67099SMatthias Ringwald# create static lib 16013d67099SMatthias Ringwaldadd_library(btstack STATIC ${SOURCES}) 16113d67099SMatthias Ringwald 16257f681c0SMatthias Ringwald# pkgconfig 163caeaa206SMatthias Ringwaldfind_package(PkgConfig) 16457f681c0SMatthias Ringwald 16557f681c0SMatthias Ringwald# portaudio 16657f681c0SMatthias Ringwaldif (PkgConfig_FOUND) 167caeaa206SMatthias Ringwald pkg_check_modules(PORTAUDIO portaudio-2.0) 16857f681c0SMatthias Ringwald if(PORTAUDIO_FOUND) 16957f681c0SMatthias Ringwald message("HAVE_PORTAUDIO") 17057f681c0SMatthias Ringwald include_directories(${PORTAUDIO_INCLUDE_DIRS}) 17157f681c0SMatthias Ringwald link_directories(${PORTAUDIO_LIBRARY_DIRS}) 17257f681c0SMatthias Ringwald link_libraries(${PORTAUDIO_LIBRARIES}) 173caeaa206SMatthias Ringwald add_compile_definitions(HAVE_PORTAUDIO) 17457f681c0SMatthias Ringwald endif() 17557f681c0SMatthias Ringwaldendif() 17657f681c0SMatthias Ringwald 177caeaa206SMatthias Ringwald# pthread 178caeaa206SMatthias Ringwaldfind_package(Threads) 179caeaa206SMatthias Ringwaldlink_libraries(${CMAKE_THREAD_LIBS_INIT}) 18057f681c0SMatthias Ringwald 181f495c712SMatthias Ringwald# Add CC256x Support and specify init script 182f495c712SMatthias Ringwaldset (CC256X_INIT_SCRIPT bluetooth_init_cc2564C_1.5.c) 183f495c712SMatthias Ringwaldinclude(${BTSTACK_ROOT}/chipset/cc256x/cc256x.cmake) 184f495c712SMatthias Ringwald 185f495c712SMatthias Ringwald# Add BCM Support and download PatchRAM files 186f495c712SMatthias Ringwaldinclude(${BTSTACK_ROOT}/chipset/bcm/bcm.cmake) 187f495c712SMatthias Ringwald 18813d67099SMatthias Ringwald# get list of examples, skipping mesh_node_demo 18913d67099SMatthias Ringwaldinclude(../../example/CMakeLists.txt) 19013d67099SMatthias Ringwaldset (EXAMPLES ${EXAMPLES_GENERAL} ${EXAMPLES_CLASSIC_ONLY} ${EXAMPLES_LE_ONLY} ${EXAMPLES_DUAL_MODE}) 19113d67099SMatthias Ringwaldlist(REMOVE_DUPLICATES EXAMPLES) 19213d67099SMatthias Ringwaldlist(REMOVE_ITEM EXAMPLES "mesh_node_demo") 19313d67099SMatthias Ringwald 19413d67099SMatthias Ringwald# create targets 19513d67099SMatthias Ringwaldforeach(EXAMPLE ${EXAMPLES}) 19613d67099SMatthias Ringwald # get c file 1971e0ee29bSMatthias Ringwald set (SOURCES_EXAMPLE ${BTSTACK_ROOT}/example/${EXAMPLE}.c) 19813d67099SMatthias Ringwald 19913d67099SMatthias Ringwald # add GATT DB creation 20013d67099SMatthias Ringwald if ( "${EXAMPLES_GATT_FILES}" MATCHES ${EXAMPLE} ) 20113d67099SMatthias Ringwald message("example ${EXAMPLE} -- with GATT DB") 20213d67099SMatthias Ringwald add_custom_command( 20313d67099SMatthias Ringwald OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 20413d67099SMatthias Ringwald DEPENDS ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt 20502bddf72SMatthias Ringwald COMMAND ${Python_EXECUTABLE} 20602bddf72SMatthias Ringwald ARGS ${BTSTACK_ROOT}/tool/compile_gatt.py ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 20713d67099SMatthias Ringwald ) 208bbce5facSMatthias Ringwald list(APPEND SOURCES_EXAMPLE ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h) 20913d67099SMatthias Ringwald else() 21013d67099SMatthias Ringwald message("example ${EXAMPLE}") 21113d67099SMatthias Ringwald endif() 2121e0ee29bSMatthias Ringwald add_executable(${EXAMPLE} ${SOURCES_EXAMPLE}) 213caeaa206SMatthias Ringwald target_link_libraries(${EXAMPLE} btstack pthread) 21413d67099SMatthias Ringwaldendforeach(EXAMPLE) 215