Skip to content

Commit 7680a7b

Browse files
jajanuszlgirdwood
authored andcommitted
cmake: add testbench host build
Signed-off-by: Janusz Jankowski <janusz.jankowski@linux.intel.com>
1 parent d2528e1 commit 7680a7b

7 files changed

Lines changed: 170 additions & 32 deletions

File tree

CMakeLists.txt

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ if(NOT (${CMAKE_VERSION} VERSION_LESS "3.13.0"))
77
cmake_policy(SET CMP0079 OLD)
88
endif()
99

10-
# firmware build supports only xtensa arch for now
11-
set(ARCH xtensa)
10+
# TODO: take `host` out of fw build
11+
option(BUILD_HOST "Build host program" OFF)
12+
13+
if(BUILD_HOST)
14+
set(ARCH host)
15+
else()
16+
# firmware build supports only xtensa arch for now
17+
set(ARCH xtensa)
18+
endif()
1219

1320
# let user override built-in toolchains
1421
if(DEFINED CMAKE_TOOLCHAIN_FILE)
@@ -21,6 +28,21 @@ include(scripts/cmake/misc.cmake)
2128

2229
project(SOF C ASM)
2330

31+
# most of other options are set on per-arch and per-target basis
32+
set(CMAKE_ASM_FLAGS -DASSEMBLY)
33+
34+
# interface library that is used only as container for sof binary options
35+
# other targets can use it to build with the same options
36+
add_library(sof_options INTERFACE)
37+
38+
target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/include)
39+
40+
if(BUILD_HOST)
41+
add_subdirectory(src)
42+
# rest of this file is not needed for host build
43+
return()
44+
endif()
45+
2446
set(PYTHON3 python3)
2547

2648
# get compiler name and version
@@ -84,15 +106,6 @@ add_custom_command(OUTPUT ${CONFIG_H_PATH}
84106

85107
add_custom_target(genconfig DEPENDS ${CONFIG_H_PATH})
86108

87-
# most of other options are set on per-arch basis
88-
set(CMAKE_ASM_FLAGS -DASSEMBLY)
89-
90-
# interface library that is used only as container for sof binary options
91-
# other targets can use it to build with the same options
92-
add_library(sof_options INTERFACE)
93-
94-
add_dependencies(sof_options genconfig)
95-
96109
add_library(sof_ld_flags INTERFACE)
97110
add_library(sof_ld_scripts INTERFACE)
98111

@@ -103,8 +116,6 @@ target_link_libraries(sof sof_ld_scripts)
103116
target_link_libraries(sof sof_ld_flags)
104117

105118
add_dependencies(sof_options genconfig)
106-
107-
target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/include)
108119
target_include_directories(sof_options INTERFACE ${GENERATED_DIRECTORY}/include)
109120

110121
add_subdirectory(src)

src/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
add_subdirectory(arch)
22

3+
if(BUILD_HOST)
4+
add_subdirectory(ipc)
5+
add_subdirectory(audio)
6+
add_subdirectory(host)
7+
return()
8+
endif()
9+
310
add_subdirectory(audio)
411
add_subdirectory(drivers)
512
add_subdirectory(init)

src/arch/host/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# includes
2+
set(GENERATED_DIRECTORY ${PROJECT_BINARY_DIR}/generated)
3+
file(MAKE_DIRECTORY ${GENERATED_DIRECTORY}/include)
4+
5+
target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/arch/host/include)
6+
target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/library/include)
7+
target_include_directories(sof_options INTERFACE ${GENERATED_DIRECTORY}/include)
8+
9+
# TODO: add Kconfig support also for testbench when it'll be decoupled from fw
10+
set(CONFIG_HOST 1)
11+
set(CONFIG_LIB 1)
12+
13+
configure_file (
14+
"${PROJECT_SOURCE_DIR}/src/arch/host/config.h.in"
15+
"${GENERATED_DIRECTORY}/include/config.h"
16+
)
17+
18+
# linker flags
19+
target_link_libraries(sof_options INTERFACE -lpthread)
20+
21+
# C & ASM flags
22+
target_compile_options(sof_options INTERFACE -g -O3 -Wall -Werror -Wl,-EL -Wmissing-prototypes -Wimplicit-fallthrough=3)

src/arch/host/config.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define CONFIG_HOST @CONFIG_HOST@
2+
#define CONFIG_LIB @CONFIG_LIB@

