Skip to content

Commit

Permalink
cmake: add testbench host build
Browse files Browse the repository at this point in the history
Signed-off-by: Janusz Jankowski <janusz.jankowski@linux.intel.com>
  • Loading branch information
jajanusz authored and lgirdwood committed Jan 22, 2019
1 parent d2528e1 commit 7680a7b
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 32 deletions.
37 changes: 24 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ if(NOT (${CMAKE_VERSION} VERSION_LESS "3.13.0"))
cmake_policy(SET CMP0079 OLD)
endif()

# firmware build supports only xtensa arch for now
set(ARCH xtensa)
# TODO: take `host` out of fw build
option(BUILD_HOST "Build host program" OFF)

if(BUILD_HOST)
set(ARCH host)
else()
# firmware build supports only xtensa arch for now
set(ARCH xtensa)
endif()

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

project(SOF C ASM)

# most of other options are set on per-arch and per-target basis
set(CMAKE_ASM_FLAGS -DASSEMBLY)

# interface library that is used only as container for sof binary options
# other targets can use it to build with the same options
add_library(sof_options INTERFACE)

target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/include)

if(BUILD_HOST)
add_subdirectory(src)
# rest of this file is not needed for host build
return()
endif()

set(PYTHON3 python3)

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

add_custom_target(genconfig DEPENDS ${CONFIG_H_PATH})

# most of other options are set on per-arch basis
set(CMAKE_ASM_FLAGS -DASSEMBLY)

# interface library that is used only as container for sof binary options
# other targets can use it to build with the same options
add_library(sof_options INTERFACE)

add_dependencies(sof_options genconfig)

add_library(sof_ld_flags INTERFACE)
add_library(sof_ld_scripts INTERFACE)

Expand All @@ -103,8 +116,6 @@ target_link_libraries(sof sof_ld_scripts)
target_link_libraries(sof sof_ld_flags)

add_dependencies(sof_options genconfig)

target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/include)
target_include_directories(sof_options INTERFACE ${GENERATED_DIRECTORY}/include)

add_subdirectory(src)
Expand Down
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
add_subdirectory(arch)

if(BUILD_HOST)
add_subdirectory(ipc)
add_subdirectory(audio)
add_subdirectory(host)
return()
endif()

add_subdirectory(audio)
add_subdirectory(drivers)
add_subdirectory(init)
Expand Down
22 changes: 22 additions & 0 deletions src/arch/host/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# includes
set(GENERATED_DIRECTORY ${PROJECT_BINARY_DIR}/generated)
file(MAKE_DIRECTORY ${GENERATED_DIRECTORY}/include)

target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/arch/host/include)
target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/library/include)
target_include_directories(sof_options INTERFACE ${GENERATED_DIRECTORY}/include)

# TODO: add Kconfig support also for testbench when it'll be decoupled from fw
set(CONFIG_HOST 1)
set(CONFIG_LIB 1)

configure_file (
"${PROJECT_SOURCE_DIR}/src/arch/host/config.h.in"
"${GENERATED_DIRECTORY}/include/config.h"
)

# linker flags
target_link_libraries(sof_options INTERFACE -lpthread)

# C & ASM flags
target_compile_options(sof_options INTERFACE -g -O3 -Wall -Werror -Wl,-EL -Wmissing-prototypes -Wimplicit-fallthrough=3)
2 changes: 2 additions & 0 deletions src/arch/host/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define CONFIG_HOST @CONFIG_HOST@
#define CONFIG_LIB @CONFIG_LIB@
103 changes: 84 additions & 19 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,90 @@
add_local_sources(sof
eq_iir.c
iir.c
eq_fir.c
fir.c
fir_hifi2ep.c
fir_hifi3.c
tone.c
src.c
src_generic.c
src_hifi2ep.c
src_hifi3.c
mixer.c
mux.c
volume.c
volume_generic.c
volume_hifi3.c
switch.c
if(NOT BUILD_HOST)
add_local_sources(sof
eq_iir.c
iir.c
eq_fir.c
fir.c
fir_hifi2ep.c
fir_hifi3.c
tone.c
src.c
src_generic.c
src_hifi2ep.c
src_hifi3.c
mixer.c
mux.c
volume.c
volume_generic.c
volume_hifi3.c
switch.c
dai.c
host.c
pipeline.c
pipeline_static.c
component.c
buffer.c
)
return()
endif()

add_library(sof_audio_core SHARED "")
target_link_libraries(sof_audio_core PRIVATE sof_options)
target_link_libraries(sof_audio_core PRIVATE -Wl,--export-dynamic)
add_local_sources(sof_audio_core
dai.c
host.c
pipeline.c
pipeline_static.c
component.c
buffer.c
)

install(TARGETS sof_audio_core DESTINATION lib)

# Audio Modules with various optimizaitons

# add rules for module compilation and installation
function(sof_audio_add_module lib_name compile_flags)
add_library(${lib_name} MODULE "")
target_link_libraries(${lib_name} PRIVATE sof_options)
target_link_libraries(${lib_name} PRIVATE -Wl,--export-dynamic)
target_compile_options(${lib_name} PRIVATE ${compile_flags})
add_local_sources(${lib_name} ${ARGN})
install(TARGETS ${lib_name} DESTINATION lib)
endfunction()

include(CheckCCompilerFlag)

set(available_optimizations)

# checks if flag is supported by compiler and sets needed flags
macro(check_optimization opt_name flag extra_define)
check_c_compiler_flag(${flag} compiles_flag_${opt_name})
if(compiles_flag_${opt_name})
list(APPEND available_optimizations ${opt_name})
set(${opt_name}_flags ${flag} ${extra_define} -ffast-math -ftree-vectorizer-verbose=0)
endif()
endmacro()

# modules will be compiled only for flags supported by compiler
check_optimization(sse42 -msse4.2 -DOPS_SSE42)
check_optimization(avx -mavx -DOPS_AVX)
check_optimization(avx2 -mavx2 -DOPS_AVX2)
check_optimization(fma -mfma -DOPS_FMA)
check_optimization(hifi2ep -mhifi2ep -DOPS_HIFI2EP)
check_optimization(hifi3 -mhifi3 -DOPS_HIFI3)

set(sof_audio_modules volume src)

# sources for each module
set(volume_sources volume.c volume_generic.c)
set(src_sources src.c src_generic.c)

foreach(audio_module ${sof_audio_modules})
# first compile with no optimizations
sof_audio_add_module(sof_${audio_module} "" ${${audio_module}_sources})

# compile for each optimization
foreach(opt ${available_optimizations})
sof_audio_add_module(sof_${audio_module}_${opt} "${${opt}_flags}" ${${audio_module}_sources})
endforeach()
endforeach()
22 changes: 22 additions & 0 deletions src/host/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

add_executable(testbench "")
add_local_sources(testbench testbench.c)

target_link_libraries(testbench PRIVATE -ldl -lm)
target_link_libraries(testbench PRIVATE sof_ipc tb_common sof_audio_core)

add_library(tb_common STATIC "")
target_link_libraries(tb_common sof_options)
add_local_sources(tb_common
alloc.c
common_test.c
file.c
ipc.c
schedule.c
topology.c
trace.c
)

install(TARGETS testbench DESTINATION bin)
9 changes: 9 additions & 0 deletions src/ipc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
if(BUILD_HOST)
add_library(sof_ipc STATIC "")
target_link_libraries(sof_ipc PRIVATE sof_options)
add_local_sources(sof_ipc
ipc.c
)
return()
endif()

add_local_sources(sof
ipc.c
handler.c
Expand Down

0 comments on commit 7680a7b

Please sign in to comment.