-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
145 lines (120 loc) · 4.61 KB
/
CMakeLists.txt
File metadata and controls
145 lines (120 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# CMakeLists.txt for microOpus
# Supports both ESP-IDF component builds and standalone host builds
#
# This build system uses a staging approach:
# 1. Copies the opus submodule to the build directory
# 2. Applies patches using standard .patch files
# 3. Builds from the staged (patched) copy
#
# This keeps the original submodule pristine.
#
# Structure:
# cmake/sources.cmake - Source file definitions (function-based)
# cmake/functions.cmake - Helper functions
# cmake/staging.cmake - Staging directory and patching system
# cmake/config.h.in - Config header template
# cmake/esp-idf.cmake - ESP-IDF specific configuration
# cmake/host.cmake - Host platform configuration
# patches/diffs/ - Patch files (.patch format)
# ==============================================================================
# Build type detection
# ==============================================================================
if(DEFINED IDF_TARGET)
set(ESP_IDF_BUILD TRUE)
else()
set(ESP_IDF_BUILD FALSE)
endif()
# Set source directory variable for consistent use
if(ESP_IDF_BUILD)
set(OPUS_COMPONENT_DIR ${COMPONENT_DIR})
else()
set(OPUS_COMPONENT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()
# ==============================================================================
# Include CMake modules
# ==============================================================================
include(${OPUS_COMPONENT_DIR}/cmake/sources.cmake)
include(${OPUS_COMPONENT_DIR}/cmake/functions.cmake)
include(${OPUS_COMPONENT_DIR}/cmake/staging.cmake)
# ==============================================================================
# ESP-IDF Build
# ==============================================================================
if(ESP_IDF_BUILD)
include(${OPUS_COMPONENT_DIR}/cmake/esp-idf.cmake)
# Get IDF target
idf_build_get_property(target IDF_TARGET)
# Setup staged build directory with patches
# Apply Xtensa patches if enabled via Kconfig (default on for ESP32/ESP32-S3)
if(CONFIG_OPUS_ENABLE_XTENSA_OPTIMIZATIONS)
opus_setup_staged_build(${COMPONENT_DIR} TRUE)
else()
opus_setup_staged_build(${COMPONENT_DIR} FALSE)
endif()
# Get sources using staged directory
opus_get_sources(${OPUS_STAGED_DIR})
# Collect all sources
set(ESP_OPUS_SOURCES
${OPUS_BASE_SOURCES}
${OPUS_DECODER_SOURCES}
${OPUS_ENCODER_SOURCES}
${OGG_OPUS_SOURCES}
${CELT_SOURCES}
${SILK_BASE_SOURCES}
)
# Add thread-local storage if needed
if(CONFIG_OPUS_THREADSAFE_PSEUDOSTACK)
list(APPEND ESP_OPUS_SOURCES ${THREAD_LOCAL_SOURCES})
endif()
# Register the component
idf_component_register(
SRCS ${ESP_OPUS_SOURCES}
INCLUDE_DIRS
"${OPUS_STAGED_DIR}/include"
"include"
"${OPUS_STAGED_DIR}"
"${OPUS_STAGED_DIR}/celt"
"${OPUS_STAGED_DIR}/silk"
"${OPUS_STAGED_DIR}/silk/float"
"${OPUS_STAGED_DIR}/silk/fixed"
"."
PRIV_REQUIRES esp_timer # Needed for timing profilers
)
# Apply ESP-IDF configuration
opus_configure_esp_idf(${COMPONENT_LIB} ${COMPONENT_DIR} ${OPUS_STAGED_DIR})
# ==============================================================================
# Host Build
# ==============================================================================
else()
cmake_minimum_required(VERSION 3.16)
project(micro_opus C CXX)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/host.cmake)
# Option for memory allocation mode
set(OPUS_ALLOCATION_MODE "THREADSAFE_PSEUDOSTACK" CACHE STRING "Memory allocation mode")
set_property(CACHE OPUS_ALLOCATION_MODE PROPERTY STRINGS
"THREADSAFE_PSEUDOSTACK"
"NONTHREADSAFE_PSEUDOSTACK"
"USE_ALLOCA"
)
# Setup staged build directory (no Xtensa patches for host)
opus_setup_staged_build(${CMAKE_CURRENT_SOURCE_DIR} FALSE)
# Get sources using staged directory
opus_get_sources(${OPUS_STAGED_DIR})
# Collect all sources
set(HOST_OPUS_SOURCES
${OPUS_BASE_SOURCES}
${OPUS_DECODER_SOURCES}
${OPUS_ENCODER_SOURCES}
${OGG_OPUS_SOURCES}
${CELT_SOURCES}
${SILK_BASE_SOURCES}
${SILK_FIXED_SOURCES}
)
# Add thread-local storage if needed
if(OPUS_ALLOCATION_MODE STREQUAL "THREADSAFE_PSEUDOSTACK")
list(APPEND HOST_OPUS_SOURCES ${THREAD_LOCAL_SOURCES})
endif()
# Create the library
add_library(micro_opus STATIC ${HOST_OPUS_SOURCES})
# Apply host configuration
opus_configure_host(micro_opus ${CMAKE_CURRENT_SOURCE_DIR} ${OPUS_STAGED_DIR})
endif()