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