Skip to content

Commit

Permalink
Tools: Testbench: Avoid need linux kernel headers in build
Browse files Browse the repository at this point in the history
This patch adds simplified linux/types.h into testbench headers
to enable include of ALSA asoc.h to build without other difficult
kernel headers content.

The CMakeLists.txt files are updated to make a build time copy of
asoc.h to subdirectory include of the build directories. The new
directory is added to headers path.

This change avoids build fail with xcc toolchain that can't use the
gcc toolchain headers from the system where the ALSA headers are
located.

Suggested-by: Marc Herbert <[email protected]>
Signed-off-by: Seppo Ingalsuo <[email protected]>
  • Loading branch information
singalsu committed Mar 17, 2023
1 parent 56abcad commit ef99cc8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tools/testbench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ project(SOF_TESTBENCH C)
include(../../scripts/cmake/misc.cmake)
include(CheckCCompilerFlag)

set(default_asoc_h "/usr/include/alsa/sound/uapi/asoc.h")

add_executable(testbench
testbench.c
common_test.c
Expand All @@ -31,6 +33,12 @@ target_include_directories(testbench PRIVATE
)
endif()

# Configuration time, make copy
configure_file(${default_asoc_h} ${CMAKE_CURRENT_BINARY_DIR}/include/alsa/sound/asoc.h)

# Build time
target_include_directories(testbench PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include")

# -Wimplicit-fallthrough is preferred, check if it's supported
check_c_compiler_flag(-Wimplicit-fallthrough supports_implicit_fallthrough)
if (supports_implicit_fallthrough)
Expand Down
22 changes: 22 additions & 0 deletions tools/testbench/include/linux/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: BSD-3-Clause */

#ifndef __TESTBENCH_LINUX_TYPES_H__
#define __TESTBENCH_LINUX_TYPES_H__

#include <stdint.h>

/*
* This header files allows to include asoc.h for topology parsing to
* non-gcc builds with other C library, e.g. the one that is used by
* xt-xcc compiler. The kernel linux/types.h cannot be used because
* the other definitions there are not compatible with the toolchain.
*/

/* There are minimum types needed for alsa/sound/uapi/asoc.h */

typedef int64_t __le64;
typedef int32_t __le32;
typedef int16_t __le16;
typedef uint8_t __u8;

#endif /* __TESTBENCH_LINUX_TYPES_H__ */
8 changes: 8 additions & 0 deletions tools/tplg_parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ project(SOF_TPLG_PARSER C)
include(../../scripts/cmake/misc.cmake)
include(CheckCCompilerFlag)

set(default_asoc_h "/usr/include/alsa/sound/uapi/asoc.h")

set(sof_source_directory "${PROJECT_SOURCE_DIR}/../..")

if (CONFIG_LIBRARY_STATIC)
Expand Down Expand Up @@ -40,6 +42,12 @@ target_include_directories(sof_tplg_parser PRIVATE ${sof_source_directory}/src/p
# TODO: The topology parser should NOT need to include RTOS header. FIX.
target_include_directories(sof_tplg_parser PRIVATE ${sof_source_directory}/xtos/include)

# Configuration time, make copy
configure_file(${default_asoc_h} ${CMAKE_CURRENT_BINARY_DIR}/include/alsa/sound/asoc.h)

# Build time
target_include_directories(sof_tplg_parser PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include")

# -Wimplicit-fallthrough is preferred, check if it's supported
check_c_compiler_flag(-Wimplicit-fallthrough supports_implicit_fallthrough)
if (supports_implicit_fallthrough)
Expand Down
22 changes: 22 additions & 0 deletions tools/tplg_parser/include/linux/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: BSD-3-Clause */

#ifndef __TPLG_PARSER_LINUX_TYPES_H__
#define __TPLG_PARSER_LINUX_TYPES_H__

#include <stdint.h>

/*
* This header files allows to include asoc.h for topology parsing to
* non-gcc builds with other C library, e.g. the one that is used by
* xt-xcc compiler. The kernel linux/types.h cannot be used because
* the other definitions there are not compatible with the toolchain.
*/

/* There are minimum types needed for alsa/sound/uapi/asoc.h */

typedef int64_t __le64;
typedef int32_t __le32;
typedef int16_t __le16;
typedef uint8_t __u8;

#endif /* __TPLG_PARSER_LINUX_TYPES_H__ */

0 comments on commit ef99cc8

Please sign in to comment.