|
| 1 | +# lapi_tests_make_lua_path provides a convenient way to define |
| 2 | +# LUA_PATH and LUA_CPATH variables. |
| 3 | +# |
| 4 | +# Example usage: |
| 5 | +# |
| 6 | +# lapi_tests_make_lua_path(LUA_PATH |
| 7 | +# PATH |
| 8 | +# ./?.lua |
| 9 | +# ${CMAKE_BINARY_DIR}/?.lua |
| 10 | +# ${CMAKE_CURRENT_SOURCE_DIR}/?.lua |
| 11 | +# ) |
| 12 | +# |
| 13 | +# This will give you the string: |
| 14 | +# "./?.lua;${CMAKE_BINARY_DIR}/?.lua;${CMAKE_CURRENT_SOURCE_DIR}/?.lua;;" |
| 15 | +# |
| 16 | +# Source: https://github.com/tarantool/luajit/blob/441405c398d625fda304b16bb10f119bfd822696/cmake/MakeLuaPath.cmake |
| 17 | + |
| 18 | +function(lapi_tests_make_lua_path path) |
| 19 | + set(prefix ARG) |
| 20 | + set(noValues) |
| 21 | + set(singleValues) |
| 22 | + set(multiValues PATHS) |
| 23 | + |
| 24 | + include(CMakeParseArguments) |
| 25 | + cmake_parse_arguments(${prefix} |
| 26 | + "${noValues}" |
| 27 | + "${singleValues}" |
| 28 | + "${multiValues}" |
| 29 | + ${ARGN}) |
| 30 | + |
| 31 | + set(_MAKE_LUA_PATH_RESULT "") |
| 32 | + |
| 33 | + foreach(inc ${ARG_PATHS}) |
| 34 | + # XXX: If one joins two strings with the semicolon, the value |
| 35 | + # automatically becomes a list. I found a single working |
| 36 | + # solution to make result variable be a string via "escaping" |
| 37 | + # the semicolon right in string interpolation. |
| 38 | + set(_MAKE_LUA_PATH_RESULT "${_MAKE_LUA_PATH_RESULT}${inc}\;") |
| 39 | + endforeach() |
| 40 | + |
| 41 | + if("${_MAKE_LUA_PATH_RESULT}" STREQUAL "") |
| 42 | + message(FATAL_ERROR |
| 43 | + "No paths are given to <lapi_tests_make_lua_path> helper.") |
| 44 | + endif() |
| 45 | + |
| 46 | + # XXX: This is the sentinel semicolon having special meaning |
| 47 | + # for LUA_PATH and LUA_CPATH variables. For more info, see the |
| 48 | + # link below: |
| 49 | + # https://www.lua.org/manual/5.1/manual.html#pdf-LUA_PATH |
| 50 | + set(${path} "${_MAKE_LUA_PATH_RESULT}\;" PARENT_SCOPE) |
| 51 | + # XXX: Unset the internal variable to not spoil CMake cache. |
| 52 | + # Study the case in CheckIPOSupported.cmake, that affected this |
| 53 | + # module: https://gitlab.kitware.com/cmake/cmake/-/commit/4b82977 |
| 54 | + unset(_MAKE_LUA_PATH_RESULT) |
| 55 | +endfunction() |
0 commit comments