# CMake build for Lua 5.1.4
cmake_minimum_required(VERSION 3.21)
project(lua LANGUAGES C)

set(LUA_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)

set(LUA_SOURCES
        src/lapi.c
        src/lcode.c
        src/ldebug.c
        src/ldo.c
        src/ldump.c
        src/lfunc.c
        src/lgc.c
        src/llex.c
        src/lmem.c
        src/loadlib.c
        src/lobject.c
        src/lopcodes.c
        src/lparser.c
        src/lstate.c
        src/lstring.c
        src/ltable.c
        src/ltm.c
        src/lundump.c
        src/lvm.c
        src/lzio.c
        src/lauxlib.c
        src/lbaselib.c
        src/ldblib.c
        src/liolib.c
        src/lmathlib.c
        src/loslib.c
        src/ltablib.c
        src/lstrlib.c
        src/linit.c
)

set(LUA_VERSION_MAJOR 5)
set(LUA_VERSION_MINOR 1)
set(LUA_VERSION_PATCH 4)
set(LUA_VERSION "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")

add_library(lua SHARED ${LUA_SOURCES})
set_target_properties(lua PROPERTIES
        VERSION ${LUA_VERSION}
        SOVERSION ${LUA_VERSION_MAJOR}
)

add_executable(lua_bin
        src/lua.c
)
target_link_libraries(lua_bin PRIVATE lua)
target_include_directories(lua_bin PRIVATE src)

add_executable(luac_bin
        src/luac.c
        src/print.c
)
target_link_libraries(luac_bin PRIVATE lua)
target_include_directories(luac_bin PRIVATE src)

# Header files
set(LUA_HEADERS
        ${LUA_SRC_DIR}/lua.h
        ${LUA_SRC_DIR}/luaconf.h
        ${LUA_SRC_DIR}/lualib.h
        ${LUA_SRC_DIR}/lauxlib.h
)

target_include_directories(lua
        PUBLIC
        ${LUA_SRC_DIR}
)
