1set(SOF_TOPOLOGY_BINARY_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
2
3# This use of VERBOSE relies on original CMake behavior.
4# From the add_custom_command() manual:
5#
6#    Use of VERBATIM is recommended as it enables correct behavior.
7#    When VERBATIM is not given the behavior is platform specific because
8#    there is no protection of tool-specific special characters.
9#
10# This is fine because:
11# - We don't expect alsatplg to work on Windows any time soon.
12# - CMake is too afraid to remove the original, no-VERBATIM behavior:
13#      https://gitlab.kitware.com/cmake/cmake/issues/18849
14#
15# Also note that in alsa-utils commit v1.2.2~15-gcbabe7a3f0cc, alsatplg
16# (accidentally?) started ignoring the verbosity level, now it's just
17# verbose or not.
18macro(add_alsatplg_command)
19	add_custom_command(
20		MAIN_DEPENDENCY ${ARGV0}
21		OUTPUT ${ARGV1}
22		# Warning: before alsa-utils fix 8e71fba810b87c,
23		# permissions are hardcoded and only the user can read
24		# the -o(utput) file.
25		# See bug https://github.com/alsa-project/alsa-utils/issues/126
26		COMMAND alsatplg \$\${VERBOSE:+-v 1} -c ${ARGV0} -o ${ARGV1}
27		USES_TERMINAL
28	)
29endmacro()
30
31macro(add_alsatplg2_command conf_header conf_target input_name output_name include_path)
32	# command line definitions are optional
33	# Set defines if there is an optional argument
34	if (${ARGC} GREATER 5)
35		set (defines ${ARGV5})
36	else()
37		set (defines "")
38	endif()
39
40	add_custom_command(
41		MAIN_DEPENDENCY ${input_name}.conf
42		# The conf_header file is the real dependency that
43		# triggers a rebuild. conf_target is the target that
44		# avoids a race to rebuild conf_header. See the CMake FAQ
45		# or (better) Sam Thursfield's blog about custom
46		# targets.
47		DEPENDS ${conf_header} ${conf_target}
48		OUTPUT ${output_name}.tplg
49
50		COMMAND cat ${conf_header} ${input_name}.conf > ${output_name}.conf
51
52		# -p to pre-process Topology2.0 conf file
53		COMMAND ALSA_CONFIG_DIR=${CMAKE_SOURCE_DIR}/topology/topology2 alsatplg \$\${VERBOSE:+-v 1}
54		        -I ${include_path} -D "'${defines}'" -p -c ${output_name}.conf -o ${output_name}.tplg
55		USES_TERMINAL
56		)
57endmacro()
58
59
60add_custom_target(topologies ALL)
61add_dependencies(topologies topologies1)
62
63add_subdirectory(topology1)
64add_subdirectory(topology2)
65