105e00d57SMatthias Ringwaldcmake_minimum_required (VERSION 3.5) 205e00d57SMatthias Ringwald 305e00d57SMatthias RingwaldSET(CMAKE_OSX_SYSROOT /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk) 405e00d57SMatthias RingwaldSET(CMAKE_EXPORT_COMPILE_COMMANDS ON) 505e00d57SMatthias Ringwald 605e00d57SMatthias Ringwaldproject(BTstack-posix-h4-zephyr) 705e00d57SMatthias Ringwald 8dce6d7b3SMatthias RingwaldSET(BTSTACK_ROOT ${CMAKE_SOURCE_DIR}/../..) 9dce6d7b3SMatthias Ringwald 1005e00d57SMatthias Ringwald 1105e00d57SMatthias Ringwald# extra compiler warnings 1205e00d57SMatthias Ringwaldif ("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang.*") 1305e00d57SMatthias Ringwald # using Clang 1405e00d57SMatthias Ringwald SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-variable -Wswitch-default -Werror") 1505e00d57SMatthias Ringwaldelseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") 1605e00d57SMatthias Ringwald # using GCC 1705e00d57SMatthias Ringwald SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-but-set-variable -Wunused-variable -Wswitch-default -Werror") 1805e00d57SMatthias Ringwaldelseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel") 1905e00d57SMatthias Ringwald # using Intel C++ 2005e00d57SMatthias Ringwaldelseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") 2105e00d57SMatthias Ringwald # using Visual Studio C++ 2205e00d57SMatthias Ringwaldendif() 2305e00d57SMatthias Ringwald 2402bddf72SMatthias Ringwald# to generate .h from .gatt files 2502bddf72SMatthias Ringwaldfind_package (Python REQUIRED COMPONENTS Interpreter) 2605e00d57SMatthias Ringwaldinclude_directories(${CMAKE_CURRENT_BINARY_DIR}) 2705e00d57SMatthias Ringwald 2805e00d57SMatthias Ringwald# local dir for btstack_config.h after build dir to avoid using .h from Makefile 2905e00d57SMatthias Ringwaldinclude_directories(.) 3005e00d57SMatthias Ringwald 3105e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/micro-ecc) 3205e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/lc3-google/include) 3305e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/md5) 3405e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/hxcmod-player) 3505e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/hxcmod-player/mod) 3605e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/rijndael) 3705e00d57SMatthias Ringwaldinclude_directories(../../src) 3805e00d57SMatthias Ringwaldinclude_directories(../../chipset/zephyr) 3905e00d57SMatthias Ringwaldinclude_directories(../../platform/embedded) 4005e00d57SMatthias Ringwaldinclude_directories(../../platform/posix) 4105e00d57SMatthias Ringwald 4205e00d57SMatthias Ringwaldfile(GLOB SOURCES_SRC "../../src/*.c") 4305e00d57SMatthias Ringwaldfile(GLOB SOURCES_BLE "../../src/ble/*.c") 4405e00d57SMatthias Ringwaldfile(GLOB SOURCES_GATT "../../src/ble/gatt-service/*.c") 4505e00d57SMatthias Ringwaldfile(GLOB SOURCES_MESH "../../src/mesh/*.c") 4605e00d57SMatthias Ringwaldfile(GLOB SOURCES_UECC "../../3rd-party/micro-ecc/uECC.c") 4705e00d57SMatthias Ringwaldfile(GLOB SOURCES_HXCMOD "../../3rd-party/hxcmod-player/*.c" "../../3rd-party/hxcmod-player/mods/*.c") 4805e00d57SMatthias Ringwaldfile(GLOB SOURCES_RIJNDAEL "../../3rd-party/rijndael/rijndael.c") 4905e00d57SMatthias Ringwaldfile(GLOB SOURCES_POSIX "../../platform/posix/*.c") 5005e00d57SMatthias Ringwaldfile(GLOB SOURCES_ZEPHYR "../../chipset/zephyr/*.c") 5105e00d57SMatthias Ringwaldfile(GLOB SOURCES_LC3_GOOGLE "../../3rd-party/lc3-google/src/*.c") 5205e00d57SMatthias Ringwaldfile(GLOB SOURCES_PORT "*.c") 5305e00d57SMatthias Ringwald 5405e00d57SMatthias Ringwaldfile(GLOB SOURCES_BLE_OFF "../../src/ble/le_device_db_memory.c") 5505e00d57SMatthias Ringwaldlist(REMOVE_ITEM SOURCES_BLE ${SOURCES_BLE_OFF}) 5605e00d57SMatthias Ringwald 5705e00d57SMatthias Ringwaldfile(GLOB SOURCES_POSIX_OFF "../../platform/posix/le_device_db_fs.c" "../../platform/posix/btstack_link_key_db_fs.c") 5805e00d57SMatthias Ringwaldlist(REMOVE_ITEM SOURCES_POSIX ${SOURCES_POSIX_OFF}) 5905e00d57SMatthias Ringwald 6005e00d57SMatthias Ringwaldset(SOURCES 6105e00d57SMatthias Ringwald ${SOURCES_BLE} 6205e00d57SMatthias Ringwald ${SOURCES_GATT} 6305e00d57SMatthias Ringwald ${SOURCES_HXCMOD} 6405e00d57SMatthias Ringwald ${SOURCES_LC3_GOOGLE} 6505e00d57SMatthias Ringwald ${SOURCES_MESH} 6605e00d57SMatthias Ringwald ${SOURCES_PORT} 6705e00d57SMatthias Ringwald ${SOURCES_POSIX} 6805e00d57SMatthias Ringwald ${SOURCES_RIJNDAEL} 6905e00d57SMatthias Ringwald ${SOURCES_SRC} 7005e00d57SMatthias Ringwald ${SOURCES_UECC} 7105e00d57SMatthias Ringwald ${SOURCES_ZEPHYR} 7205e00d57SMatthias Ringwald) 7305e00d57SMatthias Ringwaldlist(SORT SOURCES) 7405e00d57SMatthias Ringwald 7505e00d57SMatthias Ringwald# create static lib 7605e00d57SMatthias Ringwaldadd_library(btstack STATIC ${SOURCES}) 7705e00d57SMatthias Ringwald 78*57f681c0SMatthias Ringwald# pkgconfig 79*57f681c0SMatthias Ringwaldfind_package(PkgConfig QUIET) 80*57f681c0SMatthias Ringwald 81*57f681c0SMatthias Ringwald# portaudio 82*57f681c0SMatthias Ringwaldif (PkgConfig_FOUND) 83*57f681c0SMatthias Ringwald pkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0) 84*57f681c0SMatthias Ringwald if(PORTAUDIO_FOUND) 85*57f681c0SMatthias Ringwald message("HAVE_PORTAUDIO") 86*57f681c0SMatthias Ringwald include_directories(${PORTAUDIO_INCLUDE_DIRS}) 87*57f681c0SMatthias Ringwald link_directories(${PORTAUDIO_LIBRARY_DIRS}) 88*57f681c0SMatthias Ringwald link_libraries(${PORTAUDIO_LIBRARIES}) 89*57f681c0SMatthias Ringwald # CMake 3.12 - add_compile_definitions(HAVE_PORTAUDIO) 90*57f681c0SMatthias Ringwald SET(CMAKE_C_FLAGS "-DHAVE_PORTAUDIO") 91*57f681c0SMatthias Ringwald endif() 92*57f681c0SMatthias Ringwaldendif() 93*57f681c0SMatthias Ringwald 94*57f681c0SMatthias Ringwald# pthread 95*57f681c0SMatthias Ringwaldfind_package(Threads) 96*57f681c0SMatthias Ringwaldlink_libraries(${CMAKE_THREAD_LIBS_INIT}) 97*57f681c0SMatthias Ringwald 98*57f681c0SMatthias Ringwald 9905e00d57SMatthias Ringwald# get list of examples 10005e00d57SMatthias Ringwaldinclude(../../example/CMakeLists.txt) 10105e00d57SMatthias Ringwaldset (EXAMPLES ${EXAMPLES_LE_ONLY} ${EXAMPLES_GENERAL}) 10205e00d57SMatthias Ringwald 10305e00d57SMatthias Ringwald# create targets 10405e00d57SMatthias Ringwaldforeach(EXAMPLE ${EXAMPLES}) 10505e00d57SMatthias Ringwald # get c file 1061e0ee29bSMatthias Ringwald set (SOURCES_EXAMPLE ${BTSTACK_ROOT}/example/${EXAMPLE}.c) 10705e00d57SMatthias Ringwald 10805e00d57SMatthias Ringwald # add GATT DB creation 10905e00d57SMatthias Ringwald if ( "${EXAMPLES_GATT_FILES}" MATCHES ${EXAMPLE} ) 11005e00d57SMatthias Ringwald message("example ${EXAMPLE} -- with GATT DB") 11105e00d57SMatthias Ringwald add_custom_command( 11205e00d57SMatthias Ringwald OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 11302bddf72SMatthias Ringwald DEPENDS ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt 11402bddf72SMatthias Ringwald COMMAND ${Python_EXECUTABLE} 11502bddf72SMatthias Ringwald ARGS ${BTSTACK_ROOT}/tool/compile_gatt.py ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 11605e00d57SMatthias Ringwald ) 117bbce5facSMatthias Ringwald list(APPEND SOURCES_EXAMPLE ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h) 11805e00d57SMatthias Ringwald else() 11905e00d57SMatthias Ringwald message("example ${EXAMPLE}") 12005e00d57SMatthias Ringwald endif() 1211e0ee29bSMatthias Ringwald add_executable(${EXAMPLE} ${SOURCES_EXAMPLE}) 12205e00d57SMatthias Ringwald target_link_libraries(${EXAMPLE} btstack) 12305e00d57SMatthias Ringwaldendforeach(EXAMPLE) 124