2020-11-16 14:47:43 +08:00
|
|
|
|
2022-02-17 18:06:19 +08:00
|
|
|
set (AX_LUA_VERSION "5.4.4")
|
|
|
|
|
|
|
|
set(LUA_SRC_PATH ${CMAKE_CURRENT_LIST_DIR})
|
2020-11-16 14:47:43 +08:00
|
|
|
|
|
|
|
set(lib_name plainlua)
|
|
|
|
set(target_name ${lib_name})
|
|
|
|
|
|
|
|
project(${lib_name})
|
|
|
|
|
2023-03-11 22:10:18 +08:00
|
|
|
include(AXPlatform)
|
2020-11-16 14:47:43 +08:00
|
|
|
|
|
|
|
aux_source_directory(${LUA_SRC_PATH} LUA_CORE)
|
|
|
|
list(REMOVE_ITEM LUA_CORE ${LUA_SRC_PATH}/lua.c ${LUA_SRC_PATH}/luac.c)
|
|
|
|
|
2021-10-07 15:36:37 +08:00
|
|
|
set(LUA_BUILD_AS_DLL ${BUILD_SHARED_LIBS})
|
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
set(LUA_BUILD_AS_DLL TRUE)
|
2022-02-18 23:23:41 +08:00
|
|
|
add_library(${target_name} SHARED ${LUA_CORE} ${LUA_SRC_PATH}/plainlua.def)
|
2023-03-11 22:10:18 +08:00
|
|
|
if(WINRT)
|
|
|
|
target_link_libraries(${target_name} PRIVATE runtimeobject)
|
|
|
|
endif()
|
2021-10-07 15:36:37 +08:00
|
|
|
else()
|
|
|
|
add_library(${target_name} ${LUA_CORE})
|
|
|
|
endif()
|
2020-11-16 14:47:43 +08:00
|
|
|
|
|
|
|
target_compile_definitions(${target_name}
|
|
|
|
PRIVATE _CRT_SECURE_NO_WARNINGS
|
|
|
|
PRIVATE _WINSOCK_DEPRECATED_NO_WARNINGS
|
|
|
|
)
|
|
|
|
|
2022-02-17 18:06:19 +08:00
|
|
|
if(${AX_LUA_VERSION} VERSION_GREATER_EQUAL "5.4.0") # !important: traditional lua bindings solution tolua++ not support yet
|
2022-11-12 17:08:04 +08:00
|
|
|
target_compile_definitions(${target_name}
|
|
|
|
PUBLIC LUA_COMPAT_APIINTCASTS=1
|
|
|
|
PUBLIC LUA_COMPAT_MATHLIB=1
|
|
|
|
)
|
2022-02-17 18:06:19 +08:00
|
|
|
elseif(${AX_LUA_VERSION} VERSION_GREATER_EQUAL "5.3.0")
|
2020-11-16 14:47:43 +08:00
|
|
|
target_compile_definitions(${target_name}
|
2020-11-17 23:17:40 +08:00
|
|
|
PUBLIC LUA_COMPAT_5_1=1
|
|
|
|
PUBLIC LUA_COMPAT_5_2=1
|
|
|
|
PUBLIC LUA_COMPAT_MODULE=1
|
2020-11-16 14:47:43 +08:00
|
|
|
)
|
2022-02-17 18:06:19 +08:00
|
|
|
elseif(${AX_LUA_VERSION} VERSION_GREATER_EQUAL "5.2.0")
|
2020-11-17 23:17:40 +08:00
|
|
|
target_compile_definitions(${target_name}
|
|
|
|
PUBLIC LUA_COMPAT_ALL=1
|
|
|
|
PUBLIC LUA_COMPAT_MODULE=1
|
|
|
|
)
|
2020-11-16 14:47:43 +08:00
|
|
|
endif()
|
|
|
|
|
2021-10-07 15:36:37 +08:00
|
|
|
if(LUA_BUILD_AS_DLL)
|
2020-11-16 14:47:43 +08:00
|
|
|
target_compile_definitions(${target_name} PUBLIC LUA_BUILD_AS_DLL=1)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set_target_properties(${target_name} PROPERTIES
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${LUA_SRC_PATH}"
|
|
|
|
)
|
|
|
|
|
|
|
|
set_target_properties(${target_name}
|
|
|
|
PROPERTIES
|
|
|
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
2021-03-13 18:18:40 +08:00
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
2021-06-08 20:45:55 +08:00
|
|
|
FOLDER "ThirdParty"
|
2020-11-16 14:47:43 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if(WIN32 OR MACOSX)
|
2021-03-13 18:18:40 +08:00
|
|
|
|
|
|
|
function (add_lua_bin target_name src_files)
|
|
|
|
add_executable(${target_name} ${src_files})
|
2022-02-17 18:06:19 +08:00
|
|
|
if(${AX_LUA_VERSION} VERSION_GREATER_EQUAL "5.4.0") # !important: traditional lua bindings solution tolua++ not support yet
|
2021-03-13 18:18:40 +08:00
|
|
|
target_compile_definitions(${target_name} PUBLIC LUA_COMPAT_APIINTCASTS=1)
|
2022-02-17 18:06:19 +08:00
|
|
|
elseif(${AX_LUA_VERSION} VERSION_GREATER_EQUAL "5.3.0")
|
2021-03-13 18:18:40 +08:00
|
|
|
target_compile_definitions(${target_name}
|
|
|
|
PUBLIC LUA_COMPAT_5_1=1
|
|
|
|
PUBLIC LUA_COMPAT_5_2=1
|
|
|
|
)
|
2022-02-17 18:06:19 +08:00
|
|
|
elseif(${AX_LUA_VERSION} VERSION_GREATER_EQUAL "5.2.0")
|
2021-03-13 18:18:40 +08:00
|
|
|
target_compile_definitions(${target_name} PUBLIC LUA_COMPAT_ALL=1)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
target_link_libraries(${target_name} plainlua)
|
|
|
|
|
|
|
|
set_target_properties(${target_name}
|
|
|
|
PROPERTIES
|
|
|
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
|
|
|
FOLDER "Tools"
|
|
|
|
)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# tool:luac the lua bytecode compiler
|
|
|
|
add_lua_bin(luac "${LUA_SRC_PATH}/luac.c;${LUA_SRC_PATH}/ldump.c;${LUA_SRC_PATH}/lopcodes.c")
|
|
|
|
|
|
|
|
# tool:lua the lua interpreter
|
|
|
|
add_lua_bin(lua "${LUA_SRC_PATH}/lua.c")
|
2023-04-01 17:31:13 +08:00
|
|
|
elseif(LINUX)
|
|
|
|
target_compile_definitions(${target_name} PUBLIC LUA_USE_LINUX=1)
|
2020-11-16 14:47:43 +08:00
|
|
|
endif()
|