sof/tools/testbench/CMakeLists.txt

91 lines
2.9 KiB
CMake
Raw Normal View History

# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.13)
project(SOF_TESTBENCH C)
include(../../scripts/cmake/misc.cmake)
add_executable(testbench
testbench.c
common_test.c
file.c
topology.c
)
sof_append_relative_path_definitions(testbench)
target_include_directories(testbench PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
Use '-imacros config.h' instead of explicit #include <config.h> Using -imacros on the compiler command line instead of explicitly including config.h is not just less tedious in the future: - it also makes sure configuration always comes first and is never accidentally missed by an earlier #include - it makes sure all translation units get the (same) configuration - it lets parent projects like Zephyr override the config.h name To test this I ran ./scripts/xtensa-build-all.sh -a -r, compared binaries before and after this change and found no output difference. Full disclosure: this required a few unrelated tricks not submitted here like a .tarball-version file, commenting out __DATE__ and __TIME__ in a few places, running strip-determinism on the .a files because our crosstool-ng reference is not cutting-edge, etc. As Tigerlake is not built by default it required a couple more hacks to compile. Blank lines are left instead of the former #include lines so even debug objects are the same. Only defconfigs were tested. On the other hand, this commit was _not_ performed by a script but by changing the name of the generated file and clicking on and fixing every build failure. This proves that every removed #include was actually required by one or more tested defconfigs and that the added -imacros flag does affect the compilation of all the modified files. There is no #include config.h left: they were all in use in at least one _defconfig. I think comparing all binaries produced by ./scripts/xtensa-build-all.sh -r -a provides extensive enough coverage but note this was tested only with the crosstool-ng toolchain described in the SOF documentation. The obsolete[*] xt-xcc front-end is gcc-based and the newer xt-clang front-end is (surprise) clang-based. clang (copies many gcc options and) does support -imacros so I don't expect any issue with either xt-xcc or xt-clang. In the worst case, I do not expect any compiler front end to _silently_ discard any unknown command line flag nor to ignore a missing or misnamed config.h file. [*] https://github.com/zephyrproject-rtos/zephyr/issues/3165 Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2020-06-12 13:47:37 +08:00
set(sof_source_directory "${PROJECT_SOURCE_DIR}/../..")
set(sof_install_directory "${PROJECT_BINARY_DIR}/sof_ep/install")
set(sof_binary_directory "${PROJECT_BINARY_DIR}/sof_ep/build")
set(config_h ${sof_binary_directory}/library_autoconfig.h)
# TODO: testbench should not need RTOS headers: FIX.
if (NOT CONFIG_SOF_ZEPHYR_STRICT_HEADERS)
target_include_directories(testbench PRIVATE
"${PROJECT_SOURCE_DIR}/xtos/include"
)
endif()
Use '-imacros config.h' instead of explicit #include <config.h> Using -imacros on the compiler command line instead of explicitly including config.h is not just less tedious in the future: - it also makes sure configuration always comes first and is never accidentally missed by an earlier #include - it makes sure all translation units get the (same) configuration - it lets parent projects like Zephyr override the config.h name To test this I ran ./scripts/xtensa-build-all.sh -a -r, compared binaries before and after this change and found no output difference. Full disclosure: this required a few unrelated tricks not submitted here like a .tarball-version file, commenting out __DATE__ and __TIME__ in a few places, running strip-determinism on the .a files because our crosstool-ng reference is not cutting-edge, etc. As Tigerlake is not built by default it required a couple more hacks to compile. Blank lines are left instead of the former #include lines so even debug objects are the same. Only defconfigs were tested. On the other hand, this commit was _not_ performed by a script but by changing the name of the generated file and clicking on and fixing every build failure. This proves that every removed #include was actually required by one or more tested defconfigs and that the added -imacros flag does affect the compilation of all the modified files. There is no #include config.h left: they were all in use in at least one _defconfig. I think comparing all binaries produced by ./scripts/xtensa-build-all.sh -r -a provides extensive enough coverage but note this was tested only with the crosstool-ng toolchain described in the SOF documentation. The obsolete[*] xt-xcc front-end is gcc-based and the newer xt-clang front-end is (surprise) clang-based. clang (copies many gcc options and) does support -imacros so I don't expect any issue with either xt-xcc or xt-clang. In the worst case, I do not expect any compiler front end to _silently_ discard any unknown command line flag nor to ignore a missing or misnamed config.h file. [*] https://github.com/zephyrproject-rtos/zephyr/issues/3165 Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2020-06-12 13:47:37 +08:00
target_compile_options(testbench PRIVATE -g -O3 -Wall -Werror -Wl,-EL -Wmissing-prototypes
-Wimplicit-fallthrough -DCONFIG_LIBRARY -imacros${config_h})
target_link_libraries(testbench PRIVATE -ldl -lm)
install(TARGETS testbench DESTINATION bin)
include(ExternalProject)
ExternalProject_Add(sof_ep
DOWNLOAD_COMMAND ""
SOURCE_DIR "${sof_source_directory}"
PREFIX "${PROJECT_BINARY_DIR}/sof_ep"
BINARY_DIR "${sof_binary_directory}"
CMAKE_ARGS -DCONFIG_LIBRARY=ON
-DCMAKE_INSTALL_PREFIX=${sof_install_directory}
-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE}
-DINIT_CONFIG=library_defconfig
Use '-imacros config.h' instead of explicit #include <config.h> Using -imacros on the compiler command line instead of explicitly including config.h is not just less tedious in the future: - it also makes sure configuration always comes first and is never accidentally missed by an earlier #include - it makes sure all translation units get the (same) configuration - it lets parent projects like Zephyr override the config.h name To test this I ran ./scripts/xtensa-build-all.sh -a -r, compared binaries before and after this change and found no output difference. Full disclosure: this required a few unrelated tricks not submitted here like a .tarball-version file, commenting out __DATE__ and __TIME__ in a few places, running strip-determinism on the .a files because our crosstool-ng reference is not cutting-edge, etc. As Tigerlake is not built by default it required a couple more hacks to compile. Blank lines are left instead of the former #include lines so even debug objects are the same. Only defconfigs were tested. On the other hand, this commit was _not_ performed by a script but by changing the name of the generated file and clicking on and fixing every build failure. This proves that every removed #include was actually required by one or more tested defconfigs and that the added -imacros flag does affect the compilation of all the modified files. There is no #include config.h left: they were all in use in at least one _defconfig. I think comparing all binaries produced by ./scripts/xtensa-build-all.sh -r -a provides extensive enough coverage but note this was tested only with the crosstool-ng toolchain described in the SOF documentation. The obsolete[*] xt-xcc front-end is gcc-based and the newer xt-clang front-end is (surprise) clang-based. clang (copies many gcc options and) does support -imacros so I don't expect any issue with either xt-xcc or xt-clang. In the worst case, I do not expect any compiler front end to _silently_ discard any unknown command line flag nor to ignore a missing or misnamed config.h file. [*] https://github.com/zephyrproject-rtos/zephyr/issues/3165 Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2020-06-12 13:47:37 +08:00
-DCONFIG_H_PATH=${config_h}
BUILD_ALWAYS 1
BUILD_BYPRODUCTS "${sof_install_directory}/lib/libsof.so"
)
add_library(sof_library SHARED IMPORTED)
set_target_properties(sof_library PROPERTIES IMPORTED_LOCATION "${sof_install_directory}/lib/libsof.so")
add_dependencies(sof_library sof_ep)
set(parser_source_directory "${PROJECT_SOURCE_DIR}/../tplg_parser")
set(parser_install_dir "${PROJECT_BINARY_DIR}/sof_parser/install")
#External project for topology parser
ExternalProject_Add(parser_ep
SOURCE_DIR "${parser_source_directory}"
PREFIX "${PROJECT_BINARY_DIR}/sof_parser"
BINARY_DIR "${PROJECT_BINARY_DIR}/sof_parser/build"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/sof_parser/install
-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE}
BUILD_ALWAYS 1
BUILD_BYPRODUCTS "${parser_install_dir}/lib/libsof_tplg_parser.so"
)
add_library(sof_parser_lib SHARED IMPORTED)
set_target_properties(sof_parser_lib PROPERTIES IMPORTED_LOCATION "${parser_install_dir}/lib/libsof_tplg_parser.so")
add_dependencies(sof_parser_lib parser_ep)
add_dependencies(testbench sof_parser_lib)
target_link_libraries(testbench PRIVATE sof_library)
target_link_libraries(testbench PRIVATE sof_parser_lib)
target_link_libraries(testbench PRIVATE pthread)
target_include_directories(testbench PRIVATE ${sof_install_directory}/include)
target_include_directories(testbench PRIVATE ${parser_install_dir}/include)
set_target_properties(testbench
PROPERTIES
INSTALL_RPATH "${sof_install_directory}/lib"
INSTALL_RPATH_USE_LINK_PATH TRUE
)