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