
project(lualib C)
# set(CMAKE_CXX_STANDARD 17)
add_library(lualib STATIC)

set(LUA_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/deps/lua)
set(LUA_SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/lua)
set(LUA_LIBRARY lualib)

set(LUA_SRC_LIB
    ${LUA_SOURCE_DIR}/lbaselib.c
    ${LUA_SOURCE_DIR}/ldblib.c
    ${LUA_SOURCE_DIR}/liolib.c
    ${LUA_SOURCE_DIR}/lmathlib.c
    ${LUA_SOURCE_DIR}/loslib.c
    ${LUA_SOURCE_DIR}/ltablib.c
    ${LUA_SOURCE_DIR}/lstrlib.c
    ${LUA_SOURCE_DIR}/lutf8lib.c
    ${LUA_SOURCE_DIR}/loadlib.c
    ${LUA_SOURCE_DIR}/lcorolib.c
    ${LUA_SOURCE_DIR}/linit.c
)

set(LUA_SRC_AUX
    ${LUA_SOURCE_DIR}/lauxlib.c
)

set(LUA_SRC_CORE
    ${LUA_SOURCE_DIR}/lapi.c
    ${LUA_SOURCE_DIR}/lcode.c
    ${LUA_SOURCE_DIR}/lctype.c
    ${LUA_SOURCE_DIR}/ldebug.c
    ${LUA_SOURCE_DIR}/ldo.c
    ${LUA_SOURCE_DIR}/ldump.c
    ${LUA_SOURCE_DIR}/lfunc.c
    ${LUA_SOURCE_DIR}/lgc.c
    ${LUA_SOURCE_DIR}/llex.c
    ${LUA_SOURCE_DIR}/lmem.c
    ${LUA_SOURCE_DIR}/lobject.c
    ${LUA_SOURCE_DIR}/lopcodes.c
    ${LUA_SOURCE_DIR}/lparser.c
    ${LUA_SOURCE_DIR}/lstate.c
    ${LUA_SOURCE_DIR}/lstring.c
    ${LUA_SOURCE_DIR}/ltable.c
    ${LUA_SOURCE_DIR}/ltm.c
    ${LUA_SOURCE_DIR}/lundump.c
    ${LUA_SOURCE_DIR}/lvm.c
    ${LUA_SOURCE_DIR}/lzio.c
    ${LUA_SOURCE_DIR}/ltests.c
    ${LUA_SRC_AUX}
    ${LUA_SRC_LIB}
)

# aux_source_directory(${PROJECT_SOURCE_DIR}/deps/lua LUA_SRC)
# list(REMOVE_ITEM LUA_SRC ${PROJECT_SOURCE_DIR}/deps/lua/onelua.c)
# set_source_files_properties(${LUA_SRC} PROPERTIES LANGUAGE CXX)
target_sources(lualib PUBLIC ${LUA_SRC_CORE})
target_compile_options(lualib PUBLIC -DLUA_COMPAT_5_3 -g3)
target_link_libraries(lualib PUBLIC dl m)
set_target_properties(lualib PROPERTIES
    LINKER_LANGUAGE CXX
)