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