# Add a target to call checkAPIs.pl on the specified source files
# The target is excluded from the ALL target so must be manually
# specified in a build command.
# The target is added to the top-level checkAPIs target
#
# Parameters:
#   NAME: 	The name of the target, must be unique
#   SWITCHES:	Switches to be supplied to the script
#   SOURCES:	The sources to be checked

include(CMakeParseArguments)

macro( CHECKAPI )
	cmake_parse_arguments(CHECKAPI "DEBUG" "" "NAME;SWITCHES;SOURCES" ${ARGN} )

	if (CHECKAPI_UNPARSED_ARGUMENTS)
		message(FATAL_ERROR "CHECKAPIS Unknown argument: ${CHECKAPI_UNPARSED_ARGUMENTS}")
	endif()

	if( CHECKAPI_DEBUG )
		set (CHECKAPI_SWITCHES ${CHECKAPI_SWITCHES --debug)
	endif()

	# The "checkAPI" target/prefix should probably be "checkapi".
	set(TARGET_NAME checkAPI_${CHECKAPI_NAME})
	add_custom_target(${TARGET_NAME}
		COMMAND ${Python3_EXECUTABLE}
		  ${CMAKE_SOURCE_DIR}/tools/check_apis.py
		  ${CHECKAPI_SWITCHES}
		  ${CHECKAPI_SOURCES}
		DEPENDS
		  ${CHECKAPI_SOURCES}
		WORKING_DIRECTORY
		  ${CMAKE_CURRENT_SOURCE_DIR}
		COMMENT
		  "Running ${TARGET_NAME}"
	)
	add_dependencies(checkAPI ${TARGET_NAME})
	set_target_properties(${TARGET_NAME}
		PROPERTIES FOLDER "Auxiliary/CheckAPIs"
		EXCLUDE_FROM_ALL True
		EXCLUDE_FROM_DEFAULT_BUILD True
	)
ENDMACRO()