awesome/docs/generate_examples.cmake
Uli Schlachter 02cdb5103b Run shape-example-generation under LuaCov
This is ugly, but at least it works. Hopefully...

Signed-off-by: Uli Schlachter <uli.schlachter@informatik.uni-oldenburg.de>
2016-03-17 10:22:42 +01:00

51 lines
1.9 KiB
CMake

# Get and update the LUA_PATH so the scripts can be executed without Awesome
execute_process(COMMAND lua -e print\(package.path\) OUTPUT_VARIABLE LUA_PATH_)
set(ENV{LUA_PATH} "${SOURCE_DIR}/lib/?;${SOURCE_DIR}/lib/?.lua;${LUA_PATH_}")
file(MAKE_DIRECTORY "${BUILD_DIR}/doc/images")
set(ENV{BUILD_DIRECTORY} "${BUILD_DIR}/")
set(ENV{AWESOME_LIB_DIR} "${SOURCE_DIR}/lib/")
#
# Shape API
#
foreach (SHAPE_NAME "circle" "arrow" "rounded_rect" "hexagon" "infobubble"
"powerline" "isosceles_triangle" "cross" "octogon" "parallelogram"
"losange" "partially_rounded_rect" "radial_progress" "rounded_bar"
"rectangle" "rectangular_tag")
set(SHAPE_FILE "${SOURCE_DIR}/tests/shape/${SHAPE_NAME}.lua")
set(SHAPE_SVG "${BUILD_DIR}/doc/images/shape_${SHAPE_NAME}.svg")
# Generate some SVG for the documentation and load the examples for the doc
execute_process(
COMMAND lua ${SOURCE_DIR}/tests/shape/test-shape.lua ${SHAPE_FILE} ${SHAPE_SVG} ${SOURCE_DIR}/.luacov
ERROR_VARIABLE SHAPE_ERROR
)
if (NOT SHAPE_ERROR STREQUAL "")
message(${SHAPE_ERROR})
message(FATAL_ERROR ${SHAPE_NAME} " SVG generation failed, bye")
endif()
# Set the SVG paths for the doc
set(SHAPE_${SHAPE_NAME}_SVG "../images/shape_${SHAPE_NAME}.svg")
# Use the .lua as code example
file(READ ${SHAPE_FILE} SHAPE_EXAMPLE)
STRING(REGEX REPLACE "\n" ";" SHAPE_EXAMPLE "${SHAPE_EXAMPLE}")
SET(SHAPE_COMMENTED
"![Shape example](../images/shape_${SHAPE_NAME}.svg)\n--\n-- @usage"
)
foreach (EXAMPLE_FILE ${SHAPE_EXAMPLE})
if(NOT EXAMPLE_FILE MATCHES "^.+--DOC_HIDE$")
SET(SHAPE_COMMENTED ${SHAPE_COMMENTED}\n--${EXAMPLE_FILE})
endif()
endforeach()
set(SHAPE_${SHAPE_NAME}_EXAMPLE ${SHAPE_COMMENTED})
endforeach()
# vim: filetype=cmake:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80:foldmethod=marker