xref: /btstack/port/posix-h4/CMakeLists.txt (revision e3ba22907f903f11cd12321c31e7936b8dd1157e)
1cmake_minimum_required (VERSION 3.18)
2
3project(BTstack-posix-h4)
4
5SET(BTSTACK_ROOT ${CMAKE_SOURCE_DIR}/../..)
6
7# extra compiler warnings
8if ("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang.*")
9	# using Clang
10	SET(CMAKE_C_FLAGS  "${CMAKE_C_FLAGS} -Wunused-variable -Wswitch-default -Werror")
11elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
12	# using GCC
13	SET(CMAKE_C_FLAGS  "${CMAKE_C_FLAGS} -Wunused-but-set-variable -Wunused-variable -Wswitch-default -Werror")
14elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel")
15	# using Intel C++
16elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
17	# using Visual Studio C++
18endif()
19
20# pkgconfig
21find_package(PkgConfig QUIET)
22
23# portaudio
24if (PgConfig_FOUND)
25	pkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0)
26	if(PORTAUDIO_FOUND)
27		message("HAVE_PORTAUDIO")
28		include_directories(${PORTAUDIO_INCLUDE_DIRS})
29		link_directories(${PORTAUDIO_LIBRARY_DIRS})
30		link_libraries(${PORTAUDIO_LIBRARIES})
31		# CMake 3.12 - add_compile_definitions(HAVE_PORTAUDIO)
32		SET(CMAKE_C_FLAGS  "-DHAVE_PORTAUDIO")
33	endif()
34endif()
35
36# to generate .h from .gatt files
37find_package (Python REQUIRED COMPONENTS Interpreter)
38include_directories(${CMAKE_CURRENT_BINARY_DIR})
39
40# local dir for btstack_config.h after build dir to avoid using .h from Makefile
41include_directories(.)
42
43
44include_directories(${BTSTACK_ROOT}/3rd-party/micro-ecc)
45include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/include)
46include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/include)
47include_directories(${BTSTACK_ROOT}/3rd-party/lc3-google/include)
48include_directories(${BTSTACK_ROOT}/3rd-party/md5)
49include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player)
50include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player/mod)
51include_directories(${BTSTACK_ROOT}/3rd-party/lwip/core/src/include)
52include_directories(${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server)
53include_directories(${BTSTACK_ROOT}/3rd-party/rijndael)
54include_directories(${BTSTACK_ROOT}/3rd-party/yxml)
55include_directories(${BTSTACK_ROOT}/3rd-party/tinydir)
56include_directories(${BTSTACK_ROOT}/src)
57include_directories(${BTSTACK_ROOT}/chipset/bcm)
58include_directories(${BTSTACK_ROOT}/chipset/csr)
59include_directories(${BTSTACK_ROOT}/chipset/cc256x)
60include_directories(${BTSTACK_ROOT}/chipset/em9301)
61include_directories(${BTSTACK_ROOT}/chipset/realtek)
62include_directories(${BTSTACK_ROOT}/chipset/tc3566x)
63include_directories(${BTSTACK_ROOT}/chipset/stlc2500d)
64include_directories(${BTSTACK_ROOT}/chipset/zephyr)
65include_directories(${BTSTACK_ROOT}/platform/embedded)
66include_directories(${BTSTACK_ROOT}/platform/lwip)
67include_directories(${BTSTACK_ROOT}/platform/lwip/port)
68include_directories(${BTSTACK_ROOT}/platform/posix)
69
70file(GLOB SOURCES_SRC       "${BTSTACK_ROOT}/src/*.c" "${BTSTACK_ROOT}/example/sco_demo_util.c")
71file(GLOB SOURCES_BLE       "${BTSTACK_ROOT}/src/ble/*.c")
72file(GLOB SOURCES_BLUEDROID "${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/srce/*.c" "${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/srce/*.c")
73file(GLOB SOURCES_CLASSIC   "${BTSTACK_ROOT}/src/classic/*.c")
74file(GLOB SOURCES_MESH      "${BTSTACK_ROOT}/src/mesh/*.c")
75file(GLOB SOURCES_GATT      "${BTSTACK_ROOT}/src/ble/gatt-service/*.c")
76file(GLOB SOURCES_UECC      "${BTSTACK_ROOT}/3rd-party/micro-ecc/uECC.c")
77file(GLOB SOURCES_HXCMOD    "${BTSTACK_ROOT}/3rd-party/hxcmod-player/*.c"  "${BTSTACK_ROOT}/3rd-party/hxcmod-player/mods/*.c")
78file(GLOB SOURCES_MD5       "${BTSTACK_ROOT}/3rd-party/md5/md5.c")
79file(GLOB SOURCES_RIJNDAEL  "${BTSTACK_ROOT}/3rd-party/rijndael/rijndael.c")
80file(GLOB SOURCES_YXML      "${BTSTACK_ROOT}/3rd-party/yxml/yxml.c")
81file(GLOB SOURCES_POSIX     "${BTSTACK_ROOT}/platform/posix/*.c")
82file(GLOB SOURCES_BCM       "${BTSTACK_ROOT}/chipset/bcm/*.c")
83file(GLOB SOURCES_CSR       "${BTSTACK_ROOT}/chipset/csr/*.c")
84file(GLOB SOURCES_EM9301    "${BTSTACK_ROOT}/chipset/em9301/*.c")
85file(GLOB SOURCES_STLC2500D "${BTSTACK_ROOT}/chipset/stlc2500d/*.c")
86file(GLOB SOURCES_TC2566X   "${BTSTACK_ROOT}/chipset/tc3566x/*.c")
87file(GLOB SOURCES_REALTEK   "${BTSTACK_ROOT}/chipset/realtek/*.c")
88file(GLOB SOURCES_ZEPHYR    "${BTSTACK_ROOT}/chipset/zephyr/*.c")
89file(GLOB SOURCES_LC3_GOOGLE "${BTSTACK_ROOT}/3rd-party/lc3-google/src/*.c")
90file(GLOB SOURCES_PORT      "*.c")
91
92set(LWIP_CORE_SRC
93		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/def.c
94		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/inet_chksum.c
95		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/init.c
96		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ip.c
97		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/mem.c
98		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/memp.c
99		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/netif.c
100		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/pbuf.c
101		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp.c
102		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp_in.c
103		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp_out.c
104		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/timeouts.c
105		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/udp.c
106		)
107set (LWIP_IPV4_SRC
108		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/acd.c
109		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/dhcp.c
110		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/etharp.c
111		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/icmp.c
112		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4.c
113		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4_addr.c
114		${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4_frag.c
115		)
116set (LWIP_NETIF_SRC
117		${BTSTACK_ROOT}/3rd-party/lwip/core/src/netif/ethernet.c
118		)
119set (LWIP_HTTPD
120		${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/altcp_proxyconnect.c
121		${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/fs.c
122		${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/httpd.c
123		)
124set (LWIP_DHCPD
125		${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server/dhserver.c
126		)
127set (LWIP_PORT
128		${BTSTACK_ROOT}/platform/lwip/port/sys_arch.c
129		${BTSTACK_ROOT}//platform/lwip/bnep_lwip.c
130		)
131set (SOURCES_LWIP ${LWIP_CORE_SRC} ${LWIP_IPV4_SRC} ${LWIP_NETIF_SRC} ${LWIP_HTTPD} ${LWIP_DHCPD} ${LWIP_PORT})
132
133file(GLOB SOURCES_BLE_OFF "${BTSTACK_ROOT}/src/ble/le_device_db_memory.c")
134list(REMOVE_ITEM SOURCES_BLE   ${SOURCES_BLE_OFF})
135
136file(GLOB SOURCES_POSIX_OFF "${BTSTACK_ROOT}/platform/posix/le_device_db_fs.c")
137list(REMOVE_ITEM SOURCES_POSIX   ${SOURCES_POSIX_OFF})
138
139set(SOURCES
140		${SOURCES_BLE}
141		${SOURCES_BCM}
142		${SOURCES_BLUEDROID}
143		${SOURCES_CLASSIC}
144		${SOURCES_CSR}
145		${SOURCES_EM9301}
146		${SOURCES_GATT}
147		${SOURCES_HXCMOD}
148		${SOURCES_HXCMOD}
149		${SOURCES_LIBUSB}
150		${SOURCES_MD5}
151		${SOURCES_MESH}
152		${SOURCES_PORT}
153		${SOURCES_REALTEK}
154		${SOURCES_RIJNDAEL}
155		${SOURCES_SRC}
156		${SOURCES_CSR}
157		${SOURCES_STLC2500D}
158		${SOURCES_TC2566X}
159		${SOURCES_UECC}
160		${SOURCES_POSIX}
161		${SOURCES_YXML}
162		${SOURCES_ZEPHYR}
163)
164list(SORT SOURCES)
165
166# create static lib
167add_library(btstack STATIC ${SOURCES})
168
169# Add CC256x Support and specify init script
170set (CC256X_INIT_SCRIPT bluetooth_init_cc2564C_1.5.c)
171include(${BTSTACK_ROOT}/chipset/cc256x/cc256x.cmake)
172
173# Add BCM Support and download PatchRAM files
174include(${BTSTACK_ROOT}/chipset/bcm/bcm.cmake)
175
176# get list of examples, skipping mesh_node_demo
177include(../../example/CMakeLists.txt)
178set (EXAMPLES ${EXAMPLES_GENERAL} ${EXAMPLES_CLASSIC_ONLY}  ${EXAMPLES_LE_ONLY} ${EXAMPLES_DUAL_MODE})
179list(REMOVE_DUPLICATES EXAMPLES)
180list(REMOVE_ITEM EXAMPLES "mesh_node_demo")
181
182# create targets
183foreach(EXAMPLE ${EXAMPLES})
184	# get c file
185	set (SOURCES_EXAMPLE ${BTSTACK_ROOT}/example/${EXAMPLE}.c)
186
187	# add GATT DB creation
188	if ( "${EXAMPLES_GATT_FILES}" MATCHES ${EXAMPLE} )
189		message("example ${EXAMPLE} -- with GATT DB")
190	  	add_custom_command(
191		    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h
192			DEPENDS ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt
193			COMMAND ${Python_EXECUTABLE}
194			ARGS ${BTSTACK_ROOT}/tool/compile_gatt.py ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h
195		)
196		list(APPEND SOURCES_EXAMPLE ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h)
197	else()
198		message("example ${EXAMPLE}")
199	endif()
200	add_executable(${EXAMPLE} ${SOURCES_EXAMPLE})
201	target_link_libraries(${EXAMPLE} btstack)
202endforeach(EXAMPLE)
203