5 # Find lua-format executable.
10 # This module defines the following variables:
12 # ``LUA_FORMAT_FOUND``, ``LuaFormat_FOUND``
14 # ``LUA_FORMAT_EXECUTABLE``
19 # .. command:: add_lua_format
23 # add_lua_format(target [VERBOSE]
24 # [WORKING_DIRECTORY dir] [COMMENT comment] [CONFIG cfg]
25 # [OPTIONS opt ...] [SOURCES src ...] [src ...]
28 include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
29 find_program(LUA_FORMAT_EXECUTABLE NAMES lua-format)
30 mark_as_advanced(LUA_FORMAT_EXECUTABLE)
32 if(EXISTS "${LUA_FORMAT_EXECUTABLE}")
33 execute_process(COMMAND ${LUA_FORMAT_EXECUTABLE} --version
34 OUTPUT_VARIABLE LUA_FORMAT_VERSION ERROR_VARIABLE LUA_FORMAT_VERSION
36 string(REGEX REPLACE "[^0-9]+([^\n ]*).*" "\\1" LUA_FORMAT_VERSION "${LUA_FORMAT_VERSION}")
39 find_package_handle_standard_args(LuaFormat
49 set(LUA_FORMAT_FOUND 1)
50 function(add_lua_format target)
51 cmake_parse_arguments(LUA_FORMAT "VERBOSE" "WORKING_DIRECTORY;COMMENT;CONFIG" "OPTIONS;SOURCES" ${ARGN})
52 list(APPEND LUA_FORMAT_SOURCES ${LUA_FORMAT_UNPARSED_ARGUMENTS})
53 list(APPEND LUA_FORMAT_OPTIONS --in-place)
54 if(LUA_FORMAT_VERBOSE)
55 list(INSERT LUA_FORMAT_OPTIONS 0 --verbose)
57 if(EXISTS "${LUA_FORMAT_CONFIG}")
58 list(APPEND LUA_FORMAT_OPTIONS --config=${LUA_FORMAT_CONFIG})
60 if(NOT LUA_FORMAT_WORKING_DIRECTORY)
61 set(LUA_FORMAT_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
63 if(NOT LUA_FORMAT_COMMENT)
64 set(LUA_FORMAT_COMMENT "Formatting ${target} using lua-format")
66 add_custom_target(${target} # https://github.com/Koihik/LuaFormatter
67 ${LUA_FORMAT_EXECUTABLE} ${LUA_FORMAT_OPTIONS} -- ${LUA_FORMAT_SOURCES}
68 WORKING_DIRECTORY ${LUA_FORMAT_WORKING_DIRECTORY}
69 COMMENT "${LUA_FORMAT_COMMENT}"