src/audio/CMakeLists.txt

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,90 @@
1-
add_local_sources(sof
2-
eq_iir.c
3-
iir.c
4-
eq_fir.c
5-
fir.c
6-
fir_hifi2ep.c
7-
fir_hifi3.c
8-
tone.c
9-
src.c
10-
src_generic.c
11-
src_hifi2ep.c
12-
src_hifi3.c
13-
mixer.c
14-
mux.c
15-
volume.c
16-
volume_generic.c
17-
volume_hifi3.c
18-
switch.c
1+
if(NOT BUILD_HOST)
2+
add_local_sources(sof
3+
eq_iir.c
4+
iir.c
5+
eq_fir.c
6+
fir.c
7+
fir_hifi2ep.c
8+
fir_hifi3.c
9+
tone.c
10+
src.c
11+
src_generic.c
12+
src_hifi2ep.c
13+
src_hifi3.c
14+
mixer.c
15+
mux.c
16+
volume.c
17+
volume_generic.c
18+
volume_hifi3.c
19+
switch.c
20+
dai.c
21+
host.c
22+
pipeline.c
23+
pipeline_static.c
24+
component.c
25+
buffer.c
26+
)
27+
return()
28+
endif()
29+
30+
add_library(sof_audio_core SHARED "")
31+
target_link_libraries(sof_audio_core PRIVATE sof_options)
32+
target_link_libraries(sof_audio_core PRIVATE -Wl,--export-dynamic)
33+
add_local_sources(sof_audio_core
1934
dai.c
2035
host.c
2136
pipeline.c
22-
pipeline_static.c
2337
component.c
2438
buffer.c
2539
)
40+
41+
install(TARGETS sof_audio_core DESTINATION lib)
42+
43+
# Audio Modules with various optimizaitons
44+
45+
# add rules for module compilation and installation
46+
function(sof_audio_add_module lib_name compile_flags)
47+
add_library(${lib_name} MODULE "")
48+
target_link_libraries(${lib_name} PRIVATE sof_options)
49+
target_link_libraries(${lib_name} PRIVATE -Wl,--export-dynamic)
50+
target_compile_options(${lib_name} PRIVATE ${compile_flags})
51+
add_local_sources(${lib_name} ${ARGN})
52+
install(TARGETS ${lib_name} DESTINATION lib)
53+
endfunction()
54+
55+
include(CheckCCompilerFlag)
56+
57+
set(available_optimizations)
58+
59+
# checks if flag is supported by compiler and sets needed flags
60+
macro(check_optimization opt_name flag extra_define)
61+
check_c_compiler_flag(${flag} compiles_flag_${opt_name})
62+
if(compiles_flag_${opt_name})
63+
list(APPEND available_optimizations ${opt_name})
64+
set(${opt_name}_flags ${flag} ${extra_define} -ffast-math -ftree-vectorizer-verbose=0)
65+
endif()
66+
endmacro()
67+
68+
# modules will be compiled only for flags supported by compiler
69+
check_optimization(sse42 -msse4.2 -DOPS_SSE42)
70+
check_optimization(avx -mavx -DOPS_AVX)
71+
check_optimization(avx2 -mavx2 -DOPS_AVX2)
72+
check_optimization(fma -mfma -DOPS_FMA)
73+
check_optimization(hifi2ep -mhifi2ep -DOPS_HIFI2EP)
74+
check_optimization(hifi3 -mhifi3 -DOPS_HIFI3)
75+
76+
set(sof_audio_modules volume src)
77+
78+
# sources for each module
79+
set(volume_sources volume.c volume_generic.c)
80+
set(src_sources src.c src_generic.c)
81+
82+
foreach(audio_module ${sof_audio_modules})
83+
# first compile with no optimizations
84+
sof_audio_add_module(sof_${audio_module} "" ${${audio_module}_sources})
85+
86+
# compile for each optimization
87+
foreach(opt ${available_optimizations})
88+
sof_audio_add_module(sof_${audio_module}_${opt} "${${opt}_flags}" ${${audio_module}_sources})
89+
endforeach()
90+
endforeach()

src/host/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
2+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
3+
4+
add_executable(testbench "")
5+
add_local_sources(testbench testbench.c)
6+
7+
target_link_libraries(testbench PRIVATE -ldl -lm)
8+
target_link_libraries(testbench PRIVATE sof_ipc tb_common sof_audio_core)
9+
10+
add_library(tb_common STATIC "")
11+
target_link_libraries(tb_common sof_options)
12+
add_local_sources(tb_common
13+
alloc.c
14+
common_test.c
15+
file.c
16+
ipc.c
17+
schedule.c
18+
topology.c
19+
trace.c
20+
)
21+
22+
install(TARGETS testbench DESTINATION bin)

src/ipc/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
if(BUILD_HOST)
2+
add_library(sof_ipc STATIC "")
3+
target_link_libraries(sof_ipc PRIVATE sof_options)
4+
add_local_sources(sof_ipc
5+
ipc.c
6+
)
7+
return()
8+
endif()
9+
110
add_local_sources(sof
211
ipc.c
312
handler.c

0 commit comments

Comments
 (0)