1b815c7f3Sopenharmony_ci# CMake implementation of AutoGen
2b815c7f3Sopenharmony_ci# Copyright (C) 2017 Anonymous Maarten <anonymous.maarten@gmail.com>
3b815c7f3Sopenharmony_ci
4b815c7f3Sopenharmony_ciset(AUTOGEN_SCRIPT "${CMAKE_MODULE_PATH}/CMakeAutoGenScript.cmake")
5b815c7f3Sopenharmony_ci
6b815c7f3Sopenharmony_cifunction(lsf_autogen DIR_REL NAME_WE)
7b815c7f3Sopenharmony_ci	set(EXTS ${ARGN})
8b815c7f3Sopenharmony_ci	set(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/${DIR_REL}/${NAME_WE}.def")
9b815c7f3Sopenharmony_ci	set(OUTPUTS)
10b815c7f3Sopenharmony_ci	foreach(EXT ${EXTS})
11b815c7f3Sopenharmony_ci		list(APPEND OUTPUTS "${NAME_WE}.${EXT}")
12b815c7f3Sopenharmony_ci	endforeach()
13b815c7f3Sopenharmony_ci	add_autogen_target("${INPUT}" "${CMAKE_CURRENT_BINARY_DIR}/${DIR_REL}" ${OUTPUTS})
14b815c7f3Sopenharmony_ciendfunction()
15b815c7f3Sopenharmony_ci
16b815c7f3Sopenharmony_cifunction(add_autogen_target INPUT OUTPUTDIR)
17b815c7f3Sopenharmony_ci	set(OUTPUTFILES "${ARGN}")
18b815c7f3Sopenharmony_ci
19b815c7f3Sopenharmony_ci	if (OUTPUTDIR)
20b815c7f3Sopenharmony_ci		set(PREFIX "${OUTPUTDIR}/")
21b815c7f3Sopenharmony_ci	else()
22b815c7f3Sopenharmony_ci		set(PREFIX "")
23b815c7f3Sopenharmony_ci	endif()
24b815c7f3Sopenharmony_ci
25b815c7f3Sopenharmony_ci	set(ARTIFACTS)
26b815c7f3Sopenharmony_ci	foreach(OUTPUTFILE ${OUTPUTFILES})
27b815c7f3Sopenharmony_ci		list(APPEND ARTIFACTS "${PREFIX}${OUTPUTFILE}")
28b815c7f3Sopenharmony_ci	endforeach()
29b815c7f3Sopenharmony_ci
30b815c7f3Sopenharmony_ci	set(EXTRA_ARGS)
31b815c7f3Sopenharmony_ci	if (AUTOGEN_DEBUG)
32b815c7f3Sopenharmony_ci		list(APPEND EXTRA_ARGS "-DDEBUG=1")
33b815c7f3Sopenharmony_ci	endif()
34b815c7f3Sopenharmony_ci	if (OUTPUTDIR)
35b815c7f3Sopenharmony_ci		list(APPEND EXTRA_ARGS "-DOUTPUTDIR=${OUTPUTDIR}")
36b815c7f3Sopenharmony_ci	endif()
37b815c7f3Sopenharmony_ci
38b815c7f3Sopenharmony_ci	add_custom_command(
39b815c7f3Sopenharmony_ci		OUTPUT ${ARTIFACTS}
40b815c7f3Sopenharmony_ci		COMMAND ${CMAKE_COMMAND} "-DDEFINITION=${INPUT}" ${EXTRA_ARGS} -P "${AUTOGEN_SCRIPT}"
41b815c7f3Sopenharmony_ci		MAIN_DEPENDENCY "${INPUT}"
42b815c7f3Sopenharmony_ci		DEPENDS "${AUTOGEN_SCRIPT}"
43b815c7f3Sopenharmony_ci		COMMENT "CMakeAutoGen: generating ${OUTPUTFILES}"
44b815c7f3Sopenharmony_ci		WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
45b815c7f3Sopenharmony_ci	)
46b815c7f3Sopenharmony_ciendfunction()
47