From ef99cc84b50bbd805235785f1a72f304ff512331 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Wed, 9 Nov 2022 17:53:37 +0200 Subject: [PATCH] Tools: Testbench: Avoid need linux kernel headers in build 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 Signed-off-by: Seppo Ingalsuo --- tools/testbench/CMakeLists.txt | 8 ++++++++ tools/testbench/include/linux/types.h | 22 ++++++++++++++++++++++ tools/tplg_parser/CMakeLists.txt | 8 ++++++++ tools/tplg_parser/include/linux/types.h | 22 ++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 tools/testbench/include/linux/types.h create mode 100644 tools/tplg_parser/include/linux/types.h diff --git a/tools/testbench/CMakeLists.txt b/tools/testbench/CMakeLists.txt index c3024592cbfe..4816c8e1b781 100644 --- a/tools/testbench/CMakeLists.txt +++ b/tools/testbench/CMakeLists.txt @@ -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 @@ -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) diff --git a/tools/testbench/include/linux/types.h b/tools/testbench/include/linux/types.h new file mode 100644 index 000000000000..31186b5e365e --- /dev/null +++ b/tools/testbench/include/linux/types.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef __TESTBENCH_LINUX_TYPES_H__ +#define __TESTBENCH_LINUX_TYPES_H__ + +#include + +/* + * 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__ */ diff --git a/tools/tplg_parser/CMakeLists.txt b/tools/tplg_parser/CMakeLists.txt index 8180d946b9c9..c228ddad7f65 100644 --- a/tools/tplg_parser/CMakeLists.txt +++ b/tools/tplg_parser/CMakeLists.txt @@ -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) @@ -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) diff --git a/tools/tplg_parser/include/linux/types.h b/tools/tplg_parser/include/linux/types.h new file mode 100644 index 000000000000..b06e50b3c8f4 --- /dev/null +++ b/tools/tplg_parser/include/linux/types.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef __TPLG_PARSER_LINUX_TYPES_H__ +#define __TPLG_PARSER_LINUX_TYPES_H__ + +#include + +/* + * 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__ */