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-posix-h4-zephyr) 7 8SET(BTSTACK_ROOT ${CMAKE_SOURCE_DIR}/../..) 9 10 11# extra compiler warnings 12if ("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang.*") 13 # using Clang 14 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-variable -Wswitch-default -Werror") 15elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") 16 # using GCC 17 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-but-set-variable -Wunused-variable -Wswitch-default -Werror") 18elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel") 19 # using Intel C++ 20elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") 21 # using Visual Studio C++ 22endif() 23 24# to generate .h from .gatt files 25find_package (Python REQUIRED COMPONENTS Interpreter) 26include_directories(${CMAKE_CURRENT_BINARY_DIR}) 27 28# local dir for btstack_config.h after build dir to avoid using .h from Makefile 29include_directories(.) 30 31include_directories(../../3rd-party/micro-ecc) 32include_directories(../../3rd-party/lc3-google/include) 33include_directories(../../3rd-party/md5) 34include_directories(../../3rd-party/hxcmod-player) 35include_directories(../../3rd-party/hxcmod-player/mod) 36include_directories(../../3rd-party/rijndael) 37include_directories(../../src) 38include_directories(../../chipset/zephyr) 39include_directories(../../platform/embedded) 40include_directories(../../platform/posix) 41 42file(GLOB SOURCES_SRC "../../src/*.c") 43file(GLOB SOURCES_BLE "../../src/ble/*.c") 44file(GLOB SOURCES_GATT "../../src/ble/gatt-service/*.c") 45file(GLOB SOURCES_MESH "../../src/mesh/*.c") 46file(GLOB SOURCES_UECC "../../3rd-party/micro-ecc/uECC.c") 47file(GLOB SOURCES_HXCMOD "../../3rd-party/hxcmod-player/*.c" "../../3rd-party/hxcmod-player/mods/*.c") 48file(GLOB SOURCES_RIJNDAEL "../../3rd-party/rijndael/rijndael.c") 49file(GLOB SOURCES_POSIX "../../platform/posix/*.c") 50file(GLOB SOURCES_ZEPHYR "../../chipset/zephyr/*.c") 51file(GLOB SOURCES_LC3_GOOGLE "../../3rd-party/lc3-google/src/*.c") 52file(GLOB SOURCES_PORT "*.c") 53 54file(GLOB SOURCES_BLE_OFF "../../src/ble/le_device_db_memory.c") 55list(REMOVE_ITEM SOURCES_BLE ${SOURCES_BLE_OFF}) 56 57file(GLOB SOURCES_POSIX_OFF "../../platform/posix/le_device_db_fs.c" "../../platform/posix/btstack_link_key_db_fs.c") 58list(REMOVE_ITEM SOURCES_POSIX ${SOURCES_POSIX_OFF}) 59 60set(SOURCES 61 ${SOURCES_BLE} 62 ${SOURCES_GATT} 63 ${SOURCES_HXCMOD} 64 ${SOURCES_LC3_GOOGLE} 65 ${SOURCES_MESH} 66 ${SOURCES_PORT} 67 ${SOURCES_POSIX} 68 ${SOURCES_RIJNDAEL} 69 ${SOURCES_SRC} 70 ${SOURCES_UECC} 71 ${SOURCES_ZEPHYR} 72) 73list(SORT SOURCES) 74 75# create static lib 76add_library(btstack STATIC ${SOURCES}) 77 78# pkgconfig 79find_package(PkgConfig) 80 81# portaudio 82if (PkgConfig_FOUND) 83 pkg_check_modules(PORTAUDIO portaudio-2.0) 84 if(PORTAUDIO_FOUND) 85 message("HAVE_PORTAUDIO") 86 include_directories(${PORTAUDIO_INCLUDE_DIRS}) 87 link_directories(${PORTAUDIO_LIBRARY_DIRS}) 88 link_libraries(${PORTAUDIO_LIBRARIES}) 89 add_compile_definitions(HAVE_PORTAUDIO) 90 endif() 91endif() 92 93# pthread 94find_package(Threads) 95link_libraries(${CMAKE_THREAD_LIBS_INIT}) 96 97# get list of examples 98include(../../example/CMakeLists.txt) 99set (EXAMPLES ${EXAMPLES_LE_ONLY} ${EXAMPLES_GENERAL}) 100 101# create targets 102foreach(EXAMPLE ${EXAMPLES}) 103 # get c file 104 set (SOURCES_EXAMPLE ${BTSTACK_ROOT}/example/${EXAMPLE}.c) 105 106 # add GATT DB creation 107 if ( "${EXAMPLES_GATT_FILES}" MATCHES ${EXAMPLE} ) 108 message("example ${EXAMPLE} -- with GATT DB") 109 add_custom_command( 110 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 111 DEPENDS ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt 112 COMMAND ${Python_EXECUTABLE} 113 ARGS ${BTSTACK_ROOT}/tool/compile_gatt.py ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 114 ) 115 list(APPEND SOURCES_EXAMPLE ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h) 116 else() 117 message("example ${EXAMPLE}") 118 endif() 119 add_executable(${EXAMPLE} ${SOURCES_EXAMPLE}) 120 target_link_libraries(${EXAMPLE} btstack) 121endforeach(EXAMPLE) 122