11set (SOF_TOPOLOGY_BINARY_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} " )
2+ set (SOF_ALSA_TOOLS_DIR "${SOF_ROOT_SOURCE_DIRECTORY} /../tools/bin" )
3+ set (ALSATPLG_CMD "${SOF_ALSA_TOOLS_DIR} /alsatplg" )
4+
5+ function (alsatplg_version OUT_STATUS OUT_VERSION)
6+ execute_process (COMMAND ${ALSATPLG_CMD} --version
7+ RESULT_VARIABLE status
8+ OUTPUT_VARIABLE stdout
9+ OUTPUT_STRIP_TRAILING_WHITESPACE)
10+ message (DEBUG "${ALSATPLG_CMD} --version: status=${status} , output=${stdout} " )
11+
12+ set (${OUT_STATUS} "${status} " PARENT_SCOPE)
13+
14+ # Some error messages have already been printed on stderr
15+ if (NOT status EQUAL 0)
16+ message (WARNING "${ALSATPLG_CMD} --version returned status: ${status} ,
17+ ${stdout} " )
18+ return ()
19+ endif ()
20+
21+ string (REPLACE "\n " ";" ALSA_VERSION_LIST ${stdout} )
22+ list (GET ALSA_VERSION_LIST 0 ALSATPLG_VERSION)
23+ string (REGEX MATCH "[0-9]\. [0-9]\. *[0-9]*" ALSATPLG_VERSION_NUMBER ${ALSATPLG_VERSION} )
24+
25+ set (${OUT_VERSION} "${ALSATPLG_VERSION_NUMBER} " PARENT_SCOPE)
26+ endfunction ()
27+
28+
29+ # Being written in C, `alsatplg` silently ignores some invalid inputs
30+ # and produces an corrupt .tplg file instead of returning an error code
31+ # that fails the build. For instance, alsatplg versions < 1.2.5 silently
32+ # corrupt `codec_consumer` and turn it into `codec_master` instead.
33+ # Longer story in #5192.
34+ alsatplg_version(STATUS ALSATPLG_VERSION_NUMBER)
35+ if (NOT STATUS EQUAL 0)
36+ message (WARNING "${ALSATPLG_CMD} failed: ${STATUS} ; all topologies skipped" )
37+ return ()
38+ else ()
39+ if (${ALSATPLG_VERSION_NUMBER} VERSION_LESS "1.2.5" )
40+ message (WARNING "All topologies skipped: minimum alsatplg version 1.2.5,\
41+ found ${ALSATPLG_VERSION_NUMBER} ." )
42+ return ()
43+ endif ()
44+ # success
45+ endif ()
246
347# This use of VERBOSE relies on original CMake behavior.
448# From the add_custom_command() manual:
@@ -23,7 +67,7 @@ macro(add_alsatplg_command)
2367 # permissions are hardcoded and only the user can read
2468 # the -o(utput) file.
2569 # See bug https://github.com/alsa-project/alsa-utils/issues/126
26- COMMAND alsatplg \$\${VERBOSE:+-v 1} -c ${ARGV0} -o ${ARGV1}
70+ COMMAND ${ALSATPLG_CMD} \$\${VERBOSE:+-v 1} -c ${ARGV0} -o ${ARGV1}
2771 USES_TERMINAL
2872 )
2973endmacro ()
@@ -41,7 +85,7 @@ macro(add_alsatplg2_command input_file output_file include_path)
4185 MAIN_DEPENDENCY ${input_file}
4286 OUTPUT ${output_file}
4387 # -p to pre-process Topology2.0 conf file
44- COMMAND ALSA_CONFIG_DIR=${CMAKE_SOURCE_DIR} /topology/topology2 alsatplg \$\${VERBOSE:+-v 1}
88+ COMMAND ALSA_CONFIG_DIR=${CMAKE_SOURCE_DIR} /topology/topology2 ${ALSATPLG_CMD} \$\${VERBOSE:+-v 1}
4589 -I ${include_path} -D "'${defines} '" -p -c ${input_file} -o ${output_file}
4690 USES_TERMINAL
4791 )
0 commit comments