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 8*dce6d7b3SMatthias RingwaldSET(BTSTACK_ROOT ${CMAKE_SOURCE_DIR}/../..) 9*dce6d7b3SMatthias Ringwald 1005e00d57SMatthias Ringwald# pkgconfig 1105e00d57SMatthias Ringwaldfind_package(PkgConfig REQUIRED) 1205e00d57SMatthias Ringwald 1305e00d57SMatthias Ringwald# portaudio 1405e00d57SMatthias Ringwaldpkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0) 1505e00d57SMatthias Ringwaldif(PORTAUDIO_FOUND) 1605e00d57SMatthias Ringwald message("HAVE_PORTAUDIO") 1705e00d57SMatthias Ringwald include_directories(${PORTAUDIO_INCLUDE_DIRS}) 1805e00d57SMatthias Ringwald link_directories(${PORTAUDIO_LIBRARY_DIRS}) 1905e00d57SMatthias Ringwald link_libraries(${PORTAUDIO_LIBRARIES}) 2005e00d57SMatthias Ringwald # CMake 3.12 - add_compile_definitions(HAVE_PORTAUDIO) 2105e00d57SMatthias Ringwald SET(CMAKE_C_FLAGS "-DHAVE_PORTAUDIO") 2205e00d57SMatthias Ringwaldendif() 2305e00d57SMatthias Ringwald 2405e00d57SMatthias Ringwald# pthread 2505e00d57SMatthias Ringwaldfind_package(Threads) 2605e00d57SMatthias Ringwaldlink_libraries(${CMAKE_THREAD_LIBS_INIT}) 2705e00d57SMatthias Ringwald 2805e00d57SMatthias Ringwald# extra compiler warnings 2905e00d57SMatthias Ringwaldif ("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang.*") 3005e00d57SMatthias Ringwald # using Clang 3105e00d57SMatthias Ringwald SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-variable -Wswitch-default -Werror") 3205e00d57SMatthias Ringwaldelseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") 3305e00d57SMatthias Ringwald # using GCC 3405e00d57SMatthias Ringwald SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-but-set-variable -Wunused-variable -Wswitch-default -Werror") 3505e00d57SMatthias Ringwaldelseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel") 3605e00d57SMatthias Ringwald # using Intel C++ 3705e00d57SMatthias Ringwaldelseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") 3805e00d57SMatthias Ringwald # using Visual Studio C++ 3905e00d57SMatthias Ringwaldendif() 4005e00d57SMatthias Ringwald 4102bddf72SMatthias Ringwald# to generate .h from .gatt files 4202bddf72SMatthias Ringwaldfind_package (Python REQUIRED COMPONENTS Interpreter) 4305e00d57SMatthias Ringwaldinclude_directories(${CMAKE_CURRENT_BINARY_DIR}) 4405e00d57SMatthias Ringwald 4505e00d57SMatthias Ringwald# local dir for btstack_config.h after build dir to avoid using .h from Makefile 4605e00d57SMatthias Ringwaldinclude_directories(.) 4705e00d57SMatthias Ringwald 4805e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/micro-ecc) 4905e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/lc3-google/include) 5005e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/md5) 5105e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/hxcmod-player) 5205e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/hxcmod-player/mod) 5305e00d57SMatthias Ringwaldinclude_directories(../../3rd-party/rijndael) 5405e00d57SMatthias Ringwaldinclude_directories(../../src) 5505e00d57SMatthias Ringwaldinclude_directories(../../chipset/zephyr) 5605e00d57SMatthias Ringwaldinclude_directories(../../platform/embedded) 5705e00d57SMatthias Ringwaldinclude_directories(../../platform/posix) 5805e00d57SMatthias Ringwald 5905e00d57SMatthias Ringwaldfile(GLOB SOURCES_SRC "../../src/*.c") 6005e00d57SMatthias Ringwaldfile(GLOB SOURCES_BLE "../../src/ble/*.c") 6105e00d57SMatthias Ringwaldfile(GLOB SOURCES_GATT "../../src/ble/gatt-service/*.c") 6205e00d57SMatthias Ringwaldfile(GLOB SOURCES_MESH "../../src/mesh/*.c") 6305e00d57SMatthias Ringwaldfile(GLOB SOURCES_UECC "../../3rd-party/micro-ecc/uECC.c") 6405e00d57SMatthias Ringwaldfile(GLOB SOURCES_HXCMOD "../../3rd-party/hxcmod-player/*.c" "../../3rd-party/hxcmod-player/mods/*.c") 6505e00d57SMatthias Ringwaldfile(GLOB SOURCES_RIJNDAEL "../../3rd-party/rijndael/rijndael.c") 6605e00d57SMatthias Ringwaldfile(GLOB SOURCES_POSIX "../../platform/posix/*.c") 6705e00d57SMatthias Ringwaldfile(GLOB SOURCES_ZEPHYR "../../chipset/zephyr/*.c") 6805e00d57SMatthias Ringwaldfile(GLOB SOURCES_LC3_GOOGLE "../../3rd-party/lc3-google/src/*.c") 6905e00d57SMatthias Ringwaldfile(GLOB SOURCES_PORT "*.c") 7005e00d57SMatthias Ringwald 7105e00d57SMatthias Ringwaldfile(GLOB SOURCES_BLE_OFF "../../src/ble/le_device_db_memory.c") 7205e00d57SMatthias Ringwaldlist(REMOVE_ITEM SOURCES_BLE ${SOURCES_BLE_OFF}) 7305e00d57SMatthias Ringwald 7405e00d57SMatthias Ringwaldfile(GLOB SOURCES_POSIX_OFF "../../platform/posix/le_device_db_fs.c" "../../platform/posix/btstack_link_key_db_fs.c") 7505e00d57SMatthias Ringwaldlist(REMOVE_ITEM SOURCES_POSIX ${SOURCES_POSIX_OFF}) 7605e00d57SMatthias Ringwald 7705e00d57SMatthias Ringwaldset(SOURCES 7805e00d57SMatthias Ringwald ${SOURCES_BLE} 7905e00d57SMatthias Ringwald ${SOURCES_GATT} 8005e00d57SMatthias Ringwald ${SOURCES_HXCMOD} 8105e00d57SMatthias Ringwald ${SOURCES_LC3_GOOGLE} 8205e00d57SMatthias Ringwald ${SOURCES_MESH} 8305e00d57SMatthias Ringwald ${SOURCES_PORT} 8405e00d57SMatthias Ringwald ${SOURCES_POSIX} 8505e00d57SMatthias Ringwald ${SOURCES_RIJNDAEL} 8605e00d57SMatthias Ringwald ${SOURCES_SRC} 8705e00d57SMatthias Ringwald ${SOURCES_UECC} 8805e00d57SMatthias Ringwald ${SOURCES_ZEPHYR} 8905e00d57SMatthias Ringwald) 9005e00d57SMatthias Ringwaldlist(SORT SOURCES) 9105e00d57SMatthias Ringwald 9205e00d57SMatthias Ringwald# create static lib 9305e00d57SMatthias Ringwaldadd_library(btstack STATIC ${SOURCES}) 9405e00d57SMatthias Ringwald 9505e00d57SMatthias Ringwald# get list of examples 9605e00d57SMatthias Ringwaldinclude(../../example/CMakeLists.txt) 9705e00d57SMatthias Ringwaldset (EXAMPLES ${EXAMPLES_LE_ONLY} ${EXAMPLES_GENERAL}) 9805e00d57SMatthias Ringwald 9905e00d57SMatthias Ringwald# create targets 10005e00d57SMatthias Ringwaldset (EXAMPLES_C) 10105e00d57SMatthias Ringwaldforeach(EXAMPLE ${EXAMPLES}) 10205e00d57SMatthias Ringwald # get c file 10305e00d57SMatthias Ringwald file(GLOB EXAMPLE_FILE "../../example/${EXAMPLE}.c") 10405e00d57SMatthias Ringwald 10505e00d57SMatthias Ringwald # add GATT DB creation 10605e00d57SMatthias Ringwald if ( "${EXAMPLES_GATT_FILES}" MATCHES ${EXAMPLE} ) 10705e00d57SMatthias Ringwald message("example ${EXAMPLE} -- with GATT DB") 10805e00d57SMatthias Ringwald add_custom_command( 10905e00d57SMatthias Ringwald OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 11002bddf72SMatthias Ringwald DEPENDS ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt 11102bddf72SMatthias Ringwald COMMAND ${Python_EXECUTABLE} 11202bddf72SMatthias Ringwald ARGS ${BTSTACK_ROOT}/tool/compile_gatt.py ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h 11305e00d57SMatthias Ringwald ) 11405e00d57SMatthias Ringwald list(APPEND SOURCE_FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h) 11505e00d57SMatthias Ringwald else() 11605e00d57SMatthias Ringwald message("example ${EXAMPLE}") 11705e00d57SMatthias Ringwald endif() 11805e00d57SMatthias Ringwald add_executable(${EXAMPLE} ${EXAMPLE_FILE} ) 11905e00d57SMatthias Ringwald target_link_libraries(${EXAMPLE} btstack) 12005e00d57SMatthias Ringwaldendforeach(EXAMPLE) 121