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