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 8SET(BTSTACK_ROOT ${CMAKE_SOURCE_DIR}/../..) 9 10# pkgconfig 11find_package(PkgConfig QUIET) 12 13# portaudio 14if (PkgConfig_FOUND) 15 pkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0) 16 if(PORTAUDIO_FOUND) 17 message("HAVE_PORTAUDIO") 18 include_directories(${PORTAUDIO_INCLUDE_DIRS}) 19 link_directories(${PORTAUDIO_LIBRARY_DIRS}) 20 link_libraries(${PORTAUDIO_LIBRARIES}) 21 # CMake 3.12 - add_compile_definitions(HAVE_PORTAUDIO) 22 SET(CMAKE_C_FLAGS "-DHAVE_PORTAUDIO") 23 endif() 24endif() 25 26# pthread 27find_package(Threads) 28link_libraries(${CMAKE_THREAD_LIBS_INIT}) 29 30# extra compiler warnings 31if ("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang.*") 32 # using Clang 33 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-variable -Wswitch-default -Werror") 34elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") 35 # using GCC 36 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-but-set-variable -Wunused-variable -Wswitch-default -Werror") 37elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel") 38 # using Intel C++ 39elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") 40 # using Visual Studio C++ 41endif() 42 43# to generate .h from .gatt files 44find_package (Python REQUIRED COMPONENTS Interpreter) 45include_directories(${CMAKE_CURRENT_BINARY_DIR}) 46 47# local dir for btstack_config.h after build dir to avoid using .h from Makefile 48include_directories(.) 49 50include_directories(../../3rd-party/micro-ecc) 51include_directories(../../3rd-party/lc3-google/include) 52include_directories(../../3rd-party/md5) 53include_directories(../../3rd-party/hxcmod-player) 54include_directories(../../3rd-party/hxcmod-player/mod) 55include_directories(../../3rd-party/rijndael) 56include_directories(../../src) 57include_directories(../../chipset/zephyr) 58include_directories(../../platform/embedded) 59include_directories(../../platform/posix) 60 61file(GLOB SOURCES_SRC "../../src/*.c") 62file(GLOB SOURCES_BLE "../../src/ble/*.c") 63file(GLOB SOURCES_GATT "../../src/ble/gatt-service/*.c") 64file(GLOB SOURCES_MESH "../../src/mesh/*.c") 65file(GLOB SOURCES_UECC "../../3rd-party/micro-ecc/uECC.c") 66file(GLOB SOURCES_HXCMOD "../../3rd-party/hxcmod-player/*.c" "../../3rd-party/hxcmod-player/mods/*.c") 67file(GLOB SOURCES_RIJNDAEL "../../3rd-party/rijndael/rijndael.c") 68file(GLOB SOURCES_POSIX "../../platform/posix/*.c") 69file(GLOB SOURCES_ZEPHYR "../../chipset/zephyr/*.c") 70file(GLOB SOURCES_LC3_GOOGLE "../../3rd-party/lc3-google/src/*.c") 71file(GLOB SOURCES_PORT "*.c") 72 73file(GLOB SOURCES_BLE_OFF "../../src/ble/le_device_db_memory.c") 74list(REMOVE_ITEM SOURCES_BLE ${SOURCES_BLE_OFF}) 75 76file(GLOB SOURCES_POSIX_OFF "../../platform/posix/le_device_db_fs.c" "../../platform/posix/btstack_link_key_db_fs.c") 77list(REMOVE_ITEM SOURCES_POSIX ${SOURCES_POSIX_OFF}) 78 79set(SOURCES 80 ${SOURCES_BLE} 81 ${SOURCES_GATT} 82 ${SOURCES_HXCMOD} 83 ${SOURCES_LC3_GOOGLE} 84 ${SOURCES_MESH} 85 ${SOURCES_PORT} 86 ${SOURCES_POSIX} 87 ${SOURCES_RIJNDAEL} 88 ${SOURCES_SRC} 89 ${SOURCES_UECC} 90 ${SOURCES_ZEPHYR} 91) 92list(SORT SOURCES) 93 94# create static lib 95add_library(btstack STATIC ${SOURCES}) 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