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